feat: update gui insert

This commit is contained in:
RTAkland
2022-01-14 18:22:24 +08:00
parent f6f97a0785
commit 704158bc64
2 changed files with 60 additions and 1 deletions

View File

@@ -3,4 +3,56 @@
# @Author: markushammered@gmail.com
# @Development Tool: PyCharm
# @Create Time: 2022/1/9
# @File Name: GUI.py
# @File Name: buildGUIClass.py
import tkinter
import tkinter as tk
root = tk.Tk()
root.title('QWeather client')
sw = root.winfo_screenwidth()
sh = root.winfo_screenheight()
ww = 700
wh = 490
x = (sw - ww) / 2
y = (sh - wh) / 2
root.geometry("%dx%d+%d+%d" % (ww, wh, x, y))
root.minsize(700, 490)
root.maxsize(700, 490)
log_label = tk.Label(root, text='Log information')
log_label.place(x=170, y=4)
log_text = tk.Text(root, width=55, height=15)
log_text.place(x=30, y=30)
var_command = tk.StringVar()
class InsertLog:
def __init__(self):
self.log_text = log_text
def insert(self, msg: str):
"""
insert the information to gui(Text)
:param msg: information
:return:
"""
if '\n' not in msg:
msg = msg + '\n'
self.log_text.configure(state=tkinter.NORMAL) # writable
self.log_text.insert('insert', msg) # insert information
self.log_text.configure(state=tkinter.DISABLED) # readable
class Features:
def __init__(self):
self.root = root
self.tk = tk
self.log_text = log_text
def quit_(self):
"""
quit gui
:return:
"""
self.root.destroy()
self.root.quit()

View File

@@ -12,6 +12,9 @@ from core.logger import Logger
from core.read_config import read_config
from core.information import WeatherInfo
from core.language import Language
from lib.buildGUIClass import InsertLog
gui_log = InsertLog()
try:
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -20,6 +23,7 @@ try:
server.listen(5)
except OSError as e:
Logger.critical(e)
gui_log.insert(e)
language = Language()
@@ -312,16 +316,19 @@ def process_requests(c, a):
c.send('HTTP/1.1 200 OK\r\n\r\n'.encode('utf-8'))
c.send(html.encode('utf-8'))
Logger.info(f'{language["get_resource"]} {data} {language["get_resource_from"]} {a[0]}:{a[1]}')
gui_log.insert(f'{language["get_resource"]} {data} {language["get_resource_from"]} {a[0]}:{a[1]}')
try:
with open(f'./{data}', 'rb') as f:
c.send('HTTP/1.1 200 OK\r\n\r\n'.encode('utf-8'))
c.send(f.read())
Logger.info(f'{language["get_resource"]} {data} {language["get_resource_from"]} {a[0]}:{a[1]}')
gui_log.insert(f'{language["get_resource"]} {data} {language["get_resource_from"]} {a[0]}:{a[1]}')
except FileNotFoundError:
with open('./res/basic-resources/404.html', 'r') as not_found:
c.send(f'HTTP/1.1 404 Not Found\r\n\r\n{not_found.read()}'.encode('utf-8'))
except BrokenPipeError:
Logger.error(f'{language["connection_speed_too_fast"]}')
gui_log.insert(f'{language["connection_speed_too_fast"]}')
finally:
c.close()
return