Exemplo n.º 1
0
    def minimumSize(self):
        size = QSize()

        for item in self.item_list:
            size = size.expandedTo(item.minimumSize())

        size += QSize(2 * self.contentsMargins().top(), 2 * self.contentsMargins().top())
        return size
Exemplo n.º 2
0
 def wheelEvent(self, event):
     """Override wheelEvent while user press ctrl, zoom the list view icon size."""
     if event.modifiers() == Qt.ControlModifier:
         num_degrees = event.delta() / 8.0
         num_steps = num_degrees / 15.0
         factor = pow(1.125, num_steps)
         new_size = self.iconSize() * factor
         if new_size.width() > 200:
             new_size = QSize(200, 200)
         elif new_size.width() < 24:
             new_size = QSize(24, 24)
         self.setIconSize(new_size)
     else:
         super(MBigView, self).wheelEvent(event)
Exemplo n.º 3
0
 def minimumSizeHint(self):
     """
     Override the QRadioButton minimum size hint. We don't need the text space.
     :return:
     """
     height = self._dayu_size * 1.2
     return QSize(height, height / 2)
Exemplo n.º 4
0
 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))
Exemplo n.º 5
0
 def set_dayu_size(self, value):
     """
     Set the avatar size.
     :param value: integer
     :return: None
     """
     self._dayu_size = value
     self.style().polish(self)
     if self.toolButtonStyle() == Qt.ToolButtonIconOnly:
         self.setFixedSize(QSize(self._dayu_size, self._dayu_size))
Exemplo n.º 6
0
 def __init__(self, parent=None):
     super(MBigView, self).__init__(parent)
     self._no_date_image = None
     self._no_data_text = self.tr('No Data')
     self.header_list = []
     self.header_view = None
     self.setViewMode(QListView.IconMode)
     self.setResizeMode(QListView.Adjust)
     self.setMovement(QListView.Static)
     self.setSpacing(10)
     self.setIconSize(QSize(128, 128))
Exemplo n.º 7
0
    def __init__(self, multiple=False, parent=None):
        super(MDragFolderButton, self).__init__(parent=parent)
        self.setAcceptDrops(True)
        self.setMouseTracking(True)
        self.text_under_icon()
        self.set_dayu_svg('folder_line.svg')
        self.set_dayu_size(60)
        self.setIconSize(QSize(60, 60))
        self.setText(self.tr('Click or drag folder here'))
        self.clicked.connect(self.slot_browser_folder)
        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.setToolTip(self.tr('Click to browser folder or drag folder here'))

        self._path = None
        self._multiple = multiple
Exemplo n.º 8
0
 def __init__(self, size=None, color=None, parent=None):
     super(MLoading, self).__init__(parent)
     size = size or dayu_theme.default_size
     self.setFixedSize(QSize(size, size))
     self.pix = MPixmap('loading.svg', color or dayu_theme.primary_color) \
         .scaledToWidth(size, Qt.SmoothTransformation)
     self._rotation = 0
     self._loading_ani = QPropertyAnimation()
     self._loading_ani.setTargetObject(self)
     # self.loading_ani.setEasingCurve(QEasingCurve.InOutQuad)
     self._loading_ani.setDuration(1000)
     self._loading_ani.setPropertyName(b'rotation')
     self._loading_ani.setStartValue(0)
     self._loading_ani.setEndValue(360)
     self._loading_ani.setLoopCount(-1)
     self._loading_ani.start()
Exemplo n.º 9
0
    def __init__(self, text='', multiple=False, parent=None):
        super(MDragFileButton, self).__init__(parent=parent)
        self.setAcceptDrops(True)
        self.setMouseTracking(True)
        self.text_under_icon()
        self.setText(text)

        self.set_dayu_size(60)
        self.set_dayu_svg('cloud_line.svg')
        self.setIconSize(QSize(60, 60))

        self.clicked.connect(self.slot_browser_file)
        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.setToolTip(self.tr('Click to browser file'))

        self._path = None
        self._multiple = multiple
        self._filters = []
Exemplo n.º 10
0
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)
Exemplo n.º 11
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))
Exemplo n.º 12
0
 def sizeHint(self, option, index):
     orig = super(MOptionDelegate, self).sizeHint(option, index)
     return QSize(orig.width() + self.arrow_space, orig.height())
Exemplo n.º 13
0
 def _set_dayu_size(self):
     self.setFixedSize(QSize(self._dayu_size, self._dayu_size))
     self._set_dayu_image()
Exemplo n.º 14
0
 def icon_only(self):
     """Set tool button style to icon only"""
     self.setToolButtonStyle(Qt.ToolButtonIconOnly)
     self.setFixedSize(QSize(self._dayu_size, self._dayu_size))
     return self
Exemplo n.º 15
0
 def minimumSizeHint(self):
     return QSize(1, self.fontMetrics().height())
Exemplo n.º 16
0
 def minimumSizeHint(self, *args, **kwargs):
     return QSize(200, 50)
Exemplo n.º 17
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()