From 8c3589baae67718158cff2cd28bfe4f00f717b45 Mon Sep 17 00:00:00 2001 From: BarsTiger Date: Tue, 26 Apr 2022 09:07:52 +0300 Subject: [PATCH] New scrollbar + developing versions and autoupdates --- horsy.py | 5 ++- horsygui.py | 15 ++++++- modules/gui.py | 110 ++++++++++++++++++++++++++++++++++++++++++--- modules/manager.py | 2 +- modules/updates.py | 22 +++++++++ 5 files changed, 144 insertions(+), 10 deletions(-) create mode 100644 modules/updates.py diff --git a/horsy.py b/horsy.py index e302646..58db896 100644 --- a/horsy.py +++ b/horsy.py @@ -29,7 +29,10 @@ os.system('title horsy') if not os.path.exists(horsy_vars.horsypath + 'apps'): os.makedirs(horsy_vars.horsypath + 'apps') if not os.path.isfile(horsy_vars.horsypath + 'config.cfg'): - with open(horsy_vars.horsypath + 'config.cfg', 'w') as f: + with open(horsy_vars.horsypath + 'config.cfg', 'w+') as f: + f.write('{}') +if not os.path.isfile(horsy_vars.horsypath + 'apps/versions.json'): + with open(horsy_vars.horsypath + 'apps/versions.json', 'w+') as f: f.write('{}') # Checking version diff --git a/horsygui.py b/horsygui.py index 3f8a1eb..acb5773 100644 --- a/horsygui.py +++ b/horsygui.py @@ -58,7 +58,7 @@ def installed_apps(): def update_app(): try: - app_name = ui.installed_table.currentItem().text() + app_name = ui.installed_table.currentItem().text().replace('!', '') if app_name == "": return else: @@ -70,7 +70,7 @@ def update_app(): def uninstall_app(): try: - app_name = ui.installed_table.currentItem().text() + app_name = ui.installed_table.currentItem().text().replace('!', '') if app_name == "": return else: @@ -107,6 +107,16 @@ def install_app(): return +def check_updates(): + from modules.updates import check + needupdate = check() + try: + for module in needupdate: + print(module) + except: + gui.cpopup("Error", str(needupdate)) + + def get_source_gui(): from modules.source import get_source try: @@ -263,6 +273,7 @@ if __name__ == "__main__": ui.tabWidget.currentChanged.connect(refresh_gui) ui.update_button.clicked.connect(update_app) ui.delete_button.clicked.connect(uninstall_app) + ui.check_updates_button.clicked.connect(check_updates) ui.search_button.clicked.connect(search_gui) ui.install_button.clicked.connect(install_app) ui.source_button.clicked.connect(get_source_gui) diff --git a/modules/gui.py b/modules/gui.py index c1a9daa..1c656e1 100644 --- a/modules/gui.py +++ b/modules/gui.py @@ -14,10 +14,84 @@ class Ui_MainWindow(object): MainWindow.setWindowIcon(icon) MainWindow.setWindowOpacity(0.99) self.centralwidget = QtWidgets.QWidget(MainWindow) - self.centralwidget.setStyleSheet("QWidget{\n" - " background-color: rgb(30, 30, 30);\n" - "}\n" - "") + self.centralwidget.setStyleSheet("""QWidget{\n" + background-color: rgb(30, 30, 30); +} +QScrollBar:horizontal { + border: none; + background: rgb(52, 59, 72); + height: 8px; + margin: 0px 21px 0 21px; + border-radius: 0px; +} +QScrollBar::handle:horizontal { + background: rgb(47, 48, 50); + min-width: 25px; + border-radius: 4px +} +QScrollBar::add-line:horizontal { + border: none; + background: rgb(55, 63, 77); + width: 20px; + border-top-right-radius: 4px; + border-bottom-right-radius: 4px; + subcontrol-position: right; + subcontrol-origin: margin; +} +QScrollBar::sub-line:horizontal { + border: none; + background: rgb(55, 63, 77); + width: 20px; + border-top-left-radius: 4px; + border-bottom-left-radius: 4px; + subcontrol-position: left; + subcontrol-origin: margin; +} +QScrollBar::up-arrow:horizontal, QScrollBar::down-arrow:horizontal +{ + background: none; +} +QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal +{ + background: none; +} +QScrollBar:vertical { + border: none; + background: rgb(52, 59, 72); + width: 8px; + margin: 21px 0 21px 0; + border-radius: 0px; +} + QScrollBar::handle:vertical { + background: rgb(47, 48, 50); + min-height: 25px; + border-radius: 4px + } + QScrollBar::add-line:vertical { + border: none; + background: transparent; + height: 10px; + border-radius: 4px; + subcontrol-position: bottom; + subcontrol-origin: margin; + } + QScrollBar::sub-line:vertical { + border: none; + background: transparent; + height: 10px; + border-radius: 4px; + subcontrol-position: top; + subcontrol-origin: margin; + } + QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical { + background: none; + } + + QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical { + background: none; + } + +""") self.centralwidget.setObjectName("centralwidget") self.horsy_logo_lefttop = QtWidgets.QLabel(self.centralwidget) self.horsy_logo_lefttop.setGeometry(QtCore.QRect(10, 10, 32, 32)) @@ -574,7 +648,7 @@ class Ui_MainWindow(object): self.installed_tab.setObjectName("installed_tab") self.delete_button = QtWidgets.QPushButton(self.installed_tab) self.delete_button.setEnabled(True) - self.delete_button.setGeometry(QtCore.QRect(440, 575, 421, 50)) + self.delete_button.setGeometry(QtCore.QRect(300, 575, 275, 50)) self.delete_button.setMinimumSize(QtCore.QSize(0, 50)) self.delete_button.setStyleSheet("QPushButton {\n" " color: rgb(204, 204, 204);\n" @@ -597,7 +671,7 @@ class Ui_MainWindow(object): self.delete_button.setObjectName("delete_button") self.update_button = QtWidgets.QPushButton(self.installed_tab) self.update_button.setEnabled(True) - self.update_button.setGeometry(QtCore.QRect(20, 575, 401, 50)) + self.update_button.setGeometry(QtCore.QRect(5, 575, 275, 50)) self.update_button.setMinimumSize(QtCore.QSize(0, 50)) self.update_button.setStyleSheet("QPushButton {\n" " color: rgb(204, 204, 204);\n" @@ -618,6 +692,29 @@ class Ui_MainWindow(object): " background-color: rgb(92, 99, 109);\n" "}") self.update_button.setObjectName("update_button") + self.check_updates_button = QtWidgets.QPushButton(self.installed_tab) + self.check_updates_button.setEnabled(True) + self.check_updates_button.setGeometry(QtCore.QRect(595, 575, 275, 50)) + self.check_updates_button.setMinimumSize(QtCore.QSize(0, 50)) + self.check_updates_button.setStyleSheet("QPushButton {\n" + " color: rgb(204, 204, 204);\n" + " border-width: 1px;\n" + " border-radius:6px;\n" + " border-style: solid;\n" + " background-color: rgb(28, 30, 33);\n" + " border-color: rgb(66, 143, 225);\n" + "}\n" + "QPushButton:hover{\n" + " border-width: 2px;\n" + "}\n" + "QPushButton:pressed{\n" + " background-color: rgb(50, 60, 63);\n" + "}\n" + "QPushButton:disabled{\n" + " border-width: 0px;\n" + " background-color: rgb(92, 99, 109);\n" + "}") + self.check_updates_button.setObjectName("check_updates_button") self.installed_table = QtWidgets.QTableWidget(self.installed_tab) self.installed_table.setGeometry(QtCore.QRect(0, 10, 871, 571)) self.installed_table.setStyleSheet("QTableWidget\n" @@ -733,6 +830,7 @@ class Ui_MainWindow(object): self.tabWidget.setTabText(self.tabWidget.indexOf(self.browse_tab), _translate("MainWindow", "Browse")) self.delete_button.setText(_translate("MainWindow", "Uninstall")) self.update_button.setText(_translate("MainWindow", "Update")) + self.check_updates_button.setText(_translate("MainWindow", "Check all updates")) self.installed_table.setSortingEnabled(True) __sortingEnabled = self.installed_table.isSortingEnabled() self.installed_table.setSortingEnabled(False) diff --git a/modules/manager.py b/modules/manager.py index f0b3233..d7c52d3 100644 --- a/modules/manager.py +++ b/modules/manager.py @@ -76,7 +76,7 @@ def install(package): # Create launch script print(f"Generating launch script") - with open('{1}apps\{0}.bat'.format(r['name'], horsy_vars.horsypath), 'w') as f: + with open('{1}apps\{0}.bat'.format(r['name'], horsy_vars.horsypath), 'w+') as f: f.write(f"@ECHO off\n") f.write(f"""{r['run'].replace('$appdir$', f'%horsypath%/apps/{r["name"]}')} %*\n""") diff --git a/modules/updates.py b/modules/updates.py new file mode 100644 index 0000000..c5ce230 --- /dev/null +++ b/modules/updates.py @@ -0,0 +1,22 @@ +import json +import requests +import modules.vars as horsy_vars +from modules.http_status import handle +from modules.manager import apps_list +from rich import print + + +def check(): + r = requests.get(f"{horsy_vars.protocol}{horsy_vars.server_url}/packages/json/" + f"{','.join(apps_list(True))}") + r_code = handle(r.status_code) + + if r_code[1] not in [200, 201]: + return r_code[0] + r = r.text + r = json.loads(r) + print(r) + + update_this = list() + + return update_this