Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    def _get_spreadsheet_tabs(self):
        if self._spreadsheet_tabs is not None:
            return self._spreadsheet_tabs

        sh_window = spreadsheetController.findSpreadsheetWindow(create=False)
        if sh_window is None:
            return None
        tab_controller = sh_window.tabController

        # Get the cell location from the pipeline to fill in _cell_to_version
        # and _cell_to_pipeline
        cells = dict()
        sheet_sizes = dict()
        for pipeline in self._version_to_pipeline.itervalues():
            try:
                row, col, sheetname_var = get_pipeline_location(
                    self._controller,
                    pipeline)
                if sheetname_var.name.startswith('dat-sheet-'):
                    sheet_id = int(sheetname_var.name[10:])
                else:
                    raise ValueError
            except ValueError:
                continue
            try:
                p = cells[(row, col, sheet_id)]
            except KeyError:
                cells[(row, col, sheet_id)] = pipeline
                rowCount, colCount = sheet_sizes.get(sheet_id, (2, 2))
                rowCount = max(rowCount, row + 1)
                colCount = max(colCount, col + 1)
                sheet_sizes[sheet_id] = (rowCount, colCount)
            else:
                if pipeline.version > p.version:
                    # Select the latest version for a given cell
                    cells[(row, col, sheet_id)] = pipeline
        self._spreadsheet_tabs = dict()
        self._spreadsheet_tabs_rev = dict()
        for (row, col, sheet_id), pipeline in cells.iteritems():
            try:
                spreadsheet_tab = self._spreadsheet_tabs[sheet_id]
            except KeyError:
                rowCount, colCount = sheet_sizes.get(sheet_id, (2, 2))
                spreadsheet_tab = self.new_tab(
                    True,
                    tab_controller,
                    rowCount,
                    colCount,
                    sheet_id)[0]
            cellInfo = CellInformation(spreadsheet_tab, row, col)
            self._cell_to_pipeline[cellInfo] = pipeline
            self._cell_to_version[cellInfo] = pipeline.version

        if not self._spreadsheet_tabs:
            self.new_tab(True, tab_controller)

        return self._spreadsheet_tabs
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
 def compute(self):
     """ compute() -> None
     Dispatch SVG file into the spreadshet for display
     """
     if self.has_input("File"):
         window = spreadsheetController.findSpreadsheetWindow()
         file_to_display = self.get_input("File")
         fileValue = window.file_pool.make_local_copy(file_to_display.name)
     else:
         fileValue = None
     self.displayAndWait(SVGCellWidget, (fileValue,))
Exemplo n.º 5
0
 def __init__(self, parent=None):
     super(Workspace, self).__init__(parent)
     self.root=parent.root
     self.viewToItem = {}
     self.numProjects = 1
     self.setupUi(self)
     self.spreadsheetWindow = spreadsheetController.findSpreadsheetWindow(
                                                             show=False)
     self.connectSignals()
     self.currentProject = None
     self.current_controller = None
Exemplo n.º 6
0
 def compute(self):
     """ compute() -> None
     Dispatch SVG file into the spreadshet for display
     """
     if self.has_input("File"):
         window = spreadsheetController.findSpreadsheetWindow()
         file_to_display = self.get_input("File")
         fileValue = window.file_pool.make_local_copy(file_to_display.name)
     else:
         fileValue = None
     self.displayAndWait(SVGCellWidget, (fileValue, ))
Exemplo n.º 7
0
 def compute(self):
     """ compute() -> None
     Dispatch the display event to the spreadsheet with images and labels
     
     """
     if self.hasInputFromPort("File"):
         window = spreadsheetController.findSpreadsheetWindow()
         file_to_display = self.getInputFromPort("File")
         fileValue = window.file_pool.make_local_copy(file_to_display.name)
     else:
         fileValue = None
     self.displayAndWait(ImageViewerCellWidget, (fileValue, ))
Exemplo n.º 8
0
 def compute(self):
     """ compute() -> None
     Dispatch the display event to the spreadsheet with images and labels
     
     """
     if self.hasInputFromPort("File"):
         window = spreadsheetController.findSpreadsheetWindow()
         file_to_display = self.getInputFromPort("File")
         fileValue = window.file_pool.make_local_copy(file_to_display.name)
     else:
         fileValue = None
     self.displayAndWait(ImageViewerCellWidget, (fileValue, ))
Exemplo n.º 9
0
    def _get_spreadsheet_tabs(self):
        if self._spreadsheet_tabs is not None:
            return self._spreadsheet_tabs

        sh_window = spreadsheetController.findSpreadsheetWindow(create=False)
        if sh_window is None:
            return None
        tab_controller = sh_window.tabController

        # Get the cell location from the pipeline to fill in _cell_to_version
        # and _cell_to_pipeline
        cells = dict()
        sheet_sizes = dict()
        for pipeline in self._version_to_pipeline.itervalues():
            try:
                row, col, sheetname_var = get_pipeline_location(
                    self._controller, pipeline)
                if sheetname_var.name.startswith('dat-sheet-'):
                    sheet_id = int(sheetname_var.name[10:])
                else:
                    raise ValueError
            except ValueError:
                continue
            try:
                p = cells[(row, col, sheet_id)]
            except KeyError:
                cells[(row, col, sheet_id)] = pipeline
                rowCount, colCount = sheet_sizes.get(sheet_id, (2, 2))
                rowCount = max(rowCount, row + 1)
                colCount = max(colCount, col + 1)
                sheet_sizes[sheet_id] = (rowCount, colCount)
            else:
                if pipeline.version > p.version:
                    # Select the latest version for a given cell
                    cells[(row, col, sheet_id)] = pipeline
        self._spreadsheet_tabs = dict()
        self._spreadsheet_tabs_rev = dict()
        for (row, col, sheet_id), pipeline in cells.iteritems():
            try:
                spreadsheet_tab = self._spreadsheet_tabs[sheet_id]
            except KeyError:
                rowCount, colCount = sheet_sizes.get(sheet_id, (2, 2))
                spreadsheet_tab = self.new_tab(True, tab_controller, rowCount,
                                               colCount, sheet_id)[0]
            cellInfo = CellInformation(spreadsheet_tab, row, col)
            self._cell_to_pipeline[cellInfo] = pipeline
            self._cell_to_version[cellInfo] = pipeline.version

        if not self._spreadsheet_tabs:
            self.new_tab(True, tab_controller)

        return self._spreadsheet_tabs
Exemplo n.º 10
0
    def compute(self):
        """ compute() -> None
        Dispatch the display event to the spreadsheet with images and labels
        
        """

        if self.hasInputFromPort('in_dataset'):
            dataset = self.getInputFromPort('in_dataset')
            window = spreadsheetController.findSpreadsheetWindow()
            for f in dataset.files:
                if os.path.exists(f.full_path):
                    fileValue = window.file_pool.make_local_copy(f.full_path)
                    self.displayAndWait(ImageViewerCellWidget, (fileValue, ))
        else:
            self.displayAndWait(ImageViewerCellWidget, (None, ))
Exemplo n.º 11
0
    def compute(self):
        """ compute() -> None
        Dispatch the display event to the spreadsheet with images and labels
        
        """

        if self.hasInputFromPort('in_dataset'):
            dataset = self.getInputFromPort('in_dataset')
            window = spreadsheetController.findSpreadsheetWindow()
            for f in dataset.files:
                if os.path.exists(f.full_path):
                    fileValue = window.file_pool.make_local_copy(f.full_path)
                    self.displayAndWait(ImageViewerCellWidget, (fileValue, ))
        else:
            self.displayAndWait(ImageViewerCellWidget, (None, ))
Exemplo n.º 12
0
 def compute_output(self, output_module, configuration):
     fname = output_module.get_input('value').name
     window = spreadsheetController.findSpreadsheetWindow()
     local_file = window.file_pool.make_local_copy(fname)
     self.display_and_wait(output_module, configuration,
                           ImageViewerCellWidget, (local_file,))
Exemplo n.º 13
0
    def compute(self):
        """ compute() -> None
        Dispatch the display event to the spreadsheet with images and labels

        """
        model_workspace = utils.get_relative_path(self.get_input("ModelWorkspace"), self)

        if self.has_input("ModelWorkspace") and \
            utils.check_if_model_finished(model_workspace):

            auc_graph = text_output = response_curves = calibration_graph = None
            confusion_graph = residuals_graph = variable_graph = model_label = initial_display = None

            window = spreadsheetController.findSpreadsheetWindow()

            model_dir_full = os.path.normcase(model_workspace)
            model_dir = os.path.split(model_dir_full)[1]
            model_name = model_dir[:model_dir.index('_')]
            auc_graph_path = self.findFile(model_dir_full, '_modelEvalPlot.png')  #  os.path.join(model_dir_full, model_name + '_modelEvalPlot.jpg')
            if os.path.exists(auc_graph_path):
                auc_graph = window.file_pool.make_local_copy(auc_graph_path)

            text_output_path = self.findFile(model_dir_full, '_output.txt')  #  os.path.join(model_dir_full, model_name + '_output.txt')
            if os.path.exists(text_output_path):
                text_output = window.file_pool.make_local_copy(text_output_path)

            response_directory = os.path.join(model_dir_full, 'responseCurves')
            if os.path.exists(response_directory):
                responseCurveFiles = os.listdir(response_directory)
                response_curves = []
                for response_curve in responseCurveFiles:
                    if response_curve != "Thumbs.db":  #  Windows grief
                        response_curves.append(os.path.join(response_directory, response_curve))
            else:
                response_curves = []

            calibration_graph_path = self.findFile(model_dir_full, '_CalibrationPlot.png')  #  os.path.join(model_dir_full, model_name + '_CalibrationPlot.jpg')
            if os.path.exists(calibration_graph_path):
                calibration_graph = window.file_pool.make_local_copy(calibration_graph_path)

            confusion_graph_path = self.findFile(model_dir_full, '.confusion.matrix.png')  #  os.path.join(model_dir_full, model_name + '.confusion.matrix.jpg')
            if os.path.exists(confusion_graph_path):
                confusion_graph = window.file_pool.make_local_copy(confusion_graph_path)

            residuals_graph_path = self.findFile(model_dir_full, '.resid.plot.png')  #  os.path.join(model_dir_full, model_name + '.resid.plot.jpg')
            if os.path.exists(residuals_graph_path):
                residuals_graph = window.file_pool.make_local_copy(residuals_graph_path)

            variable_imp_path = self.findFile(model_dir_full, '_variable.importance.png')  #  os.path.join(model_dir_full, model_name + '_variable.importance.jpg')
            if os.path.exists(variable_imp_path):
                variable_graph = window.file_pool.make_local_copy(variable_imp_path)

            model_label = model_dir.capitalize().replace('output', 'Output')

            utils.set_sheet_location(self)

            if self.has_input('InitialModelOutputDisplay'):
                initial_display = self.get_input('InitialModelOutputDisplay')
            else:
                initial_display = 'AUC'

            self.cellWidget = self.displayAndWait(SAHMOutputViewerCellWidget, (auc_graph,
                                                                          text_output,
                                                                          response_curves,
                                                                          calibration_graph,
                                                                          confusion_graph,
                                                                          residuals_graph,
                                                                          variable_graph,
                                                                          model_label,
                                                                          initial_display))
        else:
            fileValue = None
Exemplo n.º 14
0
    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)
Exemplo n.º 15
0
Arquivo: window.py Projeto: rbax/DAT
    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)
Exemplo n.º 16
0
 def embedSpreadsheet(self):
     self.spreadsheetWindow = spreadsheetController.findSpreadsheetWindow(show=False)
     self.setCentralWidget(self.spreadsheetWindow)
     self.spreadsheetWindow.setVisible(True)