From ae98e62a7fe08aa2a83dc4a6ebe2939f9aa5ff02 Mon Sep 17 00:00:00 2001 From: kirill Date: Mon, 27 Jan 2025 23:51:42 +0300 Subject: [PATCH] =?UTF-8?q?=D1=87=D1=83=D1=82=D0=BA=D0=B0=20=D0=BE=D1=82?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 2 ++ src/app.py | 2 ++ src/screens.py | 14 ++++++++------ src/style.tcss | 4 ---- src/widgets.py | 10 +++++----- tokens.py | 2 +- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/main.py b/main.py index 9d0ccd7..4c7f349 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,5 @@ +"""Файл инициализации приложения""" + from src.app import TelegramTUI if __name__ == "__main__": diff --git a/src/app.py b/src/app.py index 1b51c91..32ba7b8 100644 --- a/src/app.py +++ b/src/app.py @@ -1,3 +1,5 @@ +"""Главный файл приложения""" + from telethon import TelegramClient, events from textual.app import App from tokens import api_id, api_hash diff --git a/src/screens.py b/src/screens.py index 1c23140..ff2041e 100644 --- a/src/screens.py +++ b/src/screens.py @@ -1,12 +1,14 @@ +"""Файл с кастомными экранами приложения""" + from textual.screen import Screen from textual.widgets import Label, Input, Footer, Static from textual.containers import Vertical, Horizontal, VerticalScroll from telethon.errors import SessionPasswordNeededError -from telethon import TelegramClient, events, utils +from telethon import TelegramClient, events from src.widgets import Dialog, Chat class AuthScreen(Screen): - """Класс логина в аккаунт""" + """Класс экрана логина в аккаунт""" def __init__( self, @@ -14,7 +16,7 @@ class AuthScreen(Screen): id = None, classes = None, telegram_client: TelegramClient | None = None - ): + ): super().__init__(name, id, classes) self.client = telegram_client @@ -55,7 +57,6 @@ class AuthScreen(Screen): await self.client.start() self.app.pop_screen() self.app.push_screen("chats") - self.app.notify("") class ChatScreen(Screen): """Класс экрана чатов, он же основной экран приложения""" @@ -117,14 +118,16 @@ class ChatScreen(Screen): async def update_chat_list(self, event = None): print("Запрос обновления чатов") + if not self.is_chat_update_blocked: self.is_chat_update_blocked = True + dialogs = await self.telegram_client.get_dialogs( limit=self.limit, archived=False ) print("Получены диалоги") + limit = len(dialogs) - #limit = 30 self.mount_chats(limit) for i in range(limit): @@ -132,7 +135,6 @@ class ChatScreen(Screen): chat.username = str(dialogs[i].name) chat.msg = str(dialogs[i].message.message) chat.peer_id = dialogs[i].id - #self.notify("Новое сообщение") #колхоз дебаг self.is_chat_update_blocked = False print("Чаты обновлены") diff --git a/src/style.tcss b/src/style.tcss index cde8031..80707e6 100644 --- a/src/style.tcss +++ b/src/style.tcss @@ -38,10 +38,6 @@ Message Container { width: 65%; } -#send { - -} - #auth_container{ align: center middle; } diff --git a/src/widgets.py b/src/widgets.py index 8f44bc0..bc06f02 100644 --- a/src/widgets.py +++ b/src/widgets.py @@ -1,3 +1,5 @@ +"""Файл с кастомными виджетами приложения""" + from textual.containers import Horizontal, Vertical, Container, VerticalScroll from textual.widget import Widget from textual.reactive import Reactive @@ -13,22 +15,20 @@ class Chat(Widget): def __init__( self, name: str | None = None, - notify_func = None, id: str | None = None, classes: str | None = None, disabled: bool = False - ): + ): super().__init__( name=str(name), id=id, classes=classes, disabled=disabled ) - self.notify = notify_func - + def _on_click(self): self.msg = str(self.peer_id) - self.notify("нажат чат") + self.app.notify("нажат чат") def compose(self): with Horizontal(): diff --git a/tokens.py b/tokens.py index 2d34b43..68aad19 100644 --- a/tokens.py +++ b/tokens.py @@ -1,4 +1,4 @@ """Получите свои API-ключи на https://my.telegram.org/apps""" api_id = 12345 -api_hash = "0123456789abcdef" \ No newline at end of file +api_hash = "0123456789abcdef"