def test_progress_circle_widget(qtbot): label = QLabel('text') circle = MProgressCircle() circle.set_widget(label) qtbot.addWidget(circle) circle.show() circle.repaint() assert not circle.isTextVisible() assert not circle._default_label.isVisible() assert label.isVisible()
def test_badge_count(qtbot, num, text, visible): """Test MBadge init.""" label = QLabel('test') badge_1 = MBadge.count(count=num, widget=label) badge_2 = MBadge.count(num) main_widget = QWidget() main_lay = QVBoxLayout() main_widget.setLayout(main_lay) main_lay.addWidget(badge_1) main_lay.addWidget(badge_2) qtbot.addWidget(main_widget) main_widget.show() assert badge_1._badge_button.text() == text assert badge_1._badge_button.isVisible() == visible assert badge_2._badge_button.text() == text assert badge_2._badge_button.isVisible() == visible assert badge_1.get_dayu_dot() is None assert badge_2.get_dayu_dot() is None assert badge_1.get_dayu_text() is None assert badge_2.get_dayu_text() is None assert badge_1.get_dayu_count() == num assert badge_2.get_dayu_count() == num assert badge_1.get_dayu_overflow() == 99 assert badge_2.get_dayu_overflow() == 99
def test_stacked_widget_init(qtbot): """Test MStackedWidget init""" stacked_widget = MStackedWidget() stacked_widget.addWidget(QLabel('test')) qtbot.addWidget(stacked_widget) stacked_widget.show() assert stacked_widget.currentIndex() == 0
def test_stacked_animation_mixin_normal(qtbot): @mixin.stacked_animation_mixin class _TestClass(QStackedWidget): def __init__(self, parent=None): super(_TestClass, self).__init__(parent) main_widget = _TestClass() qtbot.addWidget(main_widget) assert hasattr(main_widget, '_to_show_pos_ani') assert isinstance(main_widget._to_show_pos_ani, QPropertyAnimation) assert hasattr(main_widget, '_to_hide_pos_ani') assert isinstance(main_widget._to_hide_pos_ani, QPropertyAnimation) assert hasattr(main_widget, '_opacity_eff') assert isinstance(main_widget._opacity_eff, QGraphicsOpacityEffect) assert hasattr(main_widget, '_opacity_ani') assert isinstance(main_widget._opacity_ani, QPropertyAnimation) assert hasattr(main_widget, '_play_anim') assert hasattr(main_widget, '_disable_opacity') assert main_widget._previous_index == 0 label_1 = QLabel('test') index_1 = main_widget.addWidget(label_1) def check_index(): assert main_widget._previous_index == index_1 assert not label_1.graphicsEffect().isEnabled() qtbot.waitUntil(check_index) label_2 = QLabel('test2') index_2 = main_widget.addWidget(label_2) main_widget.setCurrentIndex(index_1) def check_index(): assert main_widget._previous_index == index_1 assert not label_1.graphicsEffect().isEnabled() qtbot.waitUntil(check_index) main_widget.setCurrentIndex(index_2) def check_index(): assert main_widget._previous_index == index_2 assert not label_2.graphicsEffect().isEnabled() qtbot.waitUntil(check_index)
def test_loading_wrapper(qtbot): """Test for MLoadingWrapper class methods""" label = QLabel('test') label.setFixedSize(QSize(100, 100)) widget = MLoadingWrapper(label, loading=False) widget.show() qtbot.addWidget(widget) assert not widget._loading_widget.isVisible() assert not widget._mask_widget.isVisible() assert not widget.get_dayu_loading() widget.set_dayu_loading(True) def check_loading_visible(): assert widget.get_dayu_loading() assert widget._loading_widget.isVisible() assert widget._mask_widget.isVisible() qtbot.waitUntil(check_loading_visible)
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))
def test_badge_dot(qtbot, show, visible): """Test MBadge init.""" label = QLabel('test') badge_1 = MBadge.dot(show=show, widget=label) badge_2 = MBadge.dot(show) main_widget = QWidget() main_lay = QVBoxLayout() main_widget.setLayout(main_lay) main_lay.addWidget(badge_1) main_lay.addWidget(badge_2) qtbot.addWidget(main_widget) main_widget.show() assert badge_1._badge_button.isVisible() == visible assert badge_2._badge_button.isVisible() == visible assert badge_1.get_dayu_dot() == show assert badge_2.get_dayu_dot() == show assert badge_1.get_dayu_text() is None assert badge_2.get_dayu_text() is None assert badge_1.get_dayu_count() is None assert badge_2.get_dayu_count() is None
class MMeta(QWidget): 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)) # self.setFixedWidth(200) def get_more_button(self): return self._extra_button def setup_data(self, data_dict): if data_dict.get('title'): self._title_label.setText(data_dict.get('title')) self._title_label.setVisible(True) else: self._title_label.setVisible(False) if data_dict.get('description'): self._description_label.setText(data_dict.get('description')) self._description_label.setVisible(True) else: self._description_label.setVisible(False) if data_dict.get('avatar'): self._avatar.set_dayu_image(data_dict.get('avatar')) self._avatar.setVisible(True) else: self._avatar.setVisible(False) if data_dict.get('cover'): fixed_height = self._cover_label.width() self._cover_label.setPixmap( data_dict.get('cover').scaledToWidth(fixed_height, Qt.SmoothTransformation)) self._cover_label.setVisible(True) else: self._cover_label.setVisible(False)