Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions ch341.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from ctypes import *
import global_var
import subprocess
import platform


class ch341_class(object):
Expand All @@ -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 -------------
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions Download.py → downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import zipfile


class download:
class downloader:
def __init__(self):

self.status = download_status.IDLE.value
Expand Down Expand Up @@ -41,7 +41,7 @@ def download_file(self, url, save_path, clear):
return 0


my_download = download()
my_download = downloader()


def download_thread_proc():
Expand Down
44 changes: 7 additions & 37 deletions hdzero_programmer.py
Original file line number Diff line number Diff line change
@@ -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()
8 changes: 4 additions & 4 deletions main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down Expand Up @@ -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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unknown Tinker option. Supported options are as follows:

_tkinter.TclError: bad attribute "-disable": must be -alpha, -fullscreen, -modified, -notify, -titlepath, -topmost, -transparent, or -type

#self._main_window.attributes('-disable', True)

def set_downloading_label(self, str):
self.downloading_label.config(text=str)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -765,7 +765,7 @@ def on_closing():
global my_gui


def ui_thread_proc():
def main_window_ui():
global my_gui
root = tk.Tk()

Expand Down
2 changes: 1 addition & 1 deletion package.bat
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions package.sh
Original file line number Diff line number Diff line change
@@ -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