def open_menu(self, position):
     menu = QtGui.QMenu()
     expand_all_action = QtGui.QAction('Expand all', self)
     expand_all_action.triggered.connect(self.expandAll)
     menu.addAction(expand_all_action)
     collapse_all_action = QtGui.QAction('Collapse all', self)
     collapse_all_action.triggered.connect(self.collapseAll)
     menu.addAction(collapse_all_action)
     menu.exec_(self.viewport().mapToGlobal(position))
Exemplo n.º 2
0
 def showContextMenuEvent(self, event):
     self.contextMenu = QtGui.QMenu()
     # Infos about the selected node.
     index = self.indexAt(event)
     if not index.isValid():
         return
     item = self.itemAt(event)
     name = item.text(0)
     if item.text(1) == 'Project':
         # self.contextMenu.addAction('Rename').triggered.connect(partial(self.editname, item))
         self.contextMenu.addAction('Add new dataset').triggered.connect(
             self.emitAddDataset)
     if name != self.project.name:
         # can't remove the top element without cloing the project
         self.contextMenu.addAction('Remove').triggered.connect(
             partial(self.emitRemove, item))
     self.contextMenu.popup(self.mapToGlobal(event))
Exemplo n.º 3
0
    def getMenu(self):
        """
        Create the menu
        """
        if self.menu is None:
            self.menu = QtGui.QMenu()

        self.PlotModeMenu = QtGui.QMenu("Plot mode")
        self.plotModeCombo = QtGui.QComboBox()
        self.modeItems = [
            'pen', 'scatter', 'scatter+pen', 'bar'
        ] if self.ndim < 2 else ['stack', 'map', 'image', 'surface']
        self.plotModeCombo.insertItems(1, self.modeItems)
        self.plotModeCombo.activated.connect(self.emitPlotModeChanged)
        self.plotModeAction = QtGui.QWidgetAction(None)
        self.plotModeAction.setDefaultWidget(self.plotModeCombo)
        self.PlotModeMenu.addAction(self.plotModeAction)
        self.menu.addMenu(self.PlotModeMenu)

        if self.ndim == 2:
            self.ColorMapMenu = QtGui.QMenu("Colormap")
            self.colorMapCombo = QtGui.QComboBox()
            self.colorMapItems = plt.colormaps()
            self.colorMapCombo.insertItems(1, self.colorMapItems)
            self.colorMapCombo.setCurrentIndex(
                self.colorMapItems.index(self.prefs.colormap))
            self.colorMapCombo.activated.connect(self.emitColorMapChanged)
            self.colorMapAction = QtGui.QWidgetAction(None)
            self.colorMapAction.setDefaultWidget(self.colorMapCombo)
            self.ColorMapMenu.addAction(self.colorMapAction)
            self.menu.addMenu(self.ColorMapMenu)

        self.LineMenu = QtGui.QMenu("Linewidth")
        self.lineSpinBox = pg.SpinBox(value=1, step=0.1, decimals=3)
        self.lineSpinBox.sigValueChanged.connect(self.emitLineWidthChanged)
        self.lineAction = QtGui.QWidgetAction(None)
        self.lineAction.setDefaultWidget(self.lineSpinBox)
        self.LineMenu.addAction(self.lineAction)
        self.menu.addMenu(self.LineMenu)

        self.viewAll = QtGui.QAction("Zoom reset", self.menu)
        self.viewAll.triggered.connect(self.autoRange)
        self.menu.addAction(self.viewAll)

        self.leftMenu = QtGui.QMenu("Left mouse click mode")
        group = QtGui.QActionGroup(self)
        pan = QtGui.QAction(u'Pan', self.leftMenu)
        zoom = QtGui.QAction(u'Zoom', self.leftMenu)
        self.leftMenu.addAction(pan)
        self.leftMenu.addAction(zoom)
        pan.triggered.connect(self.setPanMode)
        zoom.triggered.connect(self.setRectMode)
        pan.setCheckable(True)
        zoom.setCheckable(True)
        pan.setActionGroup(group)
        zoom.setActionGroup(group)
        self.menu.addMenu(self.leftMenu)

        self.menu.addSeparator()

        return self.menu
Exemplo n.º 4
0
    def __init__(self, show=True):

        super().__init__()

        pg.setConfigOption('background', 'w')
        pg.setConfigOption('foreground', 'k')

        siz = QtWidgets.QDesktopWidget().screenGeometry(-1)
        self.ww, self.wh = ww, wh = min(1500,
                                        siz.width() * .80), min(
                                            900,
                                            siz.height() * .80)
        self.move(QtCore.QPoint(10, 10))  # TODO: center it ?

        # --------------------------------------------------------------------------------------------------------------
        # Logging
        # --------------------------------------------------------------------------------------------------------------

        if not __DEV__:
            # production
            scp.app.log_level = logging.WARNING
        else:
            # development
            scp.app.log_level = logging.DEBUG

        # --------------------------------------------------------------------------------------------------------------
        # Main area
        # --------------------------------------------------------------------------------------------------------------

        self.area = area = LockedDockArea()
        self.setCentralWidget(area)
        self.setWindowIcon(QtGui.QIcon(str(geticon('scpy.png'))))
        self.setWindowTitle('SpectroChemPy GUI')

        # --------------------------------------------------------------------------------------------------------------
        # Create status bar
        # --------------------------------------------------------------------------------------------------------------

        self.statusbar = self.statusBar()
        self.statusbar.showMessage('Welcome to SpectroChemPy')

        # --------------------------------------------------------------------------------------------------------------
        # Create doc for plots
        # --------------------------------------------------------------------------------------------------------------

        # we need to create a dock object for this branch
        self.dplot = dplot = LockedDock('Plot', closable=False)
        dplot.hideTitleBar()

        # --------------------------------------------------------------------------------------------------------------
        # Create project window
        # --------------------------------------------------------------------------------------------------------------

        self.dproject = dproject = LockedDock("Project", size=(300, wh * .30))
        self.projectwidget = ProjectTreeWidget(showHeader=False, parent=self)

        self.project = Project(parent=self)

        dproject.addWidget(self.projectwidget)
        dproject.setMinimumWidth(300)
        dproject.setMaximumWidth(300)

        # --------------------------------------------------------------------------------------------------------------
        # Controller window
        # --------------------------------------------------------------------------------------------------------------

        dcontroller = LockedDock("Controller", size=(300, wh * .70))
        self.controller = Controller(parent=self)
        dcontroller.addWidget(self.controller)

        # --------------------------------------------------------------------------------------------------------------
        # set layout
        # --------------------------------------------------------------------------------------------------------------

        self.area.addDock(dproject, 'left')
        self.area.addDock(dplot, 'right')
        self.area.addDock(dcontroller, 'bottom', dproject)
        self.resize(ww, wh)

        # --------------------------------------------------------------------------------------------------------------
        # Create Menubar and actions
        # --------------------------------------------------------------------------------------------------------------

        # MENU FILE
        # -------------------------------------------------------------------

        project_menu = QtGui.QMenu('&Project', parent=self)
        self.menuBar().addMenu(project_menu)

        # Project menu
        # ----------------------------------------------------------------------------------------------------------

        self.new_action = QtGui.QAction('&New project', self)
        self.new_action.setShortcut(QtGui.QKeySequence.New)
        self.new_action.setStatusTip('Create a new main project')
        self.new_action.triggered.connect(
            partial(self.project.openProject, new=True))
        project_menu.addAction(self.new_action)

        self.open_action = QtGui.QAction('&Open project', self)
        self.open_action.setShortcut(QtGui.QKeySequence.Open)
        self.open_action.setStatusTip('Open a new main project')
        self.open_action.triggered.connect(
            partial(self.project.openProject, new=False))
        project_menu.addAction(self.open_action)

        # Dataset menu
        # --------------------------------------------------------------------------------------------------------------

        project_menu.addSeparator()

        self.add_dataset_action = QtGui.QAction('Add dataset', self)
        self.add_dataset_action.triggered.connect(self.project.addDataset)
        self.add_dataset_action.setShortcut(
            QtGui.QKeySequence('Ctrl+A', QtGui.QKeySequence.NativeText))
        self.add_dataset_action.setDisabled(True)
        project_menu.addAction(self.add_dataset_action)

        self.remove_dataset_action = QtGui.QAction('remove selected dataset',
                                                   self)
        self.remove_dataset_action.triggered.connect(
            self.project.removeDataset)
        self.remove_dataset_action.setShortcut(
            QtGui.QKeySequence('Ctrl+D', QtGui.QKeySequence.NativeText))
        self.remove_dataset_action.setDisabled(True)
        project_menu.addAction(self.remove_dataset_action)

        # Save project menu
        # ----------------------------------------------------------------------------------------------------------

        project_menu.addSeparator()

        self.save_action = QtGui.QAction('&Save project', self)
        self.save_action.setStatusTip('Save the entire project into a file')
        self.save_action.setShortcut(QtGui.QKeySequence.Save)
        self.save_action.triggered.connect(
            partial(self.project.saveProject, force=True))
        self.save_action.setDisabled(True)
        project_menu.addAction(self.save_action)

        self.save_as_action = QtGui.QAction('Save project as...', self)
        self.save_as_action.setStatusTip(
            'Save the entire project into a new file')
        self.save_as_action.setShortcut(QtGui.QKeySequence.SaveAs)
        self.save_as_action.triggered.connect(
            partial(self.project.saveProject, force=True, saveas=True))
        self.save_as_action.setDisabled(True)
        project_menu.addAction(self.save_as_action)

        # Close project menu
        # ----------------------------------------------------------------------------------------------------------

        project_menu.addSeparator()

        self.close_action = QtGui.QAction('Close project', self)
        self.close_action.setShortcut(
            QtGui.QKeySequence('Ctrl+Shift+W', QtGui.QKeySequence.NativeText))
        self.close_action.setStatusTip(
            'Close the main project and delete all data and plots out of '
            'memory')
        self.close_action.triggered.connect(self.project.closeProject)
        self.close_action.setDisabled(True)
        project_menu.addAction(self.close_action)

        # Quit
        # --------------------------------------------------------------------------------------------------------------

        if sys.platform != 'darwin':  # mac os makes this anyway
            quit_action = QtGui.QAction('Quit', self)
            quit_action.triggered.connect(
                QtCore.QCoreApplication.instance().quit)
            quit_action.setShortcut(QtGui.QKeySequence.Quit)
            project_menu.addAction(quit_action)

        self.menuBar().addMenu(project_menu)

        # Processing menu
        # ---------------
        proc_menu = QtGui.QMenu('Script', parent=self)
        self.menuBar().addMenu(proc_menu)

        # export script
        export_script_action = QtGui.QAction('Export script', self)
        export_script_action.triggered.connect(self.controller.exportScript)
        proc_menu.addAction(export_script_action)

        # import script
        import_script_action = QtGui.QAction('Import script', self)
        import_script_action.triggered.connect(self.controller.importScript)
        proc_menu.addAction(import_script_action)

        # Help menu
        # --------------------------------------------------------------------------------------------------------------

        help_menu = QtGui.QMenu('Help', parent=self)
        self.menuBar().addMenu(help_menu)

        # About

        about_action = QtGui.QAction('About', self)
        about_action.triggered.connect(self.onAbout)
        help_menu.addAction(about_action)

        # Preferences

        prefs_action = QtGui.QAction('Preferences', self)
        prefs_action.triggered.connect(lambda: self.onEditPreferences(True))
        prefs_action.setShortcut(QtGui.QKeySequence.Preferences)
        help_menu.addAction(prefs_action)

        # Documentation

        doc_action = QtGui.QAction('Documentationt', self)
        doc_action.triggered.connect(self.onDoc)
        help_menu.addAction(doc_action)

        # Console

        # console_action = QtGui.QAction('Console', self)
        # console_action.triggered.connect(self.show_console)
        # help_menu.addAction(console_action)

        if sys.platform == 'darwin':
            self.menuBar().setNativeMenuBar(
                False
            )  # this put the menu in the  #  window itself in OSX, as in windows.  # TODO: set this in
            # preferences

        self.preference_pages.extend([
            GeneralPreferencesWidget,
        ])

        # --------------------------------------------------------------------------------------------------------------
        # Signal connections
        # --------------------------------------------------------------------------------------------------------------

        # user requests
        self.projectwidget.sigDatasetSelected.connect(
            self.project.onSelectDataset)
        self.projectwidget.sigDatasetAdded.connect(self.project.addDataset)
        self.projectwidget.sigDatasetRemoved.connect(
            self.project.removeDataset)

        # model changes
        self.project.sigProjectChanged.connect(
            self.controller.onProjectChanged)
        self.project.sigDatasetChanged.connect(
            self.controller.onDatasetChanged)

        # --------------------------------------------------------------------------------------------------------------
        # Show window
        # --------------------------------------------------------------------------------------------------------------

        if show:
            self.show()
            self.controller.onProjectChanged('opened')