From 4bce2f80ea21e8acf496ad6b92e75137a8cabce7 Mon Sep 17 00:00:00 2001 From: Yanru Mu Date: Fri, 21 Jun 2024 12:09:14 +0800 Subject: [PATCH] style: change max line length from 88 to 120 --- dayu_widgets/alert.py | 10 +---- dayu_widgets/avatar.py | 9 +---- dayu_widgets/badge.py | 12 ++---- dayu_widgets/browser.py | 40 +++++--------------- dayu_widgets/button_group.py | 44 +++++----------------- dayu_widgets/card.py | 8 +--- dayu_widgets/carousel.py | 20 +++------- dayu_widgets/collapse.py | 24 +++--------- dayu_widgets/color_palette.py | 8 +--- dayu_widgets/combo_box.py | 8 +--- dayu_widgets/db_path_buttons.py | 20 +++------- dayu_widgets/divider.py | 8 +--- dayu_widgets/drawer.py | 44 +++++----------------- dayu_widgets/field_mixin.py | 18 ++------- dayu_widgets/flow_layout.py | 4 +- dayu_widgets/header_view.py | 32 ++++------------ dayu_widgets/item_model.py | 16 ++------ dayu_widgets/item_view.py | 43 +++++----------------- dayu_widgets/item_view_full_set.py | 20 +++------- dayu_widgets/item_view_set.py | 8 +--- dayu_widgets/label.py | 27 +++----------- dayu_widgets/line_edit.py | 4 +- dayu_widgets/line_tab_widget.py | 8 +--- dayu_widgets/loading.py | 14 +++---- dayu_widgets/menu.py | 59 +++++++----------------------- dayu_widgets/menu_tab_widget.py | 4 +- dayu_widgets/message.py | 22 +++-------- dayu_widgets/mixin.py | 10 +---- dayu_widgets/page.py | 33 ++++------------- dayu_widgets/popup.py | 6 +-- dayu_widgets/progress_circle.py | 6 +-- dayu_widgets/push_button.py | 3 +- dayu_widgets/sequence_file.py | 18 ++------- dayu_widgets/splitter.py | 4 +- dayu_widgets/text_edit.py | 4 +- dayu_widgets/toast.py | 14 ++----- dayu_widgets/utils.py | 54 ++++++--------------------- pyproject.toml | 2 +- 38 files changed, 162 insertions(+), 526 deletions(-) diff --git a/dayu_widgets/alert.py b/dayu_widgets/alert.py index a621a392..12408cb7 100644 --- a/dayu_widgets/alert.py +++ b/dayu_widgets/alert.py @@ -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): @@ -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): diff --git a/dayu_widgets/avatar.py b/dayu_widgets/avatar.py index 4738c8bb..ee8bb64f 100644 --- a/dayu_widgets/avatar.py +++ b/dayu_widgets/avatar.py @@ -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): """ @@ -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): diff --git a/dayu_widgets/badge.py b/dayu_widgets/badge.py index 3f44bdda..394ea470 100644 --- a/dayu_widgets/badge.py +++ b/dayu_widgets/badge.py @@ -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): @@ -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) diff --git a/dayu_widgets/browser.py b/dayu_widgets/browser.py index 091af106..a10d042a 100644 --- a/dayu_widgets/browser.py +++ b/dayu_widgets/browser.py @@ -43,16 +43,12 @@ 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) @@ -60,9 +56,7 @@ def _slot_browser_file(self): # @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]) @@ -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) @@ -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 @@ -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, ) @@ -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 @@ -565,11 +551,7 @@ 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() @@ -577,11 +559,7 @@ def dragEnterEvent(self, event): 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: diff --git a/dayu_widgets/button_group.py b/dayu_widgets/button_group.py index 51a51f13..fe85c3a9 100644 --- a/dayu_widgets/button_group.py +++ b/dayu_widgets/button_group.py @@ -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) @@ -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) @@ -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): @@ -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): @@ -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): @@ -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) diff --git a/dayu_widgets/card.py b/dayu_widgets/card.py index 3aa4c20b..8db41372 100644 --- a/dayu_widgets/card.py +++ b/dayu_widgets/card.py @@ -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) @@ -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: diff --git a/dayu_widgets/carousel.py b/dayu_widgets/carousel.py index a5c55b27..7b0ef8d0 100644 --- a/dayu_widgets/carousel.py +++ b/dayu_widgets/carousel.py @@ -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) @@ -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) @@ -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) @@ -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): diff --git a/dayu_widgets/collapse.py b/dayu_widgets/collapse.py index e62e57d7..cd685226 100644 --- a/dayu_widgets/collapse.py +++ b/dayu_widgets/collapse.py @@ -29,17 +29,13 @@ class MSectionItem(QtWidgets.QWidget): sig_context_menu = QtCore.Signal(object) - def __init__( - self, title="", expand=False, widget=None, closable=False, parent=None - ): + def __init__(self, title="", expand=False, widget=None, closable=False, parent=None): super(MSectionItem, self).__init__(parent) self._central_widget = None self.setAttribute(QtCore.Qt.WA_StyledBackground) self.title_label = MLabel(parent=self) self.expand_icon = MLabel(parent=self) - self.expand_icon.setSizePolicy( - QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum - ) + self.expand_icon.setSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum) self._close_button = MToolButton().icon_only().tiny().svg("close_line.svg") self._close_button.clicked.connect(self.close) @@ -52,9 +48,7 @@ def __init__( self.header_widget.setAttribute(QtCore.Qt.WA_StyledBackground) self.header_widget.setObjectName("title") self.header_widget.setLayout(header_lay) - self.header_widget.setSizePolicy( - QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum - ) + self.header_widget.setSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum) self.header_widget.setCursor(QtCore.Qt.PointingHandCursor) self.title_label.setCursor(QtCore.Qt.PointingHandCursor) self.header_widget.installEventFilter(self) @@ -70,9 +64,7 @@ def __init__( self.main_lay.addWidget(self.header_widget) self.main_lay.addWidget(self.content_widget) self.setLayout(self.main_lay) - self.setSizePolicy( - QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum - ) + self.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.setMouseTracking(True) self.set_title(title) self.set_closable(closable) @@ -102,9 +94,7 @@ def set_expand(self, value): def _set_expand(self, value): self.content_widget.setVisible(value) - self.expand_icon.setPixmap( - MPixmap("down_line.svg" if value else "right_line.svg").scaledToHeight(12) - ) + self.expand_icon.setPixmap(MPixmap("down_line.svg" if value else "right_line.svg").scaledToHeight(12)) def set_title(self, value): self.setProperty("title", value) @@ -142,9 +132,7 @@ def add_section(self, section_data): def add_section_list(self, section_list): for section_data in section_list: section_widget = self.add_section(section_data) - section_widget._close_button.clicked.connect( - functools.partial(self.remove_section, section_widget) - ) + section_widget._close_button.clicked.connect(functools.partial(self.remove_section, section_widget)) self._section_list.append(section_widget) def remove_section(self, widget): diff --git a/dayu_widgets/color_palette.py b/dayu_widgets/color_palette.py index ad2c4d7f..8e6f5daa 100644 --- a/dayu_widgets/color_palette.py +++ b/dayu_widgets/color_palette.py @@ -50,9 +50,7 @@ def set_colors(self, color_list): button.setProperty("color", target) button.setStyleSheet( "QPushButton{{background-color:{};color:{};border: 0 solid black}}" - "QPushButton:hover{{font-weight:bold;}}".format( - target, "#000" if index < 5 else "#fff" - ) + "QPushButton:hover{{font-weight:bold;}}".format(target, "#000" if index < 5 else "#fff") ) def slot_copy_color(self, button): @@ -112,9 +110,7 @@ def update_color(self): "background-color:{};".format(self.primary_color.name()) ) self.color_label.setText(self.primary_color.name()) - self.color_chart.set_colors( - [utils.generate_color(self.primary_color, index + 1) for index in range(10)] - ) + self.color_chart.set_colors([utils.generate_color(self.primary_color, index + 1) for index in range(10)]) if __name__ == "__main__": diff --git a/dayu_widgets/combo_box.py b/dayu_widgets/combo_box.py index 731c6415..9f2b29f6 100644 --- a/dayu_widgets/combo_box.py +++ b/dayu_widgets/combo_box.py @@ -44,9 +44,7 @@ def search(self): edit.setReadOnly(False) edit.returnPressed.disconnect() edit.textEdited.connect(self.filter_model.setFilterFixedString) - self.completer.activated.connect( - lambda t: t and self.setCurrentIndex(self.findText(t)) - ) + self.completer.activated.connect(lambda t: t and self.setCurrentIndex(self.findText(t))) def _set_searchable(self, value): """search property to True then trigger search""" @@ -84,9 +82,7 @@ def __init__(self, parent=None): self._has_custom_view = False self.set_value("") self.set_placeholder(self.tr("Please Select")) - self.setSizePolicy( - QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum - ) + self.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self._dayu_size = dayu_theme.default_size dayu_theme.apply(self) diff --git a/dayu_widgets/db_path_buttons.py b/dayu_widgets/db_path_buttons.py index b64e206e..a2cf6b40 100644 --- a/dayu_widgets/db_path_buttons.py +++ b/dayu_widgets/db_path_buttons.py @@ -26,9 +26,7 @@ def parse_db_orm(orm): "name": "ROOT" if hasattr(orm, "parent") and orm.parent is None else orm.name, "icon": utils.icon_formatter(orm), "get_children": lambda x: [ - parse_db_orm(orm) - for orm in getattr(x, orm_map.get(x.__tablename__, None)) - if orm.active + parse_db_orm(orm) for orm in getattr(x, orm_map.get(x.__tablename__, None)) if orm.active ], "has_children": lambda x: hasattr(x, orm_map.get(x.__tablename__, None)), "data": orm, @@ -46,9 +44,7 @@ def parse_path(path): "name": os.path.basename(path) or path, "icon": utils.icon_formatter(request_file("icon-browser.png")), "get_children": lambda x: [ - parse_path(os.path.join(path, i)) - for i in os.listdir(path) - if os.path.isdir(os.path.join(path, i)) + parse_path(os.path.join(path, i)) for i in os.listdir(path) if os.path.isdir(os.path.join(path, i)) ], "has_children": lambda x: next( (True for i in os.listdir(path) if os.path.isdir(os.path.join(path, i))), @@ -77,9 +73,7 @@ def __init__(self, data_dict, parent=None): self.menu_button.setPopupMode(QToolButton.InstantPopup) self.menu_button.setIconSize(QSize(10, 10)) self.menu_button.clicked.connect(self.slot_show_menu) - self.menu_button.setVisible( - data_dict.get("has_children")(data_dict.get("data")) - ) + self.menu_button.setVisible(data_dict.get("has_children")(data_dict.get("data"))) main_lay = QHBoxLayout() main_lay.setContentsMargins(0, 0, 0, 0) main_lay.setSpacing(0) @@ -167,9 +161,7 @@ def slot_show_menu(self, menu_button, data_dict): index = data_dict.get("index") for sub_obj in data_list: action = menu.addAction(sub_obj.get("icon"), sub_obj.get("name")) - action.triggered.connect( - partial(self.slot_menu_button_clicked, index, sub_obj) - ) + action.triggered.connect(partial(self.slot_menu_button_clicked, index, sub_obj)) menu_button.setMenu(menu) menu_button.showMenu() @@ -186,9 +178,7 @@ def slot_menu_button_clicked(self, index, data_dict): @Slot(object) def slot_go_to(self, obj_list): - for index, (his_obj, our_obj) in enumerate( - izip_longest(obj_list, self.get_obj_list()) - ): + for index, (his_obj, our_obj) in enumerate(izip_longest(obj_list, self.get_obj_list())): if his_obj is None: # 如果传来的 obj_list 最后一个是 None,则我方的 obj 多,直接清理掉多余的 self.clear_downstream(index) diff --git a/dayu_widgets/divider.py b/dayu_widgets/divider.py index ff93378d..758b7e55 100644 --- a/dayu_widgets/divider.py +++ b/dayu_widgets/divider.py @@ -67,12 +67,8 @@ def __init__( self._left_frame.setFrameShape(QtWidgets.QFrame.VLine) self._left_frame.setFrameShadow(QtWidgets.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._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) diff --git a/dayu_widgets/drawer.py b/dayu_widgets/drawer.py index 67562626..f13653e9 100644 --- a/dayu_widgets/drawer.py +++ b/dayu_widgets/drawer.py @@ -46,9 +46,7 @@ def __init__(self, title, position="right", closable=True, parent=None): # 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 = MToolButton(parent=self).icon_only().svg("close_line.svg").small() self._close_button.clicked.connect(self.close) self._close_button.setVisible(closable or False) @@ -117,56 +115,32 @@ def _set_proper_position(self): parent = self.parent() parent_geo = parent.geometry() if self._position == MDrawer.LeftPos: - pos = ( - parent_geo.topLeft() - if parent.parent() is None - else parent.mapToGlobal(parent_geo.topLeft()) - ) + pos = parent_geo.topLeft() if parent.parent() is None else parent.mapToGlobal(parent_geo.topLeft()) target_x = pos.x() target_y = pos.y() self.setFixedHeight(parent_geo.height()) - self._pos_ani.setStartValue( - QtCore.QPoint(target_x - self.width(), target_y) - ) + self._pos_ani.setStartValue(QtCore.QPoint(target_x - self.width(), target_y)) self._pos_ani.setEndValue(QtCore.QPoint(target_x, target_y)) if self._position == MDrawer.RightPos: - pos = ( - parent_geo.topRight() - if parent.parent() is None - else parent.mapToGlobal(parent_geo.topRight()) - ) + pos = parent_geo.topRight() if parent.parent() is None else parent.mapToGlobal(parent_geo.topRight()) self.setFixedHeight(parent_geo.height()) target_x = pos.x() - self.width() target_y = pos.y() - self._pos_ani.setStartValue( - QtCore.QPoint(target_x + self.width(), target_y) - ) + self._pos_ani.setStartValue(QtCore.QPoint(target_x + self.width(), target_y)) self._pos_ani.setEndValue(QtCore.QPoint(target_x, target_y)) if self._position == MDrawer.TopPos: - pos = ( - parent_geo.topLeft() - if parent.parent() is None - else parent.mapToGlobal(parent_geo.topLeft()) - ) + pos = parent_geo.topLeft() if parent.parent() is None else parent.mapToGlobal(parent_geo.topLeft()) self.setFixedWidth(parent_geo.width()) target_x = pos.x() target_y = pos.y() - self._pos_ani.setStartValue( - QtCore.QPoint(target_x, target_y - self.height()) - ) + self._pos_ani.setStartValue(QtCore.QPoint(target_x, target_y - self.height())) self._pos_ani.setEndValue(QtCore.QPoint(target_x, target_y)) if self._position == MDrawer.BottomPos: - pos = ( - parent_geo.bottomLeft() - if parent.parent() is None - else parent.mapToGlobal(parent_geo.bottomLeft()) - ) + pos = parent_geo.bottomLeft() if parent.parent() is None else parent.mapToGlobal(parent_geo.bottomLeft()) self.setFixedWidth(parent_geo.width()) target_x = pos.x() target_y = pos.y() - self.height() - self._pos_ani.setStartValue( - QtCore.QPoint(target_x, target_y + self.height()) - ) + self._pos_ani.setStartValue(QtCore.QPoint(target_x, target_y + self.height())) self._pos_ani.setEndValue(QtCore.QPoint(target_x, target_y)) def set_dayu_position(self, value): diff --git a/dayu_widgets/field_mixin.py b/dayu_widgets/field_mixin.py index 27c0165b..242287d7 100644 --- a/dayu_widgets/field_mixin.py +++ b/dayu_widgets/field_mixin.py @@ -36,9 +36,7 @@ def register_field(self, name, getter=None, setter=None, required=False): self.props_dict[name] = {"value": getter, "require": required, "bind": []} return - def bind( - self, data_name, widget, qt_property, index=None, signal=None, callback=None - ): + def bind(self, data_name, widget, qt_property, index=None, signal=None, callback=None): data_dict = { "data_name": data_name, "widget": widget, @@ -51,9 +49,7 @@ def bind( else: self.props_dict[data_name]["bind"].append(data_dict) if signal: # 用户操作绑定数据 - getattr(widget, signal).connect( - functools.partial(self._slot_changed_from_user, data_dict) - ) + getattr(widget, signal).connect(functools.partial(self._slot_changed_from_user, data_dict)) self._data_update_ui(data_dict) return widget @@ -90,14 +86,8 @@ def _data_update_ui(self, data_dict): elif isinstance(self.field(data_name), dict): value = self.field(data_name).get(index) elif isinstance(self.field(data_name), list): - value = ( - self.field(data_name)[index] - if index < len(self.field(data_name)) - else None - ) - if widget.metaObject().indexOfProperty( - widget_property - ) > -1 or widget_property in list( + value = self.field(data_name)[index] if index < len(self.field(data_name)) else None + if widget.metaObject().indexOfProperty(widget_property) > -1 or widget_property in list( map(str, [b.data().decode() for b in widget.dynamicPropertyNames()]) ): widget.setProperty(widget_property, value) diff --git a/dayu_widgets/flow_layout.py b/dayu_widgets/flow_layout.py index b4b2592f..4b65a11b 100644 --- a/dayu_widgets/flow_layout.py +++ b/dayu_widgets/flow_layout.py @@ -94,9 +94,7 @@ def minimumSize(self): for item in self.item_list: size = size.expandedTo(item.minimumSize()) - size += QtCore.QSize( - 2 * self.contentsMargins().top(), 2 * self.contentsMargins().top() - ) + size += QtCore.QSize(2 * self.contentsMargins().top(), 2 * self.contentsMargins().top()) return size def do_layout(self, rect, test_only): diff --git a/dayu_widgets/header_view.py b/dayu_widgets/header_view.py index dfe2c593..10e99081 100644 --- a/dayu_widgets/header_view.py +++ b/dayu_widgets/header_view.py @@ -52,41 +52,27 @@ def _slot_context_menu(self, point): context_menu = MMenu(parent=self) logical_column = self.logicalIndexAt(point) model = utils.real_model(self.model()) - if logical_column >= 0 and model.header_list[logical_column].get( - "checkable", False - ): + if logical_column >= 0 and model.header_list[logical_column].get("checkable", False): action_select_all = context_menu.addAction(self.tr("Select All")) action_select_none = context_menu.addAction(self.tr("Select None")) action_select_invert = context_menu.addAction(self.tr("Select Invert")) action_select_all.triggered.connect( - functools.partial( - self._slot_set_select, logical_column, QtCore.Qt.Checked - ) + functools.partial(self._slot_set_select, logical_column, QtCore.Qt.Checked) ) action_select_none.triggered.connect( - functools.partial( - self._slot_set_select, logical_column, QtCore.Qt.Unchecked - ) - ) - action_select_invert.triggered.connect( - functools.partial(self._slot_set_select, logical_column, None) + functools.partial(self._slot_set_select, logical_column, QtCore.Qt.Unchecked) ) + action_select_invert.triggered.connect(functools.partial(self._slot_set_select, logical_column, None)) context_menu.addSeparator() fit_action = context_menu.addAction(self.tr("Fit Size")) - fit_action.triggered.connect( - functools.partial(self._slot_set_resize_mode, True) - ) + fit_action.triggered.connect(functools.partial(self._slot_set_resize_mode, True)) context_menu.addSeparator() for column in range(self.count()): - action = context_menu.addAction( - model.headerData(column, QtCore.Qt.Horizontal, QtCore.Qt.DisplayRole) - ) + action = context_menu.addAction(model.headerData(column, QtCore.Qt.Horizontal, QtCore.Qt.DisplayRole)) action.setCheckable(True) action.setChecked(not self.isSectionHidden(column)) - action.toggled.connect( - functools.partial(self._slot_set_section_visible, column) - ) + action.toggled.connect(functools.partial(self._slot_set_section_visible, column)) context_menu.exec_(QtGui.QCursor.pos() + QtCore.QPoint(10, 10)) @QtCore.Slot(int, int) @@ -103,9 +89,7 @@ def _slot_set_select(self, column, state): utils.set_obj_value( data_obj, attr, - QtCore.Qt.Unchecked - if old_state == QtCore.Qt.Checked - else QtCore.Qt.Checked, + QtCore.Qt.Unchecked if old_state == QtCore.Qt.Checked else QtCore.Qt.Checked, ) else: utils.set_obj_value(data_obj, attr, state) diff --git a/dayu_widgets/item_model.py b/dayu_widgets/item_model.py index d2cb01ab..48514a24 100644 --- a/dayu_widgets/item_model.py +++ b/dayu_widgets/item_model.py @@ -217,12 +217,8 @@ def data(self, index, role=QtCore.Qt.DisplayRole): # 如果header中没有配置该role,而且也不是 DisplayRole/EditRole,直接返回None return None else: - value = apply_formatter( - formatter_from_config, get_obj_value(data_obj, attr), data_obj - ) - formatter_from_model = SETTING_MAP[role].get( - "formatter", None - ) # role 配置的转换函数 + value = apply_formatter(formatter_from_config, get_obj_value(data_obj, attr), data_obj) + formatter_from_model = SETTING_MAP[role].get("formatter", None) # role 配置的转换函数 result = apply_formatter(formatter_from_model, value) return result @@ -254,9 +250,7 @@ def setData(self, index, value, role=QtCore.Qt.EditRole): parent_obj = parent_index.internalPointer() new_parent_value = value old_parent_value = get_obj_value(parent_obj, key) - for sibling_obj in get_obj_value( - get_obj_value(data_obj, "_parent"), "children", [] - ): + for sibling_obj in get_obj_value(get_obj_value(data_obj, "_parent"), "children", []): if value != get_obj_value(sibling_obj, key): new_parent_value = 1 break @@ -298,9 +292,7 @@ def filterAcceptsRow(self, source_row, source_parent): if self.search_reg.pattern(): for index, data_dict in enumerate(self.header_list): if data_dict.get("searchable", False): - model_index = self.sourceModel().index( - source_row, index, source_parent - ) + model_index = self.sourceModel().index(source_row, index, source_parent) value = self.sourceModel().data(model_index) if self.search_reg.indexIn(six.text_type(value)) != -1: # 搜索匹配上了 diff --git a/dayu_widgets/item_view.py b/dayu_widgets/item_view.py index 29b9f04a..70c8cae2 100644 --- a/dayu_widgets/item_view.py +++ b/dayu_widgets/item_view.py @@ -39,13 +39,9 @@ def draw_empty_content(view, text=None, pix_map=None): painter.setPen(QtGui.QPen(QtGui.QColor(dayu_theme.secondary_text_color))) content_height = pix_map.height() + font_metrics.height() padding = 10 - proper_min_size = min( - view.height() - padding * 2, view.width() - padding * 2, content_height - ) + proper_min_size = min(view.height() - padding * 2, view.width() - padding * 2, content_height) if proper_min_size < content_height: - pix_map = pix_map.scaledToHeight( - proper_min_size - font_metrics.height(), QtCore.Qt.SmoothTransformation - ) + pix_map = pix_map.scaledToHeight(proper_min_size - font_metrics.height(), QtCore.Qt.SmoothTransformation) content_height = proper_min_size painter.drawText( view.width() / 2 - font_metrics.width(text) / 2, @@ -94,9 +90,7 @@ def setModelData(self, editor, model, index): def updateEditorGeometry(self, editor, option, index): editor.move( - self.parent_widget.mapToGlobal( - QtCore.QPoint(option.rect.x(), option.rect.y() + option.rect.height()) - ) + self.parent_widget.mapToGlobal(QtCore.QPoint(option.rect.x(), option.rect.y() + option.rect.height())) ) def paint(self, painter, option, index): @@ -114,9 +108,7 @@ def paint(self, painter, option, index): pix = MPixmap("down_fill.svg", icon_color) h = option.rect.height() pix = pix.scaledToWidth(h * 0.5, QtCore.Qt.SmoothTransformation) - painter.drawPixmap( - option.rect.x() + option.rect.width() - h, option.rect.y() + h / 4, pix - ) + painter.drawPixmap(option.rect.x() + option.rect.width() - h, option.rect.y() + h / 4, pix) painter.restore() super(MOptionDelegate, self).paint(painter, option, index) @@ -169,15 +161,8 @@ def slot_context_menu(self, point): if proxy_index.isValid(): need_map = isinstance(self.model(), QtCore.QSortFilterProxyModel) selection = [] - for index in ( - self.selectionModel().selectedRows() - or self.selectionModel().selectedIndexes() - ): - data_obj = ( - self.model().mapToSource(index).internalPointer() - if need_map - else index.internalPointer() - ) + for index in self.selectionModel().selectedRows() or self.selectionModel().selectedIndexes(): + data_obj = self.model().mapToSource(index).internalPointer() if need_map else index.internalPointer() selection.append(data_obj) event = utils.ItemViewMenuEvent(view=self, selection=selection, extra={}) self.sig_context_menu.emit(event) @@ -288,9 +273,7 @@ def paintEvent(self, event): draw_empty_content(self.viewport(), self._no_data_text, self._no_data_image) elif isinstance(model, MTableModel): if not model.get_data_list(): - draw_empty_content( - self.viewport(), self._no_data_text, self._no_data_image - ) + draw_empty_content(self.viewport(), self._no_data_text, self._no_data_image) return super(MTableView, self).paintEvent(event) def save_state(self, name): @@ -336,9 +319,7 @@ def paintEvent(self, event): draw_empty_content(self.viewport(), self._no_data_text, self._no_data_image) elif isinstance(model, MTableModel): if not model.get_data_list(): - draw_empty_content( - self.viewport(), self._no_data_text, self._no_data_image - ) + draw_empty_content(self.viewport(), self._no_data_text, self._no_data_image) return super(MTreeView, self).paintEvent(event) def set_no_data_text(self, text): @@ -392,9 +373,7 @@ def paintEvent(self, event): draw_empty_content(self.viewport(), self._no_data_text, self._no_data_image) elif isinstance(model, MTableModel): if not model.get_data_list(): - draw_empty_content( - self.viewport(), self._no_data_text, self._no_data_image - ) + draw_empty_content(self.viewport(), self._no_data_text, self._no_data_image) return super(MBigView, self).paintEvent(event) def set_no_data_text(self, text): @@ -432,9 +411,7 @@ def paintEvent(self, event): draw_empty_content(self.viewport(), self._no_data_text, self._no_data_image) elif isinstance(model, MTableModel): if not model.get_data_list(): - draw_empty_content( - self.viewport(), self._no_data_text, self._no_data_image - ) + draw_empty_content(self.viewport(), self._no_data_text, self._no_data_image) return super(MListView, self).paintEvent(event) def set_no_data_text(self, text): diff --git a/dayu_widgets/item_view_full_set.py b/dayu_widgets/item_view_full_set.py index b7621bcc..44294846 100644 --- a/dayu_widgets/item_view_full_set.py +++ b/dayu_widgets/item_view_full_set.py @@ -51,18 +51,14 @@ def __init__(self, table_view=True, big_view=False, parent=None): self.table_view.pressed.connect(self.slot_left_clicked) self.table_view.setModel(self.sort_filter_model) self.stack_widget.addWidget(self.table_view) - data_group.append( - {"svg": "table_view.svg", "checkable": True, "tooltip": "Table View"} - ) + data_group.append({"svg": "table_view.svg", "checkable": True, "tooltip": "Table View"}) if big_view: self.big_view = MBigView() self.big_view.doubleClicked.connect(self.sig_double_clicked) self.big_view.pressed.connect(self.slot_left_clicked) self.big_view.setModel(self.sort_filter_model) self.stack_widget.addWidget(self.big_view) - data_group.append( - {"svg": "big_view.svg", "checkable": True, "tooltip": "Big View"} - ) + data_group.append({"svg": "big_view.svg", "checkable": True, "tooltip": "Big View"}) # 设置多个view 共享 MItemSelectionModel leader_view = self.stack_widget.widget(0) @@ -75,27 +71,21 @@ def __init__(self, table_view=True, big_view=False, parent=None): self.selection_model.currentChanged.connect(self.sig_current_changed) self.selection_model.currentRowChanged.connect(self.sig_current_row_changed) - self.selection_model.currentColumnChanged.connect( - self.sig_current_column_changed - ) + self.selection_model.currentColumnChanged.connect(self.sig_current_column_changed) self.selection_model.selectionChanged.connect(self.sig_selection_changed) self.tool_bar = QtWidgets.QWidget() self.top_lay = QtWidgets.QHBoxLayout() self.top_lay.setContentsMargins(0, 0, 0, 0) if data_group and len(data_group) > 1: - self.view_button_grp.sig_checked_changed.connect( - self.stack_widget.setCurrentIndex - ) + self.view_button_grp.sig_checked_changed.connect(self.stack_widget.setCurrentIndex) self.view_button_grp.set_button_list(data_group) self.view_button_grp.set_dayu_checked(0) self.top_lay.addWidget(self.view_button_grp) 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.textChanged.connect(self.sort_filter_model.set_search_pattern) self.search_line_edit.setVisible(False) self.top_lay.addStretch() diff --git a/dayu_widgets/item_view_set.py b/dayu_widgets/item_view_set.py index 66df35de..08e65c16 100644 --- a/dayu_widgets/item_view_set.py +++ b/dayu_widgets/item_view_set.py @@ -50,13 +50,9 @@ def __init__(self, view_type=None, parent=None): 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_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.textChanged.connect(self.sort_filter_model.set_search_pattern) self._search_line_edit.setVisible(False) self._search_lay = QtWidgets.QHBoxLayout() self._search_lay.setContentsMargins(0, 0, 0, 0) diff --git a/dayu_widgets/label.py b/dayu_widgets/label.py index d9def9db..e9603abc 100644 --- a/dayu_widgets/label.py +++ b/dayu_widgets/label.py @@ -37,12 +37,8 @@ class MLabel(QtWidgets.QLabel): def __init__(self, text="", parent=None, flags=QtCore.Qt.Widget): super(MLabel, self).__init__(text, parent, flags) - self.setTextInteractionFlags( - QtCore.Qt.TextBrowserInteraction | QtCore.Qt.LinksAccessibleByMouse - ) - self.setSizePolicy( - QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Minimum - ) + self.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction | QtCore.Qt.LinksAccessibleByMouse) + self.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Minimum) self._dayu_type = "" self._dayu_underline = False self._dayu_mark = False @@ -125,9 +121,7 @@ def set_dayu_type(self, value): dayu_strong = QtCore.Property(bool, get_dayu_strong, set_dayu_strong) dayu_mark = QtCore.Property(bool, get_dayu_mark, set_dayu_mark) dayu_code = QtCore.Property(bool, get_dayu_code, set_dayu_code) - dayu_elide_mod = QtCore.Property( - QtCore.Qt.TextElideMode, get_dayu_code, set_dayu_code - ) + dayu_elide_mod = QtCore.Property(QtCore.Qt.TextElideMode, get_dayu_code, set_dayu_code) def minimumSizeHint(self): return QtCore.QSize(1, self.fontMetrics().height()) @@ -158,11 +152,7 @@ def set_link(self, href, text=None): """ # 这里富文本的超链接必须使用 html 的样式,使用 qss 不起作用 link_style = dayu_theme.hyperlink_style - self.setText( - '{style}{text}'.format( - style=link_style, href=href, text=text or href - ) - ) + self.setText('{style}{text}'.format(style=link_style, href=href, text=text or href)) self.setOpenExternalLinks(True) def _update_elided_text(self): @@ -172,9 +162,7 @@ def _update_elided_text(self): _font_metrics = self.fontMetrics() text = self.property("text") text = text if text else "" - _elided_text = _font_metrics.elidedText( - text, self._elide_mode, self.width() - 2 * 2 - ) + _elided_text = _font_metrics.elidedText(text, self._elide_mode, self.width() - 2 * 2) super(MLabel, self).setText(_elided_text) def resizeEvent(self, event): @@ -246,9 +234,6 @@ def underline(self): return self def event(self, event): - if ( - event.type() == QtCore.QEvent.DynamicPropertyChange - and event.propertyName() == "dayu_text" - ): + if event.type() == QtCore.QEvent.DynamicPropertyChange and event.propertyName() == "dayu_text": self.setText(self.property("dayu_text")) return super(MLabel, self).event(event) diff --git a/dayu_widgets/line_edit.py b/dayu_widgets/line_edit.py index e27c36c4..cc4d5589 100644 --- a/dayu_widgets/line_edit.py +++ b/dayu_widgets/line_edit.py @@ -166,9 +166,7 @@ def _slot_show_detail(self): dialog = QtWidgets.QTextEdit(self) dialog.setReadOnly(True) geo = QtWidgets.QApplication.desktop().screenGeometry() - dialog.setGeometry( - geo.width() / 2, geo.height() / 2, geo.width() / 4, geo.height() / 4 - ) + dialog.setGeometry(geo.width() / 2, geo.height() / 2, geo.width() / 4, geo.height() / 4) dialog.setWindowTitle(self.tr("Error Detail Information")) dialog.setText(self.property("history")) dialog.setWindowFlags(QtCore.Qt.Dialog) diff --git a/dayu_widgets/line_tab_widget.py b/dayu_widgets/line_tab_widget.py index d22c71b2..0fb04427 100644 --- a/dayu_widgets/line_tab_widget.py +++ b/dayu_widgets/line_tab_widget.py @@ -72,9 +72,7 @@ def get_dayu_checked(self): """Get current checked button's id""" 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 MLineTabWidget(QtWidgets.QWidget): @@ -96,9 +94,7 @@ def __init__(self, alignment=QtCore.Qt.AlignCenter, parent=None): 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 - ) + self.tool_button_group.sig_checked_changed.connect(self.stack_widget.setCurrentIndex) main_lay = QtWidgets.QVBoxLayout() main_lay.setContentsMargins(0, 0, 0, 0) main_lay.setSpacing(0) diff --git a/dayu_widgets/loading.py b/dayu_widgets/loading.py index bae35905..c51957cb 100644 --- a/dayu_widgets/loading.py +++ b/dayu_widgets/loading.py @@ -32,9 +32,9 @@ def __init__(self, size=None, color=None, parent=None): super(MLoading, self).__init__(parent) size = size or dayu_theme.default_size self.setFixedSize(QtCore.QSize(size, size)) - self.pix = MPixmap( - "loading.svg", color or dayu_theme.primary_color - ).scaledToWidth(size, QtCore.Qt.SmoothTransformation) + self.pix = MPixmap("loading.svg", color or dayu_theme.primary_color).scaledToWidth( + size, QtCore.Qt.SmoothTransformation + ) self._rotation = 0 self._loading_ani = QtCore.QPropertyAnimation() self._loading_ani.setTargetObject(self) @@ -109,13 +109,9 @@ def __init__(self, widget, loading=True, parent=None): self._widget = widget self._mask_widget = QtWidgets.QFrame() self._mask_widget.setObjectName("mask") - self._mask_widget.setSizePolicy( - QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding - ) + self._mask_widget.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) self._loading_widget = MLoading() - self._loading_widget.setSizePolicy( - QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding - ) + self._loading_widget.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) self._main_lay = QtWidgets.QGridLayout() self._main_lay.setContentsMargins(0, 0, 0, 0) diff --git a/dayu_widgets/menu.py b/dayu_widgets/menu.py index 9220b8fa..e8f33b1e 100644 --- a/dayu_widgets/menu.py +++ b/dayu_widgets/menu.py @@ -44,9 +44,7 @@ def __init__(self, *args, **kwargs): self._maximumHeight = self.maximumHeight() self._actionRects = [] - self.scrollTimer = QtCore.QTimer( - self, interval=50, singleShot=True, timeout=self.checkScroll - ) + self.scrollTimer = QtCore.QTimer(self, interval=50, singleShot=True, timeout=self.checkScroll) self.scrollTimer.setProperty("defaultInterval", 50) self.delayTimer = QtCore.QTimer(self, interval=100, singleShot=True) @@ -82,13 +80,9 @@ def setMaxItemCount(self, count): size = QtCore.QSize() fm = self.fontMetrics() qfm = opt.fontMetrics - size.setWidth( - fm.boundingRect(QtCore.QRect(), QtCore.Qt.TextSingleLine, a.text()).width() - ) + size.setWidth(fm.boundingRect(QtCore.QRect(), QtCore.Qt.TextSingleLine, a.text()).width()) size.setHeight(max(fm.height(), qfm.height())) - self.defaultItemHeight = style.sizeFromContents( - style.CT_MenuItem, opt, size, self - ).height() + self.defaultItemHeight = style.sizeFromContents(style.CT_MenuItem, opt, size, self).height() if not count: self.setMaximumHeight(self._maximumHeight) @@ -96,19 +90,14 @@ def setMaxItemCount(self, count): fw = style.pixelMetric(style.PM_MenuPanelWidth, None, self) vmargin = style.pixelMetric(style.PM_MenuHMargin, opt, self) scrollHeight = self.scrollHeight(style) - self.setMaximumHeight( - self.defaultItemHeight * count + (fw + vmargin + scrollHeight) * 2 - ) + self.setMaximumHeight(self.defaultItemHeight * count + (fw + vmargin + scrollHeight) * 2) self.dirty = True def scrollHeight(self, style): return style.pixelMetric(style.PM_MenuScrollerHeight, None, self) * 2 def isScrollable(self): - return ( - self.property("scrollable") - and self.height() < super(ScrollableMenuBase, self).sizeHint().height() - ) + return self.property("scrollable") and self.height() < super(ScrollableMenuBase, self).sizeHint().height() def checkScroll(self): pos = self.mapFromGlobal(QtGui.QCursor.pos()) @@ -156,9 +145,7 @@ def scrollBy(self, step): for lastAction in reversed(self.actions()): if lastAction.isVisible(): break - lastBottom = ( - self.actionGeometry(lastAction).bottom() - newDelta + scrollHeight - ) + lastBottom = self.actionGeometry(lastAction).bottom() - newDelta + scrollHeight if lastBottom < bottom: newDelta -= bottom - lastBottom if newDelta == self.deltaY: @@ -220,9 +207,7 @@ def event(self, event): elif event.type() == event.MouseButtonRelease: pos = event.pos() self.scrollTimer.stop() - if not ( - self.scrollUpRect.contains(pos) or self.scrollDownRect.contains(pos) - ): + if not (self.scrollUpRect.contains(pos) or self.scrollDownRect.contains(pos)): action = self.actionAt(pos) if action: action.trigger() @@ -320,9 +305,7 @@ def resizeEvent(self, event): contentWidth = self.width() - (fw + hmargin) * 2 - l - r scrollHeight = self.scrollHeight(style) - self.scrollUpRect = QtCore.QRect( - leftMargin, topMargin, contentWidth, scrollHeight - ) + self.scrollUpRect = QtCore.QRect(leftMargin, topMargin, contentWidth, scrollHeight) self.scrollDownRect = QtCore.QRect( leftMargin, self.height() - scrollHeight - bottomMargin, @@ -408,13 +391,9 @@ def paintEvent(self, event): if fw: borderReg = QtGui.QRegion() borderReg |= QtGui.QRegion(QtCore.QRect(0, 0, fw, self.height())) - borderReg |= QtGui.QRegion( - QtCore.QRect(self.width() - fw, 0, fw, self.height()) - ) + borderReg |= QtGui.QRegion(QtCore.QRect(self.width() - fw, 0, fw, self.height())) borderReg |= QtGui.QRegion(QtCore.QRect(0, 0, self.width(), fw)) - borderReg |= QtGui.QRegion( - QtCore.QRect(0, self.height() - fw, self.width(), fw) - ) + borderReg |= QtGui.QRegion(QtCore.QRect(0, self.height() - fw, self.width(), fw)) qp.setClipRegion(borderReg) emptyArea -= borderReg frame = QtWidgets.QStyleOptionFrame() @@ -443,9 +422,7 @@ def __init__(self, *args, **kwargs): self.search_label = QtWidgets.QLabel() self.search_bar.textChanged.connect(self.slot_search_change) - self.search_bar.keyPressEvent = partial( - self.search_key_event, self.search_bar.keyPressEvent - ) + self.search_bar.keyPressEvent = partial(self.search_key_event, self.search_bar.keyPressEvent) self.aboutToHide.connect(lambda: self.search_bar.setText("")) layout = QtWidgets.QVBoxLayout() @@ -595,9 +572,7 @@ def _add_menu(self, parent_menu, data_dict, long_path=None): else: self._add_menu(menu, i) else: - action = self._action_group.addAction( - utils.display_formatter(data_dict.get("label")) - ) + action = self._action_group.addAction(utils.display_formatter(data_dict.get("label"))) action.setProperty("value", data_dict.get("value")) action.setCheckable(True) # 用来将来获取父层级数据 @@ -609,9 +584,7 @@ def set_data(self, option_list): assert isinstance(option_list, list) if option_list: if all(isinstance(i, six.string_types) for i in option_list): - option_list = utils.from_list_to_nested_dict( - option_list, sep=self.property("separator") - ) + option_list = utils.from_list_to_nested_dict(option_list, sep=self.property("separator")) if all(isinstance(i, (int, float)) for i in option_list): option_list = [{"value": i, "label": str(i)} for i in option_list] # 全部转换成 dict 类型的 list @@ -640,11 +613,7 @@ def slot_on_action_triggered(self, action): if self._action_group.isExclusive(): selected_data = current_data else: - selected_data = [ - act.property("value") - for act in self._action_group.actions() - if act.isChecked() - ] + selected_data = [act.property("value") for act in self._action_group.actions() if act.isChecked()] self.set_value(selected_data) self.sig_value_changed.emit(selected_data) diff --git a/dayu_widgets/menu_tab_widget.py b/dayu_widgets/menu_tab_widget.py index ed012e36..95557dff 100644 --- a/dayu_widgets/menu_tab_widget.py +++ b/dayu_widgets/menu_tab_widget.py @@ -71,9 +71,7 @@ def get_dayu_checked(self): """Get current checked button's id""" 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 MMenuTabWidget(QtWidgets.QWidget): diff --git a/dayu_widgets/message.py b/dayu_widgets/message.py index da346e1a..37dfbd84 100644 --- a/dayu_widgets/message.py +++ b/dayu_widgets/message.py @@ -39,9 +39,7 @@ class MMessage(QtWidgets.QWidget): sig_closed = QtCore.Signal() - def __init__( - self, text, duration=None, dayu_type=None, closable=False, parent=None - ): + def __init__(self, text, duration=None, dayu_type=None, closable=False, parent=None): super(MMessage, self).__init__(parent) self.setObjectName("message") self.setWindowFlags( @@ -68,9 +66,7 @@ def __init__( # 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 = MToolButton(parent=self).icon_only().svg("close_line.svg").tiny() self._close_button.clicked.connect(self.close) self._close_button.setVisible(closable or False) @@ -85,15 +81,11 @@ def __init__( _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 - ) + _close_timer.setInterval((duration or self.default_config.get("duration")) * 1000) _ani_timer = QtCore.QTimer(self) _ani_timer.timeout.connect(self._fade_out) - _ani_timer.setInterval( - (duration or self.default_config.get("duration")) * 1000 - 300 - ) + _ani_timer.setInterval((duration or self.default_config.get("duration")) * 1000 - 300) _close_timer.start() _ani_timer.start() @@ -127,11 +119,7 @@ def _fade_int(self): def _set_proper_position(self, parent): parent_geo = parent.geometry() - pos = ( - parent_geo.topLeft() - if parent.parent() is None - else parent.mapToGlobal(parent_geo.topLeft()) - ) + pos = parent_geo.topLeft() if parent.parent() is None else parent.mapToGlobal(parent_geo.topLeft()) offset = 0 for child in parent.children(): if isinstance(child, MMessage) and child.isVisible(): diff --git a/dayu_widgets/mixin.py b/dayu_widgets/mixin.py index e7712f4b..c46f8f58 100644 --- a/dayu_widgets/mixin.py +++ b/dayu_widgets/mixin.py @@ -49,9 +49,7 @@ def _new_enter_event(self, *args, **kwargs): old_enter_event(self, *args, **kwargs) self.__dict__.update({"__dayu_enter": True}) QtWidgets.QApplication.setOverrideCursor( - QtCore.Qt.PointingHandCursor - if self.isEnabled() - else QtCore.Qt.ForbiddenCursor + QtCore.Qt.PointingHandCursor if self.isEnabled() else QtCore.Qt.ForbiddenCursor ) return super(cls, self).enterEvent(*args, **kwargs) @@ -151,11 +149,7 @@ def _stackable(widget): """Used for stacked_animation_mixin to only add mixin for widget who can stacked.""" # We use widget() to get currentWidget, use currentChanged to play the animation. # For now just QTabWidget and QStackedWidget can use this decorator. - return ( - issubclass(widget, QtWidgets.QWidget) - and hasattr(widget, "widget") - and hasattr(widget, "currentChanged") - ) + return issubclass(widget, QtWidgets.QWidget) and hasattr(widget, "widget") and hasattr(widget, "currentChanged") def stacked_animation_mixin(cls): diff --git a/dayu_widgets/page.py b/dayu_widgets/page.py index 416b0e50..b25aba37 100644 --- a/dayu_widgets/page.py +++ b/dayu_widgets/page.py @@ -54,9 +54,7 @@ def __init__(self, parent=None): self.register_field("current_page", 0) self.register_field( "total_page", - lambda: utils.get_total_page( - self.field("total"), self.field("page_size_selected") - ), + lambda: utils.get_total_page(self.field("total"), self.field("page_size_selected")), ) self.register_field("total_page_text", lambda: str(self.field("total_page"))) self.register_field( @@ -68,9 +66,7 @@ def __init__(self, parent=None): ), ) self.register_field("can_pre", lambda: self.field("current_page") > 1) - self.register_field( - "can_next", lambda: self.field("current_page") < self.field("total_page") - ) + self.register_field("can_next", lambda: self.field("current_page") < self.field("total_page")) page_setting_menu = MMenu(parent=self) self._display_label = MLabel() self._display_label.setAlignment(QtCore.Qt.AlignCenter) @@ -79,13 +75,9 @@ def __init__(self, parent=None): self._change_page_size_button.set_formatter(lambda x: "{} per page".format(x)) self._pre_button = MToolButton().icon_only().svg("left_fill.svg").small() - self._pre_button.clicked.connect( - functools.partial(self._slot_change_current_page, -1) - ) + self._pre_button.clicked.connect(functools.partial(self._slot_change_current_page, -1)) self._next_button = MToolButton().small().icon_only().svg("right_fill.svg") - self._next_button.clicked.connect( - functools.partial(self._slot_change_current_page, 1) - ) + self._next_button.clicked.connect(functools.partial(self._slot_change_current_page, 1)) self._current_page_spin_box = MSpinBox() self._current_page_spin_box.setMinimum(1) self._current_page_spin_box.set_dayu_size(dayu_theme.small) @@ -93,18 +85,14 @@ def __init__(self, parent=None): self._total_page_label = MLabel() self.bind("page_size_list", page_setting_menu, "data") - self.bind( - "page_size_selected", page_setting_menu, "value", signal="sig_value_changed" - ) + self.bind("page_size_selected", page_setting_menu, "value", signal="sig_value_changed") self.bind( "page_size_selected", self._change_page_size_button, "value", signal="sig_value_changed", ) - self.bind( - "current_page", self._current_page_spin_box, "value", signal="valueChanged" - ) + self.bind("current_page", self._current_page_spin_box, "value", signal="valueChanged") self.bind("total_page", self._current_page_spin_box, "maximum") self.bind("total_page_text", self._total_page_label, "dayu_text") self.bind("display_text", self._display_label, "dayu_text") @@ -143,13 +131,8 @@ def set_page_config(self, data_list): """Set page component per page settings.""" self.set_field( "page_size_list", - [ - {"label": str(data), "value": data} if isinstance(data, int) else data - for data in data_list - ], + [{"label": str(data), "value": data} if isinstance(data, int) else data for data in data_list], ) def _emit_page_changed(self): - self.sig_page_changed.emit( - self.field("page_size_selected"), self.field("current_page") - ) + self.sig_page_changed.emit(self.field("page_size_selected"), self.field("current_page")) diff --git a/dayu_widgets/popup.py b/dayu_widgets/popup.py index 7a84ad9a..9e3a4ff3 100644 --- a/dayu_widgets/popup.py +++ b/dayu_widgets/popup.py @@ -107,11 +107,7 @@ def mouseReleaseEvent(self, event): return super(MPopup, self).mouseReleaseEvent(event) def mouseMoveEvent(self, event): - if ( - event.buttons() == QtCore.Qt.LeftButton - and self.mouse_pos - and self.property("movable") - ): + if event.buttons() == QtCore.Qt.LeftButton and self.mouse_pos and self.property("movable"): self.move(self.mapToGlobal(event.pos() - self.mouse_pos)) return super(MPopup, self).mouseMoveEvent(event) diff --git a/dayu_widgets/progress_circle.py b/dayu_widgets/progress_circle.py index 5b07ebb1..d68119d1 100644 --- a/dayu_widgets/progress_circle.py +++ b/dayu_widgets/progress_circle.py @@ -80,11 +80,7 @@ def set_dayu_width(self, value): :return: None """ self._width = value - self.setFixedSize( - QtCore.QSize( - self._width * self._width_factor, self._width * self._height_factor - ) - ) + self.setFixedSize(QtCore.QSize(self._width * self._width_factor, self._width * self._height_factor)) def get_dayu_color(self): """ diff --git a/dayu_widgets/push_button.py b/dayu_widgets/push_button.py index 32432018..c8dc8594 100644 --- a/dayu_widgets/push_button.py +++ b/dayu_widgets/push_button.py @@ -86,8 +86,7 @@ def set_dayu_type(self, value): self._dayu_type = value else: raise ValueError( - "Input argument 'value' should be one of " - "default/primary/success/warning/danger string." + "Input argument 'value' should be one of " "default/primary/success/warning/danger string." ) self.style().polish(self) diff --git a/dayu_widgets/sequence_file.py b/dayu_widgets/sequence_file.py index 82aa68fb..83a6522e 100644 --- a/dayu_widgets/sequence_file.py +++ b/dayu_widgets/sequence_file.py @@ -47,9 +47,7 @@ def __init__(self, size=None, parent=None): self._file_label.set_dayu_size(size) self._file_label.setReadOnly(True) self._is_sequence_check_box = MCheckBox(self.tr("Sequence")) - self._is_sequence_check_box.toggled.connect( - functools.partial(self.setProperty, "sequence") - ) + self._is_sequence_check_box.toggled.connect(functools.partial(self.setProperty, "sequence")) self._is_sequence_check_box.toggled.connect(self.sig_is_sequence_changed) self._info_label = MLabel().secondary() @@ -105,19 +103,11 @@ def _update_info(self): "Range: {start}-{end}".format( ext=self.sequence_obj.ext, count=len(self.sequence_obj.frames), - start=self.sequence_obj.frames[0] - if self.sequence_obj.frames - else "/", - end=self.sequence_obj.frames[-1] - if self.sequence_obj.frames - else "/", + start=self.sequence_obj.frames[0] if self.sequence_obj.frames else "/", + end=self.sequence_obj.frames[-1] if self.sequence_obj.frames else "/", ) ) - error_info = ( - "Missing: {}".format(self.sequence_obj.missing) - if self.sequence_obj.missing - else "" - ) + error_info = "Missing: {}".format(self.sequence_obj.missing) if self.sequence_obj.missing else "" self._error_label.setText(error_info) self._error_label.setToolTip(error_info) self._info_label.setVisible(self.property("sequence")) diff --git a/dayu_widgets/splitter.py b/dayu_widgets/splitter.py index 55ca4b6f..f88dd066 100644 --- a/dayu_widgets/splitter.py +++ b/dayu_widgets/splitter.py @@ -78,9 +78,7 @@ def createHandle(self): handle = QtWidgets.QSplitterHandle(orient, self) # NOTES: double click average size - handle.mouseDoubleClickEvent = lambda e: self.setSizes( - [1 for i in range(self.count())] - ) + handle.mouseDoubleClickEvent = lambda e: self.setSizes([1 for i in range(self.count())]) layout = QtWidgets.QVBoxLayout() if is_horizontal else QtWidgets.QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) diff --git a/dayu_widgets/text_edit.py b/dayu_widgets/text_edit.py index 437804e4..81b15e06 100644 --- a/dayu_widgets/text_edit.py +++ b/dayu_widgets/text_edit.py @@ -28,9 +28,7 @@ def __init__(self, parent=None): self._size_grip = MSizeGrip(self) layout = QtWidgets.QGridLayout() layout.setContentsMargins(0, 0, 0, 0) - layout.addWidget( - self._size_grip, 0, 0, QtCore.Qt.AlignBottom | QtCore.Qt.AlignRight - ) + layout.addWidget(self._size_grip, 0, 0, QtCore.Qt.AlignBottom | QtCore.Qt.AlignRight) self.setLayout(layout) self._size_grip.setVisible(False) diff --git a/dayu_widgets/toast.py b/dayu_widgets/toast.py index 121c62e8..11b1cb45 100644 --- a/dayu_widgets/toast.py +++ b/dayu_widgets/toast.py @@ -57,9 +57,7 @@ def __init__(self, text, duration=None, dayu_type=None, parent=None): _icon_lay.addStretch() if dayu_type == MToast.LoadingType: - _icon_lay.addWidget( - MLoading(size=dayu_theme.huge, color=dayu_theme.text_color_inverse) - ) + _icon_lay.addWidget(MLoading(size=dayu_theme.huge, color=dayu_theme.text_color_inverse)) else: _icon_label = MAvatar() _icon_label.set_dayu_size(dayu_theme.toast_icon_size) @@ -90,9 +88,7 @@ def __init__(self, text, duration=None, dayu_type=None, parent=None): _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 - ) + _close_timer.setInterval((duration or self.default_config.get("duration")) * 1000) self.has_played = False if dayu_type != MToast.LoadingType: @@ -127,11 +123,7 @@ def _fade_int(self): def _get_center_position(self, parent): parent_geo = parent.geometry() - pos = ( - parent_geo.topLeft() - if parent.parent() is None - else parent.mapToGlobal(parent_geo.topLeft()) - ) + pos = parent_geo.topLeft() if parent.parent() is None else parent.mapToGlobal(parent_geo.topLeft()) offset = 0 for child in parent.children(): if isinstance(child, MToast) and child.isVisible(): diff --git a/dayu_widgets/utils.py b/dayu_widgets/utils.py index 0134e584..81a25df4 100644 --- a/dayu_widgets/utils.py +++ b/dayu_widgets/utils.py @@ -39,9 +39,7 @@ from dayu_widgets.qt import get_scale_factor -ItemViewMenuEvent = collections.namedtuple( - "ItemViewMenuEvent", ["view", "selection", "extra"] -) +ItemViewMenuEvent = collections.namedtuple("ItemViewMenuEvent", ["view", "selection", "extra"]) def get_static_file(path): @@ -53,10 +51,7 @@ def get_static_file(path): :return: if input file found, return the full path, else return None """ if not isinstance(path, six.string_types): - raise TypeError( - "Input argument 'path' should be six.string_types type, " - "but get {}".format(type(path)) - ) + raise TypeError("Input argument 'path' should be six.string_types type, " "but get {}".format(type(path))) full_path = next( ( os.path.join(prefix, path) @@ -78,15 +73,9 @@ def from_list_to_nested_dict(input_arg, sep="/"): :return: a list of nested dict """ if not isinstance(input_arg, (list, tuple, set)): - raise TypeError( - "Input argument 'input' should be list or tuple or set, " - "but get {}".format(type(input_arg)) - ) + raise TypeError("Input argument 'input' should be list or tuple or set, " "but get {}".format(type(input_arg))) if not isinstance(sep, six.string_types): - raise TypeError( - "Input argument 'sep' should be six.string_types, " - "but get {}".format(type(sep)) - ) + raise TypeError("Input argument 'sep' should be six.string_types, " "but get {}".format(type(sep))) result = [] for item in input_arg: @@ -113,9 +102,7 @@ def fade_color(color, alpha): :return: qss/css color format rgba(r, g, b, a) """ q_color = QtGui.QColor(color) - return "rgba({}, {}, {}, {})".format( - q_color.red(), q_color.green(), q_color.blue(), alpha - ) + return "rgba({}, {}, {}, {})".format(q_color.red(), q_color.green(), q_color.blue(), alpha) def generate_color(primary_color, index): @@ -170,11 +157,7 @@ def _get_value(color, i, is_light): return max((v_comp * 100 - brightness_step2 * i) / 100, 0.0) light = index <= 6 - hsv_color = ( - QtGui.QColor(primary_color) - if isinstance(primary_color, six.string_types) - else primary_color - ) + hsv_color = QtGui.QColor(primary_color) if isinstance(primary_color, six.string_types) else primary_color index = light_color_count + 1 - index if light else index - light_color_count - 1 return QtGui.QColor.fromHsvF( _get_hue(hsv_color, index, light), @@ -387,14 +370,9 @@ def overflow_format(num, overflow): When this integer is large than given overflow, return "overflow+" """ if not isinstance(num, int): - raise ValueError( - "Input argument 'num' should be int type, " "but get {}".format(type(num)) - ) + raise ValueError("Input argument 'num' should be int type, " "but get {}".format(type(num))) if not isinstance(overflow, int): - raise ValueError( - "Input argument 'overflow' should be int type, " - "but get {}".format(type(overflow)) - ) + raise ValueError("Input argument 'overflow' should be int type, " "but get {}".format(type(overflow))) return str(num) if num <= overflow else "{}+".format(overflow) @@ -450,9 +428,7 @@ def read_settings(organization, app_name): result_dict = {key: settings.value(key) for key in settings.childKeys()} for grp_name in settings.childGroups(): settings.beginGroup(grp_name) - result_dict.update( - {grp_name + "/" + key: settings.value(key) for key in settings.childKeys()} - ) + result_dict.update({grp_name + "/" + key: settings.value(key) for key in settings.childKeys()}) settings.endGroup() return result_dict @@ -524,9 +500,7 @@ def get_fit_geometry(): (screen.availableGeometry() for screen in QtWidgets.QApplication.screens()), None, ) - return QtCore.QRect( - geo.width() / 4, geo.height() / 4, geo.width() / 2, geo.height() / 2 - ) + return QtCore.QRect(geo.width() / 4, geo.height() / 4, geo.width() / 2, geo.height() / 2) def convert_to_round_pixmap(orig_pix): @@ -536,9 +510,7 @@ def convert_to_round_pixmap(orig_pix): pix_map.fill(QtCore.Qt.transparent) painter = QtGui.QPainter(pix_map) - painter.setRenderHints( - QtGui.QPainter.Antialiasing | QtGui.QPainter.SmoothPixmapTransform - ) + painter.setRenderHints(QtGui.QPainter.Antialiasing | QtGui.QPainter.SmoothPixmapTransform) path = QtGui.QPainterPath() path.addEllipse(0, 0, w, w) @@ -547,9 +519,7 @@ def convert_to_round_pixmap(orig_pix): return pix_map -def generate_text_pixmap( - width, height, text, alignment=QtCore.Qt.AlignCenter, bg_color=None -): +def generate_text_pixmap(width, height, text, alignment=QtCore.Qt.AlignCenter, bg_color=None): # Import local modules from dayu_widgets import dayu_theme diff --git a/pyproject.toml b/pyproject.toml index ea351d5d..7921a39c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,7 +55,7 @@ requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" [tool.black] -line-length = 88 +line-length = 120 target_version = ['py36'] include = '\.pyi?$' exclude = '''