예제 #1
0
    def add_dock(self, title, w):
        class DockableWithClose(QDockWidget):
            closed = pyqtSignal()

            def closeEvent(self, evt):
                self.closed.emit()
                QDockWidget.closeEvent(self, evt)

            def resizeEvent(self, evt):
                assert isinstance(evt, QResizeEvent)
                Config.doc_size = (evt.size().width(), evt.size().height())
                super(DockableWithClose, self).resizeEvent(evt)
                evt.accept()

            def sizeHint(self):
                return QSize(Config.doc_size[0], Config.doc_size[1])

        dock = DockableWithClose(title, mw)
        dock.setObjectName(title)
        dock.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea)
        dock.setFeatures(QDockWidget.DockWidgetClosable)
        dock.setWidget(w)
        dock.setContentsMargins(10, 10, 10, 10)
        if mw.width() < 600:
            mw.resize(QSize(600, mw.height()))
        mw.addDockWidget(Qt.RightDockWidgetArea, dock)
        return dock
예제 #2
0
def _dock(pb):
    """Dock for the progress bar. Giving it a blank title bar,
        making sure to set focus back to the reviewer."""
    dock = QDockWidget()
    tWidget = QWidget()
    dock.setObjectName("pbDock")
    dock.setWidget(pb)
    dock.setTitleBarWidget( tWidget )
    
    ## Note: if there is another widget already in this dock position, we have to add ourself to the list

    # first check existing widgets
    existing_widgets = [widget for widget in mw.findChildren(QDockWidget) if mw.dockWidgetArea(widget) == dockArea]

    # then add ourselves
    mw.addDockWidget(dockArea, dock)

    # stack with any existing widgets
    if len(existing_widgets) > 0:
        mw.setDockNestingEnabled(True)

        if dockArea == Qt.TopDockWidgetArea or dockArea == Qt.BottomDockWidgetArea:
            stack_method = Qt.Vertical
        if dockArea == Qt.LeftDockWidgetArea or dockArea == Qt.RightDockWidgetArea:
            stack_method = Qt.Horizontal
        mw.splitDockWidget(existing_widgets[0], dock, stack_method)

    if qbr > 0 or pbdStyle != None:
        # Matches background for round corners.
        # Also handles background for themes' percentage text.
        mw.setPalette(palette)
    mw.web.setFocus()
    return dock
예제 #3
0
    def dock(barList, dockArea):
        """Dock for the progress bar. Giving it a blank title bar,
        making sure to set focus back to the reviewer."""

        if len(barList) == 0:
            return

        mw.setDockNestingEnabled(True)
        dockWidgets = [QDockWidget() for _ in barList]
        widgets = [EmptyWidget() for _ in barList]

        prevWidget = None
        existing_widgets = [widget for widget in mw.findChildren(QDockWidget) if mw.dockWidgetArea(widget) == dockArea]
        if len(existing_widgets) > 0:
            prevWidget = existing_widgets[0]

        for i, bar in enumerate(barList):
            dock = dockWidgets[i]

            tWidget = widgets[i]
            dock.setWidget(bar)
            dock.setTitleBarWidget( tWidget )
            mw.addDockWidget(dockArea, dock)
            if prevWidget == None:
                prevWidget = dock
            else:
                # Moves second dock widget on top of first dock widget
                if dockArea == Qt.TopDockWidgetArea or dockArea == Qt.BottomDockWidgetArea:
                    stack_method = Qt.Vertical
                if dockArea == Qt.LeftDockWidgetArea or dockArea == Qt.RightDockWidgetArea:
                    stack_method = Qt.Horizontal
                mw.splitDockWidget(prevWidget, dock, stack_method)
                prevWidget = dock
        mw.web.setFocus()
예제 #4
0
 def _addDockable(self, title, w):
     dock = QDockWidget(title, mw)
     dock.setObjectName(title)
     dock.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea)
     dock.setFeatures(QDockWidget.DockWidgetClosable)
     dock.setWidget(w)
     if mw.width() < 600:
         mw.resize(QSize(600, mw.height()))
     mw.addDockWidget(Qt.RightDockWidgetArea, dock)
     return dock
예제 #5
0
 def _addDockable(self, title, w):
     dock = QDockWidget(title, mw)
     dock.setObjectName(title)
     dock.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea)
     dock.setFeatures(QDockWidget.DockWidgetClosable)
     dock.setWidget(w)
     if mw.width() < 600:
         mw.resize(QSize(600, mw.height()))
     mw.addDockWidget(Qt.RightDockWidgetArea, dock)
     return dock
예제 #6
0
 def _addDockable(self):
     self.web = QWebEngineView()
     self.dock = DockableWithClose(_(self.title), mw)
     self.dock.setObjectName(_(self.title))
     self.dock.setWidget(self.web)
     self.dock.closed.connect(self._onClosed)
     self.dock.setAllowedAreas(Qt.BottomDockWidgetArea | Qt.RightDockWidgetArea | Qt.LeftDockWidgetArea)
     if self.type>10:
         pos=Qt.RightDockWidgetArea
     elif self.type<-10:
         pos=Qt.LeftDockWidgetArea
     else:
         pos=Qt.BottomDockWidgetArea
     mw.addDockWidget(pos, self.dock)
예제 #7
0
 def _addDockable(self, title, w):
     class DockableWithClose(QDockWidget):
         def closeEvent(self, evt):
             self.emit(SIGNAL("closed"))
             QDockWidget.closeEvent(self, evt)
     dock = DockableWithClose(title, mw)
     dock.setObjectName(title)
     dock.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea)
     dock.setFeatures(QDockWidget.DockWidgetClosable)
     dock.setWidget(w)
     if mw.width() < 600:
         mw.resize(QSize(600, mw.height()))
     mw.addDockWidget(Qt.RightDockWidgetArea, dock)
     return dock
예제 #8
0
    def setup_progressbar(self):

        dockArea = Qt.TopDockWidgetArea
        # dockArea = Qt.LeftDockWidgetArea
        # dockArea = Qt.BottomDockWidgetArea

        self.pb_w = QDockWidget(mw)
        self.pb_w.setObjectName("progress_dock")
        if not self.pb:
            self.pb = ClockProgress(mw, dockArea)
            self.pb.tomato.connect(self.on_tomato)
        else:
            self.pb.reset()

        self.pb.set_seconds(self.dlg.min * MIN_SECS)
        self.pb_w.setWidget(self.pb)
        w = QWidget(self.pb_w)
        w.setFixedHeight(self.pb.height())
        self.pb_w.setTitleBarWidget(w)
        self.pb_w.setFeatures(QDockWidget.NoDockWidgetFeatures)

        # first check existing widgets
        existing_widgets = [widget for widget in mw.findChildren(QDockWidget) if mw.dockWidgetArea(widget) == dockArea]

        # then add ourselves
        mw.addDockWidget(dockArea, self.pb_w)

        # stack with any existing widgets
        if len(existing_widgets) > 0:
            mw.setDockNestingEnabled(True)

            if dockArea == Qt.TopDockWidgetArea or dockArea == Qt.BottomDockWidgetArea:
                stack_method = Qt.Vertical
            if dockArea == Qt.LeftDockWidgetArea or dockArea == Qt.RightDockWidgetArea:
                stack_method = Qt.Horizontal
            mw.splitDockWidget(existing_widgets[0], self.pb_w, stack_method)

        mw.web.setFocus()
        self._set_style_sheet(self.pb)
예제 #9
0
    def dockAt(self, place):
        '''
        Docks the bar at the specified place in the Anki window.
        '''
        barVisible = self._qProgressBar.isVisible()

        if self._dock is not None:
            self._dock.close()

        place = POSITION_OPTIONS[place]

        if place not in POSITION_OPTIONS:
            place = DEFAULTS['barPosition']

        if place == 'Top':
            dockArea = qt.Qt.TopDockWidgetArea
        elif place == 'Bottom':
            dockArea = qt.Qt.BottomDockWidgetArea

        self._dock = qt.QDockWidget()
        tWidget = qt.QWidget()
        self._dock.setWidget(self._qProgressBar)
        self._dock.setTitleBarWidget(tWidget)

        existingWidgets = [
            widget for widget in mw.findChildren(qt.QDockWidget)
            if mw.dockWidgetArea(widget) == dockArea
        ]
        if not existingWidgets:
            mw.addDockWidget(dockArea, self._dock)
        else:
            mw.setDockNestingEnabled(True)
            mw.splitDockWidget(existingWidgets[0], self._dock, qt.Qt.Vertical)
        mw.web.setFocus()

        self._qProgressBar.setVisible(barVisible)
def main():
    if not check_qt_version():
        return

    inspector = Inspector('', mw)
    mw.addDockWidget(Qt.RightDockWidgetArea, inspector)