[core] node: add some typing

This commit is contained in:
Fabien Castan 2025-03-28 12:15:39 +01:00
parent 2f08448310
commit 0c32060264

View file

@ -68,15 +68,18 @@ class StatusData(BaseObject):
def __init__(self, nodeName='', nodeType='', packageName='', packageVersion='', mrNodeType: MrNodeType = MrNodeType.NONE, parent: BaseObject = None): def __init__(self, nodeName='', nodeType='', packageName='', packageVersion='', mrNodeType: MrNodeType = MrNodeType.NONE, parent: BaseObject = None):
super(StatusData, self).__init__(parent) super(StatusData, self).__init__(parent)
self.reset()
self.nodeName: str = nodeName self.nodeName: str = nodeName
self.nodeType: str = nodeType self.nodeType: str = nodeType
self.packageName: str = packageName self.packageName: str = packageName
self.packageVersion: str = packageVersion self.packageVersion: str = packageVersion
self.mrNodeType = mrNodeType self.mrNodeType = mrNodeType
self.sessionUid: Optional[str] = meshroom.core.sessionUid self.sessionUid: Optional[str] = meshroom.core.sessionUid
self.submitterSessionUid: Optional[str] = None self.submitterSessionUid: Optional[str] = None
self.resetDynamicValues()
def merge(self, other): def merge(self, other):
self.startDateTime = min(self.startDateTime, other.startDateTime) self.startDateTime = min(self.startDateTime, other.startDateTime)
self.endDateTime = max(self.endDateTime, other.endDateTime) self.endDateTime = max(self.endDateTime, other.endDateTime)
@ -1420,7 +1423,7 @@ class BaseNode(BaseObject):
self._hasDuplicates = bool(len(newList)) self._hasDuplicates = bool(len(newList))
self.hasDuplicatesChanged.emit() self.hasDuplicatesChanged.emit()
def statusInThisSession(self): def statusInThisSession(self) -> bool:
if not self._chunks: if not self._chunks:
return False return False
for chunk in self._chunks: for chunk in self._chunks:
@ -1428,7 +1431,7 @@ class BaseNode(BaseObject):
return False return False
return True return True
def submitterStatusInThisSession(self): def submitterStatusInThisSession(self) -> bool:
if not self._chunks: if not self._chunks:
return False return False
for chunk in self._chunks: for chunk in self._chunks:
@ -1436,8 +1439,8 @@ class BaseNode(BaseObject):
return False return False
return True return True
def initFromThisSession(self): def initFromThisSession(self) -> bool:
if not self._chunks: if len(self._chunks) == 0:
return False return False
for chunk in self._chunks: for chunk in self._chunks:
mrNodeType = chunk.node.getMrNodeType() mrNodeType = chunk.node.getMrNodeType()
@ -1447,7 +1450,7 @@ class BaseNode(BaseObject):
return True return True
@Slot(result=bool) @Slot(result=bool)
def canBeStopped(self): def canBeStopped(self) -> bool:
# Only locked nodes running in local with the same # Only locked nodes running in local with the same
# sessionUid as the Meshroom instance can be stopped # sessionUid as the Meshroom instance can be stopped
return (self.getGlobalStatus() == Status.RUNNING and return (self.getGlobalStatus() == Status.RUNNING and
@ -1455,14 +1458,14 @@ class BaseNode(BaseObject):
self.initFromThisSession()) self.initFromThisSession())
@Slot(result=bool) @Slot(result=bool)
def canBeCanceled(self): def canBeCanceled(self) -> bool:
# Only locked nodes submitted in local with the same # Only locked nodes submitted in local with the same
# sessionUid as the Meshroom instance can be canceled # sessionUid as the Meshroom instance can be canceled
return (self.getGlobalStatus() == Status.SUBMITTED and return (self.getGlobalStatus() == Status.SUBMITTED and
self.globalExecMode == ExecMode.LOCAL.name and self.globalExecMode == ExecMode.LOCAL.name and
self.initFromThisSession()) self.initFromThisSession())
def hasImageOutputAttribute(self): def hasImageOutputAttribute(self) -> bool:
""" """
Return True if at least one attribute has the 'image' semantic (and can thus be loaded in the 2D Viewer), Return True if at least one attribute has the 'image' semantic (and can thus be loaded in the 2D Viewer),
False otherwise. False otherwise.
@ -1472,7 +1475,7 @@ class BaseNode(BaseObject):
return True return True
return False return False
def hasSequenceOutputAttribute(self): def hasSequenceOutputAttribute(self) -> bool:
""" """
Return True if at least one attribute has the 'sequence' semantic (and can thus be loaded in the 2D Viewer), Return True if at least one attribute has the 'sequence' semantic (and can thus be loaded in the 2D Viewer),
False otherwise. False otherwise.