发布 1.8 版本

This commit is contained in:
JoeanAmier
2024-02-19 22:09:38 +08:00
parent 2c8efd0c27
commit 18f92134d8
23 changed files with 284 additions and 78 deletions

45
source/TUI/about.py Normal file
View File

@@ -0,0 +1,45 @@
from textual.app import ComposeResult
from textual.binding import Binding
from textual.screen import Screen
from textual.widgets import Footer
from textual.widgets import Header
from textual.widgets import Label
from source.module import (
PROJECT,
)
from source.translator import (
Chinese,
English,
)
__all__ = ["About"]
class About(Screen):
BINDINGS = [
Binding(
key="q",
action="quit",
description="退出程序/Quit"),
Binding(
key="u",
action="check_update_about",
description="检查更新/Update"),
Binding(
key="b",
action="index",
description="返回首页/Back"),
]
def __init__(self, language: Chinese | English):
super().__init__()
self.prompt = language
def compose(self) -> ComposeResult:
yield Header()
yield Label()
yield Footer()
def on_mount(self) -> None:
self.title = PROJECT

View File

@@ -13,9 +13,11 @@ from source.translator import (
Chinese,
English,
)
# from .about import About
from .index import Index
from .loading import Loading
from .monitor import Monitor
from .record import Record
from .setting import Setting
from .update import Update
@@ -53,6 +55,8 @@ class XHSDownloader(App):
name="setting")
self.install_screen(Index(self.APP, self.prompt), name="index")
self.install_screen(Loading(self.prompt), name="loading")
# self.install_screen(About(self.prompt), name="about")
self.install_screen(Record(self.APP, self.prompt), name="record")
await self.push_screen("index")
async def action_settings(self):
@@ -62,15 +66,26 @@ class XHSDownloader(App):
await self.push_screen("setting", save_settings)
async def action_about(self):
await self.push_screen("about")
async def action_index(self):
await self.push_screen("index")
async def action_record(self):
await self.push_screen("record")
async def refresh_screen(self):
self.pop_screen()
await self.APP.recorder.database.close()
await self.APP.close()
self.__initialization()
await self.__aenter__()
self.uninstall_screen("index")
self.uninstall_screen("setting")
self.uninstall_screen("loading")
# self.uninstall_screen("about")
self.uninstall_screen("record")
self.install_screen(Index(self.APP, self.prompt), name="index")
self.install_screen(
Setting(
@@ -78,13 +93,21 @@ class XHSDownloader(App):
self.prompt),
name="setting")
self.install_screen(Loading(self.prompt), name="loading")
# self.install_screen(About(self.prompt), name="about")
self.install_screen(Record(self.APP, self.prompt), name="record")
await self.push_screen("index")
def update_result(self, tip: str) -> None:
self.query_one(RichLog).write(tip)
log = self.query_one(RichLog)
log.write(tip)
log.write(">" * 50)
async def action_check_update(self):
await self.push_screen(Update(self.APP, self.prompt), callback=self.update_result)
async def action_clipboard(self):
async def action_check_update_about(self):
await self.push_screen("index")
await self.action_check_update()
async def action_monitor(self):
await self.push_screen(Monitor(self.APP, self.prompt))

View File

@@ -1,9 +1,7 @@
from asyncio import create_task
from webbrowser import open
from pyperclip import paste
from rich.text import Text
from textual import on
from textual import work
from textual.app import ComposeResult
from textual.binding import Binding
from textual.containers import HorizontalScroll
@@ -26,7 +24,6 @@ from source.module import (
LICENCE,
REPOSITORY,
GENERAL,
USERSCRIPT,
)
from source.translator import (
English,
@@ -40,9 +37,10 @@ class Index(Screen):
BINDINGS = [
Binding(key="q", action="quit", description="退出程序/Quit"),
Binding(key="u", action="check_update", description="检查更新/Update"),
Binding(key="m", action="user_script", description="获取脚本/Script"),
Binding(key="s", action="settings", description="程序设置/Settings"),
Binding(key="c", action="clipboard", description="监听链接/ClipBoard"),
Binding(key="r", action="record", description="下载记录/Record"),
Binding(key="m", action="monitor", description="开启监听/Monitor"),
# Binding(key="a", action="about", description="关于项目/About"),
]
def __init__(self, app: XHS, language: Chinese | English):
@@ -68,7 +66,7 @@ class Index(Screen):
Label(
Text(
self.prompt.input_box_title,
style=PROMPT), id="prompt",
style=PROMPT), classes="prompt",
),
Input(placeholder=self.prompt.input_prompt),
HorizontalScroll(
@@ -89,7 +87,7 @@ class Index(Screen):
@on(Button.Pressed, "#deal")
async def deal_button(self):
if self.url.value:
await create_task(self.deal())
self.deal()
else:
self.tip.write(Text(self.prompt.invalid_link, style=WARNING))
self.tip.write(Text(">" * 50, style=GENERAL))
@@ -102,6 +100,7 @@ class Index(Screen):
def paste_button(self):
self.query_one(Input).value = paste()
@work()
async def deal(self):
await self.app.push_screen("loading")
if any(await self.xhs.extract(self.url.value, True, log=self.tip)):
@@ -109,7 +108,3 @@ class Index(Screen):
else:
self.tip.write(Text(self.prompt.download_failure, style=ERROR))
self.app.pop_screen()
@staticmethod
def action_user_script():
open(USERSCRIPT)

View File

@@ -37,7 +37,7 @@ class Monitor(Screen):
def compose(self) -> ComposeResult:
yield Header()
yield Label(Text(self.prompt.monitor_mode, style=INFO), id="monitor")
yield Label(Text(self.prompt.monitor_mode, style=INFO), classes="prompt")
yield RichLog(markup=True, wrap=True)
yield Button(self.prompt.close_monitor, id="close")
yield Footer()

46
source/TUI/record.py Normal file
View File

@@ -0,0 +1,46 @@
from textual import on
from textual.app import ComposeResult
from textual.containers import Grid
from textual.containers import HorizontalScroll
from textual.screen import ModalScreen
from textual.widgets import Button
from textual.widgets import Input
from textual.widgets import Label
from source.application import XHS
from source.translator import (
Chinese,
English,
)
__all__ = ["Record"]
class Record(ModalScreen):
def __init__(self, app: XHS, language: Chinese | English):
super().__init__()
self.xhs = app
self.prompt = language
def compose(self) -> ComposeResult:
yield Grid(
Label(self.prompt.record_title, classes="prompt"),
Input(placeholder=self.prompt.record_placeholder, id="id", ),
HorizontalScroll(
Button(self.prompt.record_enter_button, id="enter", ),
Button(self.prompt.record_close_button, id="close"), ),
id="record",
)
async def delete(self, text: str):
await self.xhs.recorder.delete_many(text.split())
@on(Button.Pressed, "#enter")
async def save_settings(self):
text = self.query_one(Input)
await self.delete(text.value)
text.value = ""
@on(Button.Pressed, "#close")
def reset(self):
self.dismiss()