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
pylan/ui/__init__.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""PyLan Flet Graphical User Interface (GUI) module.
|
|
2
|
+
|
|
3
|
+
This module provides modern desktop and web interfaces for local area network
|
|
4
|
+
peer discovery, file transmission, and incoming transfer management.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from pylan.ui.app import main
|
|
8
|
+
from pylan.ui.state import (
|
|
9
|
+
AppState,
|
|
10
|
+
TransferDirection,
|
|
11
|
+
TransferItem,
|
|
12
|
+
TransferStatus,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
__all__: list[str] = [
|
|
16
|
+
"AppState",
|
|
17
|
+
"TransferDirection",
|
|
18
|
+
"TransferItem",
|
|
19
|
+
"TransferStatus",
|
|
20
|
+
"main",
|
|
21
|
+
]
|
pylan/ui/app.py
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"""Flet desktop application entrypoint and main window setup for PyLan."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
import flet as ft
|
|
7
|
+
|
|
8
|
+
from pylan.core.models import StatefulDevice
|
|
9
|
+
from pylan.ui.components.file_picker import FilePickerComponent
|
|
10
|
+
from pylan.ui.components.navbar import create_top_bar
|
|
11
|
+
from pylan.ui.state import AppState
|
|
12
|
+
from pylan.ui.views.home_view import create_home_view
|
|
13
|
+
from pylan.ui.views.receive_view import create_receive_view
|
|
14
|
+
from pylan.ui.views.send_view import create_send_view
|
|
15
|
+
from pylan.ui.views.settings_view import create_settings_view
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def main(page: ft.Page) -> None:
|
|
19
|
+
"""Initialize and run the PyLan Flet user interface.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
page: Active root Page provided by the Flet runtime.
|
|
23
|
+
"""
|
|
24
|
+
page.title = "pylan"
|
|
25
|
+
page.theme_mode = ft.ThemeMode.DARK
|
|
26
|
+
page.bgcolor = ft.Colors.SURFACE_CONTAINER
|
|
27
|
+
page.padding = 0
|
|
28
|
+
|
|
29
|
+
assets_dir = Path(__file__).parent / "assets"
|
|
30
|
+
ico_file = assets_dir / "icon.ico"
|
|
31
|
+
png_file = assets_dir / "icon.png"
|
|
32
|
+
|
|
33
|
+
if hasattr(page, "window"):
|
|
34
|
+
page.window.width = 900
|
|
35
|
+
page.window.height = 680
|
|
36
|
+
page.window.min_width = 650
|
|
37
|
+
page.window.min_height = 540
|
|
38
|
+
if ico_file.exists():
|
|
39
|
+
page.window.icon = str(ico_file)
|
|
40
|
+
elif png_file.exists():
|
|
41
|
+
page.window.icon = str(png_file)
|
|
42
|
+
|
|
43
|
+
state = AppState()
|
|
44
|
+
|
|
45
|
+
file_picker_comp = FilePickerComponent()
|
|
46
|
+
file_picker_comp.attach_to_page(page)
|
|
47
|
+
|
|
48
|
+
folder_picker = ft.FilePicker()
|
|
49
|
+
if hasattr(page, "services") and folder_picker not in page.services:
|
|
50
|
+
page.services.append(folder_picker)
|
|
51
|
+
|
|
52
|
+
active_page: list[str] = ["home"]
|
|
53
|
+
content_area = ft.Container(expand=True)
|
|
54
|
+
top_bar_container = ft.Container()
|
|
55
|
+
|
|
56
|
+
def go_home() -> None:
|
|
57
|
+
active_page[0] = "home"
|
|
58
|
+
render_current_view()
|
|
59
|
+
page.update()
|
|
60
|
+
|
|
61
|
+
def go_send() -> None:
|
|
62
|
+
active_page[0] = "send"
|
|
63
|
+
render_current_view()
|
|
64
|
+
page.update()
|
|
65
|
+
|
|
66
|
+
def go_receive() -> None:
|
|
67
|
+
active_page[0] = "receive"
|
|
68
|
+
render_current_view()
|
|
69
|
+
page.update()
|
|
70
|
+
|
|
71
|
+
def go_settings() -> None:
|
|
72
|
+
active_page[0] = "settings"
|
|
73
|
+
render_current_view()
|
|
74
|
+
page.update()
|
|
75
|
+
|
|
76
|
+
def switch_to_send_with_peer(device: StatefulDevice) -> None:
|
|
77
|
+
state.select_device(device)
|
|
78
|
+
go_send()
|
|
79
|
+
|
|
80
|
+
def render_current_view() -> None:
|
|
81
|
+
current = active_page[0]
|
|
82
|
+
cur_width = page.width
|
|
83
|
+
if current == "send":
|
|
84
|
+
top_bar_container.content = create_top_bar(
|
|
85
|
+
state=state,
|
|
86
|
+
on_scan_click=state.trigger_discovery,
|
|
87
|
+
on_settings_click=go_settings,
|
|
88
|
+
on_back_click=go_home,
|
|
89
|
+
title="Send Files",
|
|
90
|
+
page_width=cur_width,
|
|
91
|
+
)
|
|
92
|
+
content_area.content = create_send_view(
|
|
93
|
+
state=state,
|
|
94
|
+
picker_component=file_picker_comp,
|
|
95
|
+
on_back_click=go_home,
|
|
96
|
+
page_width=cur_width,
|
|
97
|
+
)
|
|
98
|
+
elif current == "receive":
|
|
99
|
+
top_bar_container.content = create_top_bar(
|
|
100
|
+
state=state,
|
|
101
|
+
on_scan_click=state.trigger_discovery,
|
|
102
|
+
on_settings_click=go_settings,
|
|
103
|
+
on_back_click=go_home,
|
|
104
|
+
title="Receive Files",
|
|
105
|
+
page_width=cur_width,
|
|
106
|
+
)
|
|
107
|
+
content_area.content = create_receive_view(
|
|
108
|
+
state=state,
|
|
109
|
+
on_back_click=go_home,
|
|
110
|
+
page_width=cur_width,
|
|
111
|
+
)
|
|
112
|
+
elif current == "settings":
|
|
113
|
+
top_bar_container.content = create_top_bar(
|
|
114
|
+
state=state,
|
|
115
|
+
on_scan_click=state.trigger_discovery,
|
|
116
|
+
on_settings_click=go_home,
|
|
117
|
+
on_back_click=go_home,
|
|
118
|
+
title="Settings",
|
|
119
|
+
page_width=cur_width,
|
|
120
|
+
)
|
|
121
|
+
content_area.content = create_settings_view(
|
|
122
|
+
state=state,
|
|
123
|
+
folder_picker=folder_picker,
|
|
124
|
+
on_back_click=go_home,
|
|
125
|
+
page_width=cur_width,
|
|
126
|
+
)
|
|
127
|
+
else:
|
|
128
|
+
top_bar_container.content = create_top_bar(
|
|
129
|
+
state=state,
|
|
130
|
+
on_scan_click=state.trigger_discovery,
|
|
131
|
+
on_settings_click=go_settings,
|
|
132
|
+
page_width=cur_width,
|
|
133
|
+
)
|
|
134
|
+
content_area.content = create_home_view(
|
|
135
|
+
state=state,
|
|
136
|
+
on_send_click=go_send,
|
|
137
|
+
on_receive_click=go_receive,
|
|
138
|
+
on_quick_send=switch_to_send_with_peer,
|
|
139
|
+
page_width=cur_width,
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
def handle_state_change() -> None:
|
|
143
|
+
render_current_view()
|
|
144
|
+
try:
|
|
145
|
+
page.update()
|
|
146
|
+
except Exception:
|
|
147
|
+
pass
|
|
148
|
+
|
|
149
|
+
def handle_resize(_: Any = None) -> None:
|
|
150
|
+
render_current_view()
|
|
151
|
+
try:
|
|
152
|
+
page.update()
|
|
153
|
+
except Exception:
|
|
154
|
+
pass
|
|
155
|
+
|
|
156
|
+
page.on_resize = handle_resize
|
|
157
|
+
state.add_listener(handle_state_change)
|
|
158
|
+
|
|
159
|
+
render_current_view()
|
|
160
|
+
|
|
161
|
+
layout = ft.SafeArea(
|
|
162
|
+
content=ft.Column(
|
|
163
|
+
controls=[
|
|
164
|
+
top_bar_container,
|
|
165
|
+
content_area,
|
|
166
|
+
],
|
|
167
|
+
expand=True,
|
|
168
|
+
spacing=0,
|
|
169
|
+
),
|
|
170
|
+
expand=True,
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
page.add(layout)
|
|
174
|
+
|
|
175
|
+
# Lifecycle management
|
|
176
|
+
state.start_services()
|
|
177
|
+
state.trigger_discovery()
|
|
178
|
+
|
|
179
|
+
def cleanup() -> None:
|
|
180
|
+
state.remove_listener(handle_state_change)
|
|
181
|
+
state.stop_services()
|
|
182
|
+
|
|
183
|
+
page.on_disconnect = lambda _: cleanup()
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
if __name__ == "__main__":
|
|
187
|
+
assets_path = str(Path(__file__).parent / "assets")
|
|
188
|
+
ft.run(main, assets_dir=assets_path)
|
pylan/ui/assets/icon.ico
ADDED
|
Binary file
|
pylan/ui/assets/icon.png
ADDED
|
Binary file
|
pylan/ui/assets/logo.svg
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 100" width="400" height="100">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="pylan-grad" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
4
|
+
<stop offset="0%" stop-color="#00E5FF" />
|
|
5
|
+
<stop offset="50%" stop-color="#2979FF" />
|
|
6
|
+
<stop offset="100%" stop-color="#7C4DFF" />
|
|
7
|
+
</linearGradient>
|
|
8
|
+
<linearGradient id="glow-grad" x1="0%" y1="0%" x2="100%" y2="0%">
|
|
9
|
+
<stop offset="0%" stop-color="#00E5FF" stop-opacity="0.8" />
|
|
10
|
+
<stop offset="100%" stop-color="#2979FF" stop-opacity="0.2" />
|
|
11
|
+
</linearGradient>
|
|
12
|
+
<filter id="glow" x="-20%" y="-20%" width="140%" height="140%">
|
|
13
|
+
<feGaussianBlur stdDeviation="4" result="blur" />
|
|
14
|
+
<feComposite in="SourceGraphic" in2="blur" operator="over" />
|
|
15
|
+
</filter>
|
|
16
|
+
</defs>
|
|
17
|
+
|
|
18
|
+
<!-- Node Icon Group -->
|
|
19
|
+
<g transform="translate(15, 10)">
|
|
20
|
+
<!-- Interconnecting Data Paths -->
|
|
21
|
+
<path d="M 40 25 L 65 55" stroke="url(#pylan-grad)" stroke-width="4" stroke-linecap="round" stroke-dasharray="2 6" opacity="0.8" />
|
|
22
|
+
<path d="M 40 25 L 15 55" stroke="url(#pylan-grad)" stroke-width="4" stroke-linecap="round" />
|
|
23
|
+
<path d="M 15 55 L 65 55" stroke="url(#pylan-grad)" stroke-width="4" stroke-linecap="round" />
|
|
24
|
+
<path d="M 40 55 L 40 30" stroke="#00E5FF" stroke-width="3" stroke-linecap="round" />
|
|
25
|
+
|
|
26
|
+
<!-- Top Node -->
|
|
27
|
+
<circle cx="40" cy="22" r="14" fill="#0D1117" stroke="url(#pylan-grad)" stroke-width="4" filter="url(#glow)" />
|
|
28
|
+
<circle cx="40" cy="22" r="6" fill="#00E5FF" />
|
|
29
|
+
|
|
30
|
+
<!-- Left Bottom Node -->
|
|
31
|
+
<circle cx="15" cy="58" r="12" fill="#0D1117" stroke="#2979FF" stroke-width="3.5" />
|
|
32
|
+
<circle cx="15" cy="58" r="5" fill="#2979FF" />
|
|
33
|
+
|
|
34
|
+
<!-- Right Bottom Node -->
|
|
35
|
+
<circle cx="65" cy="58" r="12" fill="#0D1117" stroke="#7C4DFF" stroke-width="3.5" />
|
|
36
|
+
<circle cx="65" cy="58" r="5" fill="#7C4DFF" />
|
|
37
|
+
|
|
38
|
+
<!-- Pulse Ring -->
|
|
39
|
+
<circle cx="40" cy="22" r="19" fill="none" stroke="#00E5FF" stroke-width="1.5" opacity="0.4" stroke-dasharray="4 4" />
|
|
40
|
+
</g>
|
|
41
|
+
|
|
42
|
+
<!-- Typography -->
|
|
43
|
+
<g transform="translate(110, 62)">
|
|
44
|
+
<text font-family="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="44" font-weight="800" fill="#FFFFFF" letter-spacing="0.5">
|
|
45
|
+
Py<tspan fill="url(#pylan-grad)">Lan</tspan>
|
|
46
|
+
</text>
|
|
47
|
+
<text x="145" y="-2" font-family="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="12" font-weight="600" fill="#00E5FF" letter-spacing="1.5" text-transform="uppercase">
|
|
48
|
+
LAN SHARE
|
|
49
|
+
</text>
|
|
50
|
+
</g>
|
|
51
|
+
</svg>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""Reusable Flet UI components and widgets for PyLan."""
|
|
2
|
+
|
|
3
|
+
from pylan.ui.components.file_picker import FilePickerComponent
|
|
4
|
+
from pylan.ui.components.navbar import create_navigation_rail, create_top_bar
|
|
5
|
+
from pylan.ui.components.peer_tile import create_peer_tile
|
|
6
|
+
from pylan.ui.components.transfer_row import create_transfer_row
|
|
7
|
+
|
|
8
|
+
__all__: list[str] = [
|
|
9
|
+
"FilePickerComponent",
|
|
10
|
+
"create_navigation_rail",
|
|
11
|
+
"create_peer_tile",
|
|
12
|
+
"create_top_bar",
|
|
13
|
+
"create_transfer_row",
|
|
14
|
+
]
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
"""Custom file selector and drag-and-drop drop zone widget for PyLan."""
|
|
2
|
+
|
|
3
|
+
import inspect
|
|
4
|
+
import logging
|
|
5
|
+
import os
|
|
6
|
+
from typing import Any, Callable, Optional
|
|
7
|
+
|
|
8
|
+
import flet as ft
|
|
9
|
+
|
|
10
|
+
from pylan.ui.state import format_bytes
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class FilePickerComponent:
|
|
16
|
+
"""Component for picking, queuing, and managing local files to transmit.
|
|
17
|
+
|
|
18
|
+
Integrates with Flet's FilePicker service and renders a dashed drop
|
|
19
|
+
zone container alongside a list of selected files and removal controls.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def __init__(
|
|
23
|
+
self,
|
|
24
|
+
on_files_changed: Optional[Callable[[list[str]], None]] = None,
|
|
25
|
+
) -> None:
|
|
26
|
+
"""Initialize the file picker component.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
on_files_changed: Optional callback fired when file queue changes.
|
|
30
|
+
"""
|
|
31
|
+
self.selected_paths: list[str] = []
|
|
32
|
+
self.on_files_changed = on_files_changed
|
|
33
|
+
|
|
34
|
+
self.picker = ft.FilePicker(on_result=self._handle_picker_result)
|
|
35
|
+
self._files_list_view = ft.Column(spacing=6)
|
|
36
|
+
self._summary_text = ft.Text(
|
|
37
|
+
"No files selected",
|
|
38
|
+
size=12,
|
|
39
|
+
color=ft.Colors.ON_SURFACE_VARIANT,
|
|
40
|
+
)
|
|
41
|
+
self._clear_btn = ft.TextButton(
|
|
42
|
+
"Clear all",
|
|
43
|
+
icon=ft.Icons.CLEAR_ALL_ROUNDED,
|
|
44
|
+
visible=False,
|
|
45
|
+
on_click=lambda _: self.clear_files(),
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
def attach_to_page(self, page: ft.Page) -> None:
|
|
49
|
+
"""Register the underlying FilePicker service with page services.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
page: Active Flet Page instance.
|
|
53
|
+
"""
|
|
54
|
+
if hasattr(page, "services") and self.picker not in page.services:
|
|
55
|
+
page.services.append(self.picker)
|
|
56
|
+
|
|
57
|
+
async def open_picker(self, _: Any = None) -> None:
|
|
58
|
+
"""Open the native file selection dialog."""
|
|
59
|
+
try:
|
|
60
|
+
res = self.picker.pick_files(allow_multiple=True)
|
|
61
|
+
files = await res if inspect.isawaitable(res) else res
|
|
62
|
+
if files:
|
|
63
|
+
for f in files:
|
|
64
|
+
p = getattr(f, "path", None)
|
|
65
|
+
if (
|
|
66
|
+
p
|
|
67
|
+
and os.path.exists(p)
|
|
68
|
+
and p not in self.selected_paths
|
|
69
|
+
):
|
|
70
|
+
self.selected_paths.append(p)
|
|
71
|
+
self._update_ui()
|
|
72
|
+
if self.on_files_changed:
|
|
73
|
+
self.on_files_changed(list(self.selected_paths))
|
|
74
|
+
except Exception as exc:
|
|
75
|
+
logger.debug("Error during pick_files: %s", exc)
|
|
76
|
+
|
|
77
|
+
def _handle_picker_result(self, e: Any = None) -> None:
|
|
78
|
+
"""Callback processing selected files from OS dialog."""
|
|
79
|
+
files = getattr(e, "files", None)
|
|
80
|
+
if files:
|
|
81
|
+
new_paths = [
|
|
82
|
+
f.path
|
|
83
|
+
for f in files
|
|
84
|
+
if getattr(f, "path", None) and os.path.exists(f.path)
|
|
85
|
+
]
|
|
86
|
+
for path in new_paths:
|
|
87
|
+
if path not in self.selected_paths:
|
|
88
|
+
self.selected_paths.append(path)
|
|
89
|
+
self._update_ui()
|
|
90
|
+
if self.on_files_changed:
|
|
91
|
+
self.on_files_changed(list(self.selected_paths))
|
|
92
|
+
|
|
93
|
+
def remove_file(self, path: str) -> None:
|
|
94
|
+
"""Remove a single file path from the queued list.
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
path: Local file path to remove.
|
|
98
|
+
"""
|
|
99
|
+
if path in self.selected_paths:
|
|
100
|
+
self.selected_paths.remove(path)
|
|
101
|
+
self._update_ui()
|
|
102
|
+
if self.on_files_changed:
|
|
103
|
+
self.on_files_changed(list(self.selected_paths))
|
|
104
|
+
|
|
105
|
+
def clear_files(self) -> None:
|
|
106
|
+
"""Remove all files from the queue."""
|
|
107
|
+
self.selected_paths.clear()
|
|
108
|
+
self._update_ui()
|
|
109
|
+
if self.on_files_changed:
|
|
110
|
+
self.on_files_changed([])
|
|
111
|
+
|
|
112
|
+
def _update_ui(self) -> None:
|
|
113
|
+
"""Re-render the list items and summary information."""
|
|
114
|
+
self._files_list_view.controls.clear()
|
|
115
|
+
|
|
116
|
+
total_bytes = 0
|
|
117
|
+
for path in self.selected_paths:
|
|
118
|
+
try:
|
|
119
|
+
size = os.path.getsize(path)
|
|
120
|
+
total_bytes += size
|
|
121
|
+
size_str = format_bytes(size)
|
|
122
|
+
except OSError:
|
|
123
|
+
size_str = "Unknown size"
|
|
124
|
+
|
|
125
|
+
file_name = os.path.basename(path)
|
|
126
|
+
row = ft.Container(
|
|
127
|
+
content=ft.Row(
|
|
128
|
+
controls=[
|
|
129
|
+
ft.Icon(
|
|
130
|
+
ft.Icons.INSERT_DRIVE_FILE_ROUNDED,
|
|
131
|
+
size=20,
|
|
132
|
+
color=ft.Colors.PRIMARY,
|
|
133
|
+
),
|
|
134
|
+
ft.Column(
|
|
135
|
+
controls=[
|
|
136
|
+
ft.Text(
|
|
137
|
+
file_name,
|
|
138
|
+
size=13,
|
|
139
|
+
weight=ft.FontWeight.W_500,
|
|
140
|
+
color=ft.Colors.ON_SURFACE,
|
|
141
|
+
overflow=ft.TextOverflow.ELLIPSIS,
|
|
142
|
+
max_lines=1,
|
|
143
|
+
),
|
|
144
|
+
ft.Text(
|
|
145
|
+
f"{size_str} • {path}",
|
|
146
|
+
size=11,
|
|
147
|
+
color=ft.Colors.ON_SURFACE_VARIANT,
|
|
148
|
+
overflow=ft.TextOverflow.ELLIPSIS,
|
|
149
|
+
max_lines=1,
|
|
150
|
+
),
|
|
151
|
+
],
|
|
152
|
+
spacing=1,
|
|
153
|
+
expand=True,
|
|
154
|
+
),
|
|
155
|
+
ft.IconButton(
|
|
156
|
+
icon=ft.Icons.CLOSE_ROUNDED,
|
|
157
|
+
icon_size=18,
|
|
158
|
+
tooltip="Remove file",
|
|
159
|
+
on_click=lambda _, p=path: self.remove_file(p),
|
|
160
|
+
),
|
|
161
|
+
],
|
|
162
|
+
alignment=ft.MainAxisAlignment.SPACE_BETWEEN,
|
|
163
|
+
vertical_alignment=ft.CrossAxisAlignment.CENTER,
|
|
164
|
+
),
|
|
165
|
+
padding=ft.Padding.symmetric(horizontal=10, vertical=6),
|
|
166
|
+
border_radius=8,
|
|
167
|
+
bgcolor=ft.Colors.SURFACE_CONTAINER_HIGH,
|
|
168
|
+
)
|
|
169
|
+
self._files_list_view.controls.append(row)
|
|
170
|
+
|
|
171
|
+
count = len(self.selected_paths)
|
|
172
|
+
if count == 0:
|
|
173
|
+
self._summary_text.value = "No files selected"
|
|
174
|
+
self._clear_btn.visible = False
|
|
175
|
+
else:
|
|
176
|
+
total_str = format_bytes(total_bytes)
|
|
177
|
+
plural = "s" if count > 1 else ""
|
|
178
|
+
self._summary_text.value = (
|
|
179
|
+
f"{count} file{plural} selected ({total_str} total)"
|
|
180
|
+
)
|
|
181
|
+
self._clear_btn.visible = True
|
|
182
|
+
|
|
183
|
+
page = getattr(self._files_list_view, "page", None)
|
|
184
|
+
if page:
|
|
185
|
+
self._files_list_view.update()
|
|
186
|
+
self._summary_text.update()
|
|
187
|
+
self._clear_btn.update()
|
|
188
|
+
|
|
189
|
+
def build(self) -> ft.Control:
|
|
190
|
+
"""Construct the visual Flet control for the file selector.
|
|
191
|
+
|
|
192
|
+
Returns:
|
|
193
|
+
A Flet Container displaying drop zone and queued files.
|
|
194
|
+
"""
|
|
195
|
+
drop_zone = ft.Container(
|
|
196
|
+
content=ft.Column(
|
|
197
|
+
controls=[
|
|
198
|
+
ft.Icon(
|
|
199
|
+
ft.Icons.CLOUD_UPLOAD_ROUNDED,
|
|
200
|
+
size=48,
|
|
201
|
+
color=ft.Colors.PRIMARY,
|
|
202
|
+
),
|
|
203
|
+
ft.Text(
|
|
204
|
+
"Select Files to Transfer",
|
|
205
|
+
size=16,
|
|
206
|
+
weight=ft.FontWeight.BOLD,
|
|
207
|
+
color=ft.Colors.ON_SURFACE,
|
|
208
|
+
),
|
|
209
|
+
ft.Text(
|
|
210
|
+
"Browse or select multiple files from your system",
|
|
211
|
+
size=12,
|
|
212
|
+
color=ft.Colors.ON_SURFACE_VARIANT,
|
|
213
|
+
),
|
|
214
|
+
ft.Container(height=6),
|
|
215
|
+
ft.FilledButton(
|
|
216
|
+
"Browse Files",
|
|
217
|
+
icon=ft.Icons.FOLDER_OPEN_ROUNDED,
|
|
218
|
+
on_click=self.open_picker,
|
|
219
|
+
),
|
|
220
|
+
],
|
|
221
|
+
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
|
|
222
|
+
alignment=ft.MainAxisAlignment.CENTER,
|
|
223
|
+
spacing=4,
|
|
224
|
+
),
|
|
225
|
+
padding=24,
|
|
226
|
+
border_radius=12,
|
|
227
|
+
border=ft.Border.all(1.5, ft.Colors.PRIMARY),
|
|
228
|
+
bgcolor=ft.Colors.SURFACE_CONTAINER,
|
|
229
|
+
alignment=ft.Alignment.CENTER,
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
return ft.Column(
|
|
233
|
+
controls=[
|
|
234
|
+
drop_zone,
|
|
235
|
+
ft.Row(
|
|
236
|
+
controls=[self._summary_text, self._clear_btn],
|
|
237
|
+
alignment=ft.MainAxisAlignment.SPACE_BETWEEN,
|
|
238
|
+
vertical_alignment=ft.CrossAxisAlignment.CENTER,
|
|
239
|
+
),
|
|
240
|
+
self._files_list_view,
|
|
241
|
+
],
|
|
242
|
+
spacing=10,
|
|
243
|
+
)
|