def __init__(self, host, masteruri=None, parent=None): PackageDialog.__init__(self, parent) self.host = host self.setWindowTitle('Run') ns_name_label = QLabel("NS/Name:", self.content) self.ns_field = QComboBox(self.content) self.ns_field.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)) self.ns_field.setEditable(True) ns_history = nm.history().cachedParamValues('run_dialog/NS') ns_history.insert(0, '/') self.ns_field.addItems(ns_history) self.name_field = QLineEdit(self.content) self.name_field.setEnabled(False) horizontalLayout = QHBoxLayout() horizontalLayout.addWidget(self.ns_field) horizontalLayout.addWidget(self.name_field) self.contentLayout.addRow(ns_name_label, horizontalLayout) args_label = QLabel("Args:", self.content) self.args_field = QComboBox(self.content) self.args_field.setSizeAdjustPolicy(QComboBox.AdjustToMinimumContentsLength) self.args_field.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)) self.args_field.setEditable(True) self.contentLayout.addRow(args_label, self.args_field) args_history = nm.history().cachedParamValues('run_dialog/Args') args_history.insert(0, '') self.args_field.addItems(args_history) host_label = QLabel("Host:", self.content) self.host_field = QComboBox(self.content) # self.host_field.setSizeAdjustPolicy(QComboBox.AdjustToContents) self.host_field.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)) self.host_field.setEditable(True) host_label.setBuddy(self.host_field) self.contentLayout.addRow(host_label, self.host_field) self.host_history = host_history = nm.history().cachedParamValues('/Host') if self.host in host_history: host_history.remove(self.host) host_history.insert(0, self.host) self.host_field.addItems(host_history) master_label = QLabel("ROS Master URI:", self.content) self.master_field = QComboBox(self.content) self.master_field.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)) self.master_field.setEditable(True) master_label.setBuddy(self.host_field) self.contentLayout.addRow(master_label, self.master_field) self.master_history = master_history = nm.history().cachedParamValues('/Optional Parameter/ROS Master URI') self.masteruri = "ROS_MASTER_URI" if masteruri is None else masteruri if self.masteruri in master_history: master_history.remove(self.masteruri) master_history.insert(0, self.masteruri) self.master_field.addItems(master_history) # self.package_field.setFocus(QtCore.Qt.TabFocusReason) if hasattr(self.package_field, "textChanged"): # qt compatibility self.package_field.textChanged.connect(self.on_package_selected) else: self.package_field.editTextChanged.connect(self.on_package_selected) self.binary_field.activated[str].connect(self.on_binary_selected)
def updateValue(self, value): try: if isinstance(value, (dict, list)): self._value = value elif value: nm.history().addParamCache(self.fullName(), value) if self.isArrayType(): if 'int' in self.baseType() or 'byte' in self.baseType(): self._value = map(int, value.lstrip('[').rstrip(']').split(',')) elif 'float' in self.baseType(): self._value = map(float, value.lstrip('[').rstrip(']').split(',')) elif 'bool' in self.baseType(): self._value = map(str2bool, value.lstrip('[').rstrip(']').split(',')) elif self.isBinaryType(): self._value = value else: # self._value = map(str, value)#[ s.encode(sys.getfilesystemencoding()) for s in value] try: import yaml self._value = yaml.load("[%s]"%value) # if there is no YAML, load() will return an # empty string. We want an empty dictionary instead # for our representation of empty. if self._value is None: self._value = [] except yaml.MarkedYAMLError, e: raise Exception("Field [%s] yaml error: %s"%(self.fullName(), str(e))) if not self.arrayLength() is None and self.arrayLength() != len(self._value): raise Exception(''.join(["Field [", self.fullName(), "] has incorrect number of elements: ", str(len(self._value)), " != ", str(self.arrayLength())])) else: if 'int' in self.baseType() or 'byte' in self.baseType(): self._value = int(value) elif 'float' in self.baseType(): self._value = float(value) elif 'bool' in self.baseType(): if isinstance(value, bool): self._value = value else: self._value = str2bool(value) elif self.isBinaryType(): self._value = unicode(value) elif self.isTimeType(): if value == 'now': self._value = 'now' else: try: val = eval(value) if isinstance(val, dict): self._value = val else: secs = int(val) nsecs = int((val - secs) * 1000000000) self._value = {'secs': secs, 'nsecs': nsecs} except: self._value = {'secs': 0, 'nsecs': 0} else: self._value = value.encode(sys.getfilesystemencoding()) else:
def setValue(self, value): error_str = '' try: if isinstance(value, (dict, list)): self._value = value elif value: nm.history().addParamCache(self.fullName(), value) if self.isArrayType(): if 'int' in self.baseType(): self._value = map(int, value.split(',')) elif 'float' in self.baseType(): self._value = map(float, value.split(',')) elif 'bool' in self.baseType(): self._value = map(str2bool, value.split(',')) else: self._value = [ s.encode(sys.getfilesystemencoding()) for s in value.split(',')] if not self.arrayLength() is None and self.arrayLength() != len(self._value): raise Exception(''.join(["Field [", self.fullName(), "] has incorrect number of elements: ", str(len(self._value)), " != ", str(self.arrayLength())])) else: if 'int' in self.baseType(): self._value = int(value) elif 'float' in self.baseType(): self._value = float(value) elif 'bool' in self.baseType(): if isinstance(value, bool): self._value = value else: self._value = str2bool(value) elif self.isTimeType(): if value == 'now': self._value = 'now' else: val = float(value) secs = int(val) nsecs = int((val - secs) * 1000000000) self._value = {'secs': secs, 'nsecs': nsecs} else: self._value = value.encode(sys.getfilesystemencoding()) else: if self.isArrayType(): arr = [] self._value = arr else: if 'int' in self.baseType(): self._value = 0 elif 'float' in self.baseType(): self._value = 0.0 elif 'bool' in self.baseType(): self._value = False elif self.isTimeType(): self._value = {'secs': 0, 'nsecs': 0} else: self._value = '' nm.history().addParamCache(self.fullName(), value) except Exception, e: raise Exception(''.join(["Error while set value '", unicode(value), "' for '", self.fullName(), "': ", str(e)]))
def run_params(self): ''' Runs the selected node, or do nothing. :return: a tuple with host, package, binary, name, args, maseruri or empty tuple on errors ''' self.binary = self.binary_field.currentText() self.host = self.host_field.currentText( ) if self.host_field.currentText() else self.host self.masteruri = self.master_field.currentText( ) if self.master_field.currentText() else self.masteruri if not self.host in self.host_history and self.host != 'localhost' and self.host != '127.0.0.1': nm.history().add2HostHistory(self.host) ns = self.ns_field.currentText() if ns and ns != '/': nm.history().addParamCache('run_dialog/NS', ns) args = self.args_field.currentText() if args: nm.history().addParamCache('run_dialog/Args', args) if self.package and self.binary: nm.history().addParamCache('/Host', self.host) return (self.host, self.package, self.binary, self.name_field.text(), ('__ns:=%s %s' % (ns, args)).split(' '), None if self.masteruri == 'ROS_MASTER_URI' else self.masteruri) return ()
def addCachedValuesToWidget(self): if isinstance(self.widget(), QtGui.QComboBox): values = nm.history().cachedParamValues(self.fullName()) for i in range(self.widget().count()): try: values.remove(self.widget().itemText(i)) except: pass if self.widget().count() == 0: values.insert(0, '') self.widget().addItems(values)
def runSelected(self): ''' Runs the selected node, or do nothing. ''' self.binary = self.binary_field.currentText() self.host = self.host_field.currentText() if self.host_field.currentText() else self.host self.masteruri = self.master_field.currentText() if self.master_field.currentText() else self.masteruri if not self.host in self.host_history and self.host != 'localhost' and self.host != '127.0.0.1': nm.history().add2HostHistory(self.host) ns = self.ns_field.currentText() if ns and ns != '/': nm.history().addParamCache('run_dialog/NS', ns) args = self.args_field.currentText() if args: nm.history().addParamCache('run_dialog/Args', args) if self.package and self.binary: nm.history().addParamCache('/Host', self.host) nm.starter().runNodeWithoutConfig(self.host, self.package, self.binary, str(self.name_field.text()), str(''.join(['__ns:=', ns, ' ', args])).split(' '), None if self.masteruri == 'ROS_MASTER_URI' else self.masteruri)
def run_params(self): ''' Runs the selected node, or do nothing. :return: a tuple with host, package, binary, name, args, maseruri or empty tuple on errors ''' self.binary = self.binary_field.currentText() self.host = self.host_field.currentText() if self.host_field.currentText() else self.host self.masteruri = self.master_field.currentText() if self.master_field.currentText() else self.masteruri if self.host not in self.host_history and self.host != 'localhost' and self.host != '127.0.0.1': nm.history().add2HostHistory(self.host) ns = self.ns_field.currentText() if ns and ns != '/': nm.history().addParamCache('run_dialog/NS', ns) args = self.args_field.currentText() if args: nm.history().addParamCache('run_dialog/Args', args) if self.package and self.binary: nm.history().addParamCache('/Host', self.host) return (self.host, self.package, self.binary, self.name_field.text(), ('__ns:=%s %s' % (ns, args)).split(' '), None if self.masteruri == 'ROS_MASTER_URI' else self.masteruri) return ()
def __init__(self, params=dict(), buttons=QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok, sidebar_var='', parent=None): ''' Creates an input dialog. @param params: a dictionary with parameter names and (type, values). The C{value}, can be a primitive value, a list with values or parameter dictionary to create groups. In this case the type is the name of the group. @type params: C{dict(str:(str, {value, [..], dict()}))} ''' QtGui.QDialog.__init__(self, parent=parent) self.setObjectName('ParameterDialog - %s'%str(params)) self.__current_path = nm.settings().current_dialog_path self.horizontalLayout = QtGui.QHBoxLayout(self) self.horizontalLayout.setObjectName("horizontalLayout") self.horizontalLayout.setContentsMargins(1, 1, 1, 1) self.verticalLayout = QtGui.QVBoxLayout() self.verticalLayout.setObjectName("verticalLayout") self.verticalLayout.setContentsMargins(1, 1, 1, 1) # add filter row self.filter_frame = QtGui.QFrame(self) filterLayout = QtGui.QHBoxLayout(self.filter_frame) filterLayout.setContentsMargins(1, 1, 1, 1) label = QtGui.QLabel("Filter:", self.filter_frame) self.filter_field = QtGui.QLineEdit(self.filter_frame) filterLayout.addWidget(label) filterLayout.addWidget(self.filter_field) self.filter_field.textChanged.connect(self._on_filter_changed) self.filter_visible = True self.verticalLayout.addWidget(self.filter_frame) # create area for the parameter self.scrollArea = scrollArea = ScrollArea(self); scrollArea.setObjectName("scrollArea") scrollArea.setWidgetResizable(True) self.content = MainBox('/', 'str', False, self) scrollArea.setWidget(self.content) self.verticalLayout.addWidget(scrollArea) # add info text field self.info_field = QtGui.QTextEdit(self) self.info_field.setVisible(False) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(255, 254, 242)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(255, 254, 242)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(244, 244, 244)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush) self.info_field.setPalette(palette) self.info_field.setFrameShadow(QtGui.QFrame.Plain) self.info_field.setReadOnly(True) self.info_field.setTextInteractionFlags(QtCore.Qt.LinksAccessibleByKeyboard|QtCore.Qt.LinksAccessibleByMouse|QtCore.Qt.TextBrowserInteraction|QtCore.Qt.TextSelectableByKeyboard|QtCore.Qt.TextSelectableByMouse) self.info_field.setObjectName("dialog_info_field") self.verticalLayout.addWidget(self.info_field) # create buttons self.buttonBox = QtGui.QDialogButtonBox(self) self.buttonBox.setObjectName("buttonBox") self.buttonBox.setOrientation(QtCore.Qt.Horizontal) self.buttonBox.setStandardButtons(buttons) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) self.verticalLayout.addWidget(self.buttonBox) self.horizontalLayout.addLayout(self.verticalLayout) # add side bar for checklist values = nm.history().cachedParamValues('/%s'%sidebar_var) self.sidebar_frame = QtGui.QFrame() self.sidebar_frame.setObjectName(sidebar_var) sidebarframe_verticalLayout = QtGui.QVBoxLayout(self.sidebar_frame) sidebarframe_verticalLayout.setObjectName("sidebarframe_verticalLayout") sidebarframe_verticalLayout.setContentsMargins(1, 1, 1, 1) self._sidebar_selected = 0 if len(values) > 1 and sidebar_var in params: self.horizontalLayout.addWidget(self.sidebar_frame) try: self.sidebar_default_val = params[sidebar_var][1] except: self.sidebar_default_val = '' values.sort() for v in values: checkbox = QtGui.QCheckBox(v) checkbox.stateChanged.connect(self._on_sidebar_stateChanged) self.sidebar_frame.layout().addWidget(checkbox) self.sidebar_frame.layout().addItem(QtGui.QSpacerItem(100, 20, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)) # set the input fields if params: self.content.createFieldFromValue(params) self.setInfoActive(False) if self.filter_frame.isVisible(): self.filter_field.setFocus() self.setMinimumSize(350,200)
def removeCachedValue(self, value): nm.history().removeParamCache(self.fullName(), value)
arr = [] self._value = arr else: if 'int' in self.baseType() or 'byte' in self.baseType(): self._value = 0 elif 'float' in self.baseType(): self._value = 0.0 elif 'bool' in self.baseType(): self._value = False elif self.isBinaryType(): self._value = unicode(value) elif self.isTimeType(): self._value = {'secs': 0, 'nsecs': 0} else: self._value = '' nm.history().addParamCache(self.fullName(), value) except Exception, e: raise Exception(''.join(["Error while set value '", unicode(value), "' for '", self.fullName(), "': ", str(e)])) return self._value def value(self): if not self.isPrimitiveType() and not self.widget() is None: return self.widget().value() elif self.isPrimitiveType(): self.updateValueFromField() # if self.isTimeType() and self._value == 'now': # # FIX: rostopic does not support 'now' values in sub-headers # t = time.time() # return ({'secs': int(t), 'nsecs': int((t-int(t))*1000000)}, self.changed()) return (self._value, self.changed())
def __init__(self, host, masteruri=None, parent=None): QtGui.QDialog.__init__(self, parent) self.host = host self.setWindowTitle('Run') self.verticalLayout = QtGui.QVBoxLayout(self) self.verticalLayout.setObjectName("verticalLayout") self.content = QtGui.QWidget() self.contentLayout = QtGui.QFormLayout(self.content) self.contentLayout.setVerticalSpacing(0) self.verticalLayout.addWidget(self.content) self.packages = None package_label = QtGui.QLabel("Package:", self.content) self.package_field = QtGui.QComboBox(self.content) self.package_field.setInsertPolicy(QtGui.QComboBox.InsertAlphabetically) self.package_field.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)) self.package_field.setEditable(True) self.contentLayout.addRow(package_label, self.package_field) binary_label = QtGui.QLabel("Binary:", self.content) self.binary_field = QtGui.QComboBox(self.content) # self.binary_field.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents) self.binary_field.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)) self.binary_field.setEditable(True) self.contentLayout.addRow(binary_label, self.binary_field) ns_name_label = QtGui.QLabel("NS/Name:", self.content) self.ns_field = QtGui.QComboBox(self.content) self.ns_field.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)) self.ns_field.setEditable(True) ns_history = nm.history().cachedParamValues('run_dialog/NS') ns_history.insert(0, '/') self.ns_field.addItems(ns_history) self.name_field = QtGui.QLineEdit(self.content) self.name_field.setEnabled(False) horizontalLayout = QtGui.QHBoxLayout() horizontalLayout.addWidget(self.ns_field) horizontalLayout.addWidget(self.name_field) self.contentLayout.addRow(ns_name_label, horizontalLayout) args_label = QtGui.QLabel("Args:", self.content) self.args_field = QtGui.QComboBox(self.content) self.args_field.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToMinimumContentsLength) self.args_field.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)) self.args_field.setEditable(True) self.contentLayout.addRow(args_label, self.args_field) args_history = nm.history().cachedParamValues('run_dialog/Args') args_history.insert(0, '') self.args_field.addItems(args_history) host_label = QtGui.QLabel("Host:", self.content) self.host_field = QtGui.QComboBox(self.content) # self.host_field.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents) self.host_field.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)) self.host_field.setEditable(True) host_label.setBuddy(self.host_field) self.contentLayout.addRow(host_label, self.host_field) self.host_history = host_history = nm.history().cachedParamValues('/Host') if self.host in host_history: host_history.remove(self.host) host_history.insert(0, self.host) self.host_field.addItems(host_history) master_label = QtGui.QLabel("ROS Master URI:", self.content) self.master_field = QtGui.QComboBox(self.content) self.master_field.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)) self.master_field.setEditable(True) master_label.setBuddy(self.host_field) self.contentLayout.addRow(master_label, self.master_field) self.master_history = master_history = nm.history().cachedParamValues('/Optional Parameter/ROS Master URI') self.masteruri = "ROS_MASTER_URI" if masteruri is None else masteruri if self.masteruri in master_history: master_history.remove(self.masteruri) master_history.insert(0, self.masteruri) self.master_field.addItems(master_history) self.buttonBox = QtGui.QDialogButtonBox(self) self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok|QtGui.QDialogButtonBox.Cancel) self.buttonBox.setOrientation(QtCore.Qt.Horizontal) self.buttonBox.setObjectName("buttonBox") self.verticalLayout.addWidget(self.buttonBox) self.package_field.setFocus(QtCore.Qt.TabFocusReason) self.package = '' self.binary = '' if self.packages is None: self.package_field.addItems(['packages searching...']) self.package_field.setCurrentIndex(0) self._fill_packages_thread = threading.Thread(target=self._fill_packages) self._fill_packages_thread.start() QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.accept) QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.reject) QtCore.QMetaObject.connectSlotsByName(self) self.package_field.activated[str].connect(self.on_package_selected) self.package_field.textChanged.connect(self.on_package_selected) self.binary_field.activated[str].connect(self.on_binary_selected)
def __init__(self, host, parent=None): QtGui.QDialog.__init__(self, parent) self.host = host self.setWindowTitle('Run') self.verticalLayout = QtGui.QVBoxLayout(self) self.verticalLayout.setObjectName("verticalLayout") self.content = QtGui.QWidget() self.contentLayout = QtGui.QFormLayout(self.content) self.contentLayout.setVerticalSpacing(0) self.verticalLayout.addWidget(self.content) # fill the input fields self.root_paths = [os.path.normpath(p) for p in os.getenv("ROS_PACKAGE_PATH").split(':')] self.packages = {} for p in self.root_paths: ret = self._getPackages(p) self.packages = dict(ret.items() + self.packages.items()) package_label = QtGui.QLabel("Package:", self.content) self.package_field = QtGui.QComboBox(self.content) self.package_field.setInsertPolicy(QtGui.QComboBox.InsertAlphabetically) self.package_field.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)) self.package_field.setEditable(True) self.contentLayout.addRow(package_label, self.package_field) binary_label = QtGui.QLabel("Binary:", self.content) self.binary_field = QtGui.QComboBox(self.content) # self.binary_field.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents) self.binary_field.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)) self.binary_field.setEditable(True) self.contentLayout.addRow(binary_label, self.binary_field) ns_name_label = QtGui.QLabel("NS/Name:", self.content) self.ns_field = QtGui.QComboBox(self.content) self.ns_field.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)) self.ns_field.setEditable(True) ns_history = nm.history().cachedParamValues('run_dialog/NS') ns_history.insert(0, '/') self.ns_field.addItems(ns_history) self.name_field = QtGui.QLineEdit(self.content) self.name_field.setEnabled(False) horizontalLayout = QtGui.QHBoxLayout() horizontalLayout.addWidget(self.ns_field) horizontalLayout.addWidget(self.name_field) self.contentLayout.addRow(ns_name_label, horizontalLayout) args_label = QtGui.QLabel("Args:", self.content) self.args_field = QtGui.QComboBox(self.content) self.args_field.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToMinimumContentsLength) # self.args_field.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)) self.args_field.setEditable(True) self.contentLayout.addRow(args_label, self.args_field) args_history = nm.history().cachedParamValues('run_dialog/Args') args_history.insert(0, '') self.args_field.addItems(args_history) host_label = QtGui.QLabel("Host:", self.content) self.host_field = QtGui.QComboBox(self.content) # self.host_field.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents) self.host_field.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)) self.host_field.setEditable(True) host_label.setBuddy(self.host_field) self.contentLayout.addRow(host_label, self.host_field) self.host_history = host_history = nm.history().cachedParamValues('/Host') if self.host in host_history: host_history.remove(self.host) host_history.insert(0, self.host) self.host_field.addItems(host_history) master_label = QtGui.QLabel("ROS Master URI:", self.content) self.master_field = QtGui.QComboBox(self.content) self.master_field.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)) self.master_field.setEditable(True) master_label.setBuddy(self.host_field) self.contentLayout.addRow(master_label, self.master_field) self.master_history = master_history = nm.history().cachedParamValues('/Optional Parameter/ROS Master URI') self.masteruri = "ROS_MASTER_URI" if self.masteruri in master_history: master_history.remove(self.masteruri) master_history.insert(0, self.masteruri) self.master_field.addItems(master_history) self.buttonBox = QtGui.QDialogButtonBox(self) self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok|QtGui.QDialogButtonBox.Cancel) self.buttonBox.setOrientation(QtCore.Qt.Horizontal) self.buttonBox.setObjectName("buttonBox") self.verticalLayout.addWidget(self.buttonBox) QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.accept) QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.reject) QtCore.QMetaObject.connectSlotsByName(self) self.package_field.activated[str].connect(self.on_package_selected) self.package_field.textChanged.connect(self.on_package_selected) self.binary_field.activated[str].connect(self.on_binary_selected) self.package_field.setFocus(QtCore.Qt.TabFocusReason) self.package = '' self.binary = '' packages = self.packages.keys() packages.sort() self.package_field.addItems(packages) if packages: self.on_package_selected(packages[0])
def setValue(self, value): error_str = '' try: if isinstance(value, (dict, list)): self._value = value elif value: nm.history().addParamCache(self.fullName(), value) if self.isArrayType(): if 'int' in self.baseType(): self._value = map(int, value.split(',')) elif 'float' in self.baseType(): self._value = map(float, value.split(',')) elif 'bool' in self.baseType(): self._value = map(str2bool, value.split(',')) else: self._value = [ s.encode(sys.getfilesystemencoding()) for s in value.split(',') ] if not self.arrayLength() is None and self.arrayLength( ) != len(self._value): raise Exception(''.join([ "Field [", self.fullName(), "] has incorrect number of elements: ", str(len(self._value)), " != ", str(self.arrayLength()) ])) else: if 'int' in self.baseType(): self._value = int(value) elif 'float' in self.baseType(): self._value = float(value) elif 'bool' in self.baseType(): if isinstance(value, bool): self._value = value else: self._value = str2bool(value) elif self.isTimeType(): if value == 'now': self._value = 'now' else: val = float(value) secs = int(val) nsecs = int((val - secs) * 1000000000) self._value = {'secs': secs, 'nsecs': nsecs} else: self._value = value.encode(sys.getfilesystemencoding()) else: if self.isArrayType(): arr = [] self._value = arr else: if 'int' in self.baseType(): self._value = 0 elif 'float' in self.baseType(): self._value = 0.0 elif 'bool' in self.baseType(): self._value = False elif self.isTimeType(): self._value = {'secs': 0, 'nsecs': 0} else: self._value = '' nm.history().addParamCache(self.fullName(), value) except Exception, e: raise Exception(''.join([ "Error while set value '", unicode(value), "' for '", self.fullName(), "': ", str(e) ]))