예제 #1
0
def test_menubar():
    menu = widgets.MenuBar()
    menu += widgets.Action("TestAction")
    menu += widgets.Menu("TestMenu")
    menu.add_action(widgets.Action("TestAction 2"))
    menu.add_menu(widgets.Menu("TestMenu 2"))
    menu.add_separator()
    menu.add_action("test")
    menu.add_menu("test")
예제 #2
0
def test_statusbar():
    widget = widgets.MainWindow()
    status_bar = widgets.StatusBar()
    status_bar.set_color("black")
    label = widgets.Label("test")
    status_bar.addWidget(label)
    status_bar.setup_default_bar()
    status_bar.show_message("test")
    status_bar.add_action(widgets.Action())
    status_bar += widgets.Action()
    widget.setStatusBar(status_bar)
    status_bar.add_widget(widgets.Widget())
    status_bar += widgets.Widget()
    status_bar.add_widget(widgets.Widget(), permanent=True)
예제 #3
0
 def add_action(
     self,
     title: str,
     icon: types.IconType = None,
     callback: Callable = None,
     checkable: bool = False,
     shortcut: str | None = None,
     area: AreaStr = "top",
 ):
     # act = self.sidebar.add_action(label=title,
     #                                      icon=icon,
     #                                      callback=callback,
     #                                      checkable=checkable)
     act = widgets.Action(
         text=title,
         icon=icon,
         shortcut=shortcut,
         checkable=checkable,
         callback=callback,
     )
     if area == "top":
         self.sidebar.insertAction(self.spacer_action, act)
     if area == "bottom":
         self.sidebar.addAction(act)
     button = self.sidebar.widgetForAction(act)
     button.setFixedWidth(self.BUTTON_WIDTH)
     return act
예제 #4
0
    def add_action(self,
                   label: str,
                   callback: Callable,
                   icon: Optional[Any] = None,
                   checkable: bool = False,
                   checked: bool = False,
                   shortcut: Optional[str] = None,
                   status_tip: Optional[str] = None) -> widgets.Action:
        """Add an action to the menu

        Args:
            label: Label for button
            callback: gets called when action is triggered
            icon: icon for button (default: {None})
            checkable: as checkbox button (default: {False})
            checked: if checkable, turn on by default (default: {False})
            shortcut: Shortcut for action (a) (default: {None})
            status_tip: Status tip to be shown in status bar (default: {None})

        Returns:
            Action added to menu
        """
        action = widgets.Action(label, parent=self)
        action.triggered.connect(callback)
        action.set_icon(icon)
        action.set_shortcut(shortcut)
        if checkable:
            action.setCheckable(True)
            action.setChecked(checked)
        if status_tip is not None:
            action.setStatusTip(status_tip)
        self.addAction(action)
        return action
예제 #5
0
    def create_menu(self):
        act_exit = widgets.Action(gui.Icon("exit.png"), "&Exit", self)
        act_exit.setShortcut("Ctrl+Q")
        act_exit.setStatusTip("Exit application")
        act_exit.triggered.connect(self.close)

        act_open = widgets.Action(gui.Icon("open.png"), "&Open", self)
        act_open.setShortcut("Ctrl+O")
        act_open.setStatusTip("Open Markdown file")
        act_open.triggered.connect(self.open_new_file)

        self.statusBar()

        menubar = self.menuBar()
        menu_file = menubar.addMenu("&File")
        menu_file.addAction(act_open)
        menu_file.addAction(act_exit)
예제 #6
0
    def create_menu(self):
        act_exit = widgets.Action(gui.Icon('exit.png'), '&Exit', self)
        act_exit.setShortcut('Ctrl+Q')
        act_exit.setStatusTip('Exit application')
        act_exit.triggered.connect(self.close)

        act_open = widgets.Action(gui.Icon('open.png'), '&Open', self)
        act_open.setShortcut('Ctrl+O')
        act_open.setStatusTip('Open Markdown file')
        act_open.triggered.connect(self.open_new_file)

        self.statusBar()

        menubar = self.menuBar()
        menu_file = menubar.addMenu('&File')
        menu_file.addAction(act_open)
        menu_file.addAction(act_exit)
예제 #7
0
def test_widgetaction():
    action = widgets.Action()
    widgetaction = widgets.WidgetAction(action)
    widgetaction.set_tooltip("test")
    widgetaction.set_enabled()
    widgetaction.set_disabled()
    widgetaction.set_icon("mdi.timer")
    widgetaction.set_shortcut("Ctrl+A")
    return True
예제 #8
0
파일: menubar.py 프로젝트: phil65/PrettyQt
 def add(self, *items: QtWidgets.QMenu | QtWidgets.QAction):
     for i in items:
         if isinstance(i, QtWidgets.QMenu):
             action = widgets.Action(parent=self)
             action.set_text(i.title())
             action.set_menu(i)
             self.addAction(action)
         else:
             self.addAction(i)
예제 #9
0
 def createPopupMenu(self):
     # qactions = self.createPopupMenu()
     menu = widgets.Menu(parent=self)
     for i, item in enumerate(self.get_docks()):
         action = widgets.Action(item.windowTitle(), parent=self)
         action.set_checkable(True)
         action.set_checked(item.isVisible())
         action.set_shortcut(f"Ctrl+Shift+{i}")
         action.set_shortcut_context("application")
         action.toggled.connect(item.setVisible)
         menu.add_action(action)
     menu.add_separator()
     for i in self.get_toolbars():
         action = widgets.Action(i.windowTitle(), parent=self)
         action.set_checkable(True)
         action.toggled.connect(i.setVisible)
         action.set_checked(i.isVisible())
         menu.add_action(action)
     return menu
예제 #10
0
    def _setup_actions(self):
        """Create the main window actions."""
        # Show/hide callable objects
        self.toggle_callable_action = widgets.Action(
            text="Show callable attributes",
            parent=self,
            checkable=True,
            shortcut=gui.KeySequence("Alt+C"),
            statustip=
            "Shows/hides callable attributes (functions, methods, etc.)",
        )
        self.toggle_callable_action.toggled.connect(
            self._proxy_tree_model.set_show_callables)

        # Show/hide special attributes
        self.toggle_special_attribute_action = widgets.Action(
            text="Show __special__ attributes",
            parent=self,
            checkable=True,
            shortcut=gui.KeySequence("Alt+S"),
            statustip="Shows or hides __special__ attributes",
        )
        self.toggle_special_attribute_action.toggled.connect(
            self._proxy_tree_model.set_show_special_attrs)

        # Toggle auto-refresh on/off
        self.toggle_auto_refresh_action = widgets.Action(
            text="Auto-refresh",
            parent=self,
            checkable=True,
            statustip=f"Auto refresh every {self._refresh_rate} seconds",
        )
        self.toggle_auto_refresh_action.toggled.connect(
            self.toggle_auto_refresh)

        # Add another refresh action with a different shortcut. An action must be added to
        # a visible widget for it to receive events. It is added to the main windows to
        # prevent it from being displayed again in the menu
        self.refresh_action_f5 = widgets.Action(self,
                                                text="&Refresh2",
                                                shortcut="F5")
        self.refresh_action_f5.triggered.connect(self._tree_model.refresh_tree)
        self.addAction(self.refresh_action_f5)
예제 #11
0
 def update_actions(self):
     """Updates the list of actions."""
     self.clear()
     self.recent_files_actions[:] = []
     for file in self.manager.get_recent_files():
         action = widgets.Action(self)
         action.setText(os.path.split(file)[1])
         action.setToolTip(file)
         action.setStatusTip(file)
         action.setData(file)
         action.setIcon(self.icon_provider.icon(core.FileInfo(file)))
         action.triggered.connect(self._on_action_triggered)
         self.addAction(action)
         self.recent_files_actions.append(action)
     self.addSeparator()
     action_clear = widgets.Action(parent=self, text="Clear list")
     action_clear.triggered.connect(self.clear_recent_files)
     action_clear.setIcon(iconprovider.get_icon("fa.times-circle"))
     self.addAction(action_clear)
예제 #12
0
def test_menu():
    menu = widgets.Menu("1", icon="mdi.timer")
    menu.add(widgets.Action("TestAction"))
    menu += widgets.Action("TestAction")

    def test():
        pass

    menu.add_action("test",
                    test,
                    icon="mdi.timer",
                    shortcut="Ctrl+A",
                    checkable=True,
                    status_tip="test")
    assert len(menu) == 1
    for item in menu:
        pass
    menu.add_menu(widgets.Menu())
    menu._separator("test")
    menu.add_separator()
예제 #13
0
 def set_dict(self, dct: dict[str, str]):
     self.button_menu.clear()
     for k, v in dct.items():
         action = widgets.Action()
         action.set_text(v)
         action.setCheckable(True)
         action.set_id(k)
         action.triggered.connect(
             lambda: self.value_changed.emit(self.as_dict()))
         self.button_menu.add(action)
     self.value_changed.emit(self.as_dict())
예제 #14
0
 def get_header_actions(self) -> list[widgets.Action]:
     actions = list()
     labels = self.get_section_labels()[1:]
     for i, header_label in enumerate(labels, start=1):
         val = not self.isSectionHidden(i)
         action = widgets.Action(text=header_label,
                                 checkable=True,
                                 checked=val)
         fn = functools.partial(self.set_section_hidden, i=i, hide=val)
         action.triggered.connect(fn)
         actions.append(action)
     return actions
예제 #15
0
 def create_menu(self):
     act_exit = widgets.Action(
         text="&Exit",
         icon="mdi.exit-to-app",
         parent=self,
         shortcut="Ctrl+Q",
         statustip="Exit application",
         callback=self.close,
     )
     act_open = widgets.Action(
         text="&Open",
         icon="mdi.open-in-app",
         parent=self,
         shortcut="Ctrl+O",
         statustip="Open Markdown file",
         callback=self.open_new_file,
     )
     menubar = self.menuBar()
     menu_file = menubar.addMenu("&File")
     menu_file.addAction(act_open)
     menu_file.addAction(act_exit)
예제 #16
0
def test_action():
    action = widgets.Action()
    action.set_tooltip("test")
    action.set_enabled()
    action.set_disabled()
    action.set_icon("mdi.timer")
    action.set_shortcut("Ctrl+A")
    with open("data.pkl", "wb") as jar:
        pickle.dump(action, jar)
    with open("data.pkl", "rb") as jar:
        action = pickle.load(jar)
    assert action.shortcut().toString() == "Ctrl+A"
    assert action.toolTip() == "test"
예제 #17
0
 def __init__(self, font=None, parent=None):
     super().__init__(parent)
     self.current_font = font
     layout = widgets.BoxLayout("horizontal", self)
     layout.set_margin(0)
     self.lineedit = widgets.LineEdit()
     self.lineedit.set_read_only()
     layout += self.lineedit
     action = widgets.Action()
     action.triggered.connect(self.choose_font)
     self.button = widgets.ToolButton()
     self.button.setDefaultAction(action)
     layout += self.button
예제 #18
0
파일: menubar.py 프로젝트: phil65/PrettyQt
 def add_menu(self, menu_or_str):
     action = widgets.Action(parent=self)
     if isinstance(menu_or_str, str):
         menu = widgets.Menu(menu_or_str)
         action.set_text(menu_or_str)
         action.set_menu(menu)
         self.addAction(action)
         return menu
     else:
         action.set_menu(menu_or_str)
         action.set_text(menu_or_str.title())
         self.addAction(action)
         return action
예제 #19
0
 def __init__(self, color=None, parent=None):
     super().__init__(parent)
     layout = widgets.BoxLayout("horizontal", self)
     layout.set_margin(0)
     self.lineedit = widgets.LineEdit()
     self.lineedit.set_regex_validator(r"^#(?:[0-9a-fA-F]{6})$")
     layout += self.lineedit
     action = widgets.Action(icon="mdi.format-color-fill")
     action.triggered.connect(self.choose_color)
     self.button = widgets.ToolButton()
     self.button.setDefaultAction(action)
     layout += self.button
     if color is not None:
         self.set_color(color)
예제 #20
0
 def __init__(
     self, color: types.ColorType = None, parent: QtWidgets.QWidget | None = None
 ):
     super().__init__(parent)
     layout = widgets.BoxLayout("horizontal", self)
     layout.set_margin(0)
     self.lineedit = widgets.LineEdit()
     self.lineedit.set_regex_validator(r"^#(?:[0-9a-fA-F]{6})$")
     layout.add(self.lineedit)
     action = widgets.Action(icon="mdi.format-color-fill")
     action.triggered.connect(self.choose_color)
     self.button = widgets.ToolButton()
     self.button.setDefaultAction(action)
     layout.add(self.button)
     self._current_color: gui.Color = gui.Color("white")
     if color is not None:
         self.set_current_color(color)
예제 #21
0
    def __init__(self, extensions=None, mode="save", parent=None):
        super().__init__(parent)
        self.path = None
        self.extensions = extensions
        self.mode = mode
        layout = widgets.BoxLayout("horizontal", self)
        layout.set_margin(0)
        self.lineedit = widgets.LineEdit()
        self.lineedit.set_read_only()
        layout += self.lineedit
        action = widgets.Action()
        action.set_icon("mdi.file-outline")
        action.triggered.connect(self.open_file)

        self.button = widgets.ToolButton()
        self.button.setDefaultAction(action)
        layout += self.button
예제 #22
0
 def add_tab(
     self,
     item: QtWidgets.QWidget,
     title: str,
     icon: types.IconType = None,
     show: bool = False,
     shortcut: str | None = None,
     area: AreaStr = "top",
 ):
     self.area.box.add(item)
     # button = widgets.ToolButton()
     # button.set_text(title)
     # button.set_icon_size(40)
     # button.setFixedSize(80, 80)
     # button.set_icon(icon)
     # button.clicked.connect(lambda: self.area.box.setCurrentWidget(item))
     # self.sidebar.addWidget(button)
     # self.sidebar.add_separator()
     if area == "top":
         act = widgets.Action(
             text=title,
             icon=icon,
             shortcut=shortcut,
             parent=self.sidebar,
             checkable=True,
             callback=lambda: self.set_tab(item),
         )
         self.sidebar.insertAction(self.spacer_action, act)
     else:
         act = self.sidebar.add_action(
             label=title,
             icon=icon,
             callback=lambda: self.set_tab(item),
             checkable=True,
         )
     button = self.sidebar.widgetForAction(act)
     button.setFixedWidth(self.BUTTON_WIDTH)
     if len(self.area.box) == 1:
         button.setChecked(True)
     self.button_map[item] = button
     self.icon_map[item] = iconprovider.get_icon(icon)
     if show:
         self.area.box.setCurrentWidget(item)
예제 #23
0
def test_action():
    action = widgets.Action()
    action.set_tooltip("test")
    action.set_enabled()
    action.set_disabled()
    action.set_icon(None)
    action.set_icon("mdi.timer")
    action.set_shortcut("Ctrl+A")
    with open("data.pkl", "wb") as jar:
        pickle.dump(action, jar)
    with open("data.pkl", "rb") as jar:
        action = pickle.load(jar)
    assert action.shortcut().toString() == "Ctrl+A"
    assert action.toolTip() == "test"
    action.set_priority("low")
    assert action.get_priority() == "low"
    action.set_shortcut_context("widget_with_children")
    assert action.get_shortcut_context() == "widget_with_children"
    action.set_menu(widgets.Menu())
예제 #24
0
    def __init__(
        self,
        extensions: dict[str, list[str]] | None = None,
        mode: widgets.filedialog.AcceptModeStr = "save",
        file_mode: widgets.filedialog.FileModeStr = "existing_files",
        root: None | str | pathlib.Path = None,
        parent: QtWidgets.QWidget | None = None,
    ):
        """Initialize FileChooserButton.

        Args:
            extensions: dict allowed extensions
                        form: "'name': ['.ext1', '.ext2']"
            mode: Accept mode ("save" or "load")
            file_mode: File mode ("existing_files", "existing_file", "any_file",
                                  or "directory")
            root: Root path
            parent: parent widget
        """
        super().__init__(parent)
        self.path: pathlib.Path | None = None
        self.extensions = extensions
        self.mode: widgets.filedialog.AcceptModeStr = mode
        self.file_mode: widgets.filedialog.FileModeStr = file_mode
        self.root = root
        layout = widgets.BoxLayout("horizontal", self)
        layout.set_margin(0)
        self.lineedit = widgets.LineEdit()
        self.lineedit.set_read_only()
        layout.add(self.lineedit)
        action = widgets.Action()
        if self.file_mode == "directory":
            action.set_icon("mdi.folder-outline")
        else:
            action.set_icon("mdi.file-outline")
        action.triggered.connect(self.open_file)

        self.button = widgets.ToolButton()
        self.button.setDefaultAction(action)
        layout.add(self.button)
예제 #25
0
파일: menu.py 프로젝트: phil65/PrettyQt
    def add_action(
        self,
        label: str | widgets.Action,
        callback: Callable = None,
        icon: Any | None = None,
        checkable: bool = False,
        checked: bool = False,
        shortcut: str | None = None,
        status_tip: str | None = None,
    ) -> widgets.Action:
        """Add an action to the menu.

        Args:
            label: Label for button
            callback: gets called when action is triggered
            icon: icon for button
            checkable: as checkbox button
            checked: if checkable, turn on by default
            shortcut: Shortcut for action
            status_tip: Status tip to be shown in status bar

        Returns:
            Action added to menu
        """
        if isinstance(label, str):
            action = widgets.Action(text=label, parent=self)
            if callback:
                action.triggered.connect(callback)
            action.set_icon(icon)
            action.set_shortcut(shortcut)
            if checkable:
                action.setCheckable(True)
                action.setChecked(checked)
            if status_tip is not None:
                action.setStatusTip(status_tip)
        else:
            action = label
            action.setParent(self)
        self.addAction(action)
        return action
예제 #26
0
파일: menu.py 프로젝트: timfl94/PrettyQt
        Returns:
            Action added to menu
        """
        if isinstance(label, str):
            action = widgets.Action(label, parent=self)
            if callback:
                action.triggered.connect(callback)
            action.set_icon(icon)
            action.set_shortcut(shortcut)
            if checkable:
                action.setCheckable(True)
                action.setChecked(checked)
            if status_tip is not None:
                action.setStatusTip(status_tip)
        else:
            action = label
        self.addAction(action)
        return action

    def add_menu(self, menu: QtWidgets.QMenu):
        return self.addAction(menu.menuAction())


if __name__ == "__main__":
    app = widgets.app()
    menu = Menu("1")
    action = widgets.Action("test")
    menu.addAction(action)
    menu.show()
    menu.exec_(core.Point(200, 200))
예제 #27
0
파일: menubar.py 프로젝트: phil65/PrettyQt
 def add_action(self, action: QtWidgets.QAction | str) -> QtWidgets.QAction:
     if isinstance(action, str):
         action = widgets.Action(parent=self, text=action)
     self.addAction(action)
     return action
예제 #28
0
def test_menubar():
    menu = widgets.MenuBar()
    menu += widgets.Action("test")
예제 #29
0
파일: menu.py 프로젝트: phil65/PrettyQt
                action.triggered.connect(callback)
            action.set_icon(icon)
            action.set_shortcut(shortcut)
            if checkable:
                action.setCheckable(True)
                action.setChecked(checked)
            if status_tip is not None:
                action.setStatusTip(status_tip)
        else:
            action = label
            action.setParent(self)
        self.addAction(action)
        return action

    def add_actions(self, actions: list[QtWidgets.QAction]):
        self.addActions(actions)

    def add_menu(self, menu: QtWidgets.QMenu) -> QtWidgets.QAction:
        action = menu.menuAction()
        self.addAction(action)
        return action


if __name__ == "__main__":
    app = widgets.app()
    menu = Menu("1")
    action = widgets.Action(text="test")
    menu.addAction(action)
    menu.show()
    menu.exec_(core.Point(200, 200))
예제 #30
0
파일: menubar.py 프로젝트: timfl94/PrettyQt
 def add_action(self, action: Union[QtWidgets.QAction, str]):
     if isinstance(action, str):
         action = widgets.Action(action)
         self.addAction(action)
         return action
     return self.addAction(action)