Пример #1
0
    def add_toolbar(self, name, area=Qt.TopToolBarArea):
        """
        Overrides base MainWindow add_toolbar function
        :param name: str
        :param area:
        :return:
        """

        new_toolbar = QToolBar(name)
        # The 0 widget is always the header view of the window
        self.main_layout.insertWidget(1, new_toolbar)
        return new_toolbar
Пример #2
0
    def __init__(self, page, parent=None):
        super(HelpForm, self).__init__(parent)
        self.setAttribute(Qt.WA_DeleteOnClose)
        self.setAttribute(Qt.WA_GroupLeader)

        backAction = QAction(QIcon(":/back.png"), "&Back", self)
        backAction.setShortcut(QKeySequence.Back)
        homeAction = QAction(QIcon(":/home.png"), "&Home", self)
        homeAction.setShortcut("Home")
        self.pageLabel = QLabel()

        toolBar = QToolBar()
        toolBar.addAction(backAction)
        toolBar.addAction(homeAction)
        toolBar.addWidget(self.pageLabel)
        self.textBrowser = QTextBrowser()

        layout = QVBoxLayout()
        layout.addWidget(toolBar)
        layout.addWidget(self.textBrowser, 1)
        self.setLayout(layout)

        backAction.triggered.connect(self.tbackward)
        homeAction.triggered.connect(self.thome)
        self.textBrowser.sourceChanged.connect(self.updatePageTitle)

        self.textBrowser.setSearchPaths([":/help"])
        self.textBrowser.setSource(QUrl(page))
        self.resize(400, 600)
        self.setWindowTitle("{0} Help".format(QApplication.applicationName()))
Пример #3
0
    def __init__(self, *args):
        super(ImageSequenceWidget, self).__init__(*args)

        self.setMouseTracking(True)

        self._image_sequence = image.ImageSequence('')
        self._image_sequence.frameChanged.connect(self._on_frame_changed)

        self._toolbar = QToolBar(self)
        animation.fade_out_widget(self._toolbar, duration=0)

        spacer = QWidget()
        spacer.setMaximumWidth(4)
        spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
        self._toolbar.addWidget(spacer)

        spacer1 = QWidget()
        spacer1.setMaximumWidth(4)
        spacer1.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
        self._first_spacer = self._toolbar.addWidget(spacer1)

        self.set_size(150, 150)
Пример #4
0
    def _setup_toolbar(self):
        """
        Internal function that setups script editor toolbar
        """

        toolbar = QToolBar('Script Editor ToolBar', parent=self)
        toolbar.setIconSize(QSize(16, 16))

        execute_btn = buttons.BaseToolButton(parent=self)
        execute_btn.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        execute_selected_btn = buttons.BaseToolButton(parent=self)
        execute_selected_btn.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        clear_output_btn = buttons.BaseToolButton(parent=self)
        clear_output_btn.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)

        toolbar.addWidget(execute_btn)
        toolbar.addWidget(execute_selected_btn)
        toolbar.addWidget(clear_output_btn)

        execute_btn.setDefaultAction(self._execute_all_action)
        execute_selected_btn.setDefaultAction(self._execute_selected_action)
        clear_output_btn.setDefaultAction(self._clear_output_action)

        return toolbar
Пример #5
0
        def __init__(self, U, plot, length=1, title=None):
            super().__init__()

            layout = QVBoxLayout()

            if title:
                title = QLabel('<b>' + title + '</b>')
                title.setAlignment(Qt.AlignHCenter)
                layout.addWidget(title)
            layout.addWidget(plot)

            plot.set(U, 0)

            if length > 1:
                hlayout = QHBoxLayout()

                self.slider = QSlider(Qt.Horizontal)
                self.slider.setMinimum(0)
                self.slider.setMaximum(length - 1)
                self.slider.setTickPosition(QSlider.TicksBelow)
                hlayout.addWidget(self.slider)

                lcd = QLCDNumber(m.ceil(m.log10(length)))
                lcd.setDecMode()
                lcd.setSegmentStyle(QLCDNumber.Flat)
                hlayout.addWidget(lcd)

                layout.addLayout(hlayout)

                hlayout = QHBoxLayout()

                toolbar = QToolBar()
                self.a_play = QAction(self.style().standardIcon(QStyle.SP_MediaPlay), 'Play', self)
                self.a_play.setCheckable(True)
                self.a_rewind = QAction(self.style().standardIcon(QStyle.SP_MediaSeekBackward), 'Rewind', self)
                self.a_toend = QAction(self.style().standardIcon(QStyle.SP_MediaSeekForward), 'End', self)
                self.a_step_backward = QAction(self.style().standardIcon(QStyle.SP_MediaSkipBackward),
                                               'Step Back', self)
                self.a_step_forward = QAction(self.style().standardIcon(QStyle.SP_MediaSkipForward), 'Step', self)
                self.a_loop = QAction(self.style().standardIcon(QStyle.SP_BrowserReload), 'Loop', self)
                self.a_loop.setCheckable(True)
                toolbar.addAction(self.a_play)
                toolbar.addAction(self.a_rewind)
                toolbar.addAction(self.a_toend)
                toolbar.addAction(self.a_step_backward)
                toolbar.addAction(self.a_step_forward)
                toolbar.addAction(self.a_loop)
                if hasattr(self, 'save'):
                    self.a_save = QAction(self.style().standardIcon(QStyle.SP_DialogSaveButton), 'Save', self)
                    toolbar.addAction(self.a_save)
                    self.a_save.triggered.connect(self.save)
                hlayout.addWidget(toolbar)

                self.speed = QSlider(Qt.Horizontal)
                self.speed.setMinimum(0)
                self.speed.setMaximum(100)
                hlayout.addWidget(QLabel('Speed:'))
                hlayout.addWidget(self.speed)

                layout.addLayout(hlayout)

                self.timer = QTimer()
                self.timer.timeout.connect(self.update_solution)

                self.slider.valueChanged.connect(self.slider_changed)
                self.slider.valueChanged.connect(lcd.display)
                self.speed.valueChanged.connect(self.speed_changed)
                self.a_play.toggled.connect(self.toggle_play)
                self.a_rewind.triggered.connect(self.rewind)
                self.a_toend.triggered.connect(self.to_end)
                self.a_step_forward.triggered.connect(self.step_forward)
                self.a_step_backward.triggered.connect(self.step_backward)

                self.speed.setValue(50)

            elif hasattr(self, 'save'):
                hlayout = QHBoxLayout()
                toolbar = QToolBar()
                self.a_save = QAction(self.style().standardIcon(QStyle.SP_DialogSaveButton), 'Save', self)
                toolbar.addAction(self.a_save)
                hlayout.addWidget(toolbar)
                layout.addLayout(hlayout)
                self.a_save.triggered.connect(self.save)

            self.setLayout(layout)
            self.plot = plot
            self.U = U
            self.length = length
Пример #6
0
        def __init__(self, U, plot, length=1, title=None):
            super().__init__()

            layout = QVBoxLayout()

            if title:
                title = QLabel('<b>' + title + '</b>')
                title.setAlignment(Qt.AlignHCenter)
                layout.addWidget(title)
            layout.addWidget(plot)

            plot.set(U, 0)

            if length > 1:
                hlayout = QHBoxLayout()

                self.slider = QSlider(Qt.Horizontal)
                self.slider.setMinimum(0)
                self.slider.setMaximum(length - 1)
                self.slider.setTickPosition(QSlider.TicksBelow)
                hlayout.addWidget(self.slider)

                lcd = QLCDNumber(m.ceil(m.log10(length)))
                lcd.setDecMode()
                lcd.setSegmentStyle(QLCDNumber.Flat)
                hlayout.addWidget(lcd)

                layout.addLayout(hlayout)

                hlayout = QHBoxLayout()

                toolbar = QToolBar()
                self.a_play = QAction(
                    self.style().standardIcon(QStyle.SP_MediaPlay), 'Play',
                    self)
                self.a_play.setCheckable(True)
                self.a_rewind = QAction(
                    self.style().standardIcon(QStyle.SP_MediaSeekBackward),
                    'Rewind', self)
                self.a_toend = QAction(
                    self.style().standardIcon(QStyle.SP_MediaSeekForward),
                    'End', self)
                self.a_step_backward = QAction(
                    self.style().standardIcon(QStyle.SP_MediaSkipBackward),
                    'Step Back', self)
                self.a_step_forward = QAction(
                    self.style().standardIcon(QStyle.SP_MediaSkipForward),
                    'Step', self)
                self.a_loop = QAction(
                    self.style().standardIcon(QStyle.SP_BrowserReload), 'Loop',
                    self)
                self.a_loop.setCheckable(True)
                toolbar.addAction(self.a_play)
                toolbar.addAction(self.a_rewind)
                toolbar.addAction(self.a_toend)
                toolbar.addAction(self.a_step_backward)
                toolbar.addAction(self.a_step_forward)
                toolbar.addAction(self.a_loop)
                if hasattr(self, 'save'):
                    self.a_save = QAction(
                        self.style().standardIcon(QStyle.SP_DialogSaveButton),
                        'Save', self)
                    toolbar.addAction(self.a_save)
                    self.a_save.triggered.connect(self.save)
                hlayout.addWidget(toolbar)

                self.speed = QSlider(Qt.Horizontal)
                self.speed.setMinimum(0)
                self.speed.setMaximum(100)
                hlayout.addWidget(QLabel('Speed:'))
                hlayout.addWidget(self.speed)

                layout.addLayout(hlayout)

                self.timer = QTimer()
                self.timer.timeout.connect(self.update_solution)

                self.slider.valueChanged.connect(self.slider_changed)
                self.slider.valueChanged.connect(lcd.display)
                self.speed.valueChanged.connect(self.speed_changed)
                self.a_play.toggled.connect(self.toggle_play)
                self.a_rewind.triggered.connect(self.rewind)
                self.a_toend.triggered.connect(self.to_end)
                self.a_step_forward.triggered.connect(self.step_forward)
                self.a_step_backward.triggered.connect(self.step_backward)

                self.speed.setValue(50)

            elif hasattr(self, 'save'):
                hlayout = QHBoxLayout()
                toolbar = QToolBar()
                self.a_save = QAction(
                    self.style().standardIcon(QStyle.SP_DialogSaveButton),
                    'Save', self)
                toolbar.addAction(self.a_save)
                hlayout.addWidget(toolbar)
                layout.addLayout(hlayout)
                self.a_save.triggered.connect(self.save)

            self.setLayout(layout)
            self.plot = plot
            self.U = U
            self.length = length
Пример #7
0
class ImageSequenceWidget(QToolButton, object):

    DEFAULT_PLAYHEAD_COLOR = QColor(255, 255, 255, 220)
    DEFAULT_PLAYHEAD_HEIGHT = 4

    def __init__(self, *args):
        super(ImageSequenceWidget, self).__init__(*args)

        self.setMouseTracking(True)

        self._image_sequence = image.ImageSequence('')
        self._image_sequence.frameChanged.connect(self._on_frame_changed)

        self._toolbar = QToolBar(self)
        animation.fade_out_widget(self._toolbar, duration=0)

        spacer = QWidget()
        spacer.setMaximumWidth(4)
        spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
        self._toolbar.addWidget(spacer)

        spacer1 = QWidget()
        spacer1.setMaximumWidth(4)
        spacer1.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
        self._first_spacer = self._toolbar.addWidget(spacer1)

        self.set_size(150, 150)

    # =================================================================================================================
    # OVERRIDES
    # =================================================================================================================

    def addAction(self, path, text, tip, callback):
        """
        Overrides base QToolButton addAction function
        Adds aan action to the toolbar
        :param path: str
        :param text: str
        :param tip: str
        :param callback: fn
        :return: QAction
        """

        action_icon = icon.Icon.state_icon(
            path,
            color='rgb(250,250,250,160)',
            color_active='rgb(250,250,250,250)',
            color_disabled='rgb(0,0,0,20)'
        )
        action = QAction(action_icon, text, self._toolbar)
        action.setToolTip(tip)
        self._toolbar.insertAction(self._first_spacer, action)
        action.triggered.connect(callback)

        return action

    def actions(self):
        """
        Overrides base QToolButton actions function
        Returns all the actions that are a child of the toolbar
        :return: list(QAction)
        """

        actions = list()
        for child in self._toolbar.children():
            if isinstance(child, QAction):
                actions.append(child)

        return actions

    def resizeEvent(self, event):
        """
        Overrides base QToolButton resizeEvent function
        Called when the widget is resized
        :param event: QResizeEvent
        """

        self.update_toolbar()

    def enterEvent(self, event):
        """
        Overrides base QToolButton enterEvent function
        Starts playing the image sequence when the mouse enters the widget
        :param event: QEvent
        """

        self._image_sequence.start()
        animation.fade_in_widget(self._toolbar, duration=300)

    def leaveEvent(self, event):
        """
        Overrides base QToolButton leaveEvent function
        Stops playing the image sequence when the mouse leaves the widget
        :param event: QEvent
        """

        self._image_sequence.pause()
        animation.fade_out_widget(self._toolbar, duration=300)

    def mouseMoveEvent(self, event):
        """
        Overrides base QToolButton mouseMoveEvent function
        :param event: QEvent
        """

        if qtutils.is_control_modifier() and self._image_sequence.frame_count() > 1:
            percent = 1.0 - (float(self.width() - event.pos().x()) / float(self.width()))
            frame = int(self._image_sequence.frame_count() * percent)
            self._image_sequence.jump_to_frame(frame)
            frame_icon = self._image_sequence.current_icon()
            self.setIcon(frame_icon)

    def paintEvent(self, event):
        """
        Overrides base QToolButton paintEvent function
        Triggered on frame changed
        :param event: QEvent
        """

        super(ImageSequenceWidget, self).paintEvent(event)

        painter = QPainter()
        painter.begin(self)
        if self.current_filename() and self._image_sequence.frame_count() > 1:
            r = event.rect()
            playhead_height = self.playhead_height()
            playhead_pos = self._image_sequence.percent() * r.width() - 1
            x = r.x()
            y = self.height() - playhead_height
            painter.seten(Qt.NoPen)
            painter.setBrush(QBrush(self.DEFAULT_PLAYHEAD_COLOR))
            painter.drawRect(x, y, playhead_pos, playhead_height)

        painter.end()

    # =================================================================================================================
    # BASE
    # =================================================================================================================

    def is_sequence(self):
        """
        Returns whether or not the image sequence has more than one frame
        :return: bool
        """

        return bool(self._image_sequence.frame_count() > 1)

    def dirname(self):
        """
        Returns the directory where the image sequence is located on disk
        :return: str
        """

        return self._image_sequence.dirname()

    def has_frames(self):
        """
        Returns whether or not image sequences has any frames
        :return: bool
        """

        return bool(self.first_frame())

    def first_frame(self):
        """
        Returns first frame path in the image sequence
        :return: str
        """

        return self._image_sequence.first_frame()

    def set_path(self, path):
        """
        Sets a single frame image sequence
        :param path: str
        """

        self._image_sequence.set_path(path)
        self.update_icon()

    def set_dirname(self, dirname):
        """
        Sets the location of the image sequence
        :param dirname: str
        """

        self._image_sequence.set_dirname(dirname)
        self.update_icon()

    def current_filename(self):
        """
        Returns the current image location
        :return: str
        """

        return self._image_sequence.current_filename()

    def playhead_height(self):
        """
        Returns the height of the playhead
        :return: int
        """

        return self.DEFAULT_PLAYHEAD_COLOR

    def set_size(self, w, h):
        """
        Set the size of the widget and updates icon size at the same time
        :param w: int
        :param h: int
        """

        self._size = QSize(w, h)
        self.setIconSize(self._size)
        self.setFixedSize(self._size)

    def update_icon(self):
        """
        Updates the icon for the current frame
        """

        if self._image_sequence.frames():
            frame_icon = self._image_sequence.current_icon()
            self.setIcon(frame_icon)

    def update_toolbar(self):
        """
        Updates the toolbar size depending on the number of actions
        """

        self._toolbar.setIconSize(QSize(16, 16))
        count = len(self.actions()) - 3
        width = 26 * count
        self._toolbar.setGeometry(0, 0, width, 25)
        x = self.rect().center().x() - (self._toolbar.width() * 0.5)
        y = self.height() - self._toolbar.height() - 12
        self._toolbar.setGeometry(x, y, self._toolbar.width(), self._toolbar.height())

    # =================================================================================================================
    # CALLBACKS
    # =================================================================================================================

    def _on_frame_changed(self, frame=None):
        """
        Internal callback function triggered when the image sequence changes frame
        :param frame: int or None
        """

        if not qtutils.is_control_modifier():
            frame_icon = self._image_sequence.current_icon()
            self.setIcon(frame_icon)