93 lines
3.2 KiB
Python
93 lines
3.2 KiB
Python
import sys
|
|
import json
|
|
from datetime import datetime
|
|
import time
|
|
|
|
from PyQt5 import QtWidgets,QtGui
|
|
|
|
from ui.OpticsToolsGui import Ui_OpticsGUI
|
|
from OpticsPlot import OpticsPlot
|
|
from OpticsModel import Model
|
|
from OpticsMachine import Machine
|
|
from reference import ReferenceManager
|
|
from sandbox import Sandbox
|
|
|
|
|
|
class OpticsTools(QtWidgets.QMainWindow, Ui_OpticsGUI):
|
|
def __init__(self,phase=0, office = False):
|
|
super(OpticsTools, self).__init__()
|
|
self.setupUi(self)
|
|
|
|
self.version = '1.0.1'
|
|
self.setWindowIcon(QtGui.QIcon("rsc/iconoptics.png"))
|
|
self.setWindowTitle("SwissFEL Optics Tools")
|
|
|
|
self.plot = OpticsPlot()
|
|
self.plot.show()
|
|
|
|
# initialize online model
|
|
self.model = Model(phase=phase,parent=self)
|
|
if phase > 0:
|
|
office = True
|
|
self.machine = Machine(parent = True, office = office)
|
|
self.machine.initPVs(self.model.getElements())
|
|
|
|
|
|
|
|
self.reference = ReferenceManager(parent = self)
|
|
self.sandbox = Sandbox(parent = self, machine = self.machine)
|
|
|
|
# initialization
|
|
self.loadSettingsdirect("/sf/data/applications/BD-OpticsTools/reference/settings/ReferenceSetting.json")
|
|
self.sandbox.updateSandbox()
|
|
|
|
# events handling
|
|
self.actionOpen_2.triggered.connect(self.loadSettings)
|
|
self.actionSave.triggered.connect(self.saveSettings)
|
|
|
|
def closeEvent(self, event):
|
|
self.plot.close()
|
|
event.accept()
|
|
|
|
def saveSettings(self):
|
|
options = QtWidgets.QFileDialog.Options()
|
|
options |= QtWidgets.QFileDialog.DontUseNativeDialog
|
|
fileName, _ = QtWidgets.QFileDialog.getSaveFileName(self, "Save Settings",
|
|
"/sf/data/applications/BD-OpticsTools/saved_settings/newSetting.json",
|
|
"Json Files (*.json)", options=options)
|
|
if not fileName:
|
|
return
|
|
settings=self.model.getSettings()
|
|
with open(fileName, 'w', encoding='utf-8') as f:
|
|
json.dump(settings, f, ensure_ascii=False, indent=4)
|
|
|
|
|
|
def loadSettings(self):
|
|
options = QtWidgets.QFileDialog.Options()
|
|
options |= QtWidgets.QFileDialog.DontUseNativeDialog
|
|
fileName, _ = QtWidgets.QFileDialog.getOpenFileName(self, "Open Settings",
|
|
"/sf/data/applications/BD-OpticsTools/saved_settings/newSetting.json",
|
|
"Json Files (*.json)", options=options)
|
|
if not fileName:
|
|
return
|
|
self.loadSettingsdirect(fileName)
|
|
|
|
def loadSettingsdirect(self,fileName):
|
|
with open(fileName, 'r', encoding='utf-8') as f:
|
|
settings = json.load(f)
|
|
self.model.loadSettings(settings)
|
|
# --------------------------------
|
|
# Main routine
|
|
|
|
|
|
if __name__ == '__main__':
|
|
QtWidgets.QApplication.setStyle(QtWidgets.QStyleFactory.create("plastique"))
|
|
app = QtWidgets.QApplication(sys.argv)
|
|
if len(sys.argv) > 1:
|
|
arg=int(sys.argv[1])
|
|
else:
|
|
arg=0
|
|
main = OpticsTools(phase = 0 , office = True)
|
|
main.show()
|
|
sys.exit(app.exec_())
|