Skip to content

Commit

Permalink
style: limit max line width to 80
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaokang2022 committed Oct 22, 2024
1 parent e61212f commit b8ba73d
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 245 deletions.
2 changes: 1 addition & 1 deletion tkintertools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
If you ❤️ this package, leave your ⭐ to me, thanks you so much! 🎉
![](https://img.shields.io/github/stars/Xiaokang2022/tkintertools?label=Stars&color=gold&logo=github&style=flat)
![](https://img.shields.io/github/stars/Xiaokang2022/tkintertools)
"""

# MIT License
Expand Down
10 changes: 6 additions & 4 deletions tkintertools/standard/_auxiliary.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,14 @@ def __init__(
else:
shapes.HalfRoundedRectangle(self, name=".out", ignore=ignore)
shapes.HalfRoundedRectangle(
self, name=".in", size=(self.size[0], self.size[1]-3), ignore=ignore)
self, name=".in", size=(self.size[0], self.size[1]-3),
ignore=ignore)
if image is not None:
images.StillImage(self, image=image)
texts.SingleLineText(self, family=family, fontsize=fontsize, weight=weight,
slant=slant, underline=underline, overstrike=overstrike,
align=align, limit=limit, show=show, placeholder=placeholder)
texts.SingleLineText(
self, family=family, fontsize=fontsize, weight=weight, slant=slant,
underline=underline, overstrike=overstrike, align=align,
limit=limit, show=show, placeholder=placeholder)
features.InputBoxFeature(self)

def get(self) -> str:
Expand Down
60 changes: 30 additions & 30 deletions tkintertools/standard/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"InputBoxFeature",
"SliderFeature",
"SpinBoxFeature",
"OptionButtonFeature",
]

import tkinter
Expand Down Expand Up @@ -168,17 +167,21 @@ def _move_none(self, event: tkinter.Event) -> bool:
if self.widget.state != "disabled":
self.widget._shapes[-1].coords(
(self.widget.size[0]/3, self.widget.size[0]/3),
(self.widget._shapes[-1].position[0]-self.widget.size[0]/60,
self.widget._shapes[-1].position[1]-self.widget.size[0]/60))
(self.widget._shapes[-1].position[0]
- self.widget.size[0]/60,
self.widget._shapes[-1].position[1]
- self.widget.size[0]/60))
self.widget.update(
f"hover-{'on' if self.widget.get() else 'off'}")
else:
if not self.widget.state.startswith("normal"):
if self.widget.state != "disabled":
self.widget._shapes[-1].coords(
(self.widget.size[0]*3/10, self.widget.size[0]*3/10),
(self.widget._shapes[-1].position[0]+self.widget.size[0]/60,
self.widget._shapes[-1].position[1]+self.widget.size[0]/60))
(self.widget._shapes[-1].position[0]
+ self.widget.size[0]/60,
self.widget._shapes[-1].position[1]
+ self.widget.size[0]/60))
self.widget.update(
f"normal-{'on' if self.widget.get() else 'off'}")
return flag
Expand Down Expand Up @@ -398,23 +401,28 @@ def _move_none(self, event: tkinter.Event) -> bool:
if isinstance(self.widget._shapes[-1], shapes.Oval):
self.widget._shapes[-1].coords(
(self.widget.size[1]*2/3, self.widget.size[1]*2/3),
(self.widget._shapes[-2].position[0]+self.widget.size[1]/6,
self.widget._shapes[-2].position[1]+self.widget.size[1]/6))
(self.widget._shapes[-2].position[0]
+ self.widget.size[1]/6,
self.widget._shapes[-2].position[1]
+ self.widget.size[1]/6))
else:
if self.widget.state == "hover":
self.widget.update("normal")
if isinstance(self.widget._shapes[-1], shapes.Oval):
self.widget._shapes[-1].coords(
(self.widget.size[1]/2, self.widget.size[1]/2),
(self.widget._shapes[-2].position[0]+self.widget.size[1]/4,
self.widget._shapes[-2].position[1]+self.widget.size[1]/4))
(self.widget._shapes[-2].position[0]
+ self.widget.size[1]/4,
self.widget._shapes[-2].position[1]
+ self.widget.size[1]/4))
return flag

def _click_left(self, event: tkinter.Event) -> bool:
if self.widget.state == "hover":
self._temp_position = event.x, event.y
self.widget.update("active")
elif self.widget.state != "disabled" and self.widget._shapes[0].detect(event.x, event.y):
elif (self.widget.state != "disabled" and
self.widget._shapes[0].detect(event.x, event.y)):
self._temp_position = event.x, event.y
self.widget.update("active")
temp_value = self.widget.value
Expand All @@ -423,24 +431,27 @@ def _click_left(self, event: tkinter.Event) -> bool:
(self.widget.size[1]*2/3, self.widget.size[1]*2/3),
(self.widget._shapes[-2].position[0]+self.widget.size[1]/6,
self.widget._shapes[-2].position[1]+self.widget.size[1]/6))
next_value = (event.x-self.widget.position[0]-self.widget.size[1]/2) / (
self.widget.size[0]-self.widget.size[1])
next_value = (
(event.x-self.widget.position[0]-self.widget.size[1]/2)
/ (self.widget.size[0]-self.widget.size[1]))
else:
next_value = (event.x-self.widget.position[0]-self.widget.size[1]/5) / (
self.widget.size[0]-self.widget.size[1]*2/5)
next_value = (
(event.x-self.widget.position[0]-self.widget.size[1]/5)
/ (self.widget.size[0]-self.widget.size[1]*2/5))
delta = next_value - temp_value
animations.Animation(
150, controllers.smooth,
callback=lambda k: self.widget.set(temp_value + delta*k, callback=True), fps=60).start()
callback=lambda k: self.widget.set(
temp_value + delta*k, callback=True), fps=60).start()

def _move_left(self, event: tkinter.Event) -> bool:
if self._temp_position is not None:
if isinstance(self.widget._shapes[-1], shapes.Oval):
delta = (
event.x-self._temp_position[0]) / (self.widget.size[0]-self.widget.size[1])
delta = ((event.x-self._temp_position[0])
/ (self.widget.size[0]-self.widget.size[1]))
else:
delta = (
event.x-self._temp_position[0]) / (self.widget.size[0]-self.widget.size[1]*2/5)
delta = ((event.x-self._temp_position[0])
/ (self.widget.size[0]-self.widget.size[1]*2/5))
self._temp_position = event.x, event.y
self.widget.set(self.widget.value + delta, callback=True)

Expand Down Expand Up @@ -472,14 +483,3 @@ def _wheel(self, event: tkinter.Event) -> bool:
if flag := self.widget._widgets[0].state == "active":
self._command(event.delta > 0)
return flag


class OptionButtonFeature(virtual.Feature):
"""Feature of OptionButton"""

def _click_left(self, event: tkinter.Event) -> bool:
if not (flag := self.widget.detect(event.x, event.y)):
if len(self.widget._widgets) == 3:
if not self.widget._widgets[-1].detect(event.x, event.y):
self.widget._widgets[-1].destroy()
return flag
109 changes: 70 additions & 39 deletions tkintertools/standard/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(
relative_position: tuple[int, int] = (0, 0),
size: tuple[int, int] | None = None,
*,
points: list[tuple[float, float]] = [],
points: list[tuple[float, float]] | None = None,
name: str | None = None,
animation: bool = True,
styles: dict[str | int, dict[str | int, dict[str, str]]] | None = None,
Expand All @@ -46,9 +46,10 @@ def __init__(
* `styles`: style dict of component
* `kwargs`: extra parameters for CanvasItem
"""
self.points = points
virtual.Shape.__init__(self, widget, relative_position, size,
name=name, styles=styles, animation=animation, **kwargs)
self.points = [] if points is None else points
virtual.Shape.__init__(
self, widget, relative_position, size,
name=name, styles=styles, animation=animation, **kwargs)

@typing_extensions.override
def display(self) -> None:
Expand All @@ -75,7 +76,8 @@ class Rectangle(virtual.Shape):
@typing_extensions.override
def display(self) -> None:
self.items = [self.widget.master.create_rectangle(
0, 0, 0, 0, tags=("fill", "fill", "outline", "outline"), **self.kwargs)]
0, 0, 0, 0, tags=("fill", "fill", "outline", "outline"),
**self.kwargs)]

@typing_extensions.override
def coords(
Expand All @@ -94,7 +96,8 @@ class Oval(virtual.Shape):
@typing_extensions.override
def display(self) -> None:
self.items = [self.widget.master.create_oval(
0, 0, 0, 0, tags=("fill", "fill", "outline", "outline"), **self.kwargs)]
0, 0, 0, 0, tags=("fill", "fill", "outline", "outline"),
**self.kwargs)]

@typing_extensions.override
def coords(
Expand Down Expand Up @@ -141,13 +144,15 @@ def __init__(
"""
self.side = side
self.angle = angle
virtual.Shape.__init__(self, widget, relative_position, size,
name=name, styles=styles, animation=animation, **kwargs)
virtual.Shape.__init__(
self, widget, relative_position, size,
name=name, styles=styles, animation=animation, **kwargs)

@typing_extensions.override
def display(self) -> None:
self.items = [self.widget.master.create_polygon(
0, 0, 0, 0, tags=("fill", "fill", "outline", "outline"), **self.kwargs)]
0, 0, 0, 0, tags=("fill", "fill", "outline", "outline"),
**self.kwargs)]

@typing_extensions.override
def coords(
Expand Down Expand Up @@ -197,8 +202,9 @@ def __init__(
* `kwargs`: extra parameters for CanvasItem
"""
self.radius = radius
virtual.Shape.__init__(self, widget, relative_position, size,
name=name, styles=styles, animation=animation, **kwargs)
virtual.Shape.__init__(
self, widget, relative_position, size,
name=name, styles=styles, animation=animation, **kwargs)

@typing_extensions.override
def display(self) -> None:
Expand All @@ -216,21 +222,29 @@ def display(self) -> None:
self.widget.master.create_line( # e
0, 0, 0, 0, tags=("fill", "outline"), **self.kwargs),
self.widget.master.create_arc( # nw
0, 0, 0, 0, outline="", start=90, tags=("fill", "fill"), **self.kwargs),
0, 0, 0, 0, outline="", start=90,
tags=("fill", "fill"), **self.kwargs),
self.widget.master.create_arc( # sw
0, 0, 0, 0, outline="", start=180, tags=("fill", "fill"), **self.kwargs),
0, 0, 0, 0, outline="", start=180,
tags=("fill", "fill"), **self.kwargs),
self.widget.master.create_arc( # ne
0, 0, 0, 0, outline="", start=0, tags=("fill", "fill"), **self.kwargs),
0, 0, 0, 0, outline="", start=0,
tags=("fill", "fill"), **self.kwargs),
self.widget.master.create_arc( # se
0, 0, 0, 0, outline="", start=-90, tags=("fill", "fill"), **self.kwargs),
0, 0, 0, 0, outline="", start=-90,
tags=("fill", "fill"), **self.kwargs),
self.widget.master.create_arc( # nw
0, 0, 0, 0, style="arc", start=90, tags=("outline", "outline"), **self.kwargs),
0, 0, 0, 0, style="arc", start=90,
tags=("outline", "outline"), **self.kwargs),
self.widget.master.create_arc( # sw
0, 0, 0, 0, style="arc", start=180, tags=("outline", "outline"), **self.kwargs),
0, 0, 0, 0, style="arc", start=180,
tags=("outline", "outline"), **self.kwargs),
self.widget.master.create_arc( # ne
0, 0, 0, 0, style="arc", start=0, tags=("outline", "outline"), **self.kwargs),
0, 0, 0, 0, style="arc", start=0,
tags=("outline", "outline"), **self.kwargs),
self.widget.master.create_arc( # se
0, 0, 0, 0, style="arc", start=-90, tags=("outline", "outline"), **self.kwargs),
0, 0, 0, 0, style="arc", start=-90,
tags=("outline", "outline"), **self.kwargs),
]

@typing_extensions.override
Expand Down Expand Up @@ -297,8 +311,9 @@ def __init__(
"""
self.radius = radius
self.ignore = ignore
virtual.Shape.__init__(self, widget, relative_position, size,
name=name, styles=styles, animation=animation, **kwargs)
virtual.Shape.__init__(
self, widget, relative_position, size,
name=name, styles=styles, animation=animation, **kwargs)

@typing_extensions.override
def display(self) -> None:
Expand All @@ -318,22 +333,30 @@ def display(self) -> None:
]
self.items += [
self.widget.master.create_arc( # ne
0, 0, 0, 0, outline="", start=0, tags=("fill", "fill"), **self.kwargs),
0, 0, 0, 0, outline="", start=0,
tags=("fill", "fill"), **self.kwargs),
self.widget.master.create_arc( # se
0, 0, 0, 0, outline="", start=-90, tags=("fill", "fill"), **self.kwargs),
0, 0, 0, 0, outline="", start=-90,
tags=("fill", "fill"), **self.kwargs),
self.widget.master.create_arc( # ne
0, 0, 0, 0, style="arc", start=0, tags=("outline", "outline"), **self.kwargs),
0, 0, 0, 0, style="arc", start=0,
tags=("outline", "outline"), **self.kwargs),
self.widget.master.create_arc( # se
0, 0, 0, 0, style="arc", start=-90, tags=("outline", "outline"), **self.kwargs),
0, 0, 0, 0, style="arc", start=-90,
tags=("outline", "outline"), **self.kwargs),
] if self.ignore == "left" else [
self.widget.master.create_arc( # nw
0, 0, 0, 0, outline="", start=90, tags=("fill", "fill"), **self.kwargs),
0, 0, 0, 0, outline="", start=90,
tags=("fill", "fill"), **self.kwargs),
self.widget.master.create_arc( # sw
0, 0, 0, 0, outline="", start=180, tags=("fill", "fill"), **self.kwargs),
0, 0, 0, 0, outline="", start=180,
tags=("fill", "fill"), **self.kwargs),
self.widget.master.create_arc( # nw
0, 0, 0, 0, style="arc", start=90, tags=("outline", "outline"), **self.kwargs),
0, 0, 0, 0, style="arc", start=90,
tags=("outline", "outline"), **self.kwargs),
self.widget.master.create_arc( # sw
0, 0, 0, 0, style="arc", start=180, tags=("outline", "outline"), **self.kwargs),
0, 0, 0, 0, style="arc", start=180,
tags=("outline", "outline"), **self.kwargs),
]

@typing_extensions.override
Expand Down Expand Up @@ -384,15 +407,19 @@ class SemicircularRectangle(virtual.Shape):
def display(self) -> None:
self.items = [
self.widget.master.create_arc(
0, 0, 0, 0, outline="", extent=180, start=90, tags=("fill", "fill"), **self.kwargs),
0, 0, 0, 0, outline="", extent=180, start=90,
tags=("fill", "fill"), **self.kwargs),
self.widget.master.create_arc(
0, 0, 0, 0, outline="", extent=180, start=-90, tags=("fill", "fill"), **self.kwargs),
0, 0, 0, 0, outline="", extent=180, start=-90,
tags=("fill", "fill"), **self.kwargs),
self.widget.master.create_rectangle(
0, 0, 0, 0, outline="", tags=("fill", "fill"), **self.kwargs),
self.widget.master.create_arc(
0, 0, 0, 0, style="arc", extent=180, start=90, tags=("outline", "outline"), **self.kwargs),
0, 0, 0, 0, style="arc", extent=180, start=90,
tags=("outline", "outline"), **self.kwargs),
self.widget.master.create_arc(
0, 0, 0, 0, style="arc", extent=180, start=-90, tags=("outline", "outline"), **self.kwargs),
0, 0, 0, 0, style="arc", extent=180, start=-90,
tags=("outline", "outline"), **self.kwargs),
self.widget.master.create_line(
0, 0, 0, 0, tags=("fill", "outline"), **self.kwargs),
self.widget.master.create_line(
Expand Down Expand Up @@ -469,13 +496,15 @@ def __init__(
warnings.warn("Parameters are not suitable", UserWarning, 5)
if math.isclose(abs(self.ratio[0] - self.ratio[1]), 1):
warnings.warn("Parameters are not suitable", UserWarning, 5)
virtual.Shape.__init__(self, widget, relative_position, size,
name=name, styles=styles, animation=animation, **kwargs)
virtual.Shape.__init__(
self, widget, relative_position, size,
name=name, styles=styles, animation=animation, **kwargs)

@typing_extensions.override
def display(self) -> None:
self.items = [self.widget.master.create_polygon(
0, 0, 0, 0, tags=("fill", "fill", "outline", "outline"), **self.kwargs)]
0, 0, 0, 0, tags=("fill", "fill", "outline", "outline"),
**self.kwargs)]

@typing_extensions.override
def coords(
Expand Down Expand Up @@ -537,13 +566,15 @@ def __init__(
self.theta = theta
if not abs(theta) <= math.pi/3:
warnings.warn("Parameters are not suitable", UserWarning, 5)
virtual.Shape.__init__(self, widget, relative_position, size,
name=name, styles=styles, animation=animation, **kwargs)
virtual.Shape.__init__(
self, widget, relative_position, size,
name=name, styles=styles, animation=animation, **kwargs)

@typing_extensions.override
def display(self) -> None:
self.items = [self.widget.master.create_polygon(
0, 0, 0, 0, tags=("fill", "fill", "outline", "outline"), **self.kwargs)]
0, 0, 0, 0, tags=("fill", "fill", "outline", "outline"),
**self.kwargs)]

@typing_extensions.override
def coords(
Expand Down
Loading

0 comments on commit b8ba73d

Please sign in to comment.