Skip to content
Snippets Groups Projects

Fix program not fitting on low resolution screens

Merged Kien Le requested to merge bug-#180-program_does_not_fit_low_resolution_screens into master
1 file
+ 2
2
Compare changes
  • Side-by-side
  • Inline
+ 67
23
@@ -6,6 +6,7 @@ import traceback
@@ -6,6 +6,7 @@ import traceback
from pathlib import Path
from pathlib import Path
from PySide2 import QtWidgets
from PySide2 import QtWidgets
 
from PySide2.QtGui import QGuiApplication
from PySide2.QtWidgets import QMessageBox
from PySide2.QtWidgets import QMessageBox
from sohstationviewer.view.main_window import MainWindow
from sohstationviewer.view.main_window import MainWindow
@@ -14,7 +15,6 @@ from sohstationviewer.conf.config_processor import (
@@ -14,7 +15,6 @@ from sohstationviewer.conf.config_processor import (
BadConfigError,
BadConfigError,
)
)
# Enable Layer-backing for MacOs version >= 11
# Enable Layer-backing for MacOs version >= 11
# Only needed if using the pyside2 library with version>=5.15.
# Only needed if using the pyside2 library with version>=5.15.
# Layer-backing is always enabled in pyside6.
# Layer-backing is always enabled in pyside6.
@@ -26,47 +26,91 @@ if os_name == 'macOS':
@@ -26,47 +26,91 @@ 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 directory 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)
 
 
def resize_windows(main_window: MainWindow):
 
"""
 
Resize the plotting windows in the program so that they fit well on all
 
screen resolutions.
 
"""
 
screen_size = QtWidgets.QApplication.primaryScreen().size().toTuple()
 
screen_width, screen_height = screen_size
 
main_window.resize(screen_width * 1, screen_height * 1)
 
main_window.waveform_dlg.resize(screen_width * (2 / 3),
 
screen_height * (2 / 3))
 
main_window.tps_dlg.resize(screen_width * (2 / 3), screen_height * (2 / 3))
 
 
main_right_x = (main_window.x() + main_window.frameSize().width())
 
# This offset is based on the hard-coded geometry previously assigned to
 
# the waveform and TPS dialogs
 
wf_tps_x_offset = 50
 
# We are moving the TPS dialog so that it is slightly offset from the right
 
# edge of the main window
 
tps_dlg_x = main_right_x - main_window.tps_dlg.width() - wf_tps_x_offset
 
wf_tps_y = 50
 
main_window.waveform_dlg.move(wf_tps_x_offset, wf_tps_y)
 
main_window.tps_dlg.move(tps_dlg_x, wf_tps_y)
 
 
gps_dlg_y = main_window.height() / 5
 
main_window.gps_dialog.move(main_window.gps_dialog.y(), gps_dlg_y)
 
 
 
def check_if_user_want_to_reset_config() -> bool:
 
"""
 
Show a dialog asking the user if they want to reset the config.
 
:return: whether the user wants to reset the config.
 
"""
 
bad_config_dialog = QMessageBox()
 
bad_config_dialog.setText('Something went wrong when reading the '
 
'config.')
 
bad_config_dialog.setDetailedText(traceback.format_exc())
 
bad_config_dialog.setInformativeText('Do you want to reset the config '
 
'file?')
 
bad_config_dialog.setStandardButtons(QMessageBox.Ok |
 
QMessageBox.Close)
 
bad_config_dialog.setDefaultButton(QMessageBox.Ok)
 
bad_config_dialog.setIcon(QMessageBox.Critical)
 
reset_choice = bad_config_dialog.exec_()
 
return reset_choice == QMessageBox.Ok
 
 
 
def main():
 
# Change the working directory so that relative paths work correctly.
 
fix_relative_paths()
 
app = QtWidgets.QApplication(sys.argv)
app = QtWidgets.QApplication(sys.argv)
wnd = MainWindow()
wnd = MainWindow()
 
config = ConfigProcessor()
config = ConfigProcessor()
config.load_config()
config.load_config()
need_reset = False
do_reset = None
try:
try:
config.validate_config()
config.validate_config()
config.apply_config(wnd)
config.apply_config(wnd)
except (BadConfigError, ValueError) as e:
except (BadConfigError, ValueError) as e:
bad_config_dialog = QMessageBox()
do_reset = check_if_user_want_to_reset_config()
bad_config_dialog.setText('Something went wrong when reading the '
if do_reset:
'config.')
bad_config_dialog.setDetailedText(traceback.format_exc())
bad_config_dialog.setInformativeText('Do you want to reset the config '
'file?')
bad_config_dialog.setStandardButtons(QMessageBox.Ok |
QMessageBox.Close)
bad_config_dialog.setDefaultButton(QMessageBox.Ok)
bad_config_dialog.setIcon(QMessageBox.Critical)
reset_choice = bad_config_dialog.exec_()
if reset_choice == QMessageBox.Ok:
need_reset = True
else:
sys.exit(1)
if need_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)
 
elif do_reset is not None:
 
sys.exit(1)
config.apply_config(wnd)
config.apply_config(wnd)
 
 
resize_windows(wnd)
wnd.show()
wnd.show()
sys.exit(app.exec_())
sys.exit(app.exec_())
Loading