Your challenge when writing or replacing a PV value into an xml file is locating _which_ PV value to be replaced, finding the correct the xml node to be edited. Assuming the XML file uses more than a single PV, you'd need a way of finding the correct one.
That complicates the simple example you request. For example, one of the widgets in the synApps/std timer screen has this xml:
<widget type="choice" version="2.0.0">
<name>choice button #23</name>
<pv_name>$(P)timer$(N):Go</pv_name>
<x>5</x>
<y>34</y>
<width>70</width>
<height>35</height>
<background_color>
<color red="115" green="223" blue="255">
</color>
</background_color>
<horizontal>false</horizontal>
<border_alarm_sensitive>false</border_alarm_sensitive>
<items>
<item>Item 1</item>
<item>Item 2</item>
</items>
</widget>
The .bob file has these PVs:
(base) ~$ grep pv_name /usr/local/epics/synApps6.1/support/std-R3-6-2/stdApp/op/bob/autoconvert/timer.bob
<pv_name>$(P)timer$(N):elapsedSecs</pv_name>
<pv_name>$(P)timer$(N):Go</pv_name>
You could use the findall() (https://lxml.de/tutorial.html#elementpath) method to locate the `pv_name` nodes but you must still decide which to edit. The macros (with definitions unique to this file) are defined elsewhere in the file.
Describe for us what you plan to do (create a new .bob file from an empty file or edit an existing file that you provide us) and it will be simpler to provide you with an example using lxml.
Regards,
Pete
On 11/15/2022 8:48 PM, 吴煊 via Tech-talk wrote:
Many thanks for all your tips. It seems that phoebusgen is used to generate widgets.I need to write pv value into a xml file, so using etree maybe better. That would be great if there was an example.
Xuan
-----原始邮件-----
*发件人:*"Tynan Ford" <TFord at lbl.gov>
*发送时间:*2022-11-16 00:56:24 (星期三)
*收件人:* "Liu, Wanming" <wmliu at anl.gov>
*抄送:* "吴煊" <wux at ihep.ac.cn>, "kasemir, kay" <kasemirk at ornl.gov>, tech-talk <tech-talk at aps.anl.gov>
*主题:* Re: Re: [EXTERNAL] Phoebus: Find/Replace and Write XML file
I would not necessarily recommend doing this but you can see an example (exampleInPhoebus files) of creating XML file in jython here: https://github.com/als-epics/phoebusgen/tree/master/examples <https://github.com/als-epics/phoebusgen/tree/master/examples>
On Tue, Nov 15, 2022 at 8:36 AM Liu, Wanming via Tech-talk <tech-talk at aps.anl.gov <mailto:tech-talk at aps.anl.gov>> wrote:
The bob file is a xml file. So you can use etree from lxml package to manipulate the file with python. ____
__ __
*From:* Tech-talk <tech-talk-bounces at aps.anl.gov <mailto:tech-talk-bounces at aps.anl.gov>> *On Behalf Of *?? via Tech-talk
*Sent:* Monday, November 14, 2022 7:58 PM
*To:* kasemir, kay <kasemirk at ornl.gov <mailto:kasemirk at ornl.gov>>
*Cc:* tech-talk <tech-talk at aps.anl.gov <mailto:tech-talk at aps.anl.gov>>
*Subject:* Re: Re: [EXTERNAL] Phoebus: Find/Replace and Write XML file____
__ __
I'm sorry I didn't make myself clear. I wish to know how to create and write XML file using jython/python script in phoebus? Is there a way to find and replace charactors especially pv_names in xxx.bob file? ____
Xuan ____
-----原始邮件-----
*发件人:*"Kasemir, Kay" <kasemirk at ornl.gov <mailto:kasemirk at ornl.gov>>
*发送时间:*2022-11-14 22:27:56 (星期一)
*收件人:* tech-talk <tech-talk at aps.anl.gov <mailto:tech-talk at aps.anl.gov>>, "吴煊" <wux at ihep.ac.cn <mailto:wux at ihep.ac.cn>>
*抄送:*
*主**题:* Re: [EXTERNAL] Phoebus: Find/Replace and Write XML file____
> Is there "Find/Replace" function still in phoebus? It's very useful for replacing pv names or other things in CSS. Another question I'd like to ask:how to create and write XML file in phoebus? I haven't see it in display builder examples. Any advice or suggestions will be grately appretiated ____
__ __
__ __
Yes, one advantage of the XML file format is that it allows creating or modifying theses files outside of the graphical editor. ____
We don't try to include a complete XML editor in phoebus, but you can easily add an OS-specific editor to the context menu so that you can then open a display file from the phoebus file browser via the context menu. ____
__ __
For example, on Linux you can add a reference to the plain "gedit" text editor like this, so it can then be used to open *.bob or *.opi files and for example perform PV name replacements:____
__ __
org.phoebus.framework.workbench/external_app_text=Text Editor,txt|dat|tab|py|ini|def|db|xml|xsl|css|cmd|sh|st|log|out|md|tex|shp|bob|opi|pvs|edl,gedit____
__ __
You could also register VS code or another more XML-aware editor just for *.bob like that. ____
__ __
__ __
For a general python package that generates display files outside of phoebus, see https://github.com/als-epics/phoebusgen <https://github.com/als-epics/phoebusgen>____
__ __
__ __
-Kay ____
__ __
--
----------------------------------------------------------
Pete R. Jemian, Ph.D. <jemian at anl.gov>
Beam line Controls and Data Acquisition (BC, aka BCDA)
Advanced Photon Source, Argonne National Laboratory
Argonne, IL 60439 630 - 252 - 3189
-----------------------------------------------------------
Education is the one thing for which people
are willing to pay yet not receive.
-----------------------------------------------------------
- Replies:
- Re: Re: [EXTERNAL] Phoebus: Find/Replace and Write XML file 吴煊 via Tech-talk
- References:
- Phoebus: Find/Replace and Write XML file 吴煊 via Tech-talk
- Re: [EXTERNAL] Phoebus: Find/Replace and Write XML file Kasemir, Kay via Tech-talk
- Re: Re: [EXTERNAL] Phoebus: Find/Replace and Write XML file 吴煊 via Tech-talk
- RE: Re: [EXTERNAL] Phoebus: Find/Replace and Write XML file Liu, Wanming via Tech-talk
- Re: Re: [EXTERNAL] Phoebus: Find/Replace and Write XML file Tynan Ford via Tech-talk
- Re: Re: Re: [EXTERNAL] Phoebus: Find/Replace and Write XML file 吴煊 via Tech-talk
- Navigate by Date:
- Prev:
Re: Epics Archiver Appliance requests and DST/Timezones Pete Jemian via Tech-talk
- Next:
RE: Epics Archiver Appliance requests and DST/Timezones Abdalla Ahmad via Tech-talk
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
<2022>
2023
2024
- Navigate by Thread:
- Prev:
Re: Re: Re: [EXTERNAL] Phoebus: Find/Replace and Write XML file 吴煊 via Tech-talk
- Next:
Re: Re: [EXTERNAL] Phoebus: Find/Replace and Write XML file 吴煊 via Tech-talk
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
<2022>
2023
2024
|