Exemple #1
0
 def buildContextMenu(self, index):    
     contextMenu = { 
         "text": "Context",
         "items": [
             {   "text": "New",
                 "items": [
                     self.actionNewFolder, 
                     self.actionNewFile, 
                     "-", 
                     self.actionNewFromTemplate, 
                     self.actionNewProject,
                 ]
             },
             "--refresh",
             self.actionRefresh,
             "--bundles"
         ]
     }
     if index.isValid():
         node = self.projectTreeProxyModel.node(index)
         self.extendFileSystemItemMenu(contextMenu, node)
         self.extendAddonsItemMenu(contextMenu, node)
         self.extendProjectBundleItemMenu(contextMenu, node)
     # contextMenu = create_menu(contextMenu, self, separatorName = True)
     contextMenu = create_menu(self, contextMenu, separatorName = True)
     
     contextMenu.aboutToShow.connect(self.on_contextMenu_aboutToShow)
     contextMenu.aboutToHide.connect(self.on_contextMenu_aboutToHide)
     contextMenu.triggered.connect(self.on_contextMenu_triggered)
     return contextMenu
Exemple #2
0
    def __init__(self, **kwargs):
        super(ExternalProcessDock, self).__init__(**kwargs)
        self.processTableModel = self.application().supportManager.processTableModel
        self.setupUi(self)
        self.tableViewExternalProcess.activated.connect(self.on_tableViewExternalProcess_activated)
        self.tableViewExternalProcess.doubleClicked.connect(self.on_tableViewExternalProcess_doubleClicked)
        self.tableViewExternalProcess.setModel(self.processTableModel)

        #Setup Context Menu
        contextMenu = { 
            "text": "Process",
            "items": [ 
                { "text": "Close",
                  "triggered": self.on_actionCloseProcess_triggered },
                { "text": "Kill",
                  "triggered": self.on_actionKill_triggered },
                { "text": "Terminate",
                  "triggered": self.on_actionTerminate_triggered },
                "-",
                { "text": "Send Signal",
                  "items": [{ "text": "%s (%s)" % (key_value[0], key_value[1]),
                          "triggered": lambda _, signal = key_value[1]: self.on_actionSendSignal_triggered(signal)
                        } for key_value in sorted(iter(osextra.SIGNALS.items()), key = lambda k_v: k_v[1])]
                }
            ]
        }
        self.processMenu = create_menu(self, contextMenu)
        
        self.tableViewExternalProcess.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.tableViewExternalProcess.customContextMenuRequested.connect(self.showTableViewExternalProcessContextMenu)
Exemple #3
0
    def buildContextMenu(self, index):
        contextMenu = {
            "text":
            "Context",
            "items": [{
                "text":
                "New",
                "items": [
                    self.actionNewFolder,
                    self.actionNewFile,
                    "-",
                    self.actionNewFromTemplate,
                    self.actionNewProject,
                ]
            }, "--refresh", self.actionRefresh, "--bundles"]
        }
        if index.isValid():
            node = self.projectTreeProxyModel.node(index)
            self.extendFileSystemItemMenu(contextMenu, node)
            self.extendAddonsItemMenu(contextMenu, node)
            self.extendProjectBundleItemMenu(contextMenu, node)
        # contextMenu, contextMenuActions = create_menu(contextMenu, self, useSeparatorName = True)
        contextMenu, contextMenuActions = create_menu(self, contextMenu)

        for action in contextMenuActions:
            if hasattr(action, "callback"):
                action.triggered.connect(action.callback)

        contextMenu.aboutToShow.connect(self.on_contextMenu_aboutToShow)
        contextMenu.aboutToHide.connect(self.on_contextMenu_aboutToHide)
        contextMenu.triggered.connect(self.on_contextMenu_triggered)
        return contextMenu
Exemple #4
0
        def extendMainMenu(klass):
            menuExtensions = issubclass(klass, PrymatexComponent) and klass.contributeToMainMenu() or None
            if menuExtensions is not None:
                objects = []
                for name, settings in menuExtensions.items():
                    if not settings:
                        continue
    
                    # Find parent menu
                    parentMenu = self.findChild(QtGui.QMenu, 
                        text_to_objectname(name, prefix = "menu"))
                    # Extend
                    if parentMenu is not None:
                        # Fix menu extensions
                        if not isinstance(settings, list):
                            settings = [ settings ]
                        objects += extend_menu(parentMenu, settings,
                            dispatcher = self.componentInstanceDispatcher,
                            sequence_handler = self.application.registerShortcut,
                            icon_resolver = resources.get_icon)
                    else:
                        objs = create_menu(self, settings,
                            dispatcher = self.componentInstanceDispatcher,
                            allObjects = True,
                            sequence_handler = self.application.registerShortcut,
                            icon_resolver = resources.get_icon)
                        add_actions(self.menuBar(), [ objs[0] ], settings.get("before", None))
                        objects += objs

                # Store all new objects from creation or extension
                self.customComponentObjects.setdefault(klass, []).extend(objects)

                for componentClass in self.application.pluginManager.findComponentsForClass(klass):
                    extendMainMenu(componentClass)
Exemple #5
0
    def setupToolBar(self):
        #Setup Context Menu
        optionsMenu = { 
            "text": "Browser Options",
            "items": [ self.actionSyncEditor, self.actionConnectEditor ]
        }

        self.browserOptionsMenu = create_menu(self, optionsMenu)
        self.toolButtonOptions.setMenu(self.browserOptionsMenu)
Exemple #6
0
    def setupToolBar(self):
        #Setup Context Menu
        optionsMenu = {
            "text": "Browser Options",
            "items": [self.actionSyncEditor, self.actionConnectEditor]
        }

        self.browserOptionsMenu, _ = create_menu(self, optionsMenu)
        self.toolButtonOptions.setMenu(self.browserOptionsMenu)
Exemple #7
0
    def setupToolBar(self):
        #Setup Context Menu
        optionsMenu = { 
            "text": "Browser Options",
            "items": [ ]
        }

        self.browserOptionsMenu, objects = create_menu(self, optionsMenu)
        self.toolButtonOptions.setMenu(self.browserOptionsMenu)
Exemple #8
0
 def _not_index_context_menu(self):
     action_new_project = self.window().findChild(
         QtWidgets.QAction, "actionNewProject"
     )
     action_open_project = self.window().findChild(
         QtWidgets.QAction, "actionOpenProject"
     )
     contextMenu = { 
         'text': "Not index context",
         'items': [ action_new_project, action_open_project ]
     }
     contextMenu, objects = create_menu(self, contextMenu)
     return contextMenu
Exemple #9
0
    def __init__(self, parent):
        QtGui.QDockWidget.__init__(self, parent)
        self.setWindowTitle(_("External process"))
        self.setObjectName(_("ExternalProcessDock"))
        PMXBaseDock.__init__(self)
        self.processTableModel = self.application.supportManager.processTableModel
        self.tableViewProcess = QtGui.QTableView()
        self.tableViewProcess.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
        self.tableViewProcess.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
        self.tableViewProcess.setShowGrid(False)
        self.tableViewProcess.horizontalHeader().setVisible(False)
        self.tableViewProcess.verticalHeader().setVisible(False)
        self.tableViewProcess.horizontalHeader().setResizeMode(QtGui.QHeaderView.ResizeToContents)
        self.tableViewProcess.verticalHeader().setResizeMode(QtGui.QHeaderView.ResizeToContents)
        self.tableViewProcess.activated.connect(self.on_tableViewProcess_activated)
        self.tableViewProcess.doubleClicked.connect(self.on_tableViewProcess_doubleClicked)
        self.tableViewProcess.setModel(self.processTableModel)
        self.setWidget(self.tableViewProcess)

        #Setup Context Menu
        contextMenu = { 
            "text": "Process",
            "items": [ 
                { "text": "Close",
                  "callback": self.on_actionCloseProcess_triggered },
                { "text": "Kill",
                  "callback": self.on_actionKill_triggered },
                { "text": "Terminate",
                  "callback": self.on_actionTerminate_triggered },
                "-",
                { "text": "Send Signal",
                  "items": map(lambda (key, value):
                        { "text": "%s (%s)" % (key, value),
                          "callback": lambda _, signal = value: self.on_actionSendSignal_triggered(signal)
                        }, sorted(SIGNALS.iteritems(), key = lambda (k, v): v))
                }
            ]
        }
        self.processMenu, self.processMenuActions = create_menu(self, contextMenu)

        for action in self.processMenuActions:
            if hasattr(action, "callback"):
                action.triggered.connect(action.callback)
        
        self.tableViewProcess.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.tableViewProcess.customContextMenuRequested.connect(self.showtableViewProcessContextMenu)
Exemple #10
0
    def setupTreeViewProjects(self):
        self.treeViewProjects.setModel(self.projectTreeProxyModel)

        self.treeViewProjects.setHeaderHidden(True)
        self.treeViewProjects.setUniformRowHeights(False)

        #Setup Context Menu
        optionsMenu = {
            "text":
            "Project Options",
            "items": [{
                "text":
                "Order",
                "items":
                [(self.actionOrderByName, self.actionOrderBySize,
                  self.actionOrderByDate, self.actionOrderByType), "-",
                 self.actionOrderDescending, self.actionOrderFoldersFirst]
            }]
        }

        self.actionOrderFoldersFirst.setChecked(True)
        self.actionOrderByName.trigger()

        self.projectOptionsMenu, _ = create_menu(self, optionsMenu)
        self.pushButtonOptions.setMenu(self.projectOptionsMenu)

        #Connect context menu
        self.treeViewProjects.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.treeViewProjects.customContextMenuRequested.connect(
            self.showProjectTreeViewContextMenu)

        #=======================================================================
        # Drag and Drop (see the proxy model)
        #=======================================================================
        self.treeViewProjects.setDragEnabled(True)
        self.treeViewProjects.setAcceptDrops(True)
        self.treeViewProjects.setDefaultDropAction(QtCore.Qt.MoveAction)
        self.treeViewProjects.setDropIndicatorShown(True)

        self.treeViewProjects.setAlternatingRowColors(True)
        self.treeViewProjects.setAnimated(True)

        # Selection Mode
        self.treeViewProjects.setSelectionMode(
            QtGui.QAbstractItemView.ExtendedSelection)
Exemple #11
0
    def setupTreeViewProjects(self):
        self.treeViewProjects.setModel(self.projectTreeProxyModel)
        
        self.treeViewProjects.setHeaderHidden(True)
        self.treeViewProjects.setUniformRowHeights(False)
        
        #Setup Context Menu
        optionsMenu = { 
            "text": "Project Options",
            "items": [
                {   "text": "Order",
                    "items": [
                        (self.actionOrderByName, self.actionOrderBySize, self.actionOrderByDate, self.actionOrderByType),
                        "-", self.actionOrderDescending, self.actionOrderFoldersFirst
                    ]
                }
            ]
        }

        self.actionOrderFoldersFirst.setChecked(True)
        self.actionOrderByName.trigger()
        
        self.projectOptionsMenu = create_menu(self, optionsMenu)
        self.pushButtonOptions.setMenu(self.projectOptionsMenu)

        #Connect context menu
        self.treeViewProjects.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.treeViewProjects.customContextMenuRequested.connect(self.showProjectTreeViewContextMenu)
        
        #=======================================================================
        # Drag and Drop (see the proxy model)
        #=======================================================================
        self.treeViewProjects.setDragEnabled(True)
        self.treeViewProjects.setAcceptDrops(True)
        self.treeViewProjects.setDefaultDropAction(QtCore.Qt.MoveAction)
        self.treeViewProjects.setDropIndicatorShown(True)

        self.treeViewProjects.setAlternatingRowColors(True)
        self.treeViewProjects.setAnimated(True)
        
        # Selection Mode
        self.treeViewProjects.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
Exemple #12
0
 def _indexes_context_menu(self, indexes):
     indexed_nodes = [(index, self.projectTreeProxyModel.node(index)) \
         for index in indexes]
     items = []
     items.extend(self._project_menu_items(indexed_nodes))
     items.extend(self._source_folder_menu_items(indexed_nodes))
     items.extend(self._directory_menu_items(indexed_nodes))
     items.extend(self._file_menu_items(indexed_nodes))
     items.extend(self._path_menu_items(indexed_nodes))
     items.extend(self._has_children_menu_items(indexed_nodes))
     items.extend(self._bundles_menu_items(indexed_nodes))
     items.extend([{
         'text': "Settings",
         'triggered': lambda checked=False, values=indexes: [ self.settingsDialog(value) for value in values ]
         }])
     contextMenu = {
         'text': "Index context",
         'items': items
     }
     contextMenu, objects = create_menu(self, contextMenu)
     return contextMenu
Exemple #13
0
    def __init__(self, **kwargs):
        super(ExternalProcessDock, self).__init__(**kwargs)
        self.setWindowTitle(_("External process"))
        self.setObjectName(_("ExternalProcessDock"))
        self.processTableModel = self.application.supportManager.processTableModel
        self.tableViewProcess = QtGui.QTableView()
        self.tableViewProcess.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
        self.tableViewProcess.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
        self.tableViewProcess.setShowGrid(False)
        self.tableViewProcess.horizontalHeader().setVisible(False)
        self.tableViewProcess.verticalHeader().setVisible(False)
        self.tableViewProcess.horizontalHeader().setResizeMode(QtGui.QHeaderView.ResizeToContents)
        self.tableViewProcess.verticalHeader().setResizeMode(QtGui.QHeaderView.ResizeToContents)
        self.tableViewProcess.activated.connect(self.on_tableViewProcess_activated)
        self.tableViewProcess.doubleClicked.connect(self.on_tableViewProcess_doubleClicked)
        self.tableViewProcess.setModel(self.processTableModel)
        self.setWidget(self.tableViewProcess)

        #Setup Context Menu
        contextMenu = { 
            "text": "Process",
            "items": [ 
                { "text": "Close",
                  "triggered": self.on_actionCloseProcess_triggered },
                { "text": "Kill",
                  "triggered": self.on_actionKill_triggered },
                { "text": "Terminate",
                  "triggered": self.on_actionTerminate_triggered },
                "-",
                { "text": "Send Signal",
                  "items": [{ "text": "%s (%s)" % (key_value[0], key_value[1]),
                          "triggered": lambda _, signal = key_value[1]: self.on_actionSendSignal_triggered(signal)
                        } for key_value in sorted(iter(osextra.SIGNALS.items()), key = lambda k_v: k_v[1])]
                }
            ]
        }
        self.processMenu = create_menu(self, contextMenu)
        
        self.tableViewProcess.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.tableViewProcess.customContextMenuRequested.connect(self.showtableViewProcessContextMenu)
Exemple #14
0
    def extend(self, klass, parent=None):
        # Build handlers
        dispatcher = partial(self.componentInstanceDispatcher, klass)
        sequence_handler = partial(self.registerShortcut, klass)
        icon_handler = partial(self.registerIcon, klass)
        
        menuExtensions = issubclass(klass, PrymatexComponent) and \
            klass.contributeToMainMenu() or {}
        for name, settings in menuExtensions.items():
            # Find parent menu
            menu = self.parent().findChild(QtWidgets.QMenu, 
                text_to_objectname(name, prefix="menu"))

            # Extend menu or create new one
            if menu is None:
                menu, objects = create_menu(parent, settings,
                    dispatcher = dispatcher,
                    sequence_handler = sequence_handler,
                    icon_handler = icon_handler)
                add_actions(self, [ menu ], settings.get("before", None), prefix="actionMenu")
            else:
                objects = extend_menu(menu,
                    isinstance(settings, (list, tuple)) and settings or [settings],
                    dispatcher = dispatcher,
                    sequence_handler = sequence_handler,
                    icon_handler = icon_handler)
            
            menu.aboutToShow.connect(
                lambda klass=klass, objects=objects: self.on_menu_aboutToShow(klass, objects)
            )

        # Store all actions for component
        # self.componentActions.setdefault(klass, []).extend(actions + [m.menuAction() for m in menus])
        
        for componentClass in self.parent().application().findComponentsForClass(klass):
            self.extend(componentClass, parent)
Exemple #15
0
    def setupMenues(self):
        #Setup Context Menu
        def order_by(attr):
            def _order_by(checked):
                self.projectTreeProxyModel.sortBy(
                    attr,
                    self.actionFoldersFirst.isChecked(),
                    self.actionDescending.isChecked()
                )
            return _order_by
        def sync_editor(checked):
            if checked:
                #Conectar señal
                self.window().editorChanged.connect(self.on_window_editorChanged)
                self.on_window_editorChanged(self.window().currentEditor())
            else:
                #Desconectar señal
                self.window().editorChanged.disconnect(self.on_window_editorChanged)
        menu_options = {
            "text": "Project Options",
            "items": [
                {
                    'text': "Sync with current editor",
                    'checkable': True,
                    'triggered': sync_editor
                },
                {
                    'text': "Collapse all",
                    'triggered': lambda checked=False: self.treeViewProjects.collapseAll()
                },
                {   "text": "Order",
                    "items": [
                        tuple([{
                            'text': "By %s" % attr,
                            'checkable': True,
                            'triggered': order_by(attr)
                        } for attr in ["name", "size", "date", "type"]
                        ]), "-",
                        {
                            'text': "Descending",
                            'checkable': True,
                            'triggered': order_by(self.projectTreeProxyModel.orderBy)
                        },
                        {
                            'text': "Folders first",
                            'checkable': True,
                            'triggered': order_by(self.projectTreeProxyModel.orderBy)
                        }
                    ]
                }
            ]
        }
        
        self.projectOptionsMenu, objects = create_menu(self, menu_options)
        self.actionByName = [obj for obj in objects if obj.objectName() == 'actionByName'].pop()
        self.actionDescending = [obj for obj in objects if obj.objectName() == 'actionDescending'].pop()
        self.actionFoldersFirst = [obj for obj in objects if obj.objectName() == 'actionFoldersFirst'].pop()
        self.actionByName.setChecked(True)
        self.actionFoldersFirst.trigger()
        self.toolButtonOptions.setMenu(self.projectOptionsMenu)

        #Connect context menu
        self.treeViewProjects.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.treeViewProjects.customContextMenuRequested.connect(
            self.on_treeViewProjects_customContextMenuRequested)