def show_advanced_config(self): # Get the pipeline info for the cell vistraildata = VistrailManager(self._cell._controller) pipeline = vistraildata.get_pipeline(self._cell.cellInfo) self._cell._set_overlay(pipeline.recipe.plot.configWidget) self._cell._overlay.setup(self._cell, pipeline.recipe.plot)
def _color_version_nodes(node, action, tag, description): pipelineInfo = None if action is not None and VistrailManager.initialized: vistraildata = VistrailManager() # Warning: the first scene might get created before the # VistrailManager gets the 'controller_changed' signal, thus # VistrailManager() might be None if vistraildata is not None: pipelineInfo = vistraildata.get_pipeline(action.id) if tag == 'dat-vars': # Variable root brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) return dict( VERSION_USER_BRUSH=brush, VERSION_OTHER_BRUSH=brush, VERSION_LABEL_COLOR=QtGui.QColor(255, 255, 255), VERSION_SHAPE='rectangle') elif tag is not None and tag.startswith('dat-var-'): # Variables return dict( VERSION_USER_BRUSH=QtGui.QBrush(QtGui.QColor(27, 27, 75)), VERSION_OTHER_BRUSH=QtGui.QBrush(QtGui.QColor(72, 50, 25)), VERSION_LABEL_COLOR=QtGui.QColor(255, 255, 255), VERSION_SHAPE='rectangle') elif pipelineInfo is not None: return dict( VERSION_USER_BRUSH=QtGui.QBrush(QtGui.QColor(171, 169, 214)), VERSION_OTHER_BRUSH=QtGui.QBrush(QtGui.QColor(219, 198, 179))) else: return dict()
def openFile(self): builderWindow = get_vistrails_application().builderWindow with VistrailManager.defer_controller_change(): view = builderWindow.open_vistrail_default() if view is not None: VistrailManager.set_controller( view.get_controller(), register=True)
def resetClicked(self): mngr = VistrailManager(self.cell._controller) pipeline = mngr.get_pipeline(self.cell.cellInfo) if pipeline.version != self.cell._controller.current_version: self.cell._controller.change_selected_version(pipeline.version) currentTabIndex = self.tabWidget.currentIndex() self.setup(self.cell, self.plot) self.tabWidget.setCurrentIndex(currentTabIndex)
def applyClicked(self): self.okClicked() # Bring this overlay back up self.cell._set_overlay(DefaultPlotConfigOverlay) mngr = VistrailManager(self.cell._controller) pipeline = mngr.get_pipeline(self.cell.cellInfo) self.cell._overlay.setup(self.cell, pipeline.recipe.plot)
def populate(self, provenance, row=0): if row == 0: self.root = provenance try: node = self.nodes[provenance] except KeyError: pass else: if node.row <= row: node.row = row + 1 return node.item item = None links = set() if isinstance(provenance, data_provenance.Operation): item = OperationProvenanceItem(provenance['name'], provenance) for arg in provenance['args'].itervalues(): self.populate(arg, row + 1) links.add(arg) elif isinstance(provenance, data_provenance.Variable): varname = self._controller.vistrail.get_tag(provenance['version']) vistraildata = VistrailManager(self._controller) prev = vistraildata.variable_provenance(provenance['version']) if prev is None: # We are missing data! Someone tampered with the vistrail? if varname is not None and varname[:8] == 'dat-var': varname = varname[:8] else: varname = translate(ProvenanceSceneLayout)( '(deleted)') warnings.warn( "A variable (version %r) referenced from provenance " "is missing!" % provenance['version']) item = VariableProvenanceItem(varname, provenance) elif varname is not None and varname[:8] == 'dat-var-': self.populate(prev, row + 1) varname = varname[8:] item = VariableProvenanceItem(varname, provenance) links.add(prev) else: # If that variable has been deleted, we just skip it, like an # intermediate result self.populate(prev, row) elif isinstance(provenance, data_provenance.Loader): item = LoaderProvenanceItem(provenance['name'], provenance) elif isinstance(provenance, data_provenance.Constant): item = ConstantProvenanceItem(provenance['constant'], provenance) else: raise TypeError("populate() got %r" % (provenance,)) if item is not None: self.nodes[provenance] = self.TmpNode(item, row, links)
def _controller_changed_deferred(self, controller, new): vistraildata = VistrailManager(controller) if vistraildata is None: # Non-DAT controller here: create a sheet for it, so that we don't # interfere with DAT sh_window = spreadsheetController.findSpreadsheetWindow( create=False) if sh_window is not None: tab_controller = sh_window.tabController if self._vt_sheet is None: self._vt_sheet = StandardWidgetSheetTab( tab_controller, 2, 3) tab_controller.addTabWidget( self._vt_sheet, "VisTrails Sheet") VistrailManager.set_sheet_immortal(self._vt_sheet, True) tab_controller.setCurrentWidget(self._vt_sheet) return # Get the spreadsheets for this project spreadsheet_tabs = vistraildata.spreadsheet_tabs if new: # Execute the pipelines for cellInfo, pipeline in vistraildata.all_cells: tab = cellInfo.tab error = vistrails_interface.try_execute( controller, pipeline) if error is not None: from dat.gui.cellcontainer import DATCellContainer tab.setCellWidget( cellInfo.row, cellInfo.column, DATCellContainer( cellInfo=CellInformation( tab, cellInfo.row, cellInfo.column), error=error)) # Make one of these tabs current sh_window = spreadsheetController.findSpreadsheetWindow( create=False) if sh_window is not None: tab = sh_window.tabController.currentWidget() if tab not in spreadsheet_tabs.values(): tab_controller = sh_window.tabController tab = next(spreadsheet_tabs.itervalues()) tabidx = tab_controller.indexOf(tab) tab_controller.setCurrentIndex(tabidx)
def okClicked(self): mngr = VistrailManager(self.cell._controller) pipeline = mngr.get_pipeline(self.cell.cellInfo) if pipeline.version != self.cell._controller.current_version: new_pipeline = PipelineInformation( self.cell._controller.current_version, pipeline.recipe, pipeline.conn_map, pipeline.port_map) mngr.created_pipeline(self.cell.cellInfo, new_pipeline) self.cell.update_pipeline(True) else: self.cell._set_overlay(None)
def _get_custom_version_panels(controller, version): _ = translate("recipe_version_panel") if not VistrailManager.initialized: return [] vistraildata = VistrailManager(controller) if vistraildata is None: return [] pipelineInfo = vistraildata.get_pipeline(version) if pipelineInfo is None: return [] monospace = QtGui.QFont('Monospace') monospace.setStyleHint(QtGui.QFont.TypeWriter) recipe = pipelineInfo.recipe recipe_widget = QtGui.QGroupBox(_("DAT recipe")) recipe_widget.setSizePolicy( recipe_widget.sizePolicy().horizontalPolicy(), QtGui.QSizePolicy.Fixed) layout = QtGui.QVBoxLayout() line = QtGui.QHBoxLayout() line.addWidget(QtGui.QLabel(_("Plot:"))) plot_label = QtGui.QLabel("%s" % recipe.plot.name) plot_label.setFont(monospace) line.addWidget(plot_label) layout.addLayout(line) layout.addWidget(QtGui.QLabel(_("Variables:"))) variable_list = QtGui.QTextEdit() color = variable_list.textColor() variable_list.setEnabled(False) variable_list.setTextColor(color) variable_list.setFont(monospace) variable_list.setLineWrapMode(QtGui.QTextEdit.NoWrap) variable_list.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) text = [] for p_values in recipe.parameters.itervalues(): for value in p_values: if value.type == RecipeParameterValue.VARIABLE: text.append(value.variable.name) text = '\n'.join(text) variable_list.setPlainText(text) variable_list.setFixedHeight( variable_list.document().size().height()) layout.addWidget(variable_list) recipe_widget.setLayout(layout) return [(-1, recipe_widget)]
def setup(self, cell, plot): self.cell = cell self.plot = plot # Get pipeline of the cell mngr = VistrailManager(cell._controller) pipelineInfo = mngr.get_pipeline(cell.cellInfo) # Clear old tabs self.tabWidget.clear() # Get all of the plot modules in the pipeline plot_modules = get_plot_modules( pipelineInfo, cell._controller.current_pipeline) registry = get_module_registry() getter = registry.get_configuration_widget for module in plot_modules: widgetType = None widget = None # Try to get custom config widget for the module try: widgetType = \ getter(module.package, module.name, module.namespace) except ModuleRegistryException: pass if widgetType: # Use custom widget widget = widgetType(module, cell._controller) self.connect(widget, QtCore.SIGNAL("doneConfigure"), self.configureDone) self.connect(widget, QtCore.SIGNAL("stateChanged"), self.stateChanged) else: # Use PortsList widget, only if module has ports widget = DATPortsList(self) widget.update_module(module) if len(widget.port_spec_items) > 0: widget.set_controller(cell._controller) else: widget = None # Add widget in new tab if widget: self.tabWidget.addTab(widget, module.name)
def test_variable(self): controller = self.vt_controller() loader = Test_generation._loaders.get('MyVariableLoader') self.assertIsNotNone(loader) varname = 'mytest' variable = loader.load() self.assertIsNotNone(variable) VistrailManager(controller).new_variable(varname, variable) tag = controller.vistrail.get_tag_str('dat-var-%s' % varname) controller.change_selected_version(tag.action_id) pipeline = controller.current_pipeline self.assertEqual(len(pipeline.module_list), 4) # Float(17.63), Float(24.37), PythonCalc('+'), OutputPort output_port = vistrails_interface.find_modules_by_type( pipeline, [OutputPort]) self.assertEqual(len(output_port), 1) output_port, = output_port self.assertEqual(vistrails_interface.get_function(output_port, 'name'), 'value') self.assertEqual(vistrails_interface.get_function(output_port, 'spec'), 'org.vistrails.vistrails.basic:Float')
def __init__(self, cellcontainer, **kwargs): Overlay.__init__(self, cellcontainer, **kwargs) self.setStyleSheet(stylesheet) # Type-checking, so we can show which parameters are suitable to # receive the drop mimeData = kwargs.get('mimeData') if not mimeData or not mimeData.hasFormat(MIMETYPE_DAT_VARIABLE): self._compatible_ports = None else: varname = str(mimeData.data(MIMETYPE_DAT_VARIABLE)) variable = (VistrailManager( self._cell._controller).get_variable(varname)) self._compatible_ports = [] for port in self._cell._plot.ports: if issubclass(variable.type.module, port.type.module): self._compatible_ports.append(COMPATIBLE) else: if get_typecast_operations(variable.type, port.type): self._compatible_ports.append(TYPECASTABLE) else: self._compatible_ports.append(INCOMPATIBLE) self._cell._parameter_hovered = None self.setupUi(kwargs.get('overlayed', True))
def __new__(cls, *args, **kwargs): # Special case: if we are not on a DAT sheet, use VisTrails's container # class if VistrailManager() is None: return QCellContainer(*args, **kwargs) else: return super(DATCellContainer, cls).__new__(cls, *args, **kwargs)
def perform_operation(expression, controller=None): """Perform a variable operation from the given string. """ # First, parse the expressions target, expr_tree = parse_expression(expression) # Find the actual operations & variables controller, root_version, output_module_id = ( Variable._get_variables_root(controller)) vistraildata = VistrailManager(controller) if vistraildata.get_variable(target) is not None: raise InvalidOperation("Target variable %r already exists" % target) op_tree = resolve_symbols(vistraildata, expr_tree) # Build the new variable variable = op_tree.execute(controller) vistraildata.new_variable(target, variable)
def dragEnterEvent(self, event): mimeData = event.mimeData() if (mimeData.hasFormat(MIMETYPE_DAT_VARIABLE) and self._input_line.has_markers() and VistrailManager().get_variable( str(mimeData.data(MIMETYPE_DAT_VARIABLE))) is not None): event.accept() else: event.ignore()
def _controller_changed_deferred(self, controller, new): vistraildata = VistrailManager(controller) if vistraildata is None: # Non-DAT controller here: create a sheet for it, so that we don't # interfere with DAT sh_window = spreadsheetController.findSpreadsheetWindow( create=False) if sh_window is not None: tab_controller = sh_window.tabController if self._vt_sheet is None: self._vt_sheet = StandardWidgetSheetTab( tab_controller, 2, 3) tab_controller.addTabWidget(self._vt_sheet, "VisTrails Sheet") VistrailManager.set_sheet_immortal(self._vt_sheet, True) tab_controller.setCurrentWidget(self._vt_sheet) return # Get the spreadsheets for this project spreadsheet_tabs = vistraildata.spreadsheet_tabs if new: # Execute the pipelines for cellInfo, pipeline in vistraildata.all_cells: tab = cellInfo.tab error = vistrails_interface.try_execute(controller, pipeline) if error is not None: from dat.gui.cellcontainer import DATCellContainer tab.setCellWidget( cellInfo.row, cellInfo.column, DATCellContainer(cellInfo=CellInformation( tab, cellInfo.row, cellInfo.column), error=error)) # Make one of these tabs current sh_window = spreadsheetController.findSpreadsheetWindow(create=False) if sh_window is not None: tab = sh_window.tabController.currentWidget() if tab not in spreadsheet_tabs.values(): tab_controller = sh_window.tabController tab = next(spreadsheet_tabs.itervalues()) tabidx = tab_controller.indexOf(tab) tab_controller.setCurrentIndex(tabidx)
def dropEvent(self, event): mimeData = event.mimeData() if mimeData.hasFormat(MIMETYPE_DAT_VARIABLE): if self._plot is not None and self._parameter_hovered is not None: event.accept() port_name = self._plot.ports[self._parameter_hovered].name varname = str(mimeData.data(MIMETYPE_DAT_VARIABLE)) # Here we keep the old values around, and we revert if # update_pipeline() returns False old_values = self._parameters.get(port_name) if old_values is not None: old_values = list(old_values) # Try to update values = self._parameters.setdefault(port_name, []) if values and values[0].type == RecipeParameterValue.CONSTANT: # The overlay shouldn't allow this warnings.warn("a variable was dropped on a port where a " "constant is set") event.ignore() return variable = (VistrailManager( self._controller).get_variable(varname)) param = RecipeParameterValue(variable=variable) if self._insert_pos < len(values): values[self._insert_pos] = param else: values.append(param) if not self.update_pipeline(): # This is wrong somehow (ex: typecasting failed) # Revert to previous values if old_values is None: del self._parameters[port_name] else: self._parameters[port_name] = old_values else: event.ignore() elif mimeData.hasFormat(MIMETYPE_DAT_PLOT): event.accept() plotname = str(mimeData.data(MIMETYPE_DAT_PLOT)) plotname = plotname.split(',') if len(plotname) == 2: self._plot = GlobalManager.get_plot(*plotname) self._parameters = dict() self._parameter_hovered = None self.update_pipeline() else: event.ignore() self._set_overlay(None)
def dropEvent(self, event): mimeData = event.mimeData() if (mimeData.hasFormat(MIMETYPE_DAT_VARIABLE) and self._input_line.has_markers()): varname = str(mimeData.data(MIMETYPE_DAT_VARIABLE)) variable = VistrailManager().get_variable(varname) if variable is not None: self._input_line.replace_first_marker(varname) event.accept() self._input_line.setFocus(QtCore.Qt.MouseFocusReason) self._input_line.focus_first_marker() return event.ignore()
def test_pipeline_creation(self): import dat.tests.pkg_test_plots.init as pkg_test_plots controller = self.vt_controller() vistraildata = VistrailManager(controller) loader = Test_generation._loaders.get('StrMaker') loader.v = 'Hello' vistraildata.new_variable('var1', loader.load()) loader.v = 'world' vistraildata.new_variable('var2', loader.load()) cellInfo = FakeObj( row=0, column=0, tab=FakeObj(tabWidget=FakeObj(tabText=lambda w: 'Sheet 1'))) recipe = DATRecipe( pkg_test_plots.concat_plot, { 'param1': (RecipeParameterValue( variable=vistraildata.get_variable('var1')), ), 'param2': (RecipeParameterValue( variable=vistraildata.get_variable('var2')), ), 'param3': (RecipeParameterValue(constant="!"), ), }) pipelineInfo = vistrails_interface.create_pipeline( controller, recipe, cellInfo.row, cellInfo.column, None) # This plot has no cell module so this is fine controller.change_selected_version(pipelineInfo.version) result = CallRecorder() pkg_test_plots.Recorder.callback = result interpreter = get_default_interpreter() interpreter.execute(controller.current_pipeline, view=DummyView(), locator=controller.locator, current_version=pipelineInfo.version) call = (['Hello, world!'], dict()) self.assertEqual(result.calls, [call])
def dragEnterEvent(self, event): mimeData = event.mimeData() if mimeData.hasFormat(MIMETYPE_DAT_VARIABLE): if VistrailManager(self._controller).get_variable( str(mimeData.data(MIMETYPE_DAT_VARIABLE))) is None: # I can't think of another case for this than someone dragging # a variable from another instance of DAT event.ignore() return # If this doesn't fail, we would still use the variable with # the same name from this instance, not import the variable # from the other instance if self._plot is None: # We should ignore the drop here. That would make sense, and # display the correct mouse pointer # We can't though, because Qt would stop sending drag and drop # events # We still refuse the QDropEvent when the drop happens self._set_overlay(VariableDropEmptyCell, mimeData=mimeData) else: self._set_overlay(VariableDroppingOverlay, mimeData=mimeData) elif mimeData.hasFormat(MIMETYPE_DAT_PLOT): try: plot = str(mimeData.data(MIMETYPE_DAT_PLOT)) plot = plot.split(',') if len(plot) != 2: raise KeyError plot = GlobalManager.get_plot(*plot) except KeyError: # I can't think of another case for this than someone dragging # a plot from another instance of DAT event.ignore() return # If the plot is available, this operation should work as # expected else: self._set_overlay(PlotDroppingOverlay, mimeData=mimeData) else: event.ignore() return event.accept()
def apply_operation(controller, op, args): """Apply an operation to build a new variable. Either load the subworkflow or wrap the parameter variables correctly and call the callback function. """ if op.callback is not None: # FIXME : controller is ignored here... assert controller == VistrailManager().controller result = vistrails_interface.call_operation_callback( op, op.callback, args) if result is None: raise InvalidOperation("Package error: operation callback " "returned None") else: # op.subworkflow is not None: result = vistrails_interface.apply_operation_subworkflow( controller, op, op.subworkflow, args) if result.provenance is None: result.provenance = data_provenance.Operation(operation=op, arg_list=args) return result
def _sheet_changed(self, tab): vistraildata = VistrailManager.from_spreadsheet_tab(tab) if vistraildata is not None: self.builderWindow.ensureController(vistraildata.controller)
def __init__(self, parent, variables=VAR_HIDE): """Setups the widget. If variables is not VAR_HIDE, a list of the variables will be displayed on the right. You can override variable_filter to choose which variables are to be displayed. If VAR_SELECT is used, variable_selected(variable) will be called when the selection changes. """ _ = translate(OperationWizard) QtGui.QDialog.__init__(self, parent, QtCore.Qt.Dialog) self._vistraildata = VistrailManager() self._selected_varname = None self._has_error = False var_right_layout = QtGui.QHBoxLayout() vlayout = QtGui.QVBoxLayout() self._validator = VariableNameValidator(VistrailManager()) varname_layout = QtGui.QHBoxLayout() varname_layout.addWidget(QtGui.QLabel(_("Variable name:"))) self._varname_edit = AdvancedLineEdit( DEFAULT_VARIABLE_NAME, default=DEFAULT_VARIABLE_NAME, validate=self._validator, flags=(AdvancedLineEdit.COLOR_VALIDITY | AdvancedLineEdit.COLOR_DEFAULTVALUE | AdvancedLineEdit.FOLLOW_DEFAULT_UPDATE)) varname_layout.addWidget(self._varname_edit) vlayout.addStretch() vlayout.addLayout(varname_layout) # Create this wizard's specific layout app_layout = self.create_ui() assert app_layout is not None vlayout.insertLayout(0, app_layout) var_right_layout.addLayout(vlayout) # Optionally, put a list of variables on the right if variables != self.VAR_HIDE: self._variable_list = DraggableListWidget( mimetype=MIMETYPE_DAT_VARIABLE) self._variable_list.setSizePolicy( QtGui.QSizePolicy.Minimum, self._variable_list.sizePolicy().horizontalPolicy()) for varname in self._vistraildata.variables: if not self.variable_filter( self._vistraildata.get_variable(varname)): continue pos = bisect( self._variable_list.count(), lambda i: str(self._variable_list.item(i).text()), varname) self._variable_list.insertItem(pos, varname) var_right_layout.addWidget(self._variable_list) if variables == self.VAR_SELECT: self._variable_list.setDragEnabled(False) self._variable_list.setSelectionMode( QtGui.QAbstractItemView.SingleSelection) self.connect( self._variable_list, QtCore.SIGNAL('itemSelectionChanged()'), self._selection_changed) main_layout = QtGui.QVBoxLayout() main_layout.addLayout(var_right_layout) self._error_label = QtGui.QLabel() font = self._error_label.font() font.setBold(True) self._error_label.setFont(font) self._error_label.setStyleSheet('color: red;') main_layout.addWidget(self._error_label) buttons = QtGui.QDialogButtonBox( QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel, QtCore.Qt.Horizontal) self.connect(buttons, QtCore.SIGNAL('accepted()'), self._accept) self.connect(buttons, QtCore.SIGNAL('rejected()'), self, QtCore.SLOT('reject()')) main_layout.addWidget(buttons) self.setLayout(main_layout)
class OperationWizard(QtGui.QDialog): """Base class of the operation wizards. This class offers the basic behavior and functionalities needed by an operation wizard. It can be subclassed in VisTrails packages to add wizards to operations. A wizard is a dialog that is opened by clicking on the relevant icon to the right of an operation name. It then shows a graphical UI intended to do a variable operation graphically. When the user accepts, the wizard returns the new variable or operation string to DAT. """ VAR_HIDE = 0 VAR_SELECT = 1 VAR_DRAG = 2 def __init__(self, parent, variables=VAR_HIDE): """Setups the widget. If variables is not VAR_HIDE, a list of the variables will be displayed on the right. You can override variable_filter to choose which variables are to be displayed. If VAR_SELECT is used, variable_selected(variable) will be called when the selection changes. """ _ = translate(OperationWizard) QtGui.QDialog.__init__(self, parent, QtCore.Qt.Dialog) self._vistraildata = VistrailManager() self._selected_varname = None self._has_error = False var_right_layout = QtGui.QHBoxLayout() vlayout = QtGui.QVBoxLayout() self._validator = VariableNameValidator(VistrailManager()) varname_layout = QtGui.QHBoxLayout() varname_layout.addWidget(QtGui.QLabel(_("Variable name:"))) self._varname_edit = AdvancedLineEdit( DEFAULT_VARIABLE_NAME, default=DEFAULT_VARIABLE_NAME, validate=self._validator, flags=(AdvancedLineEdit.COLOR_VALIDITY | AdvancedLineEdit.COLOR_DEFAULTVALUE | AdvancedLineEdit.FOLLOW_DEFAULT_UPDATE)) varname_layout.addWidget(self._varname_edit) vlayout.addStretch() vlayout.addLayout(varname_layout) # Create this wizard's specific layout app_layout = self.create_ui() assert app_layout is not None vlayout.insertLayout(0, app_layout) var_right_layout.addLayout(vlayout) # Optionally, put a list of variables on the right if variables != self.VAR_HIDE: self._variable_list = DraggableListWidget( mimetype=MIMETYPE_DAT_VARIABLE) self._variable_list.setSizePolicy( QtGui.QSizePolicy.Minimum, self._variable_list.sizePolicy().horizontalPolicy()) for varname in self._vistraildata.variables: if not self.variable_filter( self._vistraildata.get_variable(varname)): continue pos = bisect( self._variable_list.count(), lambda i: str(self._variable_list.item(i).text()), varname) self._variable_list.insertItem(pos, varname) var_right_layout.addWidget(self._variable_list) if variables == self.VAR_SELECT: self._variable_list.setDragEnabled(False) self._variable_list.setSelectionMode( QtGui.QAbstractItemView.SingleSelection) self.connect( self._variable_list, QtCore.SIGNAL('itemSelectionChanged()'), self._selection_changed) main_layout = QtGui.QVBoxLayout() main_layout.addLayout(var_right_layout) self._error_label = QtGui.QLabel() font = self._error_label.font() font.setBold(True) self._error_label.setFont(font) self._error_label.setStyleSheet('color: red;') main_layout.addWidget(self._error_label) buttons = QtGui.QDialogButtonBox( QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel, QtCore.Qt.Horizontal) self.connect(buttons, QtCore.SIGNAL('accepted()'), self._accept) self.connect(buttons, QtCore.SIGNAL('rejected()'), self, QtCore.SLOT('reject()')) main_layout.addWidget(buttons) self.setLayout(main_layout) def _selection_changed(self): items = self._variable_list.selectedItems() if len(items) == 1: item = items[0] sel = str(item.text()) if sel != self._selected_varname: self._selected_varname = sel self.variable_selected(self._vistraildata.get_variable(sel)) def _accept(self): if self._has_error: return if not self._varname_edit.isValid(): self._varname_edit.setFocus(QtCore.Qt.OtherFocusReason) return varname = str(self._varname_edit.text()) result = self.make_operation(varname) if isinstance(result, Variable): # Operation was performed by make_operation() self._vistraildata.new_variable(varname, result) self.command = None self.accept() elif result is False: # Don't dismiss the dialog pass elif isinstance(result, basestring): # make_operation() gave us an expression to execute if '=' in result: self.command = result else: self.command = '%s = %s' % (varname, result) self.accept() elif (isinstance(result, tuple) and len(result) == 2 and isinstance(result[0], basestring) and isinstance(result[1], dict)): subworkflow, args = result # TODO : Use args from dictionary + 'variable' # self.get_variable_argument() to make the result raise NotImplementedError("Building the operation result from a " "subworkflow is not yet implemented") else: raise TypeError("make_operation returned an unexpected type") def get_variable_argument(self): variable_info = self._vistraildata.get_variable(self._selected_varname) variable = Variable.from_workflow(variable_info, record_materialized=False) return ArgumentWrapper(variable) def set_error(self, err): if err is None: self._error_label.hide() self._has_error = False else: if isinstance(err, BaseException): err = "%s: %s" % (err.__class__.__name__, err.message) self._error_label.setText(err) self._error_label.show() self._has_error = True def variable_filter(self, variable): return True def variable_selected(self, varname): pass def make_operation(self, target_var_name): raise NotImplementedError
def __init__(self, controller, parent=None): QtGui.QDialog.__init__(self, parent, QtCore.Qt.Dialog) self._vistraildata = VistrailManager(controller) self._validator = VariableNameValidator(self._vistraildata) _ = translate(LoadVariableDialog) self.setWindowTitle(_("Load variable")) self._tabs = [] main_layout = QtGui.QVBoxLayout() self._tab_widget = QtGui.QTabWidget() self.connect(self._tab_widget, QtCore.SIGNAL('currentChanged(int)'), self.update_varname) main_layout.addWidget(self._tab_widget) varname_layout = QtGui.QHBoxLayout() varname_layout.addWidget(QtGui.QLabel(_("Variable name:"))) self._varname_edit = AdvancedLineEdit( DEFAULT_VARIABLE_NAME, default=DEFAULT_VARIABLE_NAME, validate=self._validator, flags=(AdvancedLineEdit.COLOR_VALIDITY | AdvancedLineEdit.COLOR_DEFAULTVALUE | AdvancedLineEdit.FOLLOW_DEFAULT_UPDATE)) varname_layout.addWidget(self._varname_edit) main_layout.addLayout(varname_layout) buttons_layout = QtGui.QHBoxLayout() load_cont_button = QtGui.QPushButton(_("Load and close")) self.connect(load_cont_button, QtCore.SIGNAL('clicked()'), self.loadclose_clicked) buttons_layout.addWidget(load_cont_button) load_button = QtGui.QPushButton(_("Load")) self.connect(load_button, QtCore.SIGNAL('clicked()'), self.load_clicked) buttons_layout.addWidget(load_button) cancel_button = QtGui.QPushButton(_("Cancel")) self.connect(cancel_button, QtCore.SIGNAL('clicked()'), self.cancel) buttons_layout.addWidget(cancel_button) main_layout.addLayout(buttons_layout) self.setLayout(main_layout) self._file_loader = FileLoaderPanel() self._file_loader.default_variable_name_observer = ( self.default_variable_name_changed) self._add_tab(self._file_loader, _("File")) app = get_vistrails_application() app.register_notification('dat_new_loader', self.loader_added) app.register_notification('dat_removed_loader', self.loader_removed) for loader in GlobalManager.variable_loaders: self.loader_added(loader) idx = self._tab_widget.currentIndex() if idx >= 0: loader = self._tabs[idx] self._varname_edit.setDefault(loader.get_default_variable_name()) else: self._varname_edit.setDefault(DEFAULT_VARIABLE_NAME) self._varname_edit.reset()
def __init__(self, args, optionsDict={}): QtGui.QApplication.__init__(self, args) NotificationDispatcher.__init__(self) # There are lots of issues with how the notifications are used # Although create_notification() exists, it doesn't seem to be used in # every case before register_notification() is called warnings.simplefilter('ignore', NotificationDispatcher.UsageWarning) VistrailsApplicationInterface.__init__(self) self.builderWindow = None self._vt_sheet = None set_vistrails_application(self) vistrails.gui.theme.initializeCurrentTheme() VistrailsApplicationInterface.init(self, options_dict=optionsDict, args=args) from vistrails.gui.vistrails_window import QVistrailsWindow self.builderWindow = QVistrailsWindow(ui_hooks=vt_hooks.hooks) self.builderWindow.closeEvent = lambda e: None self.startup.set_package_to_enabled('spreadsheet') self.package_manager.initialize_packages() self.builderWindow.link_registry() # Create a first controller view = self.builderWindow.create_first_vistrail() controller = view.get_controller() assert controller is not None # Set our own spreadsheet cell container class from dat.gui.cellcontainer import DATCellContainer spreadsheetController.setCellContainerClass(DATCellContainer) # Discover the plots and variable loaders from packages and register to # notifications for packages loaded/unloaded in the future GlobalManager.init() # Register the VistrailManager with the 'controller_changed' # notification VistrailManager.init() VistrailManager.set_controller( controller, register=True) # Create the main window mw = MainWindow() mw.setVisible(True) # Create the spreadsheet for the first project self._controller_changed(controller, new=True) # Create a spreadsheet and execute the visualizations when a new # controller is selected self.register_notification( 'dat_controller_changed', self._controller_changed) # Change the current controller when another sheet is selected self.register_notification( 'spreadsheet_sheet_changed', self._sheet_changed)
def __init__(self): QtGui.QMainWindow.__init__(self) self.setWindowTitle("DAT") _ = dat.gui.translate(MainWindow) menubar = self.menuBar() fileMenu = menubar.addMenu(_("&File")) newAction = fileMenu.addAction(_("&New...")) newAction.setShortcut('Ctrl+N') self.connect(newAction, QtCore.SIGNAL('triggered()'), self.newFile) openAction = fileMenu.addAction(_("&Open...")) openAction.setShortcut('Ctrl+O') self.connect(openAction, QtCore.SIGNAL('triggered()'), self.openFile) saveAction = fileMenu.addAction(_("&Save")) saveAction.setShortcut('Ctrl+S') self.connect(saveAction, QtCore.SIGNAL('triggered()'), self.saveFile) saveAsAction = fileMenu.addAction(_("Save &as...")) saveAsAction.setShortcut('Ctrl+Shift+S') self.connect(saveAsAction, QtCore.SIGNAL('triggered()'), self.saveAsFile) fileMenu.addSeparator() quitAction = fileMenu.addAction(_("&Quit")) quitAction.setShortcut('Ctrl+Q') self.connect(quitAction, QtCore.SIGNAL('triggered()'), self.quitApplication) viewMenu = menubar.addMenu(_("&View")) showBuilderAction = viewMenu.addAction(_("Show &builder window")) self.connect(showBuilderAction, QtCore.SIGNAL('triggered()'), get_vistrails_application().showBuilderWindow) # Spreadsheet hooks ss_hooks = dict( window_menu_main=False, window_menu_view=False, window_menu_window=False, window_quit_action=False, global_kbd_shortcuts=False, window_create_first_sheet=False, tab_create_sheet=True, tab_create_sheet_action=VistrailManager.hook_create_tab, tab_open_sheet=False, tab_save_sheet=False, tab_rename_sheet=True, tab_begin_rename_action=VistrailManager.hook_rename_tab_begin, tab_end_rename_action=VistrailManager.hook_rename_tab_end, tab_close_sheet=True, tab_close_sheet_action=VistrailManager.hook_close_tab, tab_delete_cell=False, ) # Embed the spreadsheet window as the central widget spreadsheetController.set_hooks(ss_hooks) self.spreadsheetWindow = spreadsheetController.findSpreadsheetWindow( show=False) self.setCentralWidget(self.spreadsheetWindow) self.spreadsheetWindow.setVisible(True) # Create the panels # DockWidgetClosable is not permitted self._variables = VariablePanel(VistrailManager()) self._plots = PlotPanel() self._operations = OperationPanel() self._data_provenance = DataProvenancePanel() self.connect(self._variables, QtCore.SIGNAL('variableSelected(PyQt_PyObject)'), self._data_provenance.showVariable) def dock_panel(title, widget, pos): dock = QtGui.QDockWidget(title) dock.setFeatures(QtGui.QDockWidget.DockWidgetMovable | QtGui.QDockWidget.DockWidgetFloatable) dock.setWidget(widget) self.addDockWidget(pos, dock) return dock dock_panel(_("Plots"), self._plots, QtCore.Qt.RightDockWidgetArea) self._variables_dock = dock_panel(_("Variables"), self._variables, QtCore.Qt.LeftDockWidgetArea) dock_panel(_("Calculator"), self._operations, QtCore.Qt.LeftDockWidgetArea) prov_dock = dock_panel(_("Data Provenance"), self._data_provenance, QtCore.Qt.LeftDockWidgetArea) self.tabifyDockWidget(self._variables_dock, prov_dock) self._variables_dock.raise_() get_vistrails_application().register_notification( 'dat_controller_changed', self._controller_changed)
def vt_controller(): app = get_vistrails_application() view = app.builderWindow.new_vistrail() controller = view.get_controller() VistrailManager.set_controller(controller, register=True) return controller