source: bcdaqwidgets/trunk/src/demos/pvview.py @ 1440

Last change on this file since 1440 was 1440, checked in by jemian, 9 years ago

added a demo to view several PVs in a GUI window: pvview

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Date Revision Author HeadURL Id
File size: 1.9 KB
Line 
1#!/usr/bin/env python
2
3'''display one or more EPICS PVs in a PySide GUI window as a table'''
4
5import os
6import sys
7from PySide.QtGui import QWidget, QLabel, QGridLayout, QApplication
8
9sys.path.insert(0, os.path.abspath('..'))
10import bcdaqwidgets
11
12class PVView(QWidget):
13    ''' '''
14    def __init__(self, parent=None):
15        QWidget.__init__(self, parent)
16        self.db = {}
17
18        name_label  = QLabel("PV Name")
19        value_label = QLabel("PV Value")
20        for item in (name_label, value_label):
21            sty = bcdaqwidgets.StyleSheet(item, {
22                                   'background-color': 'gray',
23                                   'color': 'white',
24                                   'font': 'bold',
25                                   })
26            sty.updateStyleSheet()
27
28        self.grid = QGridLayout()
29        self.grid.addWidget(name_label,   0, 0)
30        self.grid.addWidget(value_label,  0, 1)
31        self.grid.setColumnStretch(0, 0)
32        self.grid.setColumnStretch(1, 1)
33
34        self.setLayout(self.grid)
35        self.setWindowTitle("EPICS PV View")
36
37    def add(self, pvname):
38        '''add a PV to the table'''
39        if pvname in self.db:
40            return
41        row = len(self.db) + 1
42        label = QLabel(pvname)
43        widget = bcdaqwidgets.BcdaQLabel()
44        widget.ca_connect(pvname)
45        widget.useAlarmState = True
46        self.db[pvname] = widget
47        self.grid.addWidget(label, row, 0)
48        self.grid.addWidget(widget, row, 1)
49
50if __name__ == '__main__':
51    app = QApplication(sys.argv)
52    probe = PVView()
53    if len(sys.argv) < 2:
54        raise RuntimeError, "Must specify one or more EPICS PVs on command line"
55    for pvname in sys.argv[1:]:
56        probe.add(pvname)
57    probe.show()
58    sys.exit(app.exec_())
59
60
61########### SVN repository information ###################
62# $Date: 2013-10-15 16:48:58 +0000 (Tue, 15 Oct 2013) $
63# $Author: jemian $
64# $Revision: 1440 $
65# $URL: bcdaqwidgets/trunk/src/demos/pvview.py $
66# $Id: pvview.py 1440 2013-10-15 16:48:58Z jemian $
67########### SVN repository information ###################
Note: See TracBrowser for help on using the repository browser.