Beispiel #1
0
    def handleException(exc_type, exc_value, exc_traceback):
        """Causes the application to quit in case of an unhandled exception.

        Shows an error dialog before quitting when not in debugging mode.
        """
        logger.critical(
            f"Bug: uncaught {exc_type.__name__}",
            exc_info=(exc_type, exc_value, exc_traceback),
        )
        if debug:
            sys.exit(1)
        else:
            from prettyqt import widgets

            # Constructing a QApplication in case this hasn't been done yet.
            _ = widgets.app()
            lst = traceback.format_exception(exc_type, exc_value,
                                             exc_traceback)
            msg_box = widgets.MessageBox(
                icon="warning",
                text=f"Bug: uncaught {exc_type.__name__}",
                informative_text=str(exc_value),
                details="".join(lst),
            )
            msg_box.main_loop()
            sys.exit(1)
Beispiel #2
0
    def browse(cls, *args, **kwargs):
        """Create and run object browser.

        For this, the following three steps are done:
        1) Create QApplication object if it doesn't yet exist
        2) Create and show an ObjectBrowser window
        3) Start the Qt event loop.

        The *args and **kwargs will be passed to the ObjectBrowser constructor.
        """
        cls.app = widgets.app(
        )  # keeping reference to prevent garbage collection.
        cls.app.setOrganizationName("phil65")
        cls.app.setApplicationName("PrettyQt")
        object_browser = cls(*args, **kwargs)
        object_browser.show()
        object_browser.raise_()
        return cls.app.main_loop()
Beispiel #3
0
        if whats_this:
            item.setWhatsThis(whats_this)
        if size_hint is not None:
            item.set_size_hint(size_hint)
        if checkstate is not None:
            item.set_checkstate(checkstate)
        self.appendRow([item])
        return item


if __name__ == "__main__":
    import pickle

    from prettyqt import widgets

    model = gui.StandardItemModel()
    model.add("test")
    app = widgets.app()
    w = widgets.ListView()
    w.set_model(model)
    model += gui.StandardItem("Item")
    for item in model:
        pass
    with open("data.pkl", "wb") as jar:
        pickle.dump(model, jar)
    with open("data.pkl", "rb") as jar:
        model = pickle.load(jar)
    model += gui.StandardItem("Item2")
    w.show()
    app.main_loop()
Beispiel #4
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)
Beispiel #5
0
    @classmethod
    def browse(cls, *args, **kwargs):
        """Create and run object browser.

        For this, the following three steps are done:
        1) Create QApplication object if it doesn't yet exist
        2) Create and show an ObjectBrowser window
        3) Start the Qt event loop.

        The *args and **kwargs will be passed to the ObjectBrowser constructor.
        """
        cls.app = widgets.app(
        )  # keeping reference to prevent garbage collection.
        cls.app.setOrganizationName("phil65")
        cls.app.setApplicationName("PrettyQt")
        object_browser = cls(*args, **kwargs)
        object_browser.show()
        object_browser.raise_()
        return cls.app.main_loop()


if __name__ == "__main__":
    logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
    struct = dict(a={1, 2, frozenset([1, 2])})
    app = widgets.app()  # keeping reference to prevent garbage collection.
    app.setOrganizationName("phil65")
    app.setApplicationName("PrettyQt")
    object_browser = ObjectBrowser(struct)
    object_browser.show()
    app.main_loop()
Beispiel #6
0
def run():
    app = widgets.app()
    widget = regexeditor.RegexEditorWidget()
    widget.show()
    app.main_loop()
Beispiel #7
0
def run():
    app = widgets.app()
    browser = IconBrowser()
    browser.show()
    sys.exit(app.main_loop())