示例#1
0
class ToolsetHelpWidget(base.BaseFrame, object):
    def __init__(self, parent=None):
        super(ToolsetHelpWidget, self).__init__(parent=parent)

    def ui(self):
        super(ToolsetHelpWidget, self).ui()

        self.setFrameStyle(QFrame.StyledPanel | QFrame.Plain)

        self._image_label = label.BaseLabel(parent=self)
        self._title_label = label.BaseLabel(parent=self).strong()
        self._description_text = QPlainTextEdit(parent=self)
        # self._description_text.setFrameShape(QFrame.NoFrame)
        self._description_text.setMinimumWidth(200)
        self._description_text.setSizePolicy(QSizePolicy.Expanding,
                                             QSizePolicy.Expanding)
        self._gif_label = gif.GifLabel(parent=self)
        self._gif_label.set_size(256, 256)

        self.main_layout.addWidget(self._title_label)
        self.main_layout.addWidget(dividers.Divider())
        body_layout = layouts.HorizontalLayout(spacing=0, margins=(0, 0, 0, 0))
        body_layout.addWidget(self._description_text)
        body_layout.addWidget(self._gif_label)
        body_layout.addWidget(self._image_label)
        body_layout.addStretch()
        self.main_layout.addLayout(body_layout)

    def set_title(self, title):
        self._title_label.setText(str(title))

    def set_description(self, description):
        self._description_text.setPlainText(str(description))

    def set_image(self, image_file):
        if not image_file or not os.path.isfile(image_file):
            return
        self._image_label.setPixmap(
            QPixmap(image_file).scaled(QSize(256, 256), Qt.KeepAspectRatio))
        self._image_label.setVisible(True)
        self._gif_label.setVisible(False)

    def set_gif(self, gif_file):
        if not gif_file or not os.path.isfile(gif_file):
            return
        self._gif_label.set_file(gif_file)
        self._gif_label.setVisible(True)
        self._image_label.setVisible(False)
class InfoMessage(base.BaseWidget, object):
    def __init__(self, name='', description='', instructions='', parent=None):
        self._name = ''
        self._description = ''
        self._instructions = instructions

        super(InfoMessage, self).__init__(parent)

        self.setAttribute(Qt.WA_StyledBackground)
        self.theme_type = message.MessageTypes.INFO
        self.style().polish(self)
        self.name = name
        self.description = description
        self.instructions = instructions

    # =================================================================================================================
    # PROPERTIES
    # =================================================================================================================

    def _get_name(self):
        return self._name

    def _set_name(self, name):
        self._name = str(name)
        self._expandable_frame.set_title(self._name)

    def _get_description(self):
        return self._description

    def _set_description(self, text):
        self._description = str(text)
        self._description_text.setPlainText(self._description)

    def _get_instructions(self):
        return self._instructions

    def _set_instructions(self, instructions):
        self._instructions = str(instructions)
        self._instructions_text.clear()
        self._instructions_text.insertHtml(instructions)
        self._instructions_widget.setVisible(bool(instructions))

    name = Property(str, _get_name, _set_name)
    description = Property(str, _get_description, _set_description)
    instructions = Property(str, _get_instructions, _set_instructions)

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

    def ui(self):
        super(InfoMessage, self).ui()

        self.setMaximumHeight(150)

        info_icon = resources.icon('info')
        self._expandable_frame = expandables.ExpandableFrame(icon=info_icon,
                                                             parent=self)
        self._expandable_frame.setFrameStyle(QFrame.StyledPanel
                                             | QFrame.Raised)

        expandable_layout = layouts.HorizontalLayout(margins=(2, 2, 2, 2))

        texts_layout = layouts.HorizontalLayout(spacing=0,
                                                margins=(0, 0, 0, 0))
        self._description_text = QPlainTextEdit(parent=self)
        self._description_text.setReadOnly(True)
        self._description_text.setSizePolicy(QSizePolicy.Preferred,
                                             QSizePolicy.Maximum)
        self._description_text.setFocusPolicy(Qt.NoFocus)
        self._description_text.setFrameShape(QFrame.NoFrame)
        self._instructions_widget = QWidget()
        instructions_layout = layouts.VerticalLayout(spacing=2,
                                                     margins=(0, 0, 0, 0))
        self._instructions_widget.setLayout(instructions_layout)
        self._instructions_text = QTextEdit(parent=self)
        self._instructions_text.setReadOnly(True)
        self._instructions_text.setSizePolicy(QSizePolicy.Preferred,
                                              QSizePolicy.Maximum)
        self._instructions_text.setFocusPolicy(Qt.NoFocus)
        self._instructions_text.setFrameShape(QFrame.NoFrame)
        self._instructions_widget.setVisible(False)
        # self._instructions_text.insertHtml("<ul><li>text 1</li><li>text 2</li><li>text 3</li></ul> <br />")
        instructions_layout.addWidget(dividers.Divider('Instructions'))
        instructions_layout.addWidget(self._instructions_text)
        texts_layout.addWidget(self._description_text)
        texts_layout.addWidget(self._instructions_widget)

        content_layout = layouts.VerticalLayout()
        content_layout.addLayout(texts_layout)
        expandable_layout.addLayout(content_layout)

        self._expandable_frame.addLayout(expandable_layout)

        self.main_layout.addWidget(self._expandable_frame)