mirror of
https://git.srhtnin.garden/sarah/SaraView.git
synced 2026-10-13 18:28:14 +02:00
Fixed download sizes and directory highlighting
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
843ad1986e
commit
d4c018a402
8 files changed
+113
-37
No files matched your search
+45
-23
@@ -11,7 +11,7 @@ from typing import Callable, Optional
|
||||
import flet as ft
|
||||
|
||||
from App import App
|
||||
from Core import ChipButtonStyle, FileIcons, HumanSize, OpenExternally, Palette
|
||||
from Core import ChipButtonStyle, FileIcons, HumanDuration, HumanSize, OpenExternally, Palette
|
||||
from Sources import BaseName, Entry, JoinPath, MoveDestination, ParentPath, SourceError
|
||||
from Graph import GraphView
|
||||
from Viewer import FileView
|
||||
@@ -84,11 +84,12 @@ class Browser(ft.Column):
|
||||
spacing=8,
|
||||
tight=True,
|
||||
)
|
||||
# Shown while uploading: which file, how far (Uploads' progress).
|
||||
self.UploadText = ft.Text("", size=12, color=Palette.Overlay0)
|
||||
self.UploadBar = ft.ProgressBar(value=0, color=Palette.Mauve, bgcolor=Palette.Surface0, bar_height=4)
|
||||
self.UploadRow = ft.Container(ft.Column([self.UploadText, self.UploadBar], spacing=4),
|
||||
# Shown while uploading or downloading: which file, how far, how long (ShowTransfer).
|
||||
self.TransferText = ft.Text("", size=12, color=Palette.Overlay0)
|
||||
self.TransferBar = ft.ProgressBar(value=0, color=Palette.Mauve, bgcolor=Palette.Surface0, bar_height=4)
|
||||
self.TransferRow = ft.Container(ft.Column([self.TransferText, self.TransferBar], spacing=4),
|
||||
padding=ft.Padding.symmetric(horizontal=8, vertical=6), visible=False)
|
||||
self.TransferShown: Optional[tuple] = None # (text, percent) on screen
|
||||
self.EntryList = ft.ListView(expand=True, spacing=2)
|
||||
# One shared popup host, opened programmatically (see _RequestMenu).
|
||||
# Its built-in triggers can't be switched off, so they're set to
|
||||
@@ -108,7 +109,7 @@ class Browser(ft.Column):
|
||||
# and the breadcrumbs get the rest (and wrap when it's tight).
|
||||
ft.Row([ft.Container(self.Breadcrumbs, padding=8, expand=True), ft.Container(self.ActionsToolbar, padding=8)]),
|
||||
ft.Divider(height=1, color=Palette.Surface1),
|
||||
self.UploadRow,
|
||||
self.TransferRow,
|
||||
self.FileArea,
|
||||
]
|
||||
self._ShowList(Update=False)
|
||||
@@ -610,21 +611,14 @@ class Browser(ft.Column):
|
||||
Total = sum(Sizes)
|
||||
Verb = "Uploading" if Server else "Copying in"
|
||||
|
||||
Shown = [-1, -1] # (file, percent) on screen: redraw only when it changes
|
||||
Started = time.monotonic()
|
||||
|
||||
def ShowProgress(Index: int, Fraction: float) -> None:
|
||||
Done = sum(Sizes[:Index]) + Sizes[Index] * Fraction
|
||||
Percent = int(Done / Total * 100) if Total else 100
|
||||
if Shown == [Index, Percent]:
|
||||
return
|
||||
Shown[:] = [Index, Percent]
|
||||
Of = f" ({Index + 1} of {len(Paths)})" if len(Paths) > 1 else ""
|
||||
self.UploadText.value = (f"{Verb} {Paths[Index].name}{Of}: {Percent}% "
|
||||
f"({HumanSize(int(Done))} of {HumanSize(Total)})")
|
||||
self.UploadBar.value = Done / Total if Total else 1
|
||||
self.UploadRow.update()
|
||||
self._ShowTransfer(f"{Verb} {Paths[Index].name}{Of}", sum(Sizes[:Index]) + Sizes[Index] * Fraction, Total, Started)
|
||||
|
||||
self.UploadRow.visible = True
|
||||
self.TransferShown = None
|
||||
self.TransferRow.visible = True
|
||||
for Index, LocalFile in enumerate(Paths):
|
||||
ShowProgress(Index, 0)
|
||||
try:
|
||||
@@ -634,15 +628,15 @@ class Browser(ft.Column):
|
||||
Saved += 1
|
||||
except SourceError as Error:
|
||||
if Error.Status == 401:
|
||||
self.UploadRow.visible = False
|
||||
self.UploadRow.update()
|
||||
self.TransferRow.visible = False
|
||||
self.TransferRow.update()
|
||||
self.TheApp.HandleError(Error)
|
||||
return
|
||||
Failed.append(f"{LocalFile.name}: {Error}")
|
||||
except OSError as Error:
|
||||
Failed.append(f"{LocalFile.name}: {Error}")
|
||||
self.UploadRow.visible = False
|
||||
self.UploadRow.update()
|
||||
self.TransferRow.visible = False
|
||||
self.TransferRow.update()
|
||||
self.Refresh()
|
||||
if Failed:
|
||||
self.TheApp.Notify("Couldn't upload " + "; ".join(Failed), "error")
|
||||
@@ -663,14 +657,42 @@ class Browser(ft.Column):
|
||||
initial_directory=str(Path.home() / "Downloads"))
|
||||
if not Chosen:
|
||||
return
|
||||
self.TheApp.Notify(f"Downloading {FileName}...", "info")
|
||||
Started = time.monotonic()
|
||||
self.TransferShown = None
|
||||
self.TransferText.value = f"Preparing {FileName}…" # a directory is zipped first
|
||||
self.TransferBar.value = None # moving, until the size is known
|
||||
self.TransferRow.visible = True
|
||||
self.TransferRow.update()
|
||||
try:
|
||||
await asyncio.to_thread(Server.Download, Root, RelativePath, Path(Chosen))
|
||||
await asyncio.to_thread(Server.Download, Root, RelativePath, Path(Chosen),
|
||||
lambda Done, Total: self._ShowTransfer(f"Downloading {FileName}", Done, Total, Started))
|
||||
except SourceError as Error:
|
||||
self.TheApp.HandleError(Error, f"Couldn't download {Name}")
|
||||
return
|
||||
finally:
|
||||
self.TransferRow.visible = False
|
||||
self.TransferRow.update()
|
||||
self.TheApp.Notify(f"Saved {Chosen}", "success")
|
||||
|
||||
def _ShowTransfer(self, What: str, Done: float, Total: int, Started: float) -> None:
|
||||
"""The transfer row: "Downloading a.zip: 45% (54.0 MB of 122.1 MB,
|
||||
about 12 s left)". Redraws only when the percentage changes."""
|
||||
Percent = int(Done / Total * 100) if Total else None
|
||||
if self.TransferShown == (What, Percent):
|
||||
return
|
||||
self.TransferShown = (What, Percent)
|
||||
Elapsed = time.monotonic() - Started
|
||||
if Percent is None:
|
||||
Detail = f"{HumanSize(int(Done))}"
|
||||
else:
|
||||
Detail = f"{Percent}% ({HumanSize(int(Done))} of {HumanSize(Total)}"
|
||||
if Elapsed > 2 and 0 < Done < Total:
|
||||
Detail += f", about {HumanDuration((Total - Done) * Elapsed / Done)} left"
|
||||
Detail += ")"
|
||||
self.TransferText.value = f"{What}: {Detail}"
|
||||
self.TransferBar.value = Done / Total if Total else None
|
||||
self.TransferRow.update()
|
||||
|
||||
# --- Keyboard ---------------------------------------------------------
|
||||
|
||||
def _SetShortcutsPaused(self, Paused: bool) -> None:
|
||||
|
||||
Reference in new issue
Block a user