diff --git a/ch341.py b/ch341.py index 8c23053..728dc7c 100644 --- a/ch341.py +++ b/ch341.py @@ -10,6 +10,7 @@ from ctypes import * import global_var import subprocess +import platform class ch341_class(object): @@ -26,11 +27,10 @@ def __init__(self): self.fw_8339_buf = create_string_buffer(FW_8339SIZE) self.dll = None + self.dll_name = None self.target = -1 self.status = ch341_status.IDLE.value # idle self.read_setting_flag = 1 - self.dll_name = "CH341DLL.DLL" - self.reconnect_vtx = 0 # ------ monitor ------------- @@ -78,19 +78,21 @@ def __init__(self): self.buffer_size = 2560 self.write_buffer = create_string_buffer(self.buffer_size) - try: - self.dll = ctypes.WinDLL(self.dll_name) - except: - command = "resource\driver\SETUP.EXE \S" - print("Need to install ch341 driver") - print("Installing ...") - subprocess.run(command, shell=True, capture_output=True, text=True) - print("done") - time.sleep(1) + if platform.system() == "Windows": try: + self.dll_name = "CH341DLL.DLL" self.dll = ctypes.WinDLL(self.dll_name) except: - a = 1 + print("Need to install ch341 driver") + print("Installing ...") + command = "resource\\driver\\SETUP.EXE \\S" + subprocess.run(command, shell=True, capture_output=True, text=True) + print("done") + time.sleep(1) + try: + self.dll = ctypes.WinDLL(self.dll_name) + except: + pass def parse_monitor_fw(self, fw_path): try: diff --git a/Download.py b/downloader.py similarity index 98% rename from Download.py rename to downloader.py index 6a7d740..479f618 100644 --- a/Download.py +++ b/downloader.py @@ -6,7 +6,7 @@ import zipfile -class download: +class downloader: def __init__(self): self.status = download_status.IDLE.value @@ -41,7 +41,7 @@ def download_file(self, url, save_path, clear): return 0 -my_download = download() +my_download = downloader() def download_thread_proc(): diff --git a/hdzero_programmer.py b/hdzero_programmer.py index 63038e5..8c0b800 100644 --- a/hdzero_programmer.py +++ b/hdzero_programmer.py @@ -1,52 +1,22 @@ import threading import os import sys -import shutil -from main_window import ui_thread_proc -from download import download_thread_proc +from main_window import main_window_ui +from downloader import download_thread_proc from ch341 import ch341_thread_proc - -def get_resource_folder(): - if getattr(sys, 'frozen', False): - base_path = sys._MEIPASS - else: - base_path = os.path.dirname(os.path.abspath(__file__)) - - resource_folder = os.path.join(base_path, "data_folder") - print(resource_folder) - - return resource_folder - - -def check_and_release_resource(): - - resource_folder = get_resource_folder() - - if os.path.exists("resource"): - pass - else: - for filename in os.listdir(resource_folder): - source_file = os.path.join(resource_folder, filename) - destination_file = os.path.join("resource", filename) - if os.path.isfile(source_file): - shutil.copy(source_file, destination_file) - elif os.path.isdir(source_file): - shutil.copytree(source_file, destination_file) - +run_path = getattr(sys, '_MEIPASS', os.path.abspath(os.path.dirname(__file__))) +os.chdir(run_path) def main(): - check_and_release_resource() - download_thread = threading.Thread( - target=download_thread_proc, name="download") - download_thread.start() - ui_thread = threading.Thread(target=ui_thread_proc, name="ui") - ui_thread.start() + download_thread = threading.Thread(target=download_thread_proc, name="downloader") + download_thread.start() ch341_thread = threading.Thread(target=ch341_thread_proc, name="ch341") ch341_thread.start() + main_window_ui() if __name__ == '__main__': main() diff --git a/main_window.py b/main_window.py index 0490441..6e7825e 100644 --- a/main_window.py +++ b/main_window.py @@ -10,7 +10,7 @@ from frame_programmer import frame_programmer from frame_statusbar import frame_statusbar -from download import * +from downloader import * from parse_file import * import global_var from global_var import * @@ -357,7 +357,7 @@ def create_downloading_firmware_window(self): self.downloading_window_status = 1 self.downloading_window.overrideredirect(True) - self._main_window.attributes('-disable', True) + #self._main_window.attributes('-disable', True) def set_downloading_label(self, str): self.downloading_label.config(text=str) @@ -403,7 +403,7 @@ def refresh(self): self._vtx_frame.create_radio_button_list( list(my_parse.vtx_info.keys()), self.on_select_vtx_target, my_parse.vtx_target_image) - self._main_window.attributes('-disable', False) + #self._main_window.attributes('-disable', False) # vtx if self.current_selected_tab() == 0: @@ -765,7 +765,7 @@ def on_closing(): global my_gui -def ui_thread_proc(): +def main_window_ui(): global my_gui root = tk.Tk() diff --git a/package.bat b/package.bat index 045a614..4af1cf3 100644 --- a/package.bat +++ b/package.bat @@ -1 +1 @@ -pyinstaller -i HDZeroIcon.ico -w --onefile --add-data "resource;data_folder" hdzero_programmer.py +pyinstaller -i HDZeroIcon.ico -w --onefile --add-data "resource;resource" hdzero_programmer.py diff --git a/package.sh b/package.sh new file mode 100755 index 0000000..11e9ee5 --- /dev/null +++ b/package.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +rm -rf build dist +pyinstaller -i HDZeroIcon.ico -w --onefile --add-data="resource:resource" hdzero_programmer.py