forked from beeware/toga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow.py
92 lines (68 loc) · 2.59 KB
/
window.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from decimal import ROUND_UP
from java import dynamic_proxy
from android import R
from android.view import ViewTreeObserver
from .container import Container
class LayoutListener(dynamic_proxy(ViewTreeObserver.OnGlobalLayoutListener)):
def __init__(self, window):
super().__init__()
self.window = window
def onGlobalLayout(self):
"""This listener is run after each native layout pass.
If any view's size or position has changed, the new values will be visible here.
"""
native_parent = self.window.native_content.getParent()
self.window.resize_content(native_parent.getWidth(), native_parent.getHeight())
class Window(Container):
def __init__(self, interface, title, position, size):
super().__init__()
self.interface = interface
self.interface._impl = self
# self.set_title(title)
def set_app(self, app):
self.app = app
native_parent = app.native.findViewById(R.id.content)
self.init_container(native_parent)
native_parent.getViewTreeObserver().addOnGlobalLayoutListener(
LayoutListener(self)
)
def get_title(self):
return str(self.app.native.getTitle())
def set_title(self, title):
self.app.native.setTitle(title)
def get_position(self):
return 0, 0
def set_position(self, position):
# Does nothing on mobile
pass
def get_size(self):
return (self.width, self.height)
def set_size(self, size):
# Does nothing on mobile
pass
def create_toolbar(self):
pass
def show(self):
pass
def hide(self):
# A no-op, as the window cannot be hidden.
pass
def refreshed(self):
if self.native_width and self.native_height:
layout = self.interface.content.layout
available_width = self.scale_out(self.native_width, ROUND_UP)
available_height = self.scale_out(self.native_height, ROUND_UP)
if (layout.width > available_width) or (layout.height > available_height):
# Show the sizes in terms of CSS pixels.
print(
f"Warning: Window content {(layout.width, layout.height)} "
f"exceeds available space {(available_width, available_height)}"
)
super().refreshed()
def get_visible(self):
# The window is always visible
return True
def close(self):
pass
def set_full_screen(self, is_full_screen):
self.interface.factory.not_implemented("Window.set_full_screen()")