示例#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_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()
示例#3
0
def test_toolbar():
    widget = widgets.ToolBar()
    widget.add_menu_button("test,", "mdi.timer", menu=widgets.Menu())
    widget.set_style("icon")
    widget.set_font_size(10)
    widget.set_enabled()
    widget.set_disabled()

    def test():
        pass

    widget.add_action("test", "mdi.timer", test, checkable=True)
示例#4
0
def test_menu():
    menu = widgets.Menu("1")

    def test():
        pass

    menu.add_action("test",
                    test,
                    icon="mdi.timer",
                    shortcut="Ctrl+A",
                    checkable=True)
    menu._separator("test")
示例#5
0
 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
示例#6
0
 def contextMenuEvent(self, event):
     """
     context menu for our files tree
     """
     menu = widgets.Menu(parent=self)
     for i, header_label in enumerate(self.section_labels()[1:], start=1):
         act = menu.addAction(header_label)
         act.setCheckable(True)
         val = not self.isSectionHidden(i)
         act.setChecked(val)
         fn = functools.partial(self.change_section_vis, i=i, val=val)
         act.triggered.connect(fn)
     menu.exec_(self.mapToGlobal(event.pos()))
示例#7
0
 def __init__(
     self,
     title: str,
     icon: types.IconType = None,
     dct: dict[str, str] = None,
     parent: QtWidgets.QWidget | None = None,
 ):
     super().__init__(parent=parent)
     self.set_text(title)
     self.set_icon(icon)
     self.button_menu = widgets.Menu()
     self.setMenu(self.button_menu)
     self.set_popup_mode("instant")
     if dct:
         self.set_dict(dct)
示例#8
0
def test_toolbar():
    widget = widgets.ToolBar()
    widget.add_menu_button("test,", "mdi.timer", menu=widgets.Menu())
    widget.set_style("icon")
    widget.set_style(None)
    assert widget.get_style() == "icon"
    widget.set_font_size(10)
    widget.set_enabled()
    widget.set_disabled()
    assert widget.is_area_allowed("top")
    with pytest.raises(ValueError):
        widget.is_area_allowed("test")

    def test():
        pass

    widget.add_action("test", "mdi.timer", test, checkable=True)
示例#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 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())
示例#11
0
 def __init__(
     self,
     parent: QtWidgets.QWidget | None = None,
     show_settings: bool = False,
     main_layout: widgets.widget.LayoutStr | QtWidgets.QLayout = "vertical",
 ):
     super().__init__(parent=parent)
     self.button_map: dict[QtWidgets.QWidget, QtWidgets.QToolButton] = {}
     self.icon_map: dict[QtWidgets.QWidget, gui.Icon] = {}
     self.sidebar = widgets.ToolBar()
     self.sidebar.set_id("SidebarWidget")
     self.sidebar.set_title("Sidebar")
     self.sidebar.set_style("text_below_icon")
     self.sidebar.set_context_menu_policy("prevent")
     self.sidebar.setFloatable(False)
     self.sidebar.set_allowed_areas("all")
     self.settings_menu = widgets.Menu()
     self.sidebar.set_icon_size(60)
     if show_settings:
         self.settings_btn = self.sidebar.add_menu_button(
             "", icon="mdi.wrench", menu=self.settings_menu)
         self.settings_btn.setFixedSize(self.BUTTON_WIDTH,
                                        self.SETTINGS_BUTTON_HEIGHT)
         self.settings_btn.set_style("icon")
         self.sidebar.orientationChanged.connect(
             self._on_orientation_change)
         self.sidebar.add_separator()
     self.spacer_action = self.sidebar.add_spacer()
     self.add_toolbar(self.sidebar, "left")
     self.area = widgets.Widget()
     self.area.set_layout("stacked")
     w = widgets.Widget()
     w.set_layout(main_layout)
     self.main_layout = w.box
     self.main_layout.set_margin(0)
     self.main_layout += self.area
     self.setCentralWidget(w)
示例#12
0
            self.addAction(action)
            return action

    def add_separator(self):
        self.addSeparator()

    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)


if __name__ == "__main__":
    app = widgets.app()
    win = widgets.MainWindow()
    menu_bar = MenuBar()
    menuaction = menu_bar.add_menu("test")
    act = menu_bar.add_action("action")
    sep = menu_bar.addSeparator()
    act2 = menu_bar.add_action("action2")
    menu = widgets.Menu("testaa")
    menu_bar.add(menu)
    win.setMenuBar(menu_bar)
    win.show()
    app.main_loop()
示例#13
0
    def __init__(self, obj, name: str = ""):
        super().__init__()
        self.set_title("Object browser")
        self._instance_nr = self._add_instance()
        self.set_icon("mdi.language-python")
        self._attr_cols = DEFAULT_ATTR_COLS
        self._attr_details = DEFAULT_ATTR_DETAILS

        logger.debug("Reading model settings for window: %d",
                     self._instance_nr)
        with core.Settings(
                settings_id=self._settings_group_name("model")) as settings:
            self._auto_refresh = settings.get("auto_refresh", False)
            self._refresh_rate = settings.get("refresh_rate", 2)
            show_callable_attrs = settings.get("show_callable_attrs", True)
            show_special_attrs = settings.get("show_special_attrs", True)
        self._tree_model = objectbrowsertreemodel.ObjectBrowserTreeModel(
            obj, name, attr_cols=self._attr_cols)

        self._proxy_tree_model = objectbrowsertreemodel.ObjectBrowserTreeProxyModel(
            show_callable_attrs=show_callable_attrs,
            show_special_attrs=show_special_attrs,
        )

        self._proxy_tree_model.setSourceModel(self._tree_model)
        # self._proxy_tree_model.setSortRole(RegistryTableModel.SORT_ROLE)
        self._proxy_tree_model.setDynamicSortFilter(True)
        # self._proxy_tree_model.setSortCaseSensitivity(Qt.CaseInsensitive)

        # Views
        self._setup_actions()
        self.central_splitter = widgets.Splitter(
            parent=self, orientation=constants.VERTICAL)
        self.setCentralWidget(self.central_splitter)

        # Tree widget
        self.obj_tree = widgets.TreeView()
        self.obj_tree.setRootIsDecorated(True)
        self.obj_tree.setAlternatingRowColors(True)
        self.obj_tree.set_model(self._proxy_tree_model)
        self.obj_tree.set_selection_behaviour("rows")
        self.obj_tree.setUniformRowHeights(True)
        self.obj_tree.setAnimated(True)

        # Stretch last column?
        # It doesn't play nice when columns are hidden and then shown again.
        self.obj_tree.h_header.set_id("table_header")
        self.obj_tree.h_header.setSectionsMovable(True)
        self.obj_tree.h_header.setStretchLastSection(False)
        self.central_splitter.addWidget(self.obj_tree)

        # Bottom pane
        bottom_pane_widget = widgets.Widget()
        bottom_pane_widget.set_layout("horizontal", spacing=0, margin=5)
        self.central_splitter.addWidget(bottom_pane_widget)

        group_box = widgets.GroupBox("Details")
        bottom_pane_widget.box.addWidget(group_box)

        group_box.set_layout("horizontal", margin=2)

        # Radio buttons
        radio_widget = widgets.Widget()
        radio_widget.set_layout("vertical", margin=0)

        self.button_group = widgets.ButtonGroup(self)
        for button_id, attr_detail in enumerate(self._attr_details):
            radio_button = widgets.RadioButton(attr_detail.name)
            radio_widget.box.addWidget(radio_button)
            self.button_group.addButton(radio_button, button_id)

        self.button_group.buttonClicked.connect(self._change_details_field)
        self.button_group.button(0).setChecked(True)

        radio_widget.box.addStretch(1)
        group_box.box.addWidget(radio_widget)

        # Editor widget
        font = gui.Font("Courier")
        font.setFixedPitch(True)
        # font.setPointSize(14)

        self.editor = widgets.PlainTextEdit()
        self.editor.setReadOnly(True)
        self.editor.setFont(font)
        group_box.box.addWidget(self.editor)

        # Splitter parameters
        self.central_splitter.setCollapsible(0, False)
        self.central_splitter.setCollapsible(1, True)
        self.central_splitter.setSizes([400, 200])
        self.central_splitter.setStretchFactor(0, 10)
        self.central_splitter.setStretchFactor(1, 0)

        selection_model = self.obj_tree.selectionModel()
        selection_model.currentChanged.connect(self._update_details)
        menubar = self.menuBar()
        file_menu = menubar.add_menu("&File")
        file_menu.addAction("C&lose", self.close, "Ctrl+W")
        file_menu.addAction("E&xit", lambda: widgets.app().closeAllWindows(),
                            "Ctrl+Q")

        view_menu = menubar.add_menu("&View")
        view_menu.addAction("&Refresh", self._tree_model.refresh_tree,
                            "Ctrl+R")
        view_menu.addAction(self.toggle_auto_refresh_action)

        view_menu.addSeparator()
        self.show_cols_submenu = widgets.Menu("Table columns")
        view_menu.add_menu(self.show_cols_submenu)
        actions = self.obj_tree.h_header.get_header_actions()
        self.show_cols_submenu.add_actions(actions)
        view_menu.addSeparator()
        view_menu.addAction(self.toggle_callable_action)
        view_menu.addAction(self.toggle_special_attribute_action)

        assert self._refresh_rate > 0
        self._refresh_timer = core.Timer(self)
        self._refresh_timer.setInterval(self._refresh_rate * 1000)
        self._refresh_timer.timeout.connect(self._tree_model.refresh_tree)

        # Update views with model
        self.toggle_special_attribute_action.setChecked(show_special_attrs)
        self.toggle_callable_action.setChecked(show_callable_attrs)
        self.toggle_auto_refresh_action.setChecked(self._auto_refresh)

        # Select first row so that a hidden root node will not be selected.
        first_row_index = self._proxy_tree_model.first_item_index()
        self.obj_tree.setCurrentIndex(first_row_index)
        if self._tree_model.inspected_node_is_visible:
            self.obj_tree.expand(first_row_index)
示例#14
0
 def add_menu(self, menu: Union[QtWidgets.QMenu, str]):
     if isinstance(menu, str):
         menu = widgets.Menu(menu)
         self.addMenu(menu)
         return menu
     return self.addMenu(menu)
示例#15
0
 def contextMenuEvent(self, event):
     """Context menu for our files tree."""
     menu = widgets.Menu(parent=self)
     actions = self.get_header_actions()
     menu.add_actions(actions)
     menu.exec_(self.mapToGlobal(event.position()))
示例#16
0
def test_menu():
    menu = widgets.Menu("1")
    action = widgets.Action("test")
    menu.addAction(action)
    menu.show()