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,250 @@
|
|
|
1
|
+
"""Top app bar and navigation controls for PyLan UI."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Callable, Optional
|
|
4
|
+
|
|
5
|
+
import flet as ft
|
|
6
|
+
|
|
7
|
+
from pylan.ui.state import AppState
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def create_top_bar(
|
|
11
|
+
state: AppState,
|
|
12
|
+
on_scan_click: Optional[Callable[[], None]] = None,
|
|
13
|
+
on_settings_click: Optional[Callable[[], None]] = None,
|
|
14
|
+
on_back_click: Optional[Callable[[], None]] = None,
|
|
15
|
+
title: Optional[str] = None,
|
|
16
|
+
page_width: Optional[float] = None,
|
|
17
|
+
) -> ft.Container:
|
|
18
|
+
"""Create a styled top application header bar.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
state: Application state instance providing node identity and status.
|
|
22
|
+
on_scan_click: Callback fired when clicking the search/scan button.
|
|
23
|
+
on_settings_click: Callback fired when clicking the settings icon.
|
|
24
|
+
on_back_click: Optional callback for returning to the home screen.
|
|
25
|
+
title: Optional custom header title string.
|
|
26
|
+
page_width: Optional current viewport width for responsive sizing.
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
A Flet Container styled as an application header bar.
|
|
30
|
+
"""
|
|
31
|
+
settings = state.settings
|
|
32
|
+
alias = settings.device_alias
|
|
33
|
+
is_compact = page_width is not None and page_width < 500
|
|
34
|
+
|
|
35
|
+
status_color = (
|
|
36
|
+
ft.Colors.GREEN_ACCENT_400
|
|
37
|
+
if state.is_receiver_running
|
|
38
|
+
else ft.Colors.ORANGE_400
|
|
39
|
+
)
|
|
40
|
+
status_text = (
|
|
41
|
+
"Ready to share" if state.is_receiver_running else "Offline"
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
scan_button = (
|
|
45
|
+
ft.ProgressRing(width=16, height=16, stroke_width=2)
|
|
46
|
+
if state.is_scanning
|
|
47
|
+
else ft.IconButton(
|
|
48
|
+
icon=ft.Icons.REFRESH_ROUNDED,
|
|
49
|
+
tooltip="Find devices",
|
|
50
|
+
icon_color=ft.Colors.PRIMARY,
|
|
51
|
+
on_click=lambda _: on_scan_click() if on_scan_click else None,
|
|
52
|
+
)
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
settings_button = ft.IconButton(
|
|
56
|
+
icon=ft.Icons.SETTINGS_ROUNDED,
|
|
57
|
+
tooltip="Settings",
|
|
58
|
+
icon_color=ft.Colors.ON_SURFACE_VARIANT,
|
|
59
|
+
on_click=lambda _: (
|
|
60
|
+
on_settings_click() if on_settings_click else None
|
|
61
|
+
),
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
if on_back_click is not None:
|
|
65
|
+
leading_area = ft.Row(
|
|
66
|
+
controls=[
|
|
67
|
+
ft.IconButton(
|
|
68
|
+
icon=ft.Icons.ARROW_BACK_ROUNDED,
|
|
69
|
+
tooltip="Back to Home",
|
|
70
|
+
icon_color=ft.Colors.ON_SURFACE,
|
|
71
|
+
on_click=lambda _: on_back_click(),
|
|
72
|
+
),
|
|
73
|
+
ft.Text(
|
|
74
|
+
title or "pylan",
|
|
75
|
+
size=16 if is_compact else 18,
|
|
76
|
+
weight=ft.FontWeight.W_700,
|
|
77
|
+
color=ft.Colors.ON_SURFACE,
|
|
78
|
+
overflow=ft.TextOverflow.ELLIPSIS,
|
|
79
|
+
max_lines=1,
|
|
80
|
+
),
|
|
81
|
+
],
|
|
82
|
+
spacing=2 if is_compact else 4,
|
|
83
|
+
vertical_alignment=ft.CrossAxisAlignment.CENTER,
|
|
84
|
+
)
|
|
85
|
+
else:
|
|
86
|
+
leading_area = ft.Row(
|
|
87
|
+
controls=[
|
|
88
|
+
ft.Image(
|
|
89
|
+
src="icon.png",
|
|
90
|
+
width=24 if is_compact else 26,
|
|
91
|
+
height=24 if is_compact else 26,
|
|
92
|
+
fit=ft.BoxFit.CONTAIN,
|
|
93
|
+
error_content=ft.Icon(
|
|
94
|
+
ft.Icons.SHARE_ROUNDED,
|
|
95
|
+
size=24 if is_compact else 26,
|
|
96
|
+
color=ft.Colors.PRIMARY,
|
|
97
|
+
),
|
|
98
|
+
),
|
|
99
|
+
ft.Text(
|
|
100
|
+
"pylan",
|
|
101
|
+
size=18 if is_compact else 20,
|
|
102
|
+
weight=ft.FontWeight.W_800,
|
|
103
|
+
color=ft.Colors.ON_SURFACE,
|
|
104
|
+
),
|
|
105
|
+
],
|
|
106
|
+
spacing=6 if is_compact else 8,
|
|
107
|
+
vertical_alignment=ft.CrossAxisAlignment.CENTER,
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
# Responsive status indicator
|
|
111
|
+
if page_width is not None and page_width < 380:
|
|
112
|
+
status_pill_content = ft.Row(
|
|
113
|
+
controls=[
|
|
114
|
+
ft.Icon(
|
|
115
|
+
ft.Icons.CIRCLE,
|
|
116
|
+
size=8,
|
|
117
|
+
color=status_color,
|
|
118
|
+
),
|
|
119
|
+
],
|
|
120
|
+
spacing=0,
|
|
121
|
+
tight=True,
|
|
122
|
+
)
|
|
123
|
+
status_padding = ft.Padding.all(8)
|
|
124
|
+
elif is_compact:
|
|
125
|
+
status_pill_content = ft.Row(
|
|
126
|
+
controls=[
|
|
127
|
+
ft.Icon(
|
|
128
|
+
ft.Icons.CIRCLE,
|
|
129
|
+
size=8,
|
|
130
|
+
color=status_color,
|
|
131
|
+
),
|
|
132
|
+
ft.Text(
|
|
133
|
+
status_text,
|
|
134
|
+
size=11,
|
|
135
|
+
weight=ft.FontWeight.W_500,
|
|
136
|
+
color=ft.Colors.ON_SURFACE,
|
|
137
|
+
overflow=ft.TextOverflow.ELLIPSIS,
|
|
138
|
+
max_lines=1,
|
|
139
|
+
),
|
|
140
|
+
],
|
|
141
|
+
spacing=4,
|
|
142
|
+
tight=True,
|
|
143
|
+
)
|
|
144
|
+
status_padding = ft.Padding.symmetric(horizontal=8, vertical=4)
|
|
145
|
+
else:
|
|
146
|
+
status_pill_content = ft.Row(
|
|
147
|
+
controls=[
|
|
148
|
+
ft.Icon(
|
|
149
|
+
ft.Icons.CIRCLE,
|
|
150
|
+
size=8,
|
|
151
|
+
color=status_color,
|
|
152
|
+
),
|
|
153
|
+
ft.Text(
|
|
154
|
+
f"{alias} • {status_text}",
|
|
155
|
+
size=12,
|
|
156
|
+
weight=ft.FontWeight.W_500,
|
|
157
|
+
color=ft.Colors.ON_SURFACE,
|
|
158
|
+
overflow=ft.TextOverflow.ELLIPSIS,
|
|
159
|
+
max_lines=1,
|
|
160
|
+
),
|
|
161
|
+
],
|
|
162
|
+
spacing=6,
|
|
163
|
+
tight=True,
|
|
164
|
+
)
|
|
165
|
+
status_padding = ft.Padding.symmetric(horizontal=12, vertical=6)
|
|
166
|
+
|
|
167
|
+
status_pill = ft.Container(
|
|
168
|
+
content=status_pill_content,
|
|
169
|
+
padding=status_padding,
|
|
170
|
+
border_radius=20,
|
|
171
|
+
bgcolor=ft.Colors.SURFACE_CONTAINER_HIGH,
|
|
172
|
+
tooltip=f"{alias} • {status_text}",
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
return ft.Container(
|
|
176
|
+
content=ft.Row(
|
|
177
|
+
controls=[
|
|
178
|
+
leading_area,
|
|
179
|
+
ft.Row(
|
|
180
|
+
controls=[
|
|
181
|
+
status_pill,
|
|
182
|
+
scan_button,
|
|
183
|
+
settings_button,
|
|
184
|
+
],
|
|
185
|
+
spacing=4 if is_compact else 8,
|
|
186
|
+
vertical_alignment=ft.CrossAxisAlignment.CENTER,
|
|
187
|
+
),
|
|
188
|
+
],
|
|
189
|
+
alignment=ft.MainAxisAlignment.SPACE_BETWEEN,
|
|
190
|
+
vertical_alignment=ft.CrossAxisAlignment.CENTER,
|
|
191
|
+
),
|
|
192
|
+
padding=ft.Padding.symmetric(
|
|
193
|
+
horizontal=12 if is_compact else 16,
|
|
194
|
+
vertical=8 if is_compact else 10,
|
|
195
|
+
),
|
|
196
|
+
bgcolor=ft.Colors.SURFACE_CONTAINER,
|
|
197
|
+
border=ft.Border(
|
|
198
|
+
bottom=ft.BorderSide(1, ft.Colors.OUTLINE_VARIANT)
|
|
199
|
+
),
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def create_navigation_rail(
|
|
204
|
+
selected_index: int,
|
|
205
|
+
on_change: Callable[[int], None],
|
|
206
|
+
) -> ft.NavigationRail:
|
|
207
|
+
"""Create a vertical sidebar navigation rail for main views.
|
|
208
|
+
|
|
209
|
+
Args:
|
|
210
|
+
selected_index: Index of currently active page.
|
|
211
|
+
on_change: Callback fired when user selects a different destination.
|
|
212
|
+
|
|
213
|
+
Returns:
|
|
214
|
+
A configured Flet NavigationRail control.
|
|
215
|
+
"""
|
|
216
|
+
|
|
217
|
+
def handle_change(e: Any = None) -> None:
|
|
218
|
+
idx = getattr(e.control, "selected_index", 0) if e else 0
|
|
219
|
+
on_change(int(idx))
|
|
220
|
+
|
|
221
|
+
return ft.NavigationRail(
|
|
222
|
+
selected_index=selected_index,
|
|
223
|
+
label_type=ft.NavigationRailLabelType.ALL,
|
|
224
|
+
min_width=72,
|
|
225
|
+
min_extended_width=160,
|
|
226
|
+
bgcolor=ft.Colors.SURFACE_CONTAINER_LOW,
|
|
227
|
+
on_change=handle_change,
|
|
228
|
+
destinations=[
|
|
229
|
+
ft.NavigationRailDestination(
|
|
230
|
+
icon=ft.Icons.DASHBOARD_OUTLINED,
|
|
231
|
+
selected_icon=ft.Icons.DASHBOARD_ROUNDED,
|
|
232
|
+
label="Home",
|
|
233
|
+
),
|
|
234
|
+
ft.NavigationRailDestination(
|
|
235
|
+
icon=ft.Icons.SEND_OUTLINED,
|
|
236
|
+
selected_icon=ft.Icons.SEND_ROUNDED,
|
|
237
|
+
label="Send",
|
|
238
|
+
),
|
|
239
|
+
ft.NavigationRailDestination(
|
|
240
|
+
icon=ft.Icons.DOWNLOAD_OUTLINED,
|
|
241
|
+
selected_icon=ft.Icons.DOWNLOAD_ROUNDED,
|
|
242
|
+
label="Receive",
|
|
243
|
+
),
|
|
244
|
+
ft.NavigationRailDestination(
|
|
245
|
+
icon=ft.Icons.SETTINGS_OUTLINED,
|
|
246
|
+
selected_icon=ft.Icons.SETTINGS_ROUNDED,
|
|
247
|
+
label="Settings",
|
|
248
|
+
),
|
|
249
|
+
],
|
|
250
|
+
)
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"""Peer tile widget displaying discovered PyLan network nodes."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Callable, Optional
|
|
4
|
+
|
|
5
|
+
import flet as ft
|
|
6
|
+
|
|
7
|
+
from pylan.core.models import StatefulDevice
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def create_peer_tile(
|
|
11
|
+
device: StatefulDevice,
|
|
12
|
+
is_selected: bool = False,
|
|
13
|
+
on_select: Optional[Callable[[StatefulDevice], None]] = None,
|
|
14
|
+
on_quick_send: Optional[Callable[[StatefulDevice], None]] = None,
|
|
15
|
+
) -> ft.Control:
|
|
16
|
+
"""Create a card widget representing a discovered network peer.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
device: Discovered StatefulDevice model instance.
|
|
20
|
+
is_selected: Whether this peer is currently marked as target.
|
|
21
|
+
on_select: Callback fired when the tile is clicked.
|
|
22
|
+
on_quick_send: Optional callback fired on quick-send action.
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
A styled Flet Container control.
|
|
26
|
+
"""
|
|
27
|
+
dev = device.device
|
|
28
|
+
alias = getattr(dev, "alias", "Unknown Peer")
|
|
29
|
+
model = getattr(dev, "device_model", "PyLan Node") or "PyLan Node"
|
|
30
|
+
fingerprint = getattr(dev, "fingerprint", "N/A")[:8]
|
|
31
|
+
channel = getattr(dev, "channel", None)
|
|
32
|
+
address = f"{channel.host}:{channel.port}" if channel else "Unknown"
|
|
33
|
+
|
|
34
|
+
border_color = (
|
|
35
|
+
ft.Colors.PRIMARY if is_selected else ft.Colors.OUTLINE_VARIANT
|
|
36
|
+
)
|
|
37
|
+
bg_color = (
|
|
38
|
+
ft.Colors.SURFACE_CONTAINER_HIGHEST
|
|
39
|
+
if is_selected
|
|
40
|
+
else ft.Colors.SURFACE_CONTAINER
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
def handle_click(_: Any = None) -> None:
|
|
44
|
+
if on_select is not None:
|
|
45
|
+
on_select(device)
|
|
46
|
+
|
|
47
|
+
def handle_send_click(_: Any = None) -> None:
|
|
48
|
+
if on_quick_send is not None:
|
|
49
|
+
on_quick_send(device)
|
|
50
|
+
|
|
51
|
+
actions: list[ft.Control] = [
|
|
52
|
+
ft.Container(
|
|
53
|
+
content=ft.Row(
|
|
54
|
+
controls=[
|
|
55
|
+
ft.Icon(
|
|
56
|
+
ft.Icons.CIRCLE,
|
|
57
|
+
size=8,
|
|
58
|
+
color=ft.Colors.GREEN_ACCENT_400,
|
|
59
|
+
),
|
|
60
|
+
ft.Text(
|
|
61
|
+
"ONLINE",
|
|
62
|
+
size=10,
|
|
63
|
+
weight=ft.FontWeight.W_600,
|
|
64
|
+
color=ft.Colors.GREEN_ACCENT_400,
|
|
65
|
+
),
|
|
66
|
+
],
|
|
67
|
+
spacing=4,
|
|
68
|
+
),
|
|
69
|
+
padding=ft.Padding.symmetric(horizontal=8, vertical=4),
|
|
70
|
+
border_radius=8,
|
|
71
|
+
bgcolor=(
|
|
72
|
+
ft.Colors.GREEN_900
|
|
73
|
+
if is_selected
|
|
74
|
+
else ft.Colors.SURFACE_CONTAINER_HIGH
|
|
75
|
+
),
|
|
76
|
+
)
|
|
77
|
+
]
|
|
78
|
+
|
|
79
|
+
if on_quick_send is not None:
|
|
80
|
+
actions.append(
|
|
81
|
+
ft.IconButton(
|
|
82
|
+
icon=ft.Icons.SEND_ROUNDED,
|
|
83
|
+
tooltip="Send files to this device",
|
|
84
|
+
icon_color=ft.Colors.PRIMARY,
|
|
85
|
+
on_click=handle_send_click,
|
|
86
|
+
)
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
return ft.Container(
|
|
90
|
+
content=ft.Row(
|
|
91
|
+
controls=[
|
|
92
|
+
ft.Container(
|
|
93
|
+
content=ft.Icon(
|
|
94
|
+
ft.Icons.DEVICES_ROUNDED,
|
|
95
|
+
size=28,
|
|
96
|
+
color=ft.Colors.PRIMARY,
|
|
97
|
+
),
|
|
98
|
+
padding=10,
|
|
99
|
+
border_radius=10,
|
|
100
|
+
bgcolor=ft.Colors.PRIMARY_CONTAINER,
|
|
101
|
+
),
|
|
102
|
+
ft.Column(
|
|
103
|
+
controls=[
|
|
104
|
+
ft.Row(
|
|
105
|
+
controls=[
|
|
106
|
+
ft.Text(
|
|
107
|
+
alias,
|
|
108
|
+
size=15,
|
|
109
|
+
weight=ft.FontWeight.BOLD,
|
|
110
|
+
color=ft.Colors.ON_SURFACE,
|
|
111
|
+
overflow=ft.TextOverflow.ELLIPSIS,
|
|
112
|
+
max_lines=1,
|
|
113
|
+
),
|
|
114
|
+
ft.Container(
|
|
115
|
+
content=ft.Text(
|
|
116
|
+
f"#{fingerprint}",
|
|
117
|
+
size=10,
|
|
118
|
+
color=ft.Colors.ON_SURFACE_VARIANT,
|
|
119
|
+
),
|
|
120
|
+
padding=ft.Padding.symmetric(
|
|
121
|
+
horizontal=6, vertical=2
|
|
122
|
+
),
|
|
123
|
+
border_radius=6,
|
|
124
|
+
bgcolor=ft.Colors.SURFACE_CONTAINER_HIGH,
|
|
125
|
+
),
|
|
126
|
+
],
|
|
127
|
+
spacing=8,
|
|
128
|
+
alignment=ft.MainAxisAlignment.START,
|
|
129
|
+
),
|
|
130
|
+
ft.Text(
|
|
131
|
+
f"{model} • {address}",
|
|
132
|
+
size=12,
|
|
133
|
+
color=ft.Colors.ON_SURFACE_VARIANT,
|
|
134
|
+
overflow=ft.TextOverflow.ELLIPSIS,
|
|
135
|
+
max_lines=1,
|
|
136
|
+
),
|
|
137
|
+
],
|
|
138
|
+
spacing=2,
|
|
139
|
+
expand=True,
|
|
140
|
+
),
|
|
141
|
+
ft.Row(controls=actions, spacing=6),
|
|
142
|
+
],
|
|
143
|
+
alignment=ft.MainAxisAlignment.SPACE_BETWEEN,
|
|
144
|
+
vertical_alignment=ft.CrossAxisAlignment.CENTER,
|
|
145
|
+
),
|
|
146
|
+
padding=12,
|
|
147
|
+
border_radius=12,
|
|
148
|
+
bgcolor=bg_color,
|
|
149
|
+
border=ft.Border.all(1.5 if is_selected else 1.0, border_color),
|
|
150
|
+
ink=True,
|
|
151
|
+
on_click=handle_click,
|
|
152
|
+
)
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"""Transfer row widget displaying progress and controls for file transfers."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import subprocess
|
|
5
|
+
from typing import Any, Callable, Optional
|
|
6
|
+
|
|
7
|
+
import flet as ft
|
|
8
|
+
|
|
9
|
+
from pylan.ui.state import TransferDirection, TransferItem, TransferStatus
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def create_transfer_row(
|
|
13
|
+
item: TransferItem,
|
|
14
|
+
on_accept: Optional[Callable[[str], None]] = None,
|
|
15
|
+
on_reject: Optional[Callable[[str], None]] = None,
|
|
16
|
+
on_cancel: Optional[Callable[[str], None]] = None,
|
|
17
|
+
on_open_folder: Optional[Callable[[str], None]] = None,
|
|
18
|
+
) -> ft.Control:
|
|
19
|
+
"""Create a row widget representing a file transfer session.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
item: TransferItem model instance containing session metadata.
|
|
23
|
+
on_accept: Optional callback fired when accepting incoming transfer.
|
|
24
|
+
on_reject: Optional callback fired when rejecting incoming transfer.
|
|
25
|
+
on_cancel: Optional callback fired to cancel an in-progress transfer.
|
|
26
|
+
on_open_folder: Optional callback to reveal file in system explorer.
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
A styled Flet Container control.
|
|
30
|
+
"""
|
|
31
|
+
is_send = item.direction == TransferDirection.SEND
|
|
32
|
+
icon = ft.Icons.UPLOAD_ROUNDED if is_send else ft.Icons.DOWNLOAD_ROUNDED
|
|
33
|
+
icon_color = ft.Colors.CYAN_300 if is_send else ft.Colors.BLUE_300
|
|
34
|
+
|
|
35
|
+
def default_open_folder(_: Any = None) -> None:
|
|
36
|
+
if on_open_folder is not None:
|
|
37
|
+
on_open_folder(item.file_path)
|
|
38
|
+
return
|
|
39
|
+
folder = os.path.dirname(item.file_path)
|
|
40
|
+
if os.path.exists(folder):
|
|
41
|
+
try:
|
|
42
|
+
if os.name == "nt":
|
|
43
|
+
os.startfile(folder) # type: ignore[attr-defined]
|
|
44
|
+
else:
|
|
45
|
+
subprocess.Popen(["xdg-open", folder])
|
|
46
|
+
except Exception:
|
|
47
|
+
pass
|
|
48
|
+
|
|
49
|
+
status_badge: ft.Control
|
|
50
|
+
action_controls: list[ft.Control] = []
|
|
51
|
+
|
|
52
|
+
if item.status == TransferStatus.TRANSFERRING:
|
|
53
|
+
pct = int(item.progress * 100)
|
|
54
|
+
status_badge = ft.Row(
|
|
55
|
+
controls=[
|
|
56
|
+
ft.Text(
|
|
57
|
+
f"{pct}%",
|
|
58
|
+
size=12,
|
|
59
|
+
weight=ft.FontWeight.BOLD,
|
|
60
|
+
color=ft.Colors.PRIMARY,
|
|
61
|
+
),
|
|
62
|
+
ft.Text(
|
|
63
|
+
f"({item.formatted_speed})",
|
|
64
|
+
size=11,
|
|
65
|
+
color=ft.Colors.ON_SURFACE_VARIANT,
|
|
66
|
+
),
|
|
67
|
+
],
|
|
68
|
+
spacing=4,
|
|
69
|
+
)
|
|
70
|
+
if on_cancel is not None:
|
|
71
|
+
action_controls.append(
|
|
72
|
+
ft.IconButton(
|
|
73
|
+
icon=ft.Icons.CLOSE_ROUNDED,
|
|
74
|
+
icon_size=18,
|
|
75
|
+
tooltip="Cancel transfer",
|
|
76
|
+
on_click=lambda _: on_cancel(item.id),
|
|
77
|
+
)
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
elif item.status == TransferStatus.COMPLETED:
|
|
81
|
+
status_badge = ft.Row(
|
|
82
|
+
controls=[
|
|
83
|
+
ft.Icon(
|
|
84
|
+
ft.Icons.CHECK_CIRCLE_ROUNDED,
|
|
85
|
+
size=16,
|
|
86
|
+
color=ft.Colors.GREEN_400,
|
|
87
|
+
),
|
|
88
|
+
ft.Text("Completed", size=12, color=ft.Colors.GREEN_400),
|
|
89
|
+
],
|
|
90
|
+
spacing=4,
|
|
91
|
+
)
|
|
92
|
+
action_controls.append(
|
|
93
|
+
ft.IconButton(
|
|
94
|
+
icon=ft.Icons.FOLDER_OPEN_ROUNDED,
|
|
95
|
+
icon_size=18,
|
|
96
|
+
tooltip="Open containing folder",
|
|
97
|
+
on_click=default_open_folder,
|
|
98
|
+
)
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
elif item.status == TransferStatus.PENDING:
|
|
102
|
+
if item.direction == TransferDirection.RECEIVE:
|
|
103
|
+
status_badge = ft.Text(
|
|
104
|
+
"Awaiting approval",
|
|
105
|
+
size=12,
|
|
106
|
+
weight=ft.FontWeight.W_600,
|
|
107
|
+
color=ft.Colors.AMBER_400,
|
|
108
|
+
)
|
|
109
|
+
if on_accept is not None:
|
|
110
|
+
action_controls.append(
|
|
111
|
+
ft.FilledButton(
|
|
112
|
+
"Accept",
|
|
113
|
+
icon=ft.Icons.CHECK,
|
|
114
|
+
height=30,
|
|
115
|
+
on_click=lambda _: on_accept(item.id),
|
|
116
|
+
)
|
|
117
|
+
)
|
|
118
|
+
if on_reject is not None:
|
|
119
|
+
action_controls.append(
|
|
120
|
+
ft.OutlinedButton(
|
|
121
|
+
"Decline",
|
|
122
|
+
icon=ft.Icons.CLOSE,
|
|
123
|
+
height=30,
|
|
124
|
+
on_click=lambda _: on_reject(item.id),
|
|
125
|
+
)
|
|
126
|
+
)
|
|
127
|
+
else:
|
|
128
|
+
status_badge = ft.Text(
|
|
129
|
+
"Connecting...", size=12, color=ft.Colors.AMBER_300
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
elif item.status == TransferStatus.REJECTED:
|
|
133
|
+
status_badge = ft.Row(
|
|
134
|
+
controls=[
|
|
135
|
+
ft.Icon(
|
|
136
|
+
ft.Icons.CANCEL_ROUNDED,
|
|
137
|
+
size=16,
|
|
138
|
+
color=ft.Colors.ORANGE_400,
|
|
139
|
+
),
|
|
140
|
+
ft.Text("Declined", size=12, color=ft.Colors.ORANGE_400),
|
|
141
|
+
],
|
|
142
|
+
spacing=4,
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
else:
|
|
146
|
+
status_badge = ft.Row(
|
|
147
|
+
controls=[
|
|
148
|
+
ft.Icon(
|
|
149
|
+
ft.Icons.ERROR_OUTLINE_ROUNDED,
|
|
150
|
+
size=16,
|
|
151
|
+
color=ft.Colors.RED_400,
|
|
152
|
+
),
|
|
153
|
+
ft.Text(
|
|
154
|
+
item.error_message or "Failed",
|
|
155
|
+
size=12,
|
|
156
|
+
color=ft.Colors.RED_400,
|
|
157
|
+
),
|
|
158
|
+
],
|
|
159
|
+
spacing=4,
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
# Progress bar displayed when active
|
|
163
|
+
progress_bar = (
|
|
164
|
+
ft.ProgressBar(
|
|
165
|
+
value=item.progress,
|
|
166
|
+
bgcolor=ft.Colors.SURFACE_CONTAINER_HIGH,
|
|
167
|
+
color=ft.Colors.PRIMARY,
|
|
168
|
+
height=4,
|
|
169
|
+
border_radius=2,
|
|
170
|
+
)
|
|
171
|
+
if item.status == TransferStatus.TRANSFERRING
|
|
172
|
+
else ft.Container(height=0)
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
direction_label = "To" if is_send else "From"
|
|
176
|
+
|
|
177
|
+
return ft.Container(
|
|
178
|
+
content=ft.Column(
|
|
179
|
+
controls=[
|
|
180
|
+
ft.Row(
|
|
181
|
+
controls=[
|
|
182
|
+
ft.Container(
|
|
183
|
+
content=ft.Icon(icon, size=24, color=icon_color),
|
|
184
|
+
padding=8,
|
|
185
|
+
border_radius=8,
|
|
186
|
+
bgcolor=ft.Colors.SURFACE_CONTAINER_HIGH,
|
|
187
|
+
),
|
|
188
|
+
ft.Column(
|
|
189
|
+
controls=[
|
|
190
|
+
ft.Text(
|
|
191
|
+
item.file_name,
|
|
192
|
+
size=14,
|
|
193
|
+
weight=ft.FontWeight.W_600,
|
|
194
|
+
color=ft.Colors.ON_SURFACE,
|
|
195
|
+
overflow=ft.TextOverflow.ELLIPSIS,
|
|
196
|
+
max_lines=1,
|
|
197
|
+
),
|
|
198
|
+
ft.Text(
|
|
199
|
+
f"{item.formatted_size} • "
|
|
200
|
+
f"{direction_label} {item.peer_alias}",
|
|
201
|
+
size=12,
|
|
202
|
+
color=ft.Colors.ON_SURFACE_VARIANT,
|
|
203
|
+
overflow=ft.TextOverflow.ELLIPSIS,
|
|
204
|
+
max_lines=1,
|
|
205
|
+
),
|
|
206
|
+
],
|
|
207
|
+
spacing=2,
|
|
208
|
+
expand=True,
|
|
209
|
+
),
|
|
210
|
+
status_badge,
|
|
211
|
+
ft.Row(controls=action_controls, spacing=4),
|
|
212
|
+
],
|
|
213
|
+
alignment=ft.MainAxisAlignment.SPACE_BETWEEN,
|
|
214
|
+
vertical_alignment=ft.CrossAxisAlignment.CENTER,
|
|
215
|
+
),
|
|
216
|
+
progress_bar,
|
|
217
|
+
],
|
|
218
|
+
spacing=8,
|
|
219
|
+
),
|
|
220
|
+
padding=12,
|
|
221
|
+
border_radius=10,
|
|
222
|
+
bgcolor=ft.Colors.SURFACE_CONTAINER,
|
|
223
|
+
border=ft.Border.all(1, ft.Colors.OUTLINE_VARIANT),
|
|
224
|
+
)
|