dynamic layout + start maximized
This commit is contained in:
parent
48f8dc221a
commit
de44023116
4 changed files with 290 additions and 328 deletions
131
src/main.py
131
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()
|
||||
|
|
|
@ -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 = "<p align='center'><h1>" + qApp.applicationDisplayName() + " " + \
|
||||
"<br>" + qApp.applicationVersion() + "</h1>" + \
|
||||
"<br>" + APP_NAME + "<br>" + \
|
||||
"<br>" + APP_DESCR + "<br>" + \
|
||||
"<br>" + qApp.applicationName() + "<br>" + \
|
||||
"<br>" + qApp.translate("main", "Calculates available garage space") + "<br>" + \
|
||||
"<br>" + qApp.translate("utils", "Idea") + ": Balazs Fabian" + "<br>" + \
|
||||
"<br>" + qApp.copyright + "<br>" \
|
||||
"<br> <a href='" + qApp.website + "'>" + qApp.website + "</a></p>"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue