GUI development
This commit is contained in:
35
horsygui.py
35
horsygui.py
@@ -9,11 +9,13 @@ from modules.console import cls
|
|||||||
import modules.vars as horsy_vars
|
import modules.vars as horsy_vars
|
||||||
|
|
||||||
# Initialize GUI
|
# Initialize GUI
|
||||||
app = QtWidgets.QApplication(sys.argv)
|
if __name__ == "__main__":
|
||||||
|
app = QtWidgets.QApplication(sys.argv)
|
||||||
|
|
||||||
|
|
||||||
MainWindow = QtWidgets.QMainWindow()
|
MainWindow = QtWidgets.QMainWindow()
|
||||||
ui = gui.Ui_MainWindow()
|
ui = gui.Ui_MainWindow()
|
||||||
ui.setupUi(MainWindow)
|
ui.setupUi(MainWindow)
|
||||||
MainWindow.show()
|
|
||||||
|
|
||||||
UiMainWindow = QtWidgets.QMainWindow()
|
UiMainWindow = QtWidgets.QMainWindow()
|
||||||
login_ui = gui.Ui_LoginWindow()
|
login_ui = gui.Ui_LoginWindow()
|
||||||
@@ -23,6 +25,8 @@ UiDownloadWindow = QtWidgets.QMainWindow()
|
|||||||
download_ui = gui.Ui_DownloadWindow()
|
download_ui = gui.Ui_DownloadWindow()
|
||||||
download_ui.setupUi(UiDownloadWindow)
|
download_ui.setupUi(UiDownloadWindow)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
MainWindow.show()
|
||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
def refresh_gui():
|
def refresh_gui():
|
||||||
@@ -80,7 +84,7 @@ def install_app():
|
|||||||
if app_name == "":
|
if app_name == "":
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
install(app_name, UiDownloadWindow, download_ui)
|
gui.popup("Installation", str(install(app_name)))
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -100,21 +104,22 @@ def get_source_gui():
|
|||||||
|
|
||||||
def upload_gui():
|
def upload_gui():
|
||||||
from modules.uploader import upload
|
from modules.uploader import upload
|
||||||
gui.popup('Upload', upload(True, ui, login_ui, UiMainWindow))
|
gui.popup('Upload', str(upload(True, ui, login_ui, UiMainWindow)))
|
||||||
|
|
||||||
|
|
||||||
# Run functions on startup
|
# Run functions on startup
|
||||||
installed_apps()
|
if __name__ == "__main__":
|
||||||
|
installed_apps()
|
||||||
|
|
||||||
# Binds
|
# Binds
|
||||||
ui.tabWidget.currentChanged.connect(refresh_gui)
|
ui.tabWidget.currentChanged.connect(refresh_gui)
|
||||||
ui.update_button.clicked.connect(update_app)
|
ui.update_button.clicked.connect(update_app)
|
||||||
ui.delete_button.clicked.connect(uninstall_app)
|
ui.delete_button.clicked.connect(uninstall_app)
|
||||||
ui.search_button.clicked.connect(search_gui)
|
ui.search_button.clicked.connect(search_gui)
|
||||||
ui.install_button.clicked.connect(install_app)
|
ui.install_button.clicked.connect(install_app)
|
||||||
ui.source_button.clicked.connect(get_source_gui)
|
ui.source_button.clicked.connect(get_source_gui)
|
||||||
ui.upload_button.clicked.connect(upload_gui)
|
ui.upload_button.clicked.connect(upload_gui)
|
||||||
|
|
||||||
|
|
||||||
# Handle GUI exiting to exit whole program
|
# Handle GUI exiting to exit whole program
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
|
|||||||
@@ -5,43 +5,49 @@ import modules.vars as horsy_vars
|
|||||||
import os
|
import os
|
||||||
import zipfile
|
import zipfile
|
||||||
from modules.virustotal import get_key, scan_file, get_report
|
from modules.virustotal import get_key, scan_file, get_report
|
||||||
|
from horsygui import UiDownloadWindow, download_ui
|
||||||
|
|
||||||
|
|
||||||
def install(package, UiDownloadWindow=None, ui_download=None):
|
def install(package):
|
||||||
r = requests.get(f"{horsy_vars.protocol}{horsy_vars.server_url}/packages/json/{package}").text
|
r = requests.get(f"{horsy_vars.protocol}{horsy_vars.server_url}/packages/json/{package}").text
|
||||||
if r == "":
|
if r == "":
|
||||||
print(f"[red]Package {package} not found[/]")
|
return f"Package {package} not found"
|
||||||
return
|
|
||||||
try:
|
try:
|
||||||
r = json.loads(r)
|
r = json.loads(r)
|
||||||
except:
|
except:
|
||||||
print("[red]Error with unsupported message[/]")
|
print("[red]Error with unsupported message[/]")
|
||||||
return
|
return "Error with unsupported message"
|
||||||
try:
|
try:
|
||||||
if r["message"] == "Internal server error":
|
if r["message"] == "Internal server error":
|
||||||
print("[red]Internal server error[/]")
|
print("[red]Internal server error[/]")
|
||||||
return
|
return "Internal server error"
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print(f"[green]App {r['name']} found, information loaded[/]")
|
print(f"[green]App {r['name']} found, information loaded[/]")
|
||||||
|
UiDownloadWindow.show()
|
||||||
|
|
||||||
if not os.path.exists('{1}apps/{0}'.format(r['name'], horsy_vars.horsypath)):
|
if not os.path.exists('{1}apps/{0}'.format(r['name'], horsy_vars.horsypath)):
|
||||||
os.makedirs('{1}apps/{0}'.format(r['name'], horsy_vars.horsypath))
|
os.makedirs('{1}apps/{0}'.format(r['name'], horsy_vars.horsypath))
|
||||||
|
|
||||||
# if not is_gui:
|
download_ui.logs_box.clear()
|
||||||
print(f"Downloading {r['url'].split('/')[-1]}")
|
download_ui.logs_box.append(f"Downloading {r['url'].split('/')[-1]}")
|
||||||
|
success = 0
|
||||||
|
|
||||||
chunk_size = 1024
|
def dl_main_file(success):
|
||||||
file_r = requests.get(r['url'], stream=True)
|
UiDownloadWindow.show()
|
||||||
with open('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1], horsy_vars.horsypath), "wb") as f:
|
file_r = requests.get(r['url'], stream=True)
|
||||||
pbar = tqdm(unit="B", unit_scale=True, total=int(file_r.headers['Content-Length']))
|
chunk_size = int(int(file_r.headers['Content-Length']) / 100)
|
||||||
for chunk in file_r.iter_content(chunk_size=chunk_size):
|
with open('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1], horsy_vars.horsypath), "wb") as f:
|
||||||
if chunk:
|
for chunk in file_r.iter_content(chunk_size=chunk_size):
|
||||||
pbar.update(len(chunk))
|
if chunk:
|
||||||
f.write(chunk)
|
download_ui.progressBar_1.setValue(download_ui.progressBar_1.value() + 1)
|
||||||
pbar.close()
|
f.write(chunk)
|
||||||
|
download_ui.progressBar_1.setValue(0)
|
||||||
|
success += 1
|
||||||
|
|
||||||
|
threading.Thread(target=dl_main_file, args=(success,)).start()
|
||||||
|
|
||||||
print(f"Starting virustotal scan")
|
print(f"Starting virustotal scan")
|
||||||
if not get_key():
|
if not get_key():
|
||||||
@@ -75,16 +81,20 @@ def install(package, UiDownloadWindow=None, ui_download=None):
|
|||||||
# if not is_gui:
|
# if not is_gui:
|
||||||
print(f"Downloading {r['download'].split('/')[-1]}")
|
print(f"Downloading {r['download'].split('/')[-1]}")
|
||||||
|
|
||||||
chunk_size = 1024
|
def dl_dep_file(success):
|
||||||
file_r = requests.get(r['download'], stream=True)
|
download_ui.logs_box.append(f"Downloading {r['download'].split('/')[-1]}")
|
||||||
with open('{2}apps/{0}/{1}'.format(r['name'], r['download'].split('/')[-1], horsy_vars.horsypath),
|
file_r = requests.get(r['download'], stream=True)
|
||||||
"wb") as f:
|
chunk_size = int(int(file_r.headers['Content-Length']) / 100)
|
||||||
pbar = tqdm(unit="B", unit_scale=True, total=int(file_r.headers['Content-Length']))
|
with open('{2}apps/{0}/{1}'.format(r['name'], r['download'].split('/')[-1], horsy_vars.horsypath),
|
||||||
for chunk in file_r.iter_content(chunk_size=chunk_size):
|
"wb") as f:
|
||||||
if chunk:
|
for chunk in file_r.iter_content(chunk_size=chunk_size):
|
||||||
pbar.update(len(chunk))
|
if chunk:
|
||||||
f.write(chunk)
|
download_ui.progressBar_2.setValue(download_ui.progressBar_2.value() + 1)
|
||||||
pbar.close()
|
f.write(chunk)
|
||||||
|
download_ui.progressBar_2.setValue(0)
|
||||||
|
success += 1
|
||||||
|
|
||||||
|
threading.Thread(target=dl_dep_file, args=(success,)).start()
|
||||||
|
|
||||||
print(f"Starting virustotal scan")
|
print(f"Starting virustotal scan")
|
||||||
if not get_key():
|
if not get_key():
|
||||||
@@ -114,13 +124,11 @@ def install(package, UiDownloadWindow=None, ui_download=None):
|
|||||||
f.write(f"@ECHO off\n")
|
f.write(f"@ECHO off\n")
|
||||||
f.write(f"{horsy_vars.horsypath}apps/{r['name']}/{r['run']} %*\n")
|
f.write(f"{horsy_vars.horsypath}apps/{r['name']}/{r['run']} %*\n")
|
||||||
|
|
||||||
print(f"[green][OK] All done![/]")
|
return f"All done!\n You can run your app by entering {r['name']} in terminal"
|
||||||
print(f"[green]You can run your app by entering [italic white]{r['name']}[/] in terminal[/]")
|
|
||||||
|
|
||||||
except:
|
except:
|
||||||
print("[red]Unexpected error[/]")
|
raise
|
||||||
# raise
|
return "Unexpected error"
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def uninstall(package, is_gui=False):
|
def uninstall(package, is_gui=False):
|
||||||
|
|||||||
Reference in New Issue
Block a user