-
Notifications
You must be signed in to change notification settings - Fork 590
feat: custom TimePicker hour formats
#5790
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
Open
ndonkoHenri
wants to merge
16
commits into
main
Choose a base branch
from
timepicker-time-format
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+541
−166
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
cfd90f6
initial commit
ndonkoHenri cb62a49
docs
ndonkoHenri e02d43e
examples
ndonkoHenri 287477f
`PageMediaData.always_use_24_hour_format`
ndonkoHenri d605d5a
tests
ndonkoHenri 6662886
improve basic test
ndonkoHenri 6b95c8c
Merge branch 'main' into timepicker-time-format
ndonkoHenri c6461f8
apply review suggestions
ndonkoHenri 955b679
refactor: make `TimePickerEntryModeChangeEvent` a dataclass
ndonkoHenri 94c041f
Add finder index support to tester interactions
FeodorFitsner 6bfc4c1
Merge branch 'timepicker-time-format' of https://github.com/flet-dev/…
FeodorFitsner bf1f7e9
Remove await from resize_page in test_hour_formats
FeodorFitsner deaec08
docs: add example image for time picker hour formats
ndonkoHenri 2c3884d
Update time picker hour format tests and golden images
FeodorFitsner 0f78cf4
Merge branch 'timepicker-time-format' of https://github.com/flet-dev/…
FeodorFitsner 90d6037
Update golden images for macOS time picker tests
FeodorFitsner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| from datetime import time | ||
|
|
||
| import flet as ft | ||
|
|
||
|
|
||
| def main(page: ft.Page): | ||
| page.horizontal_alignment = ft.CrossAxisAlignment.CENTER | ||
|
|
||
| def get_system_hour_format(): | ||
| """Returns the current system's hour format.""" | ||
| return "24h" if page.media.always_use_24_hour_format else "12h" | ||
|
|
||
| def format_time(value: time) -> str: | ||
| """Returns a formatted time string based on TimePicker and system settings.""" | ||
| use_24h = time_picker.hour_format == ft.TimePickerHourFormat.H24 or ( | ||
| time_picker.hour_format == ft.TimePickerHourFormat.SYSTEM | ||
| and page.media.always_use_24_hour_format | ||
| ) | ||
| return value.strftime("%H:%M" if use_24h else "%I:%M %p") | ||
|
|
||
| def handle_change(e: ft.Event[ft.TimePicker]): | ||
| selection.value = f"Selection: {format_time(time_picker.value)}" | ||
|
|
||
| time_picker = ft.TimePicker( | ||
| value=time(hour=9, minute=30), | ||
| help_text="Choose your meeting time", | ||
| on_change=handle_change, | ||
| ) | ||
|
|
||
| def open_picker(e: ft.Event[ft.Button]): | ||
| choice = format_dropdown.value | ||
| hour_format_map = { | ||
| "system": ft.TimePickerHourFormat.SYSTEM, | ||
| "12h": ft.TimePickerHourFormat.H12, | ||
| "24h": ft.TimePickerHourFormat.H24, | ||
| } | ||
| time_picker.hour_format = hour_format_map[choice] | ||
| page.show_dialog(time_picker) | ||
|
|
||
| page.add( | ||
| ft.Row( | ||
| alignment=ft.MainAxisAlignment.CENTER, | ||
| controls=[ | ||
| format_dropdown := ft.Dropdown( | ||
| label="Hour format", | ||
| value="system", | ||
| width=260, | ||
| key="dd", | ||
| options=[ | ||
| ft.DropdownOption( | ||
| key="system", | ||
| text=f"System default ({get_system_hour_format()})", | ||
| ), | ||
| ft.DropdownOption(key="12h", text="12-hour clock"), | ||
| ft.DropdownOption(key="24h", text="24-hour clock"), | ||
| ], | ||
| ), | ||
| ft.Button( | ||
| "Open TimePicker", | ||
| icon=ft.Icons.SCHEDULE, | ||
| on_click=open_picker, | ||
| ), | ||
| ], | ||
| ), | ||
| selection := ft.Text(weight=ft.FontWeight.BOLD), | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| ft.run(main) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {{ class_all_options("flet.TimePickerHourFormat", separate_signature=False) }} |
Binary file added
BIN
+10.4 KB
...ages/flet/integration_tests/controls/material/golden/macos/dropdown/basic_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+47.2 KB
...ges/flet/integration_tests/controls/material/golden/macos/time_picker/basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+45.8 KB
...integration_tests/controls/material/golden/macos/time_picker/hour_format_12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+56.8 KB
...integration_tests/controls/material/golden/macos/time_picker/hour_format_24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed
BIN
-47.1 KB
...egration_tests/controls/material/golden/macos/time_picker/time_picker_basic.png
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.