Persist the main window geometry for the PyQt wrapper app.

master
Pacman Ghost 6 years ago
parent 8e13cae682
commit f4a5b8386d
  1. 10
      vasl_templates/main.py
  2. 22
      vasl_templates/main_window.py
  3. 4
      vasl_templates/webapp/static/css/main.css

@ -10,7 +10,7 @@ import logging
import urllib.request
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import Qt
from PyQt5.QtCore import Qt, QSettings, QDir
import click
from vasl_templates.main_window import MainWindow
@ -61,6 +61,12 @@ def main( template_pack, remote_debugging, debug ):
remote_debugging = remote_debugging.replace( "localhost", "127.0.0.1" )
os.environ["QTWEBENGINE_REMOTE_DEBUGGING"] = remote_debugging
# load the application settings
fname = "vasl-templates.ini" if sys.platform == "win32" else ".vasl-templates.conf"
if not os.path.isfile( fname ) :
fname = os.path.join( QDir.homePath() , fname )
settings = QSettings( fname , QSettings.IniFormat )
# install the debug config file
if debug:
load_debug_config( debug )
@ -99,7 +105,7 @@ def main( template_pack, remote_debugging, debug ):
# run the application
app = QApplication( sys.argv )
url = "http://localhost:{}".format( port )
main_window = MainWindow( url )
main_window = MainWindow( settings, url )
main_window.show()
ret_code = app.exec_()

@ -32,18 +32,27 @@ class AppWebPage( QWebEnginePage ):
class MainWindow( QWidget ):
"""Main application window."""
def __init__( self, url ):
def __init__( self, settings, url ):
# initialize
super().__init__()
self.settings = settings
self._view = None
self._is_closing = False
# initialize
# initialize the main window
self.setWindowTitle( APP_NAME )
self.setWindowIcon( QIcon(
os.path.join( os.path.split(__file__)[0], "webapp/static/images/snippet.png" )
) )
self.setMinimumSize( 800, 500 )
# restore the window geometry
val = self.settings.value( "MainWindow/geometry" )
if val :
self.restoreGeometry( val )
else :
self.resize( 1000, 600 )
# initialize the layout
# FUDGE! We offer the option to disable the QWebEngineView since getting it to run
@ -94,13 +103,18 @@ class MainWindow( QWidget ):
if self._view is None or self._is_closing:
return
def close_window():
"""Close the main window."""
self.settings.setValue( "MainWindow/geometry" , self.saveGeometry() )
self.close()
# check if the scenario is dirty
def callback( is_dirty ):
"""Callback for PyQt to return the result of running the Javascript."""
if not is_dirty:
# nope - just close the window
self._is_closing = True
self.close()
close_window()
return
# yup - ask the user to confirm the close
rc = self.ask(
@ -111,7 +125,7 @@ class MainWindow( QWidget ):
if rc == QMessageBox.Yes:
# confirmed - close the window
self._is_closing = True
self.close()
close_window()
self._view.page().runJavaScript( "is_scenario_dirty()", callback )
evt.ignore() # nb: we wait until the Javascript finishes to process the event

@ -40,8 +40,8 @@ ul, ol { margin: 0.5em 0 0 1.25em ; br}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#tabs-scenario { display: flex ; }
#tabs-scenario .left { width: 28em ; min-width: 28em ; }
#tabs-scenario .right { flex-grow: 1 ; min-width: 23em ; }
#tabs-scenario .left { width: 32em ; min-width: 32em ; }
#tabs-scenario .right { flex-grow: 1 ; min-width: 25em ; }
#tabs-scenario .left { display: flex ; flex-direction: column ; }
#tabs-scenario .tl { flex-basis: content ; }

Loading…
Cancel
Save