working settings
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -5,4 +5,6 @@
|
||||
/tests/
|
||||
*.spec
|
||||
*.gtabase
|
||||
*.gtaback
|
||||
*.baseback
|
||||
*.cfg
|
||||
@@ -594,7 +594,7 @@ class Ui_MainWindow(object):
|
||||
MainWindow.setCentralWidget(self.centralwidget)
|
||||
|
||||
self.retranslateUi(MainWindow)
|
||||
self.settings_toolbox.setCurrentIndex(1)
|
||||
self.settings_toolbox.setCurrentIndex(0)
|
||||
QtCore.QMetaObject.connectSlotsByName(MainWindow)
|
||||
|
||||
def retranslateUi(self, MainWindow):
|
||||
@@ -641,7 +641,7 @@ class Ui_MainWindow(object):
|
||||
self.create_backup_button.setText(_translate("MainWindow", "Create backup"))
|
||||
self.load_backup_button.setText(_translate("MainWindow", "Load backup"))
|
||||
self.delete_db_button.setText(_translate("MainWindow", "Delete this database"))
|
||||
self.new_db_name_box.setPlaceholderText(_translate("MainWindow", "New database name"))
|
||||
self.new_db_name_box.setPlaceholderText(_translate("MainWindow", "New database name (without extension)"))
|
||||
self.new_db_create_button.setText(_translate("MainWindow", "Create"))
|
||||
self.settings_toolbox.setItemText(self.settings_toolbox.indexOf(self.database_options_page), _translate("MainWindow", "Database options"))
|
||||
self.app_theme_label.setText(_translate("MainWindow", "App theme (requires restart)"))
|
||||
|
||||
@@ -1688,7 +1688,7 @@ p, li { white-space: pre-wrap; }
|
||||
<item>
|
||||
<widget class="QToolBox" name="settings_toolbox">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="database_options_page">
|
||||
<property name="geometry">
|
||||
@@ -1822,7 +1822,7 @@ p, li { white-space: pre-wrap; }
|
||||
</size>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>New database name</string>
|
||||
<string>New database name (without extension)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import os
|
||||
from gui.modules.core.popup import popup
|
||||
from gui.gui import Ui_MainWindow
|
||||
from modules.config import Config
|
||||
from gui.modules.core import items_list
|
||||
@@ -8,5 +10,50 @@ def on_load_another_db_click(ui: Ui_MainWindow):
|
||||
items_list.refill_list(ui)
|
||||
|
||||
|
||||
def create_backup():
|
||||
with open(os.path.splitext(Config.get().database)[0] + '.gtaback', 'w') as f:
|
||||
f.write(open(Config.get().database).read())
|
||||
|
||||
|
||||
def load_backup(ui: Ui_MainWindow):
|
||||
if os.path.isfile(os.path.splitext(Config.get().database)[0] + '.gtaback'):
|
||||
if popup('Loading backup', 'Do you really want to rollback you database to newest backup state?', 4) == 6:
|
||||
with open(Config.get().database, 'w') as f:
|
||||
try:
|
||||
f.write(open(os.path.splitext(Config.get().database)[0] + '.gtaback').read())
|
||||
except Exception as e:
|
||||
popup("Error", f"Error happened: {e}")
|
||||
items_list.refill_list(ui)
|
||||
|
||||
else:
|
||||
popup('Error', 'No backup found')
|
||||
|
||||
|
||||
def remove_db(ui: Ui_MainWindow):
|
||||
if popup('Removing database', 'Do you really want to remove selected database?', 4) != 6:
|
||||
return
|
||||
|
||||
os.remove(ui.database_list_box.currentText())
|
||||
ui.database_list_box.removeItem(ui.database_list_box.currentIndex())
|
||||
if ui.database_list_box.currentText() != "":
|
||||
Config.update("database", ui.database_list_box.currentText())
|
||||
items_list.refill_list(ui)
|
||||
else:
|
||||
Config.update("database", "default.gtabase")
|
||||
ui.database_list_box.addItem("default.gtabase")
|
||||
items_list.refill_list(ui)
|
||||
|
||||
|
||||
def create_db(ui: Ui_MainWindow):
|
||||
Config.update("database", ui.new_db_name_box.text() + ".gtabase")
|
||||
ui.database_list_box.addItem(Config.get().database)
|
||||
ui.database_list_box.setCurrentText(Config.get().database)
|
||||
items_list.refill_list(ui)
|
||||
|
||||
|
||||
def register_db_handlers(ui: Ui_MainWindow):
|
||||
ui.load_this_db_button.clicked.connect(lambda: on_load_another_db_click(ui))
|
||||
ui.create_backup_button.clicked.connect(create_backup)
|
||||
ui.load_backup_button.clicked.connect(lambda: load_backup(ui))
|
||||
ui.delete_db_button.clicked.connect(lambda: remove_db(ui))
|
||||
ui.new_db_create_button.clicked.connect(lambda: create_db(ui))
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import json
|
||||
import os.path
|
||||
from gui.modules.core.popup import popup
|
||||
from modules.database.model import DatabaseModel, default_database, Item, Profile
|
||||
from modules.config import Config
|
||||
|
||||
@@ -11,9 +13,14 @@ class Database:
|
||||
except Exception as e:
|
||||
print(f"Cannot load database: {e}. Writing default database")
|
||||
print("Old data:")
|
||||
print(open(Config.get().database).read())
|
||||
with open("error.baseback", 'w') as f:
|
||||
f.write(open(Config.get().database).read())
|
||||
if os.path.isfile(Config.get().database):
|
||||
print(open(Config.get().database).read())
|
||||
with open("error.baseback", 'w') as f:
|
||||
f.write(open(Config.get().database).read())
|
||||
popup('Error', 'Error happened while getting database, writing default \n'
|
||||
'Old database wrote to error.baseback file')
|
||||
else:
|
||||
print('No database file, writing new with name from config')
|
||||
with open(Config.get().database, 'w') as f:
|
||||
json.dump(default_database, f, indent=4)
|
||||
return DatabaseModel.from_dict(default_database)
|
||||
|
||||
@@ -29,6 +29,6 @@ class DatabaseModel:
|
||||
|
||||
|
||||
default_database = {
|
||||
"items": None,
|
||||
"profiles": None
|
||||
"items": {},
|
||||
"profiles": {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user