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
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
386 changes: 220 additions & 166 deletions packages/flet/lib/src/controls/page.dart

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions packages/flet/lib/src/reducers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@ AppState appReducer(AppState state, dynamic action) {
}
controls[page.id] = page.copyWith(attrs: pageAttrs);
action.backend.updateControlState("page", props, client: false);
action.backend.triggerControlEvent("page", "resize",
"${action.newPageSize.width},${action.newPageSize.height}");
action.backend.triggerControlEvent(
"page",
"resized",
jsonEncode({
"width": action.newPageSize.width,
"height": action.newPageSize.height
}));
}

return state.copyWith(
Expand Down
75 changes: 59 additions & 16 deletions packages/flet/lib/src/utils/desktop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import '../models/window_media_data.dart';

Future setWindowTitle(String title) async {
if (isDesktop()) {
debugPrint("setWindowTitle()");
debugPrint("setWindowTitle($title)");
await windowManager.setTitle(title);
}
}

Future setWindowBackgroundColor(Color bgcolor) async {
if (isDesktop()) {
debugPrint("setWindowBackgroundColor()");
debugPrint("setWindowBackgroundColor($bgcolor)");
await windowManager.setBackgroundColor(bgcolor);
}
}

Future setWindowSize(double? width, double? height) async {
if (isDesktop()) {
debugPrint("setWindowSize()");
debugPrint("setWindowSize($width, $height)");
var currentSize = await windowManager.getSize();
await windowManager.setSize(
Size(width ?? currentSize.width, height ?? currentSize.height),
Expand All @@ -31,21 +31,21 @@ Future setWindowSize(double? width, double? height) async {

Future setWindowMinSize(double? minWidth, double? minHeight) async {
if (isDesktop()) {
debugPrint("setWindowMinSize()");
debugPrint("setWindowMinSize($minWidth, $minHeight)");
await windowManager.setMinimumSize(Size(minWidth ?? 0, minHeight ?? 0));
}
}

Future setWindowMaxSize(double? maxWidth, double? maxHeight) async {
if (isDesktop()) {
debugPrint("setWindowMaxSize()");
debugPrint("setWindowMaxSize($maxWidth, $maxHeight)");
await windowManager.setMaximumSize(Size(maxWidth ?? -1, maxHeight ?? -1));
}
}

Future setWindowPosition(double? top, double? left) async {
if (isDesktop()) {
debugPrint("setWindowPosition()");
debugPrint("setWindowPosition($top, $left)");
var currentPos = await windowManager.getPosition();
await windowManager.setPosition(
Offset(left ?? currentPos.dx, top ?? currentPos.dy),
Expand All @@ -55,56 +55,63 @@ Future setWindowPosition(double? top, double? left) async {

Future setWindowOpacity(double opacity) async {
if (isDesktop()) {
debugPrint("setWindowOpacity()");
debugPrint("setWindowOpacity($opacity)");
await windowManager.setOpacity(opacity);
}
}

Future setWindowMinimizability(bool minimizable) async {
if (isDesktop()) {
debugPrint("setWindowMinimizability()");
debugPrint("setWindowMinimizability($minimizable)");
await windowManager.setMinimizable(minimizable);
}
}

Future setWindowMaximizability(bool maximizable) async {
if (isDesktop()) {
debugPrint("setWindowMaximizability()");
debugPrint("setWindowMaximizability($maximizable)");
await windowManager.setMaximizable(maximizable);
}
}

Future setWindowResizability(bool resizable) async {
if (isDesktop()) {
debugPrint("setWindowResizability()");
debugPrint("setWindowResizability($resizable)");
await windowManager.setResizable(resizable);
}
}

Future setWindowMovability(bool movable) async {
if (isDesktop()) {
debugPrint("setWindowMovability()");
debugPrint("setWindowMovability($movable)");
await windowManager.setMovable(movable);
}
}

Future setWindowFullScreen(bool fullScreen) async {
if (isDesktop() && await windowManager.isFullScreen() != fullScreen) {
debugPrint("setWindowFullScreen()");
debugPrint("setWindowFullScreen($fullScreen)");
await windowManager.setFullScreen(fullScreen);
}
}

Future setWindowAlwaysOnTop(bool alwaysOnTop) async {
if (isDesktop() && await windowManager.isAlwaysOnTop() != alwaysOnTop) {
debugPrint("setWindowAlwaysOnTop()");
debugPrint("setWindowAlwaysOnTop($alwaysOnTop)");
await windowManager.setAlwaysOnTop(alwaysOnTop);
}
}

Future setWindowAlwaysOnBottom(bool alwaysOnBottom) async {
if (isDesktop()) {
debugPrint("setWindowAlwaysOnBottom($alwaysOnBottom)");
await windowManager.setAlwaysOnBottom(alwaysOnBottom);
}
}

Future setWindowPreventClose(bool preventClose) async {
if (isDesktop()) {
debugPrint("setWindowPreventClose()");
debugPrint("setWindowPreventClose($preventClose)");
await windowManager.setPreventClose(preventClose);
}
}
Expand All @@ -121,7 +128,7 @@ Future setWindowTitleBarVisibility(

Future setWindowSkipTaskBar(bool skipTaskBar) async {
if (isDesktop()) {
debugPrint("setWindowSkipTaskBar()");
debugPrint("setWindowSkipTaskBar($skipTaskBar)");
await windowManager.setSkipTaskbar(skipTaskBar);
}
}
Expand All @@ -135,11 +142,40 @@ Future setWindowFrameless() async {

Future setWindowProgressBar(double progress) async {
if (isDesktop()) {
debugPrint("setWindowProgressBar()");
debugPrint("setWindowProgressBar($progress)");
await windowManager.setProgressBar(progress);
}
}

Future setWindowShadow(bool hasShadow) async {
if (isDesktop()) {
debugPrint("setWindowHasShadow($hasShadow)");
debugPrint("${windowManager.hasShadow()}");
await windowManager.setHasShadow(hasShadow);
}
}

Future setWindowBadgeLabel(String label) async {
if (isDesktop()) {
debugPrint("setWindowBadgeLabel($label)");
await windowManager.setBadgeLabel(label);
}
}

Future setWindowIcon(String iconPath) async {
if (isWindowsDesktop()) {
debugPrint("setWindowIcon($iconPath)");
await windowManager.setIcon(iconPath);
}
}

Future setWindowAlignment(Alignment alignment, [bool animate = true]) async {
if (isDesktop()) {
debugPrint("setWindowAlignment($alignment, animate: $animate)");
await windowManager.setAlignment(alignment, animate: animate);
}
}

Future minimizeWindow() async {
if (isDesktop() && !await windowManager.isMinimized()) {
debugPrint("minimizeWindow()");
Expand Down Expand Up @@ -214,6 +250,13 @@ Future destroyWindow() async {
}
}

Future waitUntilReadyToShow() async {
if (isDesktop()) {
debugPrint("waitUntilReadyToShow()");
await windowManager.waitUntilReadyToShow();
}
}

Future centerWindow() async {
if (isDesktop()) {
debugPrint("centerWindow()");
Expand Down
2 changes: 1 addition & 1 deletion packages/flet/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies:
flutter_redux: ^0.10.0
equatable: ^2.0.3
web_socket_channel: ^2.4.0
window_manager: ^0.3.7
window_manager: ^0.3.9
http: ^1.1.2
collection: ^1.16.0
url_launcher: ^6.1.5
Expand Down
2 changes: 1 addition & 1 deletion packages/flet_geolocator/lib/src/geolocator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class _GeolocatorControlState extends State<GeolocatorControl>
case "request_permission":
var permission = await Geolocator.requestPermission();
return permission.name;
case "has_permission":
case "get_permission_status":
var permission = await Geolocator.checkPermission();
return permission.name;
case "is_location_service_enabled":
Expand Down
9 changes: 9 additions & 0 deletions packages/flet_map/lib/src/map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ class _MapControlState extends State<MapControl> with FletStoreMixin {
triggerEvent(config.control, "pointer_down", {
"lat": latlng.latitude,
"long": latlng.longitude,
"gx": e.position.dx,
"gy": e.position.dy,
"kind": e.kind.name,
});
}
: null,
Expand All @@ -130,6 +133,9 @@ class _MapControlState extends State<MapControl> with FletStoreMixin {
triggerEvent(config.control, "pointer_cancel", {
"lat": latlng.latitude,
"long": latlng.longitude,
"gx": e.position.dx,
"gy": e.position.dy,
"kind": e.kind.name,
});
}
: null,
Expand All @@ -138,6 +144,9 @@ class _MapControlState extends State<MapControl> with FletStoreMixin {
triggerEvent(config.control, "pointer_up", {
"lat": latlng.latitude,
"long": latlng.longitude,
"gx": e.position.dx,
"gy": e.position.dy,
"kind": e.kind.name,
});
}
: null,
Expand Down
7 changes: 6 additions & 1 deletion sdk/python/packages/flet-core/src/flet_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@
from flet_core.flet_app import FletApp
from flet_core.floating_action_button import FloatingActionButton
from flet_core.form_field_control import InputBorder
from flet_core.geolocator import Geolocator, LocationAccuracy
from flet_core.geolocator import (
Geolocator,
GeolocatorPositionAccuracy,
GeolocatorPermissionStatus,
GeolocatorPosition,
)
from flet_core.gesture_detector import (
DragEndEvent,
DragStartEvent,
Expand Down
40 changes: 23 additions & 17 deletions sdk/python/packages/flet-core/src/flet_core/geolocator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from flet_core.ref import Ref


class LocationAccuracy(Enum):
class GeolocatorPositionAccuracy(Enum):
LOWEST = "lowest"
LOW = "low"
MEDIUM = "medium"
Expand All @@ -17,7 +17,7 @@ class LocationAccuracy(Enum):
REDUCED = "reduced"


class LocationPermission(Enum):
class GeolocatorPermissionStatus(Enum):
DENIED = "denied"
DENIED_FOREVER = "deniedForever"
WHILE_IN_USE = "whileInUse"
Expand Down Expand Up @@ -70,15 +70,17 @@ def _get_control_name(self):

def get_current_position(
self,
accuracy: Optional[LocationAccuracy] = LocationAccuracy.BEST,
accuracy: Optional[
GeolocatorPositionAccuracy
] = GeolocatorPositionAccuracy.BEST,
wait_timeout: Optional[float] = 25,
) -> GeolocatorPosition:
output = self.invoke_method(
"get_current_position",
{
"accuracy": (
accuracy.value
if isinstance(accuracy, LocationAccuracy)
if isinstance(accuracy, GeolocatorPositionAccuracy)
else accuracy
)
},
Expand All @@ -93,15 +95,17 @@ def get_current_position(

async def get_current_position_async(
self,
accuracy: Optional[LocationAccuracy] = LocationAccuracy.BEST,
accuracy: Optional[
GeolocatorPositionAccuracy
] = GeolocatorPositionAccuracy.BEST,
wait_timeout: Optional[float] = 25,
) -> GeolocatorPosition:
output = await self.invoke_method_async(
"get_current_position",
{
"accuracy": (
accuracy.value
if isinstance(accuracy, LocationAccuracy)
if isinstance(accuracy, GeolocatorPositionAccuracy)
else accuracy
)
},
Expand Down Expand Up @@ -146,43 +150,45 @@ async def get_last_known_position_async(
else GeolocatorPosition()
)

def has_permission(self, wait_timeout: Optional[float] = 25) -> LocationPermission:
def get_permission_status(
self, wait_timeout: Optional[float] = 25
) -> GeolocatorPermissionStatus:
p = self.invoke_method(
"has_permission",
"get_permission_status",
wait_for_result=True,
wait_timeout=wait_timeout,
)
return LocationPermission(p)
return GeolocatorPermissionStatus(p)

async def has_permission_async(
async def get_permission_status_async(
self, wait_timeout: Optional[float] = 25
) -> LocationPermission:
) -> GeolocatorPermissionStatus:
p = await self.invoke_method_async(
"has_permission",
"get_permission_status",
wait_for_result=True,
wait_timeout=wait_timeout,
)
return LocationPermission(p)
return GeolocatorPermissionStatus(p)

def request_permission(
self, wait_timeout: Optional[float] = 25
) -> LocationPermission:
) -> GeolocatorPermissionStatus:
p = self.invoke_method(
"request_permission",
wait_for_result=True,
wait_timeout=wait_timeout,
)
return LocationPermission(p)
return GeolocatorPermissionStatus(p)

async def request_permission_async(
self, wait_timeout: Optional[float] = 25
) -> LocationPermission:
) -> GeolocatorPermissionStatus:
p = await self.invoke_method_async(
"request_permission",
wait_for_result=True,
wait_timeout=wait_timeout,
)
return LocationPermission(p)
return GeolocatorPermissionStatus(p)

def is_location_service_enabled(self, wait_timeout: Optional[float] = 10) -> bool:
enabled = self.invoke_method(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
MapInteractionConfiguration,
MapInteractiveFlag,
MapMultiFingerGesture,
TapEvent,
MapTapEvent,
MapEvent,
MapEventSource,
)
Expand Down
Loading