class GstMediaSettings(SettingsSection):

    Name = 'Media Settings'

    def __init__(self, size, cue=None, parent=None):
        super().__init__(size, cue=cue, parent=parent)
        self._pipe = ''
        self._conf = {}
        self._check = False

        self.glayout = QGridLayout(self)

        self.listWidget = QListWidget(self)
        self.glayout.addWidget(self.listWidget, 0, 0)

        self.pipeButton = QPushButton('Change Pipe', self)
        self.glayout.addWidget(self.pipeButton, 1, 0)

        self.elements = QStackedWidget(self)
        self.glayout.addWidget(self.elements, 0, 1, 2, 1)

        self.glayout.setColumnStretch(0, 2)
        self.glayout.setColumnStretch(1, 5)

        self.listWidget.currentItemChanged.connect(self.__change_page)
        self.pipeButton.clicked.connect(self.__edit_pipe)

    def set_configuration(self, conf):
        # Get the media section of the cue configuration
        if conf is not None:
            conf = conf.get('media', {})

            # Activate the layout, so we can get the right widgets size
            self.glayout.activate()

            # Create a local copy of the configuration
            self._conf = deepcopy(conf)

            # Create the widgets
            sections = sections_by_element_name()
            for element in conf.get('pipe', '').split('!'):
                widget = sections.get(element)

                if widget is not None:
                    widget = widget(self.elements.size(), element, self)
                    widget.set_configuration(self._conf['elements'])
                    self.elements.addWidget(widget)

                    item = QListWidgetItem(widget.NAME)
                    self.listWidget.addItem(item)

            self.listWidget.setCurrentRow(0)

    def get_configuration(self):
        conf = {'elements': {}}

        for el in self.elements.children():
            if isinstance(el, SettingsSection):
                conf['elements'].update(el.get_configuration())

        # If in check mode the pipeline is not returned
        if not self._check:
            conf['pipe'] = self._conf['pipe']

        return {'media': conf}

    def enable_check(self, enable):
        self._check = enable
        for element in self.elements.children():
            if isinstance(element, SettingsSection):
                element.enable_check(enable)

    def __change_page(self, current, previous):
        if not current:
            current = previous

        self.elements.setCurrentIndex(self.listWidget.row(current))

    def __edit_pipe(self):
        # Backup the settings
        self._conf.update(self.get_configuration()['media'])

        # Show the dialog
        dialog = GstPipeEdit(self._conf.get('pipe', ''), parent=self)

        if dialog.exec_() == dialog.Accepted:
            # Reset the view
            for _ in range(self.elements.count()):
                self.elements.removeWidget(self.elements.widget(0))
            self.listWidget.clear()

            # Reload with the new pipeline
            self._conf['pipe'] = dialog.get_pipe()

            self.set_configuration({'media': self._conf})
            self.enable_check(self._check)
Esempio n. 2
0
class NavigationInterface(QWidget):
    """ 导航界面 """
    def __init__(self, contactInfo_list: List[Dict[str, str]], parent=None):
        super().__init__(parent=parent)
        # 读取用户信息
        self.userInfo = getUserInfo()
        # 实例化小部件
        self.searchLineEdit = SearchLineEdit(self)
        self.__createButtons()
        self.userNameLabel = QLabel(self)
        self.personalSignatureLabel = QLabel(self)
        self.headPortraitWidget = HeadPortrait(
            self.userInfo['headPortraitPath'], (45, 45), self)
        self.stackedWidget = QStackedWidget(self)
        self.chatListWidget = ChatListWidget(self)
        self.contactInterface = ContactInterface(contactInfo_list, self)
        self.stateWidget = StateWidget(parent=self)
        # 界面字典
        self.__interface_dict = {
            0: self.chatListWidget,
            1: self.contactInterface
        }
        # 初始化界面
        self.__initWidget()

    def __initWidget(self):
        """ 初始化界面 """
        self.setFixedWidth(402)
        self.resize(402, 917)
        self.stateWidget.move(40, 40)
        self.dialsButton.move(351, 70)
        self.searchButton.move(22, 83)
        self.stackedWidget.move(0, 183)
        self.userNameLabel.move(67, 13)
        self.searchLineEdit.move(10, 70)
        self.headPortraitWidget.move(10, 10)
        self.moreActionsButton.move(351, 11)
        self.personalSignatureLabel.move(67, 33)
        self.chatButton.move(38, 127)
        self.noticeButton.move(340, 127)
        self.contactButton.move(233, 127)
        self.conversationButton.move(138, 127)
        # 将子窗口添加到层叠窗口中
        self.stackedWidget.addWidget(self.chatListWidget)
        self.stackedWidget.addWidget(self.contactInterface)
        self.chatButton.setSelected(True)
        # 设置层叠样式
        self.setAttribute(Qt.WA_StyledBackground)
        self.setObjectName('navigationInterface')
        self.userNameLabel.setObjectName('userNameLabel')
        self.personalSignatureLabel.setObjectName('personalSignatureLabel')
        self.__setQss()
        # 调整个新签名和用户名长度
        self.__setLabelText()
        # 信号连接到槽函数
        self.__connectSignalToSlot()

    def __createButtons(self):
        """ 创建按钮 """
        opacity_dict = {'normal': 1, 'hover': 0.72, 'pressed': 0.2}
        chatButtonIconPath_dict = {
            'normal': r'app\resource\Image\navigation_interface\聊天_normal.png',
            'hover': r'app\resource\Image\navigation_interface\聊天_hover.png',
            'selected':
            r'app\resource\Image\navigation_interface\聊天_selected.png',
        }
        conversationButtonIconPath_dict = {
            'normal': r'app\resource\Image\navigation_interface\通话_normal.png',
            'hover': r'app\resource\Image\navigation_interface\通话_hover.png',
            'selected':
            r'app\resource\Image\navigation_interface\通话_selected.png',
        }
        contactsButtonIconPath_dict = {
            'normal':
            r'app\resource\Image\navigation_interface\联系人_normal.png',
            'hover':
            r'app\resource\Image\navigation_interface\联系人_hover.png',
            'selected':
            r'app\resource\Image\navigation_interface\联系人_selected.png',
        }
        noticeButtonIconPath_dict = {
            'normal': r'app\resource\Image\navigation_interface\通知_normal.png',
            'hover': r'app\resource\Image\navigation_interface\通知_hover.png',
            'selected':
            r'app\resource\Image\navigation_interface\通知_selected.png',
        }
        self.moreActionsButton = OpacityThreeStateToolButton(
            r'app\resource\Image\navigation_interface\更多操作.png',
            opacity_dict,
            parent=self)
        self.searchButton = OpacityThreeStateToolButton(
            r'app\resource\Image\navigation_interface\搜索.png', opacity_dict,
            (18, 18), self)
        self.dialsButton = OpacityThreeStateToolButton(
            r'app\resource\Image\navigation_interface\拨号盘.png', opacity_dict,
            (40, 40), self)
        self.chatButton = NavigationButton(chatButtonIconPath_dict,
                                           '聊天',
                                           parent=self)
        self.conversationButton = NavigationButton(
            conversationButtonIconPath_dict, '通话', parent=self)
        self.contactButton = NavigationButton(contactsButtonIconPath_dict,
                                              '联系人', (38, 42),
                                              parent=self)
        self.noticeButton = NavigationButton(noticeButtonIconPath_dict,
                                             '通知',
                                             parent=self)
        self.navigationButton_list = [
            self.chatButton, self.contactButton, self.conversationButton,
            self.noticeButton
        ]

    def __setQss(self):
        """ 设置层叠样式 """
        with open(r'app\resource\qss\navigation_interface.qss',
                  encoding='utf-8') as f:
            self.setStyleSheet(f.read())

    def paintEvent(self, e):
        """ 绘制背景 """
        super().paintEvent(e)
        painter = QPainter(self)
        painter.setPen(QPen(QColor(213, 217, 222)))
        painter.drawLine(0, 182, self.width(), 183)

    def resizeEvent(self, e):
        """ 调整窗口大小 """
        super().resizeEvent(e)
        self.stackedWidget.resize(self.width(), self.height() - 183)
        self.contactInterface.resize(self.stackedWidget.size())
        self.chatListWidget.resize(self.stackedWidget.size())

    def __setLabelText(self):
        """设置用户名和个新签名标签的文字并根据字符串长短来添加省略号 """
        # 调整个新签名
        fontMetrics = QFontMetrics(QFont('Microsoft YaHei', 8))
        newText = fontMetrics.elidedText(self.userInfo['personalSignature'],
                                         Qt.ElideRight, 250)
        self.personalSignatureLabel.setText(newText)
        self.personalSignatureLabel.adjustSize()
        # 调整用户名
        newText = fontMetrics.elidedText(self.userInfo['userName'],
                                         Qt.ElideRight, 260)
        self.userNameLabel.setText(newText)
        self.userNameLabel.adjustSize()

    def updateUserInfo(self, userInfo: dict):
        """ 更新用户信息 """
        self.userInfo = userInfo.copy()
        self.__setLabelText()
        self.headPortraitWidget.setHeadPortrait(userInfo['headPortraitPath'])

    def switchToContactInterface(self):
        """ 切换到联系人界面 """
        self.__switchInterface(1)

    def switchToChatInterface(self):
        """ 切换到联系人界面 """
        self.__switchInterface(0)

    def __switchInterface(self, index: int):
        """ 切换界面 """
        currentIndex = self.stackedWidget.currentIndex()
        if index not in self.__interface_dict.keys():
            self.navigationButton_list[index].setSelected(False)
            return
        elif index == currentIndex:
            return
        self.navigationButton_list[currentIndex].setSelected(False)
        self.navigationButton_list[index].setSelected(True)
        self.stackedWidget.setCurrentWidget(self.__interface_dict[index])

    def __connectSignalToSlot(self):
        """ 信号连接到槽函数 """
        # 切换界面
        for i, button in enumerate(self.navigationButton_list):
            button.clicked.connect(lambda x, i=i: self.__switchInterface(i))
Esempio n. 3
0
class Toolbox(QWidget):
    """A side-oriented widget similar to a TabWidget that can be collapsed and
    expanded.

    A Toolbox is designed to be a container for sets of controls, grouped into
    'pages' and accessible by a TabBar, in the same way as a TabWidget.
    A page is normally a QWidget with a layout that contains controls.
    A widget can be added as a new tab using :meth:`addTab`.
    The Toolbox has slots for triggering its collapse and expansion, both in an
    animated mode (soft slide) and a 'quick' mode which skips the animation.
    Commonly the collapse/expand slots are connected to the tabBar's
    :meth:`tabBarDoubleClicked` signal. Normally in the DataLogger a Toolbox is
    created and then added to a :class:`~cued_datalogger.api.toolbox.MasterToolbox`,
    which connects the relevant signals for collapsing and expanding the
    Toolbox.


    Attributes
    ----------
    tabBar : QTabBar
    tabPages : QStackedWidget
        The stack of widgets that form the pages of the tabs.
    collapse_animation : QPropertyAnimation
        The animation that controls how the Toolbox collapses.
    """
    sig_collapsed_changed = pyqtSignal()

    def __init__(self, widget_side='left', parent=None):
        self.parent = parent
        self.widget_side = widget_side

        super().__init__(parent)

        self.layout = QHBoxLayout()
        self.layout.setSpacing(0)
        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

        # # Create the tab bar
        self.tabBar = QTabBar(self)

        self.tabBar.setTabsClosable(False)
        self.tabBar.setMovable(False)
        self.tabBar.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding)
        # # Create the Stacked widget for the pages
        self.tabPages = QStackedWidget(self)

        # # Link the signals so that changing tab leads to a change of page
        self.tabBar.currentChanged.connect(self.changePage)

        # # Add them to the splitter (self)
        # Right side orientation
        if self.widget_side == 'right':
            self.tabBar.setShape(QTabBar.RoundedWest)

            self.layout.addWidget(self.tabBar)
            self.layout.addWidget(self.tabPages)

        # Left side orientation
        else:
            self.tabBar.setShape(QTabBar.RoundedEast)

            self.layout.addWidget(self.tabPages)
            self.layout.addWidget(self.tabBar)

        self.setLayout(self.layout)
        self.collapsed = False
        self.expanded_width = self.sizeHint().width()

    def addTab(self, widget, title):
        """Add a new tab, with the page widget *widget* and tab title
        *title*."""
        self.tabBar.addTab(title)
        self.tabPages.addWidget(widget)

    def removeTab(self, title):
        """Remove the tab with title *title*."""
        for tab_num in range(self.tabBar.count()):
            if self.tabBar.tabText(tab_num) == title:
                self.tabBar.removeTab(tab_num)
                self.tabPages.removeWidget(self.tabPages.widget(tab_num))

    def toggle_collapse(self):
        """If collapsed, expand the widget so the pages are visible. If not
        collapsed, collapse the widget so that only the tabBar is showing."""
        # If collapsed, expand
        if self.collapsed:
            self.expand()
        # If expanded, collapse:
        else:
            self.collapse()

    def expand(self):
        """Expand the widget so that the pages are visible."""
        self.tabPages.show()
        self.sig_collapsed_changed.emit()
        self.collapsed = False

    def collapse(self):
        """Collapse the widget so that only the tab bar is visible."""
        self.tabPages.hide()
        self.sig_collapsed_changed.emit()
        self.collapsed = True

    def changePage(self, index):
        """Set the current page to *index*."""
        self.tabBar.setCurrentIndex(index)
        self.tabPages.setCurrentIndex(index)

        if self.tabPages.currentWidget():
            self.tabPages.currentWidget().resize(self.tabPages.size())

    def clear(self):
        """Remove all tabs and pages."""
        for i in range(self.tabBar.count()):
            # Remove the tab and page at position 0
            self.tabBar.removeTab(0)
            self.tabPages.removeWidget(self.tabPages.currentWidget())