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 __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 attributeEditor(self,label,selFunc,modFunc,addFunc,delFunc): fax = QtGui.QGroupBox(label) lax = QtGui.QVBoxLayout() fax.setLayout(lax) fa1 = QtGui.QFrame() fa1l=QtGui.QHBoxLayout() fa1.setLayout(fa1l) lax.addWidget(fa1) p = QtGui.QComboBox() self.connect(p,QtCore.SIGNAL('currentIndexChanged(const QString&)'),selFunc) #self.connect(p,QtCore.SIGNAL('activated(int)'),self.selAxAttribute) fa1l.addWidget(p) attName = QtGui.QLineEdit() self.connect(attName,QtCore.SIGNAL("textEdited(const QString&)"),self.modifiedOn) fa1l.addWidget(attName) b = QDockPushButton("Modify") b.setFocusPolicy(QtCore.Qt.NoFocus) fa1l.addWidget(b) self.connect(b,QtCore.SIGNAL("clicked()"),modFunc) fa2=QtGui.QFrame() fa2l=QtGui.QHBoxLayout() fa2.setLayout(fa2l) lax.addWidget(fa2) newAttName = QtGui.QLineEdit() fa2l.addWidget(newAttName) b = QDockPushButton("Create Attribute") b.setFocusPolicy(QtCore.Qt.NoFocus) fa2l.addWidget(b) self.connect(b,QtCore.SIGNAL("clicked()"),addFunc) b = QDockPushButton("Delete Attribute") b.setFocusPolicy(QtCore.Qt.NoFocus) fa2l.addWidget(b) self.connect(b,QtCore.SIGNAL("clicked()"),delFunc) return fax,p,attName,newAttName
def __init__(self, module, controller, parent=None, show_buttons=True): QtGui.QWidget.__init__(self, parent) self.module = module self.module_instance = 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_instance.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) if self.wrldCoordEditor: 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 __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 create_remove_button(self): widget = QWidget() self.btn_del_var = QDockPushButton("Remove") self.btn_del_var.setEnabled(False) btn_layout = QHBoxLayout() btn_layout.setSpacing(3) btn_layout.setMargin(0) btn_layout.addWidget(self.btn_del_var) btn_layout.addStretch() widget.setLayout(btn_layout) self.connect(self.btn_del_var, SIGNAL('clicked(bool)'), self.delete_clicked) return widget
def __init__(self, parent=None): super(PlotSource, self).__init__(parent) #self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) self.setWindowTitle("Visualization Source") #self.main_widget = QtGui.QWidget() self.btn_copy_to_clipboard = QDockPushButton("Copy to clipboard") self.btn_save_to_file = QDockPushButton("Save to file") btnlayout = QtGui.QHBoxLayout() btnlayout.addStretch() btnlayout.addWidget(self.btn_copy_to_clipboard) btnlayout.addWidget(self.btn_save_to_file) self.tabWidget = QtGui.QTabWidget() self.tabWidget.setTabsClosable(True) self.tabWidget.setDocumentMode(True) layout = QtGui.QVBoxLayout() layout.addWidget(self.tabWidget) layout.addLayout(btnlayout) self.setLayout(layout) # self.main_widget.setLayout(layout) # self.setWidget(self.main_widget) self.btn_copy_to_clipboard.clicked.connect(self.copyToClipboard) self.btn_save_to_file.clicked.connect(self.saveToFile) self.tabWidget.tabCloseRequested.connect(self.closeTab)
def create_remove_button(self): widget = QWidget() self.btn_del_var = QDockPushButton("Remove") self.btn_del_var.setEnabled(False) btn_layout = QHBoxLayout() btn_layout.setSpacing(3) btn_layout.setMargin(0) btn_layout.addWidget(self.btn_del_var) btn_layout.addStretch() widget.setLayout(btn_layout) self.connect(self.btn_del_var, SIGNAL("clicked(bool)"), self.delete_clicked) return widget
class PVGenericCellConfigurationWidget(PVClimateConfigurationWidget): """ PVGenericCellConfigurationWidget ... """ def __init__(self, module, controller, parent=None): """ PVGenericCellConfigurationWidget(module: Module, controller: VistrailController, parent: QWidget) -> DemoDataConfigurationWidget Setup the dialog ... """ self.cellAddress = "A1" self.sliceOffset = 0 self.representation_modules = [] self.controller = controller self.moduleId = module.id # self.init_representations() PVClimateConfigurationWidget.__init__(self, module, controller, "PVClimate Cell Configuration", parent) def init(self, pipeline=None, version=None): if pipeline is None: # assume current_pipeline when we're not in uv-cdat pipeline = self.controller.current_pipeline version = self.controller.current_version self.version = version self.init_representations(pipeline) self.createLayout() def getParameters(self, module): pass def updateVistrail(self): print "controller.current_version", self.controller.current_version functions = [] action = None functions.append(("sliceOffset", [self.sliceOffset])) action = self.controller.update_functions(self.module, functions) return action def init_representations(self, pipeline): # pipeline = self.controller.current_pipeline representation_ids = pipeline.get_inputPort_modules(self.moduleId, "representation") for i, rep_id in enumerate(representation_ids): rep_module = pipeline.get_module_by_id(rep_id) self.representation_modules.append(rep_module) def create_remove_button(self): widget = QWidget() self.btn_del_var = QDockPushButton("Remove") self.btn_del_var.setEnabled(False) btn_layout = QHBoxLayout() btn_layout.setSpacing(3) btn_layout.setMargin(0) btn_layout.addWidget(self.btn_del_var) btn_layout.addStretch() widget.setLayout(btn_layout) self.connect(self.btn_del_var, SIGNAL("clicked(bool)"), self.delete_clicked) return widget def delete_clicked(self): if self.representations_table.selectedItems(): item = self.representations_table.selectedItems()[0] row = item.row() self.representations_table.removeRow(row) pv_generic_cell = self.get_workflow_module(self.moduleId) pv_generic_cell.removeRepresentation(row) # self.controller.execute_current_workflow() def create_representation_table(self): self.representations_table = PVRepresentationPlotTableWidget(self) self.representations_table.setRowCount(len(self.representation_modules)) self.connect(self.representations_table, SIGNAL("itemSelectionChanged()"), self.itemSelectionChanged) for i, rep_module in enumerate(self.representation_modules): # call static method to name to display display_name = rep_module.module_descriptor.module.name() item = PVRepresentationTableWidgetItem(rep_module, display_name) item.setText(display_name) self.representations_table.setItem(i, 0, item) rep_config_widget = rep_module.module_descriptor.module.configuration_widget(self, rep_module) self.connect(self, SIGNAL("okTriggered()"), rep_config_widget.okTriggered) self.config_panel_layout.addWidget(rep_config_widget) return self.representations_table def create_config_panel(self): self.config_panel = QWidget() self.config_panel_layout = QStackedLayout() self.config_panel.setLayout(self.config_panel_layout) return self.config_panel def createLayout(self): """ createlayout() -> None Configure sections """ super(PVGenericCellConfigurationWidget, self).createLayout() representations_panel = QWidget() self.layout().addWidget(representations_panel) layout = QVBoxLayout() representations_panel.setLayout(layout) self.create_config_panel() self.create_representation_table() layout.addWidget(self.representations_table) layout.addWidget(self.create_remove_button()) layout.addWidget(self.config_panel) self.setDefaults() def itemSelectionChanged(self): if self.representations_table.selectedItems(): self.btn_del_var.setEnabled(True) item = self.representations_table.selectedItems()[0] self.config_panel.layout().setCurrentIndex(item.row()) else: self.btn_del_var.setEnabled(False) def setDefaults(self): moduleInstance = self.module.module_descriptor.module() # self.sliceOffset = moduleInstance.getSliceOffset(); # self.slice_offset_value.setText(str(self.sliceOffset)) def updateController(self, controller=None): parmRecList = [] parmRecList.append(("slice_offset", [self.sliceOffset])) self.persistParameterList(parmRecList) self.stateChanged(False) def okTriggered(self, checked=False): """ okTriggered(checked: bool) -> None Update vistrail controller (if neccesssary) then close the widget """ self.emit(SIGNAL("okTriggered()")) self.controller.execute_current_workflow() def startOver(self): self.setDefaults() def get_workflow_module(self, module_id): vistrails_interpreter = get_default_interpreter() object_map = vistrails_interpreter.find_persistent_entities(self.controller.current_pipeline)[0] module_instance = object_map.get(module_id) return module_instance
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)
def __init__(self, parent=None, mode="add"): super(VariableProperties, self).__init__(parent) self.setWindowTitle("Load Variable") self.setMinimumHeight(400) self.roi = [-180.0, -90.0, 180.0, 90.0] self.ask = QtGui.QInputDialog() self.ask.setWindowModality(QtCore.Qt.WindowModal) self.ask.setLabelText( "This variable already exists!\nPlease change its name below and click ok to replace it.\n" ) self.mode = mode self.axisListHolder = None #self.setFloating(True) v = QtGui.QVBoxLayout() if mode == "add": self.label = QtGui.QLabel("Load From") else: self.label = QtGui.QLabel("Edit Variable") v.addWidget(self.label) P = parent.root.size() self.resize(QtCore.QSize(P.width() * .8, P.height() * .9)) self.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) self.originTabWidget = QtGui.QTabWidget(self) #self.connect(self.originTabWidget,QtCore.SIGNAL("currentChanged(int)"),self.tabHasChanged) sp = QtGui.QSplitter(QtCore.Qt.Vertical) #sc=QtGui.QScrollArea() #sc.setWidget(self.originTabWidget) #sc.setWidgetResizable(True) sp.addWidget(self.originTabWidget) self.dims = QtGui.QFrame() self.dimsLayout = QtGui.QVBoxLayout() self.dims.setLayout(self.dimsLayout) sp.addWidget(self.dims) v.addWidget(sp) h = QtGui.QHBoxLayout() self.selectRoiButton = QDockPushButton( 'Select Region Of Interest (ROI)') h.addWidget(self.selectRoiButton) s = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred) h.addItem(s) self.btnDefine = QDockPushButton("Load") h.addWidget(self.btnDefine) self.btnDefineClose = QDockPushButton("Load and Close") h.addWidget(self.btnDefineClose) self.btnDefineAs = QDockPushButton("Load As") h.addWidget(self.btnDefineAs) self.btnApplyEdits = QDockPushButton("Apply") self.btnApplyEdits.setVisible(False) h.addWidget(self.btnApplyEdits) self.btnSaveEditsAs = QDockPushButton("Save As") self.btnSaveEditsAs.setVisible(False) h.addWidget(self.btnSaveEditsAs) self.btnCancel = QDockPushButton("Close") # defaults? self.btnDefine.setDefault(True) self.btnDefineClose.setDefault(False) self.btnDefineAs.setDefault(False) self.selectRoiButton.setDefault(False) # Disabling at first self.btnDefine.setEnabled(False) self.btnDefineClose.setEnabled(False) self.btnDefineAs.setEnabled(False) self.selectRoiButton.setEnabled(False) h.addWidget(self.btnCancel) v.addLayout(h) self.layout = v #f=QtGui.QFrame() #f.setLayout(v) #self.setWidget(f) self.setLayout(v) self.parent = parent self.root = parent.root self.varNameInFile = None #store the name of the variable when loaded from file self.createFileTab() self.createESGFTab() self.createOpenDAPTab() self.createEditTab() self.createInfoTab() for i in range(self.originTabWidget.count()): if self.originTabWidget.tabText(i) == "Edit": self.originTabWidget.setTabEnabled(i, False) self.connectSignals() sp.setStretchFactor(0, 2) self.cdmsFile = None self.updatingFile = False self.roiSelector = ROISelectionDialog(self.parent) self.roiSelector.setWindowFlags(self.roiSelector.windowFlags() | Qt.WindowStaysOnTopHint) self.connect(self.roiSelector, QtCore.SIGNAL('doneConfigure()'), self.setRoi) if self.roi: self.roiSelector.setROI(self.roi)
class VariableProperties(QtGui.QDialog): FILTER = "CDAT data (*.cdms *.ctl *.dic *.hdf *.nc *.xml)" FILETYPE = {'CDAT': ['cdms', 'ctl', 'dic', 'hdf', 'nc', 'xml']} def __init__(self, parent=None, mode="add"): super(VariableProperties, self).__init__(parent) self.setWindowTitle("Load Variable") self.setMinimumHeight(400) self.roi = [-180.0, -90.0, 180.0, 90.0] self.ask = QtGui.QInputDialog() self.ask.setWindowModality(QtCore.Qt.WindowModal) self.ask.setLabelText( "This variable already exists!\nPlease change its name below and click ok to replace it.\n" ) self.mode = mode self.axisListHolder = None #self.setFloating(True) v = QtGui.QVBoxLayout() if mode == "add": self.label = QtGui.QLabel("Load From") else: self.label = QtGui.QLabel("Edit Variable") v.addWidget(self.label) P = parent.root.size() self.resize(QtCore.QSize(P.width() * .8, P.height() * .9)) self.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) self.originTabWidget = QtGui.QTabWidget(self) #self.connect(self.originTabWidget,QtCore.SIGNAL("currentChanged(int)"),self.tabHasChanged) sp = QtGui.QSplitter(QtCore.Qt.Vertical) #sc=QtGui.QScrollArea() #sc.setWidget(self.originTabWidget) #sc.setWidgetResizable(True) sp.addWidget(self.originTabWidget) self.dims = QtGui.QFrame() self.dimsLayout = QtGui.QVBoxLayout() self.dims.setLayout(self.dimsLayout) sp.addWidget(self.dims) v.addWidget(sp) h = QtGui.QHBoxLayout() self.selectRoiButton = QDockPushButton( 'Select Region Of Interest (ROI)') h.addWidget(self.selectRoiButton) s = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred) h.addItem(s) self.btnDefine = QDockPushButton("Load") h.addWidget(self.btnDefine) self.btnDefineClose = QDockPushButton("Load and Close") h.addWidget(self.btnDefineClose) self.btnDefineAs = QDockPushButton("Load As") h.addWidget(self.btnDefineAs) self.btnApplyEdits = QDockPushButton("Apply") self.btnApplyEdits.setVisible(False) h.addWidget(self.btnApplyEdits) self.btnSaveEditsAs = QDockPushButton("Save As") self.btnSaveEditsAs.setVisible(False) h.addWidget(self.btnSaveEditsAs) self.btnCancel = QDockPushButton("Close") # defaults? self.btnDefine.setDefault(True) self.btnDefineClose.setDefault(False) self.btnDefineAs.setDefault(False) self.selectRoiButton.setDefault(False) # Disabling at first self.btnDefine.setEnabled(False) self.btnDefineClose.setEnabled(False) self.btnDefineAs.setEnabled(False) self.selectRoiButton.setEnabled(False) h.addWidget(self.btnCancel) v.addLayout(h) self.layout = v #f=QtGui.QFrame() #f.setLayout(v) #self.setWidget(f) self.setLayout(v) self.parent = parent self.root = parent.root self.varNameInFile = None #store the name of the variable when loaded from file self.createFileTab() self.createESGFTab() self.createOpenDAPTab() self.createEditTab() self.createInfoTab() for i in range(self.originTabWidget.count()): if self.originTabWidget.tabText(i) == "Edit": self.originTabWidget.setTabEnabled(i, False) self.connectSignals() sp.setStretchFactor(0, 2) self.cdmsFile = None self.updatingFile = False self.roiSelector = ROISelectionDialog(self.parent) self.roiSelector.setWindowFlags(self.roiSelector.windowFlags() | Qt.WindowStaysOnTopHint) self.connect(self.roiSelector, QtCore.SIGNAL('doneConfigure()'), self.setRoi) if self.roi: self.roiSelector.setROI(self.roi) ## @classmethod ## def instance(klass): ## if not hasattr(klass, '_instance'): ## klass._instance = klass() ## return klass._instance def closeEvent(self, event): super(VariableProperties, self).closeEvent(event) self.btnDefine.setVisible(True) self.btnDefineAs.setVisible(True) self.btnDefineClose.setVisible(True) self.btnApplyEdits.setVisible(False) self.btnSaveEditsAs.setVisible(False) def tabHasChanged(self, index): if (index == 1) or (index == 2): self.root.varProp.btnDefine.setEnabled(False) self.root.varProp.btnDefineClose.setEnabled(False) self.root.varProp.btnDefineAs.setEnabled(False) self.root.varProp.selectRoiButton.setEnabled(False) if (index == 2): self.clearDimensionsWidget() elif (index == 3): self.root.varProp.selectRoiButton.setEnabled(True) ## else: ## self.root.varProp.btnDefine.setEnabled(True) ## self.root.varProp.btnDefineClose.setEnabled(True) ## self.root.varProp.btnDefineAs.setEnabled(True) def connectSignals(self): self.btnCancel.clicked.connect(self.close) self.connect(self.ask, QtCore.SIGNAL('accepted()'), self.checkTargetVarName) if self.mode == "add": self.tbOpenFile.clicked.connect(self.openSelectFileDialog) self.connect(self.originTabWidget, QtCore.SIGNAL("currentChanged(int)"), self.tabHasChanged) self.connect(self.fileEdit, QtCore.SIGNAL('returnPressed()'), self.updateFileFromReturnPressed) self.connect(self.historyList, QtCore.SIGNAL('itemClicked(QListWidgetItem *)'), self.selectFromList) self.connect(self.bookmarksList, QtCore.SIGNAL('itemClicked(QListWidgetItem *)'), self.selectFromList) self.connect(self.varCombo, QtCore.SIGNAL('activated(const QString&)'), self.variableSelected) self.connect(self.bookmarksList, QtCore.SIGNAL("droppedInto"), self.droppedBookmark) self.connect(self.root.dockVariable.widget(), QtCore.SIGNAL("setupDefinedVariableAxes"), self.varAddedToDefined) ## Define button self.btnDefine.clicked.connect(self.defineVarClicked) self.btnDefineClose.clicked.connect(self.defineVarCloseClicked) self.btnDefineAs.clicked.connect(self.defineAsVarClicked) self.connect(self, QtCore.SIGNAL('definedVariableEvent'), self.root.dockVariable.widget().addVariable) self.btnApplyEdits.clicked.connect(self.applyEditsClicked) self.btnSaveEditsAs.clicked.connect(self.saveEditsAsClicked) self.selectRoiButton.clicked.connect(self.selectRoi) def checkTargetVarName(self): result = None while result is None: result = self.ask.result() value = self.ask.textValue() if result == 1: # make sure we pressed Ok and not Cancel if str(value) != self.checkAgainst: self.getUpdatedVarCheck(str(value)) else: self.getUpdatedVar(str(value)) def varAddedToDefined(self, var): axisList = axesWidgets.QAxisList(None, var, self) self.axisListHolder = axisList self.updateVarInfo(axisList) def droppedBookmark(self, event): text = str(event.mimeData().text()) self.addBookmark(text) def addBookmark(self, txt): duplicate = False for i in range(self.bookmarksList.count()): it = self.bookmarksList.item(i) if it.text() == txt: duplicate = True break if duplicate is False: self.bookmarksList.addItem(txt) customizeUVCDAT.fileBookmarks.append(txt) def createFileTab(self): #Top Part ## File Select Section v = QtGui.QVBoxLayout() h = QtGui.QHBoxLayout() l = QtGui.QLabel("File") h.addWidget(l) self.fileEdit = QtGui.QLineEdit() h.addWidget(self.fileEdit) self.tbOpenFile = QtGui.QToolButton() self.tbOpenFile.setText('...') self.tbOpenFile.setToolTip('View and select files') h.addWidget(self.tbOpenFile) v.addLayout(h) ## Variable Select part h = QtGui.QHBoxLayout() l = QtGui.QLabel("Variable(s):") l.setSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Preferred) h.addWidget(l) self.varCombo = QtGui.QComboBox() self.varCombo.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed) h.addWidget(self.varCombo) v.addLayout(h) ## Bottom Part h = QtGui.QHBoxLayout() l = QtGui.QLabel("History:") l.setSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Preferred) self.historyList = uvcdatCommons.QDragListWidget(type="history") #self.historyList.setSizePolicy(QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Minimum) self.historyList.setAlternatingRowColors(True) #for i in self.parent.historyList: # self.historyList.addItem(i) h.addWidget(l) h.addWidget(self.historyList) v.addLayout(h) h = QtGui.QHBoxLayout() l = QtGui.QLabel("Bookmarks:") l.setSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Preferred) self.bookmarksList = QBookMarksListWidget(type="bookmarks", dropTypes=["history"]) #self.bookmarksList.setSizePolicy(QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Minimum) self.bookmarksList.setAlternatingRowColors(True) self.bookmarksList.setSortingEnabled(True) for f in customizeUVCDAT.fileBookmarks: self.addBookmark(f) h.addWidget(l) h.addWidget(self.bookmarksList) v.addLayout(h) fileTab = QtGui.QFrame() fileTab.setLayout(v) self.originTabWidget.addTab(fileTab, "File") def createESGFTab(self): ## layout = QtGui.QVBoxLayout() ## self.esgfBrowser = QEsgfBrowser(self) ## layout.addWidget(self.esgfBrowser) try: esgf = QEsgfBrowser(self) #esgf.addGateway(gateway=customizeUVCDAT.defaultEsgfNode) esgf.addGateway( gateway=str(self.root.preferences.host_url.currentText())) except Exception, err: esgf = QtGui.QLabel("No Internet?\nError log: %s" % err) self.originTabWidget.addTab(esgf, "ESGF")
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:
def build_widget(self): name_label = QtGui.QLabel("Name:") self.name_edit = QtGui.QLineEdit() self.connect(self.name_edit, QtCore.SIGNAL('editingFinished()'), self.name_editing_finished) self.name_edit.setMinimumSize(50, 22) type_label = QtGui.QLabel("Type:") self.type_edit = QtGui.QLabel("") # self.type_edit.setReadOnly(True) package_label = QtGui.QLabel("Package:") self.package_edit = QtGui.QLabel("") # self.package_edit.setReadOnly(True) self.configure_button = QDockPushButton("Configure") self.connect(self.configure_button, QtCore.SIGNAL('clicked()'), self.configure) self.doc_button = QDockPushButton("Documentation") self.connect(self.doc_button, QtCore.SIGNAL('clicked()'), self.documentation) layout = QtGui.QVBoxLayout() layout.setMargin(2) layout.setSpacing(4) h_layout = QtGui.QHBoxLayout() h_layout.setMargin(2) h_layout.setSpacing(2) h_layout.setAlignment(QtCore.Qt.AlignLeft) h_layout.addWidget(name_label) h_layout.addWidget(self.name_edit) layout.addLayout(h_layout) h_layout = QtGui.QHBoxLayout() h_layout.setMargin(2) h_layout.setSpacing(2) h_layout.setAlignment(QtCore.Qt.AlignLeft) h_layout.addWidget(type_label) h_layout.addWidget(self.type_edit) h_widget = QtGui.QWidget() h_widget.setLayout(h_layout) h_widget.setSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Preferred) layout.addWidget(h_widget) h_layout = QtGui.QHBoxLayout() h_layout.setMargin(2) h_layout.setSpacing(2) h_layout.setAlignment(QtCore.Qt.AlignLeft) h_layout.addWidget(package_label) h_layout.addWidget(self.package_edit) h_widget = QtGui.QWidget() h_widget.setLayout(h_layout) h_widget.setSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Preferred) layout.addWidget(h_widget) h_layout = QtGui.QHBoxLayout() h_layout.setMargin(2) h_layout.setSpacing(5) h_layout.setAlignment(QtCore.Qt.AlignCenter) h_layout.addWidget(self.configure_button) h_layout.addWidget(self.doc_button) layout.addLayout(h_layout) self.tab_widget = QtGui.QTabWidget() # this causes a crash when undocking the palette in Mac OS X # see https://bugreports.qt-project.org/browse/QTBUG-16851 # self.tab_widget.setDocumentMode(True) self.input_ports_list = PortsList('input') self.tab_widget.addTab(self.input_ports_list, 'Inputs') self.output_ports_list = PortsList('output') self.tab_widget.addTab(self.output_ports_list, 'Outputs') self.ports_lists = [self.input_ports_list, self.output_ports_list] self.annotations = QModuleAnnotationTable() self.tab_widget.addTab(self.annotations, 'Annotations') layout.addWidget(self.tab_widget, 1) layout.setAlignment(QtCore.Qt.AlignTop) self.setLayout(layout) self.setWindowTitle('Module Information')
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, controller=None, parent=None): QtGui.QWidget.__init__(self, parent) self.controller = controller self.versionNumber = -1 vLayout = QtGui.QVBoxLayout() vLayout.setMargin(0) vLayout.setSpacing(5) self.setLayout(vLayout) gLayout = QtGui.QGridLayout() gLayout.setMargin(0) gLayout.setSpacing(5) gLayout.setColumnMinimumWidth(1, 5) gLayout.setRowMinimumHeight(0, 24) gLayout.setRowMinimumHeight(1, 24) gLayout.setRowMinimumHeight(2, 24) gLayout.setRowMinimumHeight(3, 24) vLayout.addLayout(gLayout) #vtVersionLabel = QtGui.QLabel('Workflow:', self) #gLayout.addWidget(vtVersionLabel, 0, 0, 1, 1) #self.vtVersionEdit = QtGui.QLabel('', self) #gLayout.addWidget(self.vtVersionEdit, 0, 2, 1, 1) tagLabel = QtGui.QLabel('Mashup Tag:', self) gLayout.addWidget(tagLabel, 0, 0, 1, 1) editLayout = QtGui.QHBoxLayout() editLayout.setMargin(0) editLayout.setSpacing(2) self.tagEdit = QtGui.QLineEdit() tagLabel.setBuddy(self.tagEdit) editLayout.addWidget(self.tagEdit) self.tagEdit.setEnabled(False) self.tagReset = QtGui.QToolButton(self) self.tagReset.setIcon( QtGui.QIcon(self.style().standardPixmap( QtGui.QStyle.SP_DialogCloseButton))) self.tagReset.setIconSize(QtCore.QSize(12, 12)) self.tagReset.setAutoRaise(True) self.tagReset.setEnabled(False) editLayout.addWidget(self.tagReset) gLayout.addLayout(editLayout, 0, 2, 1, 1) userLabel = QtGui.QLabel('User:'******'', self) gLayout.addWidget(self.userEdit, 1, 2, 1, 1) dateLabel = QtGui.QLabel('Date:', self) gLayout.addWidget(dateLabel, 2, 0, 1, 1) self.dateEdit = QtGui.QLabel('', self) gLayout.addWidget(self.dateEdit, 2, 2, 1, 1) self.btnExport = QDockPushButton("Export...") gLayout.addWidget(self.btnExport, 3, 0, 1, 3, QtCore.Qt.AlignHCenter) vLayout.addStretch() self.connect(self.tagEdit, QtCore.SIGNAL('editingFinished()'), self.tagFinished) self.connect(self.tagEdit, QtCore.SIGNAL('textChanged(QString)'), self.tagChanged) self.connect(self.tagReset, QtCore.SIGNAL('clicked()'), self.tagCleared) self.connect(self.btnExport, QtCore.SIGNAL("clicked()"), self.exportMashupGUI)
class PVGenericCellConfigurationWidget(PVClimateConfigurationWidget): """ PVGenericCellConfigurationWidget ... """ def __init__(self, module, controller, parent=None): """ PVGenericCellConfigurationWidget(module: Module, controller: VistrailController, parent: QWidget) -> DemoDataConfigurationWidget Setup the dialog ... """ self.cellAddress = 'A1' self.sliceOffset = 0 self.representation_modules = [] self.controller = controller self.moduleId = module.id # self.init_representations() PVClimateConfigurationWidget.__init__(self, module, controller, 'PVClimate Cell Configuration', parent) def init(self, pipeline=None, version=None): if pipeline is None: # assume current_pipeline when we're not in uv-cdat pipeline = self.controller.current_pipeline version = self.controller.current_version self.version = version self.init_representations(pipeline) self.createLayout() def getParameters(self, module): pass def updateVistrail(self): print 'controller.current_version', self.controller.current_version functions = [] action = None functions.append(("sliceOffset", [self.sliceOffset])) action = self.controller.update_functions(self.module, functions) return action def init_representations(self, pipeline): # pipeline = self.controller.current_pipeline representation_ids = pipeline.get_inputPort_modules( self.moduleId, 'representation') for i, rep_id in enumerate(representation_ids): rep_module = pipeline.get_module_by_id(rep_id) self.representation_modules.append(rep_module) def create_remove_button(self): widget = QWidget() self.btn_del_var = QDockPushButton("Remove") self.btn_del_var.setEnabled(False) btn_layout = QHBoxLayout() btn_layout.setSpacing(3) btn_layout.setMargin(0) btn_layout.addWidget(self.btn_del_var) btn_layout.addStretch() widget.setLayout(btn_layout) self.connect(self.btn_del_var, SIGNAL('clicked(bool)'), self.delete_clicked) return widget def delete_clicked(self): if self.representations_table.selectedItems(): item = self.representations_table.selectedItems()[0] row = item.row() self.representations_table.removeRow(row) pv_generic_cell = self.get_workflow_module(self.moduleId) pv_generic_cell.removeRepresentation(row) # self.controller.execute_current_workflow() def create_representation_table(self): self.representations_table = PVRepresentationPlotTableWidget(self) self.representations_table.setRowCount(len( self.representation_modules)) self.connect(self.representations_table, SIGNAL('itemSelectionChanged()'), self.itemSelectionChanged) for i, rep_module in enumerate(self.representation_modules): # call static method to name to display display_name = rep_module.module_descriptor.module.name() item = PVRepresentationTableWidgetItem(rep_module, display_name) item.setText(display_name) self.representations_table.setItem(i, 0, item) rep_config_widget = rep_module.module_descriptor.module.configuration_widget( self, rep_module) self.connect(self, SIGNAL('okTriggered()'), rep_config_widget.okTriggered) self.config_panel_layout.addWidget(rep_config_widget) return self.representations_table def create_config_panel(self): self.config_panel = QWidget() self.config_panel_layout = QStackedLayout() self.config_panel.setLayout(self.config_panel_layout) return self.config_panel def createLayout(self): """ createlayout() -> None Configure sections """ super(PVGenericCellConfigurationWidget, self).createLayout() representations_panel = QWidget() self.layout().addWidget(representations_panel) layout = QVBoxLayout() representations_panel.setLayout(layout) self.create_config_panel() self.create_representation_table() layout.addWidget(self.representations_table) layout.addWidget(self.create_remove_button()) layout.addWidget(self.config_panel) self.setDefaults() def itemSelectionChanged(self): if self.representations_table.selectedItems(): self.btn_del_var.setEnabled(True) item = self.representations_table.selectedItems()[0] self.config_panel.layout().setCurrentIndex(item.row()) else: self.btn_del_var.setEnabled(False) def setDefaults(self): moduleInstance = self.module.module_descriptor.module() #self.sliceOffset = moduleInstance.getSliceOffset(); #self.slice_offset_value.setText(str(self.sliceOffset)) def updateController(self, controller=None): parmRecList = [] parmRecList.append(('slice_offset', [self.sliceOffset]), ) self.persistParameterList(parmRecList) self.stateChanged(False) def okTriggered(self, checked=False): """ okTriggered(checked: bool) -> None Update vistrail controller (if neccesssary) then close the widget """ self.emit(SIGNAL('okTriggered()')) self.controller.execute_current_workflow() def startOver(self): self.setDefaults() def get_workflow_module(self, module_id): vistrails_interpreter = get_default_interpreter() object_map = vistrails_interpreter.find_persistent_entities( self.controller.current_pipeline)[0] module_instance = object_map.get(module_id) return module_instance
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 VariableProperties(QtGui.QDialog): FILTER = "CDAT data (*.cdms *.ctl *.dic *.hdf *.nc *.xml)" FILETYPE = {'CDAT': ['cdms', 'ctl', 'dic', 'hdf', 'nc', 'xml']} def __init__(self, parent=None,mode="add"): super(VariableProperties, self).__init__(parent) self.setWindowTitle("Load Variable") self.setMinimumHeight(400) self.roi = [ -180.0, -90.0, 180.0, 90.0 ] self.ask = QtGui.QInputDialog() self.ask.setWindowModality(QtCore.Qt.WindowModal) self.ask.setLabelText("This variable already exists!\nPlease change its name below and click ok to replace it.\n") self.mode=mode self.axisListHolder = None #self.setFloating(True) v=QtGui.QVBoxLayout() if mode=="add": self.label=QtGui.QLabel("Load From") else: self.label=QtGui.QLabel("Edit Variable") v.addWidget(self.label) P=parent.root.size() self.resize(QtCore.QSize(P.width()*.8,P.height()*.9)) self.setSizePolicy(QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Expanding) self.originTabWidget=QtGui.QTabWidget(self) #self.connect(self.originTabWidget,QtCore.SIGNAL("currentChanged(int)"),self.tabHasChanged) sp = QtGui.QSplitter(QtCore.Qt.Vertical) #sc=QtGui.QScrollArea() #sc.setWidget(self.originTabWidget) #sc.setWidgetResizable(True) sp.addWidget(self.originTabWidget) self.dims=QtGui.QFrame() self.dimsLayout=QtGui.QVBoxLayout() self.dims.setLayout( self.dimsLayout ) sp.addWidget(self.dims) v.addWidget(sp) h=QtGui.QHBoxLayout() self.selectRoiButton = QDockPushButton('Select Region Of Interest (ROI)') h.addWidget( self.selectRoiButton ) s=QtGui.QSpacerItem(40,20,QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Preferred) h.addItem(s) self.btnDefine=QDockPushButton("Load") h.addWidget(self.btnDefine) self.btnDefineClose=QDockPushButton("Load and Close") h.addWidget(self.btnDefineClose) self.btnDefineAs=QDockPushButton("Load As") h.addWidget(self.btnDefineAs) self.btnApplyEdits=QDockPushButton("Apply") self.btnApplyEdits.setVisible(False) h.addWidget(self.btnApplyEdits) self.btnCancel=QDockPushButton("Close") # defaults? self.btnDefine.setDefault(False) self.btnDefineClose.setDefault(False) self.btnDefineAs.setDefault(False) self.selectRoiButton.setDefault(False) # Disabling at first self.btnDefine.setEnabled(False) self.btnDefineClose.setEnabled(False) self.btnDefineAs.setEnabled(False) self.selectRoiButton.setEnabled(False) h.addWidget(self.btnCancel) v.addLayout(h) self.layout=v #f=QtGui.QFrame() #f.setLayout(v) #self.setWidget(f) self.setLayout(v) self.parent=parent self.root = parent.root self.varNameInFile = None #store the name of the variable when loaded from file self.createFileTab() self.createESGFTab() self.createOpenDAPTab() self.createEditTab() self.createInfoTab() for i in range(self.originTabWidget.count()): if self.originTabWidget.tabText(i) == "Edit": self.originTabWidget.setTabEnabled(i,False) self.connectSignals() sp.setStretchFactor(0,2) self.cdmsFile = None self.updatingFile = False self.roiSelector = ROISelectionDialog( self.parent ) self.roiSelector.setWindowFlags( self.roiSelector.windowFlags() | Qt.WindowStaysOnTopHint ) self.connect(self.roiSelector, QtCore.SIGNAL('doneConfigure()'), self.setRoi ) if self.roi: self.roiSelector.setROI( self.roi ) ## @classmethod ## def instance(klass): ## if not hasattr(klass, '_instance'): ## klass._instance = klass() ## return klass._instance def closeEvent(self, event): super(VariableProperties, self).closeEvent(event) self.btnDefine.setVisible(True) self.btnDefineAs.setVisible(True) self.btnDefineClose.setVisible(True) self.btnApplyEdits.setVisible(False) def tabHasChanged(self,index): if (index==1) or (index==2): self.root.varProp.btnDefine.setEnabled(False) self.root.varProp.btnDefineClose.setEnabled(False) self.root.varProp.btnDefineAs.setEnabled(False) self.root.varProp.selectRoiButton.setEnabled(False) if (index==2): self.clearDimensionsWidget() elif (index==3): self.root.varProp.selectRoiButton.setEnabled(True) ## else: ## self.root.varProp.btnDefine.setEnabled(True) ## self.root.varProp.btnDefineClose.setEnabled(True) ## self.root.varProp.btnDefineAs.setEnabled(True) def connectSignals(self): self.btnCancel.clicked.connect(self.close) self.connect(self.ask,QtCore.SIGNAL('accepted()'),self.checkTargetVarName) if self.mode=="add": self.tbOpenFile.clicked.connect(self.openSelectFileDialog) self.connect(self.originTabWidget,QtCore.SIGNAL("currentChanged(int)"),self.tabHasChanged) self.connect(self.fileEdit, QtCore.SIGNAL('returnPressed()'), self.updateFileFromReturnPressed) self.connect(self.historyList, QtCore.SIGNAL('itemClicked(QListWidgetItem *)'), self.selectFromList) self.connect(self.bookmarksList, QtCore.SIGNAL('itemClicked(QListWidgetItem *)'), self.selectFromList) self.connect(self.varCombo, QtCore.SIGNAL('currentIndexChanged(const QString&)'), self.variableSelected) self.connect(self.bookmarksList,QtCore.SIGNAL("droppedInto"),self.droppedBookmark) self.connect(self.root.dockVariable.widget(),QtCore.SIGNAL("setupDefinedVariableAxes"),self.varAddedToDefined) ## Define button self.btnDefine.clicked.connect(self.defineVarClicked) self.btnDefineClose.clicked.connect(self.defineVarCloseClicked) self.btnDefineAs.clicked.connect(self.defineAsVarClicked) self.connect(self,QtCore.SIGNAL('definedVariableEvent'),self.root.dockVariable.widget().addVariable) self.btnApplyEdits.clicked.connect(self.applyEditsClicked) self.selectRoiButton.clicked.connect( self.selectRoi ) def checkTargetVarName(self): result = None while result is None: result = self.ask.result() value = self.ask.textValue() if result == 1: # make sure we pressed Ok and not Cancel if str(value)!=self.checkAgainst: self.getUpdatedVarCheck(str(value)) else: self.getUpdatedVar(str(value)) def varAddedToDefined(self,var): axisList = axesWidgets.QAxisList(None,var,self) self.axisListHolder = axisList self.updateVarInfo(axisList) def droppedBookmark(self,event): text = str(event.mimeData().text()) self.addBookmark(text) def addBookmark(self,txt): duplicate=False for i in range(self.bookmarksList.count()): it = self.bookmarksList.item(i) if it.text()==txt: duplicate=True break if duplicate is False: self.bookmarksList.addItem(txt) customizeUVCDAT.fileBookmarks.append(txt) def createFileTab(self): #Top Part ## File Select Section v=QtGui.QVBoxLayout() h=QtGui.QHBoxLayout() l=QtGui.QLabel("File") h.addWidget(l) self.fileEdit=QtGui.QLineEdit() h.addWidget(self.fileEdit) self.tbOpenFile=QtGui.QToolButton() self.tbOpenFile.setText('...') self.tbOpenFile.setToolTip('View and select files') h.addWidget(self.tbOpenFile) v.addLayout(h) ## Variable Select part h=QtGui.QHBoxLayout() l=QtGui.QLabel("Variable(s):") l.setSizePolicy(QtGui.QSizePolicy.Maximum,QtGui.QSizePolicy.Preferred) h.addWidget(l) self.varCombo=QtGui.QComboBox() self.varCombo.setSizePolicy(QtGui.QSizePolicy.Preferred,QtGui.QSizePolicy.Fixed) h.addWidget(self.varCombo) v.addLayout(h) ## Bottom Part h=QtGui.QHBoxLayout() l=QtGui.QLabel("History:") l.setSizePolicy(QtGui.QSizePolicy.Minimum,QtGui.QSizePolicy.Preferred) self.historyList=uvcdatCommons.QDragListWidget(type="history") #self.historyList.setSizePolicy(QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Minimum) self.historyList.setAlternatingRowColors(True) #for i in self.parent.historyList: # self.historyList.addItem(i) h.addWidget(l) h.addWidget(self.historyList) v.addLayout(h) h=QtGui.QHBoxLayout() l=QtGui.QLabel("Bookmarks:") l.setSizePolicy(QtGui.QSizePolicy.Minimum,QtGui.QSizePolicy.Preferred) self.bookmarksList=QBookMarksListWidget(type="bookmarks",dropTypes=["history"]) #self.bookmarksList.setSizePolicy(QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Minimum) self.bookmarksList.setAlternatingRowColors(True) self.bookmarksList.setSortingEnabled(True) for f in customizeUVCDAT.fileBookmarks: self.addBookmark(f) h.addWidget(l) h.addWidget(self.bookmarksList) v.addLayout(h) fileTab = QtGui.QFrame() fileTab.setLayout(v) self.originTabWidget.addTab( fileTab, "File" ) def createESGFTab(self): ## layout = QtGui.QVBoxLayout() ## self.esgfBrowser = QEsgfBrowser(self) ## layout.addWidget(self.esgfBrowser) try: esgf = QEsgfBrowser(self) #esgf.addGateway(gateway=customizeUVCDAT.defaultEsgfNode) esgf.addGateway(gateway=str(self.root.preferences.host_url.currentText())) except Exception: esgf = QtGui.QLabel("No Internet?") self.originTabWidget.addTab(esgf,"ESGF") def createOpenDAPTab(self): from packages.vtDV3D.RemoteDataBrowser import RemoteDataBrowser browser = RemoteDataBrowser() self.connect( browser, RemoteDataBrowser.new_data_element, self.processDataAddress ) self.originTabWidget.addTab(browser,"OpenDAP") def processDataAddress( self, address ): self.originTabWidget.setCurrentIndex( 0 ) self.fileEdit.setText( address ) self.updateFile() def createInfoTab(self): info = QtGui.QFrame() v=QtGui.QVBoxLayout() l=QtGui.QLabel("Variable Information") v.addWidget(l) sc=QtGui.QScrollArea() sc.setWidgetResizable(True) self.varInfoWidget = QtGui.QTextEdit() self.varInfoWidget.setReadOnly(True) sc.setWidget(self.varInfoWidget) v.addWidget(sc) info.setLayout(v) self.originTabWidget.addTab(info,"Info") def createEditTab(self): self.varEditArea=QtGui.QScrollArea() self.varEditArea.setWidgetResizable(True) self.originTabWidget.addTab(self.varEditArea,"Edit") def selectRoi( self ): if self.roi: self.roiSelector.setROI( self.roi ) self.roiSelector.show() def setRoi(self): self.roi = self.roiSelector.getROI() self.updateAxesFromRoi() def updateAxesFromRoi(self): from packages.vtDV3D.CDMS_VariableReaders import getAxisType, AxisType #print "Selected roi: %s " % str( self.roi ) # Add code here to update Lat Lon sliders. n = self.axisListHolder.gridLayout.rowCount() #print "ok in roi self is: ",n for i in range(len(self.axisListHolder.axisWidgets)): axis = self.axisListHolder.axisWidgets[i] axis_type = getAxisType( axis.axis ) if ( axis_type == AxisType.Latitude ) or axis.virtual==1: # Ok this is a lat we need to adjust the sliders now. lat1 = self.roi[1] lat2 = self.roi[3] [ lat1, lat2 ] = axis.sliderCombo.checkBounds( [ lat1, lat2 ], axis.axis.parent ) axis.sliderCombo.updateTopSlider(axis.sliderCombo.findAxisIndex(lat1)) axis.sliderCombo.updateBottomSlider(axis.sliderCombo.findAxisIndex(lat2)) if ( axis_type == AxisType.Longitude ) or axis.virtual==1: # Ok this is a lat we need to adjust the sliders now. lon1 = self.roi[0] lon2 = self.roi[2] [ lon1, lon2 ] = axis.sliderCombo.checkBounds( [ lon1, lon2 ], axis.axis.parent ) axis.sliderCombo.updateTopSlider(axis.sliderCombo.findAxisIndex(lon1)) axis.sliderCombo.updateBottomSlider(axis.sliderCombo.findAxisIndex(lon2)) def openSelectFileDialog(self): file = QtGui.QFileDialog.getOpenFileName(self, 'Open CDAT data file...', '', VariableProperties.FILTER + ';;All files (*.*)') if not file.isNull(): self.setFileName(file) def setFileName(self,fnm): self.fileEdit.setText(fnm) self.updateFile() def updateFileFromReturnPressed(self): self.updatingFile = True self.updateFile() def updateFile(self): self.cdmsFile = None fnm = self.fileEdit.text() fi = QtCore.QFileInfo(fnm) ft = str(fi.suffix()) for i in range(self.historyList.count()): it = self.historyList.item(i) if it.text()==fnm: self.historyList.takeItem(i) break self.historyList.insertItem(0,fnm) self.historyList.setCurrentRow(0) if fi.exists() or fnm[:7]=="http://": if fi.exists(): self.root.dockVariable.lastDirectory=str(fi.dir().path()) self.emit(QtCore.SIGNAL('fileChanged'), str(fnm)) other_list = [] for name, types in VariableProperties.FILETYPE.iteritems(): if ft in types: if name == 'CDAT': self.updateCDMSFile(str(fnm)) if name not in other_list: other_list.append(name) # elif name=="CDAT": # # some OpenDAP files don't have an extension trynig to open in CDAT # try: # tmpf=cdms2.open(str(fnm)) # tmpf.variables.keys() # tmpf.close() # self.updateCDMSFile(str(fnm)) # except: # pass elif name=="CDAT": # some OpenDAP files don't have an extension trynig to open in CDAT try: file_path = os.path.expanduser(str(fnm)) if file_path in CdmsCache.d: #print "Using cache2 for %s" % file_path tmpf = CdmsCache.d[file_path] else: #print "Loading file2 %s" % file_path tmpf = CdmsCache.d[file_path] = cdms2.open(file_path) tmpf.variables.keys() #tmpf.close() self.updateCDMSFile(file_path) except: pass self.updateOtherPlots(other_list) self.root.varProp.btnDefine.setEnabled(True) self.root.varProp.btnDefineClose.setEnabled(True) self.root.varProp.btnDefineAs.setEnabled(True) self.root.varProp.selectRoiButton.setEnabled(True) else: print "Unable to find file %s" % fnm self.emit(QtCore.SIGNAL('fileChanged'), None) self.historyList.takeItem(0) #remove from history if self.historyList.item(0): self.historyList.setCurrentRow(0) self.setFileName(self.historyList.item(0).text()) else: self.root.varProp.btnDefine.setEnabled(False) self.root.varProp.btnDefineClose.setEnabled(False) self.root.varProp.btnDefineAs.setEnabled(False) self.root.varProp.selectRoiButton.setEnabled(False) def selectFromList(self,item): self.setFileName(str(item.text())) def updateCDMSFile(self, fn): if fn[:7]=="http://": ## Maybe add something for my proxy errors here? if fn in CdmsCache.d: #print "Using cache3 for %s" % fn self.cdmsFile = CdmsCache.d[fn] else: #print "Loading file3 %s" % fn self.cdmsFile = CdmsCache.d[fn] = cdms2.open(fn) self.root.record("## Open file: %s" % fn) self.root.record("cdmsFile = cdms2.open('%s')" % fn) else: file_path = os.path.expanduser(fn) if fn in CdmsCache.d: #print "Using cache4 for %s" % file_path self.cdmsFile = CdmsCache.d[file_path] else: #print "Loading file4 %s" % file_path self.cdmsFile = CdmsCache.d[file_path] = cdms2.open(file_path) self.root.record("## Open file: %s" % file_path) self.root.record("cdmsFile = cdms2.open('%s')" % file_path) self.updateVariableList() def updateOtherPlots(self, namelist): self.emit(QtCore.SIGNAL('updateOtherPlots'), namelist) def updateVariableList(self): self.varCombo.clear() if self.cdmsFile!=None: # Add Variables sorted based on their dimensions (most dims first) curDim = -1 for (dim, varId) in sorted([(len(var.listdimnames()), var.id) for var in self.cdmsFile.variables.itervalues()])[::-1]: if dim!=curDim: curDim = dim count = self.varCombo.count() self.varCombo.insertSeparator(count) self.varCombo.model().item(count, 0).setText('%dD VARIABLES' % dim) var = self.cdmsFile.variables[varId] varName = var.id + ' ' + str(var.shape) + ' [' if hasattr(var, 'long_name'): varName += var.long_name if hasattr(var, 'units') and var.units!='': if varName[-1]!='[': varName += ' ' varName += var.units varName += ']' self.varCombo.addItem(varName, QtCore.QVariant(QtCore.QStringList(['variables', var.id]))) # Add Axis List count = self.varCombo.count() self.varCombo.insertSeparator(count) self.varCombo.model().item(count, 0).setText('AXIS LIST') for axis in self.cdmsFile.axes.itervalues(): axisName = axis.id + " (" + str(len(axis)) + ") - [" + axis.units + ": (" + str(axis[0]) + ", " + str(axis[-1]) + ")]" self.varCombo.addItem(axisName, QtCore.QVariant(QtCore.QStringList(['axes', axis.id]))) # By default, select first var self.varCombo.setCurrentIndex(1) def variableSelected(self, varName): if varName == '': self.varNameInFile = None return # self.defineVarButton.setEnabled(not varName.isNull()) # Enable define button varName = str(varName).split()[0] # Send signal to setup axisList in 'quickplot' tab self.root.record("## Open a variable in file") self.root.record("cdmsFileVariable = cdmsFile['%s']" % varName) self.varNameInFile = varName # Create and setup the axislist axisList = axesWidgets.QAxisList(self.cdmsFile, varName, self) axisList.setupVariableAxes() self.axisListHolder = axisList self.fillDimensionsWidget(axisList) self.root.varProp.btnDefine.setEnabled(True) self.root.varProp.btnDefineClose.setEnabled(True) self.root.varProp.btnDefineAs.setEnabled(True) self.root.varProp.selectRoiButton.setEnabled(True) def clearDimensionsWidget(self): if not self.axisListHolder is None: self.axisListHolder.destroy() it = self.dimsLayout.takeAt(0) if it: it.widget().deleteLater() ## it.widget().destroy() # self.dimsLayout.removeItem(it) del(it) def fillDimensionsWidget(self,axisList): self.clearDimensionsWidget() self.axisListHolder = axisList self.dimsLayout.insertWidget(0,axisList) self.updateVarInfo(axisList) self.dims.update() self.update() # def fillDimensionsWidget1(self,axisList): # if not self.axisListHolder is None: # self.axisListHolder.destroy() # N=self.dimsLayout.count() # while N>1: # it = self.dimsLayout.takeAt(N-1) # it.widget().deleteLater() ### it.widget().destroy() # self.dimsLayout.removeItem(it) # del(it) # self.dims.update() # self.update() # N=self.dimsLayout.count() # self.axisListHolder = axisList # self.dimsLayout.addWidget(axisList) # self.updateVarInfo(axisList) def updateVarInfo(self, axisList): from packages.vtDV3D.CDMS_VariableReaders import getAxisType, AxisType """ Update the text box with the variable's information """ if axisList is None: return var = axisList.getVar() varInfo = '' for line in var.listall(): varInfo += line + '\n' self.varInfoWidget.setText(varInfo) showRoi = False for i in range(len(self.axisListHolder.axisWidgets)): axis = self.axisListHolder.axisWidgets[i] axis_type = getAxisType(axis.axis) if axis_type in [ AxisType.Latitude, AxisType.Longitude ] or axis.virtual==1: showRoi = True if showRoi: self.selectRoiButton.setHidden(False) else: self.selectRoiButton.setHidden(True) def setupEditTab(self,var): self.varEditArea.takeWidget() self.varEditArea.setWidget(editVariableWidget.editVariableWidget(var,parent=self.parent,root=self.root)) def defineVarClicked(self,*args): self.getUpdatedVarCheck() def defineVarCloseClicked(self,*args): self.getUpdatedVarCheck() self.close() def defineAsVarClicked(self, *args): ok = False (qtname, ok) = QtGui.QInputDialog.getText(self, "UV-CDAT Variable Definition", "New variable name:", mode=QtGui.QLineEdit.Normal, text="") if ok: self.getUpdatedVarCheck(str(qtname)) def getUpdatedVarCheck(self,targetId=None): """ Return a new tvariable object with the updated information from evaluating the var with the current user selected args / options """ axisList = self.dimsLayout.itemAt(0).widget() if targetId is not None: tid = targetId elif axisList.cdmsFile is None: tid = axisList.var.id else: tid = axisList.var exists = False for it in self.root.dockVariable.widget().getItems(project=False): if tid == str(it.text()).split()[1]: exists = True ## Ok at that point we need to figure out if if exists: self.checkAgainst = tid self.ask.setTextValue(tid) self.ask.show() self.ask.exec_() else: self.getUpdatedVar(tid) def getUpdatedVar(self,targetId): if self.updatingFile: self.updatingFile = False return axisList = self.dimsLayout.itemAt(0).widget() kwargs = self.generateKwArgs() # Here we try to remove useless keywords as we record them cmds = "" for k in kwargs: if k=='order': o = kwargs[k] skip = True for i in range(len(o)): if int(o[i])!=i: skip = False break if skip: continue cmds += "%s=%s," % (k, repr(kwargs[k])) cmds=cmds[:-1] uvar=axisList.getVar() if isinstance(uvar,cdms2.axis.FileAxis): updatedVar = cdms2.MV2.array(uvar) else: updatedVar = uvar(**kwargs) # Get the variable after carrying out the: def, sum, avg... operations updatedVar = axisList.execAxesOperations(updatedVar) self.root.record("## Defining variable in memory") if axisList.cdmsFile is None: oid = updatedVar.id else: oid = "cdmsFileVariable" if self.varNameInFile is not None: original_id = self.varNameInFile computed_var = False else: original_id = updatedVar.id computed_var = True updatedVar.id = targetId self.root.record("%s = %s(%s)" % (targetId,oid,cmds)) ## Squeeze? if updatedVar.rank() !=0: if self.root.preferences.squeeze.isChecked(): updatedVar=updatedVar(squeeze=1) self.root.record("%s = %s(squeeze=1)" % (targetId,targetId)) kwargs['squeeze']=1 else: val = QtGui.QMessageBox() val.setText("%s = %f" % (updatedVar.id,float(updatedVar))) val.exec_() # Send information to controller so the Variable can be reconstructed # later. The best way is by emitting a signal to be processed by the # main window. When this panel becomes a global panel, then we will do # that. For now I will talk to the main window directly. _app = get_vistrails_application() controller = _app.uvcdatWindow.get_current_project_controller() def get_kwargs_str(kwargs_dict): kwargs_str = "" for k, v in kwargs_dict.iteritems(): if k == 'order': o = kwargs_dict[k] skip = True for i in range(len(o)): if int(o[i])!=i: skip = False break if skip: continue kwargs_str += "%s=%s," % (k, repr(v)) return kwargs_str axes_ops_dict = axisList.getAxesOperations() url = None if hasattr(self.cdmsFile, "uri"): url = self.cdmsFile.uri if not computed_var: cdmsVar = CDMSVariable(filename=self.cdmsFile.id, url=url, name=targetId, varNameInFile=original_id, axes=get_kwargs_str(kwargs), axesOperations=str(axes_ops_dict)) self.emit(QtCore.SIGNAL('definedVariableEvent'),(updatedVar,cdmsVar)) controller.add_defined_variable(cdmsVar) else: self.emit(QtCore.SIGNAL('definedVariableEvent'),updatedVar) controller.copy_computed_variable(original_id, targetId, axes=get_kwargs_str(kwargs), axesOperations=str(axes_ops_dict)) self.updateVarInfo(axisList) return updatedVar def generateKwArgs(self, axisList=None): """ Generate and return the variable axes keyword arguments """ if axisList is None: axisList = self.dimsLayout.itemAt(0).widget() kwargs = {} for axisWidget in axisList.getAxisWidgets(): if not axisWidget.isHidden(): kwargs[axisWidget.axis.id] = axisWidget.getCurrentValues() # Generate additional args #kwargs['squeeze'] = 0 kwargs['order'] = axisList.getAxesOrderString() return kwargs def applyEditsClicked(self): varname = self.varEditArea.widget().var.id self.getUpdatedVar(varname) _app = get_vistrails_application() controller = _app.uvcdatWindow.get_current_project_controller() controller.variableEdited(varname)
def __init__(self, parent=None, f=QtCore.Qt.WindowFlags()): QtGui.QWidget.__init__(self, parent, f) self.set_title("Export To LaTeX") # add button to select tex source # listview to select figure # thumbnail display # set figure specific options (show workflow, show execution, show # set includegraphics options source_label = QtGui.QLabel("LaTeX Source:") self.source_edit = QtGui.QLineEdit() source_selector = QDockPushButton("Select...") # source_selector = QtGui.QToolButton() # source_selector.setIcon(QtGui.QIcon( # self.style().standardPixmap(QtGui.QStyle.SP_DirOpenIcon))) # source_selector.setIconSize(QtCore.QSize(12,12)) source_selector.setToolTip("Open a file chooser") # source_selector.setAutoRaise(True) self.connect(source_selector, QtCore.SIGNAL('clicked()'), self.selectSource) source_group = QtGui.QGroupBox("LaTeX Source") s_layout = QtGui.QHBoxLayout() s_layout.addWidget(source_label) s_layout.addWidget(self.source_edit) s_layout.addWidget(source_selector) s_layout.setStretch(1,1) source_group.setLayout(s_layout) self.figure_list = QtGui.QListWidget() self.figure_list.setSelectionMode(self.figure_list.SingleSelection) self.preview_image = QtGui.QLabel() self.preview_image.setScaledContents(False) self.preview_image.setMinimumSize(240, 240) add_figure = QDockPushButton("Add Figure") delete_figure = QDockPushButton("Delete Figure") self.connect(add_figure, QtCore.SIGNAL("clicked()"), self.addFigure) self.connect(delete_figure, QtCore.SIGNAL("clicked()"), self.deleteFigure) self.connect(self.figure_list, QtCore.SIGNAL("itemSelectionChanged()"), self.figureSelected) figure_group = QtGui.QGroupBox("Figures") figure_layout = QtGui.QGridLayout() figure_layout.addWidget(self.figure_list,0,0,1,2) figure_layout.addWidget(self.preview_image,0,2) figure_layout.addWidget(add_figure,1,0,QtCore.Qt.AlignRight) figure_layout.addWidget(delete_figure,1,1,QtCore.Qt.AlignRight) figure_group.setLayout(figure_layout) # figure type, vistrail reference (vt_locator), version (smart tag) # use current version self.figure_type = QtGui.QComboBox() self.figure_type.setEditable(False) # items = QtCore.QStringList() # items << "Workflow Results" << "Workflow Graph" << "History Tree Graph"; self.figure_type.addItems(["Workflow Results", "Workflow Graph", "Version Tree"]) self.figure_ref = QtGui.QLineEdit() version_label = QtGui.QLabel("Version:") self.figure_version = QtGui.QLineEdit() tag_label = QtGui.QLabel("Tag:") self.figure_tag = QtGui.QComboBox() self.figure_tag.setEditable(True) self.figure_smart = QtGui.QCheckBox("Smart Tag") current_button = QDockPushButton("Use Current") self.connect(current_button, QtCore.SIGNAL("clicked()"), self.useCurrent) graphicx_label = QtGui.QLabel("Arguments for includegraphics:") self.graphicx_edit = QtGui.QLineEdit() self.def_group = QtGui.QGroupBox("Figure Definition") def_layout = QtGui.QVBoxLayout() def_h_layout = QtGui.QHBoxLayout() def_h_layout.addWidget(self.figure_ref) def_h_layout.addWidget(self.figure_type) def_h_layout.setStretch(0,1) def_layout.addLayout(def_h_layout) def_h_layout = QtGui.QHBoxLayout() def_h_layout.addWidget(version_label) def_h_layout.addWidget(self.figure_version) def_h_layout.addWidget(tag_label) def_h_layout.addWidget(self.figure_tag) def_h_layout.addWidget(self.figure_smart) def_h_layout.addWidget(current_button) def_h_layout.setStretch(3,1) def_layout.addLayout(def_h_layout) def_h_layout = QtGui.QHBoxLayout() def_h_layout.addWidget(graphicx_label) def_h_layout.addWidget(self.graphicx_edit) def_h_layout.setStretch(1,1) def_layout.addLayout(def_h_layout) self.def_group.setLayout(def_layout) self.chbPdf = QtGui.QCheckBox("As PDF") self.chbCache = QtGui.QCheckBox("Cache Images") self.chbLatexVTL = QtGui.QCheckBox("Include .vtl") self.chbWorkflow = QtGui.QCheckBox("Include Workflow") self.chbFullTree = QtGui.QCheckBox("Include Full Tree") self.chbFullTree.setEnabled(False) self.chbExecute = QtGui.QCheckBox("Execute Workflow") self.chbSpreadsheet = QtGui.QCheckBox("Show Spreadsheet Only") self.gbEmbedOpt = QtGui.QGroupBox("Embed Options") gblayout = QtGui.QGridLayout() gblayout.addWidget(self.chbPdf, 0, 0) gblayout.addWidget(self.chbCache, 0, 1) gblayout.addWidget(self.chbLatexVTL, 1, 0) self.gbEmbedOpt.setLayout(gblayout) self.gbDownOpt = QtGui.QGroupBox("Download Options") gblayout = QtGui.QGridLayout() gblayout.addWidget(self.chbWorkflow, 0, 0) gblayout.addWidget(self.chbFullTree, 0, 1) gblayout.addWidget(self.chbExecute, 1, 0) gblayout.addWidget(self.chbSpreadsheet, 1, 1) self.gbDownOpt.setLayout(gblayout) revert_button = QDockPushButton("Revert...") save_button = QDockPushButton("Save...") save_button.setAutoDefault(True) self.connect(save_button, QtCore.SIGNAL("clicked()"), self.saveLatex) main_layout = QtGui.QVBoxLayout() main_layout.addWidget(source_group) main_layout.addWidget(figure_group) main_layout.addWidget(self.def_group) main_h_layout = QtGui.QHBoxLayout() main_h_layout.addWidget(self.gbEmbedOpt) main_h_layout.addWidget(self.gbDownOpt) main_layout.addLayout(main_h_layout) main_h_layout = QtGui.QHBoxLayout() main_h_layout.setAlignment(QtCore.Qt.AlignRight) main_h_layout.addWidget(revert_button) main_h_layout.addWidget(save_button) main_layout.addLayout(main_h_layout) self.setLayout(main_layout) self.texts = None self.selected_item = None
class VariableProperties(QtGui.QDialog): FILTER = "CDAT data (*.cdms *.ctl *.dic *.hdf *.nc *.xml)" FILETYPE = {'CDAT': ['cdms', 'ctl', 'dic', 'hdf', 'nc', 'xml']} def __init__(self, parent=None,mode="add"): super(VariableProperties, self).__init__(parent) self.setWindowTitle("Load Variable") self.setMinimumHeight(400) self.roi = [ -180.0, -90.0, 180.0, 90.0 ] self.ask = QtGui.QInputDialog() self.ask.setWindowModality(QtCore.Qt.WindowModal) self.ask.setLabelText("This variable already exists!\nPlease change its name below and click ok to replace it.\n") self.mode=mode self.axisListHolder = None #self.setFloating(True) v=QtGui.QVBoxLayout() if mode=="add": self.label=QtGui.QLabel("Load From") else: self.label=QtGui.QLabel("Edit Variable") v.addWidget(self.label) P=parent.root.size() self.resize(QtCore.QSize(P.width()*.8,P.height()*.9)) self.setSizePolicy(QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Expanding) self.originTabWidget=QtGui.QTabWidget(self) #self.connect(self.originTabWidget,QtCore.SIGNAL("currentChanged(int)"),self.tabHasChanged) sp = QtGui.QSplitter(QtCore.Qt.Vertical) #sc=QtGui.QScrollArea() #sc.setWidget(self.originTabWidget) #sc.setWidgetResizable(True) sp.addWidget(self.originTabWidget) self.dims=QtGui.QFrame() self.dimsLayout=QtGui.QVBoxLayout() self.dims.setLayout( self.dimsLayout ) sp.addWidget(self.dims) v.addWidget(sp) h=QtGui.QHBoxLayout() self.selectRoiButton = QDockPushButton('Select Region Of Interest (ROI)') h.addWidget( self.selectRoiButton ) s=QtGui.QSpacerItem(40,20,QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Preferred) h.addItem(s) self.btnDefine=QDockPushButton("Load") h.addWidget(self.btnDefine) self.btnDefineClose=QDockPushButton("Load and Close") h.addWidget(self.btnDefineClose) self.btnDefineAs=QDockPushButton("Load As") h.addWidget(self.btnDefineAs) self.btnApplyEdits=QDockPushButton("Apply") self.btnApplyEdits.setVisible(False) h.addWidget(self.btnApplyEdits) self.btnSaveEditsAs=QDockPushButton("Save As") self.btnSaveEditsAs.setVisible(False) h.addWidget(self.btnSaveEditsAs) self.btnCancel=QDockPushButton("Close") # defaults? self.btnDefine.setDefault(False) self.btnDefineClose.setDefault(False) self.btnDefineAs.setDefault(False) self.selectRoiButton.setDefault(False) # Disabling at first self.btnDefine.setEnabled(False) self.btnDefineClose.setEnabled(False) self.btnDefineAs.setEnabled(False) self.selectRoiButton.setEnabled(False) h.addWidget(self.btnCancel) v.addLayout(h) self.layout=v #f=QtGui.QFrame() #f.setLayout(v) #self.setWidget(f) self.setLayout(v) self.parent=parent self.root = parent.root self.varNameInFile = None #store the name of the variable when loaded from file self.createFileTab() self.createESGFTab() self.createOpenDAPTab() self.createEditTab() self.createInfoTab() for i in range(self.originTabWidget.count()): if self.originTabWidget.tabText(i) == "Edit": self.originTabWidget.setTabEnabled(i,False) self.connectSignals() sp.setStretchFactor(0,2) self.cdmsFile = None self.updatingFile = False self.roiSelector = ROISelectionDialog( self.parent ) self.roiSelector.setWindowFlags( self.roiSelector.windowFlags() | Qt.WindowStaysOnTopHint ) self.connect(self.roiSelector, QtCore.SIGNAL('doneConfigure()'), self.setRoi ) if self.roi: self.roiSelector.setROI( self.roi ) ## @classmethod ## def instance(klass): ## if not hasattr(klass, '_instance'): ## klass._instance = klass() ## return klass._instance def closeEvent(self, event): super(VariableProperties, self).closeEvent(event) self.btnDefine.setVisible(True) self.btnDefineAs.setVisible(True) self.btnDefineClose.setVisible(True) self.btnApplyEdits.setVisible(False) self.btnSaveEditsAs.setVisible(False) def tabHasChanged(self,index): if (index==1) or (index==2): self.root.varProp.btnDefine.setEnabled(False) self.root.varProp.btnDefineClose.setEnabled(False) self.root.varProp.btnDefineAs.setEnabled(False) self.root.varProp.selectRoiButton.setEnabled(False) if (index==2): self.clearDimensionsWidget() elif (index==3): self.root.varProp.selectRoiButton.setEnabled(True) ## else: ## self.root.varProp.btnDefine.setEnabled(True) ## self.root.varProp.btnDefineClose.setEnabled(True) ## self.root.varProp.btnDefineAs.setEnabled(True) def connectSignals(self): self.btnCancel.clicked.connect(self.close) self.connect(self.ask,QtCore.SIGNAL('accepted()'),self.checkTargetVarName) if self.mode=="add": self.tbOpenFile.clicked.connect(self.openSelectFileDialog) self.connect(self.originTabWidget,QtCore.SIGNAL("currentChanged(int)"),self.tabHasChanged) self.connect(self.fileEdit, QtCore.SIGNAL('returnPressed()'), self.updateFileFromReturnPressed) self.connect(self.historyList, QtCore.SIGNAL('itemClicked(QListWidgetItem *)'), self.selectFromList) self.connect(self.bookmarksList, QtCore.SIGNAL('itemClicked(QListWidgetItem *)'), self.selectFromList) self.connect(self.varCombo, QtCore.SIGNAL('activated(const QString&)'), self.variableSelected) self.connect(self.bookmarksList,QtCore.SIGNAL("droppedInto"),self.droppedBookmark) self.connect(self.root.dockVariable.widget(),QtCore.SIGNAL("setupDefinedVariableAxes"),self.varAddedToDefined) ## Define button self.btnDefine.clicked.connect(self.defineVarClicked) self.btnDefineClose.clicked.connect(self.defineVarCloseClicked) self.btnDefineAs.clicked.connect(self.defineAsVarClicked) self.connect(self,QtCore.SIGNAL('definedVariableEvent'),self.root.dockVariable.widget().addVariable) self.btnApplyEdits.clicked.connect(self.applyEditsClicked) self.btnSaveEditsAs.clicked.connect(self.saveEditsAsClicked) self.selectRoiButton.clicked.connect( self.selectRoi ) def checkTargetVarName(self): result = None while result is None: result = self.ask.result() value = self.ask.textValue() if result == 1: # make sure we pressed Ok and not Cancel if str(value)!=self.checkAgainst: self.getUpdatedVarCheck(str(value)) else: self.getUpdatedVar(str(value)) def varAddedToDefined(self,var): axisList = axesWidgets.QAxisList(None,var,self) self.axisListHolder = axisList self.updateVarInfo(axisList) def droppedBookmark(self,event): text = str(event.mimeData().text()) self.addBookmark(text) def addBookmark(self,txt): duplicate=False for i in range(self.bookmarksList.count()): it = self.bookmarksList.item(i) if it.text()==txt: duplicate=True break if duplicate is False: self.bookmarksList.addItem(txt) customizeUVCDAT.fileBookmarks.append(txt) def createFileTab(self): #Top Part ## File Select Section v=QtGui.QVBoxLayout() h=QtGui.QHBoxLayout() l=QtGui.QLabel("File") h.addWidget(l) self.fileEdit=QtGui.QLineEdit() h.addWidget(self.fileEdit) self.tbOpenFile=QtGui.QToolButton() self.tbOpenFile.setText('...') self.tbOpenFile.setToolTip('View and select files') h.addWidget(self.tbOpenFile) v.addLayout(h) ## Variable Select part h=QtGui.QHBoxLayout() l=QtGui.QLabel("Variable(s):") l.setSizePolicy(QtGui.QSizePolicy.Maximum,QtGui.QSizePolicy.Preferred) h.addWidget(l) self.varCombo=QtGui.QComboBox() self.varCombo.setSizePolicy(QtGui.QSizePolicy.Preferred,QtGui.QSizePolicy.Fixed) h.addWidget(self.varCombo) v.addLayout(h) ## Bottom Part h=QtGui.QHBoxLayout() l=QtGui.QLabel("History:") l.setSizePolicy(QtGui.QSizePolicy.Minimum,QtGui.QSizePolicy.Preferred) self.historyList=uvcdatCommons.QDragListWidget(type="history") #self.historyList.setSizePolicy(QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Minimum) self.historyList.setAlternatingRowColors(True) #for i in self.parent.historyList: # self.historyList.addItem(i) h.addWidget(l) h.addWidget(self.historyList) v.addLayout(h) h=QtGui.QHBoxLayout() l=QtGui.QLabel("Bookmarks:") l.setSizePolicy(QtGui.QSizePolicy.Minimum,QtGui.QSizePolicy.Preferred) self.bookmarksList=QBookMarksListWidget(type="bookmarks",dropTypes=["history"]) #self.bookmarksList.setSizePolicy(QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Minimum) self.bookmarksList.setAlternatingRowColors(True) self.bookmarksList.setSortingEnabled(True) for f in customizeUVCDAT.fileBookmarks: self.addBookmark(f) h.addWidget(l) h.addWidget(self.bookmarksList) v.addLayout(h) fileTab = QtGui.QFrame() fileTab.setLayout(v) self.originTabWidget.addTab( fileTab, "File" ) def createESGFTab(self): ## layout = QtGui.QVBoxLayout() ## self.esgfBrowser = QEsgfBrowser(self) ## layout.addWidget(self.esgfBrowser) try: esgf = QEsgfBrowser(self) #esgf.addGateway(gateway=customizeUVCDAT.defaultEsgfNode) esgf.addGateway(gateway=str(self.root.preferences.host_url.currentText())) except Exception,err: esgf = QtGui.QLabel("No Internet?\nError log: %s"%err) self.originTabWidget.addTab(esgf,"ESGF")
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
def __init__(self, parent=None,mode="add"): super(VariableProperties, self).__init__(parent) self.setWindowTitle("Load Variable") self.setMinimumHeight(400) self.roi = [ -180.0, -90.0, 180.0, 90.0 ] self.ask = QtGui.QInputDialog() self.ask.setWindowModality(QtCore.Qt.WindowModal) self.ask.setLabelText("This variable already exists!\nPlease change its name below and click ok to replace it.\n") self.mode=mode self.axisListHolder = None #self.setFloating(True) v=QtGui.QVBoxLayout() if mode=="add": self.label=QtGui.QLabel("Load From") else: self.label=QtGui.QLabel("Edit Variable") v.addWidget(self.label) P=parent.root.size() self.resize(QtCore.QSize(P.width()*.8,P.height()*.9)) self.setSizePolicy(QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Expanding) self.originTabWidget=QtGui.QTabWidget(self) #self.connect(self.originTabWidget,QtCore.SIGNAL("currentChanged(int)"),self.tabHasChanged) sp = QtGui.QSplitter(QtCore.Qt.Vertical) #sc=QtGui.QScrollArea() #sc.setWidget(self.originTabWidget) #sc.setWidgetResizable(True) sp.addWidget(self.originTabWidget) self.dims=QtGui.QFrame() self.dimsLayout=QtGui.QVBoxLayout() self.dims.setLayout( self.dimsLayout ) sp.addWidget(self.dims) v.addWidget(sp) h=QtGui.QHBoxLayout() self.selectRoiButton = QDockPushButton('Select Region Of Interest (ROI)') h.addWidget( self.selectRoiButton ) s=QtGui.QSpacerItem(40,20,QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Preferred) h.addItem(s) self.btnDefine=QDockPushButton("Load") h.addWidget(self.btnDefine) self.btnDefineClose=QDockPushButton("Load and Close") h.addWidget(self.btnDefineClose) self.btnDefineAs=QDockPushButton("Load As") h.addWidget(self.btnDefineAs) self.btnApplyEdits=QDockPushButton("Apply") self.btnApplyEdits.setVisible(False) h.addWidget(self.btnApplyEdits) self.btnSaveEditsAs=QDockPushButton("Save As") self.btnSaveEditsAs.setVisible(False) h.addWidget(self.btnSaveEditsAs) self.btnCancel=QDockPushButton("Close") # defaults? self.btnDefine.setDefault(False) self.btnDefineClose.setDefault(False) self.btnDefineAs.setDefault(False) self.selectRoiButton.setDefault(False) # Disabling at first self.btnDefine.setEnabled(False) self.btnDefineClose.setEnabled(False) self.btnDefineAs.setEnabled(False) self.selectRoiButton.setEnabled(False) h.addWidget(self.btnCancel) v.addLayout(h) self.layout=v #f=QtGui.QFrame() #f.setLayout(v) #self.setWidget(f) self.setLayout(v) self.parent=parent self.root = parent.root self.varNameInFile = None #store the name of the variable when loaded from file self.createFileTab() self.createESGFTab() self.createOpenDAPTab() self.createEditTab() self.createInfoTab() for i in range(self.originTabWidget.count()): if self.originTabWidget.tabText(i) == "Edit": self.originTabWidget.setTabEnabled(i,False) self.connectSignals() sp.setStretchFactor(0,2) self.cdmsFile = None self.updatingFile = False self.roiSelector = ROISelectionDialog( self.parent ) self.roiSelector.setWindowFlags( self.roiSelector.windowFlags() | Qt.WindowStaysOnTopHint ) self.connect(self.roiSelector, QtCore.SIGNAL('doneConfigure()'), self.setRoi ) if self.roi: self.roiSelector.setROI( self.roi )
def attributeEditor(self, label, selFunc, modFunc, addFunc, delFunc): fax = QtGui.QGroupBox(label) lax = QtGui.QVBoxLayout() fax.setLayout(lax) fa1 = QtGui.QFrame() fa1l = QtGui.QHBoxLayout() fa1.setLayout(fa1l) lax.addWidget(fa1) p = QtGui.QComboBox() self.connect(p, QtCore.SIGNAL('currentIndexChanged(const QString&)'), selFunc) #self.connect(p,QtCore.SIGNAL('activated(int)'),self.selAxAttribute) fa1l.addWidget(p) attName = QtGui.QLineEdit() self.connect(attName, QtCore.SIGNAL("textEdited(const QString&)"), self.modifiedOn) fa1l.addWidget(attName) b = QDockPushButton("Modify") b.setFocusPolicy(QtCore.Qt.NoFocus) fa1l.addWidget(b) self.connect(b, QtCore.SIGNAL("clicked()"), modFunc) fa2 = QtGui.QFrame() fa2l = QtGui.QHBoxLayout() fa2.setLayout(fa2l) lax.addWidget(fa2) newAttName = QtGui.QLineEdit() fa2l.addWidget(newAttName) b = QDockPushButton("Create Attribute") b.setFocusPolicy(QtCore.Qt.NoFocus) fa2l.addWidget(b) self.connect(b, QtCore.SIGNAL("clicked()"), addFunc) b = QDockPushButton("Delete Attribute") b.setFocusPolicy(QtCore.Qt.NoFocus) fa2l.addWidget(b) self.connect(b, QtCore.SIGNAL("clicked()"), delFunc) return fax, p, attName, newAttName