def _remove_variable(self, varname, renamed_to=None): get_vistrails_application().send_notification('dat_removed_variable', self._controller, varname, renamed_to=renamed_to) if renamed_to is None: # A variable was removed! # We'll remove all the mappings that used it to_remove = set([]) for pipeline in self._version_to_pipeline.itervalues(): if any(p.type == RecipeParameterValue.VARIABLE and p.variable.name == varname for p_values in pipeline.recipe.parameters.itervalues() for p in p_values): to_remove.add(pipeline.version) if to_remove: warnings.warn("Variable %r was used in %d pipelines!" % (varname, len(to_remove))) for version in to_remove: del self._version_to_pipeline[version] # Remove the annotations from the vistrail for key in (self._RECIPE_KEY, self._PORTMAP_KEY): self._controller.vistrail.set_action_annotation( version, key, None) cell_to_remove = [] for cellInfo, version in self._cell_to_version.iteritems(): if version in to_remove: cell_to_remove.append(cellInfo) for cellInfo in cell_to_remove: del self._cell_to_version[cellInfo] del self._cell_to_pipeline[cellInfo]
def init(self): """Initial setup of the Manager. Discovers plots and variable loaders from packages and registers notifications for packages loaded in the future. """ app = get_vistrails_application() # dat_new_plot(plot: Plot) app.create_notification('dat_new_plot') # dat_removed_plot(plot: Plot) app.create_notification('dat_removed_plot') # dat_new_loader(loader: BaseVariableLoader) app.create_notification('dat_new_loader') # dat_removed_loader(loader: BaseVariableLoader) app.create_notification('dat_removed_loader') # dat_new_operation(loader: VariableOperation) app.create_notification('dat_new_operation') # dat_removed_operation(loader: VariableOperation) app.create_notification('dat_removed_operation') app.register_notification("reg_new_package", self.new_package) app.register_notification("reg_deleted_package", self.deleted_package) # Load the Plots and VariableLoaders from the packages registry = get_module_registry() for package in registry.package_list: self.new_package(package.identifier)
def stop(): """Stops the application and cleans up. """ app = get_vistrails_application() app.finishSession() app.save_configuration() app.destroy()
def _open_vt(self): items = self._result_tree.selectedItems() item = items[0] vt = self._find_vt(item) if vt is None: return workflow, module_id = vt if ':' in workflow: filename, version = workflow.rsplit(':', 1) try: version = int(version) except ValueError: filename, version = workflow, None else: filename, version = workflow, None app = get_vistrails_application() if (not app.is_running_gui() or not hasattr(app, 'builderWindow') or app.builderWindow is None): return view = app.builderWindow.open_vistrail(FileLocator(filename), version=version) if module_id is not None: from vistrails.gui.pipeline_view import QGraphicsModuleItem scene = view.controller.current_pipeline_view.scene() for module_item in (i for i in scene.items() if isinstance(i, QGraphicsModuleItem)): if module_item.module.id == module_id: module_item.setSelected(True) break
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 compute(self): import shutil idf = self.get_input('idf') idd_path = force_get_path(self, 'idd', find_idd()) epw_path = self.get_input('epw').name energyplus_path = force_get_path(self, 'energyplus', find_energyplus()) tmp = tempfile.mkdtemp( prefix=datetime.datetime.now().strftime('%Y.%m.%d.%H.%M.%S') + "_RunEnergyPlus_") idf_path = os.path.join(tmp, 'in.idf') with open(idf_path, 'w') as out: out.write(idf.idfstr()) shutil.copy(idd_path, tmp) shutil.copyfile(epw_path, os.path.join(tmp, 'in.epw')) copy_list = self.force_get_input('copy_list', None) if copy_list: relnames = copy_list.split(';') from vistrails.core import application app = application.get_vistrails_application() wf_path = app.get_vistrail().locator.name wf_folder = os.path.dirname(wf_path) for relname in relnames: absolute_path = os.path.normpath( os.path.join(wf_folder, relname)) shutil.copy(absolute_path, tmp) subprocess.check_call([energyplus_path], cwd=tmp) self.set_output('results', basic.PathObject(tmp))
def __init__(self, vistraildata): QtGui.QWidget.__init__(self) self._vistraildata = vistraildata _ = dat.gui.translate(VariablePanel) layout = QtGui.QVBoxLayout() toolbar = QtGui.QToolBar() toolbar.setIconSize(QtCore.QSize(24, 24)) new_variable = QtGui.QAction(get_icon('new_variable.png'), _("New variable..."), self) toolbar.addAction(new_variable) delete_variable = QtGui.QAction(get_icon('delete_variable.png'), _("Delete variable"), self) toolbar.addAction(delete_variable) rename_variable = QtGui.QAction(get_icon('rename_variable.png'), _("Rename variable..."), self) toolbar.addAction(rename_variable) layout.addWidget(toolbar) self._list_widget = DraggableListWidget(self, MIMETYPE_DAT_VARIABLE, use_overlay_lock=True) layout.addWidget(self._list_widget) self.setLayout(layout) # UI created; stop here if this panel is disabled if self._vistraildata is None: self.setEnabled(False) return self.connect(new_variable, QtCore.SIGNAL("triggered()"), self.new_variable) self.connect(delete_variable, QtCore.SIGNAL("triggered()"), self.delete_variable) self.connect(rename_variable, QtCore.SIGNAL("triggered()"), self.rename_variable) def select_variable(varname): varname = str(varname) self.variableSelected.emit(vistraildata.get_variable(varname)) self.connect(self._list_widget, QtCore.SIGNAL('currentTextChanged(QString)'), select_variable) self._variable_loader = LoadVariableDialog( self._vistraildata.controller, self) app = get_vistrails_application() app.register_notification('dat_new_variable', self.variable_added) app.register_notification('dat_removed_variable', self.variable_removed) for varname in self._vistraildata.variables: self.variable_added(self._vistraildata.controller, varname)
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 _add_variable(self, varname, renamed_from=None): if renamed_from is not None: # Variable was renamed -- reflect this change on the annotations for pipeline in self._version_to_pipeline.itervalues(): if any(p.type == RecipeParameterValue.VARIABLE and p.variable.name == varname for p_values in pipeline.recipe.parameters.itervalues() for p in p_values): self._controller.vistrail.set_action_annotation( pipeline.version, self._RECIPE_KEY, self._build_recipe_annotation(pipeline.recipe, pipeline.conn_map)) get_vistrails_application().send_notification( 'dat_new_variable', self._controller, varname, renamed_from=renamed_from)
def hook_close_tab(self, tab): if self._immortal_sheets.get(tab, False): return False try: vistraildata, sheet_id = self._tabs[tab] except KeyError: return True # Close the project if it was the last sheet if vistraildata._spreadsheet_tabs.keys() == [sheet_id]: get_vistrails_application().builderWindow.close_vistrail() return False else: del self._tabs[tab] # Remove the tab from the associated VistrailData del vistraildata._spreadsheet_tabs[sheet_id] del vistraildata._spreadsheet_tabs_rev[tab] return True
def compute(self): from vistrails.core import application app = application.get_vistrails_application() wf_path = app.get_vistrail().locator.name wf_folder = os.path.dirname(wf_path) relative_path = self.get_input('relative_path') relative_path = replace_vars(relative_path) absolute_path = os.path.normpath( os.path.join(wf_folder, relative_path)) self.set_output('absolute_path', basic.PathObject(absolute_path))
def set_controller(self, controller, register=False, _deferred=False, _auto=False): """Called through the notification mechanism. Changes the 'current' controller, optionally building a VistrailData for it if register is True. A VistrailData will not be built if register is not True, which means not every controller that Vistrail will use will be considered DAT controllers. This works around issues with internal controllers such as the one used by the query view. A DAT project has to be opened from DAT's 'File/Open' action. """ if _auto and controller == self._current_controller: # VisTrails sends 'controller_changed' a lot return if controller is not None and self._forgotten.get(controller, False): # Yes, 'controller_changed' can happen after 'controller_closed' # This is unfortunate return new = False self._current_controller = controller if _auto and self._deferred_controller_change: return if controller is not None and controller not in self._vistrails: if not register: warnings.warn("Current controller is not a DAT vistrail:\n" " %r" % controller) else: vistraildata = VistrailData(controller) name = self._make_ctrl_name(controller.name) vistraildata.name = name self._names[name] = vistraildata self._vistrails[controller] = vistraildata new = True get_vistrails_application().send_notification('dat_controller_changed', controller, new=new)
def setCellInfo(self, cellInfo): super(DATCellContainer, self).setCellInfo(cellInfo) if cellInfo is None: # We were removed from the spreadsheet app = get_vistrails_application() app.unregister_notification('dat_new_variable', self._variable_added) app.unregister_notification('dat_removed_variable', self._variable_removed) app.unregister_notification('dragging_to_overlays', self._set_dragging)
def set_controller(self, controller, register=False, _deferred=False, _auto=False): """Called through the notification mechanism. Changes the 'current' controller, optionally building a VistrailData for it if register is True. A VistrailData will not be built if register is not True, which means not every controller that Vistrail will use will be considered DAT controllers. This works around issues with internal controllers such as the one used by the query view. A DAT project has to be opened from DAT's 'File/Open' action. """ if _auto and controller == self._current_controller: # VisTrails sends 'controller_changed' a lot return if controller is not None and self._forgotten.get(controller, False): # Yes, 'controller_changed' can happen after 'controller_closed' # This is unfortunate return new = False self._current_controller = controller if _auto and self._deferred_controller_change: return if controller is not None and controller not in self._vistrails: if not register: warnings.warn("Current controller is not a DAT vistrail:\n" " %r" % controller) else: vistraildata = VistrailData(controller) name = self._make_ctrl_name(controller.name) vistraildata.name = name self._names[name] = vistraildata self._vistrails[controller] = vistraildata new = True get_vistrails_application().send_notification( 'dat_controller_changed', controller, new=new)
def _add_variable(self, varname, renamed_from=None): if renamed_from is not None: # Variable was renamed -- reflect this change on the annotations for pipeline in self._version_to_pipeline.itervalues(): if any( p.type == RecipeParameterValue.VARIABLE and p.variable.name == varname for p_values in pipeline.recipe.parameters.itervalues() for p in p_values): self._controller.vistrail.set_action_annotation( pipeline.version, self._RECIPE_KEY, self._build_recipe_annotation( pipeline.recipe, pipeline.conn_map)) get_vistrails_application().send_notification( 'dat_new_variable', self._controller, varname, renamed_from=renamed_from)
def _remove_variable(self, varname, renamed_to=None): get_vistrails_application().send_notification( 'dat_removed_variable', self._controller, varname, renamed_to=renamed_to) if renamed_to is None: # A variable was removed! # We'll remove all the mappings that used it to_remove = set([]) for pipeline in self._version_to_pipeline.itervalues(): if any( p.type == RecipeParameterValue.VARIABLE and p.variable.name == varname for p_values in pipeline.recipe.parameters.itervalues() for p in p_values): to_remove.add(pipeline.version) if to_remove: warnings.warn( "Variable %r was used in %d pipelines!" % ( varname, len(to_remove))) for version in to_remove: del self._version_to_pipeline[version] # Remove the annotations from the vistrail for key in ( self._RECIPE_KEY, self._PORTMAP_KEY): self._controller.vistrail.set_action_annotation( version, key, None) cell_to_remove = [] for cellInfo, version in self._cell_to_version.iteritems(): if version in to_remove: cell_to_remove.append(cellInfo) for cellInfo in cell_to_remove: del self._cell_to_version[cellInfo] del self._cell_to_pipeline[cellInfo]
def init(self): """Initialization function, called when the application is created. This is not done at module-import time to avoid complex import-order issues. """ app = get_vistrails_application() app.register_notification('controller_changed', lambda c: self.set_controller(c, _auto=True)) app.register_notification('controller_closed', self.forget_controller) app.register_notification('vistrail_saved', self.controller_name_changed) self.initialized = True
def replace_vars(s): """replaces variables in the string. Using the string.Template. Variables known: - $basename: the basename of the name of the workflow (without the '.vt') - $dirname: the folder the workflow resides in""" from vistrails.core import application from string import Template app = application.get_vistrails_application() wf_path = app.get_vistrail().locator.name dirname = os.path.dirname(wf_path) basename = os.path.basename(wf_path) basename = os.path.splitext(basename)[0] t = Template(s) return t.safe_substitute(dirname=dirname, basename=basename)
def get_vistrails_temp_configuration(): """get_vistrails_temp_configuration() -> ConfigurationObject or None Returns the temp configuration of the application. It returns None if configuration was not found (when running as a bogus application for example. The temp configuration is the one that is used just for the current session and is not persistent. To make changes persistent, use get_vistrails_persistent_configuration() instead. """ from vistrails.core.application import get_vistrails_application app = get_vistrails_application() if hasattr(app, 'temp_configuration'): return app.temp_configuration else: return None
def get_vistrails_persistent_configuration(): """get_vistrails_persistent_configuration() -> ConfigurationObject or None Returns the persistent configuration of the application. It returns None if configuration was not found (when running as a bogus application for example. Notice that this function should be use only to write configurations to the user's startup.xml file. Otherwise, use get_vistrails_configuration or get_vistrails_temp_configuration. """ from vistrails.core.application import get_vistrails_application app = get_vistrails_application() if hasattr(app, 'configuration'): return app.configuration else: return None
def init(self): """Initialization function, called when the application is created. This is not done at module-import time to avoid complex import-order issues. """ app = get_vistrails_application() app.register_notification( 'controller_changed', lambda c: self.set_controller(c, _auto=True)) app.register_notification( 'controller_closed', self.forget_controller) app.register_notification( 'vistrail_saved', self.controller_name_changed) self.initialized = True
def __init__(self): QtGui.QWidget.__init__(self) self._plots = dict() # Plot -> PlotItem layout = QtGui.QVBoxLayout() self._list_widget = PlotList(self, MIMETYPE_DAT_PLOT) layout.addWidget(self._list_widget) self.setLayout(layout) app = get_vistrails_application() app.register_notification('dat_new_plot', self.plot_added) app.register_notification('dat_removed_plot', self.plot_removed) for plot in GlobalManager.plots: self.plot_added(plot)
def test_external_upgrade(self): from vistrails.core.application import get_vistrails_application app = get_vistrails_application() app.new_vistrail() default_upgrade_on = app.temp_configuration.upgradeOn default_upgrade_delay = app.temp_configuration.upgradeDelay app.temp_configuration.upgradeOn = True app.temp_configuration.upgradeDelay = False created_vistrail = False try: pm = get_package_manager() pm.late_enable_package('upgrades', {'upgrades': 'vistrails.tests.resources.'}) app.new_vistrail() created_vistrail = True c = app.get_controller() current_version = self.create_workflow(c) for m in c.current_pipeline.modules.itervalues(): self.assertEqual(m.version, '0.8') c.change_selected_version(current_version, from_root=True) self.assertEqual(len(c.current_pipeline.modules), 2) for m in c.current_pipeline.modules.itervalues(): self.assertEqual(m.version, '1.0') if m.name == "TestUpgradeA": self.assertEqual(m.functions[0].name, 'aaa') self.assertEqual(len(c.current_pipeline.connections), 1) conn = c.current_pipeline.connections.values()[0] self.assertEqual(conn.source.name, 'zzz') self.assertEqual(conn.destination.name, 'b') finally: if created_vistrail: app.close_vistrail() try: pm.late_disable_package('upgrades') except MissingPackage: pass app.temp_configuration.upgradeOn = default_upgrade_on app.temp_configuration.upgradeDelay = default_upgrade_delay
def test_external_upgrade(self): from vistrails.core.application import get_vistrails_application app = get_vistrails_application() default_upgrades = app.temp_configuration.upgrades default_upgrade_delay = app.temp_configuration.upgradeDelay app.temp_configuration.upgrades = True app.temp_configuration.upgradeDelay = False created_vistrail = False pm = get_package_manager() try: pm.late_enable_package('upgrades', {'upgrades': 'vistrails.tests.resources.'}) app.new_vistrail() created_vistrail = True c = app.get_controller() current_version = self.create_workflow(c) for m in c.current_pipeline.modules.itervalues(): self.assertEqual(m.version, '0.8') c.change_selected_version(current_version, from_root=True) self.assertEqual(len(c.current_pipeline.modules), 2) for m in c.current_pipeline.modules.itervalues(): self.assertEqual(m.version, '1.0') if m.name == "TestUpgradeA": self.assertEqual(m.functions[0].name, 'aaa') self.assertEqual(len(c.current_pipeline.connections), 1) conn = c.current_pipeline.connections.values()[0] self.assertEqual(conn.source.name, 'zzz') self.assertEqual(conn.destination.name, 'b') finally: if created_vistrail: app.close_vistrail() try: pm.late_disable_package('upgrades') except MissingPackage: pass app.temp_configuration.upgrades = default_upgrades app.temp_configuration.upgradeDelay = default_upgrade_delay
def __init__(self): QtGui.QWidget.__init__(self) self._plots = dict() # Plot -> PlotItem layout = QtGui.QVBoxLayout() self._list_widget = PlotList( self, MIMETYPE_DAT_PLOT) layout.addWidget(self._list_widget) self.setLayout(layout) app = get_vistrails_application() app.register_notification('dat_new_plot', self.plot_added) app.register_notification('dat_removed_plot', self.plot_removed) for plot in GlobalManager.plots: self.plot_added(plot)
def __init__(self): QtGui.QWidget.__init__(self) _ = translate(OperationPanel) self.setAcceptDrops(True) self._operations = dict() # VariableOperation -> OperationItem layout = QtGui.QVBoxLayout() self._console = ConsoleWidget() layout.addWidget(self._console) layout.addWidget(QtGui.QLabel(_("Enter a command and press return"))) self._input_line = MarkerHighlighterLineEdit() self.connect(self._input_line, QtCore.SIGNAL('returnPressed()'), self.execute_line) layout.addWidget(self._input_line) layout.addWidget(QtGui.QLabel(_("Available operations:"))) self._list = CategorizedListWidget() self._list.setSelectionMode(QtGui.QAbstractItemView.NoSelection) self._list.header().setResizeMode(QtGui.QHeaderView.Stretch) self.connect( self._list, QtCore.SIGNAL('itemClicked(QTreeWidgetItem*, int)'), self.operation_clicked) layout.addWidget(self._list) self.setLayout(layout) app = get_vistrails_application() app.register_notification('dat_new_operation', self.operation_added) app.register_notification('dat_removed_operation', self.operation_removed) for operation in GlobalManager.variable_operations: self.operation_added(operation)
def __init__(self): QtGui.QWidget.__init__(self) _ = translate(OperationPanel) self.setAcceptDrops(True) self._operations = dict() # VariableOperation -> OperationItem layout = QtGui.QVBoxLayout() self._console = ConsoleWidget() layout.addWidget(self._console) layout.addWidget(QtGui.QLabel(_("Enter a command and press return"))) self._input_line = MarkerHighlighterLineEdit() self.connect(self._input_line, QtCore.SIGNAL('returnPressed()'), self.execute_line) layout.addWidget(self._input_line) layout.addWidget(QtGui.QLabel(_("Available operations:"))) self._list = CategorizedListWidget() self._list.setSelectionMode(QtGui.QAbstractItemView.NoSelection) self._list.header().setResizeMode(QtGui.QHeaderView.Stretch) self.connect(self._list, QtCore.SIGNAL('itemClicked(QTreeWidgetItem*, int)'), self.operation_clicked) layout.addWidget(self._list) self.setLayout(layout) app = get_vistrails_application() app.register_notification('dat_new_operation', self.operation_added) app.register_notification('dat_removed_operation', self.operation_removed) for operation in GlobalManager.variable_operations: self.operation_added(operation)
def run_multi_upgrade_test(self, pkg_remap): from vistrails.core.application import get_vistrails_application app = get_vistrails_application() created_vistrail = False pm = get_package_manager() try: pm.late_enable_package("upgrades", {"upgrades": "vistrails.tests.resources."}) app.new_vistrail() created_vistrail = True c = app.get_controller() self.create_workflow(c) p = c.current_pipeline actions = UpgradeWorkflowHandler.remap_module(c, 0, p, pkg_remap) finally: if created_vistrail: app.close_vistrail() try: pm.late_disable_package("upgrades") except MissingPackage: pass
def run_multi_upgrade_test(self, pkg_remap): from vistrails.core.application import get_vistrails_application app = get_vistrails_application() created_vistrail = False pm = get_package_manager() try: pm.late_enable_package('upgrades', {'upgrades': 'vistrails.tests.resources.'}) app.new_vistrail() created_vistrail = True c = app.get_controller() self.create_workflow(c) p = c.current_pipeline actions = UpgradeWorkflowHandler.remap_module(c, 0, p, pkg_remap) finally: if created_vistrail: app.close_vistrail() try: pm.late_disable_package('upgrades') except MissingPackage: pass
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 __exit__(self, exc_type, exc_val, exc_tb): get_vistrails_application().send_notification('dragging_to_overlays', False)
def saveAsFile(self): from vistrails.core.db.locator import DBLocator, FileLocator bw = get_vistrails_application().builderWindow bw.get_current_view().save_vistrail_as(bw.dbDefault and DBLocator or FileLocator())
def install_clicked(self, checked=False): from vistrails.core.application import get_vistrails_application app = get_vistrails_application() if app.ask_update_default_application(False): self.label.setText(".vt, .vtl handlers installed")
def _remove_plot(self, plot): del self._plots[(plot.package_identifier, plot.name)] get_vistrails_application().send_notification('dat_removed_plot', plot)
def _add_loader(self, loader): self._variable_loaders.add(loader) get_vistrails_application().send_notification('dat_new_loader', loader)
def _remove_loader(self, loader): self._variable_loaders.remove(loader) get_vistrails_application().send_notification('dat_removed_loader', loader)
def _add_plot(self, plot): self._plots[(plot.package_identifier, plot.name)] = plot get_vistrails_application().send_notification('dat_new_plot', plot)
def install(): app = get_vistrails_application() if app.ask_update_default_application(False): self._handler_status.setText(u".vt .vtl has a handler set")
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 _add_operation(self, operation): self._variable_operations.add(operation) get_vistrails_application().send_notification('dat_new_operation', operation)
def _remove_operation(self, operation): self._variable_operations.remove(operation) get_vistrails_application().send_notification('dat_removed_operation', operation)
def __init__(self, controller): """Initial setup of the VistrailData. Discovers plots and variable loaders from packages and registers notifications for packages loaded in the future. """ self._controller = controller self._spreadsheet_tabs = None # id: int -> spreadsheet_tab self._variables = dict() self._data_provenance = dict() # version: int -> provenance self._cell_to_version = dict() # CellInformation -> int self._version_to_pipeline = dict() # int -> PipelineInformation # CellInformation -> PipelineInformation self._cell_to_pipeline = dict() self._failed_infer_calls = set() # [version: int] app = get_vistrails_application() # dat_new_variable(varname: str) app.create_notification('dat_new_variable') # dat_removed_variable(varname: str) app.create_notification('dat_removed_variable') annotations = self._controller.vistrail.action_annotations # Load variables from tagged versions if self._controller.vistrail.has_tag_str('dat-vars'): # Load all data provenance annotations # Loading from known variables is not enough, we also need deleted # variables to form the complete graph for an in annotations: if an.key == self._DATA_PROVENANCE_KEY: version = an.action_id provenance = data_provenance.read_from_annotation(an.value) self._data_provenance[version] = provenance tagmap = self._controller.vistrail.get_tagMap() for version, tag in tagmap.iteritems(): if tag.startswith('dat-var-'): varname = tag[8:] # Get the type from the OutputPort module's spec input port type = Variable.read_type(get_upgraded_pipeline( self._controller.vistrail, version)) if type is None: warnings.warn("Found invalid DAT variable pipeline " "%r, ignored" % tag) continue # Get the data provenance provenance = self._data_provenance.get(version) variable = Variable.VariableInformation( varname, self._controller, type, provenance) self._variables[varname] = variable self._add_variable(varname) # Load mappings from annotations # First, read the recipes for an in annotations: if an.key == self._RECIPE_KEY: version = an.action_id recipe, conn_map = self._read_recipe_annotation(self, an.value) if recipe is not None: pipeline = PipelineInformation( version, recipe, conn_map, None) # to be filled by the next block self._version_to_pipeline[version] = pipeline # Then, read the port maps for an in annotations: if an.key == self._PORTMAP_KEY: pipeline = self._version_to_pipeline[an.action_id] if not pipeline: # Purge the lone port map warnings.warn("Found a DAT port map annotation with no " "associated recipe -- removing") self._controller.vistrail.set_action_annotation( an.action_id, an.key, None) else: port_map = self._read_portmap_annotation(an.value) if port_map is not None: pipeline.port_map = port_map
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 quitApplication(self): return get_vistrails_application().try_quit()
def __init__(self, vistraildata): QtGui.QWidget.__init__(self) self._vistraildata = vistraildata _ = dat.gui.translate(VariablePanel) layout = QtGui.QVBoxLayout() toolbar = QtGui.QToolBar() toolbar.setIconSize(QtCore.QSize(24, 24)) new_variable = QtGui.QAction(get_icon('new_variable.png'), _("New variable..."), self) toolbar.addAction(new_variable) delete_variable = QtGui.QAction(get_icon('delete_variable.png'), _("Delete variable"), self) toolbar.addAction(delete_variable) rename_variable = QtGui.QAction(get_icon('rename_variable.png'), _("Rename variable..."), self) toolbar.addAction(rename_variable) layout.addWidget(toolbar) self._list_widget = DraggableListWidget(self, MIMETYPE_DAT_VARIABLE, use_overlay_lock=True) layout.addWidget(self._list_widget) self.setLayout(layout) # UI created; stop here if this panel is disabled if self._vistraildata is None: self.setEnabled(False) return self.connect(new_variable, QtCore.SIGNAL("triggered()"), self.new_variable) self.connect(delete_variable, QtCore.SIGNAL("triggered()"), self.delete_variable) self.connect(rename_variable, QtCore.SIGNAL("triggered()"), self.rename_variable) def select_variable(varname): varname = str(varname) self.variableSelected.emit(vistraildata.get_variable(varname)) self.connect( self._list_widget, QtCore.SIGNAL('currentTextChanged(QString)'), select_variable) self._variable_loader = LoadVariableDialog( self._vistraildata.controller, self) app = get_vistrails_application() app.register_notification('dat_new_variable', self.variable_added) app.register_notification('dat_removed_variable', self.variable_removed) for varname in self._vistraildata.variables: self.variable_added(self._vistraildata.controller, varname)
def unregister_notifications(self): app = get_vistrails_application() app.unregister_notification('dat_new_variable', self.variable_added) app.unregister_notification('dat_removed_variable', self.variable_removed)
def saveAsFile(self): from vistrails.core.db.locator import DBLocator, FileLocator bw = get_vistrails_application().builderWindow bw.get_current_view().save_vistrail_as( bw.dbDefault and DBLocator or FileLocator())