def createArgument(self, arg): warg = QWidget() vlayout = QVBoxLayout() vlayout.setSpacing(5) vlayout.setMargin(0) winfo = QWidget() infolayout = QFormLayout() infolayout.setMargin(0) requirement = arg.requirementType() # Generate argument's widget warguments = self.getWidgetFromType(arg) if arg.requirementType() in (Argument.Optional, Argument.Empty): checkBox = checkBoxWidget(self, winfo, warguments, self.labActivate.text()) vlayout.addWidget(checkBox, 0) infolayout.addRow(self.labType.text(), QLabel(str(typeId.Get().typeToName(arg.type())))) tedit = QTextEdit(str(arg.description())) tedit.setReadOnly(True) infolayout.addRow(tedit) winfo.setLayout(infolayout) vlayout.addWidget(winfo, 1) if warguments: vlayout.addWidget(warguments, 2) self.valueArgs[arg.name()] = warguments else: self.valueArgs[arg.name()] = winfo warg.setLayout(vlayout) self.stackedargs.addWidget(warg) argitem = QListWidgetItem(str(arg.name()), self.listargs)
def createArgument(self, arg): warg = QWidget() vlayout = QVBoxLayout() vlayout.setSpacing(5) vlayout.setMargin(0) winfo = QWidget() infolayout = QFormLayout() infolayout.setMargin(0) requirement = arg.requirementType() # Generate argument's widget warguments = self.getWidgetFromType(arg) if arg.requirementType() in (Argument.Optional, Argument.Empty): checkBox = checkBoxWidget(self, winfo, warguments, self.labActivate.text()) vlayout.addWidget(checkBox, 0) tedit = QTextEdit(str(arg.description())) tedit.setReadOnly(True) infolayout.addRow(tedit) winfo.setLayout(infolayout) vlayout.addWidget(winfo, 1) if warguments: vlayout.addWidget(warguments, 2) self.valueArgs[arg.name()] = warguments else: self.valueArgs[arg.name()] = winfo warg.setLayout(vlayout) self.stackedargs.addWidget(warg) argitem = QListWidgetItem(str(arg.name()), self.listargs)
def createArgument(self, arg): warg = QWidget() vlayout = QVBoxLayout() vlayout.setSpacing(5) vlayout.setMargin(0) winfo = QWidget() infolayout = QFormLayout() infolayout.setMargin(0) requirement = arg.requirementType() # Generate argument's widget warguments = self.getWidgetFromType(arg) if arg.requirementType() in (Argument.Optional, Argument.Empty): checkBox = checkBoxWidget(self, winfo, warguments, self.labActivate.text()) vlayout.addWidget(checkBox, 0) if arg.type() in [ typeId.Int16, typeId.UInt16, typeId.Int32, typeId.UInt32, typeId.Int64, typeId.UInt64 ]: typeinfo = self.tr("Number") elif arg.type() in [typeId.String, typeId.CArray]: typeinfo = self.tr("String") elif arg.type() in [typeId.Bool]: typeinfo = self.tr("Boolean") elif arg.type() in [typeId.Path]: typeinfo = self.tr("File or folder stored on the local system") elif arg.type() in [typeId.Node]: typeinfo = self.tr("Node from the virtual filesystem") else: typeinfo = None if typeinfo is not None: self.labType.setText(self.tr("Input type:")) infolayout.addRow(self.labType.text(), QLabel(typeinfo)) tedit = QTextEdit(str(arg.description())) tedit.setReadOnly(True) infolayout.addRow(tedit) winfo.setLayout(infolayout) vlayout.addWidget(winfo, 1) if warguments: vlayout.addWidget(warguments, 2) self.valueArgs[arg.name()] = warguments else: self.valueArgs[arg.name()] = winfo warg.setLayout(vlayout) self.stackedargs.addWidget(warg) argitem = QListWidgetItem(str(arg.name()), self.listargs)
class layoutManager(QWidget): '''Create a layout manager which will help widget creation and data managment The system work with a key / value system and return python type data (ex: str, int, long, list, tupple, etc..) ''' def __init__(self, displaykey=False): QWidget.__init__(self) self.layout = QFormLayout() self.layout.setMargin(0) self.widgets = {} self.displaykey = displaykey self.setLayout(self.layout) self.translation() def overwriteKeys(self, key): ''' Check if inserted key already exists in the layout system ''' for k, v in self.widgets.iteritems(): if k == key: return True return False def addBool(self, key, state = False): ''' Create a non-exclusive checkbox widget and add it into the layout. It permit you to create Bool data representations ''' if not self.overwriteKeys(key): if type(key).__name__=='str': w = QCheckBox(key) if not self.displaykey: self.layout.addRow(w) else: self.layout.addRow(key, w) self.widgets[key] = w else: return -1 else: return -1 return 1 def addList(self, key, predefs, editable=False): if len(predefs) > 0 and not self.overwriteKeys(key): # Check if value list has the same type if type(key) == types.StringType: w = QComboBox() self.connect(w, SIGNAL("currentIndexChanged(QString)"), self.argumentChanged) w.setEditable(editable) w.setValidator(QIntValidator()) for value in predefs: if type(value).__name__=='str': if w.findText(value) == -1: w.addItem(value) elif type(value).__name__=='int': if w.findText(str(value)) == -1: w.addItem(str(value)) else: return -1 if not self.displaykey: self.layout.addRow(w) else: self.layout.addRow(key, w) self.widgets[key] = w return 1 else: return -1 else: return -1 def addSingleArgument(self, key, predefs, typeid, editable=False): if not self.overwriteKeys(key): if type(key) == types.StringType: if len(predefs) > 0: w = QComboBox() self.connect(w, SIGNAL("editTextChanged(QString)"), self.argumentChanged) self.connect(w, SIGNAL("currentIndexChanged(QString)"), self.argumentChanged) w.setEditable(editable) for value in predefs: w.addItem(value.toString()) else: w = QLineEdit() self.connect(w, SIGNAL("editingFinished()"), self.argumentChanged) if typeid not in (typeId.String, typeId.Char, typeId.Node, typeId.Path): w.insert("0") w.setReadOnly(not editable) w.setValidator(fieldValidator(self, typeid)) if not self.displaykey: self.layout.addRow(w) else: self.layout.addRow(key, w) self.widgets[key] = w return 1 else: return -1 else: return -1 def addString(self, key, value=""): if not self.overwriteKeys(key): if type(key).__name__=='str': w = QLineEdit() self.connect(w, SIGNAL("editingFinished()"), self.argumentChanged) w.insert(value) if not self.displaykey: self.layout.addRow(w) else: self.layout.addRow(key, w) self.widgets[key] = w return 1 else: return -1 else: return -1 def addText(self, key, value=""): if not self.overwriteKeys(key): if type(key).__name__=='str': w = QTextEdit() self.connect(w, SIGNAL("textChanged()"), self.argumentChanged) w.setPlainText(value) if not self.displaykey: self.layout.addRow(w) else: self.layout.addRow(key, w) self.widgets[key] = w return 1 else: return -1 else: return -1 def addListArgument(self, key, typeid, predefs, editable=False, config=None): if not self.overwriteKeys(key) and type(key) == types.StringType: w = multipleListWidget(self, typeid, predefs, editable) if not self.displaykey: self.layout.addRow(w) else: self.layout.addRow(key, w) self.widgets[key] = w.valuelist if config: w.addParameterConfig(config) return 1 else: return -1 def addPathList(self, key, typeid, predefs, selectednodes): if not self.overwriteKeys(key) and type(key).__name__=='str': layout = QVBoxLayout() listpathcontainer = QListWidget() ##XXX listpathcontainer.setDragDropMode(QAbstractItemView.InternalMove) if len(predefs) > 0: if not self.checkUnifiedTypes(predefs): return -1 for predef in predefs: listpathcontainer.insertItem(listpathcontainer.count() + 1, str(predef)) if selectednodes and len(selectednodes) > 0: for node in selectednodes: if type(node) == Node and typeid == typeId.Node: listpathcontainer.insertItem(listpathcontainer.count() + 1, QString.fromUtf8(node.absolute())) elif type(node) != Node: listpathcontainer.insertItem(listpathcontainer.count() + 1, node) hbox = QHBoxLayout() buttonbox = QDialogButtonBox() if typeid == typeId.Path: combo = QComboBox() self.connect(combo, SIGNAL("editTextChanged(QString)"), self.argumentChanged) self.connect(combo, SIGNAL("currentIndexChanged(QString)"), self.argumentChanged) combo.addItem(self.inputFile) combo.addItem(self.inputDirectory) add = addLocalPathButton(self, key, listpathcontainer, combo) else: add = addLocalPathButton(self, key, listpathcontainer, nodetype=True) buttonbox.addButton(add, QDialogButtonBox.ActionRole) rm = rmLocalPathButton(self, listpathcontainer) buttonbox.addButton(rm, QDialogButtonBox.ActionRole) self.connect(add, SIGNAL("clicked()"), self.argumentChanged) self.connect(rm, SIGNAL("clicked()"), self.argumentChanged) hbox.addWidget(buttonbox, 3, Qt.AlignLeft) if typeid == typeId.Path: hbox.addWidget(combo, 1, Qt.AlignRight) layout.addLayout(hbox, 0) layout.addWidget(listpathcontainer, 2) if not self.displaykey: self.layout.addRow(layout) else: self.layout.addRow(key, layout) self.widgets[key] = listpathcontainer return 1 else: return -1 def addPath(self, key, typeid, predefs, selectednodes, editable=False, config=None): if config: predefs.push_front(config[0]) if not self.overwriteKeys(key) and type(key).__name__=='str': vbox = QVBoxLayout() if typeid == typeId.Path: combo = QComboBox() self.connect(combo, SIGNAL("editTextChanged(QString)"), self.argumentChanged) self.connect(combo, SIGNAL("currentIndexChanged(QString)"), self.argumentChanged) combo.addItem(self.inputFile) combo.addItem(self.inputDirectory) vbox.addWidget(combo) layout = QHBoxLayout() if len(predefs) > 0 or len(selectednodes) > 0: pathcontainer = QComboBox() self.connect(pathcontainer, SIGNAL("editTextChanged(QString)"), self.argumentChanged) self.connect(pathcontainer, SIGNAL("currentIndexChanged(QString)"), self.argumentChanged) pathcontainer.setEditable(editable) for value in predefs: if typeid == typeId.Node: pathcontainer.addItem(value.value().name()) else: pathcontainer.addItem(value.toString()) if typeid == typeId.Node: for node in selectednodes: pathcontainer.addItem(QString.fromUtf8(node.absolute())) else: pathcontainer = QLineEdit() pathcontainer.setReadOnly(not editable) self.connect(pathcontainer, SIGNAL("editingFinished()"), self.argumentChanged) if typeid == typeId.Path: browse = addLocalPathButton(self, key, pathcontainer, inputchoice=combo) else: browse = addLocalPathButton(self, key, pathcontainer, nodetype=True) layout.addWidget(pathcontainer, 2) layout.addWidget(browse, 0) vbox.addLayout(layout) if not self.displaykey: self.layout.addRow(vbox) else: self.layout.addRow(key, vbox) self.widgets[key] = pathcontainer return 1 else: return -1 def checkUnifiedTypes(self, values): if len(values) == 0: return vtype = type(values[0]).__name__ for v in values: if type(v).__name__!=vtype: return False return True def get(self, key): for k, v in self.widgets.iteritems(): if k == key: if isinstance(self.widgets[k], QLineEdit): return str(v.text().toUtf8()) elif isinstance(self.widgets[k], QListWidget): items = [] for index in xrange(self.widgets[k].count()): items.append(str(self.widgets[k].item(index).text().toUtf8())) return items elif isinstance(self.widgets[k], QCheckBox): state = self.widgets[k].checkState() if state == Qt.Unchecked: return False else: return True elif isinstance(self.widgets[k], QTextEdit): return str(self.widgets[k].toPlainText().toUtf8()) elif isinstance(self.widgets[k], QComboBox): return str(self.widgets[k].currentText().toUtf8()) else: return -1 def argumentChanged(self, event = None): self.emit(SIGNAL("argumentChanged()")) def translation(self): self.inputFile = self.tr("File") self.inputDirectory = self.tr("Directory") def changeEvent(self, event): """ Search for a language change event This event have to call retranslateUi to change interface language on the fly. """ if event.type() == QEvent.LanguageChange: self.retranslateUi(self) self.translation() else: QWidget.changeEvent(self, event)
class layoutManager(QWidget): '''Create a layout manager which will help widget creation and data managment The system work with a key / value system and return python type data (ex: str, int, long, list, tupple, etc..) ''' def __init__(self, displaykey=False): QWidget.__init__(self) self.layout = QFormLayout() self.layout.setMargin(0) self.widgets = {} self.displaykey = displaykey self.setLayout(self.layout) self.translation() def overwriteKeys(self, key): ''' Check if inserted key already exists in the layout system ''' return self.widgets.has_key(key) def addBool(self, key, state=False): ''' Create a non-exclusive checkbox widget and add it into the layout. It permit you to create Bool data representations ''' if not self.overwriteKeys(key): if type(key).__name__ == 'str': w = QCheckBox(key) if not self.displaykey: self.layout.addRow(w) else: self.layout.addRow(key, w) self.widgets[key] = w else: return -1 else: return -1 return 1 def addList(self, key, predefs, editable=False): if len(predefs) > 0 and not self.overwriteKeys(key): # Check if value list has the same type if type(key) == types.StringType: w = QComboBox() self.connect(w, SIGNAL("currentIndexChanged(QString)"), self.argumentChanged) w.setEditable(editable) w.setValidator(QIntValidator()) w.setMinimumContentsLength(20) for value in predefs: if type(value).__name__ == 'str': if w.findText(value) == -1: w.addItem(value) elif type(value).__name__ == 'int': if w.findText(str(value)) == -1: w.addItem(str(value)) else: return -1 if not self.displaykey: self.layout.addRow(w) else: self.layout.addRow(key, w) self.widgets[key] = w return 1 else: return -1 else: return -1 def addSingleArgument(self, key, predefs, typeid, editable=False): if not self.overwriteKeys(key): if type(key) == types.StringType: if len(predefs) > 0: w = QComboBox() self.connect(w, SIGNAL("editTextChanged(QString)"), self.argumentChanged) self.connect(w, SIGNAL("currentIndexChanged(QString)"), self.argumentChanged) w.setEditable(editable) for value in predefs: w.addItem(value.toString()) else: w = QLineEdit() self.connect(w, SIGNAL("editingFinished()"), self.argumentChanged) if typeid not in (typeId.String, typeId.Char, typeId.Node, typeId.Path): w.insert("0") w.setReadOnly(not editable) w.setValidator(fieldValidator(self, typeid)) if not self.displaykey: self.layout.addRow(w) else: self.layout.addRow(key, w) self.widgets[key] = w return 1 else: return -1 else: return -1 def addString(self, key, value=""): if not self.overwriteKeys(key): if type(key).__name__ == 'str': w = QLineEdit() self.connect(w, SIGNAL("editingFinished()"), self.argumentChanged) w.insert(value) if not self.displaykey: self.layout.addRow(w) else: self.layout.addRow(key, w) self.widgets[key] = w return 1 else: return -1 else: return -1 def addText(self, key, value=""): if not self.overwriteKeys(key): if type(key).__name__ == 'str': w = QTextEdit() self.connect(w, SIGNAL("textChanged()"), self.argumentChanged) w.setPlainText(value) if not self.displaykey: self.layout.addRow(w) else: self.layout.addRow(key, w) self.widgets[key] = w return 1 else: return -1 else: return -1 def addSingleNode(self, key, predefs, selectednodes, editable=False, config=None): if config: predefs.push_front(config[0]) if not self.overwriteKeys(key) and type(key).__name__ == 'str': vbox = QVBoxLayout() layout = QHBoxLayout() nodecontainer = NodeComboItem(self) self.connect(nodecontainer, SIGNAL("editTextChanged(QString)"), self.argumentChanged) self.connect(nodecontainer, SIGNAL("currentIndexChanged(QString)"), self.argumentChanged) nodecontainer.setEditable(editable) if len(predefs) > 0: if config: for value in predefs: node = value.value() name = QString.fromUtf8(node.absolute()) nodecontainer.addSingleItem(name, node.uid()) else: category = self.tr("Predefined parameters") nodecontainer.addParentItem(category) for value in predefs: node = value.value() name = QString.fromUtf8(node.absolute()) nodecontainer.addChildItem(name, node.uid()) if len(selectednodes) == 1: node = selectednodes[0] name = QString.fromUtf8(node.absolute()) nodecontainer.addSingleItem(name, node.uid()) elif len(selectednodes) > 0: category = self.tr("Selected nodes") nodecontainer.addParentItem(category) for node in selectednodes: name = QString.fromUtf8(node.absolute()) nodecontainer.addChildItem(name, node.uid()) browse = NodeSelectionButton(self, key, nodecontainer) layout.addWidget(nodecontainer, 2) layout.addWidget(browse, 0) vbox.addLayout(layout) if not self.displaykey: self.layout.addRow(vbox) else: self.layout.addRow(key, vbox) self.widgets[key] = nodecontainer return 1 else: return -1 def addNodeList(self, key, predefs, selectednodes): if not self.overwriteKeys(key) and type(key).__name__ == 'str': layout = QVBoxLayout() nodeList = NodeListItem() nodeList.setDragDropMode(QAbstractItemView.InternalMove) if len(predefs) > 0: if not self.checkUnifiedTypes(predefs): return -1 for predef in predefs: nodeList.addSingleItem(str(predef), predef.value().uid()) if selectednodes and len(selectednodes) > 0: for node in selectednodes: name = QString.fromUtf8(node.absolute()) nodeList.addSingleItem(name, node.uid()) hbox = QHBoxLayout() buttonbox = QDialogButtonBox() add = NodeSelectionButton(self, key, nodeList) buttonbox.addButton(add, QDialogButtonBox.ActionRole) rm = rmLocalPathButton(self, nodeList) buttonbox.addButton(rm, QDialogButtonBox.ActionRole) self.connect(add, SIGNAL("clicked()"), self.argumentChanged) self.connect(rm, SIGNAL("clicked()"), self.argumentChanged) hbox.addWidget(buttonbox, 3, Qt.AlignLeft) layout.addLayout(hbox, 0) layout.addWidget(nodeList, 2) if not self.displaykey: self.layout.addRow(layout) else: self.layout.addRow(key, layout) self.widgets[key] = nodeList return 1 else: return -1 def addSinglePath(self, key, predefs, editable=False, config=None): if config: predefs.push_front(config[0]) if not self.overwriteKeys(key) and type(key).__name__ == 'str': vbox = QVBoxLayout() layout = QHBoxLayout() pathcontainer = ComboItem(self) self.connect(pathcontainer, SIGNAL("editTextChanged(QString)"), self.argumentChanged) self.connect(pathcontainer, SIGNAL("currentIndexChanged(QString)"), self.argumentChanged) if len(predefs) > 0: if config: for value in predefs: val = value.value() name = val.path pathcontainer.addSingleItem(name) else: category = self.tr("Predefined parameters") pathcontainer.setEditable(editable) pathcontainer.addParentItem(category) for value in predefs: val = value.value() name = val.path pathcontainer.addChildItem(name) combo = QComboBox() browse = PathSelectionButton(self, key, pathcontainer, inputchoice=combo) self.connect(combo, SIGNAL("editTextChanged(QString)"), self.argumentChanged) self.connect(combo, SIGNAL("currentIndexChanged(QString)"), self.argumentChanged) combo.addItem(self.inputFile) combo.addItem(self.inputDirectory) vbox.addWidget(combo) layout.addWidget(pathcontainer, 2) layout.addWidget(browse, 0) vbox.addLayout(layout) if not self.displaykey: self.layout.addRow(vbox) else: self.layout.addRow(key, vbox) self.widgets[key] = pathcontainer return 1 else: return -1 def addPathList(self, key, predefs): if not self.overwriteKeys(key) and type(key).__name__ == 'str': layout = QVBoxLayout() pathList = ListItem() ##XXX pathList.setDragDropMode(QAbstractItemView.InternalMove) if len(predefs) > 0: if not self.checkUnifiedTypes(predefs): return -1 for predef in predefs: pathList.addSingleItem(str(predef)) hbox = QHBoxLayout() buttonbox = QDialogButtonBox() combo = QComboBox() combo.setMinimumContentsLength(20) self.connect(combo, SIGNAL("editTextChanged(QString)"), self.argumentChanged) self.connect(combo, SIGNAL("currentIndexChanged(QString)"), self.argumentChanged) combo.addItem(self.inputFile) combo.addItem(self.inputDirectory) add = PathSelectionButton(self, key, pathList, combo) buttonbox.addButton(add, QDialogButtonBox.ActionRole) rm = rmLocalPathButton(self, pathList) buttonbox.addButton(rm, QDialogButtonBox.ActionRole) self.connect(add, SIGNAL("clicked()"), self.argumentChanged) self.connect(rm, SIGNAL("clicked()"), self.argumentChanged) hbox.addWidget(buttonbox, 3, Qt.AlignLeft) hbox.addWidget(combo, 1, Qt.AlignRight) layout.addLayout(hbox, 0) layout.addWidget(pathList, 2) if not self.displaykey: self.layout.addRow(layout) else: self.layout.addRow(key, layout) self.widgets[key] = pathList return 1 else: return -1 def addListArgument(self, key, typeid, predefs, editable=False, config=None): if not self.overwriteKeys(key) and type(key) == types.StringType: w = multipleListWidget(self, typeid, predefs, editable) if not self.displaykey: self.layout.addRow(w) else: self.layout.addRow(key, w) self.widgets[key] = w.valuelist if config: w.addParameterConfig(config) return 1 else: return -1 def checkUnifiedTypes(self, values): if len(values) == 0: return vtype = type(values[0]).__name__ for v in values: if type(v).__name__ != vtype: return False return True def get(self, key): if self.widgets.has_key(key): widget = self.widgets[key] if isinstance(widget, ComboItem): return widget.getItem() elif isinstance(widget, ListItem): return widget.getItems() elif isinstance(widget, QLineEdit): return str(widget.text().toUtf8()) elif isinstance(widget, QCheckBox): state = widget.checkState() if state == Qt.Unchecked: return False else: return True elif isinstance(widget, QTextEdit): return str(widget.toPlainText().toUtf8()) elif isinstance(widget, QComboBox): return str(widget.currentText().toUtf8()) else: return -1 else: return -1 def argumentChanged(self, event=None): self.emit(SIGNAL("argumentChanged()")) def translation(self): self.inputFile = self.tr("File") self.inputDirectory = self.tr("Directory")