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

CHORE: Move page.window_* and page.browser_context_menu_* properties to Window and BrowserContextMenu classes #3463

Merged
merged 16 commits into from
Jun 17, 2024

Conversation

ndonkoHenri
Copy link
Collaborator

@ndonkoHenri ndonkoHenri commented Jun 13, 2024

Description

  • Moved page.window_* and page.browser_context_menu_* properties to Window and BrowserContextMenu classes respectively
  • Deprecated page.window_* props in favor of page.window.*
  • Exposed some more properties of the window_manager packages (shadow, alignment, wait_until_ready_to_show, always_on_bottom, icon, badge_label)

Fixes #3414

Test Code

import flet as ft


def main(page: ft.Page):
    page.window_always_on_top = True  # deprecated
    page.window.title = "Hello, World!"
    page.window.on_event = lambda e: print(e.type)
    page.on_resize = lambda e: print(e.width, e.height)  # deprecated
    page.window.shadow = True  # new
    page.window.badge_label = "2"  # new (macos only)
    page.window.alignment = ft.alignment.center_right  # new
    page.window.always_on_bottom = False  # new
    page.window.wait_until_ready_to_show = True  # new

    page.add(
        ft.Text("Hello, World!", size=30),
    )


ft.app(target=main)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • I signed the CLA.
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • New and existing tests pass locally with my changes
  • I have made corresponding changes to the documentation (if applicable)

Screenshots (if applicable):

Additional details

page.window.icon was added but not tested since it is windows-only (which I don't have)

Copy link
Contributor

sourcery-ai bot commented Jun 13, 2024

Reviewer's Guide by Sourcery

This pull request refactors the page class by moving page.window_* and page.browser_context_menu_* properties to new Window and BrowserContextMenu classes respectively. It also introduces deprecation warnings for the old page.window_* properties, advising the use of the new page.window.* properties.

File-Level Changes

Files Changes
sdk/python/packages/flet-core/src/flet_core/page.py
sdk/python/packages/flet-core/src/flet_core/types.py
sdk/python/packages/flet-core/src/flet_core/utils/deprecated.py
Refactored page class to use new Window and BrowserContextMenu classes, added deprecation warnings, and introduced WindowEventType enum.
packages/flet/lib/src/controls/page.dart
packages/flet/lib/src/utils/desktop.dart
Updated Flutter code to handle new Window properties and methods, including alignment, badge label, icon, shadow, and always on bottom.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @ndonkoHenri - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • Typo in property name (link)
Here's what I looked at during the review
  • 🔴 General issues: 1 blocking issue, 2 other issues
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

self.page.update()

def center(self) -> None:
self.page._set_attr("windowCenter", str(time.time()))
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Use of time.time() for unique values

Using time.time() to generate unique values might not be reliable in all cases. Consider using a more robust method for generating unique identifiers.

Suggested change
self.page._set_attr("windowCenter", str(time.time()))
import uuid
self.page._set_attr("windowCenter", str(uuid.uuid4()))

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense.

@FeodorFitsner FeodorFitsner merged commit 4b51546 into main Jun 17, 2024
2 checks passed
@ndonkoHenri ndonkoHenri deleted the window branch June 17, 2024 18:58
zrr1999 added a commit to zrr1999/flet that referenced this pull request Jul 17, 2024
…ies to `Window` and `BrowserContextMenu` classes (flet-dev#3463)

* initial commit

* commit

* update Window

* create BrowserContextMenu class

* chore: remove deprecation_warning and reformat deprecated

* change signal to SIG_DFL after exit_gracefully (flet-dev#3466)

* improve type hint for run_task and run_thread (flet-dev#3459)

* add type hint

* fix Future[RetT]

* feat(map): add missing py-events, better typing (flet-dev#3464)

* initial commit

* commit

* update Window

* create BrowserContextMenu class

* chore: remove deprecation_warning and reformat deprecated

* Geolocator: rename some classes and methods

---------

Co-authored-by: Zhan Rongrui <46243324+zrr1999@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create new Window class for page.window_* properties
3 participants