Esempio n. 1
0
 def __init__(self, initial=None, parent=None):
     QtGui.QDialog.__init__(self, p(parent))
     BaseForm.__init__(self, initial=initial)
     ThreadedCalls.__init__(self)
     # widget creation
     widgets = []
     if self.description:
         widgets.append(QtGui.QLabel(self.description, p(self)))
     sub_layout = QtGui.QFormLayout(self)
     self._fill_form_layout(layout=sub_layout)
     widgets.append(sub_layout)
     self._buttons = []
     if self.text_confirm:
         self._buttons.append(create_button(self.text_confirm, connect=self.accept, min_size=True))
     if self.text_cancel:
         self._buttons.append(create_button(self.text_cancel, connect=self.reject, min_size=True))
     if self._buttons:
         widgets.append(h_layout(self, *self._buttons, direction=QtGui.QBoxLayout.RightToLeft))
     self.setLayout(v_layout(self, *widgets))
     if self.verbose_name:
         self.setWindowTitle(str(self.verbose_name))
     self.raise_()
Esempio n. 2
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_()
Esempio n. 3
0
 def __init__(self, parent=None):
     QtGui.QDockWidget.__init__(self, str(self.verbose_name), p(parent))
     ThreadedCalls.__init__(self)
     self.parent_window = weakref.ref(parent)
     self.setObjectName(self.__class__.__name__)