diff --git a/.DS_Store b/.DS_Store index 8c08889..c41c847 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/pytohub/__main__.py b/pytohub/__main__.py index f7d0e00..c777d40 100644 --- a/pytohub/__main__.py +++ b/pytohub/__main__.py @@ -1,7 +1,9 @@ from .main import run, download_program from .hmd_maker import run_lmod_maker from .logging import log +import time import sys +import os def show_help(): print(""" @@ -21,7 +23,7 @@ def show_help(): download_program() elif '--module_maker' in sys.argv: - run_lmod_maker() + run_lmod_maker(sys.argv) elif '--help' in sys.argv: show_help() diff --git a/pytohub/__pycache__/__main__.cpython-311.pyc b/pytohub/__pycache__/__main__.cpython-311.pyc index 4d246a4..74993b0 100644 Binary files a/pytohub/__pycache__/__main__.cpython-311.pyc and b/pytohub/__pycache__/__main__.cpython-311.pyc differ diff --git a/pytohub/__pycache__/hmd_maker.cpython-311.pyc b/pytohub/__pycache__/hmd_maker.cpython-311.pyc index affc112..b8590a6 100644 Binary files a/pytohub/__pycache__/hmd_maker.cpython-311.pyc and b/pytohub/__pycache__/hmd_maker.cpython-311.pyc differ diff --git a/pytohub/__pycache__/main.cpython-311.pyc b/pytohub/__pycache__/main.cpython-311.pyc index 29fba80..c9ee64f 100644 Binary files a/pytohub/__pycache__/main.cpython-311.pyc and b/pytohub/__pycache__/main.cpython-311.pyc differ diff --git a/pytohub/hmd_maker.py b/pytohub/hmd_maker.py index 49bbf23..5f58722 100644 --- a/pytohub/hmd_maker.py +++ b/pytohub/hmd_maker.py @@ -1,18 +1,70 @@ from .menu import * import time from .textcolors import textcolors -from tkinter.filedialog import askdirectory +from tkinter.filedialog import * import os +import sys from .logging import log file = None +premake = False -def run_lmod_maker(): +def clear(): + os.system("cls" if os.name == "nt" else "clear") + +def run_lmod_maker(args): print( textcolors.BOLD + textcolors.PURPLE + "PYToHub is made by @mas6y6 on github\n" + textcolors.END ) - time.sleep(3) + a = args + + if a[2] == '-file': + log.info('Asking where to store file') + d = askdirectory() + if d == '': + log.error('No directory to store file') + else: + log.info("Creating file") + f = open(f"{d}/setup.umd",'w+') + f.write("#Use \"python3 -m pytohub --hmd_maker -h\" to get the help guide to use this file\n") + f.write("#This file is needed to install your module to your hub\n") + elif a[2] == '-guide': + print("""How to use the module_maker + +You well be given a file that pytohub will need to use to install the module to your lego hub + + Comments will be ignored # + + How to use arguments: + After the command, you need to use a space to implement an argument + Example: upload_file main.py + + File commands: + make_module : Builds the module folder on the hub and get the hub ready (You can only run this one) + ARGUMENTS: () + return_home : Returns to the main directory of the module on the computer and hub + ARGUMENTS: (None) + + upload_file : Uploads a file thats in a directory + ARGUMENTS: () + + mkdir : Makes a directory in the hub + ARGUMENTS: () + + chdir : Changes the current directory in the hub + ARGUMENTS: () + + finish : Finishs the module when its done (You can only run this one) + ARGUMENTS: (None) +""") + else: + log.error("UNKNOWN ERROR") + + #w = sys.argv[0].split('/') + #w.pop(len(w) - 1) + #main_mod = '/'.join(w) + #time.sleep(3) \ No newline at end of file diff --git a/pytohub/main.py b/pytohub/main.py index 4f48ba4..6bdd389 100644 --- a/pytohub/main.py +++ b/pytohub/main.py @@ -113,20 +113,23 @@ def upload_file(): global hub log.log("Asking for file to upload...") - window = tk.Tk() w = fbox.askopenfilename( filetypes=[("Python Files", "*.py")], ) - window.destroy() - log.log(f"Uploading: {w}") + if w == '': + log.info('No file selected') + time.sleep(5) + return + while True: - qa = input(f"Do you want to upload {w} (Y/n)") + qa = input(f"Do you want to upload {w} (Y/n) :\n") if qa == "Y" or qa == "y": break elif qa == "N" or qa == "n": - return + return else: pass + filename1 = w.split("/") filename = filename1[len(filename1) - 1] log.log("Uploading...") @@ -151,6 +154,10 @@ def upload_file(): ] f = open(w, "r") lines = f.readlines() + if lines == []: + log.error("There are no lines in this file upload canceled.") + time.sleep(3) + return pbar = progressbar.ProgressBar(max_value=len(lines), widgets=widgets) pbar.start() @@ -192,6 +199,26 @@ def upload_file(): log.log("Please wait for 1 seconds before returning to main menu") time.sleep(1) +def delete_mods(): + while True: + mods = hub.send_command('listdir',[]) + mods_files = [] + for i in mods: + if not len(i.split('.')) == 1: + mods.append(i) + + out = second_menu('Select the mod that you want to remove',mods_files) + if out[0] == 'Back': + break + else: + out2 = options_menu(f'Are you sure that you want remove \"{out[0]}\"',['Yes','No'],include_exit=False,exitfn=None) + if out2[1] == 0: + log.info("Sending command to delete file") + cmd = hub.send_command('') + if cmd['packet-type'] == 4: + log.error(f"An error occurred: {cmd['error']}") + else: + log.success("File deleted") def start_main_menu(): global version, hub_version @@ -224,7 +251,7 @@ def start_main_menu(): "Manage", options=["View mods", "Delete mods", "Delete files"] ) if out2[1] == 0: - pass + delete_mods() elif out2[1] == 1: pass elif out2[1] == 2: @@ -281,7 +308,7 @@ def download_program(): "LEGO 45678 Education Spike Prime Hub", "LEGO 51515 MINDSTORMS Robot Inventor hub", ], - include_exit=True, + include_exit=True ) if h[1] == 0: log.log("Requesting where to download...")