diff --git a/README.md b/README.md index 62b911d8..75b172d2 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,6 @@ Wriiten in Python for QT5. ### Roadmap - Test installer for Ubuntu -- Load the database in a thread when the application starts. It will prevent the delay of showing the icon. - Locales - System notification whe new updates - Search and install applications. \ No newline at end of file diff --git a/app.py b/app.py index 0f0b6820..7e9c272f 100755 --- a/app.py +++ b/app.py @@ -1,4 +1,5 @@ #!env/bin/python +import argparse import sys from PyQt5.QtWidgets import QApplication, QWidget @@ -6,9 +7,15 @@ from PyQt5.QtWidgets import QApplication, QWidget from core.controller import FlatpakController from core.model import FlatpakManager from view.qt.systray import TrayIcon +from core import __version__ + +parser = argparse.ArgumentParser(prog='fpakman', description="GUI for Flatpak applications management") +parser.add_argument('-v', '--version', action='version', version='%(prog)s {}'.format(__version__)) +args = parser.parse_args() app = QApplication(sys.argv) manager = FlatpakManager() +manager.load_database_async() controller = FlatpakController(manager) hidden_widget = QWidget() trayIcon = TrayIcon(parent=hidden_widget, controller=controller, check_interval=30) diff --git a/core/model.py b/core/model.py index 505ba6f9..b8be52b6 100755 --- a/core/model.py +++ b/core/model.py @@ -1,3 +1,4 @@ +from threading import Lock, Thread from typing import List import requests @@ -17,15 +18,23 @@ class FlatpakManager: self.apps = [] self.apps_db = {} self.http_session = requests.Session() - self._load_database() + self.lock_db_read = Lock() - def _load_database(self): + def load_database_async(self): + Thread(target=self.load_database).start() - res = self.http_session.get(__FLATHUB_API_URL__ + '/apps') + def load_database(self): - if res.status_code == 200: - for app in res.json(): - self.apps_db[app['flatpakAppId']] = app + self.lock_db_read.acquire() + + try: + res = self.http_session.get(__FLATHUB_API_URL__ + '/apps') + + if res.status_code == 200: + for app in res.json(): + self.apps_db[app['flatpakAppId']] = app + finally: + self.lock_db_read.release() def get_version(self): return flatpak.get_version() @@ -41,6 +50,9 @@ class FlatpakManager: for app in installed: + if not self.apps_db: + self.load_database() + if self.apps_db: app_data = self.apps_db.get(app['id'], None) else: diff --git a/run.sh b/run.sh deleted file mode 100755 index aea3a644..00000000 --- a/run.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -/home/dafiti/workspace/fpakman/env/bin/python /home/dafiti/workspace/fpakman/app.py \ No newline at end of file diff --git a/view/qt/window.py b/view/qt/window.py index fa06bab4..261d3852 100755 --- a/view/qt/window.py +++ b/view/qt/window.py @@ -3,8 +3,8 @@ from functools import reduce from threading import Lock from typing import List -from PyQt5.QtCore import Qt, QThread, pyqtSignal, QUrl -from PyQt5.QtGui import QIcon, QColor, QPixmap +from PyQt5.QtCore import Qt, QThread, pyqtSignal, QUrl, QEvent +from PyQt5.QtGui import QIcon, QColor, QPixmap, QWindowStateChangeEvent from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest from PyQt5.QtWidgets import QWidget, QVBoxLayout, QApplication, QTableWidget, \ QTableWidgetItem, QTableView, QCheckBox, QHeaderView, QToolButton, QToolBar, \ @@ -105,9 +105,7 @@ class ManageWindow(QWidget): self.table_apps.setHorizontalHeaderLabels(ManageWindow.__COLUMNS__) self.table_apps.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) - header_horizontal = self.table_apps.horizontalHeader() - for i in range(0, len(ManageWindow.__COLUMNS__)): - header_horizontal.setSectionResizeMode(i, QHeaderView.Stretch + QHeaderView.AdjustToContents) + self._change_table_headers_policy() self.layout.addWidget(self.table_apps) @@ -130,6 +128,16 @@ class ManageWindow(QWidget): self.centralize() + def _change_table_headers_policy(self, policy: QHeaderView = QHeaderView.ResizeToContents): + header_horizontal = self.table_apps.horizontalHeader() + for i in range(0, len(ManageWindow.__COLUMNS__)): + header_horizontal.setSectionResizeMode(i, policy) + + def changeEvent(self, e: QEvent): + + if isinstance(e, QWindowStateChangeEvent): + self._change_table_headers_policy(QHeaderView.Stretch if self.isMaximized() else QHeaderView.ResizeToContents) + def closeEvent(self, event): if self.tray_icon: