Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Zhang, Tong
Online Model App
Commits
8c2e4593
Commit
8c2e4593
authored
Jul 14, 2021
by
Tong Zhang
Browse files
ENH: Support visualize beam envelope when any quad is changed.
parent
5f30e4e1
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/myApp/app.py
View file @
8c2e4593
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Template Python module generated based on 'app_template', 'phantasy-ui'
is required to make it executable as a PyQt5 app.
...
...
@@ -15,14 +14,20 @@ Show the available templates:
>>> makeBasePyQtApp -l
"""
from
PyQt5.QtCore
import
pyqtSlot
from
PyQt5.QtWidgets
import
QMainWindow
from
phantasy
import
MachinePortal
from
phantasy_ui
import
BaseAppForm
from
.ui.ui_app
import
Ui_MainWindow
MACH
,
SEGM
=
"ARIS"
,
"F1"
ARIS_MP
=
MachinePortal
(
MACH
,
SEGM
)
ARIS_LAT
=
ARIS_MP
.
work_lattice_conf
class
MyAppWindow
(
BaseAppForm
,
Ui_MainWindow
):
class
MyAppWindow
(
BaseAppForm
,
Ui_MainWindow
):
def
__init__
(
self
,
version
,
**
kws
):
super
(
self
.
__class__
,
self
).
__init__
()
...
...
@@ -37,6 +42,85 @@ class MyAppWindow(BaseAppForm, Ui_MainWindow):
self
.
setupUi
(
self
)
self
.
postInitUi
()
# post init
self
.
_post_init
()
def
_post_init
(
self
):
"""Initialize UI, user customized code put here.
"""
# Fill comboBox quad1_name_cbb with all quad names.
quad_name_list
=
[
i
.
name
for
i
in
ARIS_MP
.
get_elements
(
type
=
'QUAD'
)]
self
.
quad1_name_cbb
.
addItems
(
quad_name_list
)
# connect currentTextChanged signal to slot: on_quad1_name_changed()
self
.
quad1_name_cbb
.
currentTextChanged
.
connect
(
self
.
on_quad1_name_changed
)
# connect valueChanged signal of quad1_grad_dsbox to on_quad1_grad_changed()
self
.
quad1_grad_dsbox
.
valueChanged
.
connect
(
self
.
on_quad1_grad_changed
)
# initialize quad1_name_cbb
self
.
quad1_name_cbb
.
currentTextChanged
.
emit
(
quad_name_list
[
0
])
@
pyqtSlot
(
'QString'
)
def
on_quad1_name_changed
(
self
,
name
:
str
)
->
None
:
"""When the current selected quad name is changed, do:
show the current setting of the selected quad on quad1_grad_dsbox.
when set value to quad1_grad_dsbox, disconnect valueChanged and
reconnect, to avoid unnecessary trigging.
"""
self
.
quad_selected
=
ARIS_MP
.
get_elements
(
name
=
name
)[
0
]
self
.
quad1_grad_dsbox
.
valueChanged
.
disconnect
()
self
.
quad1_grad_dsbox
.
setValue
(
self
.
quad_selected
.
current_setting
(
'B2'
))
self
.
quad1_grad_dsbox
.
valueChanged
.
connect
(
self
.
on_quad1_grad_changed
)
@
pyqtSlot
(
float
)
def
on_quad1_grad_changed
(
self
,
grad
:
float
)
->
None
:
"""When the setting of the selected quad is changed, do:
1. print the setting of selected quad
2. update drawing with online simulated results
"""
q
=
self
.
quad_selected
.
name
print
(
f
"'
{
q
}
' setting is:
{
grad
}
T/m"
)
# draw ellipse
self
.
update_drawing
()
def
update_drawing
(
self
):
"""This is the routine to update the figure with the updated drawing.
Here I'm drawing the beam envelop along the entire beamline, try to
replace with your routine for beam ellipse drawing.
"""
try
:
self
.
draw_ellipse
()
except
NotImplementedError
:
self
.
draw_envelope
()
def
draw_envelope
(
self
):
"""Draw beam envelop onto the figure area.
"""
# online simulation
ARIS_LAT
.
sync_settings
()
_
,
fm
=
ARIS_LAT
.
run
()
r
,
_
=
fm
.
run
(
monitor
=
'all'
)
results_dict
=
fm
.
collect_data
(
r
,
'pos'
,
'xrms'
,
'yrms'
)
pos
=
results_dict
[
'pos'
]
xrms
=
results_dict
[
'xrms'
]
yrms
=
results_dict
[
'yrms'
]
# update drawing
# Note: matplotlibbaseWidget is used here for generic drawing,
# for curve visualization, matplotlibCurveWidget is a better choice.
self
.
matplotlibbaseWidget
.
clear_figure
()
self
.
matplotlibbaseWidget
.
axes
.
plot
(
pos
,
xrms
,
'b-'
,
pos
,
yrms
,
'r-'
,
)
self
.
matplotlibbaseWidget
.
update_figure
()
def
draw_ellipse
(
self
):
raise
NotImplementedError
if
__name__
==
"__main__"
:
from
PyQt5.QtWidgets
import
QApplication
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment