dynamic layout + start maximized

This commit is contained in:
Paul S 2021-07-01 12:22:26 +02:00
parent 48f8dc221a
commit de44023116
4 changed files with 290 additions and 328 deletions

View file

@ -1,5 +1,15 @@
# Changelog GarageCalc1 # 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 ## [0.3] - 2021-06-29
### Added ### Added
- Warnt beim Beenden falls ungespeicherte Einträge vorhanden sind - Warnt beim Beenden falls ungespeicherte Einträge vorhanden sind

View file

@ -28,14 +28,14 @@ from utils import show_about, resource_path
from clsTableWidget import TableWidget from clsTableWidget import TableWidget
# Local globals # Local globals
APP_VERSION = "v0.4" APP_VERSION = "v0.4.1"
DIR_APPDATA = os.getenv('LOCALAPPDATA') DIR_APPDATA = os.getenv('LOCALAPPDATA')
APP_NAME = QCoreApplication.translate("main", "Garage Space Calculator") APP_NAME = "Garage Space Calculator"
APP_DISPNAME = "GarageCalc" APP_DISPNAME = "GarageCalc"
APP_AUTHOR = "Paul Salajean" 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_COPYRIGHT = "(c) Paul Salajean 2021"
APP_WEBSITE = "https://gitlab.com/ProfP303" APP_WEBSITE = "https://gitlab.com/ProfP303"
APP_DESKTOPFILENAME = APP_DISPNAME 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?") 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): def __init__(self, language):
super().__init__() super().__init__()
@ -83,8 +139,10 @@ class MyMainWindow(QMainWindow):
self.create_actions() self.create_actions()
self.create_toolbar() self.create_toolbar()
self.create_statusbar() self.create_statusbar()
global APP_NAME 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.statusBar.showMessage(f"{APP_NAME} {APP_VERSION} - {APP_AUTHOR}", 5000)
self.calc_voluminae() self.calc_voluminae()
self.ui.efWeight.setText(str("0")) self.ui.efWeight.setText(str("0"))
@ -157,20 +215,12 @@ class MyMainWindow(QMainWindow):
self.ui = loader.load(ui_file, self) self.ui = loader.load(ui_file, self)
ui_file.close() 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 = TableWidget()
self.ui.tableStuff.setColumnCount(TBL_STUFF_COL_COUNT) self.ui.tableStuff.setColumnCount(TBL_STUFF_COL_COUNT)
self.ui.tableStuff.setRowCount(TBL_STUFF_ROW_COUNT) self.ui.tableStuff.setRowCount(TBL_STUFF_ROW_COUNT)
self.ui.tableStuff.move(10, 23) layoutGb.addWidget(self.ui.tableStuff)
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)
def create_actions(self): def create_actions(self):
self.actionNew = QAction() self.actionNew = QAction()
@ -782,50 +832,7 @@ class MyMainWindow(QMainWindow):
self.retranslateUi() self.retranslateUi()
####################################################################
if __name__ == "__main__": if __name__ == "__main__":
qApp = QApplication([]) main()
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_())

View file

@ -34,13 +34,10 @@ def show_about():
msg = QMessageBox() msg = QMessageBox()
msg.setIconPixmap(QPixmap(resource_path(APP_ICON))) 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 = "<p align='center'><h1>" + qApp.applicationDisplayName() + " " + \ text = "<p align='center'><h1>" + qApp.applicationDisplayName() + " " + \
"<br>" + qApp.applicationVersion() + "</h1>" + \ "<br>" + qApp.applicationVersion() + "</h1>" + \
"<br>" + APP_NAME + "<br>" + \ "<br>" + qApp.applicationName() + "<br>" + \
"<br>" + APP_DESCR + "<br>" + \ "<br>" + qApp.translate("main", "Calculates available garage space") + "<br>" + \
"<br>" + qApp.translate("utils", "Idea") + ": Balazs Fabian" + "<br>" + \ "<br>" + qApp.translate("utils", "Idea") + ": Balazs Fabian" + "<br>" + \
"<br>" + qApp.copyright + "<br>" \ "<br>" + qApp.copyright + "<br>" \
"<br> <a href='" + qApp.website + "'>" + qApp.website + "</a></p>" "<br> <a href='" + qApp.website + "'>" + qApp.website + "</a></p>"

View file

@ -13,271 +13,219 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<widget class="QGroupBox" name="gbResults"> <layout class="QVBoxLayout" name="verticalLayout_2">
<property name="geometry"> <item>
<rect> <widget class="QGroupBox" name="gbGarage">
<x>20</x> <property name="minimumSize">
<y>440</y> <size>
<width>541</width> <width>0</width>
<height>121</height> <height>91</height>
</rect> </size>
</property>
<property name="title">
<string>Ergebnis</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
<widget class="QLabel" name="lblVol_Garage">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>140</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Volumen der Garage:</string>
</property>
</widget>
<widget class="QLabel" name="lblVol_Stuff">
<property name="geometry">
<rect>
<x>10</x>
<y>40</y>
<width>140</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Volumen der Gegenstände:</string>
</property>
</widget>
<widget class="QLabel" name="lblVol_Free">
<property name="geometry">
<rect>
<x>10</x>
<y>60</y>
<width>140</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Freier Raum in der Garage:</string>
</property>
</widget>
<widget class="QLineEdit" name="efVol_Garage">
<property name="geometry">
<rect>
<x>174</x>
<y>20</y>
<width>113</width>
<height>20</height>
</rect>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
<widget class="QLineEdit" name="efVol_Stuff">
<property name="geometry">
<rect>
<x>174</x>
<y>40</y>
<width>113</width>
<height>20</height>
</rect>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
<widget class="QLineEdit" name="efVol_Free">
<property name="geometry">
<rect>
<x>174</x>
<y>60</y>
<width>113</width>
<height>20</height>
</rect>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="lblM3">
<property name="geometry">
<rect>
<x>294</x>
<y>20</y>
<width>47</width>
<height>13</height>
</rect>
</property>
<property name="text">
<string>m³</string>
</property>
</widget>
<widget class="QLabel" name="lblM3_2">
<property name="geometry">
<rect>
<x>294</x>
<y>40</y>
<width>47</width>
<height>13</height>
</rect>
</property>
<property name="text">
<string>m³</string>
</property>
</widget>
<widget class="QLabel" name="lblM3_3">
<property name="geometry">
<rect>
<x>294</x>
<y>60</y>
<width>47</width>
<height>13</height>
</rect>
</property>
<property name="text">
<string>m³</string>
</property>
</widget>
<widget class="QLineEdit" name="efWeight">
<property name="geometry">
<rect>
<x>174</x>
<y>80</y>
<width>113</width>
<height>20</height>
</rect>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="lblM3_4">
<property name="geometry">
<rect>
<x>294</x>
<y>80</y>
<width>47</width>
<height>13</height>
</rect>
</property>
<property name="text">
<string>kg</string>
</property>
</widget>
<widget class="QLabel" name="lblWeight">
<property name="geometry">
<rect>
<x>10</x>
<y>80</y>
<width>140</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Gesamtgewicht:</string>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="gbStuff">
<property name="geometry">
<rect>
<x>20</x>
<y>120</y>
<width>561</width>
<height>301</height>
</rect>
</property>
<property name="title">
<string>Dimensionen der zu verstauenden Gegenstände</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout"/>
</widget>
<widget class="QGroupBox" name="gbGarage">
<property name="geometry">
<rect>
<x>20</x>
<y>20</y>
<width>561</width>
<height>91</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>91</height>
</size>
</property>
<property name="title">
<string>Dimension der Garage</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
<widget class="QTableWidget" name="tableGarage">
<property name="geometry">
<rect>
<x>10</x>
<y>23</y>
<width>351</width>
<height>58</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>58</height>
</size>
</property>
<row>
<property name="text">
<string>Garage</string>
</property> </property>
</row> <property name="maximumSize">
<column> <size>
<property name="text"> <width>16777215</width>
<string>Länge [m]</string> <height>91</height>
</size>
</property> </property>
</column> <property name="title">
<column> <string>Dimension der Garage</string>
<property name="text">
<string>Breite [m]</string>
</property> </property>
</column> <property name="flat">
<column> <bool>true</bool>
<property name="text">
<string>Höhe [m]</string>
</property> </property>
</column> <layout class="QHBoxLayout" name="horizontalLayout">
</widget> <item>
</widget> <widget class="QTableWidget" name="tableGarage">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>58</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>58</height>
</size>
</property>
<row>
<property name="text">
<string>Garage</string>
</property>
</row>
<column>
<property name="text">
<string>Länge [m]</string>
</property>
</column>
<column>
<property name="text">
<string>Breite [m]</string>
</property>
</column>
<column>
<property name="text">
<string>Höhe [m]</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gbStuff">
<property name="title">
<string>Dimensionen der zu verstauenden Gegenstände</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout"/>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gbResults">
<property name="title">
<string>Ergebnis</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="3">
<widget class="QLabel" name="lblM3_3">
<property name="text">
<string>m³</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="lblVol_Garage">
<property name="text">
<string>Volumen der Garage:</string>
</property>
</widget>
</item>
<item row="0" column="4">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="3">
<widget class="QLabel" name="lblM3_4">
<property name="text">
<string>kg</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLabel" name="lblM3_2">
<property name="text">
<string>m³</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="lblWeight">
<property name="text">
<string>Gesamtgewicht:</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="lblM3">
<property name="text">
<string>m³</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLineEdit" name="efVol_Free">
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QLineEdit" name="efWeight">
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="lblVol_Stuff">
<property name="text">
<string>Volumen der Gegenstände:</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLineEdit" name="efVol_Garage">
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="efVol_Stuff">
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="lblVol_Free">
<property name="text">
<string>Freier Raum in der Garage:</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget> </widget>
<tabstops> <tabstops>
<tabstop>tableGarage</tabstop> <tabstop>tableGarage</tabstop>