Skip to content

Commit

Permalink
style: change max line length from 88 to 120
Browse files Browse the repository at this point in the history
  • Loading branch information
muyr authored and loonghao committed Jun 21, 2024
1 parent d3e721f commit 4bce2f8
Show file tree
Hide file tree
Showing 38 changed files with 162 additions and 526 deletions.
10 changes: 2 additions & 8 deletions dayu_widgets/alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ def set_dayu_text(self, value):
if isinstance(value, six.string_types):
self._dayu_text = value
else:
raise TypeError(
"Input argument 'value' should be string type, "
"but get {}".format(type(value))
)
raise TypeError("Input argument 'value' should be string type, " "but get {}".format(type(value)))
self._set_dayu_text()

def _set_dayu_type(self):
Expand All @@ -114,10 +111,7 @@ def set_dayu_type(self, value):
]:
self._dayu_type = value
else:
raise ValueError(
"Input argument 'value' should be one of "
"info/success/warning/error string."
)
raise ValueError("Input argument 'value' should be one of " "info/success/warning/error string.")
self._set_dayu_type()

def get_dayu_type(self):
Expand Down
9 changes: 2 additions & 7 deletions dayu_widgets/avatar.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ def _set_dayu_size(self):
self._set_dayu_image()

def _set_dayu_image(self):
self.setPixmap(
self._pixmap.scaledToWidth(self.height(), QtCore.Qt.SmoothTransformation)
)
self.setPixmap(self._pixmap.scaledToWidth(self.height(), QtCore.Qt.SmoothTransformation))

def set_dayu_image(self, value):
"""
Expand All @@ -68,10 +66,7 @@ def set_dayu_image(self, value):
elif isinstance(value, QtGui.QPixmap):
self._pixmap = self._default_pix if value.isNull() else value
else:
raise TypeError(
"Input argument 'value' should be QPixmap or None, "
"but get {}".format(type(value))
)
raise TypeError("Input argument 'value' should be QPixmap or None, " "but get {}".format(type(value)))
self._set_dayu_image()

def get_dayu_image(self):
Expand Down
12 changes: 3 additions & 9 deletions dayu_widgets/badge.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,13 @@ def __init__(self, widget=None, parent=None):
self._count = None

self._badge_button = QtWidgets.QPushButton()
self._badge_button.setSizePolicy(
QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum
)
self._badge_button.setSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)

self._main_lay = QtWidgets.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, QtCore.Qt.AlignTop | QtCore.Qt.AlignRight
)
self._main_lay.addWidget(self._badge_button, 0, 0, QtCore.Qt.AlignTop | QtCore.Qt.AlignRight)
self.setLayout(self._main_lay)

def get_dayu_overflow(self):
Expand Down Expand Up @@ -113,9 +109,7 @@ def set_dayu_count(self, num):
self._update_number()

def _update_number(self):
self._badge_button.setText(
utils.overflow_format(self._count, self._overflow_count)
)
self._badge_button.setText(utils.overflow_format(self._count, self._overflow_count))
self._badge_button.setVisible(self._count > 0)
self._dot = False
self.style().polish(self)
Expand Down
40 changes: 9 additions & 31 deletions dayu_widgets/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,20 @@ def _slot_browser_file(self):
else "Any File(*)"
)
if self.get_dayu_multiple():
r_files, _ = QtWidgets.QFileDialog.getOpenFileNames(
self, "Browser File", self.get_dayu_path(), filter_list
)
r_files, _ = QtWidgets.QFileDialog.getOpenFileNames(self, "Browser File", self.get_dayu_path(), filter_list)
if r_files:
self.sig_files_changed.emit(r_files)
self.set_dayu_path(r_files[0])
else:
r_file, _ = QtWidgets.QFileDialog.getOpenFileName(
self, "Browser File", self.get_dayu_path(), filter_list
)
r_file, _ = QtWidgets.QFileDialog.getOpenFileName(self, "Browser File", self.get_dayu_path(), filter_list)
if r_file:
self.sig_file_changed.emit(r_file)
self.set_dayu_path(r_file)


# @Slot()
def _slot_browser_folder(self):
r_folder = QtWidgets.QFileDialog.getExistingDirectory(
self, "Browser Folder", self.get_dayu_path()
)
r_folder = QtWidgets.QFileDialog.getExistingDirectory(self, "Browser Folder", self.get_dayu_path())
if r_folder:
if self.get_dayu_multiple():
self.sig_folders_changed.emit([r_folder])
Expand All @@ -78,9 +72,7 @@ def _slot_save_file(self):
if self.get_dayu_filters()
else "Any File(*)"
)
r_file, _ = QtWidgets.QFileDialog.getSaveFileName(
self, "Save File", self.get_dayu_path(), filter_list
)
r_file, _ = QtWidgets.QFileDialog.getSaveFileName(self, "Save File", self.get_dayu_path(), filter_list)
if r_file:
self.sig_file_changed.emit(r_file)
self.set_dayu_path(r_file)
Expand Down Expand Up @@ -291,9 +283,7 @@ def __init__(self, text="", multiple=False, parent=None):
self.set_dayu_svg("cloud_line.svg")

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

self._path = None
Expand Down Expand Up @@ -378,9 +368,7 @@ def _get_valid_file_list(self, url_list):
file_name = url.toLocalFile()
if sys.platform == "darwin":
sub_process = subprocess.Popen(
"osascript -e 'get posix path of posix file \"file://{}\" -- kthxbai'".format(
file_name
),
"osascript -e 'get posix path of posix file \"file://{}\" -- kthxbai'".format(file_name),
stdout=subprocess.PIPE,
shell=True,
)
Expand Down Expand Up @@ -521,9 +509,7 @@ def __init__(self, multiple=False, parent=None):
self.setIconSize(QtCore.QSize(size, size))
self.setText(self.tr("Click or drag folder here"))
self.clicked.connect(self.slot_browser_folder)
self.setSizePolicy(
QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding
)
self.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
self.setToolTip(self.tr("Click to browser folder or drag folder here"))

self._path = None
Expand Down Expand Up @@ -565,23 +551,15 @@ def set_dayu_multiple(self, value):
def dragEnterEvent(self, event):
"""Override dragEnterEvent. Validate dragged folders"""
if event.mimeData().hasFormat("text/uri-list"):
folder_list = [
url.toLocalFile()
for url in event.mimeData().urls()
if os.path.isdir(url.toLocalFile())
]
folder_list = [url.toLocalFile() for url in event.mimeData().urls() if os.path.isdir(url.toLocalFile())]
count = len(folder_list)
if count == 1 or (count > 1 and self.get_dayu_multiple()):
event.acceptProposedAction()
return

def dropEvent(self, event):
"""Override dropEvent to accept the dropped folders"""
folder_list = [
url.toLocalFile()
for url in event.mimeData().urls()
if os.path.isdir(url.toLocalFile())
]
folder_list = [url.toLocalFile() for url in event.mimeData().urls() if os.path.isdir(url.toLocalFile())]
if self.get_dayu_multiple():
self.sig_folders_changed.emit(folder_list)
else:
Expand Down
44 changes: 10 additions & 34 deletions dayu_widgets/button_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ def __init__(self, orientation=QtCore.Qt.Horizontal, parent=None):
self.setLayout(self._main_layout)
self.setSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
self._button_group = QtWidgets.QButtonGroup()
self._orientation = (
"horizontal" if orientation == QtCore.Qt.Horizontal else "vertical"
)
self._orientation = "horizontal" if orientation == QtCore.Qt.Horizontal else "vertical"

def set_spacing(self, value):
self._main_layout.setSpacing(value)
Expand Down Expand Up @@ -156,15 +154,9 @@ def _slot_context_menu(self, point):
action_select_all = context_menu.addAction("Select All")
action_select_none = context_menu.addAction("Select None")
action_select_invert = context_menu.addAction("Select Invert")
action_select_all.triggered.connect(
functools.partial(self._slot_set_select, True)
)
action_select_none.triggered.connect(
functools.partial(self._slot_set_select, False)
)
action_select_invert.triggered.connect(
functools.partial(self._slot_set_select, None)
)
action_select_all.triggered.connect(functools.partial(self._slot_set_select, True))
action_select_none.triggered.connect(functools.partial(self._slot_set_select, False))
action_select_invert.triggered.connect(functools.partial(self._slot_set_select, None))
context_menu.exec_(QtGui.QCursor.pos() + QtCore.QPoint(10, 10))

@QtCore.Slot(bool)
Expand All @@ -180,11 +172,7 @@ def _slot_set_select(self, state):
@QtCore.Slot(int)
def _slot_map_signal(self, state=None):
self.sig_checked_changed.emit(
[
check_box.text()
for check_box in self._button_group.buttons()
if check_box.isChecked()
]
[check_box.text() for check_box in self._button_group.buttons() if check_box.isChecked()]
)

def set_dayu_checked(self, value):
Expand All @@ -195,23 +183,15 @@ def set_dayu_checked(self, value):

self._dayu_checked = value
for check_box in self._button_group.buttons():
flag = (
QtCore.Qt.Checked if check_box.text() in value else QtCore.Qt.Unchecked
)
flag = QtCore.Qt.Checked if check_box.text() in value else QtCore.Qt.Unchecked
if flag != check_box.checkState():
check_box.setCheckState(flag)
self.sig_checked_changed.emit(value)

def get_dayu_checked(self):
return [
check_box.text()
for check_box in self._button_group.buttons()
if check_box.isChecked()
]
return [check_box.text() for check_box in self._button_group.buttons() if check_box.isChecked()]

dayu_checked = QtCore.Property(
"QVariantList", get_dayu_checked, set_dayu_checked, notify=sig_checked_changed
)
dayu_checked = QtCore.Property("QVariantList", get_dayu_checked, set_dayu_checked, notify=sig_checked_changed)


class MRadioButtonGroup(MButtonGroupBase):
Expand Down Expand Up @@ -245,9 +225,7 @@ def set_dayu_checked(self, value):
def get_dayu_checked(self):
return self._button_group.checkedId()

dayu_checked = QtCore.Property(
int, get_dayu_checked, set_dayu_checked, notify=sig_checked_changed
)
dayu_checked = QtCore.Property(int, get_dayu_checked, set_dayu_checked, notify=sig_checked_changed)


class MToolButtonGroup(MButtonGroupBase):
Expand Down Expand Up @@ -294,6 +272,4 @@ def set_dayu_checked(self, value):
def get_dayu_checked(self):
return self._button_group.checkedId()

dayu_checked = QtCore.Property(
int, get_dayu_checked, set_dayu_checked, notify=sig_checked_changed
)
dayu_checked = QtCore.Property(int, get_dayu_checked, set_dayu_checked, notify=sig_checked_changed)
8 changes: 2 additions & 6 deletions dayu_widgets/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
@hover_shadow_mixin
@cursor_mixin
class MCard(QtWidgets.QWidget):
def __init__(
self, title=None, image=None, size=None, extra=None, type=None, parent=None
):
def __init__(self, title=None, image=None, size=None, extra=None, type=None, parent=None):
super(MCard, self).__init__(parent=parent)
self.setAttribute(QtCore.Qt.WA_StyledBackground)
self.setProperty("border", False)
Expand Down Expand Up @@ -150,9 +148,7 @@ def setup_data(self, data_dict):
if data_dict.get("cover"):
fixed_height = self._cover_label.width()
self._cover_label.setPixmap(
data_dict.get("cover").scaledToWidth(
fixed_height, QtCore.Qt.SmoothTransformation
)
data_dict.get("cover").scaledToWidth(fixed_height, QtCore.Qt.SmoothTransformation)
)
self._cover_label.setVisible(True)
else:
Expand Down
20 changes: 5 additions & 15 deletions dayu_widgets/carousel.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ def __init__(self, parent=None):

def set_checked(self, value):
self.setStyleSheet(
"background-color:{}".format(
dayu_theme.primary_color if value else dayu_theme.background_color
)
"background-color:{}".format(dayu_theme.primary_color if value else dayu_theme.background_color)
)
self.setFixedSize(20 if value else 16, 4)

Expand All @@ -51,9 +49,7 @@ class MCarousel(QtWidgets.QGraphicsView):
def __init__(self, pix_list, autoplay=True, width=500, height=500, parent=None):
super(MCarousel, self).__init__(parent)
self.scene = QtWidgets.QGraphicsScene()
self.scene.setBackgroundBrush(
QtGui.QBrush(QtGui.QColor(dayu_theme.background_color))
)
self.scene.setBackgroundBrush(QtGui.QBrush(QtGui.QColor(dayu_theme.background_color)))
self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.setScene(self.scene)
Expand All @@ -77,9 +73,7 @@ def __init__(self, pix_list, autoplay=True, width=500, height=500, parent=None):
if pix.width() > pix.height():
new_pix = pix.scaledToWidth(target_size, QtCore.Qt.SmoothTransformation)
else:
new_pix = pix.scaledToHeight(
target_size, QtCore.Qt.SmoothTransformation
)
new_pix = pix.scaledToHeight(target_size, QtCore.Qt.SmoothTransformation)
pix_item = QtWidgets.QGraphicsPixmapItem(new_pix)
pix_item.setPos(pos)
pix_item.setTransformationMode(QtCore.Qt.SmoothTransformation)
Expand Down Expand Up @@ -122,15 +116,11 @@ def set_interval(self, ms):
self.autoplay_timer.setInterval(ms)

def next_page(self):
index = (
self.current_index + 1 if self.current_index + 1 < self.page_count else 0
)
index = self.current_index + 1 if self.current_index + 1 < self.page_count else 0
self.go_to_page(index)

def pre_page(self):
index = (
self.current_index - 1 if self.current_index > 0 else self.page_count - 1
)
index = self.current_index - 1 if self.current_index > 0 else self.page_count - 1
self.go_to_page(index)

def go_to_page(self, index):
Expand Down
Loading

0 comments on commit 4bce2f8

Please sign in to comment.