Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
perf(ui): ⚡️ save a thread while initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
AnzhiZhang committed Jun 26, 2022
1 parent 2bf3ad2 commit 269134e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def main():
shutil.rmtree(PATH.TEMP_DIR_PATH)
os.mkdir(PATH.TEMP_DIR_PATH)

Main()
Main().main()

shutil.rmtree(PATH.TEMP_DIR_PATH)

Expand Down
6 changes: 3 additions & 3 deletions utils/window/frames/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, master: 'Main'):
self.__main_window = master
self.__search_index = -1
self.__selected_index = -1
self.__updating = False
self.__updating = True
self.__data: List[Dict] = []

self.__list_listbox = Listbox(self, font=('Arial', 12))
Expand All @@ -32,7 +32,7 @@ def __init__(self, master: 'Main'):
self.__list_listbox.pack(side='left', fill='both', expand=True)
self.__list_listbox_scrollbar.pack(side='left', fill='y')

def update_list(self, append=False):
def update_list(self, append=False, force=False):
def request(index):
# Get filters
keyword = sorting = game_version = None
Expand Down Expand Up @@ -78,7 +78,7 @@ def run():
self.__updating = False

# Protection
if not self.__updating:
if force or not self.__updating:
Thread(
target=run,
name='Update List Data'
Expand Down
17 changes: 8 additions & 9 deletions utils/window/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import sys
import platform
from threading import Thread
from tkinter import Tk
from tkinter.messagebox import askokcancel

Expand Down Expand Up @@ -42,16 +41,16 @@ def __init__(self):
self.__filters_frame.pack(**self.PACK_KWARGS)
self.__buttons_frame.pack(**self.PACK_KWARGS)

Thread(target=self.__ask_license, name='Init').start()
def main(self):
# ask license
if not ('--no-license' in sys.argv or askokcancel('版权声明', LICENSE)):
return

self.mainloop()
# update list
self.show_frame.update_list(force=True)

def __ask_license(self):
"""
Ask to accept license.
"""
if not ('--no-license' in sys.argv or askokcancel('版权声明', LICENSE)):
self.quit()
# main loop
self.mainloop()

@property
def search_frame(self):
Expand Down

0 comments on commit 269134e

Please sign in to comment.