Skip to content
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

Implement str and repr magic methods for Events #3601

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/flet/lib/src/controls/container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,10 @@ class ContainerControl extends StatelessWidget with FletStoreMixin {
: null,
child: child);

if ((onClick || onLongPress || onHover || url != "") && !disabled) {
if ((onClick || onLongPress || onHover || onTapDown || url != "") &&
FeodorFitsner marked this conversation as resolved.
Show resolved Hide resolved
!disabled) {
result = MouseRegion(
cursor: onClick || url != ""
cursor: onClick || onTapDown || url != ""
FeodorFitsner marked this conversation as resolved.
Show resolved Hide resolved
? SystemMouseCursors.click
: MouseCursor.defer,
onEnter: onHover
Expand Down
12 changes: 12 additions & 0 deletions sdk/python/packages/flet-core/src/flet_core/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,15 @@ def __init__(self, target: str, name: str, data: str):
self.target: str = target
self.name: str = name
self.data: str = data

def __repr__(self):
attrs = ", ".join(f"{k}={v!r}" for k, v in self.__dict__.items())
return f"{self.__class__.__name__}({attrs})"

def __str__(self):
attrs = ", ".join(
f"{k}={v!r}"
for k, v in self.__dict__.items()
if k not in ["control", "page", "target"] # ignore these keys
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider making ignored keys a class-level constant.

Defining the ignored keys as a class-level constant (e.g., IGNORED_KEYS = ["control", "page", "target"]) can improve maintainability and readability.

Suggested change
if k not in ["control", "page", "target"] # ignore these keys
class YourClassName:
IGNORED_KEYS = ["control", "page", "target"]
def your_method(self):
attrs = ", ".join(
f"{k}={v!r}"
for k, v in self.__dict__.items()
if k not in self.IGNORED_KEYS
)
return f"{self.__class__.__name__}({attrs})"

)
return f"{self.__class__.__name__}({attrs})"