Exemplo n.º 1
0
class ViewStatusBar(QWidget):
    def __init__(self, parent=None):
        super(ViewStatusBar, self).__init__(parent)
        
        layout = QHBoxLayout()
        layout.setContentsMargins(2, 1, 0, 1)
        layout.setSpacing(4)
        self.setLayout(layout)
        self.pos = QLabel()
        layout.addWidget(self.pos)
        
        self.state = QLabel()
        self.state.setFixedSize(16, 16)
        layout.addWidget(self.state)
        
        self.info = QLabel()
        layout.addWidget(self.info, 1)
        
        self.installEventFilter(self)
        self.translateUI()
        app.languageChanged.connect(self.translateUI)
        
    def translateUI(self):
        text = _("Line: {line}, Col: {column}").format(line=9999, column=99)
        self.pos.setMinimumWidth(self.pos.fontMetrics().width(text))
    
    def eventFilter(self, obj, ev):
        if ev.type() == QEvent.MouseButtonPress:
            if ev.button() == Qt.RightButton:
                self.showContextMenu(ev.globalPos())
            else:
                self.parent().activeView().setFocus()
            return True
        return False

    def showContextMenu(self, pos):
        menu = QMenu(self)
        menu.aboutToHide.connect(menu.deleteLater)
        viewspace = self.parent()
        manager = viewspace.manager()
        
        a = QAction(icons.get('view-split-top-bottom'), _("Split &Horizontally"), menu)
        menu.addAction(a)
        a.triggered.connect(lambda: manager.splitViewSpace(viewspace, Qt.Vertical))
        a = QAction(icons.get('view-split-left-right'), _("Split &Vertically"), menu)
        menu.addAction(a)
        a.triggered.connect(lambda: manager.splitViewSpace(viewspace, Qt.Horizontal))
        menu.addSeparator()
        a = QAction(icons.get('view-close'), _("&Close View"), menu)
        a.triggered.connect(lambda: manager.closeViewSpace(viewspace))
        a.setEnabled(manager.canCloseViewSpace())
        menu.addAction(a)
        
        menu.exec_(pos)
Exemplo n.º 2
0
class ViewStatusBar(QWidget):
    def __init__(self, parent=None):
        super(ViewStatusBar, self).__init__(parent)
        
        layout = QHBoxLayout()
        layout.setContentsMargins(2, 1, 0, 1)
        layout.setSpacing(4)
        self.setLayout(layout)
        self.pos = QLabel()
        layout.addWidget(self.pos)
        
        self.state = QLabel()
        self.state.setFixedSize(16, 16)
        layout.addWidget(self.state)
        
        self.info = QLabel()
        layout.addWidget(self.info, 1)
        
        self.installEventFilter(self)
        self.translateUI()
        app.languageChanged.connect(self.translateUI)
        
    def translateUI(self):
        text = _("Line: {line}, Col: {column}").format(line=9999, column=99)
        self.pos.setMinimumWidth(self.pos.fontMetrics().width(text))
    
    def eventFilter(self, obj, ev):
        if ev.type() == QEvent.MouseButtonPress:
            if ev.button() == Qt.RightButton:
                self.showContextMenu(ev.globalPos())
            else:
                self.parent().activeView().setFocus()
            return True
        return False

    def showContextMenu(self, pos):
        menu = QMenu(self)
        menu.aboutToHide.connect(menu.deleteLater)
        viewspace = self.parent()
        manager = viewspace.manager()
        
        a = QAction(icons.get('view-split-top-bottom'), _("Split &Horizontally"), menu)
        menu.addAction(a)
        a.triggered.connect(lambda: manager.splitViewSpace(viewspace, Qt.Vertical))
        a = QAction(icons.get('view-split-left-right'), _("Split &Vertically"), menu)
        menu.addAction(a)
        a.triggered.connect(lambda: manager.splitViewSpace(viewspace, Qt.Horizontal))
        menu.addSeparator()
        a = QAction(icons.get('view-close'), _("&Close View"), menu)
        a.triggered.connect(lambda: manager.closeViewSpace(viewspace))
        a.setEnabled(manager.canCloseViewSpace())
        menu.addAction(a)
        
        menu.exec_(pos)
Exemplo n.º 3
0
class TimerWidget(QLabel):
    def __init__(self,ressource_directory, dim: QSize, clock_dim_ratio: tuple=(0.9, 0.35), clock_color="#FFFFFF", dev_mode=False):
        super().__init__()
        self.setMaximumSize(dim)
        self.setMinimumSize(dim)
        self.font_color = clock_color
        # Setup clock background
        self._load_timer_picture(ressource_directory)
        #self.setPixmap(self.fond_pixmap.scaled(dim, Qt.KeepAspectRatio))
        self.setPixmap(self.fond_pixmap.scaled(QSize(dim.width()-5,dim.height()-5), Qt.KeepAspectRatio))
        self.setContentsMargins((dim.width() - self.pixmap().width()) * 0.5,
                                (dim.height() - self.pixmap().height()) * 0.5,
                                (dim.width() - self.pixmap().width()) * 0.5,
                                (dim.height() - self.pixmap().height()) * 0.5)
        if dev_mode:
            self.setStyleSheet("background-color:yellow")
        else:
            self.setAttribute(Qt.WA_TranslucentBackground, True)
        # Setup clock foreground
        self.clock_layout = QtGui.QGridLayout()
        self.setLayout(self.clock_layout)
        self.clock_layout.setContentsMargins(0,0,0,0)
        self.clock_label = QLabel()
        self.clock_layout.addWidget(self.clock_label)
        self.clock_label.setAlignment(Qt.AlignCenter)
        #self.default_font = self.font() #TODO set custom font
        font = self.clock_label.font()
        font.setBold(True)
        self.clock_label.setFont(font)
        bound = self.clock_label.fontMetrics().boundingRect("00")
        font_size_ratio = min(dim.width() * clock_dim_ratio[0] / bound.width() * 0.5,
                              dim.height() * clock_dim_ratio[1] / bound.height())
        font.setPointSizeF(font_size_ratio * self.clock_label.font().pointSize()+10)
        self.clock_label.setFont(font)
        self.clock_label.setAttribute(Qt.WA_TranslucentBackground, True)
        self.set_timer_value(0)

    # TODO def adjustSize , to resize the widget

    def set_timer_value(self, new_val):
        self.clock_label.setText("<font color=" + self.font_color + ">" + str(new_val) + "</font>")

    def _load_timer_picture(self, ressource_directory):
        """Load les Pixelmap des images du timer
        Utile a l'initialisation """
        # Image de fond
        self.fond_pixmap = QtGui.QPixmap(ressource_directory + "fond_timer.png")
Exemplo n.º 4
0
class MusicPosition(plugin.ViewSpacePlugin):
    def __init__(self, space):
        self._timer = QTimer(singleShot=True, timeout=self.slotTimeout)
        self._waittimer = QTimer(singleShot=True, timeout=self.slotTimeout)
        self._label = QLabel()
        space.status.layout().insertWidget(1, self._label)
        self._view = lambda: None
        space.viewChanged.connect(self.slotViewChanged)
        view = space.activeView()
        if view:
            self.slotViewChanged(view)
        app.translateUI(self)

    def translateUI(self):
        text = _("Pos: {pos}").format(pos="999/16")
        pos_width = self._label.fontMetrics().width(text)
        text = _("Length: {length}").format(length="999/16")
        len_width = self._label.fontMetrics().width(text)
        self._label.setMinimumWidth(max(pos_width, len_width))

    def slotViewChanged(self, view):
        old = self._view()
        if old:
            self.disconnectView(old)
        self._view = weakref.ref(view)
        self.connectView(view)
        self.startTimer()

    def connectView(self, view):
        view.cursorPositionChanged.connect(self.startTimer)
        view.document().contentsChanged.connect(self.startWaitTimer)

    def disconnectView(self, view):
        view.cursorPositionChanged.disconnect(self.startTimer)
        view.document().contentsChanged.disconnect(self.startWaitTimer)

    def startWaitTimer(self):
        """Called when the document changes, waits longer to prevent stutter."""
        self._waittimer.start(900)
        self._timer.stop()

    def startTimer(self):
        """Called when the cursor moves."""
        if not self._waittimer.isActive():
            self._timer.start(100)

    def slotTimeout(self):
        """Called when one of the timers fires."""
        view = self._view()
        if view:
            d = view.document()
            c = view.textCursor()
            import documentinfo

            m = documentinfo.music(d)
            import ly.duration

            if c.hasSelection():
                cursortools.strip_selection(c)
                length = m.time_length(c.selectionStart(), c.selectionEnd())
                text = (
                    _("Length: {length}").format(length=ly.duration.format_fraction(length))
                    if length is not None
                    else ""
                )
            else:
                pos = m.time_position(c.position())
                text = _("Pos: {pos}").format(pos=ly.duration.format_fraction(pos)) if pos is not None else ""
            self._label.setText(text)
Exemplo n.º 5
0
class MusicPosition(plugin.ViewSpacePlugin):
    def __init__(self, space):
        self._timer = QTimer(singleShot=True, timeout=self.slotTimeout)
        self._waittimer = QTimer(singleShot=True, timeout=self.slotTimeout)
        self._label = QLabel()
        space.status.layout().insertWidget(1, self._label)
        self._view = lambda: None
        space.viewChanged.connect(self.slotViewChanged)
        view = space.activeView()
        if view:
            self.slotViewChanged(view)
        app.translateUI(self)
    
    def translateUI(self):
        text = _("Pos: {pos}").format(pos="999/16")
        pos_width = self._label.fontMetrics().width(text)
        text = _("Length: {length}").format(length="999/16")
        len_width = self._label.fontMetrics().width(text)
        self._label.setMinimumWidth(max(pos_width, len_width))
    
    def slotViewChanged(self, view):
        old = self._view()
        if old:
            self.disconnectView(old)
        self._view = weakref.ref(view)
        self.connectView(view)
        self.startTimer()
    
    def connectView(self, view):
        view.cursorPositionChanged.connect(self.startTimer)
        view.document().contentsChanged.connect(self.startWaitTimer)
        
    def disconnectView(self, view):
        view.cursorPositionChanged.disconnect(self.startTimer)
        view.document().contentsChanged.disconnect(self.startWaitTimer)
    
    def startWaitTimer(self):
        """Called when the document changes, waits longer to prevent stutter."""
        self._waittimer.start(900)
        self._timer.stop()
        
    def startTimer(self):
        """Called when the cursor moves."""
        if not self._waittimer.isActive():
            self._timer.start(100)
    
    def slotTimeout(self):
        """Called when one of the timers fires."""
        view = self._view()
        if view:
            d = view.document()
            c = view.textCursor()
            import documentinfo
            m = documentinfo.music(d)
            import ly.duration
            if c.hasSelection():
                cursortools.strip_selection(c)
                length = m.time_length(c.selectionStart(), c.selectionEnd())
                text = _("Length: {length}").format(
                    length=ly.duration.format_fraction(length)) if length is not None else ''
            else:
                pos = m.time_position(c.position())
                text = _("Pos: {pos}").format(
                    pos=ly.duration.format_fraction(pos)) if pos is not None else ''
            self._label.setText(text)