Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed Nov 12, 2023
1 parent 6ed4039 commit 5ff7d3f
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 11 deletions.
Binary file modified .DS_Store
Binary file not shown.
4 changes: 3 additions & 1 deletion pytohub/__main__.py
Original file line number Diff line number Diff line change
@@ -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("""
Expand All @@ -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()
Expand Down
Binary file modified pytohub/__pycache__/__main__.cpython-311.pyc
Binary file not shown.
Binary file modified pytohub/__pycache__/hmd_maker.cpython-311.pyc
Binary file not shown.
Binary file modified pytohub/__pycache__/main.cpython-311.pyc
Binary file not shown.
58 changes: 55 additions & 3 deletions pytohub/hmd_maker.py
Original file line number Diff line number Diff line change
@@ -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 #<comment>
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: (<module_name>)
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: (<file_directory>)
mkdir : Makes a directory in the hub
ARGUMENTS: (<new_directory>)
chdir : Changes the current directory in the hub
ARGUMENTS: (<directory>)
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)
41 changes: 34 additions & 7 deletions pytohub/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...")
Expand All @@ -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()

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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...")
Expand Down

0 comments on commit 5ff7d3f

Please sign in to comment.