From de440231165ac90bfb429fca26142f52ad4b2577 Mon Sep 17 00:00:00 2001 From: Paul S Date: Thu, 1 Jul 2021 12:22:26 +0200 Subject: [PATCH] dynamic layout + start maximized --- changelog.md | 10 ++ src/main.py | 131 +++++++------- src/utils.py | 7 +- ui/main.ui | 470 +++++++++++++++++++++++---------------------------- 4 files changed, 290 insertions(+), 328 deletions(-) diff --git a/changelog.md b/changelog.md index 73058ff..c9b13fc 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,15 @@ # Changelog GarageCalc1 +## [0.4.1] - 2021-07-01 +## Added +- Dynamisches Layout +- Programm startet maximiert wenn Breite der Auflösung <= 700 pixel, ansonsten 610 * 640 + +## [0.4] - 2021-06-30 +## Added +- Einzelne Zellen lassen sich nun selektieren/kopieren/verschieben/löschen (zusätzlich zu Reihen) +- Kontextmenü für Zellen + ## [0.3] - 2021-06-29 ### Added - Warnt beim Beenden falls ungespeicherte Einträge vorhanden sind diff --git a/src/main.py b/src/main.py index de26027..a5ff8db 100644 --- a/src/main.py +++ b/src/main.py @@ -28,14 +28,14 @@ from utils import show_about, resource_path from clsTableWidget import TableWidget # Local globals -APP_VERSION = "v0.4" +APP_VERSION = "v0.4.1" DIR_APPDATA = os.getenv('LOCALAPPDATA') -APP_NAME = QCoreApplication.translate("main", "Garage Space Calculator") +APP_NAME = "Garage Space Calculator" APP_DISPNAME = "GarageCalc" APP_AUTHOR = "Paul Salajean" -APP_DESCR = QCoreApplication.translate("main", "Calculates available garage space") +APP_DESCR = "Calculates available garage space" APP_COPYRIGHT = "(c) Paul Salajean 2021" APP_WEBSITE = "https://gitlab.com/ProfP303" APP_DESKTOPFILENAME = APP_DISPNAME @@ -66,7 +66,63 @@ TBL_STUFF_ROW_COUNT = 50 TXT_UNSAVED_CHANGES = QCoreApplication.translate("main", "There are unsaved entries. Without saving, all changes are lost. Continue anyway?") -class MyMainWindow(QMainWindow): +#################################################################### +def main(): + qApp = QApplication(sys.argv) + + qApp.setApplicationName(APP_NAME) + qApp.setApplicationDisplayName(APP_DISPNAME) + qApp.setApplicationVersion(APP_VERSION) + qApp.description = APP_DESCR + qApp.copyright = APP_COPYRIGHT + qApp.website = APP_WEBSITE + qApp.setWindowIcon(QIcon(APP_ICON)) + qApp.setDesktopFileName(APP_DESKTOPFILENAME) + + config = configparser.ConfigParser() + + language = "Deutsch" + + if os.path.exists(os.path.join(DIR_APPDATA, APP_DISPNAME, APP_DISPNAME + '.ini')): + config.read(os.path.join(DIR_APPDATA, APP_DISPNAME, APP_DISPNAME + '.ini')) + language = config['DEFAULT']['language'] + else: + config['DEFAULT']['language'] = language + if not os.path.exists(os.path.join(DIR_APPDATA, APP_DISPNAME)): + os.makedirs(os.path.join(DIR_APPDATA, APP_DISPNAME)) + + with open(os.path.join(DIR_APPDATA, APP_DISPNAME, APP_DISPNAME + '.ini'), 'w') as configfile: # save + config.write(configfile) + + translator = QTranslator() + + print("Current dir:", os.getcwd()) + if language == "Deutsch": + print("Loading german language file.") + translator.load(resource_path('./i18n/de_DE')) + elif language == "Magyar": + print("Loading hungarian langauge file.") + translator.load(resource_path('./i18n/hu_HU')) + else: + print(f"Unknown language setting '{language}' -> defaulting to english language.") + + qApp.installTranslator(translator) + + winMain = MainWindow(language) + + if qApp.primaryScreen().size().width() <= 700: + winMain.showMaximized() + else: + winMain.resize(610, 640) + + winMain.show() + + sys.exit(qApp.exec_()) + +#################################################################### + +#################################################################### +class MainWindow(QMainWindow): def __init__(self, language): super().__init__() @@ -83,8 +139,10 @@ class MyMainWindow(QMainWindow): self.create_actions() self.create_toolbar() self.create_statusbar() + global APP_NAME - APP_NAME = qApp.translate("main", "Garage Space Calculator") + APP_NAME = qApp.setApplicationName(qApp.translate("main", "Garage Space Calculator")) + self.statusBar.showMessage(f"{APP_NAME} {APP_VERSION} - {APP_AUTHOR}", 5000) self.calc_voluminae() self.ui.efWeight.setText(str("0")) @@ -157,20 +215,12 @@ class MyMainWindow(QMainWindow): self.ui = loader.load(ui_file, self) ui_file.close() - #self.ui.tableStuff = TableWidget(self.ui.gbStuff) + # implement custom class 'TableWidget' + layoutGb = self.ui.gbStuff.layout() self.ui.tableStuff = TableWidget() self.ui.tableStuff.setColumnCount(TBL_STUFF_COL_COUNT) self.ui.tableStuff.setRowCount(TBL_STUFF_ROW_COUNT) - self.ui.tableStuff.move(10, 23) - self.ui.tableStuff.resize(541,268) - - # create layout - #hBox = QHBoxLayout() - #hBox.addWidget(self.ui.tableStuff) - #self.ui.tableStuff.move(10, 23) - self.ui.tableStuff.setParent(self.ui.gbStuff) - #self.ui.gbStuff.setLayout(hBox) - + layoutGb.addWidget(self.ui.tableStuff) def create_actions(self): self.actionNew = QAction() @@ -782,50 +832,7 @@ class MyMainWindow(QMainWindow): self.retranslateUi() +#################################################################### + if __name__ == "__main__": - qApp = QApplication([]) - - qApp.setApplicationName(APP_NAME) - qApp.setApplicationDisplayName(APP_DISPNAME) - qApp.setApplicationVersion(APP_VERSION) - qApp.description = APP_DESCR - qApp.copyright = APP_COPYRIGHT - qApp.website = APP_WEBSITE - qApp.setWindowIcon(QIcon(APP_ICON)) - qApp.setDesktopFileName(APP_DESKTOPFILENAME) - - config = configparser.ConfigParser() - - language = "Deutsch" - - if os.path.exists(os.path.join(DIR_APPDATA, APP_DISPNAME, APP_DISPNAME + '.ini')): - config.read(os.path.join(DIR_APPDATA, APP_DISPNAME, APP_DISPNAME + '.ini')) - language = config['DEFAULT']['language'] - else: - config['DEFAULT']['language'] = language - if not os.path.exists(os.path.join(DIR_APPDATA, APP_DISPNAME)): - os.makedirs(os.path.join(DIR_APPDATA, APP_DISPNAME)) - - with open(os.path.join(DIR_APPDATA, APP_DISPNAME, APP_DISPNAME + '.ini'), 'w') as configfile: # save - config.write(configfile) - - translator = QTranslator() - - print("Current dir:", os.getcwd()) - if language == "Deutsch": - print("Loading german language file.") - translator.load(resource_path('./i18n/de_DE')) - elif language == "Magyar": - print("Loading hungarian langauge file.") - translator.load(resource_path('./i18n/hu_HU')) - else: - print(f"Unknown language setting '{language}' -> defaulting to english language.") - - qApp.installTranslator(translator) - - winMain = MyMainWindow(language) - # winMain.setWidth(600) - # winMain.setHeight(625) - winMain.resize(610, 640) - winMain.show() - sys.exit(qApp.exec_()) + main() diff --git a/src/utils.py b/src/utils.py index 9d008bb..a6d03e5 100644 --- a/src/utils.py +++ b/src/utils.py @@ -34,13 +34,10 @@ def show_about(): msg = QMessageBox() msg.setIconPixmap(QPixmap(resource_path(APP_ICON))) - APP_NAME = qApp.translate("main", "Garage Space Calculator") - APP_DESCR = qApp.translate("main", "Calculates available garage space") - text = "

" + qApp.applicationDisplayName() + " " + \ "
" + qApp.applicationVersion() + "

" + \ - "
" + APP_NAME + "
" + \ - "
" + APP_DESCR + "
" + \ + "
" + qApp.applicationName() + "
" + \ + "
" + qApp.translate("main", "Calculates available garage space") + "
" + \ "
" + qApp.translate("utils", "Idea") + ": Balazs Fabian" + "
" + \ "
" + qApp.copyright + "
" \ "
" + qApp.website + "

" diff --git a/ui/main.ui b/ui/main.ui index 85b7d1d..b7f95e2 100644 --- a/ui/main.ui +++ b/ui/main.ui @@ -13,271 +13,219 @@ Form - - - - 20 - 440 - 541 - 121 - - - - Ergebnis - - - true - - - - - 10 - 20 - 140 - 16 - - - - Volumen der Garage: - - - - - - 10 - 40 - 140 - 16 - - - - Volumen der Gegenstände: - - - - - - 10 - 60 - 140 - 16 - - - - Freier Raum in der Garage: - - - - - - 174 - 20 - 113 - 20 - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - true - - - - - - 174 - 40 - 113 - 20 - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - true - - - - - - 174 - 60 - 113 - 20 - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - true - - - - - - 294 - 20 - 47 - 13 - - - - - - - - - - 294 - 40 - 47 - 13 - - - - - - - - - - 294 - 60 - 47 - 13 - - - - - - - - - - 174 - 80 - 113 - 20 - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - true - - - - - - 294 - 80 - 47 - 13 - - - - kg - - - - - - 10 - 80 - 140 - 16 - - - - Gesamtgewicht: - - - - - - - 20 - 120 - 561 - 301 - - - - Dimensionen der zu verstauenden Gegenstände - - - true - - - - - - - 20 - 20 - 561 - 91 - - - - - 0 - 91 - - - - Dimension der Garage - - - true - - - - - 10 - 23 - 351 - 58 - - - - - 0 - 0 - - - - - 0 - 58 - - - - - Garage + + + + + + 0 + 91 + - - - - Länge [m] + + + 16777215 + 91 + - - - - Breite [m] + + Dimension der Garage - - - - Höhe [m] + + true - - - + + + + + + 0 + 0 + + + + + 0 + 58 + + + + + 16777215 + 58 + + + + + Garage + + + + + Länge [m] + + + + + Breite [m] + + + + + Höhe [m] + + + + + + + + + + + Dimensionen der zu verstauenden Gegenstände + + + true + + + + + + + + Ergebnis + + + true + + + + + + + + + + + + + Volumen der Garage: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + kg + + + + + + + + + + + + + + Gesamtgewicht: + + + + + + + + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + + + + + Volumen der Gegenstände: + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + + + + + Freier Raum in der Garage: + + + + + + + tableGarage