-
-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a new widget and a new feature #66
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -970,6 +970,57 @@ | |
return self.texts[0].set(text) | ||
|
||
|
||
class IconOnlyButton(IconButton): | ||
"""A button with nothing but an icon""" | ||
|
||
def __init__( | ||
self, | ||
master: containers.Canvas | virtual.Widget, | ||
position: tuple[int, int], | ||
size: tuple[int, int] | None = None, | ||
*, | ||
command: collections.abc.Callable | None = None, | ||
image: enhanced.PhotoImage | None = None, | ||
borderless=True, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 此处缺少类型提示,请完善。 |
||
anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw", | ||
capture_events: bool | None = None, | ||
gradient_animation: bool | None = None, | ||
auto_update: bool | None = None, | ||
style: type[virtual.Style] | None = None, | ||
) -> None: | ||
""" | ||
* `master`: parent canvas | ||
* `position`: position of the widget | ||
* `size`: size of the widget | ||
* `command`: a function that is triggered when the button is pressed | ||
* `image`: image of the widget | ||
* `anchor`: anchor of the widget | ||
* `capture_events`: wether detect another widget under the widget | ||
* `gradient_animation`: wether enable gradient_animation | ||
* `auto_update`: whether the theme manager update it automatically | ||
* `style`: style of the widget | ||
""" | ||
if size is None: | ||
size = image.width(), image.height() | ||
virtual.Widget.__init__( | ||
self, master, position, size, anchor=anchor, | ||
capture_events=capture_events, gradient_animation=gradient_animation, | ||
auto_update=auto_update, style=style) | ||
if style is None: | ||
self.style = styles.TextStyle(self) if borderless else styles.IconButtonStyle(self) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 此处应该不需要 在其超类 |
||
if image is not None: | ||
images.StillImage(self, ((size[1]-size[0]) / 2, 0), image=image) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 此处以及上面的参数部分应该改一改,参数 |
||
self.feature = features.IconOnlyFeature(self, command=command) | ||
|
||
def get(self) -> Exception: | ||
"""This class has nothing to get""" | ||
raise AttributeError() | ||
|
||
def set(self, thing: None) -> Exception: | ||
"""This class has nothing to set""" | ||
raise AttributeError() | ||
|
||
|
||
class Slider(virtual.Widget): | ||
"""A slider for visually resizing values""" | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docstring 里面的类名不要拆开来写。