Ejemplo n.º 1
0
 def __init__(self, alignment=Qt.AlignCenter, parent=None):
     super(MLineTabWidget, self).__init__(parent=parent)
     self.tool_button_group = MUnderlineButtonGroup()
     self.bar_layout = QHBoxLayout()
     self.bar_layout.setContentsMargins(0, 0, 0, 0)
     if alignment == Qt.AlignCenter:
         self.bar_layout.addStretch()
         self.bar_layout.addWidget(self.tool_button_group)
         self.bar_layout.addStretch()
     elif alignment == Qt.AlignLeft:
         self.bar_layout.addWidget(self.tool_button_group)
         self.bar_layout.addStretch()
     elif alignment == Qt.AlignRight:
         self.bar_layout.addStretch()
         self.bar_layout.addWidget(self.tool_button_group)
     self.stack_widget = MStackedWidget()
     self.tool_button_group.sig_checked_changed.connect(
         self.stack_widget.setCurrentIndex)
     main_lay = QVBoxLayout()
     main_lay.setContentsMargins(0, 0, 0, 0)
     main_lay.setSpacing(0)
     main_lay.addLayout(self.bar_layout)
     main_lay.addWidget(MDivider())
     main_lay.addSpacing(5)
     main_lay.addWidget(self.stack_widget)
     self.setLayout(main_lay)
Ejemplo n.º 2
0
    def __init__(self, parent=None):
        super(SpinBoxExample, self).__init__(parent)
        self.setWindowTitle('Examples for Spin Box')

        main_lay = QVBoxLayout()
        class_list = [
            MSpinBox, MDoubleSpinBox, MDateTimeEdit, MDateEdit, MTimeEdit
        ]
        size_list = [dayu_theme.large, dayu_theme.medium, dayu_theme.small]
        for cls in class_list:
            main_lay.addWidget(MDivider(cls.__name__))
            lay = QHBoxLayout()
            for size in size_list:
                line_edit_large = cls()
                line_edit_large.set_dayu_size(size)
                lay.addWidget(line_edit_large)
            main_lay.addLayout(lay)

        main_lay.addWidget(MDivider('Pop Calendar Widget'))
        date_time_edit = MDateTimeEdit()
        date_time_edit.setCalendarPopup(True)
        date_edit = MDateEdit()
        date_edit.setCalendarPopup(True)
        time_edit = MTimeEdit()
        time_edit.setCalendarPopup(True)
        date_lay = QHBoxLayout()
        date_lay.addWidget(date_time_edit)
        date_lay.addWidget(date_edit)
        date_lay.addWidget(time_edit)
        main_lay.addLayout(date_lay)

        main_lay.addStretch()
        self.setLayout(main_lay)
Ejemplo n.º 3
0
    def __init__(self, text='', parent=None, flags=0):
        super(MAlert, self).__init__(parent, flags)
        self.setAttribute(Qt.WA_StyledBackground)
        self._icon_label = MAvatar()
        self._icon_label.set_dayu_size(dayu_theme.tiny)
        self._content_label = MLabel().secondary()
        self._close_button = MToolButton().svg(
            'close_line.svg').tiny().icon_only()
        self._close_button.clicked.connect(
            functools.partial(self.setVisible, False))

        self._main_lay = QHBoxLayout()
        self._main_lay.setContentsMargins(8, 8, 8, 8)
        self._main_lay.addWidget(self._icon_label)
        self._main_lay.addWidget(self._content_label)
        self._main_lay.addStretch()
        self._main_lay.addWidget(self._close_button)

        self.setLayout(self._main_lay)

        self.set_show_icon(True)
        self.set_closeable(False)
        self._dayu_type = None
        self._dayu_text = None
        self.set_dayu_type(MAlert.InfoType)
        self.set_dayu_text(text)
Ejemplo n.º 4
0
    def __init__(self, view_type=None, parent=None):
        super(MItemViewSet, self).__init__(parent)
        self.main_lay = QVBoxLayout()
        self.main_lay.setSpacing(5)
        self.main_lay.setContentsMargins(0, 0, 0, 0)

        self.sort_filter_model = MSortFilterModel()
        self.source_model = MTableModel()
        self.sort_filter_model.setSourceModel(self.source_model)
        view_class = view_type or MItemViewSet.TableViewType
        self.item_view = view_class()
        self.item_view.doubleClicked.connect(self.sig_double_clicked)
        self.item_view.pressed.connect(self.slot_left_clicked)
        self.item_view.setModel(self.sort_filter_model)

        self._search_line_edit = MLineEdit().search().small()
        self._search_attr_button = MToolButton().icon_only().svg(
            'down_fill.svg').small()
        self._search_line_edit.set_prefix_widget(self._search_attr_button)
        self._search_line_edit.textChanged.connect(
            self.sort_filter_model.set_search_pattern)
        self._search_line_edit.setVisible(False)
        self._search_lay = QHBoxLayout()
        self._search_lay.setContentsMargins(0, 0, 0, 0)
        self._search_lay.addStretch()
        self._search_lay.addWidget(self._search_line_edit)

        self.main_lay.addLayout(self._search_lay)
        self.main_lay.addWidget(self.item_view)
        self.setLayout(self.main_lay)
Ejemplo n.º 5
0
class MMenuTabWidget(QWidget):
    """MMenuTabWidget"""
    def __init__(self, parent=None):
        super(MMenuTabWidget, self).__init__(parent=parent)
        self.tool_button_group = MBlockButtonGroup()
        self._bar_layout = QHBoxLayout()
        self._bar_layout.setContentsMargins(10, 0, 10, 0)
        self._bar_layout.addWidget(self.tool_button_group)
        self._bar_layout.addStretch()
        bar_widget = QWidget()
        bar_widget.setObjectName('bar_widget')
        bar_widget.setLayout(self._bar_layout)
        bar_widget.setAttribute(Qt.WA_StyledBackground)
        main_lay = QVBoxLayout()
        main_lay.setContentsMargins(0, 0, 0, 0)
        main_lay.setSpacing(0)
        main_lay.addWidget(bar_widget)
        main_lay.addWidget(MDivider())
        main_lay.addSpacing(5)
        self.setLayout(main_lay)
        self.setFixedHeight(dayu_theme.large + 10)

    def tool_bar_append_widget(self, widget):
        """Add the widget too menubar's right position."""
        self._bar_layout.addWidget(widget)

    def tool_bar_insert_widget(self, widget):
        """Insert the widget to menubar's left position."""
        self._bar_layout.insertWidget(0, widget)

    def add_menu(self, data_dict, index=None):
        """Add a menu"""
        self.tool_button_group.add_button(data_dict, index)
Ejemplo n.º 6
0
    def __init__(self, text='', orientation=Qt.Horizontal, alignment=Qt.AlignCenter, parent=None):
        super(MDivider, self).__init__(parent)
        self._orient = orientation
        self._text_label = MLabel().secondary()
        self._left_frame = QFrame()
        self._right_frame = QFrame()
        self._main_lay = QHBoxLayout()
        self._main_lay.setContentsMargins(0, 0, 0, 0)
        self._main_lay.setSpacing(0)
        self._main_lay.addWidget(self._left_frame)
        self._main_lay.addWidget(self._text_label)
        self._main_lay.addWidget(self._right_frame)
        self.setLayout(self._main_lay)

        if orientation == Qt.Horizontal:
            self._left_frame.setFrameShape(QFrame.HLine)
            self._left_frame.setFrameShadow(QFrame.Sunken)
            self._right_frame.setFrameShape(QFrame.HLine)
            self._right_frame.setFrameShadow(QFrame.Sunken)
        else:
            self._text_label.setVisible(False)
            self._right_frame.setVisible(False)
            self._left_frame.setFrameShape(QFrame.VLine)
            self._left_frame.setFrameShadow(QFrame.Plain)
            self.setFixedWidth(2)
        self._main_lay.setStretchFactor(self._left_frame,
                                        self._alignment_map.get(alignment, 50))
        self._main_lay.setStretchFactor(self._right_frame,
                                        100 - self._alignment_map.get(alignment, 50))
        self._text = None
        self.set_dayu_text(text)
Ejemplo n.º 7
0
    def __init__(self, text, duration=None, dayu_type=None, closable=False, parent=None):
        super(MMessage, self).__init__(parent)
        self.setObjectName('message')
        self.setWindowFlags(
            Qt.FramelessWindowHint | Qt.Dialog | Qt.WA_TranslucentBackground | Qt.WA_DeleteOnClose)
        self.setAttribute(Qt.WA_StyledBackground)

        if dayu_type == MMessage.LoadingType:
            _icon_label = MLoading.tiny()
        else:
            _icon_label = MAvatar.tiny()
            current_type = dayu_type or MMessage.InfoType
            _icon_label.set_dayu_image(MPixmap('{}_fill.svg'.format(current_type),
                                               vars(dayu_theme).get(current_type + '_color')))

        self._content_label = MLabel(parent=self)
        # self._content_label.set_elide_mode(Qt.ElideMiddle)
        self._content_label.setText(text)

        self._close_button = MToolButton(parent=self).icon_only().svg('close_line.svg').tiny()
        self._close_button.clicked.connect(self.close)
        self._close_button.setVisible(closable or False)

        self._main_lay = QHBoxLayout()
        self._main_lay.addWidget(_icon_label)
        self._main_lay.addWidget(self._content_label)
        self._main_lay.addStretch()
        self._main_lay.addWidget(self._close_button)
        self.setLayout(self._main_lay)

        _close_timer = QTimer(self)
        _close_timer.setSingleShot(True)
        _close_timer.timeout.connect(self.close)
        _close_timer.timeout.connect(self.sig_closed)
        _close_timer.setInterval((duration or self.default_config.get('duration')) * 1000)

        _ani_timer = QTimer(self)
        _ani_timer.timeout.connect(self._fade_out)
        _ani_timer.setInterval((duration or self.default_config.get('duration')) * 1000 - 300)

        _close_timer.start()
        _ani_timer.start()

        self._pos_ani = QPropertyAnimation(self)
        self._pos_ani.setTargetObject(self)
        self._pos_ani.setEasingCurve(QEasingCurve.OutCubic)
        self._pos_ani.setDuration(300)
        self._pos_ani.setPropertyName('pos')

        self._opacity_ani = QPropertyAnimation()
        self._opacity_ani.setTargetObject(self)
        self._opacity_ani.setDuration(300)
        self._opacity_ani.setEasingCurve(QEasingCurve.OutCubic)
        self._opacity_ani.setPropertyName('windowOpacity')
        self._opacity_ani.setStartValue(0.0)
        self._opacity_ani.setEndValue(1.0)

        self._set_proper_position(parent)
        self._fade_int()
Ejemplo n.º 8
0
class MCard(QWidget):
    def __init__(self,
                 title=None,
                 image=None,
                 size=None,
                 extra=None,
                 type=None,
                 parent=None):
        super(MCard, self).__init__(parent=parent)
        self.setAttribute(Qt.WA_StyledBackground)
        self.setProperty('border', False)
        size = size or dayu_theme.default_size
        map_label = {
            dayu_theme.large: (MLabel.H2Level, 20),
            dayu_theme.medium: (MLabel.H3Level, 15),
            dayu_theme.small: (MLabel.H4Level, 10),
        }
        self._title_label = MLabel(text=title)
        self._title_label.set_dayu_level(map_label.get(size)[0])

        padding = map_label.get(size)[-1]
        self._title_layout = QHBoxLayout()
        self._title_layout.setContentsMargins(padding, padding, padding,
                                              padding)
        if image:
            self._title_icon = MAvatar()
            self._title_icon.set_dayu_image(image)
            self._title_icon.set_dayu_size(size)
            self._title_layout.addWidget(self._title_icon)
        self._title_layout.addWidget(self._title_label)
        self._title_layout.addStretch()
        if extra:
            self._extra_button = MToolButton().icon_only().svg('more.svg')
            self._title_layout.addWidget(self._extra_button)

        self._content_layout = QVBoxLayout()

        self._main_lay = QVBoxLayout()
        self._main_lay.setSpacing(0)
        self._main_lay.setContentsMargins(1, 1, 1, 1)
        if title:
            self._main_lay.addLayout(self._title_layout)
            self._main_lay.addWidget(MDivider())
        self._main_lay.addLayout(self._content_layout)
        self.setLayout(self._main_lay)

    def get_more_button(self):
        return self._extra_button

    def set_widget(self, widget):
        self._content_layout.addWidget(widget)

    def border(self):
        self.setProperty('border', True)
        self.style().polish(self)
        return self
Ejemplo n.º 9
0
    def __init__(self, title, position='right', closable=True, parent=None):
        super(MDrawer, self).__init__(parent)
        self.setObjectName('message')
        self.setWindowFlags(Qt.Popup)
        # self.setWindowFlags(
        #     Qt.FramelessWindowHint | Qt.Popup | Qt.WA_TranslucentBackground)
        self.setAttribute(Qt.WA_StyledBackground)

        self._title_label = MLabel(parent=self).h4()
        # self._title_label.set_elide_mode(Qt.ElideRight)
        self._title_label.setText(title)

        self._close_button = MToolButton(
            parent=self).icon_only().svg('close_line.svg').small()
        self._close_button.clicked.connect(self.close)
        self._close_button.setVisible(closable or False)

        _title_lay = QHBoxLayout()
        _title_lay.addWidget(self._title_label)
        _title_lay.addStretch()
        _title_lay.addWidget(self._close_button)
        self._button_lay = QHBoxLayout()
        self._button_lay.addStretch()

        self._scroll_area = QScrollArea()
        self._main_lay = QVBoxLayout()
        self._main_lay.addLayout(_title_lay)
        self._main_lay.addWidget(MDivider())
        self._main_lay.addWidget(self._scroll_area)
        self._main_lay.addWidget(MDivider())
        self._main_lay.addLayout(self._button_lay)
        self.setLayout(self._main_lay)

        self._position = position

        self._close_timer = QTimer(self)
        self._close_timer.setSingleShot(True)
        self._close_timer.timeout.connect(self.close)
        self._close_timer.timeout.connect(self.sig_closed)
        self._close_timer.setInterval(300)
        self._is_first_close = True

        self._pos_ani = QPropertyAnimation(self)
        self._pos_ani.setTargetObject(self)
        self._pos_ani.setEasingCurve(QEasingCurve.OutCubic)
        self._pos_ani.setDuration(300)
        self._pos_ani.setPropertyName(b'pos')

        self._opacity_ani = QPropertyAnimation()
        self._opacity_ani.setTargetObject(self)
        self._opacity_ani.setDuration(300)
        self._opacity_ani.setEasingCurve(QEasingCurve.OutCubic)
        self._opacity_ani.setPropertyName(b'windowOpacity')
        self._opacity_ani.setStartValue(0.0)
        self._opacity_ani.setEndValue(1.0)
Ejemplo n.º 10
0
 def __init__(self, separator='/', parent=None):
     super(MBreadcrumb, self).__init__(parent)
     self._separator = separator
     self._main_layout = QHBoxLayout()
     self._main_layout.setContentsMargins(0, 0, 0, 0)
     self._main_layout.setSpacing(0)
     self._main_layout.addStretch()
     self.setLayout(self._main_layout)
     self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
     self._button_group = QButtonGroup()
     self._label_list = []
Ejemplo n.º 11
0
    def __init__(self, parent=None):
        super(CheckBoxExample, self).__init__(parent)
        self.setWindowTitle('Example for MCheckBox')
        grid_lay = QGridLayout()

        for index, (text, state) in enumerate([('Unchecked', Qt.Unchecked),
                                               ('Checked', Qt.Checked),
                                               ('Partially',
                                                Qt.PartiallyChecked)]):
            check_box_normal = MCheckBox(text)
            check_box_normal.setCheckState(state)

            check_box_disabled = MCheckBox(text)
            check_box_disabled.setCheckState(state)
            check_box_disabled.setEnabled(False)

            grid_lay.addWidget(check_box_normal, 0, index)
            grid_lay.addWidget(check_box_disabled, 1, index)

        icon_lay = QHBoxLayout()
        for text, icon in [('Maya', MIcon('app-maya.png')),
                           ('Nuke', MIcon('app-nuke.png')),
                           ('Houdini', MIcon('app-houdini.png'))]:
            check_box_icon = MCheckBox(text)
            check_box_icon.setIcon(icon)
            icon_lay.addWidget(check_box_icon)

        check_box_bind = MCheckBox('Data Bind')
        label = MLabel()
        button = MPushButton(text='Change State')
        button.clicked.connect(
            lambda: self.set_field('checked', not self.field('checked')))
        self.register_field('checked', True)
        self.register_field(
            'checked_text', lambda: 'Yes!'
            if self.field('checked') else 'No!!')
        self.bind('checked', check_box_bind, 'checked', signal='stateChanged')
        self.bind('checked_text', label, 'text')

        main_lay = QVBoxLayout()
        main_lay.addWidget(MDivider('Basic'))
        main_lay.addLayout(grid_lay)
        main_lay.addWidget(MDivider('Icon'))
        main_lay.addLayout(icon_lay)
        main_lay.addWidget(MDivider('Data Bind'))
        main_lay.addWidget(check_box_bind)
        main_lay.addWidget(label)
        main_lay.addWidget(button)
        main_lay.addStretch()
        self.setLayout(main_lay)
Ejemplo n.º 12
0
    def _init_ui(self):
        self.register_field('percent', 20)
        main_lay = QVBoxLayout()
        main_lay.addWidget(MDivider('different orientation'))
        for orn in [Qt.Horizontal, Qt.Vertical]:
            line_edit_hor = MSlider(orn)
            line_edit_hor.setRange(1, 100)
            self.bind('percent', line_edit_hor, 'value')
            lay = QVBoxLayout()
            lay.addWidget(line_edit_hor)
            main_lay.addLayout(lay)
        spin_box = MSpinBox()
        spin_box.setRange(1, 100)
        self.bind('percent', spin_box, 'value', signal='valueChanged')

        lay3 = QHBoxLayout()
        button_grp = MPushButtonGroup()
        button_grp.set_button_list([
            {
                'text': '+',
                'clicked': functools.partial(self.slot_change_value, 10)
            },
            {
                'text': '-',
                'clicked': functools.partial(self.slot_change_value, -10)
            },
        ])
        lay3.addWidget(spin_box)
        lay3.addWidget(button_grp)
        lay3.addStretch()
        main_lay.addWidget(MDivider('data bind'))
        main_lay.addLayout(lay3)
        main_lay.addStretch()
        self.setLayout(main_lay)
Ejemplo n.º 13
0
    def __init__(self, text='', parent=None):
        super(MTag, self).__init__(text=text, parent=parent)
        self._is_pressed = False
        self._close_button = MToolButton().tiny().svg('close_line.svg').icon_only()
        self._close_button.clicked.connect(self.sig_closed)
        self._close_button.clicked.connect(self.close)
        self._close_button.setVisible(False)

        self._main_lay = QHBoxLayout()
        self._main_lay.setContentsMargins(0, 0, 0, 0)
        self._main_lay.addStretch()
        self._main_lay.addWidget(self._close_button)

        self.setLayout(self._main_lay)

        self._clickable = False
        self._border = True
        self._border_style = QssTemplate('''
            MTag{
                font-size: 12px;
                padding: 3px;
                color: @text_color;
                border-radius: @border_radius;
                border: 1px solid @border_color;
                background-color: @background_color;
            }
            MTag:hover{
                color: @hover_color;
            }
            ''')
        self._no_border_style = QssTemplate('''
            MTag{
                font-size: 12px;
                padding: 4px;
                border-radius: @border_radius;
                color: @text_color;
                border: 0 solid @border_color;
                background-color: @background_color;
            }
            MTag:hover{
                background-color:@hover_color;
            }
        ''')
        self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)

        self._color = None
        self.set_dayu_color(dayu_theme.secondary_text_color)
Ejemplo n.º 14
0
 def __init__(self, parent=None):
     super(MMenuTabWidget, self).__init__(parent=parent)
     self.tool_button_group = MBlockButtonGroup()
     self._bar_layout = QHBoxLayout()
     self._bar_layout.setContentsMargins(10, 0, 10, 0)
     self._bar_layout.addWidget(self.tool_button_group)
     self._bar_layout.addStretch()
     bar_widget = QWidget()
     bar_widget.setObjectName('bar_widget')
     bar_widget.setLayout(self._bar_layout)
     bar_widget.setAttribute(Qt.WA_StyledBackground)
     main_lay = QVBoxLayout()
     main_lay.setContentsMargins(0, 0, 0, 0)
     main_lay.setSpacing(0)
     main_lay.addWidget(bar_widget)
     main_lay.addWidget(MDivider())
     main_lay.addSpacing(5)
     self.setLayout(main_lay)
     self.setFixedHeight(dayu_theme.large + 10)
Ejemplo n.º 15
0
    def __init__(self, text='', parent=None):
        super(MLineEdit, self).__init__(text, parent)
        self._main_layout = QHBoxLayout()
        self._main_layout.setContentsMargins(0, 0, 0, 0)
        self._main_layout.addStretch()

        self._prefix_widget = None
        self._suffix_widget = None

        self.setLayout(self._main_layout)
        self.setProperty('history', self.property('text'))
        self.setTextMargins(2, 0, 2, 0)

        self._delay_timer = QTimer()
        self._delay_timer.setInterval(500)
        self._delay_timer.setSingleShot(True)
        self._delay_timer.timeout.connect(self._slot_delay_text_changed)

        self._dayu_size = dayu_theme.default_size
Ejemplo n.º 16
0
 def __init__(self, layout=None, parent=None):
     super(MForm, self).__init__(parent)
     layout = layout or MForm.Horizontal
     if layout == MForm.Inline:
         self._main_layout = QHBoxLayout()
     elif layout == MForm.Vertical:
         self._main_layout = QVBoxLayout()
     else:
         self._main_layout = QFormLayout()
     self._model = None
     self._label_list = []
Ejemplo n.º 17
0
    def __init__(self, dashboard=False, parent=None):
        super(MProgressCircle, self).__init__(parent)
        self._main_lay = QHBoxLayout()
        self._default_label = MLabel().h3()
        self._default_label.setAlignment(Qt.AlignCenter)
        self._main_lay.addWidget(self._default_label)
        self.setLayout(self._main_lay)
        self._color = None
        self._width = None

        self._start_angle = 90 * 16
        self._max_delta_angle = 360 * 16
        self._height_factor = 1.0
        self._width_factor = 1.0
        if dashboard:
            self._start_angle = 225 * 16
            self._max_delta_angle = 270 * 16
            self._height_factor = (2 + pow(2, 0.5)) / 4 + 0.03

        self.set_dayu_width(120)
        self.set_dayu_color(dayu_theme.primary_color)
Ejemplo n.º 18
0
    def _init_ui(self):
        # 工具
        item_list = [
            {'text': u'文件', 'svg': 'folder_line.svg',
             'clicked': self.openFile},
            {'text': u'编辑', 'svg': 'edit_line.svg',
             'clicked': self.editFile},
            {'text': u'关于', 'svg': 'warning_line.svg',
             'clicked': self.showAbout},
        ]
        tool_bar = MMenuTabWidget()
        tool_bar.tool_bar_insert_widget(MLabel('Zeus').h4().secondary().strong())
        self.user_toolButton = MToolButton().large()
        pixmap = QPixmap(file_path + "\\res\\headPortrial\\user_default.png")
        self.user_toolButton.setIcon(pixmap)
        tool_bar.tool_bar_append_widget(
            MBadge.dot(show=False, widget=self.user_toolButton))
        self.label = MLabel(u"未登录")
        tool_bar.tool_bar_append_widget(
            MBadge.dot(show=False, widget=self.label))
      
        for index, data_dict in enumerate(item_list):
            tool_bar.add_menu(data_dict, index)

        main_lay = QHBoxLayout()
        main_lay.setContentsMargins(0, 0, 0, 0)
        main_lay.addWidget(tool_bar)

        self.setLayout(main_lay)
        self.layout().setSpacing(0)
        self.layout().setContentsMargins(0, 0, 0, 0)

        self.user_toolButton.clicked.connect(self.setUser)
Ejemplo n.º 19
0
    def _init_ui(self):
        check_box_1 = MSwitch()
        check_box_1.setChecked(True)
        check_box_2 = MSwitch()
        check_box_3 = MSwitch()
        check_box_3.setEnabled(False)
        lay = QHBoxLayout()
        lay.addWidget(check_box_1)
        lay.addWidget(check_box_2)
        lay.addWidget(check_box_3)

        size_lay = QFormLayout()
        size_lay.addRow('Huge', MSwitch().huge())
        size_lay.addRow('Large', MSwitch().large())
        size_lay.addRow('Medium', MSwitch().medium())
        size_lay.addRow('Small', MSwitch().small())
        size_lay.addRow('Tiny', MSwitch().tiny())

        main_lay = QVBoxLayout()
        main_lay.addWidget(MDivider('Basic'))
        main_lay.addLayout(lay)
        main_lay.addWidget(MDivider('different size'))
        main_lay.addLayout(size_lay)
        main_lay.addStretch()
        self.setLayout(main_lay)
Ejemplo n.º 20
0
    def __init__(self, parent=None):
        super(AddDelete, self).__init__(parent)
        self.tag_lay = MFlowLayout()
        tag1 = MTag('Unremoveable')
        tag2 = MTag('Tag2').closeable()
        tag3 = MTag('Tag3').closeable()
        add_tag = MNewTag('New Tag')
        add_tag.sig_add_tag.connect(self.slot_add_tag)
        self.tag_lay.addWidget(tag1)
        self.tag_lay.addWidget(tag2)
        self.tag_lay.addWidget(tag3)
        self.tag_lay.addWidget(add_tag)

        main_lay = QHBoxLayout()
        main_lay.addLayout(self.tag_lay)
        self.setLayout(main_lay)

        geo = QApplication.desktop().screenGeometry()
        self.setGeometry(geo.width() / 4,
                         geo.height() / 4,
                         geo.width() / 2,
                         geo.height() / 2)
Ejemplo n.º 21
0
    def __init__(self,
                 cover=None,
                 avatar=None,
                 title=None,
                 description=None,
                 extra=False,
                 parent=None):
        super(MMeta, self).__init__(parent)
        self.setAttribute(Qt.WA_StyledBackground)
        self._cover_label = QLabel()
        self._avatar = MAvatar()
        self._title_label = MLabel().h4()
        self._description_label = MLabel().secondary()
        self._description_label.setWordWrap(True)
        self._description_label.set_elide_mode(Qt.ElideRight)
        self._title_layout = QHBoxLayout()
        self._title_layout.addWidget(self._title_label)
        self._title_layout.addStretch()
        self._extra_button = MToolButton(
            parent=self).icon_only().svg('more.svg')
        self._title_layout.addWidget(self._extra_button)
        self._extra_button.setVisible(extra)

        content_lay = QFormLayout()
        content_lay.setContentsMargins(5, 5, 5, 5)
        content_lay.addRow(self._avatar, self._title_layout)
        content_lay.addRow(self._description_label)

        self._button_layout = QHBoxLayout()

        main_lay = QVBoxLayout()
        main_lay.setSpacing(0)
        main_lay.setContentsMargins(1, 1, 1, 1)
        main_lay.addWidget(self._cover_label)
        main_lay.addLayout(content_lay)
        main_lay.addLayout(self._button_layout)
        main_lay.addStretch()
        self.setLayout(main_lay)
        self._cover_label.setFixedSize(QSize(200, 200))
Ejemplo n.º 22
0
    def __init__(self, parent=None):
        super(Basic, self).__init__(parent)
        main_lay = QHBoxLayout()
        tag1 = MTag('Tag 1')
        tag2 = MTag('Clickable Tag').clickable()
        tag3 = MTag('Closeable Tag').closeable()

        tag2.sig_clicked.connect(
            functools.partial(self.slot_handle_signal, 'sig_clicked'))
        tag3.sig_closed.connect(
            functools.partial(self.slot_handle_signal, 'sig_closed'))
        main_lay.addWidget(tag1)
        main_lay.addWidget(tag2)
        main_lay.addWidget(tag3)
        main_lay.addStretch()
        self.setLayout(main_lay)
Ejemplo n.º 23
0
    def _init_ui(self):
        form_lay = QFormLayout()
        form_lay.setLabelAlignment(Qt.AlignRight)
        gender_grp = MRadioButtonGroup()
        gender_grp.set_button_list([{
            'text': 'Female',
            'icon': MIcon('female.svg')
        }, {
            'text': 'Male',
            'icon': MIcon('male.svg')
        }])

        country_combo_box = MComboBox().small()
        country_combo_box.addItems(['China', 'France', 'Japan', 'US'])
        date_edit = MDateEdit().small()
        date_edit.setCalendarPopup(True)

        form_lay.addRow('Name:', MLineEdit().small())
        form_lay.addRow('Gender:', gender_grp)
        form_lay.addRow('Age:', MSpinBox().small())
        form_lay.addRow('Password:'******'Country:', country_combo_box)
        form_lay.addRow('Birthday:', date_edit)
        switch = MSwitch()
        switch.setChecked(True)
        form_lay.addRow('Switch:', switch)
        slider = MSlider()
        slider.setValue(30)
        form_lay.addRow('Slider:', slider)

        button_lay = QHBoxLayout()
        button_lay.addStretch()
        button_lay.addWidget(MPushButton(text='Submit').primary())
        button_lay.addWidget(MPushButton(text='Cancel'))

        main_lay = QVBoxLayout()
        main_lay.addLayout(form_lay)
        main_lay.addWidget(MCheckBox('I accept the terms and conditions'))
        main_lay.addStretch()
        main_lay.addWidget(MDivider())
        main_lay.addLayout(button_lay)
        self.setLayout(main_lay)
Ejemplo n.º 24
0
    def _init_ui(self):

        self.setWindowModality(Qt.ApplicationModal)
        meta_card_lay = QHBoxLayout()
        meta_card_lay.setSpacing(20)
        for setting in [
            {
                'title':
                u'ZEUS',
                'cover':
                MPixmap(
                    r'C:\Users\huangPeiXin\Documents\houdini17.5\python2.7libs\Zeus_Lin\res\ZeusDesign\zeus.png'
                )
            },
            {
                'title':
                u'IDO',
                'cover':
                MPixmap(
                    r'C:\Users\huangPeiXin\Documents\houdini17.5\python2.7libs\Zeus_Lin\res\ZeusDesign\ido.png'
                )
            },
        ]:
            meta_card = MMeta()
            meta_card.setup_data(setting)
            meta_card_lay.addWidget(meta_card)

        left_lay = QVBoxLayout()

        left_lay.addWidget(MDivider('About Zeus'))
        left_lay.addLayout(meta_card_lay)
        left_lay.addWidget(MDivider(''))
        left_lay.setSpacing(20)
        label_1 = MLabel(u"Zues是由一灯工作室开发的一个软件")
        label_1.setAlignment(Qt.AlignHCenter)
        label_2 = MLabel(u"用于管理CG开发的相关资源")
        label_2.setAlignment(Qt.AlignHCenter)
        left_lay.addWidget(label_1)
        left_lay.addWidget(label_2)
        btn = MPushButton(u"确定")
        btn.clicked.connect(self.close)
        left_lay.addWidget(btn)
        left_lay.addStretch()

        self.setLayout(left_lay)

        dayu_theme.background_color = "#262626"

        dayu_theme.apply(self)
Ejemplo n.º 25
0
    def __init__(self, parent=None):
        super(AvatarExample, self).__init__(parent)
        self.setWindowTitle('Example for MAvatar')
        main_lay = QVBoxLayout()
        main_lay.addWidget(MDivider('different size'))

        size_list = [('Huge', MAvatar.huge), ('Large', MAvatar.large),
                     ('Medium', MAvatar.medium), ('Small', MAvatar.small),
                     ('Tiny', MAvatar.tiny)]

        self.pix_map_list = [
            None,
            MPixmap('avatar.png'),
            MPixmap('app-maya.png'),
            MPixmap('app-nuke.png'),
            MPixmap('app-houdini.png')
        ]
        form_lay = QFormLayout()
        form_lay.setLabelAlignment(Qt.AlignRight)

        for label, cls in size_list:
            h_lay = QHBoxLayout()
            for image in self.pix_map_list:
                avatar_tmp = cls(image)
                h_lay.addWidget(avatar_tmp)
            h_lay.addStretch()
            form_lay.addRow(MLabel(label), h_lay)
        main_lay.addLayout(form_lay)
        self.register_field('image', None)
        main_lay.addWidget(MDivider('different image'))
        avatar = MAvatar()
        self.bind('image', avatar, 'dayu_image')
        button = MPushButton(text='Change Avatar Image').primary()
        button.clicked.connect(self.slot_change_image)

        main_lay.addWidget(avatar)
        main_lay.addWidget(button)
        main_lay.addStretch()
        self.setLayout(main_lay)
Ejemplo n.º 26
0
    def _init_ui(self):
        main_lay = QVBoxLayout()
        self.setLayout(main_lay)
        main_lay.addWidget(MDivider('circle'))
        lay1 = QHBoxLayout()
        circle_1 = MProgressCircle(parent=self)
        circle_1.setFormat(u'%p Days')
        circle_1.setValue(80)
        circle_2 = MProgressCircle(parent=self)
        circle_2.set_dayu_color(dayu_theme.success_color)
        circle_2.setValue(100)
        circle_3 = MProgressCircle(parent=self)
        circle_3.set_dayu_color(dayu_theme.error_color)
        circle_3.setValue(40)

        dashboard_1 = MProgressCircle.dashboard(parent=self)
        dashboard_1.setFormat(u'%p Days')
        dashboard_1.setValue(80)
        dashboard_2 = MProgressCircle.dashboard(parent=self)
        dashboard_2.set_dayu_color(dayu_theme.success_color)
        dashboard_2.setValue(100)
        dashboard_3 = MProgressCircle.dashboard(parent=self)
        dashboard_3.set_dayu_color(dayu_theme.error_color)
        dashboard_3.setValue(40)

        lay1.addWidget(circle_1)
        lay1.addWidget(circle_2)
        lay1.addWidget(circle_3)

        dashboard_lay = QHBoxLayout()
        dashboard_lay.addWidget(dashboard_1)
        dashboard_lay.addWidget(dashboard_2)
        dashboard_lay.addWidget(dashboard_3)
        main_lay.addLayout(lay1)
        main_lay.addWidget(MDivider('dashboard'))
        main_lay.addLayout(dashboard_lay)
        main_lay.addWidget(MDivider('different radius'))

        circle_4 = MProgressCircle(parent=self)
        circle_4.set_dayu_width(100)
        circle_4.setValue(40)
        circle_5 = MProgressCircle(parent=self)
        circle_5.setValue(40)
        circle_6 = MProgressCircle(parent=self)
        circle_6.set_dayu_width(160)
        circle_6.setValue(40)
        lay2 = QHBoxLayout()
        lay2.addWidget(circle_4)
        lay2.addWidget(circle_5)
        lay2.addWidget(circle_6)

        main_lay.addLayout(lay2)
        main_lay.addWidget(MDivider('data bind'))

        self.register_field('percent', 0)
        self.register_field('color', self.get_color)
        self.register_field('format', self.get_format)
        circle = MProgressCircle(parent=self)

        self.bind('percent', circle, 'value')
        self.bind('color', circle, 'dayu_color')
        self.bind('format', circle, 'format')
        lay3 = QHBoxLayout()
        button_grp = MPushButtonGroup()
        button_grp.set_dayu_type(MPushButton.DefaultType)
        button_grp.set_button_list([
            {'text': '+', 'clicked': functools.partial(self.slot_change_percent, 10)},
            {'text': '-', 'clicked': functools.partial(self.slot_change_percent, -10)},
        ])
        lay3.addWidget(circle)
        lay3.addWidget(button_grp)
        lay3.addStretch()
        main_lay.addLayout(lay3)

        custom_widget = QWidget()
        custom_layout = QVBoxLayout()
        custom_layout.setContentsMargins(20, 20, 20, 20)
        custom_layout.addStretch()
        custom_widget.setLayout(custom_layout)
        lab1 = MLabel(text='42,001,776').h3()
        lab2 = MLabel(text=u'消费人群规模').secondary()
        lab3 = MLabel(text=u'总占人数 75%').secondary()
        lab1.setAlignment(Qt.AlignCenter)
        lab2.setAlignment(Qt.AlignCenter)
        lab3.setAlignment(Qt.AlignCenter)
        custom_layout.addWidget(lab1)
        custom_layout.addWidget(lab2)
        custom_layout.addWidget(MDivider())
        custom_layout.addWidget(lab3)
        custom_layout.addStretch()
        custom_circle = MProgressCircle()
        custom_circle.set_dayu_width(180)
        custom_circle.setValue(75)
        custom_circle.set_widget(custom_widget)

        main_lay.addWidget(MDivider('custom circle'))
        main_lay.addWidget(custom_circle)
        main_lay.addStretch()
Ejemplo n.º 27
0
 def __init__(self, parent=None):
     super(Login, self).__init__(parent)
     self.setWindowTitle('Login')
     self.resize(250, 150)
     main_layout = QVBoxLayout()
     name_layout = QHBoxLayout()
     password_layout = QHBoxLayout()
     name_layout.addWidget(MLabel('Name:'), 1, 0)
     name_layout.addWidget(MLineEdit())
     password_layout.addWidget(MLabel('Password:'******'Query').primary()
     main_layout.addWidget(query_button)
     self.setLayout(main_layout)
Ejemplo n.º 28
0
    def _init_ui(self):
        size_lay = QVBoxLayout()
        sub_lay1 = QHBoxLayout()
        sub_lay1.addWidget(MToolButton().svg('left_line.svg').icon_only())
        sub_lay1.addWidget(MToolButton().svg('right_line.svg').icon_only())
        sub_lay1.addWidget(MToolButton().svg('up_line.svg').icon_only())
        sub_lay1.addWidget(MToolButton().svg('down_line.svg').icon_only())
        sub_lay1.addStretch()
        size_lay.addLayout(sub_lay1)

        button2 = MToolButton().svg('detail_line.svg').icon_only()
        button2.setEnabled(False)
        button7 = MToolButton().svg('trash_line.svg').icon_only()
        button7.setCheckable(True)
        state_lay = QHBoxLayout()
        state_lay.addWidget(button2)
        state_lay.addWidget(button7)
        state_lay.addStretch()

        button_trash = MToolButton().svg('trash_line.svg').text_beside_icon()
        button_trash.setText('Delete')
        button_login = MToolButton().svg('user_line.svg').text_beside_icon()
        button_login.setText('Login')

        button_lay = QHBoxLayout()
        button_lay.addWidget(button_trash)
        button_lay.addWidget(button_login)

        sub_lay2 = QHBoxLayout()
        sub_lay2.addWidget(button2)
        sub_lay2.addWidget(button7)

        main_lay = QVBoxLayout()
        main_lay.addWidget(MDivider('different button_size'))
        main_lay.addLayout(size_lay)
        main_lay.addWidget(MDivider('disabled & checkable'))
        main_lay.addLayout(state_lay)
        main_lay.addWidget(MDivider('type=normal'))
        main_lay.addLayout(button_lay)
        main_lay.addStretch()
        self.setLayout(main_lay)
Ejemplo n.º 29
0
class MProgressCircle(QProgressBar):
    """
    MProgressCircle: Display the current progress of an operation flow.
    When you need to display the completion percentage of an operation.

    Property:
        dayu_width: int
        dayu_color: str
    """

    def __init__(self, dashboard=False, parent=None):
        super(MProgressCircle, self).__init__(parent)
        self._main_lay = QHBoxLayout()
        self._default_label = MLabel().h3()
        self._default_label.setAlignment(Qt.AlignCenter)
        self._main_lay.addWidget(self._default_label)
        self.setLayout(self._main_lay)
        self._color = None
        self._width = None

        self._start_angle = 90 * 16
        self._max_delta_angle = 360 * 16
        self._height_factor = 1.0
        self._width_factor = 1.0
        if dashboard:
            self._start_angle = 225 * 16
            self._max_delta_angle = 270 * 16
            self._height_factor = (2 + pow(2, 0.5)) / 4 + 0.03

        self.set_dayu_width(120)
        self.set_dayu_color(dayu_theme.primary_color)

    def set_widget(self, widget):
        """
        Set a custom widget to show on the circle's inner center
         and replace the default percent label
        :param widget: QWidget
        :return: None
        """
        self.setTextVisible(False)
        self._main_lay.addWidget(widget)

    def get_dayu_width(self):
        """
        Get current circle fixed width
        :return: int
        """
        return self._width

    def set_dayu_width(self, value):
        """
        Set current circle fixed width
        :param value: int
        :return: None
        """
        self._width = value
        self.setFixedSize(QSize(self._width * self._width_factor,
                                self._width * self._height_factor))

    def get_dayu_color(self):
        """
        Get current circle foreground color
        :return: str
        """
        return self._color

    def set_dayu_color(self, value):
        """
        Set current circle's foreground color
        :param value: str
        :return:
        """
        self._color = value
        self.update()

    dayu_color = Property(str, get_dayu_color, set_dayu_color)
    dayu_width = Property(int, get_dayu_width, set_dayu_width)

    def paintEvent(self, event):
        """Override QProgressBar's paintEvent."""
        if self.text() != self._default_label.text():
            self._default_label.setText(self.text())
        if self.isTextVisible() != self._default_label.isVisible():
            self._default_label.setVisible(self.isTextVisible())

        percent = utils.get_percent(self.value(), self.minimum(), self.maximum())
        total_width = self.get_dayu_width()
        pen_width = int(3 * total_width / 50.0)
        radius = total_width - pen_width - 1

        painter = QPainter(self)
        painter.setRenderHints(QPainter.Antialiasing)

        # draw background circle
        pen_background = QPen()
        pen_background.setWidth(pen_width)
        pen_background.setColor(dayu_theme.background_selected_color)
        pen_background.setCapStyle(Qt.RoundCap)
        painter.setPen(pen_background)
        painter.drawArc(pen_width / 2.0 + 1,
                        pen_width / 2.0 + 1,
                        radius,
                        radius,
                        self._start_angle,
                        -self._max_delta_angle)

        # draw foreground circle
        pen_foreground = QPen()
        pen_foreground.setWidth(pen_width)
        pen_foreground.setColor(self._color)
        pen_foreground.setCapStyle(Qt.RoundCap)
        painter.setPen(pen_foreground)
        painter.drawArc(pen_width / 2.0 + 1,
                        pen_width / 2.0 + 1,
                        radius,
                        radius,
                        self._start_angle,
                        -percent * 0.01 * self._max_delta_angle)
        painter.end()

    @classmethod
    def dashboard(cls, parent=None):
        """Create a dashboard style MCircle"""
        return MProgressCircle(dashboard=True, parent=parent)
Ejemplo n.º 30
0
    def __init__(self, text, duration=None, dayu_type=None, parent=None):
        super(MToast, self).__init__(parent)
        self.setWindowFlags(Qt.FramelessWindowHint | Qt.Dialog
                            | Qt.WA_TranslucentBackground
                            | Qt.WA_DeleteOnClose)
        self.setAttribute(Qt.WA_StyledBackground)

        _icon_lay = QHBoxLayout()
        _icon_lay.addStretch()

        if dayu_type == MToast.LoadingType:
            _icon_lay.addWidget(
                MLoading(size=dayu_theme.huge,
                         color=dayu_theme.text_color_inverse))
        else:
            _icon_label = MAvatar()
            _icon_label.set_dayu_size(60)
            _icon_label.set_dayu_image(
                MPixmap('{}_line.svg'.format(dayu_type or MToast.InfoType),
                        dayu_theme.text_color_inverse))
            _icon_lay.addWidget(_icon_label)
        _icon_lay.addStretch()

        _content_label = MLabel()
        _content_label.setText(text)
        _content_label.setAlignment(Qt.AlignCenter)

        _main_lay = QVBoxLayout()
        _main_lay.setContentsMargins(0, 0, 0, 0)
        _main_lay.addStretch()
        _main_lay.addLayout(_icon_lay)
        _main_lay.addSpacing(10)
        _main_lay.addWidget(_content_label)
        _main_lay.addStretch()
        self.setLayout(_main_lay)
        self.setFixedSize(QSize(120, 120))

        _close_timer = QTimer(self)
        _close_timer.setSingleShot(True)
        _close_timer.timeout.connect(self.close)
        _close_timer.timeout.connect(self.sig_closed)
        _close_timer.setInterval(
            (duration or self.default_config.get('duration')) * 1000)

        _ani_timer = QTimer(self)
        _ani_timer.timeout.connect(self._fade_out)
        _ani_timer.setInterval(
            (duration or self.default_config.get('duration')) * 1000 - 300)

        _close_timer.start()
        _ani_timer.start()

        self._opacity_ani = QPropertyAnimation()
        self._opacity_ani.setTargetObject(self)
        self._opacity_ani.setDuration(300)
        self._opacity_ani.setEasingCurve(QEasingCurve.OutCubic)
        self._opacity_ani.setPropertyName(b'windowOpacity')
        self._opacity_ani.setStartValue(0.0)
        self._opacity_ani.setEndValue(0.9)

        self._get_center_position(parent)
        self._fade_int()