parent
a90b2a6d4a
commit
9c9771a1b4
After Width: | Height: | Size: 3.8 KiB |
@ -0,0 +1,91 @@ |
|||||||
|
"""Implement the "server settings" dialog.""" |
||||||
|
|
||||||
|
import os |
||||||
|
|
||||||
|
from PyQt5 import uic |
||||||
|
from PyQt5.QtWidgets import QDialog, QFileDialog |
||||||
|
from PyQt5.QtGui import QIcon |
||||||
|
|
||||||
|
from vasl_templates.main import app_settings |
||||||
|
from vasl_templates.main_window import MainWindow |
||||||
|
from vasl_templates.webapp.config.constants import DATA_DIR |
||||||
|
from vasl_templates.webapp.file_server.vasl_mod import VaslMod |
||||||
|
from vasl_templates.webapp.files import install_vasl_mod |
||||||
|
|
||||||
|
# --------------------------------------------------------------------- |
||||||
|
|
||||||
|
class ServerSettingsDialog( QDialog ): |
||||||
|
"""Let the user manage the server settings.""" |
||||||
|
|
||||||
|
def __init__( self, parent ) : |
||||||
|
|
||||||
|
# initialize |
||||||
|
super().__init__( parent=parent ) |
||||||
|
|
||||||
|
# initialize the UI |
||||||
|
base_dir = os.path.split( __file__ )[0] |
||||||
|
dname = os.path.join( base_dir, "ui/server_settings.ui" ) |
||||||
|
uic.loadUi( dname, self ) |
||||||
|
self.select_vasl_mod_button.setIcon( |
||||||
|
QIcon( os.path.join( base_dir, "resources/file_browser.png" ) ) |
||||||
|
) |
||||||
|
self.setMinimumSize( self.size() ) |
||||||
|
|
||||||
|
# initialize handlers |
||||||
|
self.select_vasl_mod_button.clicked.connect( self.on_select_vasl_mod ) |
||||||
|
self.ok_button.clicked.connect( self.on_ok ) |
||||||
|
self.cancel_button.clicked.connect( self.on_cancel ) |
||||||
|
|
||||||
|
# load the current server settings |
||||||
|
self.vasl_mod.setText( app_settings.value( "ServerSettings/vasl-mod" ) ) |
||||||
|
|
||||||
|
def on_select_vasl_mod( self ): |
||||||
|
"""Let the user select a VASL module.""" |
||||||
|
fname = QFileDialog.getOpenFileName( |
||||||
|
self, "Select VASL module", |
||||||
|
app_settings.value( "ServerSettings/vasl-mod" ), |
||||||
|
"VASL module files (*.vmod)|All files (*.*)" |
||||||
|
)[0] |
||||||
|
if fname: |
||||||
|
self.vasl_mod.setText( fname ) |
||||||
|
|
||||||
|
def on_ok( self ): |
||||||
|
"""Accept the new server settings.""" |
||||||
|
|
||||||
|
# save the new settings |
||||||
|
fname = self.vasl_mod.text().strip() |
||||||
|
vasl_mod_changed = fname != app_settings.value( "ServerSettings/vasl-mod" ) |
||||||
|
app_settings.setValue( "ServerSettings/vasl-mod", fname ) |
||||||
|
|
||||||
|
# install the new settings |
||||||
|
# NOTE: We should really do this before saving the new settings, but that's more trouble |
||||||
|
# than it's worth at this stage... :-/ |
||||||
|
try: |
||||||
|
install_server_settings() |
||||||
|
except Exception as ex: #pylint: disable=broad-except |
||||||
|
MainWindow.showErrorMsg( "Couldn't install the server settings:\n\n{}".format( ex ) ) |
||||||
|
return |
||||||
|
self.close() |
||||||
|
|
||||||
|
# check if the VASL module was changed |
||||||
|
if vasl_mod_changed: |
||||||
|
# NOTE: It would be nice not to require a restart, but calling QWebEngineProfile.clearHttpCache() doesn't |
||||||
|
# seem to, ya know, clear the cache, nor does setting the cache type to NoCache seem to do anything :-/ |
||||||
|
MainWindow.showInfoMsg( "The VASL module was changed - you should restart the program." ) |
||||||
|
|
||||||
|
def on_cancel( self ): |
||||||
|
"""Cancel the dialog.""" |
||||||
|
self.close() |
||||||
|
|
||||||
|
# --------------------------------------------------------------------- |
||||||
|
|
||||||
|
def install_server_settings(): |
||||||
|
"""Install the server settings.""" |
||||||
|
|
||||||
|
# load the VASL module |
||||||
|
fname = app_settings.value( "ServerSettings/vasl-mod" ) |
||||||
|
if fname: |
||||||
|
vasl_mod = VaslMod( fname, DATA_DIR ) |
||||||
|
else: |
||||||
|
vasl_mod = None |
||||||
|
install_vasl_mod( vasl_mod ) |
@ -0,0 +1,204 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<ui version="4.0"> |
||||||
|
<class>Dialog</class> |
||||||
|
<widget class="QDialog" name="Dialog"> |
||||||
|
<property name="windowModality"> |
||||||
|
<enum>Qt::ApplicationModal</enum> |
||||||
|
</property> |
||||||
|
<property name="geometry"> |
||||||
|
<rect> |
||||||
|
<x>0</x> |
||||||
|
<y>0</y> |
||||||
|
<width>400</width> |
||||||
|
<height>90</height> |
||||||
|
</rect> |
||||||
|
</property> |
||||||
|
<property name="windowTitle"> |
||||||
|
<string>Server settings</string> |
||||||
|
</property> |
||||||
|
<property name="modal"> |
||||||
|
<bool>true</bool> |
||||||
|
</property> |
||||||
|
<layout class="QVBoxLayout" name="verticalLayout"> |
||||||
|
<item> |
||||||
|
<widget class="QWidget" name="widget_2" native="true"> |
||||||
|
<property name="sizePolicy"> |
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Fixed"> |
||||||
|
<horstretch>0</horstretch> |
||||||
|
<verstretch>0</verstretch> |
||||||
|
</sizepolicy> |
||||||
|
</property> |
||||||
|
<property name="minimumSize"> |
||||||
|
<size> |
||||||
|
<width>0</width> |
||||||
|
<height>30</height> |
||||||
|
</size> |
||||||
|
</property> |
||||||
|
<property name="maximumSize"> |
||||||
|
<size> |
||||||
|
<width>16777215</width> |
||||||
|
<height>30</height> |
||||||
|
</size> |
||||||
|
</property> |
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2"> |
||||||
|
<property name="spacing"> |
||||||
|
<number>5</number> |
||||||
|
</property> |
||||||
|
<property name="leftMargin"> |
||||||
|
<number>0</number> |
||||||
|
</property> |
||||||
|
<property name="topMargin"> |
||||||
|
<number>0</number> |
||||||
|
</property> |
||||||
|
<property name="rightMargin"> |
||||||
|
<number>0</number> |
||||||
|
</property> |
||||||
|
<property name="bottomMargin"> |
||||||
|
<number>0</number> |
||||||
|
</property> |
||||||
|
<item> |
||||||
|
<widget class="QLabel" name="label"> |
||||||
|
<property name="text"> |
||||||
|
<string>&VASL module:</string> |
||||||
|
</property> |
||||||
|
<property name="buddy"> |
||||||
|
<cstring>vasl_mod</cstring> |
||||||
|
</property> |
||||||
|
</widget> |
||||||
|
</item> |
||||||
|
<item> |
||||||
|
<widget class="QLineEdit" name="vasl_mod"/> |
||||||
|
</item> |
||||||
|
<item> |
||||||
|
<widget class="QPushButton" name="select_vasl_mod_button"> |
||||||
|
<property name="sizePolicy"> |
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> |
||||||
|
<horstretch>0</horstretch> |
||||||
|
<verstretch>0</verstretch> |
||||||
|
</sizepolicy> |
||||||
|
</property> |
||||||
|
<property name="minimumSize"> |
||||||
|
<size> |
||||||
|
<width>25</width> |
||||||
|
<height>25</height> |
||||||
|
</size> |
||||||
|
</property> |
||||||
|
<property name="maximumSize"> |
||||||
|
<size> |
||||||
|
<width>25</width> |
||||||
|
<height>25</height> |
||||||
|
</size> |
||||||
|
</property> |
||||||
|
<property name="text"> |
||||||
|
<string/> |
||||||
|
</property> |
||||||
|
<property name="autoDefault"> |
||||||
|
<bool>true</bool> |
||||||
|
</property> |
||||||
|
</widget> |
||||||
|
</item> |
||||||
|
</layout> |
||||||
|
<zorder>vasl_mod</zorder> |
||||||
|
<zorder>label</zorder> |
||||||
|
<zorder>select_vasl_mod_button</zorder> |
||||||
|
</widget> |
||||||
|
</item> |
||||||
|
<item> |
||||||
|
<spacer name="verticalSpacer"> |
||||||
|
<property name="orientation"> |
||||||
|
<enum>Qt::Vertical</enum> |
||||||
|
</property> |
||||||
|
<property name="sizeHint" stdset="0"> |
||||||
|
<size> |
||||||
|
<width>20</width> |
||||||
|
<height>40</height> |
||||||
|
</size> |
||||||
|
</property> |
||||||
|
</spacer> |
||||||
|
</item> |
||||||
|
<item> |
||||||
|
<widget class="QWidget" name="widget" native="true"> |
||||||
|
<property name="sizePolicy"> |
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Fixed"> |
||||||
|
<horstretch>0</horstretch> |
||||||
|
<verstretch>0</verstretch> |
||||||
|
</sizepolicy> |
||||||
|
</property> |
||||||
|
<property name="minimumSize"> |
||||||
|
<size> |
||||||
|
<width>0</width> |
||||||
|
<height>30</height> |
||||||
|
</size> |
||||||
|
</property> |
||||||
|
<property name="maximumSize"> |
||||||
|
<size> |
||||||
|
<width>16777215</width> |
||||||
|
<height>30</height> |
||||||
|
</size> |
||||||
|
</property> |
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout"> |
||||||
|
<property name="spacing"> |
||||||
|
<number>5</number> |
||||||
|
</property> |
||||||
|
<property name="leftMargin"> |
||||||
|
<number>0</number> |
||||||
|
</property> |
||||||
|
<property name="topMargin"> |
||||||
|
<number>0</number> |
||||||
|
</property> |
||||||
|
<property name="rightMargin"> |
||||||
|
<number>0</number> |
||||||
|
</property> |
||||||
|
<property name="bottomMargin"> |
||||||
|
<number>0</number> |
||||||
|
</property> |
||||||
|
<item> |
||||||
|
<spacer name="horizontalSpacer"> |
||||||
|
<property name="orientation"> |
||||||
|
<enum>Qt::Horizontal</enum> |
||||||
|
</property> |
||||||
|
<property name="sizeHint" stdset="0"> |
||||||
|
<size> |
||||||
|
<width>309</width> |
||||||
|
<height>20</height> |
||||||
|
</size> |
||||||
|
</property> |
||||||
|
</spacer> |
||||||
|
</item> |
||||||
|
<item> |
||||||
|
<widget class="QPushButton" name="ok_button"> |
||||||
|
<property name="sizePolicy"> |
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> |
||||||
|
<horstretch>0</horstretch> |
||||||
|
<verstretch>0</verstretch> |
||||||
|
</sizepolicy> |
||||||
|
</property> |
||||||
|
<property name="text"> |
||||||
|
<string>OK</string> |
||||||
|
</property> |
||||||
|
<property name="default"> |
||||||
|
<bool>true</bool> |
||||||
|
</property> |
||||||
|
</widget> |
||||||
|
</item> |
||||||
|
<item> |
||||||
|
<widget class="QPushButton" name="cancel_button"> |
||||||
|
<property name="sizePolicy"> |
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> |
||||||
|
<horstretch>0</horstretch> |
||||||
|
<verstretch>0</verstretch> |
||||||
|
</sizepolicy> |
||||||
|
</property> |
||||||
|
<property name="text"> |
||||||
|
<string>Cancel</string> |
||||||
|
</property> |
||||||
|
</widget> |
||||||
|
</item> |
||||||
|
</layout> |
||||||
|
</widget> |
||||||
|
</item> |
||||||
|
</layout> |
||||||
|
</widget> |
||||||
|
<resources/> |
||||||
|
<connections/> |
||||||
|
</ui> |
@ -1,4 +1,4 @@ |
|||||||
<div id="user-settings" style="display:none;"> |
<div id="user-settings" style="display:none;"> |
||||||
<input type="checkbox" name="include-vasl-images-in-snippets"> Include VASL images in snippets |
<input type="checkbox" name="include-vasl-images-in-snippets"> Include VASL images in snippets |
||||||
<div class="note include-vasl-images-in-snippets-hint" style="margin-left:20px;">This program must be running before you load the VASL scenario.</div> |
<div class="note include-vasl-images-in-snippets-hint" style="margin-left:20px;">This program must be running before you load the scenario in VASL.</div> |
||||||
</div> |
</div> |
||||||
|
Loading…
Reference in new issue