Exemplo n.º 1
0
 def _selected_menu_default(self):
     root = MenuManager(name="selected_menu")
     actions = [
         Action(name="Delete point",
                on_perform=self.do_delete_selected_point),
         ]
     for a in actions:
         root.append(a)
     return root
    def _create_window(self):
        box = Box(bounds=[100.0, 100.0], position=[50.0, 50.0])
        menu = MenuManager()
        menu.append(Action(name="Hello World", on_perform=self.hello))
        context_menu = ContextMenuTool(component=box, menu_manager=menu)

        box.tools.append(context_menu)
        container = Container(bounds=[500, 500])
        container.add(box)
        return Window(self, -1, component=container)
Exemplo n.º 3
0
    def _create_window(self):
        box = Box(bounds=[100.0, 100.0], position=[50.0, 50.0])
        menu=MenuManager()
        menu.append(Action(name="Hello World", on_perform=self.hello))
        context_menu = ContextMenuTool(component=box, menu_manager=menu)

        box.tools.append(context_menu)
        container = Container(bounds=[500,500])
        container.add(box)
        return Window(self, -1, component=container)
Exemplo n.º 4
0
    def get_context_menu(self, pos):
        """ Returns a context menu containing split/collapse actions

        pos : position (in global coordinates) where the context menu was
        requested
        """
        menu = MenuManager()
        splitter = None

        splitter = None
        for tabwidget in self.tabwidgets():
            # obtain tabwidget's bounding rectangle in global coordinates
            global_rect = QtCore.QRect(tabwidget.mapToGlobal(QtCore.QPoint(0, 0)),
                                        tabwidget.size())
            if global_rect.contains(pos):
                splitter = tabwidget.parent()

        # no split/collapse context menu for positions outside any tabwidget
        # region
        if not splitter:
            return

        # add split actions (only show for non-empty tabwidgets)
        if not splitter.is_empty():
            actions = [Action(id='split_hor', name='Create new pane to the right',
                       on_perform=lambda : splitter.split(orientation=
                        QtCore.Qt.Horizontal)),
                       Action(id='split_ver', name='Create new pane to the bottom',
                       on_perform=lambda : splitter.split(orientation=
                        QtCore.Qt.Vertical))]

            splitgroup = Group(*actions, id='split')
            menu.append(splitgroup)

        # add collapse action (only show for collapsible splitters)
        if splitter.is_collapsible():
            if splitter is splitter.parent().leftchild:
                if splitter.parent().orientation() is QtCore.Qt.Horizontal:
                    text = 'Merge with right pane'
                else:
                    text = 'Merge with bottom pane'
            else:
                if splitter.parent().orientation() is QtCore.Qt.Horizontal:
                    text = 'Merge with left pane'
                else:
                    text = 'Merge with top pane'
            actions = [Action(id='merge', name=text,
                        on_perform=lambda : splitter.collapse())]

            collapsegroup = Group(*actions, id='collapse')
            menu.append(collapsegroup)

        # return QMenu object
        return menu
Exemplo n.º 5
0
    def _menu_bar_manager_default(self):
        # Create an action that exits the application.
        exit_action = Action(name='E&xit', on_perform=self.close)
        self.exit_action = exit_action
        file_menu = MenuManager(name='&File')
        file_menu.append(Group(exit_action))

        self.undo = UndoAction(undo_manager=self.undo_manager,
                               accelerator='Ctrl+Z')
        self.redo = RedoAction(undo_manager=self.undo_manager,
                               accelerator='Ctrl+Shift+Z')
        menu_bar_manager = MenuBarManager(
            file_menu, MenuManager(self.undo, self.redo, name='&Edit'))
        return menu_bar_manager
Exemplo n.º 6
0
    def _menu_bar_manager_default(self):
        # Create an action that exits the application.
        exit_action = Action(name='E&xit', on_perform=self.close)
        self.exit_action = exit_action
        file_menu = MenuManager(name='&File')
        file_menu.append(Group(exit_action))

        self.undo = UndoAction(undo_manager=self.undo_manager,
                               accelerator='Ctrl+Z')
        self.redo = RedoAction(undo_manager=self.undo_manager,
                               accelerator='Ctrl+Shift+Z')
        menu_bar_manager = MenuBarManager(
            file_menu,
            MenuManager(
                self.undo,
                self.redo,
                name='&Edit')
        )
        return menu_bar_manager
Exemplo n.º 7
0
    def get_context_menu(self, pos):
        """ Return a context menu containing split/collapse actions.

        Parameters
        ----------
        pos : QtCore.QPoint
            Mouse position in global coordinates for which the context menu was
            requested.

        Returns
        -------
        menu : pyface.action.menu_manager.MenuManager or None
            Context menu, or None if the given position doesn't correspond
            to any of the tab widgets.
        """
        menu = MenuManager()

        for tabwidget in self.tabwidgets():
            widget_pos = tabwidget.mapFromGlobal(pos)
            if tabwidget.rect().contains(widget_pos):
                splitter = tabwidget.parent()
                break
        else:
            # no split/collapse context menu for positions outside any
            # tabwidget region
            return None

        # add split actions (only show for non-empty tabwidgets)
        if not splitter.is_empty():
            split_group = Group(
                Action(
                    id="split_hor",
                    name="Create new pane to the right",
                    on_perform=lambda: splitter.split(orientation=QtCore.Qt.
                                                      Horizontal),
                ),
                Action(
                    id="split_ver",
                    name="Create new pane below",
                    on_perform=lambda: splitter.split(orientation=QtCore.Qt.
                                                      Vertical),
                ),
                id="split",
            )
            menu.append(split_group)

        # add collapse action (only show for collapsible splitters)
        if splitter.is_collapsible():
            if splitter is splitter.parent().leftchild:
                if splitter.parent().orientation() == QtCore.Qt.Horizontal:
                    text = "Merge with right pane"
                else:
                    text = "Merge with bottom pane"
            else:
                if splitter.parent().orientation() == QtCore.Qt.Horizontal:
                    text = "Merge with left pane"
                else:
                    text = "Merge with top pane"

            collapse_group = Group(
                Action(
                    id="merge",
                    name=text,
                    on_perform=lambda: splitter.collapse(),
                ),
                id="collapse",
            )
            menu.append(collapse_group)

        return menu
Exemplo n.º 8
0
    def get_context_menu(self, pos):
        """ Returns a context menu containing split/collapse actions

        pos : position (in global coordinates) where the context menu was
        requested
        """
        menu = MenuManager()
        splitter = None

        splitter = None
        for tabwidget in self.tabwidgets():
            # obtain tabwidget's bounding rectangle in global coordinates
            global_rect = QtCore.QRect(
                tabwidget.mapToGlobal(QtCore.QPoint(0, 0)), tabwidget.size())
            if global_rect.contains(pos):
                splitter = tabwidget.parent()

        # no split/collapse context menu for positions outside any tabwidget
        # region
        if not splitter:
            return

        # add split actions (only show for non-empty tabwidgets)
        if not splitter.is_empty():
            actions = [
                Action(id='split_hor',
                       name='Create new pane to the right',
                       on_perform=lambda: splitter.split(orientation=QtCore.Qt.
                                                         Horizontal)),
                Action(id='split_ver',
                       name='Create new pane to the bottom',
                       on_perform=lambda: splitter.split(orientation=QtCore.Qt.
                                                         Vertical))
            ]

            splitgroup = Group(*actions, id='split')
            menu.append(splitgroup)

        # add collapse action (only show for collapsible splitters)
        if splitter.is_collapsible():
            if splitter is splitter.parent().leftchild:
                if splitter.parent().orientation() is QtCore.Qt.Horizontal:
                    text = 'Merge with right pane'
                else:
                    text = 'Merge with bottom pane'
            else:
                if splitter.parent().orientation() is QtCore.Qt.Horizontal:
                    text = 'Merge with left pane'
                else:
                    text = 'Merge with top pane'
            actions = [
                Action(id='merge',
                       name=text,
                       on_perform=lambda: splitter.collapse())
            ]

            collapsegroup = Group(*actions, id='collapse')
            menu.append(collapsegroup)

        # return QMenu object
        return menu