Skip to content

Commit

Permalink
style: Improve code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaokang2022 committed Jan 10, 2025
1 parent 54ba520 commit f7ecdd1
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 18 deletions.
5 changes: 4 additions & 1 deletion tkintertools/color/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ def str_to_rgb(value: str, /) -> tuple[int, int, int]:
* `value`: a color name or a hexadecimal code
"""
return hex_to_rgb(fix_hex_length(value)) if value.startswith("#") else name_to_rgb(value)
if value.startswith("#"):
return hex_to_rgb(fix_hex_length(value))

return name_to_rgb(value)


# Alias
Expand Down
23 changes: 15 additions & 8 deletions tkintertools/core/virtual.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ def forget(
*,
gradient_animation: bool = False,
) -> None:
"""Let the element to disappear.
"""Let the element to forget.
* `value`: whether to disappear
* `value`: whether to forget
* `gradient_animation`: whether use gradient animation
"""
self.visible = not value
Expand Down Expand Up @@ -397,7 +397,8 @@ def zoom(
* `zoom_position`: whether or not to zoom the location of the text
* `zoom_size`: whether or not to zoom the size of the text
"""
Element.zoom(self, ratios, zoom_position=zoom_position, zoom_size=zoom_size)
Element.zoom(
self, ratios, zoom_position=zoom_position, zoom_size=zoom_size)

self.font.config(size=round(self._initial_fontsize*math.sqrt(
self.widget.master.ratios[0]*self.widget.master.ratios[1])))
Expand Down Expand Up @@ -453,7 +454,8 @@ def zoom(
* `zoom_position`: whether or not to zoom the location of the image
* `zoom_size`: whether or not to zoom the size of the image
"""
Element.zoom(self, ratios, zoom_position=zoom_position, zoom_size=zoom_size)
Element.zoom(
self, ratios, zoom_position=zoom_position, zoom_size=zoom_size)

if self.initail_image is None:
raise RuntimeError("Image is empty.")
Expand Down Expand Up @@ -568,7 +570,10 @@ def reset(
element.update()

@staticmethod
def _wrap_arg(arg: tuple[str | None, ...] | str, /) -> tuple[str | None, ...]:
def _wrap_arg(
arg: tuple[str | None, ...] | str,
/,
) -> tuple[str | None, ...]:
"""Wrap the argument to a tuple.
* `arg`: argument
Expand Down Expand Up @@ -926,7 +931,7 @@ def disable(self, value: bool = True, /) -> None:
widget.disable(value)

def forget(self, value: bool = True, /) -> None:
"""Let all elements of the widget to disappear.
"""Let all elements of the widget to forget.
* `value`: whether to forget the widget
"""
Expand Down Expand Up @@ -1013,7 +1018,9 @@ def zoom(
self.position = self.position[0]*ratios[0], self.position[1]*ratios[1]

for widget in self.widgets:
widget.zoom(ratios, zoom_position=zoom_position, zoom_size=zoom_size)
widget.zoom(
ratios, zoom_position=zoom_position, zoom_size=zoom_size)

for element in self.elements:
element.zoom(ratios, zoom_position=zoom_position, zoom_size=zoom_size)
element.zoom(
ratios, zoom_position=zoom_position, zoom_size=zoom_size)
8 changes: 4 additions & 4 deletions tkintertools/standard/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,10 @@ def _button_release_1(self, event: tkinter.Event) -> bool:
if self.widget.state.startswith("active"):
if self.widget.get():
return flag
else:
for radio_box in tuple(self.widget.groups):
if radio_box.get():
radio_box.set(False, callback=True)

for radio_box in tuple(self.widget.groups):
if radio_box.get():
radio_box.set(False, callback=True)

boolean = not self.widget.get()
self.widget.set(boolean)
Expand Down
2 changes: 1 addition & 1 deletion tkintertools/standard/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def set(self, value: bool, *, callback: bool = False) -> None:
if callback and self.feature.command is not None:
self.feature.command(value)
if self.get() == bool(value):
return None
return
self.update(f"{self.state.split('-', maxsplit=1)[0]}-{'on' if value else 'off'}")


Expand Down
4 changes: 3 additions & 1 deletion tkintertools/theme/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@
`"light"` is the light color, and `"dark"` is the dark color."""


def set_color_mode(mode: typing.Literal["system", "dark", "light"] = "system") -> None:
def set_color_mode(
mode: typing.Literal["system", "dark", "light"] = "system",
) -> None:
"""Set the color mode of the program
* `mode`: it can be `"light"`, `"dark"`, and `"system"`
Expand Down
9 changes: 6 additions & 3 deletions tkintertools/toolbox/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ def embed_window(
* `parent`: parent widget, `None` indicates that the parent widget is the screen
* `focus`: whether direct input focus to this window
"""
ctypes.windll.user32.SetParent(get_parent(window), parent.winfo_id() if parent else None)
ctypes.windll.user32.SetParent(
get_parent(window), parent.winfo_id() if parent else None)

if not focus and window.master is not None:
window.master.focus_set()
Expand Down Expand Up @@ -133,7 +134,8 @@ def load_font(
add_font_resource_ex = ctypes.windll.gdi32.AddFontResourceExA

flags = (0x10 if private else 0) | (0x20 if not enumerable else 0)
num_fonts_added = add_font_resource_ex(ctypes.byref(path_buffer), flags, 0)
num_fonts_added = add_font_resource_ex(
ctypes.byref(path_buffer), flags, 0)

return bool(min(num_fonts_added, 1))

Expand All @@ -148,7 +150,8 @@ def load_font(
shutil.copy(font_path, linux_fonts_dir)

if private:
atexit.register(os.remove, linux_fonts_dir + font_path.rsplit("/", 1)[-1])
atexit.register(
os.remove, linux_fonts_dir + font_path.rsplit("/", 1)[-1])

return True
except Exception as exc: # pylint: disable=W0718
Expand Down

0 comments on commit f7ecdd1

Please sign in to comment.