1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | ''' |
---|
4 | PySide implementation of EPICS probe |
---|
5 | |
---|
6 | :author: Matt Newville, CARS, University of Chicago |
---|
7 | :note: Does not use bcdaqwidgets |
---|
8 | ''' |
---|
9 | |
---|
10 | import epics |
---|
11 | import os |
---|
12 | import sys |
---|
13 | from PySide.QtGui import QWidget, QLabel, QLineEdit, QGridLayout, QApplication |
---|
14 | |
---|
15 | class PVProbe(QWidget): |
---|
16 | '''frame that monitors a user-entered EPICS PV''' |
---|
17 | def __init__(self, parent=None): |
---|
18 | QWidget.__init__(self, parent) |
---|
19 | |
---|
20 | name_label = QLabel("PV Name:") |
---|
21 | self.pvname = QLineEdit() |
---|
22 | value_label = QLabel("PV Value:") |
---|
23 | self.value = QLabel(" "*4) |
---|
24 | |
---|
25 | self.pvname.returnPressed.connect(self.onPVNameReturn) |
---|
26 | self.pv = None |
---|
27 | |
---|
28 | grid = QGridLayout() |
---|
29 | grid.addWidget(name_label, 0, 0) |
---|
30 | grid.addWidget(self.pvname, 0, 1) |
---|
31 | grid.addWidget(value_label, 1, 0) |
---|
32 | grid.addWidget(self.value, 1, 1) |
---|
33 | |
---|
34 | self.setLayout(grid) |
---|
35 | self.setWindowTitle("PySide PV Probe:") |
---|
36 | |
---|
37 | def onPVNameReturn(self): |
---|
38 | '''responds when user enters a new PV''' |
---|
39 | if self.pv is not None: |
---|
40 | self.pv.remove_callback() |
---|
41 | self.pv.ca_disconnect() |
---|
42 | self.pv = epics.PV(self.pvname.text(), callback=self.onPVChange) |
---|
43 | |
---|
44 | def onPVChange(self, pvname=None, char_value=None, **kws): |
---|
45 | '''updates the widget (not thread-safe)''' |
---|
46 | self.value.setText(char_value) |
---|
47 | |
---|
48 | |
---|
49 | def main(): |
---|
50 | app = QApplication(sys.argv) |
---|
51 | probe = PVProbe() |
---|
52 | probe.show() |
---|
53 | sys.exit(app.exec_()) |
---|
54 | |
---|
55 | |
---|
56 | if __name__ == '__main__': |
---|
57 | main() |
---|
58 | |
---|
59 | |
---|
60 | ########### SVN repository information ################### |
---|
61 | # $Date: 2013-10-16 01:22:10 +0000 (Wed, 16 Oct 2013) $ |
---|
62 | # $Author: jemian $ |
---|
63 | # $Revision: 1443 $ |
---|
64 | # $URL: bcdaqwidgets/trunk/src/bcdaqwidgets_demos/pyside_probe.py $ |
---|
65 | # $Id: pyside_probe.py 1443 2013-10-16 01:22:10Z jemian $ |
---|
66 | ########### SVN repository information ################### |
---|