python-pylan 0.0.2__py3-none-any.whl → 0.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pylan/__init__.py +17 -2
- pylan/__main__.py +29 -0
- pylan/cli/__init__.py +25 -0
- pylan/cli/cli.py +36 -0
- pylan/cli/receive.py +201 -0
- pylan/cli/scan.py +103 -0
- pylan/cli/send.py +106 -0
- pylan/client/__init__.py +14 -0
- pylan/core/__init__.py +103 -0
- pylan/core/discovery.py +475 -0
- pylan/core/handshake.py +145 -0
- pylan/core/models.py +77 -0
- pylan/core/net.py +88 -0
- pylan/core/protocol.py +132 -0
- pylan/core/transfer.py +420 -0
- pylan/errors/__init__.py +28 -0
- pylan/errors/base.py +13 -0
- pylan/main.py +6 -0
- pylan/ui/__init__.py +21 -0
- pylan/ui/app.py +188 -0
- pylan/ui/assets/icon.ico +0 -0
- pylan/ui/assets/icon.png +0 -0
- pylan/ui/assets/logo.svg +51 -0
- pylan/ui/components/__init__.py +14 -0
- pylan/ui/components/file_picker.py +243 -0
- pylan/ui/components/navbar.py +250 -0
- pylan/ui/components/peer_tile.py +152 -0
- pylan/ui/components/transfer_row.py +224 -0
- pylan/ui/state.py +823 -0
- pylan/ui/views/__init__.py +13 -0
- pylan/ui/views/home_view.py +245 -0
- pylan/ui/views/receive_view.py +249 -0
- pylan/ui/views/send_view.py +200 -0
- pylan/ui/views/settings_view.py +233 -0
- pylan/utils/utils.py +21 -0
- {python_pylan-0.0.2.dist-info → python_pylan-0.0.3.dist-info}/METADATA +13 -3
- python_pylan-0.0.3.dist-info/RECORD +39 -0
- {python_pylan-0.0.2.dist-info → python_pylan-0.0.3.dist-info}/WHEEL +1 -1
- python_pylan-0.0.3.dist-info/entry_points.txt +2 -0
- python_pylan-0.0.2.dist-info/RECORD +0 -4
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Full-screen application views for PyLan Flet UI."""
|
|
2
|
+
|
|
3
|
+
from pylan.ui.views.home_view import create_home_view
|
|
4
|
+
from pylan.ui.views.receive_view import create_receive_view
|
|
5
|
+
from pylan.ui.views.send_view import create_send_view
|
|
6
|
+
from pylan.ui.views.settings_view import create_settings_view
|
|
7
|
+
|
|
8
|
+
__all__: list[str] = [
|
|
9
|
+
"create_home_view",
|
|
10
|
+
"create_receive_view",
|
|
11
|
+
"create_send_view",
|
|
12
|
+
"create_settings_view",
|
|
13
|
+
]
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
"""Home dashboard view displaying nearby devices and primary actions."""
|
|
2
|
+
|
|
3
|
+
from typing import Callable, Optional
|
|
4
|
+
|
|
5
|
+
import flet as ft
|
|
6
|
+
|
|
7
|
+
from pylan.core.models import StatefulDevice
|
|
8
|
+
from pylan.ui.components.peer_tile import create_peer_tile
|
|
9
|
+
from pylan.ui.components.transfer_row import create_transfer_row
|
|
10
|
+
from pylan.ui.state import AppState, TransferStatus
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def create_home_view(
|
|
14
|
+
state: AppState,
|
|
15
|
+
on_send_click: Optional[Callable[[], None]] = None,
|
|
16
|
+
on_receive_click: Optional[Callable[[], None]] = None,
|
|
17
|
+
on_quick_send: Optional[Callable[[StatefulDevice], None]] = None,
|
|
18
|
+
page_width: Optional[float] = None,
|
|
19
|
+
) -> ft.Control:
|
|
20
|
+
"""Construct the unified Home view.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
state: Reactive application state store.
|
|
24
|
+
on_send_click: Callback to open the Send files workflow.
|
|
25
|
+
on_receive_click: Callback to open the Receive files workflow.
|
|
26
|
+
on_quick_send: Callback to send files directly to a clicked device.
|
|
27
|
+
page_width: Current viewport width for responsive layout adjustments.
|
|
28
|
+
|
|
29
|
+
Returns:
|
|
30
|
+
A Flet Control containing the complete home screen.
|
|
31
|
+
"""
|
|
32
|
+
is_mobile = page_width is not None and page_width < 500
|
|
33
|
+
|
|
34
|
+
def handle_device_select(device: StatefulDevice) -> None:
|
|
35
|
+
state.select_device(device)
|
|
36
|
+
if on_quick_send is not None:
|
|
37
|
+
on_quick_send(device)
|
|
38
|
+
elif on_send_click is not None:
|
|
39
|
+
on_send_click()
|
|
40
|
+
|
|
41
|
+
# Nearby devices listing
|
|
42
|
+
devices_controls: list[ft.Control] = []
|
|
43
|
+
if state.devices:
|
|
44
|
+
for dev in state.devices:
|
|
45
|
+
is_sel = (
|
|
46
|
+
state.selected_device is not None
|
|
47
|
+
and state.selected_device.device.fingerprint
|
|
48
|
+
== dev.device.fingerprint
|
|
49
|
+
)
|
|
50
|
+
devices_controls.append(
|
|
51
|
+
create_peer_tile(
|
|
52
|
+
device=dev,
|
|
53
|
+
is_selected=is_sel,
|
|
54
|
+
on_select=lambda d: state.select_device(d),
|
|
55
|
+
on_quick_send=handle_device_select,
|
|
56
|
+
)
|
|
57
|
+
)
|
|
58
|
+
else:
|
|
59
|
+
empty_device_message = (
|
|
60
|
+
"Looking for nearby devices..."
|
|
61
|
+
if state.is_scanning
|
|
62
|
+
else "No nearby devices found."
|
|
63
|
+
)
|
|
64
|
+
devices_controls.append(
|
|
65
|
+
ft.Container(
|
|
66
|
+
content=ft.Column(
|
|
67
|
+
controls=[
|
|
68
|
+
ft.Icon(
|
|
69
|
+
ft.Icons.ROUTER_ROUNDED,
|
|
70
|
+
size=44,
|
|
71
|
+
color=ft.Colors.OUTLINE,
|
|
72
|
+
),
|
|
73
|
+
ft.Text(
|
|
74
|
+
empty_device_message,
|
|
75
|
+
size=15,
|
|
76
|
+
weight=ft.FontWeight.W_600,
|
|
77
|
+
color=ft.Colors.ON_SURFACE_VARIANT,
|
|
78
|
+
),
|
|
79
|
+
ft.Text(
|
|
80
|
+
"Make sure other devices are connected to the "
|
|
81
|
+
"same Wi-Fi and have PyLan open.",
|
|
82
|
+
size=12,
|
|
83
|
+
color=ft.Colors.OUTLINE,
|
|
84
|
+
text_align=ft.TextAlign.CENTER,
|
|
85
|
+
),
|
|
86
|
+
ft.Container(height=6),
|
|
87
|
+
ft.FilledTonalButton(
|
|
88
|
+
"Find Devices",
|
|
89
|
+
icon=ft.Icons.SEARCH_ROUNDED,
|
|
90
|
+
height=38,
|
|
91
|
+
on_click=lambda _: state.trigger_discovery(),
|
|
92
|
+
),
|
|
93
|
+
],
|
|
94
|
+
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
|
|
95
|
+
alignment=ft.MainAxisAlignment.CENTER,
|
|
96
|
+
spacing=6,
|
|
97
|
+
),
|
|
98
|
+
padding=22 if is_mobile else 36,
|
|
99
|
+
border_radius=12,
|
|
100
|
+
bgcolor=ft.Colors.SURFACE_CONTAINER_LOW,
|
|
101
|
+
alignment=ft.Alignment.CENTER,
|
|
102
|
+
)
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
devices_section = ft.Column(
|
|
106
|
+
controls=[
|
|
107
|
+
ft.Row(
|
|
108
|
+
controls=[
|
|
109
|
+
ft.Text(
|
|
110
|
+
"Nearby Devices",
|
|
111
|
+
size=16,
|
|
112
|
+
weight=ft.FontWeight.BOLD,
|
|
113
|
+
color=ft.Colors.ON_SURFACE,
|
|
114
|
+
),
|
|
115
|
+
ft.FilledTonalButton(
|
|
116
|
+
"Find Devices",
|
|
117
|
+
icon=ft.Icons.REFRESH_ROUNDED,
|
|
118
|
+
height=32,
|
|
119
|
+
on_click=lambda _: state.trigger_discovery(),
|
|
120
|
+
),
|
|
121
|
+
],
|
|
122
|
+
alignment=ft.MainAxisAlignment.SPACE_BETWEEN,
|
|
123
|
+
vertical_alignment=ft.CrossAxisAlignment.CENTER,
|
|
124
|
+
),
|
|
125
|
+
ft.Column(controls=devices_controls, spacing=8),
|
|
126
|
+
],
|
|
127
|
+
spacing=12,
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
# Active and pending transfers section
|
|
131
|
+
active_transfers = [
|
|
132
|
+
t
|
|
133
|
+
for t in state.transfers
|
|
134
|
+
if t.status in (TransferStatus.PENDING, TransferStatus.TRANSFERRING)
|
|
135
|
+
]
|
|
136
|
+
transfer_rows: list[ft.Control] = []
|
|
137
|
+
transfers_section: ft.Control
|
|
138
|
+
if active_transfers:
|
|
139
|
+
for t in active_transfers:
|
|
140
|
+
transfer_rows.append(
|
|
141
|
+
create_transfer_row(
|
|
142
|
+
item=t,
|
|
143
|
+
on_accept=state.accept_incoming,
|
|
144
|
+
on_reject=state.reject_incoming,
|
|
145
|
+
on_cancel=state.cancel_transfer
|
|
146
|
+
if hasattr(state, "cancel_transfer")
|
|
147
|
+
else None,
|
|
148
|
+
)
|
|
149
|
+
)
|
|
150
|
+
transfers_section = ft.Column(
|
|
151
|
+
controls=[
|
|
152
|
+
ft.Row(
|
|
153
|
+
controls=[
|
|
154
|
+
ft.Text(
|
|
155
|
+
"Active Transfers",
|
|
156
|
+
size=15,
|
|
157
|
+
weight=ft.FontWeight.BOLD,
|
|
158
|
+
color=ft.Colors.AMBER_400,
|
|
159
|
+
),
|
|
160
|
+
ft.TextButton(
|
|
161
|
+
"View history",
|
|
162
|
+
icon=ft.Icons.ARROW_FORWARD_ROUNDED,
|
|
163
|
+
on_click=lambda _: on_receive_click()
|
|
164
|
+
if on_receive_click
|
|
165
|
+
else None,
|
|
166
|
+
),
|
|
167
|
+
],
|
|
168
|
+
alignment=ft.MainAxisAlignment.SPACE_BETWEEN,
|
|
169
|
+
vertical_alignment=ft.CrossAxisAlignment.CENTER,
|
|
170
|
+
),
|
|
171
|
+
ft.Column(controls=transfer_rows, spacing=8),
|
|
172
|
+
],
|
|
173
|
+
spacing=10,
|
|
174
|
+
)
|
|
175
|
+
else:
|
|
176
|
+
transfers_section = ft.Container(height=0)
|
|
177
|
+
|
|
178
|
+
# Primary bottom actions: Send and Receive
|
|
179
|
+
btn_height = 48 if is_mobile else 52
|
|
180
|
+
icon_size = 20 if is_mobile else 22
|
|
181
|
+
text_size = 15 if is_mobile else 16
|
|
182
|
+
|
|
183
|
+
bottom_actions = ft.Container(
|
|
184
|
+
content=ft.Row(
|
|
185
|
+
controls=[
|
|
186
|
+
ft.FilledButton(
|
|
187
|
+
content=ft.Row(
|
|
188
|
+
controls=[
|
|
189
|
+
ft.Icon(ft.Icons.SEND_ROUNDED, size=icon_size),
|
|
190
|
+
ft.Text(
|
|
191
|
+
"Send",
|
|
192
|
+
size=text_size,
|
|
193
|
+
weight=ft.FontWeight.BOLD,
|
|
194
|
+
),
|
|
195
|
+
],
|
|
196
|
+
alignment=ft.MainAxisAlignment.CENTER,
|
|
197
|
+
spacing=6 if is_mobile else 8,
|
|
198
|
+
),
|
|
199
|
+
height=btn_height,
|
|
200
|
+
expand=True,
|
|
201
|
+
on_click=lambda _: (
|
|
202
|
+
on_send_click() if on_send_click else None
|
|
203
|
+
),
|
|
204
|
+
),
|
|
205
|
+
ft.FilledTonalButton(
|
|
206
|
+
content=ft.Row(
|
|
207
|
+
controls=[
|
|
208
|
+
ft.Icon(
|
|
209
|
+
ft.Icons.DOWNLOAD_ROUNDED, size=icon_size
|
|
210
|
+
),
|
|
211
|
+
ft.Text(
|
|
212
|
+
"Receive",
|
|
213
|
+
size=text_size,
|
|
214
|
+
weight=ft.FontWeight.BOLD,
|
|
215
|
+
),
|
|
216
|
+
],
|
|
217
|
+
alignment=ft.MainAxisAlignment.CENTER,
|
|
218
|
+
spacing=6 if is_mobile else 8,
|
|
219
|
+
),
|
|
220
|
+
height=btn_height,
|
|
221
|
+
expand=True,
|
|
222
|
+
on_click=lambda _: (
|
|
223
|
+
on_receive_click() if on_receive_click else None
|
|
224
|
+
),
|
|
225
|
+
),
|
|
226
|
+
],
|
|
227
|
+
spacing=10 if is_mobile else 16,
|
|
228
|
+
),
|
|
229
|
+
padding=ft.Padding.symmetric(
|
|
230
|
+
vertical=6 if is_mobile else 8, horizontal=0
|
|
231
|
+
),
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
return ft.ListView(
|
|
235
|
+
controls=[
|
|
236
|
+
devices_section,
|
|
237
|
+
ft.Container(height=10),
|
|
238
|
+
transfers_section,
|
|
239
|
+
ft.Container(height=14),
|
|
240
|
+
bottom_actions,
|
|
241
|
+
],
|
|
242
|
+
spacing=10,
|
|
243
|
+
padding=12 if is_mobile else 20,
|
|
244
|
+
expand=True,
|
|
245
|
+
)
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"""Receive view for incoming transfer approvals, status, and history."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import subprocess
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any, Callable, Optional
|
|
7
|
+
|
|
8
|
+
import flet as ft
|
|
9
|
+
|
|
10
|
+
from pylan.ui.components.transfer_row import create_transfer_row
|
|
11
|
+
from pylan.ui.state import AppState, TransferDirection, TransferStatus
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def create_receive_view(
|
|
15
|
+
state: AppState,
|
|
16
|
+
on_back_click: Optional[Callable[[], None]] = None,
|
|
17
|
+
page_width: Optional[float] = None,
|
|
18
|
+
) -> ft.Control:
|
|
19
|
+
"""Construct the Receive Transfers workspace view.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
state: Reactive application state store.
|
|
23
|
+
on_back_click: Optional callback to return to the home screen.
|
|
24
|
+
page_width: Optional viewport width for responsive layout adjustments.
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
A Flet Control rendering the receiver status, approvals, and history.
|
|
28
|
+
"""
|
|
29
|
+
settings = state.settings
|
|
30
|
+
download_dir = settings.download_dir
|
|
31
|
+
|
|
32
|
+
_ = on_back_click
|
|
33
|
+
is_mobile = page_width is not None and page_width < 500
|
|
34
|
+
|
|
35
|
+
def open_downloads_folder(_: Any = None) -> None:
|
|
36
|
+
target = Path(download_dir)
|
|
37
|
+
target.mkdir(parents=True, exist_ok=True)
|
|
38
|
+
try:
|
|
39
|
+
if os.name == "nt":
|
|
40
|
+
os.startfile(str(target)) # type: ignore[attr-defined]
|
|
41
|
+
else:
|
|
42
|
+
subprocess.Popen(["xdg-open", str(target)])
|
|
43
|
+
except Exception:
|
|
44
|
+
pass
|
|
45
|
+
|
|
46
|
+
def toggle_auto_accept(e: Any = None) -> None:
|
|
47
|
+
val = bool(getattr(getattr(e, "control", None), "value", False))
|
|
48
|
+
state.update_settings(auto_accept=val)
|
|
49
|
+
|
|
50
|
+
# Receiver status banner
|
|
51
|
+
status_card = ft.Container(
|
|
52
|
+
content=ft.Column(
|
|
53
|
+
controls=[
|
|
54
|
+
ft.Row(
|
|
55
|
+
controls=[
|
|
56
|
+
ft.Row(
|
|
57
|
+
controls=[
|
|
58
|
+
ft.Icon(
|
|
59
|
+
ft.Icons.DOWNLOAD_DONE_ROUNDED,
|
|
60
|
+
size=24,
|
|
61
|
+
color=ft.Colors.PRIMARY,
|
|
62
|
+
),
|
|
63
|
+
ft.Text(
|
|
64
|
+
"Ready to Receive",
|
|
65
|
+
size=16,
|
|
66
|
+
weight=ft.FontWeight.BOLD,
|
|
67
|
+
color=ft.Colors.ON_SURFACE,
|
|
68
|
+
),
|
|
69
|
+
],
|
|
70
|
+
spacing=8,
|
|
71
|
+
),
|
|
72
|
+
ft.FilledTonalButton(
|
|
73
|
+
"Open Folder",
|
|
74
|
+
icon=ft.Icons.FOLDER_OPEN_ROUNDED,
|
|
75
|
+
height=32,
|
|
76
|
+
on_click=open_downloads_folder,
|
|
77
|
+
),
|
|
78
|
+
],
|
|
79
|
+
alignment=ft.MainAxisAlignment.SPACE_BETWEEN,
|
|
80
|
+
),
|
|
81
|
+
ft.Divider(height=1, color=ft.Colors.OUTLINE_VARIANT),
|
|
82
|
+
ft.Row(
|
|
83
|
+
controls=[
|
|
84
|
+
ft.Column(
|
|
85
|
+
controls=[
|
|
86
|
+
ft.Text(
|
|
87
|
+
"Save Location",
|
|
88
|
+
size=12,
|
|
89
|
+
color=ft.Colors.ON_SURFACE_VARIANT,
|
|
90
|
+
),
|
|
91
|
+
ft.Text(
|
|
92
|
+
download_dir,
|
|
93
|
+
size=13,
|
|
94
|
+
weight=ft.FontWeight.W_500,
|
|
95
|
+
color=ft.Colors.ON_SURFACE,
|
|
96
|
+
overflow=ft.TextOverflow.ELLIPSIS,
|
|
97
|
+
max_lines=1,
|
|
98
|
+
),
|
|
99
|
+
],
|
|
100
|
+
spacing=2,
|
|
101
|
+
expand=True,
|
|
102
|
+
),
|
|
103
|
+
],
|
|
104
|
+
spacing=16,
|
|
105
|
+
),
|
|
106
|
+
ft.Switch(
|
|
107
|
+
label=(
|
|
108
|
+
"Automatically accept incoming files from nearby "
|
|
109
|
+
"devices"
|
|
110
|
+
),
|
|
111
|
+
value=settings.auto_accept,
|
|
112
|
+
on_change=toggle_auto_accept,
|
|
113
|
+
),
|
|
114
|
+
],
|
|
115
|
+
spacing=12,
|
|
116
|
+
),
|
|
117
|
+
padding=12 if is_mobile else 16,
|
|
118
|
+
border_radius=12,
|
|
119
|
+
bgcolor=ft.Colors.SURFACE_CONTAINER,
|
|
120
|
+
border=ft.Border.all(1, ft.Colors.OUTLINE_VARIANT),
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
# Pending approvals
|
|
124
|
+
pending = [
|
|
125
|
+
t
|
|
126
|
+
for t in state.transfers
|
|
127
|
+
if t.direction == TransferDirection.RECEIVE
|
|
128
|
+
and t.status == TransferStatus.PENDING
|
|
129
|
+
]
|
|
130
|
+
pending_controls: list[ft.Control] = []
|
|
131
|
+
pending_section: ft.Control
|
|
132
|
+
if pending:
|
|
133
|
+
for item in pending:
|
|
134
|
+
pending_controls.append(
|
|
135
|
+
create_transfer_row(
|
|
136
|
+
item=item,
|
|
137
|
+
on_accept=state.accept_incoming,
|
|
138
|
+
on_reject=state.reject_incoming,
|
|
139
|
+
)
|
|
140
|
+
)
|
|
141
|
+
pending_section = ft.Container(
|
|
142
|
+
content=ft.Column(
|
|
143
|
+
controls=[
|
|
144
|
+
ft.Row(
|
|
145
|
+
controls=[
|
|
146
|
+
ft.Icon(
|
|
147
|
+
ft.Icons.NOTIFICATIONS_ACTIVE_ROUNDED,
|
|
148
|
+
size=20,
|
|
149
|
+
color=ft.Colors.AMBER_400,
|
|
150
|
+
),
|
|
151
|
+
ft.Text(
|
|
152
|
+
f"Pending Approvals ({len(pending)})",
|
|
153
|
+
size=15,
|
|
154
|
+
weight=ft.FontWeight.BOLD,
|
|
155
|
+
color=ft.Colors.AMBER_400,
|
|
156
|
+
),
|
|
157
|
+
],
|
|
158
|
+
spacing=6,
|
|
159
|
+
),
|
|
160
|
+
ft.Column(controls=pending_controls, spacing=8),
|
|
161
|
+
],
|
|
162
|
+
spacing=10,
|
|
163
|
+
),
|
|
164
|
+
padding=14,
|
|
165
|
+
border_radius=12,
|
|
166
|
+
bgcolor=ft.Colors.SURFACE_CONTAINER_HIGH,
|
|
167
|
+
border=ft.Border.all(1.5, ft.Colors.AMBER_400),
|
|
168
|
+
)
|
|
169
|
+
else:
|
|
170
|
+
pending_section = ft.Container(height=0)
|
|
171
|
+
|
|
172
|
+
# Incoming history
|
|
173
|
+
incoming_transfers = [
|
|
174
|
+
t
|
|
175
|
+
for t in state.transfers
|
|
176
|
+
if t.direction == TransferDirection.RECEIVE
|
|
177
|
+
and t.status != TransferStatus.PENDING
|
|
178
|
+
]
|
|
179
|
+
history_rows: list[ft.Control] = []
|
|
180
|
+
history_section: ft.Control
|
|
181
|
+
if incoming_transfers:
|
|
182
|
+
for t in incoming_transfers:
|
|
183
|
+
history_rows.append(create_transfer_row(item=t))
|
|
184
|
+
history_section = ft.Column(
|
|
185
|
+
controls=[
|
|
186
|
+
ft.Row(
|
|
187
|
+
controls=[
|
|
188
|
+
ft.Text(
|
|
189
|
+
"Transfer History",
|
|
190
|
+
size=15,
|
|
191
|
+
weight=ft.FontWeight.BOLD,
|
|
192
|
+
color=ft.Colors.ON_SURFACE,
|
|
193
|
+
),
|
|
194
|
+
ft.TextButton(
|
|
195
|
+
"Clear history",
|
|
196
|
+
icon=ft.Icons.CLEAR_ALL_ROUNDED,
|
|
197
|
+
on_click=lambda _: (
|
|
198
|
+
state.clear_completed_transfers()
|
|
199
|
+
),
|
|
200
|
+
),
|
|
201
|
+
],
|
|
202
|
+
alignment=ft.MainAxisAlignment.SPACE_BETWEEN,
|
|
203
|
+
),
|
|
204
|
+
ft.Column(controls=history_rows, spacing=8),
|
|
205
|
+
],
|
|
206
|
+
spacing=10,
|
|
207
|
+
)
|
|
208
|
+
else:
|
|
209
|
+
history_section = ft.Container(
|
|
210
|
+
content=ft.Column(
|
|
211
|
+
controls=[
|
|
212
|
+
ft.Icon(
|
|
213
|
+
ft.Icons.INBOX_ROUNDED,
|
|
214
|
+
size=40,
|
|
215
|
+
color=ft.Colors.OUTLINE,
|
|
216
|
+
),
|
|
217
|
+
ft.Text(
|
|
218
|
+
"No incoming transfers yet.",
|
|
219
|
+
size=14,
|
|
220
|
+
color=ft.Colors.ON_SURFACE_VARIANT,
|
|
221
|
+
),
|
|
222
|
+
ft.Text(
|
|
223
|
+
"Files sent to this machine from other devices "
|
|
224
|
+
"will appear here.",
|
|
225
|
+
size=12,
|
|
226
|
+
color=ft.Colors.OUTLINE,
|
|
227
|
+
text_align=ft.TextAlign.CENTER,
|
|
228
|
+
),
|
|
229
|
+
],
|
|
230
|
+
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
|
|
231
|
+
alignment=ft.MainAxisAlignment.CENTER,
|
|
232
|
+
spacing=6,
|
|
233
|
+
),
|
|
234
|
+
padding=30,
|
|
235
|
+
border_radius=12,
|
|
236
|
+
bgcolor=ft.Colors.SURFACE_CONTAINER_LOW,
|
|
237
|
+
alignment=ft.Alignment.CENTER,
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
return ft.ListView(
|
|
241
|
+
controls=[
|
|
242
|
+
status_card,
|
|
243
|
+
pending_section,
|
|
244
|
+
history_section,
|
|
245
|
+
],
|
|
246
|
+
spacing=12 if is_mobile else 16,
|
|
247
|
+
padding=12 if is_mobile else 20,
|
|
248
|
+
expand=True,
|
|
249
|
+
)
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"""Send view for queuing files, picking nearby devices, and transferring."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Callable, Optional
|
|
4
|
+
|
|
5
|
+
import flet as ft
|
|
6
|
+
|
|
7
|
+
from pylan.ui.components.file_picker import FilePickerComponent
|
|
8
|
+
from pylan.ui.components.transfer_row import create_transfer_row
|
|
9
|
+
from pylan.ui.state import AppState, TransferDirection
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def show_notice(page: Any, text: str) -> None:
|
|
13
|
+
"""Display an informational notification bar.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
page: Flet Page instance.
|
|
17
|
+
text: Message string to present.
|
|
18
|
+
"""
|
|
19
|
+
if page is None:
|
|
20
|
+
return
|
|
21
|
+
snack = ft.SnackBar(content=ft.Text(text))
|
|
22
|
+
if hasattr(page, "show_dialog"):
|
|
23
|
+
page.show_dialog(snack)
|
|
24
|
+
elif hasattr(page, "show_snack_bar"):
|
|
25
|
+
page.show_snack_bar(snack)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def create_send_view(
|
|
29
|
+
state: AppState,
|
|
30
|
+
picker_component: FilePickerComponent,
|
|
31
|
+
on_back_click: Optional[Callable[[], None]] = None,
|
|
32
|
+
on_transfer_started: Optional[Callable[[], None]] = None,
|
|
33
|
+
page_width: Optional[float] = None,
|
|
34
|
+
) -> ft.Control:
|
|
35
|
+
"""Construct the Send Files view.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
state: Reactive application state store.
|
|
39
|
+
picker_component: Shared FilePickerComponent instance.
|
|
40
|
+
on_back_click: Optional callback to return to the home screen.
|
|
41
|
+
on_transfer_started: Optional event handler on transfer dispatch.
|
|
42
|
+
page_width: Optional viewport width for responsive layout adjustments.
|
|
43
|
+
|
|
44
|
+
Returns:
|
|
45
|
+
A Flet Control rendering the file sending workspace.
|
|
46
|
+
"""
|
|
47
|
+
_ = on_back_click
|
|
48
|
+
is_mobile = page_width is not None and page_width < 500
|
|
49
|
+
manual_ip_field = ft.TextField(
|
|
50
|
+
label="Or enter device address directly",
|
|
51
|
+
hint_text="e.g. 192.168.1.50:44000",
|
|
52
|
+
prefix_icon=ft.Icons.ROUTER_ROUNDED,
|
|
53
|
+
dense=True,
|
|
54
|
+
expand=True,
|
|
55
|
+
border=ft.OutlineInputBorder(border_radius=8),
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
peer_options = [
|
|
59
|
+
ft.dropdown.Option(
|
|
60
|
+
key=dev.device.fingerprint,
|
|
61
|
+
text=(
|
|
62
|
+
f"{dev.device.alias} "
|
|
63
|
+
f"({dev.device.channel.host}:{dev.device.channel.port})"
|
|
64
|
+
),
|
|
65
|
+
)
|
|
66
|
+
for dev in state.devices
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
selected_key: Optional[str] = (
|
|
70
|
+
state.selected_device.device.fingerprint
|
|
71
|
+
if state.selected_device
|
|
72
|
+
else (peer_options[0].key if peer_options else None)
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
def handle_peer_dropdown_change(e: Any = None) -> None:
|
|
76
|
+
key = getattr(getattr(e, "control", None), "value", None)
|
|
77
|
+
matched = next(
|
|
78
|
+
(d for d in state.devices if d.device.fingerprint == key), None
|
|
79
|
+
)
|
|
80
|
+
state.select_device(matched)
|
|
81
|
+
|
|
82
|
+
peer_dropdown = ft.Dropdown(
|
|
83
|
+
label="Select nearby device",
|
|
84
|
+
options=peer_options,
|
|
85
|
+
value=selected_key,
|
|
86
|
+
dense=True,
|
|
87
|
+
expand=True,
|
|
88
|
+
border=ft.OutlineInputBorder(border_radius=8),
|
|
89
|
+
)
|
|
90
|
+
peer_dropdown.on_select = handle_peer_dropdown_change
|
|
91
|
+
|
|
92
|
+
def handle_send_click(e: Any = None) -> None:
|
|
93
|
+
page = getattr(getattr(e, "control", None), "page", None)
|
|
94
|
+
files = picker_component.selected_paths
|
|
95
|
+
if not files:
|
|
96
|
+
show_notice(page, "Please select at least one file to send.")
|
|
97
|
+
return
|
|
98
|
+
|
|
99
|
+
manual_val = (manual_ip_field.value or "").strip()
|
|
100
|
+
target_dev = state.selected_device
|
|
101
|
+
|
|
102
|
+
if not target_dev and not manual_val:
|
|
103
|
+
show_notice(page, "Please choose a recipient device or address.")
|
|
104
|
+
return
|
|
105
|
+
|
|
106
|
+
state.queue_send(
|
|
107
|
+
file_paths=files,
|
|
108
|
+
target_device=target_dev,
|
|
109
|
+
manual_target=manual_val if not target_dev else None,
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
picker_component.clear_files()
|
|
113
|
+
show_notice(page, f"Queued {len(files)} file(s) for transmission.")
|
|
114
|
+
if on_transfer_started is not None:
|
|
115
|
+
on_transfer_started()
|
|
116
|
+
|
|
117
|
+
send_button = ft.FilledButton(
|
|
118
|
+
"Send Files",
|
|
119
|
+
icon=ft.Icons.SEND_ROUNDED,
|
|
120
|
+
height=42,
|
|
121
|
+
on_click=handle_send_click,
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
recipient_card = ft.Container(
|
|
125
|
+
content=ft.Column(
|
|
126
|
+
controls=[
|
|
127
|
+
ft.Text(
|
|
128
|
+
"Recipient",
|
|
129
|
+
size=15,
|
|
130
|
+
weight=ft.FontWeight.BOLD,
|
|
131
|
+
color=ft.Colors.ON_SURFACE,
|
|
132
|
+
),
|
|
133
|
+
peer_dropdown
|
|
134
|
+
if peer_options
|
|
135
|
+
else ft.Text(
|
|
136
|
+
"No nearby devices detected yet. "
|
|
137
|
+
"Enter device address manually:",
|
|
138
|
+
size=12,
|
|
139
|
+
color=ft.Colors.ON_SURFACE_VARIANT,
|
|
140
|
+
),
|
|
141
|
+
manual_ip_field,
|
|
142
|
+
ft.Row(
|
|
143
|
+
controls=[send_button],
|
|
144
|
+
alignment=ft.MainAxisAlignment.END,
|
|
145
|
+
),
|
|
146
|
+
],
|
|
147
|
+
spacing=10,
|
|
148
|
+
),
|
|
149
|
+
padding=12 if is_mobile else 16,
|
|
150
|
+
border_radius=12,
|
|
151
|
+
bgcolor=ft.Colors.SURFACE_CONTAINER,
|
|
152
|
+
border=ft.Border.all(1, ft.Colors.OUTLINE_VARIANT),
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
# Outgoing transfers list
|
|
156
|
+
outgoing_transfers = [
|
|
157
|
+
t for t in state.transfers if t.direction == TransferDirection.SEND
|
|
158
|
+
]
|
|
159
|
+
outgoing_rows: list[ft.Control] = []
|
|
160
|
+
transfers_section: ft.Control
|
|
161
|
+
if outgoing_transfers:
|
|
162
|
+
for t in outgoing_transfers:
|
|
163
|
+
outgoing_rows.append(create_transfer_row(item=t))
|
|
164
|
+
transfers_section = ft.Column(
|
|
165
|
+
controls=[
|
|
166
|
+
ft.Row(
|
|
167
|
+
controls=[
|
|
168
|
+
ft.Text(
|
|
169
|
+
"Outgoing Transfers",
|
|
170
|
+
size=15,
|
|
171
|
+
weight=ft.FontWeight.BOLD,
|
|
172
|
+
color=ft.Colors.ON_SURFACE,
|
|
173
|
+
),
|
|
174
|
+
ft.TextButton(
|
|
175
|
+
"Clear completed",
|
|
176
|
+
icon=ft.Icons.CLEAR_ALL_ROUNDED,
|
|
177
|
+
on_click=lambda _: (
|
|
178
|
+
state.clear_completed_transfers()
|
|
179
|
+
),
|
|
180
|
+
),
|
|
181
|
+
],
|
|
182
|
+
alignment=ft.MainAxisAlignment.SPACE_BETWEEN,
|
|
183
|
+
),
|
|
184
|
+
ft.Column(controls=outgoing_rows, spacing=8),
|
|
185
|
+
],
|
|
186
|
+
spacing=10,
|
|
187
|
+
)
|
|
188
|
+
else:
|
|
189
|
+
transfers_section = ft.Container(height=0)
|
|
190
|
+
|
|
191
|
+
return ft.ListView(
|
|
192
|
+
controls=[
|
|
193
|
+
picker_component.build(),
|
|
194
|
+
recipient_card,
|
|
195
|
+
transfers_section,
|
|
196
|
+
],
|
|
197
|
+
spacing=12 if is_mobile else 16,
|
|
198
|
+
padding=12 if is_mobile else 20,
|
|
199
|
+
expand=True,
|
|
200
|
+
)
|