def __init__(self, parent=None): super(MTextEdit, self).__init__(parent) self.setWindowFlags(Qt.SubWindow) self._size_grip = MSizeGrip(self) layout = QGridLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self._size_grip, 0, 0, Qt.AlignBottom | Qt.AlignRight) self.setLayout(layout) self._size_grip.setVisible(False)
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)
class MLoadingWrapper(QWidget): """ A wrapper widget to show the loading widget or hide. Property: dayu_loading: bool. current loading state. """ def __init__(self, widget, loading=True, parent=None): super(MLoadingWrapper, self).__init__(parent) self._widget = widget self._mask_widget = QFrame() self._mask_widget.setObjectName('mask') self._mask_widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self._loading_widget = MLoading() self._loading_widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self._main_lay = QGridLayout() self._main_lay.setContentsMargins(0, 0, 0, 0) self._main_lay.addWidget(widget, 0, 0) self._main_lay.addWidget(self._mask_widget, 0, 0) self._main_lay.addWidget(self._loading_widget, 0, 0, Qt.AlignCenter) self.setLayout(self._main_lay) self._loading = None self.set_dayu_loading(loading) def _set_loading(self): self._loading_widget.setVisible(self._loading) self._mask_widget.setVisible(self._loading) def set_dayu_loading(self, loading): """ Set current state to loading or not :param loading: bool :return: None """ self._loading = loading self._set_loading() def get_dayu_loading(self): """ Get current loading widget is loading or not. :return: bool """ return self._loading dayu_loading = Property(bool, get_dayu_loading, set_dayu_loading)
class MBadge(QWidget): """ Badge normally appears in proximity to notifications or user avatars with eye-catching appeal, typically displaying unread messages count. Show something at the wrapped widget top right. There is 3 type styles: dot: show a dot count: show a number at text: show a string Property: dayu_dot: bool dayu_text: basestring dayu_count: int dayu_overflow: int """ def __init__(self, widget=None, parent=None): super(MBadge, self).__init__(parent) self._widget = widget self._overflow_count = 99 self._dot = None self._text = None self._count = None self._badge_button = QPushButton() self._badge_button.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) self._main_lay = QGridLayout() self._main_lay.setContentsMargins(0, 0, 0, 0) if widget is not None: self._main_lay.addWidget(widget, 0, 0) self._main_lay.addWidget(self._badge_button, 0, 0, Qt.AlignTop | Qt.AlignRight) self.setLayout(self._main_lay) def get_dayu_overflow(self): """ Get current overflow number :return: int """ return self._overflow_count def set_dayu_overflow(self, num): """ Set the overflow number :param num: new max number :return: None """ self._overflow_count = num self._update_number() def get_dayu_dot(self): """ Get current style is dot or not and dot is show or not :return: bool """ return self._dot def set_dayu_dot(self, show): """ Set dot style and weather show the dot or not :param show: bool :return: None """ self._dot = show self._badge_button.setText('') self._badge_button.setVisible(show) self.style().polish(self) def get_dayu_count(self): """ Get actual count number :return: int """ return self._count def set_dayu_count(self, num): """ Set current style to show a number :param num: int :return: None """ self._count = num self._update_number() def _update_number(self): self._badge_button.setText( utils.overflow_format(self._count, self._overflow_count)) self._badge_button.setVisible(self._count > 0) self._dot = None self.style().polish(self) def get_dayu_text(self): """ Get current showed text :return: basestring """ return self._text def set_dayu_text(self, text): """ Set current style to show a text. :param text: basestring :return: None """ self._text = text self._badge_button.setText(self._text) self._badge_button.setVisible(bool(self._text)) self._dot = None self.style().polish(self) dayu_overflow = Property(int, get_dayu_overflow, set_dayu_overflow) dayu_dot = Property(bool, get_dayu_dot, set_dayu_dot) dayu_count = Property(int, get_dayu_count, set_dayu_count) dayu_text = Property(basestring, get_dayu_text, set_dayu_text) @classmethod def dot(cls, show=False, widget=None): """ Create a Badge with dot style. :param show: bool :param widget: the wrapped widget :return: instance badge """ inst = cls(widget=widget) inst.set_dayu_dot(show) return inst @classmethod def count(cls, count=0, widget=None): """ Create a Badge with number style. :param count: int :param widget: the wrapped widget :return: instance badge """ inst = cls(widget=widget) inst.set_dayu_count(count) return inst @classmethod def text(cls, text='', widget=None): """ Create a Badge with text style. :param text: basestring :param widget: the wrapped widget :return: instance badge """ inst = cls(widget=widget) inst.set_dayu_text(text) return inst
def _init_ui(self): title_lay = QGridLayout() title_lay.addWidget(MLabel(u'一级标题').h1(), 0, 0) title_lay.addWidget(MLabel(u'二级标题').h2(), 1, 0) title_lay.addWidget(MLabel(u'三级标题').h3(), 2, 0) title_lay.addWidget(MLabel(u'四级标题').h4(), 3, 0) title_lay.addWidget(MLabel('h1 Level').h1(), 0, 1) title_lay.addWidget(MLabel('h2 Level').h2(), 1, 1) title_lay.addWidget(MLabel('h3 Level').h3(), 2, 1) title_lay.addWidget(MLabel('h4 Level').h4(), 3, 1) text_type_lay = QHBoxLayout() text_type_lay.addWidget(MLabel('MLabel: Normal')) text_type_lay.addWidget(MLabel('MLabel: Secondary').secondary()) text_type_lay.addWidget(MLabel('MLabel: Warning').warning()) text_type_lay.addWidget(MLabel('MLabel: Danger').danger()) disable_text = MLabel('MLabel: Disabled') disable_text.setEnabled(False) text_type_lay.addWidget(disable_text) text_attr_lay = QHBoxLayout() text_attr_lay.addWidget(MLabel('MLabel: Mark').mark()) text_attr_lay.addWidget(MLabel('MLabel: Code').code()) text_attr_lay.addWidget(MLabel('MLabel: Underline').underline()) text_attr_lay.addWidget(MLabel('MLabel: Delete').delete()) text_attr_lay.addWidget(MLabel('MLabel: Strong').strong()) text_mix_lay = QHBoxLayout() text_mix_lay.addWidget(MLabel('MLabel: Strong & Underline').strong().underline()) text_mix_lay.addWidget(MLabel('MLabel: Danger & Delete').danger().delete()) text_mix_lay.addWidget(MLabel('MLabel: Warning & Strong').warning().strong()) text_mix_lay.addWidget(MLabel('MLabel: H4 & Mark').h4().mark()) data_bind_lay = QHBoxLayout() data_bind_label = MLabel() button = MPushButton(text='Random An Animal').primary() button.clicked.connect(self.slot_change_text) data_bind_lay.addWidget(data_bind_label) data_bind_lay.addWidget(button) data_bind_lay.addStretch() self.register_field('show_text', 'Guess') self.bind('show_text', data_bind_label, 'text') lay_elide = QVBoxLayout() label_none = MLabel('This is a elide NONE mode label. ' 'Ellipsis should NOT appear in the text.') label_left = MLabel( 'This is a elide LEFT mode label. ' 'The ellipsis should appear at the beginning of the text. ' 'xiao mao xiao gou xiao ci wei') label_left.set_elide_mode(Qt.ElideLeft) label_middle = MLabel( 'This is a elide MIDDLE mode label. ' 'The ellipsis should appear in the middle of the text. ' 'xiao mao xiao gou xiao ci wei') label_middle.set_elide_mode(Qt.ElideMiddle) label_right = MLabel() label_right.setText('This is a elide RIGHT mode label. ' 'The ellipsis should appear at the end of the text. ' 'Some text to fill the line bala bala bala.') label_right.set_elide_mode(Qt.ElideRight) lay_elide.addWidget(label_none) lay_elide.addWidget(label_left) lay_elide.addWidget(label_middle) lay_elide.addWidget(label_right) main_lay = QVBoxLayout() main_lay.addWidget(MDivider('different level')) main_lay.addLayout(title_lay) main_lay.addWidget(MDivider('different type')) main_lay.addLayout(text_type_lay) main_lay.addWidget(MDivider('different property')) main_lay.addLayout(text_attr_lay) main_lay.addWidget(MDivider('mix')) main_lay.addLayout(text_mix_lay) # main_lay.addWidget(MDivider('data bind')) # main_lay.addLayout(data_bind_lay) main_lay.addWidget(MDivider('elide mode')) main_lay.addLayout(lay_elide) main_lay.addStretch() self.setLayout(main_lay)
def _init_ui(self): browser_1 = MClickBrowserFilePushButton( text='Browser File PushButton').primary() browser_2 = MClickBrowserFolderPushButton( text='Browser Folder PushButton') browser_2.setIcon(MIcon('upload_line.svg')) browser_3 = MClickBrowserFilePushButton(text='Browser Multi Files', multiple=True).primary() lay_1 = QHBoxLayout() lay_1.addWidget(browser_1) lay_1.addWidget(browser_2) lay_1.addWidget(browser_3) browser_4 = MClickBrowserFileToolButton().huge() label_4 = MLabel() label_4.set_elide_mode(Qt.ElideMiddle) browser_4.sig_file_changed.connect(label_4.setText) browser_5 = MClickBrowserFolderToolButton().huge() label_5 = MLabel() label_5.set_elide_mode(Qt.ElideMiddle) browser_5.sig_folder_changed.connect(label_5.setText) lay_2 = QHBoxLayout() lay_2.addWidget(label_4) lay_2.addWidget(browser_4) lay_2.addWidget(label_5) lay_2.addWidget(browser_5) browser_6 = MDragFileButton(text='Click or drag file here') browser_6.set_dayu_svg('attachment_line.svg') label_6 = MLabel() label_6.set_elide_mode(Qt.ElideMiddle) browser_6.sig_file_changed.connect(label_6.setText) browser_7 = MDragFolderButton() label_7 = MLabel() label_7.set_elide_mode(Qt.ElideRight) browser_7.sig_folder_changed.connect(label_7.setText) lay_3 = QGridLayout() lay_3.addWidget(browser_6, 2, 0) lay_3.addWidget(browser_7, 2, 1) lay_3.addWidget(label_6, 3, 0) lay_3.addWidget(label_7, 3, 1) browser_8 = MDragFileButton(text='Click or drag media file here', multiple=False) browser_8.set_dayu_svg('media_line.svg') browser_8.set_dayu_filters(['.mov', '.mp4']) browser_8_label = MLabel() browser_8_label.set_elide_mode(Qt.ElideRight) self.register_field('current_file', '') self.bind('current_file', browser_8, 'dayu_path', signal='sig_file_changed') self.bind('current_file', browser_8_label, 'text') main_lay = QVBoxLayout() main_lay.addWidget(MDivider('MClickBrowser*PushButton')) main_lay.addLayout(lay_1) main_lay.addWidget(MDivider('MClickBrowser*ToolButton')) main_lay.addLayout(lay_2) main_lay.addWidget(MDivider('MDragBrowser*ToolButton')) main_lay.addLayout(lay_3) main_lay.addWidget(MDivider('data bind')) main_lay.addWidget(browser_8) main_lay.addWidget(browser_8_label) main_lay.addStretch() self.setLayout(main_lay)