From 63c8a9e32590c7d5f9e8f960545fe4523b3d34ea Mon Sep 17 00:00:00 2001 From: JoeanAmier Date: Sun, 29 Dec 2024 11:00:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E4=BA=A4=E4=BA=92=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/TUI/about.py | 6 +++--- source/TUI/app.py | 10 ++-------- source/TUI/index.py | 7 ++++++- source/TUI/monitor.py | 5 ++++- source/TUI/record.py | 1 + source/TUI/update.py | 34 +++++++++++++++++++--------------- source/module/tools.py | 2 +- 7 files changed, 36 insertions(+), 29 deletions(-) diff --git a/source/TUI/about.py b/source/TUI/about.py index c88cb48..e538efe 100644 --- a/source/TUI/about.py +++ b/source/TUI/about.py @@ -26,7 +26,7 @@ class About(Screen): description=_("退出程序")), Binding( key="U", - action="check_update", + action="update", description=_("检查更新")), Binding( key="B", @@ -76,5 +76,5 @@ class About(Screen): async def action_back(self) -> None: await self.app.action_back() - async def action_check_update(self): - await self.app.run_action("update_and_return") + async def action_update(self): + await self.app.run_action("update") diff --git a/source/TUI/app.py b/source/TUI/app.py index 2abe949..1692e71 100644 --- a/source/TUI/app.py +++ b/source/TUI/app.py @@ -95,18 +95,12 @@ class XHSDownloader(App): self.install_screen(Record(self.APP, ), name="record") await self.push_screen("index") - def update_result(self, tip: str) -> None: - log = self.query_one(RichLog) - log.write(tip) - log.write(">" * 50) + def update_result(self, args: tuple[str, str]) -> None: + self.notify(args[0], severity=args[1], ) async def action_update(self): await self.push_screen(Update(self.APP, ), callback=self.update_result) - async def action_update_and_return(self): - await self.action_back() - await self.action_update() - async def close_database(self): await self.APP.id_recorder.cursor.close() await self.APP.id_recorder.database.close() diff --git a/source/TUI/index.py b/source/TUI/index.py index 2af3833..4805941 100644 --- a/source/TUI/index.py +++ b/source/TUI/index.py @@ -76,7 +76,7 @@ class Index(Screen): Button(_("清空输入框"), id="reset"), ), ) - yield RichLog(markup=True, wrap=True, ) + yield RichLog(markup=True, wrap=True, auto_scroll=True, ) yield Footer() def on_mount(self) -> None: @@ -91,6 +91,7 @@ class Index(Screen): 50}", style=MASTER), animate=True, + scroll_end=True, ) self.xhs.manager.print_proxy_tip(log=self.tip, ) @@ -102,10 +103,12 @@ class Index(Screen): self.tip.write( Text(_("未输入任何小红书作品链接"), style=WARNING), animate=True, + scroll_end=True, ) self.tip.write( Text(">" * 50, style=GENERAL), animate=True, + scroll_end=True, ) @on(Button.Pressed, "#reset") @@ -125,10 +128,12 @@ class Index(Screen): self.tip.write( Text(_("下载小红书作品文件失败"), style=ERROR), animate=True, + scroll_end=True, ) self.tip.write( Text(">" * 50, style=GENERAL), animate=True, + scroll_end=True, ) await self.app.action_back() diff --git a/source/TUI/monitor.py b/source/TUI/monitor.py index 40d0c3e..3f1d638 100644 --- a/source/TUI/monitor.py +++ b/source/TUI/monitor.py @@ -52,7 +52,10 @@ class Monitor(Screen): self.query_one(RichLog).write( Text(_( "程序会自动读取并提取剪贴板中的小红书作品链接,并自动下载链接对应的作品文件,如需关闭,请点击关闭按钮,或者向剪贴板写入 “close” 文本!"), - style=MASTER)) + style=MASTER), + animate=True, + scroll_end=True, + ) self.run_monitor() async def action_close(self): diff --git a/source/TUI/record.py b/source/TUI/record.py index 8d80d53..5db25c0 100644 --- a/source/TUI/record.py +++ b/source/TUI/record.py @@ -31,6 +31,7 @@ class Record(ModalScreen): async def delete(self, text: str): await self.xhs.id_recorder.delete(text) + self.app.notify(_("删除下载记录成功")) @on(Button.Pressed, "#enter") async def save_settings(self): diff --git a/source/TUI/update.py b/source/TUI/update.py index 897d354..b12cc5e 100644 --- a/source/TUI/update.py +++ b/source/TUI/update.py @@ -1,4 +1,3 @@ -from rich.text import Text from textual import work from textual.app import ComposeResult from textual.containers import Grid @@ -8,9 +7,6 @@ from textual.widgets import LoadingIndicator from ..application import XHS from ..module import ( - ERROR, - WARNING, - INFO, RELEASES, ) from ..translation import _ @@ -37,25 +33,33 @@ class Update(ModalScreen): version = url.split("/")[-1] match self.compare_versions(f"{XHS.VERSION_MAJOR}.{XHS.VERSION_MINOR}", version, XHS.VERSION_BETA): case 4: - tip = Text(f"{_("检测到新版本:{0}.{1}").format( - XHS.VERSION_MAJOR, XHS.VERSION_MINOR)}\n{RELEASES}", style=WARNING) + args = ( + _("检测到新版本:{0}.{1}").format( + XHS.VERSION_MAJOR, + XHS.VERSION_MINOR, + ), + "warning", + ) case 3: - tip = Text( - f"{_("当前版本为开发版, 可更新至正式版")}\n{RELEASES}", - style=WARNING) + args = ( + _("当前版本为开发版, 可更新至正式版"), + "warning", + ) case 2: - tip = Text( + args = ( _("当前已是最新开发版"), - style=WARNING) + "warning", + ) case 1: - tip = Text( + args = ( _("当前已是最新正式版"), - style=INFO) + "information", + ) case _: raise ValueError except ValueError: - tip = Text(_("检测新版本失败"), style=ERROR) - self.dismiss(tip) + args = (_("检测新版本失败"), "error",) + self.dismiss(args) def on_mount(self) -> None: self.check_update() diff --git a/source/module/tools.py b/source/module/tools.py index e96cbfd..7510929 100644 --- a/source/module/tools.py +++ b/source/module/tools.py @@ -22,7 +22,7 @@ def retry(function): def logging(log, text, style=INFO): string = Text(text, style=style) if log: - log.write(string, animate=True, ) + log.write(string, animate=True, scroll_end=True, ) else: print(string)