예제 #1
0
파일: pgplotitem.py 프로젝트: xyt556/argos
    def __init__(self,
                 borderPen=DEFAULT_BORDER_PEN,
                 *args, **kwargs):
        """ Constructor.

            :param borderPen: pen for drawing the viewBox border. Default black and width of 1.
        """
        super(ArgosPgPlotItem, self).__init__(*args, **kwargs)

        self.setMenuEnabled(False)
        #pg.setConfigOption('leftButtonPan', False)

        viewBox = self.getViewBox()
        viewBox.border = borderPen
        viewBox.setCursor(Qt.CrossCursor)
        viewBox.disableAutoRange(BOTH_AXES)
        viewBox.mouseClickEvent = lambda ev: self._axesMouseClickEvent(ev, BOTH_AXES)

        # Color of zoom-rectangle.
        alpha = 100
        greyVal = 160
        viewBox.rbScaleBox.setPen(pg.mkPen((0, 0, 0, alpha), width=2))
        viewBox.rbScaleBox.setBrush(pg.mkBrush(greyVal, greyVal, greyVal, alpha))

        # Add mouseClickEvent event handlers to the X and Y axis. This allows for resetting
        # the scale of each axes separately by middle mouse clicking the axis.
        for xAxisItem in (self.getAxis('bottom'), self.getAxis('top')):
            xAxisItem.mouseClickEvent = lambda ev: self._axesMouseClickEvent(ev, X_AXIS)
            xAxisItem.setCursor(Qt.SizeHorCursor)

        for yAxisItem in (self.getAxis('left'), self.getAxis('right')):
            yAxisItem.mouseClickEvent = lambda ev: self._axesMouseClickEvent(ev, Y_AXIS)
            yAxisItem.setCursor(Qt.SizeVerCursor)

        self.resetAxesAction = QtWidgets.QAction("Reset Axes", self,
                                 triggered = lambda: self.emitResetAxisSignal(BOTH_AXES),
                                 toolTip = "Resets the zoom factor of the X-axis and Y-axis")
        self.addAction(self.resetAxesAction)

        self.resetXAxisAction = QtWidgets.QAction("Reset X-axis", self,
                                 triggered = lambda: self.emitResetAxisSignal(X_AXIS),
                                 toolTip = "Resets the zoom factor of the X-axis")
        self.addAction(self.resetXAxisAction)

        self.resetYAxisAction = QtWidgets.QAction("Reset Y-axis", self,
                                 triggered = lambda: self.emitResetAxisSignal(Y_AXIS),
                                 toolTip = "Resets the zoom factor of the Y-axis")
        self.addAction(self.resetYAxisAction)
예제 #2
0
파일: mainwindow.py 프로젝트: xyt556/argos
    def _repopulateOpenAsMenu(self, *args, **kwargs):
        """ Clear the window menu and fills it with the actions of the actionGroup
        """
        logger.debug("Called repopulateOpenAsMenu")

        for action in self.openAsMenu.actions():
            self.openAsMenu.removeAction(action)

        rtiRegistry = self.argosApplication.rtiRegistry
        for rtiRegItem in (rtiRegistry.items + rtiRegistry.extraItemsForOpenAsMenu()):
            if not rtiRegItem.triedImport:
                rtiRegItem.tryImportClass()

            def createTrigger():
                "Function to create a closure with the regItem"
                _rtiRegItem = rtiRegItem # keep reference in closure
                return lambda: self.openFiles(rtiRegItem=_rtiRegItem,
                                              fileMode = QtWidgets.QFileDialog.ExistingFiles,
                                              caption="Open {}".format(_rtiRegItem.name))

            action = QtWidgets.QAction("{}...".format(rtiRegItem.name), self,
                enabled=bool(rtiRegItem.successfullyImported),
                triggered=createTrigger(), icon=rtiRegItem.decoration)

            self.openAsMenu.addAction(action)
예제 #3
0
    def __createInspectorActionGroup(self, parent):
        """ Creates an action group with 'set inspector' actions for all installed inspector.
        """
        actionGroup = QtWidgets.QActionGroup(parent)
        actionGroup.setExclusive(True)

        sortedItems = sorted(self.argosApplication.inspectorRegistry.items,
                             key=lambda item: item.identifier)
        shortCutNr = 1
        for item in sortedItems:
            logger.debug("item: {}".format(item.identifier))
            setAndDrawFn = partial(self.setAndDrawInspectorById,
                                   item.identifier)
            action = QtWidgets.QAction(item.name,
                                       self,
                                       triggered=setAndDrawFn,
                                       checkable=True)
            action.setData(item.identifier)
            if shortCutNr <= 9 and "debug" not in item.identifier:  # TODO: make configurable by the user
                action.setShortcut(
                    QtGui.QKeySequence("Ctrl+{}".format(shortCutNr)))
                shortCutNr += 1

            actionGroup.addAction(action)

        return actionGroup
예제 #4
0
파일: mainwindow.py 프로젝트: xyt556/argos
    def __setupViews(self):
        """ Creates the UI widgets.
        """
        self._collector = Collector(self.windowNumber)
        self._collector.sigShowMessage.connect(self.sigShowMessage)

        self.configWidget = ConfigWidget(self._configTreeModel)
        self.repoWidget = RepoWidget(self.argosApplication.repo, self.collector)

        # self._configTreeModel.insertItem(self.repoWidget.repoTreeView.config) # No configurable items yet

        # Define a central widget that will be the parent of the inspector widget.
        # We don't set the inspector directly as the central widget to retain the size when the
        # inspector is changed.
        self.mainWidget = QtWidgets.QWidget()
        self.mainLayout = QtWidgets.QVBoxLayout(self.mainWidget)
        self.mainLayout.setContentsMargins(0, 0, 0, 0)
        self.mainLayout.setSpacing(0)
        self.setCentralWidget(self.mainWidget)

        self.topPane = QtWidgets.QFrame()
        # self.topPane.setFrameStyle(QtWidgets.QFrame.Panel | QtWidgets.QFrame.Raised)
        # self.topPane.setLineWidth(1)
        self.mainLayout.addWidget(self.topPane)

        self.topLayout = QtWidgets.QHBoxLayout(self.topPane)
        self.topLayout.setContentsMargins(0, 0, 0, 0)
        self.topLayout.setSpacing(0)

        self.inspectorSelectionPane = InspectorSelectionPane(self.inspectorActionGroup)
        self.topLayout.addWidget(self.inspectorSelectionPane)
        self.sigInspectorChanged.connect(self.inspectorSelectionPane.updateFromInspectorRegItem)
        self.sigShowMessage.connect(self.inspectorSelectionPane.showMessage)

        showInspectorMenuAction = QtWidgets.QAction("ShowInspectorMenu", self,
            triggered=self.inspectorSelectionPane.menuButton.showMenu, checkable=False)
        showInspectorMenuAction.setShortcut("Ctrl+I")
        self.addAction(showInspectorMenuAction)

        self.wrapperWidget = QtWidgets.QWidget()
        self.mainLayout.addWidget(self.wrapperWidget)

        self.wrapperLayout = QtWidgets.QVBoxLayout(self.wrapperWidget)
        self.wrapperLayout.setContentsMargins(0, 0, 0, 0)
        self.wrapperLayout.setSpacing(0)
        self.wrapperLayout.addWidget(self.inspector)

        # Must be after setInspector since that already draws the inspector
        self.collector.sigContentsChanged.connect(self.collectorContentsChanged)
        self._configTreeModel.sigItemChanged.connect(self.configContentsChanged)

        # Populate table headers menu
        self.__addTableHeadersSubMenu("Data", self.repoWidget.repoTreeView)
        self.__addTableHeadersSubMenu("Settings", self.configWidget.configTreeView)
        self.__addTableHeadersSubMenu(
            "Properties", self.repoWidget.propertiesPane.table)
        self.__addTableHeadersSubMenu(
            "Attributes", self.repoWidget.attributesPane.table)
예제 #5
0
파일: mainwindow.py 프로젝트: xyt556/argos
    def _repopulateOpenRecentMenu(self, *args, **kwargs):
        """ Clear the window menu and fills it with the actions of the actionGroup
        """
        logger.debug("Called _repopulateOpenRecentMenu")
        rtiIconFactory = RtiIconFactory.singleton()

        for action in self.openRecentMenu.actions():
            self.openRecentMenu.removeAction(action)

        # Count duplicate basename. These will be added with their full path.
        baseNameCount = {}
        for _timeStamp, fileName, _rtiRegName in self._argosApplication.getRecentFiles():
            _, baseName = os.path.split(fileName)
            if baseName in baseNameCount:
                baseNameCount[baseName] += 1
            else:
                baseNameCount[baseName] = 1

        # List returned by getRecentFiles is already sorted.
        for _timeStamp, fileName, rtiRegItemName in self._argosApplication.getRecentFiles():

            regItemId = nameToIdentifier(rtiRegItemName)
            rtiRegItem = self.argosApplication.rtiRegistry.getItemById(regItemId)

            # Bit of a hack to use a Directory RegItem, which is not in the registry.
            if rtiRegItem is None:
                directoryRtiRegItem = self.argosApplication.rtiRegistry.DIRECTORY_REG_ITEM
                if rtiRegItemName == 'Directory':
                    rtiRegItem = directoryRtiRegItem

            if rtiRegItem and not rtiRegItem.triedImport:
                rtiRegItem.tryImportClass()

            def createTrigger():
                "Function to create a closure with the regItem"
                _fileNames = [fileName] # keep reference in closure
                _rtiRegItem = rtiRegItem # keep reference in closure
                return lambda: self.openFiles(_fileNames, rtiRegItem=_rtiRegItem)

            dirName, baseName = os.path.split(fileName)
            fileLabel = fileName if baseNameCount[baseName] > 1 else baseName

            action = QtWidgets.QAction(fileLabel, self, enabled=True, triggered=createTrigger())
            action.setToolTip(fileName)
            if rtiRegItem is not None:
                action.setIcon(rtiRegItem.decoration)
            else:
                # Reserve space
                action.setIcon(rtiIconFactory.getIcon(RtiIconFactory.TRANSPARENT, False))

            self.openRecentMenu.addAction(action)
예제 #6
0
 def __init__(self, *args, histHeightPercentile=99.0, **kwargs):
     """ Constructor
     """
     super(ArgosColorLegendItem,
           self).__init__(*args,
                          histHeightPercentile=histHeightPercentile,
                          **kwargs)
     self.resetColorScaleAction = QtWidgets.QAction("Reset Color Range",
                                                    self)
     self.resetColorScaleAction.triggered.connect(
         self.emitResetColorScaleSignal)
     self.resetColorScaleAction.setToolTip(
         "Reset the range of the color scale.")
     self.addAction(self.resetColorScaleAction)
예제 #7
0
    def addHeaderContextMenu(self, checked=None, checkable=None, enabled=None):
        """ Adds the context menu from using header information

            checked can be a header_name -> boolean dictionary. If given, headers
            with the key name will get the checked value from the dictionary.
            The corresponding column will be hidden if checked is False.

            checkable can be a header_name -> boolean dictionary. If given, header actions
            with the key name will get the checkable value from the dictionary. (Default True)

            enabled can be a header_name -> boolean dictionary. If given, header actions
            with the key name will get the enabled value from the dictionary. (Default True)
        """
        checked = checked if checked is not None else {}
        checkable = checkable if checkable is not None else {}
        enabled = enabled if enabled is not None else {}

        horizontal_header = self.horizontalHeader()
        horizontal_header.setContextMenuPolicy(Qt.ActionsContextMenu)

        self.toggle_column_actions_group = QtWidgets.QActionGroup(self)
        self.toggle_column_actions_group.setExclusive(False)
        self.__toggle_functions = []  # for keeping references

        for col in range(horizontal_header.count()):
            column_label = self.model().headerData(col, Qt.Horizontal,
                                                   Qt.DisplayRole)
            #logger.debug("Adding: col {}: {}".format(col, column_label))
            action = QtWidgets.QAction(
                str(column_label),
                self.toggle_column_actions_group,
                checkable=checkable.get(column_label, True),
                enabled=enabled.get(column_label, True),
                toolTip="Shows or hides the {} column".format(column_label))
            func = self.__makeShowColumnFunction(col)
            self.__toggle_functions.append(func)  # keep reference
            horizontal_header.addAction(action)
            is_checked = checked.get(
                column_label, not horizontal_header.isSectionHidden(col))
            horizontal_header.setSectionHidden(col, not is_checked)
            action.setChecked(is_checked)
            action.toggled.connect(func)
예제 #8
0
파일: repotreeview.py 프로젝트: whigg/argos
    def createOpenAsMenu(self, parent=None):
        """ Creates the submenu for the Open As choice
        """
        openAsMenu = QtWidgets.QMenu(parent=parent)
        openAsMenu.setTitle("Open Item As")

        registry = globalRtiRegistry()
        for rtiRegItem in registry.items:
            #rtiRegItem.tryImportClass()
            def createTrigger():
                """Function to create a closure with the regItem"""
                _rtiRegItem = rtiRegItem  # keep reference in closure
                return lambda: self.reloadFileOfCurrentItem(_rtiRegItem)

            action = QtWidgets.QAction(
                "{}".format(rtiRegItem.name),
                self,
                enabled=bool(rtiRegItem.successfullyImported is not False),
                triggered=createTrigger())
            openAsMenu.addAction(action)

        return openAsMenu
예제 #9
0
파일: mainwindow.py 프로젝트: xyt556/argos
    def __createInspectorActionGroup(self, parent):
        """ Creates an action group with 'set inspector' actions for all installed inspector.
        """
        actionGroup = QtWidgets.QActionGroup(parent)
        actionGroup.setExclusive(True)

        for item in self.argosApplication.inspectorRegistry.items:
            logger.debug("__createInspectorActionGroup item: {} {}".format(item.identifier, item._data))
            setAndDrawFn = partial(self.setAndDrawInspectorById, item.identifier)
            action = QtWidgets.QAction(item.name, self, triggered=setAndDrawFn, checkable=True)
            action.setData(item.identifier)
            if item.shortCut:
                try:
                    keySeq = QtGui.QKeySequence(item.shortCut.strip())
                except Exception as ex:
                    logger.warning("Unable to create short cut from: '{}".format(item.shortCut))
                else:
                    action.setShortcut(QtGui.QKeySequence(keySeq))

            actionGroup.addAction(action)

        return actionGroup
예제 #10
0
    def _populateOpenAsMenu(self, openAsMenu):
        """ Repopulates the submenu for the Open Item choice (which is used to reload files).
        """
        registry = globalRtiRegistry()
        for rtiRegItem in (registry.items +
                           registry.extraItemsForOpenAsMenu()):

            if not rtiRegItem.triedImport:
                rtiRegItem.tryImportClass()

            def createTrigger():
                """Function to create a closure with the regItem"""
                _rtiRegItem = rtiRegItem  # keep reference in closure
                return lambda: self.reloadFileOfCurrentItem(_rtiRegItem)

            action = QtWidgets.QAction(
                "{}".format(rtiRegItem.name),
                self,
                enabled=bool(rtiRegItem.successfullyImported is not False),
                triggered=createTrigger(),
                icon=rtiRegItem.decoration)
            openAsMenu.addAction(action)

        return openAsMenu
예제 #11
0
    def __init__(self, repoTreeModel, collector, parent=None):
        """ Constructor.

            Maintains a reference to a collector. The repo tree view updates the collector when
            the currentIndex changes.
        """
        super(RepoTreeView, self).__init__(treeModel=repoTreeModel,
                                           parent=parent)

        self._collector = collector
        self._config = self._createConfig()

        treeHeader = self.header()
        treeHeader.resizeSection(RepoTreeModel.COL_NODE_NAME,
                                 COL_NODE_NAME_WIDTH)
        treeHeader.resizeSection(RepoTreeModel.COL_SHAPE, COL_SHAPE_WIDTH)
        treeHeader.resizeSection(RepoTreeModel.COL_ELEM_TYPE,
                                 COL_ELEM_TYPE_WIDTH)
        treeHeader.setStretchLastSection(True)

        headerNames = self.model().horizontalHeaders
        enabled = dict((name, True) for name in headerNames)
        enabled[headerNames[
            RepoTreeModel.COL_NODE_NAME]] = False  # Cannot be unchecked
        checked = dict((name, False) for name in headerNames)
        checked[headerNames[RepoTreeModel.COL_NODE_NAME]] = True
        checked[headerNames[RepoTreeModel.COL_SHAPE]] = True
        checked[headerNames[RepoTreeModel.COL_ELEM_TYPE]] = True
        self.addHeaderContextMenu(checked=checked,
                                  enabled=enabled,
                                  checkable={})

        self.setContextMenuPolicy(
            Qt.DefaultContextMenu)  # will call contextMenuEvent
        self.setUniformRowHeights(True)
        #self.setIconSize(QtCore.QSize(16, 16))

        # Add actions
        self.currentItemActionGroup = QtWidgets.QActionGroup(self)
        self.currentItemActionGroup.setExclusive(False)

        removeFileAction = QtWidgets.QAction(
            "Remove from Tree",
            self.currentItemActionGroup,
            shortcut=QtGui.QKeySequence.Delete,
            triggered=self.removeCurrentItem)
        self.addAction(removeFileAction)

        reloadFileAction = QtWidgets.QAction(
            "Reload File",
            self.currentItemActionGroup,
            shortcut=QtGui.QKeySequence.Refresh,  #"Ctrl+R",
            triggered=self.reloadFileOfCurrentItem)
        self.addAction(reloadFileAction)

        self.openItemAction = QtWidgets.QAction("Open Item",
                                                self,
                                                triggered=self.openCurrentItem)
        self.addAction(self.openItemAction)

        self.closeItemAction = QtWidgets.QAction(
            "Close Item", self, triggered=self.closeCurrentItem)
        self.addAction(self.closeItemAction)

        self.collapseItemAction = QtWidgets.QAction(
            "Collapse Item", self, triggered=self.collapseCurrentItem)
        self.addAction(self.collapseItemAction)

        # Connect signals
        selectionModel = self.selectionModel(
        )  # need to store reference to prevent crash in PySide
        selectionModel.currentChanged.connect(self.currentItemChanged)

        # Close files on collapse. Note that, self.collapsed does NOT seem to be connected to self.collapse by default,
        # so there is not conflict here. Also there is no need to connect to expand, this is automatic with the
        # fetchMore mechanism
        self.collapsed.connect(self.closeItem)

        self.model().sigItemChanged.connect(self.repoTreeItemChanged)
        self.model().sigAllChildrenRemovedAtIndex.connect(self.collapse)
예제 #12
0
파일: repotreeview.py 프로젝트: whigg/argos
    def __init__(self, repoTreeModel, collector, parent=None):
        """ Constructor.

            Maintains a reference to a collector. The repo tree view updates the collector when
            the currentIndex changes.
        """
        super(RepoTreeView, self).__init__(treeModel=repoTreeModel,
                                           parent=parent)

        self._collector = collector
        self._config = self._createConfig()

        treeHeader = self.header()
        treeHeader.resizeSection(RepoTreeModel.COL_NODE_NAME,
                                 COL_NODE_NAME_WIDTH)
        treeHeader.resizeSection(RepoTreeModel.COL_SHAPE, COL_SHAPE_WIDTH)
        treeHeader.resizeSection(RepoTreeModel.COL_ELEM_TYPE,
                                 COL_ELEM_TYPE_WIDTH)
        treeHeader.setStretchLastSection(True)

        headerNames = self.model().horizontalHeaders
        enabled = dict((name, True) for name in headerNames)
        enabled[headerNames[
            RepoTreeModel.COL_NODE_NAME]] = False  # Cannot be unchecked
        checked = dict((name, False) for name in headerNames)
        checked[headerNames[RepoTreeModel.COL_NODE_NAME]] = True
        checked[headerNames[RepoTreeModel.COL_SHAPE]] = False
        checked[headerNames[RepoTreeModel.COL_ELEM_TYPE]] = False
        self.addHeaderContextMenu(checked=checked,
                                  enabled=enabled,
                                  checkable={})

        self.setContextMenuPolicy(
            Qt.DefaultContextMenu)  # will call contextMenuEvent
        self.setUniformRowHeights(True)
        #self.setIconSize(QtCore.QSize(16, 16))

        # Add actions
        self.topLevelItemActionGroup = QtWidgets.QActionGroup(
            self)  # TODO: not used anymore?
        self.topLevelItemActionGroup.setExclusive(False)
        self.currentItemActionGroup = QtWidgets.QActionGroup(self)
        self.currentItemActionGroup.setExclusive(False)

        removeFileAction = QtWidgets.QAction(
            "Remove from Tree",
            self.currentItemActionGroup,
            shortcut=QtGui.QKeySequence.Delete,
            triggered=self.removeCurrentItem)
        self.addAction(removeFileAction)

        reloadFileAction = QtWidgets.QAction(
            "Reload File",
            self.currentItemActionGroup,
            shortcut=QtGui.QKeySequence.Refresh,  #"Ctrl+R",
            triggered=self.reloadFileOfCurrentItem)
        self.addAction(reloadFileAction)

        self.openItemAction = QtWidgets.QAction(
            "Open Item",
            self,
            #shortcut="Ctrl+Shift+C",
            triggered=self.openCurrentItem)
        self.addAction(self.openItemAction)

        self.closeItemAction = QtWidgets.QAction(
            "Close Item",
            self,
            #shortcut="Ctrl+C", # Ctrl+C already taken for Copy
            triggered=self.closeCurrentItem)
        self.addAction(self.closeItemAction)

        # Connect signals
        selectionModel = self.selectionModel(
        )  # need to store reference to prevent crash in PySide
        selectionModel.currentChanged.connect(self.currentItemChanged)

        self.model().sigItemChanged.connect(self.repoTreeItemChanged)
예제 #13
0
파일: mainwindow.py 프로젝트: xyt556/argos
    def __setupMenus(self):
        """ Sets up the main menu.
        """
        if True:
            # Don't use self.menuBar(), on OS-X this is not shared across windows.
            # See: http://qt-project.org/doc/qt-4.8/qmenubar.html#details
            # And:http://qt-project.org/doc/qt-4.8/qmainwindow.html#menuBar
            menuBar = QtWidgets.QMenuBar() # Make a menu without parent.
            self.setMenuBar(menuBar)
        else:
            menuBar = self.menuBar()

        ### File Menu ###

        fileMenu = menuBar.addMenu("&File")

        fileMenu.addAction("&New Window", self.cloneWindow, QtGui.QKeySequence("Ctrl+N"))
        fileMenu.addAction("Close &Window", self.close, QtGui.QKeySequence.Close)

        fileMenu.addSeparator()

        action = fileMenu.addAction("Browse Directory...",
            lambda: self.openFiles(fileMode = QtWidgets.QFileDialog.Directory))
        action.setShortcut(QtGui.QKeySequence("Ctrl+B"))

        action = fileMenu.addAction("&Open Files...",
            lambda: self.openFiles(fileMode = QtWidgets.QFileDialog.ExistingFiles))
        action.setShortcut(QtGui.QKeySequence("Ctrl+O"))

        self.openAsMenu = fileMenu.addMenu("Open As")
        self.openAsMenu.aboutToShow.connect(self._repopulateOpenAsMenu)

        self.openRecentMenu = fileMenu.addMenu("Open Recent")
        self.openRecentMenu.aboutToShow.connect(self._repopulateOpenRecentMenu)

        fileMenu.addSeparator()

        fileMenu.addSeparator()
        fileMenu.addAction("E&xit", self.argosApplication.quit, 'Ctrl+Q')

        ### View Menu ###

        self.viewMenu = menuBar.addMenu("&View")

        self.inspectorActionGroup = self.__createInspectorActionGroup(self)
        for action in self.inspectorActionGroup.actions():
            self.viewMenu.addAction(action)

        self.viewMenu.addSeparator()
        self.panelsMenu = self.viewMenu.addMenu("&Panels")
        self.tableHeadersMenu = self.viewMenu.addMenu("&Table Headers")

        ### Config Menu ###
        self.configMenu = menuBar.addMenu("Configure")

        app = self.argosApplication
        action = self.configMenu.addAction("&File Format Plugins...",
            lambda: self.execPluginsDialog("File Formats", app.rtiRegistry))
        if DEBUGGING:
            action.setShortcut(QtGui.QKeySequence("Ctrl+P"))

        action = self.configMenu.addAction("&Inspector Plugins...",
            lambda: self.execPluginsDialog("Inspectors", app.inspectorRegistry))
        # if DEBUGGING:
        #     action.setShortcut(QtGui.QKeySequence("Ctrl+P"))

        self.configMenu.addSeparator()

        self.configMenu.addAction(
            "Show Config Files...",
            lambda: self.openInExternalApp(argosConfigDirectory()))

        ### Window Menu ###
        self.windowMenu = menuBar.addMenu("&Window")

        # The action added to the menu in the repopulateWindowMenu method, which is called by
        # the ArgosApplication object every time a window is added or removed.
        self.activateWindowAction = QtWidgets.QAction(
            "Window #{}".format(self.windowNumber), self,
            triggered=self.activateAndRaise, checkable=True)
        if self.windowNumber <= 9:
            self.activateWindowAction.setShortcut(QtGui.QKeySequence(
                "Alt+{}".format(self.windowNumber)))

        ### Help Menu ###
        menuBar.addSeparator()
        helpMenu = menuBar.addMenu("&Help")
        helpMenu.addAction(
            "&Online Documentation...",
            lambda: self.openInWebBrowser("https://github.com/titusjan/argos#argos"))

        helpMenu.addSeparator()

        helpMenu.addAction(
            "Show Log Files...",
            lambda: self.openInExternalApp(argosLogDirectory()))

        helpMenu.addAction('&About...', self.about)

        if TESTING or DEBUGGING:
            helpMenu.addSeparator()
            helpMenu.addAction("&My Test", self.myTest, "Meta+T")
            helpMenu.addAction("&Test Walk Current", self.testWalkCurrentNode, "Meta+W")
            helpMenu.addAction("&Extensive Test Walk", self.testWalk, "Meta+E")
            helpMenu.addAction("Add Test Data", self.addTestData, "Meta+A")
예제 #14
0
    def __setupMenus(self):
        """ Sets up the main menu.
        """
        if True:
            # Don't use self.menuBar(), on OS-X this is not shared across windows.
            # See: http://qt-project.org/doc/qt-4.8/qmenubar.html#details
            # And:http://qt-project.org/doc/qt-4.8/qmainwindow.html#menuBar
            menuBar = QtWidgets.QMenuBar()  # Make a menu without parent.
            self.setMenuBar(menuBar)
        else:
            menuBar = self.menuBar()

        ### File Menu ###

        fileMenu = menuBar.addMenu("&File")

        fileMenu.addAction("&New Window", self.cloneWindow,
                           QtGui.QKeySequence("Ctrl+N"))
        fileMenu.addAction("Close &Window", self.close,
                           QtGui.QKeySequence.Close)

        fileMenu.addSeparator()

        action = fileMenu.addAction(
            "Browse Directory...",
            lambda: self.openFiles(fileMode=QtWidgets.QFileDialog.Directory))
        action.setShortcut(QtGui.QKeySequence("Ctrl+B"))

        action = fileMenu.addAction(
            "&Open Files...", lambda: self.openFiles(
                fileMode=QtWidgets.QFileDialog.ExistingFiles))
        action.setShortcut(QtGui.QKeySequence("Ctrl+O"))

        openAsMenu = fileMenu.addMenu("Open As")
        for rtiRegItem in self.argosApplication.rtiRegistry.items:
            #rtiRegItem.tryImportClass()
            def createTrigger():
                "Function to create a closure with the regItem"
                _rtiRegItem = rtiRegItem  # keep reference in closure
                return lambda: self.openFiles(
                    rtiRegItem=_rtiRegItem,
                    fileMode=QtWidgets.QFileDialog.ExistingFiles,
                    caption="Open {}".format(_rtiRegItem.name))

            action = QtWidgets.QAction(
                "{}...".format(rtiRegItem.name),
                self,
                enabled=
                True,  # Since this is only executed at start-up, it must be static
                #enabled=bool(rtiRegItem.successfullyImported), # TODO: make this work?
                triggered=createTrigger())
            openAsMenu.addAction(action)

        fileMenu.addSeparator()

        # for action in self.repoWidget.repoTreeView.topLevelItemActionGroup.actions():
        #     fileMenu.addAction(action)
        #
        # for action in self.repoWidget.repoTreeView.currentItemActionGroup.actions():
        #     fileMenu.addAction(action)

        fileMenu.addSeparator()
        fileMenu.addAction("E&xit", self.argosApplication.closeAllWindows,
                           QtGui.QKeySequence.Quit)

        ### View Menu ###
        self.viewMenu = menuBar.addMenu("&View")
        action = self.viewMenu.addAction("Installed &Plugins...",
                                         self.execPluginsDialog)
        action.setShortcut(QtGui.QKeySequence("Ctrl+P"))
        self.viewMenu.addSeparator()

        ### Inspector Menu ###
        self.execInspectorDialogAction = QtWidgets.QAction(
            "&Browse Inspectors...", self, triggered=self.execInspectorDialog)
        self.execInspectorDialogAction.setShortcut(
            QtGui.QKeySequence("Ctrl+i"))

        self.inspectorActionGroup = self.__createInspectorActionGroup(self)
        self.inspectorMenu = menuBar.addMenu("Inspector")
        addInspectorActionsToMenu(self.inspectorMenu,
                                  self.execInspectorDialogAction,
                                  self.inspectorActionGroup)

        ### Window Menu ###
        self.windowMenu = menuBar.addMenu("&Window")

        # The action added to the menu in the repopulateWindowMenu method, which is called by
        # the ArgosApplication object every time a window is added or removed.
        self.activateWindowAction = QtWidgets.QAction(
            "Window #{}".format(self.windowNumber),
            self,
            triggered=self.activateAndRaise,
            checkable=True)
        if self.windowNumber <= 9:
            self.activateWindowAction.setShortcut(
                QtGui.QKeySequence("Alt+{}".format(self.windowNumber)))
        ### Help Menu ###
        menuBar.addSeparator()
        helpMenu = menuBar.addMenu("&Help")
        helpMenu.addAction('&About...', self.about)

        if DEBUGGING:
            helpMenu.addSeparator()
            helpMenu.addAction("&Test", self.myTest, "Alt+T")
            helpMenu.addAction("Add Test Data", self.addTestData, "Alt+A")

        ### Context menu ###

        # Note that the dock-widgets have a Qt.PreventContextMenu context menu policy.
        # Therefor the context menu is only shown in the center widget.
        self.setContextMenuPolicy(Qt.CustomContextMenu)
        self.customContextMenuRequested.connect(self.showContextMenu)
예제 #15
0
    def __init__(self, configTreeModel, parent=None):
        """ Constructor.
            :param parent:
        """
        super(ConfigWidget, self).__init__(parent=parent)

        # Actions that change the reset mode of the reset button
        self.modeActionGroup = QtWidgets.QActionGroup(self)
        self.modeActionGroup.setExclusive(True)

        self.modeAllAction = QtWidgets.QAction("Reset All",
                                               self.modeActionGroup)
        self.modeAllAction.setToolTip(
            "Changes button reset mode to reset all settings")
        self.modeAllAction.setCheckable(True)
        self.modeAllAction.triggered.connect(
            lambda: self.setResetMode(ResetMode.All))

        self.modeRangeAction = QtWidgets.QAction("Reset Ranges",
                                                 self.modeActionGroup)
        self.modeRangeAction.setToolTip(
            "Changes button reset mode to reset axes")
        self.modeRangeAction.setCheckable(True)
        self.modeRangeAction.triggered.connect(
            lambda: self.setResetMode(ResetMode.Ranges))

        # Sanity check that actions have been added to action group
        assert self.modeActionGroup.actions(
        ), "Sanity check. resetActionGroup is empty"

        # Actions that actually reset the settings

        self.resetAllAction = QtWidgets.QAction("Reset All", self)
        self.resetAllAction.setToolTip("Resets all settings.")
        self.resetAllAction.setIcon(
            QtGui.QIcon(os.path.join(icons_directory(), 'reset-l.svg')))
        self.resetAllAction.setShortcut("Ctrl+=")

        self.resetRangesAction = QtWidgets.QAction("Reset Ranges", self)
        self.resetRangesAction.setToolTip(
            "Resets range of all plots, color scales, table column/row sizes etc."
        )
        self.resetRangesAction.setIcon(
            QtGui.QIcon(os.path.join(icons_directory(), 'reset-l.svg')))
        self.resetRangesAction.setShortcut("Ctrl+0")

        self.resetButtonMenu = QtWidgets.QMenu()
        self.resetButtonMenu.addAction(self.resetAllAction)
        self.resetButtonMenu.addAction(self.resetRangesAction)
        self.resetButtonMenu.addSection("Default")
        self.resetButtonMenu.addAction(self.modeAllAction)
        self.resetButtonMenu.addAction(self.modeRangeAction)

        # Widgets

        self.mainLayout = QtWidgets.QVBoxLayout(self)
        self.mainLayout.setSpacing(5)
        self.mainLayout.setContentsMargins(DOCK_MARGIN, DOCK_MARGIN,
                                           DOCK_MARGIN, DOCK_MARGIN)

        self.configTreeView = ConfigTreeView(configTreeModel, parent=self)
        self.mainLayout.addWidget(self.configTreeView)

        self.buttonLayout = QtWidgets.QHBoxLayout()
        self.mainLayout.addLayout(self.buttonLayout)

        self.autoCheckBox = QtWidgets.QCheckBox("Auto")
        self.autoCheckBox.setToolTip(
            "Auto reset when a new item or axis is selected.")
        self.autoCheckBox.setChecked(True)

        self.resetButton = QtWidgets.QToolButton()
        self.resetButton.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        self.resetButton.setDefaultAction(self.resetButtonMenu.defaultAction())
        self.resetButton.setPopupMode(QtWidgets.QToolButton.MenuButtonPopup)
        self.resetButton.setMenu(self.resetButtonMenu)

        # Set font size to the same as used for push buttons
        dummyButton = QtWidgets.QPushButton("dummy")
        fontSize = dummyButton.font().pointSize()
        del dummyButton

        logger.debug(
            "Setting QToolButtons font size to: {} point".format(fontSize))
        font = self.resetButton.font()
        font.setPointSizeF(fontSize)
        self.resetButton.setFont(font)

        self.buttonLayout.addStretch()
        self.buttonLayout.addWidget(self.autoCheckBox)
        self.buttonLayout.addWidget(self.resetButton)
        self.buttonLayout.addStretch()

        self.autoCheckBox.stateChanged.connect(self.setAutoReset)
        self.resetRangesAction.triggered.connect(
            self.configTreeView.resetAllRanges)
        self.resetAllAction.triggered.connect(
            self.configTreeView.resetAllSettings)

        self.setResetMode(self.configTreeView.resetMode)