Skip to content
Snippets Groups Projects
Commit 66252307 authored by Kien Le's avatar Kien Le
Browse files

Refactored entry point to make it easier to read

parent 0f8db625
No related branches found
No related tags found
1 merge request!218Fix program not fitting on low resolution screens
No preview for this file type
...@@ -27,21 +27,17 @@ if os_name == 'macOS': ...@@ -27,21 +27,17 @@ if os_name == 'macOS':
os.environ['QT_MAC_WANTS_LAYER'] = '1' os.environ['QT_MAC_WANTS_LAYER'] = '1'
def main(): def fix_relative_paths() -> None:
# Change the working directory so that relative paths work correctly. """
Change the working director so that the relative paths in the code work
correctly.
"""
current_file_path = os.path.abspath(__file__) current_file_path = os.path.abspath(__file__)
current_file_dir = Path(current_file_path).parent current_file_dir = Path(current_file_path).parent
os.chdir(current_file_dir) os.chdir(current_file_dir)
app = QtWidgets.QApplication(sys.argv)
wnd = MainWindow() def check_if_user_want_to_reset_config():
config = ConfigProcessor()
config.load_config()
need_reset = False
try:
config.validate_config()
config.apply_config(wnd)
except (BadConfigError, ValueError) as e:
bad_config_dialog = QMessageBox() bad_config_dialog = QMessageBox()
bad_config_dialog.setText('Something went wrong when reading the ' bad_config_dialog.setText('Something went wrong when reading the '
'config.') 'config.')
...@@ -53,20 +49,35 @@ def main(): ...@@ -53,20 +49,35 @@ def main():
bad_config_dialog.setDefaultButton(QMessageBox.Ok) bad_config_dialog.setDefaultButton(QMessageBox.Ok)
bad_config_dialog.setIcon(QMessageBox.Critical) bad_config_dialog.setIcon(QMessageBox.Critical)
reset_choice = bad_config_dialog.exec_() reset_choice = bad_config_dialog.exec_()
if reset_choice == QMessageBox.Ok: return reset_choice == QMessageBox.Ok
need_reset = True
else:
sys.exit(1) def main():
if need_reset: # Change the working directory so that relative paths work correctly.
fix_relative_paths()
app = QtWidgets.QApplication(sys.argv)
wnd = MainWindow()
config = ConfigProcessor()
config.load_config()
do_reset = False
try:
config.validate_config()
config.apply_config(wnd)
except (BadConfigError, ValueError) as e:
do_reset = check_if_user_want_to_reset_config()
if do_reset:
try: try:
config.reset() config.reset()
except OSError: except OSError:
QMessageBox.critical(None, 'Cannot reset config', QMessageBox.critical(None, 'Cannot reset config',
'Config file cannot be reset. Please ' 'Config file cannot be reset. Please ensure '
'ensure that it is not opened in another ' 'that it is not opened in another program.',
'program.',
QMessageBox.Close) QMessageBox.Close)
sys.exit(1) sys.exit(1)
else:
sys.exit(1)
config.apply_config(wnd) config.apply_config(wnd)
screen_width, screen_height = app.primaryScreen().size().toTuple() screen_width, screen_height = app.primaryScreen().size().toTuple()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment