Esempio n. 1
0
 def __init__(self, parent, menu, toolbar):
     QObject.__init__(self, parent)
     self._currier = PersistentCurrier()
     # get list of mouse modes from config
     modelist = []
     for mid in Config.get("mouse-modes", _DefaultModes).split(","):
         if not ConfigFile.has_section(mid):
             print("ERROR: unknown mouse-mode '%s', skipping. Check your %s." % (mid, ConfigFileName))
         else:
             modelist.append(self._readModeConfig(mid))
     self._modes = dict([(mode.id, mode) for mode in modelist])
     self._qag_mode = QActionGroup(self)
     self._qag_submode = QActionGroup(self)
     self._all_submodes = []
     # make entries for main modes
     for mode in modelist:
         mode.addAction(menu, self._qag_mode, callback=self._currier.curry(self._setMode, mode.id))
         if mode.submodes:
             self._all_submodes += list(mode.submodes)
     # make entries for submodes
     self._qa_submode_sep = menu.addSeparator()
     self._modes.update([(mode.id, mode) for mode in self._all_submodes])
     for mode in self._all_submodes:
         mode.addAction(menu, self._qag_submode, toolbar=toolbar,
                        callback=self._currier.curry(self._setSubmode, mode.id))
     # other init
     self._current_context = None
     self._available_submodes = []
     # set initial mode
     initmode = Config.get("current-mouse-mode", _DefaultInitialMode)
     if initmode not in self._modes:
         initmode = modelist[0].id
     self._modes[initmode].qa.setChecked(True)
     self._setMode(initmode, write_config=False)
Esempio n. 2
0
 def _setMode(self, mid, write_config=True):
     """Called when the mouse mode changes"""
     if write_config:
         Config.set("current-mouse-mode", mid)
     self._current_mode = mode = self._modes[mid]
     # hide submodes if any
     for mm in self._all_submodes:
         mm.qa.setVisible(False)
     self._qa_submode_sep.setVisible(bool(mode.submodes))
     self._current_submode = None
     self._available_submodes = mode.submodes
     # make relevant submodes visible, and make sure one is enabled
     if mode.submodes:
         self._ensureValidSubmodes()
     else:
         self.setMouseMode.emit(mode)
Esempio n. 3
0
 def _setMode(self, mid, write_config=True):
     """Called when the mouse mode changes"""
     if write_config:
         Config.set("current-mouse-mode", mid)
     self._current_mode = mode = self._modes[mid]
     # hide submodes if any
     for mm in self._all_submodes:
         mm.qa.setVisible(False)
     self._qa_submode_sep.setVisible(bool(mode.submodes))
     self._current_submode = None
     self._available_submodes = mode.submodes
     # make relevant submodes visible, and make sure one is enabled
     if mode.submodes:
         self._ensureValidSubmodes()
     else:
         self.emit(SIGNAL("setMouseMode"), mode)
Esempio n. 4
0
 def loadSizes(self):
     if self._current_layout is not None:
         dprint(1, "loading sizes for layout", self._current_layout)
         # get main window size and splitter dimensions
         w = Config.getint('%s-main-window-width' % self._current_layout, 0)
         h = Config.getint('%s-main-window-height' % self._current_layout, 0)
         dprint(2, "window size is", w, h)
         if not (w and h):
             return None
         self.resize(QSize(w, h))
         for spl, name in (self._splitter1, "splitter1"), (self._splitter2, "splitter2"):
             ssz = [Config.getint('%s-%s-size%d' % (self._current_layout, name, i), -1) for i in (0, 1)]
             dprint(2, "splitter", name, "sizes", ssz)
             if all([sz >= 0 for sz in ssz]):
                 spl.setSizes(ssz)
             else:
                 return None
     return True
Esempio n. 5
0
 def saveSizes(self):
     if self._current_layout is not None:
         dprint(1, "saving sizes for layout", self._current_layout)
         # save main window size and splitter dimensions
         sz = self.size()
         Config.set('%s-main-window-width' % self._current_layout, sz.width())
         Config.set('%s-main-window-height' % self._current_layout, sz.height())
         for spl, name in ((self._splitter1, "splitter1"), (self._splitter2, "splitter2")):
             ssz = spl.sizes()
             for i, sz in enumerate(ssz):
                 Config.set('%s-%s-size%d' % (self._current_layout, name, i), sz)
Esempio n. 6
0
    def setLayout(self, layout):
        """Changes the current window layout. Restores sizes etc. from config file."""
        if self._current_layout is layout:
            return
        dprint(1, "switching to layout", layout)
        # save sizes to config file
        self.saveSizes()
        # remove imgman widget from all layouts
        for lo in self._skyplot_stack_lo, self._grouptab_stack_lo:
            if lo.indexOf(self.imgman) >= 0:
                lo.removeWidget(self.imgman)
        # assign it to appropriate parent and parent's layout
        if layout is self.LayoutImage:
            lo = self._skyplot_stack_lo
            self.setMaximumSize(self.max_width, self.max_height)
            self.setBaseSize(self.max_width, self.max_height)
            size_policy = QSizePolicy()
            size_policy.setVerticalPolicy(QSizePolicy.Minimum)
            size_policy.setHorizontalPolicy(QSizePolicy.Expanding)
            self.setSizePolicy(size_policy)
            # set central widget size - workaround for bug #164
            # self.cw.setFixedSize(self.max_width - self._ctrl_dialog_min_size - self._profile_and_zoom_widget_min_size, self.max_height)
            # self.cw.setGeometry(0, self.max_width - self._ctrl_dialog_min_size - self._profile_and_zoom_widget_min_size / 2,
            # self.max_width - self._ctrl_dialog_min_size - self._profile_and_zoom_widget_min_size, self.max_height)
        elif layout is self.LayoutEmpty:
            lo = self._skyplot_stack_lo
        else:
            lo = self._grouptab_stack_lo
        self.imgman.setParent(lo.parentWidget())
        lo.addWidget(self.imgman, 0)
        # show/hide panels
        if layout is self.LayoutEmpty:
            self.tw.hide()
            self.grouptab.hide()
            # self.skyplot.show()
        elif layout is self.LayoutImage:
            self.tw.hide()
            self.grouptab.hide()
            self.skyplot.show()
            # setup dockable state from config file
            if Config.getbool('livezoom-show'):
                self.skyplot._livezoom.setVisible(True)
                self.skyplot._dockable_livezoom.setVisible(True)
                self.addDockWidget(Qt.LeftDockWidgetArea,
                                   self.skyplot._dockable_livezoom)
            if Config.getbool('liveprofile-show'):
                self.skyplot._liveprofile.setVisible(True)
                self.skyplot._dockable_liveprofile.setVisible(True)
                self.addDockWidget(Qt.LeftDockWidgetArea,
                                   self.skyplot._dockable_liveprofile)

            # resize dock areas
            widget_list = self.findChildren(QDockWidget)
            size_list = []
            result = []
            for widget in widget_list:
                if not isinstance(widget.bind_widget, ImageControlDialog):
                    size_list.append(widget.bind_widget.width())
                    result.append(widget)
                    dprint(2, f"{widget} width {widget.width()}")
                    dprint(
                        2,
                        f"{widget} bind_widget width {widget.bind_widget.width()}"
                    )
                    if isinstance(widget.bind_widget, LiveImageZoom):
                        widget.bind_widget.setMinimumWidth(widget.width())
            widget_list = result
            # resize dock areas
            self.resizeDocks(widget_list, size_list, Qt.Horizontal)
        elif layout is self.LayoutImageModel:
            self.tw.show()
            self.grouptab.show()
            self.skyplot.show()
        # reload sizes
        self._current_layout = layout
        if not self.loadSizes():
            dprint(1, "no sizes loaded, setting defaults")
            if layout is self.LayoutEmpty:
                self.resize(QSize(512, 256))
            elif layout is self.LayoutImage:
                self.resize(QSize(512, 512))
                self._splitter2.setSizes([512, 0])
            elif layout is self.LayoutImageModel:
                self.resize(QSize(1024, 512))
                self._splitter1.setSizes([256, 256])
                self._splitter2.setSizes([256, 256])