Example #1
0
    def create(self, window: QtGui.QMainWindow, parent_menu: QtGui.QMenu):
        if self.disabled:
            return
        if callable(self.method_name):
            method = self.method_name
        else:
            method = getattr(window, self.method_name)

        if self.sep:
            parent_menu.addSeparator()
        if self.submenu:
            menu = QtGui.QMenu(self.verbose_name, p(parent_menu))
            if self.icon:
                action = parent_menu.addMenu(get_icon(self.icon), menu)
            else:
                action = parent_menu.addMenu(menu)
            action.hovered.connect(functools.partial(self.fill_submenu, window, menu, method))
        else:
            if self.icon:
                action = QtGui.QAction(get_icon(self.icon), self.verbose_name, p(parent_menu))
            else:
                action = QtGui.QAction(self.verbose_name, p(parent_menu))
            # noinspection PyUnresolvedReferences
            action.triggered.connect(method)
            parent_menu.addAction(action)
        if self.shortcut:
            action.setShortcut(self.shortcut)
        if self.help_text:
            action.setStatusTip(self.help_text)
Example #2
0
    def __init__(self, args: list):
        super().__init__()
        self.load()  # load preferences

        # initialize QtApplication
        self.application = QtGui.QApplication(args)
        self.parent = QtGui.QWidget()
        global_dict[application_key] = self
        # initialize thread pool executor
        self.executor = QtCore.QThreadPool()
        self.executor.setMaxThreadCount(self.GlobalInfos.pool_thread_size)

        # set some global stuff
        if self.description_icon:
            self.application.setWindowIcon(get_icon(self.description_icon))
        if self.verbose_name:
            self.application.setApplicationName(str(self.verbose_name))
        if self.application_version:
            self.application.setApplicationVersion(self.application_version)
        if self.systemtray_icon:
            self._parent_obj = QtGui.QWidget()
            self.systray = QtGui.QSystemTrayIcon(get_icon(self.systemtray_icon), self._parent_obj)
            self.systray.setVisible(True)
            self.systray.show()

            # retrieve menu and associated actions for the whole class hierarchy
            created_action_keys = set()
            menu = None
            for qualname in self.__class__.__mro__:
                cls_name = qualname.__name__.rpartition('.')[2]
                if cls_name not in registered_menus:
                    continue
                for menu_action in registered_menu_actions[cls_name]:
                    if menu is None:
                        menu = QtGui.QMenu(self.verbose_name, self._parent_obj)
                    if menu_action.uid in created_action_keys:  # skip overriden actions (there are already created)
                        continue
                    created_action_keys.add(menu_action.uid)
                    menu_action.create(self, menu)
            if menu is not None:
                self.systray.setContextMenu(menu)
            # noinspection PyUnresolvedReferences
            self.systray.activated.connect(self.systray_activated)
            # noinspection PyUnresolvedReferences
            self.systray.messageClicked.connect(self.systray_message_clicked)
        if self.splashscreen_icon:
            self.splashscreen = QtGui.QSplashScreen(self.parent, get_pixmap(self.splashscreen_icon),
                                                    QtCore.Qt.WindowStaysOnTopHint)
            self.splashscreen.showMessage(_('Loading data…'))
            self.splashscreen.show()

        # noinspection PyUnresolvedReferences
        self.application.lastWindowClosed.connect(self.save)
        self.load_data()
        if self.splashscreen is not None:
            self.splashscreen.hide()
Example #3
0
 def __init__(
     self,
     parent,
     connect: callable = None,
     legend: str = None,
     min_size: bool = True,
     icon: str = None,
     flat: bool = False,
     tooltip: str = None,
 ):
     QtGui.QPushButton.__init__(self, parent)
     if icon is not None:
         self.setIcon(get_icon(icon))
     if min_size:
         if legend:
             self.setText(legend)
         size = self.minimumSizeHint()
         if not legend:
             size.setWidth(self.iconSize().width() + 8)
         self.setFixedSize(size)
     self.connected_function = connect
     self.setFlat(flat)
     if tooltip:
         self.setToolTip(tooltip)
     self.args = []
     self.kwargs = {}
     if connect:
         # noinspection PyUnresolvedReferences
         self.clicked.connect(self.button_clicked)
Example #4
0
 def create(self, window: QtGui.QMainWindow, parent: QtGui.QToolBar):
     if self.disabled:
         return
     if callable(self.method_name):
         method = self.method_name
     else:
         method = getattr(window, self.method_name)
     if self.sep:
         parent.addSeparator()
     if self.icon:
         action = QtGui.QAction(get_icon(self.icon), self.verbose_name, p(window))
     else:
         action = QtGui.QAction(self.verbose_name, p(window))
     # noinspection PyUnresolvedReferences
     action.triggered.connect(method)
     parent.addAction(action)
     if self.shortcut:
         action.setShortcut(self.shortcut)
     if self.help_text:
         action.setStatusTip(self.help_text)
Example #5
0
    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self, p(parent))
        ThreadedCalls.__init__(self)

        self._window_id = next(BaseMainWindow._window_counter)
        self._docks = {}
        application.windows[self._window_id] = self

        # retrieve menus and associated actions from the whole class hierarchy
        menubar = self.menuBar()
        defined_qmenus = {}
        created_action_keys = set()
        supernames = [x.__name__.rpartition('.')[2] for x in self.__class__.__mro__]
        supernames.reverse()
        for menu_name in self.menus:
            defined_qmenus[menu_name] = menubar.addMenu(menu_name)
        for cls_name in supernames:
            for menu_name in registered_menus.get(cls_name, []):  # create all top-level menus
                if menu_name not in defined_qmenus:
                    defined_qmenus[menu_name] = menubar.addMenu(menu_name)
        supernames.reverse()
        for cls_name in supernames:
            for menu_action in registered_menu_actions.get(cls_name, []):
                if menu_action.uid in created_action_keys:  # skip overriden actions (there are already created)
                    continue
                created_action_keys.add(menu_action.uid)
                menu_action.create(self, defined_qmenus[menu_action.menu])

        # retrieve toolbar actions from the whole class hierarchy
        self.setUnifiedTitleAndToolBarOnMac(True)
        defined_qtoolbars = {}
        created_action_keys = set()
        for superclass in self.__class__.__mro__:
            cls_name = superclass.__name__.rpartition('.')[2]
            if cls_name not in registered_toolbars:
                continue
            for toolbar_name in registered_toolbars[cls_name]:  # create all top-level menus
                if toolbar_name not in defined_qtoolbars:
                    if toolbar_name is not None:
                        defined_qtoolbars[toolbar_name] = BaseToolBar(toolbar_name, p(self))
                    else:
                        defined_qtoolbars[toolbar_name] = BaseToolBar(_('Toolbar'), p(self))
                    self.addToolBar(defined_qtoolbars[toolbar_name])
            for toolbar_action in registered_toolbar_actions[cls_name]:
                if toolbar_action.uid in created_action_keys:  # skip overriden actions (there are already created)
                    continue
                created_action_keys.add(toolbar_action.uid)
                toolbar_action.create(self, defined_qtoolbars[toolbar_action.toolbar])

        # create all dock widgets
        for dock_cls in self.docks:
            """:type dock_cls: type"""
            if not isinstance(dock_cls, type) or not issubclass(dock_cls, BaseDock):
                continue
            dock = dock_cls(parent=self)
            """:type dock: BaseDock"""
            self._docks[dock_cls] = dock
            self.addDockWidget(dock.default_position, dock)
            menu_name = dock.menu
            if menu_name is not None:
                if menu_name not in defined_qmenus:
                    defined_qmenus[menu_name] = menubar.addMenu(menu_name)
                    connect = functools.partial(self._base_swap_dock_display, dock_cls)
                    action = MenuAction(connect, verbose_name=dock.verbose_name, menu=menu_name, shortcut=dock.shortcut)
                    action.create(self, defined_qmenus[menu_name])

        # some extra stuff
        self.setWindowTitle(self.verbose_name)
        if self.description_icon:
            self.setWindowIcon(get_icon(self.description_icon))

        self.setCentralWidget(self.central_widget())
        # restore state and geometry
        # noinspection PyBroadException
        self.adjustSize()
        try:
            cls_name = self.__class__.__name__
            if cls_name in application['GlobalInfos/main_window_geometries']:
                geometry_str = application['GlobalInfos/main_window_geometries'][cls_name].encode('utf-8')
                geometry = base64.b64decode(geometry_str)
                self.restoreGeometry(geometry)
            if cls_name in application['GlobalInfos/main_window_states']:
                state_str = application['GlobalInfos/main_window_states'][cls_name].encode('utf-8')
                state = base64.b64decode(state_str)
                self.restoreState(state)
        except ValueError:
            pass
        self.raise_()