Verbesserungen in Sprachdatei "hu_HU.ts" + Laden von Zahlen aus der .CSV-Datei als Zahlenwerte, nicht Text

This commit is contained in:
Paul S 2021-07-02 17:16:03 +02:00
parent fb88dac713
commit f1123a6fd5
4 changed files with 57 additions and 31 deletions

View file

@ -1,5 +1,13 @@
# Changelog GarageCalc1 # Changelog GarageCalc1
## [0.5.2] - 2021-07-02
## Changed
- Verbesserungen in Sprachdatei "hu_HU.ts"
## [0.5.1] - 2021-07-02
## Fixed
- Laden von Zahlen aus der .CSV-Datei als Zahlenwerte, nicht Text
## [0.5] - 2021-07-02 ## [0.5] - 2021-07-02
## Added ## Added
- Tabelle "Gegenstände": Zeilen sind sortierbar (-> Klick auf Spaltenköpfe) - Tabelle "Gegenstände": Zeilen sind sortierbar (-> Klick auf Spaltenköpfe)

Binary file not shown.

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS> <!DOCTYPE TS>
<TS version="2.1" language="de_DE"> <TS version="2.1" language="de_DE">
<context> <context>
@ -6,12 +6,12 @@
<message> <message>
<location filename="clsTableWidget.py" line="87"/> <location filename="clsTableWidget.py" line="87"/>
<source>Cut</source> <source>Cut</source>
<translation>Vágd ki</translation> <translation>kivágni</translation>
</message> </message>
<message> <message>
<location filename="clsTableWidget.py" line="88"/> <location filename="clsTableWidget.py" line="88"/>
<source>Copy</source> <source>Copy</source>
<translation>Vettem</translation> <translation>másolás</translation>
</message> </message>
<message> <message>
<location filename="clsTableWidget.py" line="89"/> <location filename="clsTableWidget.py" line="89"/>
@ -21,7 +21,7 @@
<message> <message>
<location filename="clsTableWidget.py" line="258"/> <location filename="clsTableWidget.py" line="258"/>
<source>Delete</source> <source>Delete</source>
<translation>Törölje</translation> <translation>Törlés</translation>
</message> </message>
<message> <message>
<location filename="clsTableWidget.py" line="108"/> <location filename="clsTableWidget.py" line="108"/>

View file

@ -28,7 +28,7 @@ from utils import show_about, resource_path
from clsTableWidget import TableWidget from clsTableWidget import TableWidget
# Local globals # Local globals
APP_VERSION = "v0.5" APP_VERSION = "v0.5.2"
DIR_APPDATA = os.getenv('LOCALAPPDATA') DIR_APPDATA = os.getenv('LOCALAPPDATA')
@ -70,11 +70,15 @@ WIN_HEIGHT = 640
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?")
CONFIG = configparser.ConfigParser()
TRANSLATOR = QTranslator()
#################################################################### ####################################################################
def main(): def main():
qApp = QApplication(sys.argv) qApp = QApplication(sys.argv)
global APP_NAME global APP_NAME, CONFIG, TRANSLATOR
qApp.setApplicationName(APP_NAME) qApp.setApplicationName(APP_NAME)
qApp.setApplicationDisplayName(APP_DISPNAME) qApp.setApplicationDisplayName(APP_DISPNAME)
qApp.setApplicationVersion(APP_VERSION) qApp.setApplicationVersion(APP_VERSION)
@ -84,34 +88,30 @@ def main():
qApp.setWindowIcon(QIcon(APP_ICON)) qApp.setWindowIcon(QIcon(APP_ICON))
qApp.setDesktopFileName(APP_DESKTOPFILENAME) qApp.setDesktopFileName(APP_DESKTOPFILENAME)
config = configparser.ConfigParser()
language = "Deutsch" language = "Deutsch"
if os.path.exists(os.path.join(DIR_APPDATA, APP_DISPNAME, APP_DISPNAME + '.ini')): 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')) CONFIG.read(os.path.join(DIR_APPDATA, APP_DISPNAME, APP_DISPNAME + '.ini'))
language = config['DEFAULT']['language'] language = CONFIG['DEFAULT']['language']
else: else:
config['DEFAULT']['language'] = language CONFIG['DEFAULT']['language'] = language
if not os.path.exists(os.path.join(DIR_APPDATA, APP_DISPNAME)): if not os.path.exists(os.path.join(DIR_APPDATA, APP_DISPNAME)):
os.makedirs(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 with open(os.path.join(DIR_APPDATA, APP_DISPNAME, APP_DISPNAME + '.ini'), 'w') as configfile: # save
config.write(configfile) CONFIG.write(configfile)
translator = QTranslator()
print("Current dir:", os.getcwd()) print("Current dir:", os.getcwd())
if language == "Deutsch": if language == "Deutsch":
print("Loading german language file.") print("Loading german language file.")
translator.load(resource_path('./i18n/de_DE')) TRANSLATOR.load(resource_path('./i18n/de_DE'))
elif language == "Magyar": elif language == "Magyar":
print("Loading hungarian langauge file.") print("Loading hungarian langauge file.")
translator.load(resource_path('./i18n/hu_HU')) TRANSLATOR.load(resource_path('./i18n/hu_HU'))
else: else:
print(f"Unknown language setting '{language}' -> defaulting to english language.") print(f"Unknown language setting '{language}' -> defaulting to english language.")
qApp.installTranslator(translator) qApp.installTranslator(TRANSLATOR)
app_name = qApp.translate("main", APP_NAME) app_name = qApp.translate("main", APP_NAME)
qApp.setApplicationName(app_name) qApp.setApplicationName(app_name)
@ -258,7 +258,6 @@ class MainWindow(QMainWindow):
layoutGb.addWidget(self.ui.tableStuff) layoutGb.addWidget(self.ui.tableStuff)
def create_actions(self): def create_actions(self):
self.actionNew = QAction() self.actionNew = QAction()
self.actionNew.setIcon(QIcon(resource_path(ICON_NEW))) self.actionNew.setIcon(QIcon(resource_path(ICON_NEW)))
@ -369,6 +368,7 @@ class MainWindow(QMainWindow):
if reply == QMessageBox.No: if reply == QMessageBox.No:
return False return False
self.init_ui() self.init_ui()
self.ui.tableStuff.sortByColumn(-1) # reset sorting
def file_save(self): def file_save(self):
tblGarage = self.ui.tableGarage tblGarage = self.ui.tableGarage
@ -515,6 +515,7 @@ class MainWindow(QMainWindow):
options=options) options=options)
if fileName: if fileName:
self.init_ui() self.init_ui()
self.ui.tableStuff.sortByColumn(-1) # reset sorting
file = open(fileName, "r", newline='') file = open(fileName, "r", newline='')
reader = csv.reader(file, delimiter=';') reader = csv.reader(file, delimiter=';')
@ -528,9 +529,9 @@ class MainWindow(QMainWindow):
garage_height = row[3] garage_height = row[3]
garage_comment = row[4] garage_comment = row[4]
tblGarage.setItem(0, COL_LENGTH-1, QTableWidgetItem(str(garage_length))) tblGarage.setItem(0, COL_LENGTH-1, QTableWidgetItem(garage_length))
tblGarage.setItem(0, COL_WIDTH-1, QTableWidgetItem(str(garage_width))) tblGarage.setItem(0, COL_WIDTH-1, QTableWidgetItem(garage_width))
tblGarage.setItem(0, COL_HEIGHT-1, QTableWidgetItem(str(garage_height))) tblGarage.setItem(0, COL_HEIGHT-1, QTableWidgetItem(garage_height))
tblGarage.setItem(0, COL_COMMENT-1, QTableWidgetItem(garage_comment)) tblGarage.setItem(0, COL_COMMENT-1, QTableWidgetItem(garage_comment))
except IndexError as ex: except IndexError as ex:
@ -546,10 +547,26 @@ class MainWindow(QMainWindow):
stuff_comment = row[5] stuff_comment = row[5]
tblStuff.setItem(row_idx - 1, COL_STUFF, QTableWidgetItem(stuff)) tblStuff.setItem(row_idx - 1, COL_STUFF, QTableWidgetItem(stuff))
tblStuff.setItem(row_idx - 1, COL_LENGTH, QTableWidgetItem(str(stuff_length)))
tblStuff.setItem(row_idx - 1, COL_WIDTH, QTableWidgetItem(str(stuff_width))) item = QTableWidgetItem()
tblStuff.setItem(row_idx - 1, COL_HEIGHT, QTableWidgetItem(str(stuff_height))) item.setData(Qt.DisplayRole, float(stuff_length))
tblStuff.setItem(row_idx - 1, COL_WEIGHT, QTableWidgetItem(str(stuff_weight))) tblStuff.setItem(row_idx - 1, COL_LENGTH, item)
# tblStuff.setItem(row_idx - 1, COL_WIDTH, QTableWidgetItem(float(stuff_width)))
item = QTableWidgetItem()
item.setData(Qt.DisplayRole, float(stuff_width))
tblStuff.setItem(row_idx - 1, COL_WIDTH, item)
#tblStuff.setItem(row_idx - 1, COL_HEIGHT, QTableWidgetItem(float(stuff_height)))
item = QTableWidgetItem(stuff_height)
item.setData(Qt.DisplayRole, float(stuff_height))
tblStuff.setItem(row_idx - 1, COL_HEIGHT, item)
# tblStuff.setItem(row_idx - 1, COL_WEIGHT, QTableWidgetItem(float(stuff_weight)))
item = QTableWidgetItem(stuff_weight)
item.setData(Qt.DisplayRole, float(stuff_weight))
tblStuff.setItem(row_idx - 1, COL_WEIGHT, item)
tblStuff.setItem(row_idx - 1, COL_COMMENT, QTableWidgetItem(stuff_comment)) tblStuff.setItem(row_idx - 1, COL_COMMENT, QTableWidgetItem(stuff_comment))
except IndexError as ex: except IndexError as ex:
@ -871,6 +888,7 @@ class MainWindow(QMainWindow):
def store_selected_language(self, menu): def store_selected_language(self, menu):
""" Stores selected menu labels to ini-file. """ """ Stores selected menu labels to ini-file. """
# [print(action.text()) for action in menu.actions() if action.isChecked()] # [print(action.text()) for action in menu.actions() if action.isChecked()]
global CONFIG
print("Current dir:", os.getcwd()) print("Current dir:", os.getcwd())
language = "English" language = "English"
@ -878,23 +896,23 @@ class MainWindow(QMainWindow):
if action.isChecked(): if action.isChecked():
language = action.text() language = action.text()
config['DEFAULT']['language'] = language CONFIG['DEFAULT']['language'] = language
if not os.path.exists(os.path.join(DIR_APPDATA, APP_DISPNAME)): if not os.path.exists(os.path.join(DIR_APPDATA, APP_DISPNAME)):
os.makedirs(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 with open(os.path.join(DIR_APPDATA, APP_DISPNAME, APP_DISPNAME + '.ini'), 'w') as configfile: # save
config.write(configfile) CONFIG.write(configfile)
if language == "Deutsch": if language == "Deutsch":
print("Loading german language file.") print("Loading german language file.")
translator.load(resource_path('./i18n/de_DE')) TRANSLATOR.load(resource_path('./i18n/de_DE'))
elif language == "Magyar": elif language == "Magyar":
print("Loading hungarian langauge file.") print("Loading hungarian langauge file.")
translator.load(resource_path('./i18n/hu_HU')) TRANSLATOR.load(resource_path('./i18n/hu_HU'))
else: else:
#qApp.removeTranslator(translator)
translator.load("dummy")
print(f"Unknown language setting '{language}' -> defaulting to english language.") print(f"Unknown language setting '{language}' -> defaulting to english language.")
TRANSLATOR.load("dummy")
self.retranslateUi() self.retranslateUi()