class ChooseTargetsPage(BaseDepPage): """ A Page allowing the user to pick the actual dependant and dependsOn items """ def __init__(self, parent=None, project=None, **kwargs): super(ChooseTargetsPage, self).__init__(parent) self.__project = project self.setTitle("Apply the dependency") layout = QtGui.QVBoxLayout(self) layout.setContentsMargins(2, 0, 2, 0) self.__errText = QtGui.QLabel("", self) self.group1 = group1 = QtGui.QGroupBox("Dependant Item", self) groupLayout1 = QtGui.QVBoxLayout(group1) groupLayout1.setContentsMargins(0, 0, 0, 0) self.__sourceSelector = src = common.job.JobColumnWidget( project=project, parent=self) # src.setSingleSelections(True) groupLayout1.addWidget(src) self.group2 = group2 = QtGui.QGroupBox("Item Depends On", self) groupLayout2 = QtGui.QVBoxLayout(group2) groupLayout2.setContentsMargins(0, 0, 0, 0) self.__destSelector = dst = common.job.JobColumnWidget(project=project, parent=self) groupLayout2.addWidget(self.__destSelector) layout.addWidget(self.__errText) layout.addWidget(group1) layout.addWidget(group2) self.registerField("sourceSelection*", self, "sourceSelection") self.registerField("destSelection*", self, "destSelection") def initializePage(self): depType = self.field("dependType") meta = DEPEND_TYPES[depType] subtitle = meta['descript'] self.setSubTitle(subtitle) srcType, dstType = meta['selection'] self.group1.setTitle("Dependant %s" % srcType.__name__) self.group2.setTitle("Depends On %s" % dstType.__name__) self.__errText.clear() src = self.__sourceSelector self.__initSelector(src) dst = self.__destSelector self.__initSelector(dst) layers = depType != DependType.JOB_ON_JOB src.setLayersEnabled(layers) dst.setLayersEnabled(layers) def __initSelector(self, selector): src = self.sourceObject() dst = self.destObject() name = src.name if selector is self.__sourceSelector: obj = src name = src.name select = True elif dst: obj = dst name = dst.name select = True else: obj = src select = False try: name = src.username except: name = src.name isDest = selector is self.__destSelector if isinstance(obj, client.Job): selector.setJobFilter(name, selectFirst=select) return job = obj.get_job() selector.setJobFilter(job.name) if isinstance(obj, client.Layer): selector.setLayerFilter(name) return if isinstance(obj, client.Task): layer = client.get_layer_by_id(obj.layerId) selector.setLayerFilter(layer.name) selector.setTaskFilter(name) def validatePage(self): src = self.sourceSelection dst = self.destSelection errText = self.__errText errText.clear() if not src or not dst: errText.setText("<font color=red>Both dependant and "\ "target selections are required</font>") return False if set(src).intersection(dst): errText.setText("<font color=red>Dependant item cannot "\ "be set to depend on itself</font>") return False depType = self.field("dependType") srcType, dstType = DEPEND_TYPES[depType]['selection'] for s in src: if not isinstance(s, srcType): errText.setText( "<font color=red>Dependant item must be a %s</font>" % srcType.__name__) return False for d in dst: if not isinstance(d, dstType): errText.setText( "<font color=red>'DependsOn' items must be a %s</font>" % dstType.__name__) return False return super(ChooseTargetsPage, self).validatePage() def getSourceSelection(self): sel = self.__sourceSelector.getSelection() return sel sourceSelection = QtCore.Property(list, fget=getSourceSelection) def getDestSelection(self): sel = self.__destSelector.getSelection() return sel destSelection = QtCore.Property(list, fget=getDestSelection)
class ChooseTypeDepPage(BaseDepPage): """ A Page giving the user a choice of which dependency type to apply. """ def __init__(self, *args, **kwargs): super(ChooseTypeDepPage, self).__init__(*args, **kwargs) self.setTitle("Choose the type of dependency") layout = QtGui.QVBoxLayout(self) self.__title = QtGui.QLabel("", self) layout.addWidget(self.__title) self.__radioGroup = QtGui.QButtonGroup(self) self.__radioGroup.setExclusive(True) for val, meta in sorted(DEPEND_TYPES.items()): btn = QtGui.QRadioButton(meta['label'], self) self.__radioGroup.addButton(btn, val) label = QtGui.QLabel( "<font color='#c3c3c3'>%s</font>" % meta['descript'], self) label.setIndent(30) font = btn.font() font.setPointSize(font.pointSize() - 1) label.setFont(font) layout.addWidget(btn) layout.addWidget(label) self.registerField("dependType*", self, "dependType") self.__radioGroup.buttonClicked[int].connect(self.completeChanged) def initializePage(self): src = self.sourceObject() srcTyp = src.__class__.__name__.lower() if src else None buttons = self.__radioGroup.buttons() defaultSelection = False for button in buttons: text = button.text().lower() button.setEnabled(bool(src)) if src and text.startswith(srcTyp): if not defaultSelection: button.setChecked(True) defaultSelection = True if not src: msg = "<font color='red'>No Plow object given to apply dependencies</font>" self.__title.setText(msg) return name = src.name txt = "Dependency Options for <strong>%s</strong> %r" % ( srcTyp.title(), name) self.__title.setText(txt) def isComplete(self): if self.dependType == -1: return False return super(ChooseTypeDepPage, self).isComplete() def getDependType(self): return self.__radioGroup.checkedId() dependType = QtCore.Property(int, fget=getDependType)