111 lines
4.0 KiB
Python
111 lines
4.0 KiB
Python
import sys
|
|
import json
|
|
from datetime import datetime
|
|
import time
|
|
from argparse import ArgumentParser
|
|
|
|
from PyQt5 import QtWidgets,QtGui
|
|
|
|
from ui.OpticsToolsGui import Ui_OpticsGUI
|
|
from plot import OpticsPlot
|
|
from model import Model
|
|
from machine import Machine
|
|
from reference import ReferenceManager
|
|
from sandbox import Sandbox
|
|
from matching import Matching
|
|
|
|
class OpticsTools(QtWidgets.QMainWindow, Ui_OpticsGUI):
|
|
def __init__(self,phase=0, office= 1):
|
|
super(OpticsTools, self).__init__()
|
|
self.setupUi(self)
|
|
|
|
office = office== 1
|
|
self.version = '1.0.1'
|
|
self.setWindowIcon(QtGui.QIcon("rsc/iconoptics.png"))
|
|
|
|
self.plot = OpticsPlot(parent=self)
|
|
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.sandbox = Sandbox(parent = self, machine = self.machine)
|
|
|
|
title = "SwissFEL Optics Tools - Lattice %s (Phase %d)" % (self.model.getLatticeVersion(),phase)
|
|
if office:
|
|
title += " - offline"
|
|
self.setWindowTitle(title)
|
|
|
|
# initialization
|
|
self.loadSettingsdirect("Settings/ReferenceSetting.json")
|
|
self.sandbox.updateSandbox()
|
|
self.reference = ReferenceManager(parent=self)
|
|
self.matching = Matching(parent=self, model=self.model, reference = self.reference)
|
|
|
|
# events handling
|
|
self.actionOpen_2.triggered.connect(self.loadSettings)
|
|
self.actionSave.triggered.connect(self.saveSettings)
|
|
self.UIUpdateFromMachine.clicked.connect(self.fullUpdate)
|
|
|
|
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)
|
|
self.status('Reference loaded')
|
|
|
|
def fullUpdate(self):
|
|
machine = self.machine.getMachineStatus()
|
|
self.model.updateFromMachine(machine)
|
|
self.sandbox.updateSandbox()
|
|
self.status('Machine Settings')
|
|
|
|
def status(self,msg=''):
|
|
self.UIStatus.setText(msg)
|
|
# --------------------------------
|
|
# Main routine
|
|
|
|
|
|
if __name__ == '__main__':
|
|
QtWidgets.QApplication.setStyle(QtWidgets.QStyleFactory.create("plastique"))
|
|
parser = ArgumentParser()
|
|
parser.add_argument('-phase', type=int, help='Disable any action on the machine', default=0)
|
|
parser.add_argument('-offline', type=int, help='Excludes any connection to control system', default=1)
|
|
args = parser.parse_args()
|
|
app = QtWidgets.QApplication(sys.argv)
|
|
|
|
main = OpticsTools(phase = args.phase, office = args.offline)
|
|
if main:
|
|
main.show()
|
|
sys.exit(app.exec_())
|