class GraphicsMethodConfigurationWidget(QtGui.QWidget): def __init__(self, module, controller, parent=None, show_buttons=True): QtGui.QWidget.__init__(self, parent) self.module = module self.module_descriptor = self.module.module_descriptor.module self.controller = controller self.show_buttons = show_buttons self.layout = QtGui.QVBoxLayout() self.layout.setSpacing(3) self.layout.setMargin(0) self.fun_map = {} self.populate_fun_map() self.gmName = self.getValueFromFunction("graphicsMethodName") if self.gmName is None: self.gmName = self.module_descriptor().graphics_method_name self.mapAttributesToFunctions() self.tabWidget = QtGui.QTabWidget(self) self.tabWidget.setTabPosition(QtGui.QTabWidget.North) self.tabWidget.setDocumentMode(True) self.gmEditor = self.createEditor(self, self.gmName) self.tabWidget.insertTab(0, self.gmEditor, "Properties") self.wrldCoordEditor = self.tabWidget.widget(1) self.layout.addWidget(self.tabWidget) self.setupEditors() #default gmName can't be changed if str(self.gmName) == "default": self.gmEditor.setEnabled(False) self.wrldCoordEditor.setEnabled(False) if show_buttons: self.buttonLayout = QtGui.QHBoxLayout() self.buttonLayout.setMargin(5) self.saveButton = QDockPushButton('&Save', self) self.saveButton.setFixedWidth(100) self.saveButton.setEnabled(True) self.buttonLayout.addWidget(self.saveButton) self.resetButton = QDockPushButton('&Reset', self) self.resetButton.setFixedWidth(100) self.resetButton.setEnabled(True) self.buttonLayout.addWidget(self.resetButton) self.layout.addLayout(self.buttonLayout) self.connect(self.saveButton, QtCore.SIGNAL('clicked(bool)'), self.saveTriggered) self.connect(self.resetButton, QtCore.SIGNAL('clicked(bool)'), self.resetTriggered) self.setLayout(self.layout) self.tabWidget.setCurrentIndex(0) def createEditor(self, parent, gmName): plot_type = self.module.module_descriptor.module().plot_type if plot_type == "Boxfill": return QBoxfillEditor(self.tabWidget, gmName) elif plot_type == "Isofill": return QIsofillEditor(self.tabWidget, gmName) elif plot_type == "Isoline": return QIsolineEditor(self.tabWidget, gmName) elif plot_type == "Meshfill": return QMeshfillEditor(self.tabWidget, gmName) elif plot_type == "Outfill": return QOutfillEditor(self.tabWidget, gmName) elif plot_type == "Outline": return QOutlineEditor(self.tabWidget, gmName) elif plot_type == "Scatter": return QScatterEditor(self.tabWidget, gmName) elif plot_type == "Taylordiagram": return QTaylorDiagramEditor(self.tabWidget, gmName) elif plot_type == "Vector": return QVectorEditor(self.tabWidget, gmName) elif plot_type == "XvsY": return Q1DPlotEditor(self.tabWidget, gmName, type="xvsy") elif plot_type == "Xyvsy": return Q1DPlotEditor(self.tabWidget, gmName, type="xyvsy") elif plot_type == "Yxvsx": return Q1DPlotEditor(self.tabWidget, gmName, type="yxvsx") def setupEditors(self): gm = InstanceObject(**self.attributes) self.gmEditor.initValues(gm) #set continent self.continents = self.getValueFromFunction('continents') if self.continents: self.gmEditor.continents.setCurrentIndex(self.continents - 1) #set aspect ratio self.ratio = self.getValueFromFunction('ratio') #taylor diagram does not have aspectAuto if hasattr(self.gmEditor, 'aspectAuto'): if self.ratio is None or self.ratio == 'autot': self.gmEditor.aspectAuto.setCheckState(Qt.Checked) else: #if the ratio cannot cast to float, check auto in gui try: self.gmEditor.aspectRatio.setText(str(float(self.ratio))) self.gmEditor.aspectAuto.setCheckState(Qt.Unchecked) except ValueError: self.gmEditor.aspectAuto.setCheckState(Qt.Checked) def getValueFromFunction(self, fun): if fun in self.fun_map: fid = self.fun_map[fun] f = self.module.functions[fid] try: if fun == "skillColor": value = int(f.params[0].strValue) else: value = f.params[0].value() if fun == 'Marker': value = pickle.loads(value) except Exception, e: if fun == "skillColor": #if skillColor failed to parse as int, it should be string from init import get_canvas value = get_canvas().match_color(f.params[0].strValue) else: value = ast.literal_eval(f.params[0].strValue) return value else:
class AliasesPlotWidget(QtGui.QWidget): def __init__(self,controller, version, plot_obj, parent=None): QtGui.QWidget.__init__(self,parent) self.proj_controller = controller self.controller = controller.vt_controller self.version = version self.plot = plot_obj self.state_changed = False self.plot_widget = None self.buttonLayout = QtGui.QHBoxLayout() self.buttonLayout.setMargin(5) self.saveButton = QDockPushButton('&Save', self) self.saveButton.setFixedWidth(100) self.saveButton.setEnabled(True) self.buttonLayout.addWidget(self.saveButton) self.resetButton = QDockPushButton('&Reset', self) self.resetButton.setFixedWidth(100) self.resetButton.setEnabled(True) self.buttonLayout.addWidget(self.resetButton) layout = QtGui.QVBoxLayout() self.setLayout(layout) self.alias_widgets = {} self.updateWidgets(plot_obj) layout.addLayout(self.buttonLayout) self.connect(self.saveButton, QtCore.SIGNAL('clicked(bool)'), self.saveTriggered) self.connect(self.resetButton, QtCore.SIGNAL('clicked(bool)'), self.resetTriggered) def updateWidgets(self, plot_obj=None): self.plot = plot_obj if self.plot_widget is not None: self.layout().removeWidget(self.plot_widget) self.plot_widget.deleteLater() self.plot_widget = None if self.plot: pipeline = self.controller.vistrail.getPipeline(self.version) self.plot_widget = self.loadWidget(pipeline) self.layout().insertWidget(0,self.plot_widget) self.adjustSize() def updateVistrail(self): aliases = {} pipeline = self.controller.vistrail.getPipeline(self.version) for name in pipeline.aliases: aliases[name] = pipeline.get_alias_str_value(name) for a,w in self.alias_widgets.iteritems(): aliases[a] = w.contents() print a, aliases[a] action = self.applyChanges(pipeline, aliases) return action def applyChanges(self, pipeline, aliases): print " @@ Pipeline aliases: ", str( pipeline.aliases ) self.plot.addMergedAliases( aliases, pipeline ) action = self.plot.addParameterChangesFromAliasesAction(pipeline, self.controller, self.controller.vistrail, self.version, aliases) return action def saveTriggered(self, checked): action = self.updateVistrail() self.emit(QtCore.SIGNAL('plotDoneConfigure'), action) def resetTriggered(self, checked): self.updateWidgets(self.plot) self.emit(QtCore.SIGNAL("stateChanged")) def loadWidget( self, pipeline): from PyQt4 import QtGui aliases = pipeline.aliases widget = QtGui.QWidget() layout = QtGui.QVBoxLayout() hidden_aliases = self.plot.computeHiddenAliases() for name, (type, oId, parentType, parentId, mId) in aliases.iteritems(): if name not in hidden_aliases: p = pipeline.db_get_object(type, oId) if p.identifier == '': idn = 'edu.utah.sci.vistrails.basic' else: idn = p.identifier reg = get_module_registry() p_module = reg.get_module_by_name(idn, p.type, p.namespace) if p_module is not None: widget_type = get_widget_class(p_module) else: widget_type = StandardConstantWidget p_widget = widget_type(p, None) a_layout = QtGui.QHBoxLayout() label = QtGui.QLabel(name) a_layout.addWidget(label) a_layout.addWidget(p_widget) layout.addLayout(a_layout) self.alias_widgets[name] = p_widget widget.setLayout(layout) return widget
def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) core.debug.DebugPrint.getInstance().set_stream(debugStream(self.write)) self.setWindowTitle('VisTrails Messages') layout = QtGui.QVBoxLayout() self.setLayout(layout) # top message filter buttons filterHolder = QtGui.QGridLayout() layout.addLayout(filterHolder) filter = QtGui.QGridLayout() filterHolder.addLayout(filter, 0, 0, QtCore.Qt.AlignLeft) filterLabel = QtGui.QLabel('Filter:') filterLabel.setFixedWidth(40) filter.addWidget(filterLabel, 0, 0) self.infoFilter = QtGui.QCheckBox('Info', self) self.infoFilter.setCheckable(True) self.infoFilter.setChecked(True) self.infoFilter.setStyleSheet('color:' + CurrentTheme.DEBUG_INFO_COLOR.name() + ';background-color:' + CurrentTheme.DEBUG_FILTER_BACKGROUND_COLOR.name()) self.connect(self.infoFilter, QtCore.SIGNAL('stateChanged(int)'), self.toggleInfo) filter.addWidget(self.infoFilter, 0, 1) self.warningFilter = QtGui.QCheckBox('Warning', self) self.warningFilter.setCheckable(True) self.warningFilter.setChecked(True) self.warningFilter.setStyleSheet('color:' + CurrentTheme.DEBUG_WARNING_COLOR.name() + ';background-color:' + CurrentTheme.DEBUG_FILTER_BACKGROUND_COLOR.name()) self.connect(self.warningFilter, QtCore.SIGNAL('stateChanged(int)'), self.toggleWarning) filter.addWidget(self.warningFilter, 0, 2) self.criticalFilter = QtGui.QCheckBox('Critical', self) self.criticalFilter.setCheckable(True) self.criticalFilter.setChecked(True) self.criticalFilter.setStyleSheet('color:' + CurrentTheme.DEBUG_CRITICAL_COLOR.name() + ';background-color:' + CurrentTheme.DEBUG_FILTER_BACKGROUND_COLOR.name()) self.connect(self.criticalFilter, QtCore.SIGNAL('stateChanged(int)'), self.toggleCritical) filter.addWidget(self.criticalFilter, 0, 3) # message list self.list = QtGui.QListWidget() self.connect(self.list, QtCore.SIGNAL('currentItemChanged(QListWidgetItem *, QListWidgetItem *)'), self.showMessage) layout.addWidget(self.list) # message details field self.text = QtGui.QTextEdit() self.text.setReadOnly(True) self.text.hide() layout.addWidget(self.text) # bottom buttons buttons = QtGui.QGridLayout() layout.addLayout(buttons) leftbuttons = QtGui.QGridLayout() buttons.addLayout(leftbuttons, 0, 0, QtCore.Qt.AlignLeft) rightbuttons = QtGui.QGridLayout() buttons.addLayout(rightbuttons, 0, 1, QtCore.Qt.AlignRight) copy = QDockPushButton('Copy &Message', self) copy.setToolTip('Copy selected message to clipboard') copy.setFixedWidth(125) rightbuttons.addWidget(copy, 0, 0) self.connect(copy, QtCore.SIGNAL('clicked()'), self.copyMessage) copyAll = QDockPushButton('Copy &All', self) copyAll.setToolTip('Copy all messages to clipboard (Can be a lot)') copyAll.setFixedWidth(125) rightbuttons.addWidget(copyAll, 0, 1) self.connect(copyAll, QtCore.SIGNAL('clicked()'), self.copyAll) self.msg_box = None self.itemQueue = [] self.resize(700, 400)
def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) core.debug.DebugPrint.getInstance().set_stream(debugStream(self.write)) self.setWindowTitle('VisTrails Messages') layout = QtGui.QVBoxLayout() self.setLayout(layout) # top message filter buttons filterHolder = QtGui.QGridLayout() layout.addLayout(filterHolder) filter = QtGui.QGridLayout() filterHolder.addLayout(filter, 0, 0, QtCore.Qt.AlignLeft) filterLabel = QtGui.QLabel('Filter:') filterLabel.setFixedWidth(40) filter.addWidget(filterLabel, 0, 0) self.infoFilter = QtGui.QCheckBox('Info', self) self.infoFilter.setCheckable(True) self.infoFilter.setChecked(True) self.infoFilter.setStyleSheet( 'color:' + CurrentTheme.DEBUG_INFO_COLOR.name() + ';background-color:' + CurrentTheme.DEBUG_FILTER_BACKGROUND_COLOR.name()) self.connect(self.infoFilter, QtCore.SIGNAL('stateChanged(int)'), self.toggleInfo) filter.addWidget(self.infoFilter, 0, 1) self.warningFilter = QtGui.QCheckBox('Warning', self) self.warningFilter.setCheckable(True) self.warningFilter.setChecked(True) self.warningFilter.setStyleSheet( 'color:' + CurrentTheme.DEBUG_WARNING_COLOR.name() + ';background-color:' + CurrentTheme.DEBUG_FILTER_BACKGROUND_COLOR.name()) self.connect(self.warningFilter, QtCore.SIGNAL('stateChanged(int)'), self.toggleWarning) filter.addWidget(self.warningFilter, 0, 2) self.criticalFilter = QtGui.QCheckBox('Critical', self) self.criticalFilter.setCheckable(True) self.criticalFilter.setChecked(True) self.criticalFilter.setStyleSheet( 'color:' + CurrentTheme.DEBUG_CRITICAL_COLOR.name() + ';background-color:' + CurrentTheme.DEBUG_FILTER_BACKGROUND_COLOR.name()) self.connect(self.criticalFilter, QtCore.SIGNAL('stateChanged(int)'), self.toggleCritical) filter.addWidget(self.criticalFilter, 0, 3) # message list self.list = QtGui.QListWidget() self.connect( self.list, QtCore.SIGNAL( 'currentItemChanged(QListWidgetItem *, QListWidgetItem *)'), self.showMessage) layout.addWidget(self.list) # message details field self.text = QtGui.QTextEdit() self.text.setReadOnly(True) self.text.hide() layout.addWidget(self.text) # bottom buttons buttons = QtGui.QGridLayout() layout.addLayout(buttons) leftbuttons = QtGui.QGridLayout() buttons.addLayout(leftbuttons, 0, 0, QtCore.Qt.AlignLeft) rightbuttons = QtGui.QGridLayout() buttons.addLayout(rightbuttons, 0, 1, QtCore.Qt.AlignRight) copy = QDockPushButton('Copy &Message', self) copy.setToolTip('Copy selected message to clipboard') copy.setFixedWidth(125) rightbuttons.addWidget(copy, 0, 0) self.connect(copy, QtCore.SIGNAL('clicked()'), self.copyMessage) copyAll = QDockPushButton('Copy &All', self) copyAll.setToolTip('Copy all messages to clipboard (Can be a lot)') copyAll.setFixedWidth(125) rightbuttons.addWidget(copyAll, 0, 1) self.connect(copyAll, QtCore.SIGNAL('clicked()'), self.copyAll) self.msg_box = None self.itemQueue = [] self.resize(700, 400)
class GraphicsMethodConfigurationWidget(QtGui.QWidget): def __init__(self, module, controller, parent=None, show_buttons=True): QtGui.QWidget.__init__(self, parent) self.module = module self.module_descriptor = self.module.module_descriptor.module self.controller = controller self.show_buttons = show_buttons self.layout = QtGui.QVBoxLayout() self.layout.setSpacing(3) self.layout.setMargin(0) self.fun_map = {} self.populate_fun_map() self.gmName = self.getValueFromFunction("graphicsMethodName") if self.gmName is None: self.gmName = self.module_descriptor().graphics_method_name self.mapAttributesToFunctions() self.tabWidget = QtGui.QTabWidget(self) self.tabWidget.setTabPosition(QtGui.QTabWidget.North) self.tabWidget.setDocumentMode(True) self.gmEditor = self.createEditor(self, self.gmName) self.tabWidget.insertTab(0,self.gmEditor, "Properties") self.wrldCoordEditor = self.tabWidget.widget(1) self.layout.addWidget(self.tabWidget) self.setupEditors() #default gmName can't be changed if str(self.gmName) == "default": self.gmEditor.setEnabled(False) self.wrldCoordEditor.setEnabled(False) if show_buttons: self.buttonLayout = QtGui.QHBoxLayout() self.buttonLayout.setMargin(5) self.saveButton = QDockPushButton('&Save', self) self.saveButton.setFixedWidth(100) self.saveButton.setEnabled(True) self.buttonLayout.addWidget(self.saveButton) self.resetButton = QDockPushButton('&Reset', self) self.resetButton.setFixedWidth(100) self.resetButton.setEnabled(True) self.buttonLayout.addWidget(self.resetButton) self.layout.addLayout(self.buttonLayout) self.connect(self.saveButton, QtCore.SIGNAL('clicked(bool)'), self.saveTriggered) self.connect(self.resetButton, QtCore.SIGNAL('clicked(bool)'), self.resetTriggered) self.setLayout(self.layout) self.tabWidget.setCurrentIndex(0) def createEditor(self, parent, gmName): plot_type = self.module.module_descriptor.module().plot_type if plot_type == "Boxfill": return QBoxfillEditor(self.tabWidget, gmName) elif plot_type == "Isofill": return QIsofillEditor(self.tabWidget, gmName) elif plot_type == "Isoline": return QIsolineEditor(self.tabWidget, gmName) elif plot_type == "Meshfill": return QMeshfillEditor(self.tabWidget, gmName) elif plot_type == "Outfill": return QOutfillEditor(self.tabWidget, gmName) elif plot_type == "Outline": return QOutlineEditor(self.tabWidget, gmName) elif plot_type == "Scatter": return QScatterEditor(self.tabWidget, gmName) elif plot_type == "Taylordiagram": return QTaylorDiagramEditor(self.tabWidget, gmName) elif plot_type == "Vector": return QVectorEditor(self.tabWidget, gmName) elif plot_type == "XvsY": return Q1DPlotEditor(self.tabWidget, gmName, type="xvsy") elif plot_type == "Xyvsy": return Q1DPlotEditor(self.tabWidget, gmName, type="xyvsy") elif plot_type == "Yxvsx": return Q1DPlotEditor(self.tabWidget, gmName, type="yxvsx") def setupEditors(self): gm = InstanceObject(**self.attributes) self.gmEditor.initValues(gm) #set continent self.continents = self.getValueFromFunction('continents') if self.continents: self.gmEditor.continents.setCurrentIndex(self.continents-1) #set aspect ratio self.ratio = self.getValueFromFunction('ratio') if self.ratio is None or self.ratio == 'autot': self.gmEditor.aspectAuto.setCheckState(Qt.Checked) else: #if the ratio cannot cast to float, check auto in gui try: self.gmEditor.aspectRatio.setText(str(float(self.ratio))) self.gmEditor.aspectAuto.setCheckState(Qt.Unchecked) except ValueError: self.gmEditor.aspectAuto.setCheckState(Qt.Checked) def getValueFromFunction(self, fun): if fun in self.fun_map: fid = self.fun_map[fun] f = self.module.functions[fid] try: value = f.params[0].value() except: value = ast.literal_eval(f.params[0].strValue) return value else: return None def populate_fun_map(self): self.fun_map = {} for i in xrange(self.module.getNumFunctions()): self.fun_map[self.module.functions[i].name] = i def mapAttributesToFunctions(self): self.attributes = {} default = self.module_descriptor() default.set_default_values(self.gmName) for name in default.gm_attributes: self.attributes[name] = getattr(default, name) for fun in self.fun_map: if fun in self.module_descriptor.gm_attributes: self.attributes[fun] = self.getValueFromFunction(fun) def updateVistrail(self): functions = [] gm = InstanceObject(**self.attributes) self.gmEditor.applyChanges(gm) pipeline = self.controller.vistrail.getPipeline(self.controller.current_version) # maybe this module was just added by the user in the gui and it was not # added to the pipeline yet. So we need to add it before updating the # functions action1 = None if self.module.id not in pipeline.modules: ops = [('add', self.module)] action1 = core.db.action.create_action(ops) self.controller.add_new_action(action1) self.controller.perform_action(action1) for attr in self.attributes: newval = getattr(gm,attr) if newval != self.attributes[attr]: functions.append((attr,[str(getattr(gm,attr))])) self.attributes[attr] = newval #continents gui_continent = self.gmEditor.continents.currentIndex() + 1 if self.continents is None: func_obj = self.controller.create_function(self.module, 'continents', [str(gui_continent)]) action1 = self.controller.add_function_action(self.module, func_obj) self.continents = gui_continent elif gui_continent != self.continents: functions.append(('continents',[str(gui_continent)])) self.continents = gui_continent # aspect ratio gui_ratio = self.gmEditor.getAspectRatio() if self.ratio is None: func_obj = self.controller.create_function(self.module, 'ratio', [str(gui_ratio)]) action1 = self.controller.add_function_action(self.module, func_obj) self.ratio = gui_ratio elif gui_ratio != self.ratio: functions.append(('ratio', [str(gui_ratio)])) self.ratio = gui_ratio action = self.controller.update_functions(self.module, functions) if action is None: action = action1 return (action, True) def checkForChanges(self): gm = InstanceObject(**self.attributes) self.gmEditor.applyChanges(gm) changed = False for attr in self.attributes: if getattr(gm,attr) != self.attributes[attr]: if str(getattr(gm,attr)) != str(self.attributes[attr]): changed = True break #check if continents or ratios changed if not changed: if self.continents is None: if self.gmEditor.continents.currentIndex() != 0: changed = True elif self.continents != self.gmEditor.continents.currentIndex()+1: changed = True if self.ratio is None: if self.gmEditor.getAspectRatio() != 'autot': changed = True elif self.ratio != self.gmEditor.getAspectRatio(): changed = True return changed def saveTriggered(self, checked = False): """ saveTriggered(checked: bool) -> None Update vistrail controller and module when the user click Ok """ (action, res) = self.updateVistrail() if res: self.emit(QtCore.SIGNAL('doneConfigure'), self.module.id) self.emit(QtCore.SIGNAL('plotDoneConfigure'), action) def resetTriggered(self): self.setupEditors() self.state_changed = False self.emit(QtCore.SIGNAL("stateChanged")) def askToSaveChanges(self): if self.checkForChanges(): message = ('Configuration panel contains unsaved changes. ' 'Do you want to save changes before proceeding?' ) res = show_question('VisTrails', message, buttons = [SAVE_BUTTON, DISCARD_BUTTON]) if res == SAVE_BUTTON: self.saveTriggered() return True else: self.resetTriggered() return False
class AliasesPlotWidget(QtGui.QWidget): def __init__(self, controller, version, plot_obj, parent=None): QtGui.QWidget.__init__(self, parent) self.proj_controller = controller self.controller = controller.vt_controller self.version = version self.plot = plot_obj self.state_changed = False self.plot_widget = None self.buttonLayout = QtGui.QHBoxLayout() self.buttonLayout.setMargin(5) self.saveButton = QDockPushButton('&Save', self) self.saveButton.setFixedWidth(100) self.saveButton.setEnabled(True) self.buttonLayout.addWidget(self.saveButton) self.resetButton = QDockPushButton('&Reset', self) self.resetButton.setFixedWidth(100) self.resetButton.setEnabled(True) self.buttonLayout.addWidget(self.resetButton) layout = QtGui.QVBoxLayout() self.setLayout(layout) self.alias_widgets = {} self.updateWidgets(plot_obj) layout.addLayout(self.buttonLayout) self.connect(self.saveButton, QtCore.SIGNAL('clicked(bool)'), self.saveTriggered) self.connect(self.resetButton, QtCore.SIGNAL('clicked(bool)'), self.resetTriggered) def updateWidgets(self, plot_obj=None): self.plot = plot_obj if self.plot_widget is not None: self.layout().removeWidget(self.plot_widget) self.plot_widget.deleteLater() self.plot_widget = None if self.plot: pipeline = self.controller.vistrail.getPipeline(self.version) self.plot_widget = self.loadWidget(pipeline) self.layout().insertWidget(0, self.plot_widget) self.adjustSize() def updateVistrail(self): aliases = {} pipeline = self.controller.vistrail.getPipeline(self.version) for name in pipeline.aliases: aliases[name] = pipeline.get_alias_str_value(name) for a, w in self.alias_widgets.iteritems(): aliases[a] = w.contents() print a, aliases[a] action = self.applyChanges(pipeline, aliases) return action def applyChanges(self, pipeline, aliases): print " @@ Pipeline aliases: ", str(pipeline.aliases) self.plot.addMergedAliases(aliases, pipeline) action = self.plot.addParameterChangesFromAliasesAction( pipeline, self.controller, self.controller.vistrail, self.version, aliases) return action def saveTriggered(self, checked): action = self.updateVistrail() self.emit(QtCore.SIGNAL('plotDoneConfigure'), action) def resetTriggered(self, checked): self.updateWidgets(self.plot) self.emit(QtCore.SIGNAL("stateChanged")) def loadWidget(self, pipeline): from PyQt4 import QtGui aliases = pipeline.aliases widget = QtGui.QWidget() layout = QtGui.QVBoxLayout() hidden_aliases = self.plot.computeHiddenAliases() for name, (type, oId, parentType, parentId, mId) in aliases.iteritems(): if name not in hidden_aliases: p = pipeline.db_get_object(type, oId) if p.identifier == '': idn = 'edu.utah.sci.vistrails.basic' else: idn = p.identifier reg = get_module_registry() p_module = reg.get_module_by_name(idn, p.type, p.namespace) if p_module is not None: widget_type = get_widget_class(p_module) else: widget_type = StandardConstantWidget p_widget = widget_type(p, None) a_layout = QtGui.QHBoxLayout() label = QtGui.QLabel(name) a_layout.addWidget(label) a_layout.addWidget(p_widget) layout.addLayout(a_layout) self.alias_widgets[name] = p_widget widget.setLayout(layout) return widget
class GraphicsMethodConfigurationWidget(QtGui.QWidget): def __init__(self, module, controller, parent=None, show_buttons=True): QtGui.QWidget.__init__(self, parent) self.module = module self.module_descriptor = self.module.module_descriptor.module self.controller = controller self.show_buttons = show_buttons self.layout = QtGui.QVBoxLayout() self.layout.setSpacing(3) self.layout.setMargin(0) self.fun_map = {} self.populate_fun_map() self.gmName = self.getValueFromFunction("graphicsMethodName") if self.gmName is None: self.gmName = self.module_descriptor().graphics_method_name self.mapAttributesToFunctions() self.tabWidget = QtGui.QTabWidget(self) self.tabWidget.setTabPosition(QtGui.QTabWidget.North) self.tabWidget.setDocumentMode(True) self.gmEditor = self.createEditor(self, self.gmName) self.tabWidget.insertTab(0,self.gmEditor, "Properties") self.wrldCoordEditor = self.tabWidget.widget(1) self.layout.addWidget(self.tabWidget) self.setupEditors() #default gmName can't be changed if str(self.gmName) == "default": self.gmEditor.setEnabled(False) self.wrldCoordEditor.setEnabled(False) if show_buttons: self.buttonLayout = QtGui.QHBoxLayout() self.buttonLayout.setMargin(5) self.saveButton = QDockPushButton('&Save', self) self.saveButton.setFixedWidth(100) self.saveButton.setEnabled(True) self.buttonLayout.addWidget(self.saveButton) self.resetButton = QDockPushButton('&Reset', self) self.resetButton.setFixedWidth(100) self.resetButton.setEnabled(True) self.buttonLayout.addWidget(self.resetButton) self.layout.addLayout(self.buttonLayout) self.connect(self.saveButton, QtCore.SIGNAL('clicked(bool)'), self.saveTriggered) self.connect(self.resetButton, QtCore.SIGNAL('clicked(bool)'), self.resetTriggered) self.setLayout(self.layout) self.tabWidget.setCurrentIndex(0) def createEditor(self, parent, gmName): plot_type = self.module.module_descriptor.module().plot_type if plot_type == "Boxfill": return QBoxfillEditor(self.tabWidget, gmName) elif plot_type == "Isofill": return QIsofillEditor(self.tabWidget, gmName) elif plot_type == "Isoline": return QIsolineEditor(self.tabWidget, gmName) elif plot_type == "Meshfill": return QMeshfillEditor(self.tabWidget, gmName) elif plot_type == "Outfill": return QOutfillEditor(self.tabWidget, gmName) elif plot_type == "Outline": return QOutlineEditor(self.tabWidget, gmName) elif plot_type == "Scatter": return QScatterEditor(self.tabWidget, gmName) elif plot_type == "Taylordiagram": return QTaylorDiagramEditor(self.tabWidget, gmName) elif plot_type == "Vector": return QVectorEditor(self.tabWidget, gmName) elif plot_type == "XvsY": return Q1DPlotEditor(self.tabWidget, gmName, type="xvsy") elif plot_type == "Xyvsy": return Q1DPlotEditor(self.tabWidget, gmName, type="xyvsy") elif plot_type == "Yxvsx": return Q1DPlotEditor(self.tabWidget, gmName, type="yxvsx") def setupEditors(self): gm = InstanceObject(**self.attributes) self.gmEditor.initValues(gm) #set continent self.continents = self.getValueFromFunction('continents') if self.continents: self.gmEditor.continents.setCurrentIndex(self.continents-1) #set aspect ratio self.ratio = self.getValueFromFunction('ratio') #taylor diagram does not have aspectAuto if hasattr(self.gmEditor, 'aspectAuto'): if self.ratio is None or self.ratio == 'autot': self.gmEditor.aspectAuto.setCheckState(Qt.Checked) else: #if the ratio cannot cast to float, check auto in gui try: self.gmEditor.aspectRatio.setText(str(float(self.ratio))) self.gmEditor.aspectAuto.setCheckState(Qt.Unchecked) except ValueError: self.gmEditor.aspectAuto.setCheckState(Qt.Checked) def getValueFromFunction(self, fun): if fun in self.fun_map: fid = self.fun_map[fun] f = self.module.functions[fid] try: if fun == "skillColor": value = int(f.params[0].strValue) else: value = f.params[0].value() if fun == 'Marker': value = pickle.loads(value) except Exception, e: if fun == "skillColor": #if skillColor failed to parse as int, it should be string from init import get_canvas value = get_canvas().match_color(f.params[0].strValue) else: value = ast.literal_eval(f.params[0].strValue) return value else: