Skip to content

Commit

Permalink
Добавление соединения с сервером (теперь по нормальному)
Browse files Browse the repository at this point in the history
  • Loading branch information
themanyfaceddemon committed Aug 28, 2024
1 parent d9148a6 commit 29e4b7b
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 253 deletions.
59 changes: 0 additions & 59 deletions Code/gui/conntect.py

This file was deleted.

File renamed without changes.
48 changes: 0 additions & 48 deletions Code/gui/main_app.py

This file was deleted.

123 changes: 0 additions & 123 deletions Code/gui/map.py

This file was deleted.

11 changes: 0 additions & 11 deletions Code/gui/settings.py

This file was deleted.

85 changes: 85 additions & 0 deletions Code/gui/start.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
from pathlib import Path

import dearpygui.dearpygui as dpg
from dearpygui_async import DearPyGuiAsync
from DMBotNetwork import Client
from misc import decode_string
from root_path import ROOT_PATH
from systems.loc import Localization as loc
from .fonts_setup import FontManager


class DMClientApp:
def __init__(self):
self.dpg_async = DearPyGuiAsync()

def setup(self):
dpg.create_context()
FontManager.load_fonts()
dpg.create_viewport(title=loc.get_string("main-app-name"), width=600, min_width=600, height=400, min_height=400)
dpg.setup_dearpygui()
self._create_warning_window()

def _create_warning_window(self):
with dpg.window(label="Warning", tag="warning_window", no_move=True, no_close=True, no_collapse=True, width=380, no_resize=True):
dpg.add_text(loc.get_string("main_text_warning_window"), wrap=380)
dpg.add_button(label=loc.get_string("yes_warning_window"), callback=self._on_yes)
dpg.add_button(label=loc.get_string("no_warning_window"), callback=self._on_no)

def _on_yes(self, *args):
dpg.delete_item("warning_window")
self._create_connect_window()

def _on_no(self, *args):
self.stop()

def _create_connect_window(self):
if dpg.does_item_exist("connect_window"):
dpg.focus_item("connect_window")
return

with dpg.window(label="Connect", tag="connect_window", no_close=True, no_collapse=True, no_move=True, width=380):
dpg.add_text(loc.get_string("connect_main_text"))

dpg.add_input_text(hint=loc.get_string("connect_login_hint") , tag="connect_login")
dpg.add_input_text(hint=loc.get_string("connect_password_hint"), tag="connect_password", password=True)
dpg.add_input_text(hint=loc.get_string("connect_host_hint") , tag="connect_host")
dpg.add_input_int (label=loc.get_string("connect_port_lable") , tag="connect_port")
dpg.add_button(label=loc.get_string("connect_button"), callback=self._run_client)

async def _run_client(self, *args):
await Client.close_connection()

login_value = decode_string(dpg.get_value("connect_login"))
password_value = decode_string(dpg.get_value("connect_password"))
host_value = decode_string(dpg.get_value("connect_host"))
port_value = dpg.get_value("connect_port")

Client.set_login(login_value)
Client.set_password(password_value)
Client.set_host(host_value)
Client.set_port(port_value)

server_path = Path(ROOT_PATH) / "Content" / "Servers"
Client.set_server_file_path(server_path)

await Client.connect()

if Client._listen_task is None: # FIXME: Так делать нельзя, но проверить законектились ли мы иначе на текущий момент невозможно. Cain. DM-Bot-net v 0.0.12
with dpg.window(no_title_bar=True, modal=True, width=380) as con_err:
dpg.add_text(loc.get_string("on_connect_error_msg"), wrap=380)

dpg.add_button(label=loc.get_string("ok"), callback=lambda: dpg.delete_item(con_err))

else:
dpg.delete_item("connect_window")
# TODO: Запрос других окон с сервера.

def run(self):
dpg.show_viewport()
self.dpg_async.run()
dpg.start_dearpygui()
dpg.destroy_context()

def stop(self):
dpg.stop_dearpygui()
2 changes: 1 addition & 1 deletion Code/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from api import *
from DMBotNetwork import Client
from gui.main_app import DMClientApp
from gui.start import DMClientApp
from root_path import ROOT_PATH
from systems.loc import Localization as loc

Expand Down
6 changes: 0 additions & 6 deletions Content/Client/loc/rus/connect_window.loc

This file was deleted.

5 changes: 0 additions & 5 deletions Content/Client/loc/rus/main_app.loc

This file was deleted.

3 changes: 3 additions & 0 deletions Content/Client/loc/rus/standarts.loc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ok = ОК
yes = Да
no = Нет
14 changes: 14 additions & 0 deletions Content/Client/loc/rus/start_app.loc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
main-app-name = DM-Bot Client

main_text_warning_window = Внимание! Использование DM-Bot разрешено только для пользователей, достигших 18-летнего возраста.
yes_warning_window = Мне 18 или более лет
no_warning_window = Мне нет 18 лет

connect_main_text = Соединение с сервером
connect_login_hint = Логин
connect_password_hint = Пароль
connect_host_hint = IP
connect_port_lable = Порт
connect_button = Соединиться

on_connect_error_msg = Ошибка при подключении к серверу. Проверьте пароль/логин или адресс подключении

0 comments on commit 29e4b7b

Please sign in to comment.