source: bcdaqwidgets/trunk/src/bcdaqwidgets/test53.py @ 1425

Last change on this file since 1425 was 1425, checked in by jemian, 10 years ago

try to build GUI from .ui files

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Date Revision Author HeadURL Id
File size: 2.4 KB
Line 
1#!/usr/bin/env python
2
3########### SVN repository information ###################
4# $Date: 2013-08-07 21:42:32 +0000 (Wed, 07 Aug 2013) $
5# $Author: jemian $
6# $Revision: 1425 $
7# $URL: bcdaqwidgets/trunk/src/bcdaqwidgets/test53.py $
8# $Id: test53.py 1425 2013-08-07 21:42:32Z jemian $
9########### SVN repository information ###################
10
11'''
12Test code for TRAC ticket #53.
13'''
14
15
16import epics
17from PySide import QtGui, QtCore
18import bcdaqwidgets
19import sys
20
21
22class DemoView(QtGui.QWidget):
23    '''
24    Show the BcdaQWidgets using an EPICS PV connection.
25
26    Allow it to connect and ca_disconnect.
27    This is a variation of EPICS PV Probe.
28
29    '''
30
31    def __init__(self, parent=None, rbv='', dmov=None):
32        '''constructor'''
33        QtGui.QWidget.__init__(self, parent)
34
35        layout = QtGui.QGridLayout()
36        layout.addWidget(QtGui.QLabel('BcdaQLabel'), 0, 0)
37        self.value = bcdaqwidgets.BcdaQLabel(pvname=rbv)
38        layout.addWidget(self.value, 0, 1)
39        self.setLayout(layout)
40
41        if dmov is not None:
42            self.dmov = epics.PV(pvname=dmov, callback=self.onDmovChanged)
43
44        self.dmov_bg_clut = {'not connected':   'white', 
45                             '0':               '#8f8', 
46                             '1':               'transparent'
47                             }
48        self.dmov_bg_color = None
49
50        self.dmovSignal = bcdaqwidgets.BcdaQSignalDef()
51        self.dmovSignal.newBgColor.connect(self.SetBackgroundColor)
52
53    def onDmovChanged(self, *args, **kw):
54        '''epics pv callback when motor starts or stops moving'''         
55        if not self.dmov.connected:     # white and displayed text is ' '
56            self.dmov_bg_color = self.dmov_bg_clut['not connected']
57        else:
58            value = str(self.dmov.get())
59            if value in self.dmov_bg_clut:
60                self.dmov_bg_color = self.dmov_bg_clut[value]
61        # trigger the background color to change
62        self.dmovSignal.newBgColor.emit()
63
64    def SetBackgroundColor(self, *args, **kw):
65        '''changes the background color of the widget'''
66        if self.dmov_bg_color is not None:
67            self.value.updateStyleSheet({'background-color': self.dmov_bg_color})
68            self.dmov_bg_color = None
69
70           
71#------------------------------------------------------------------
72
73
74def main():
75    '''command-line interface to test this GUI widget'''
76    app = QtGui.QApplication(sys.argv)
77    view = DemoView(rbv='prj:m1.RBV', dmov='prj:m1.DMOV')
78    view.show()
79    sys.exit(app.exec_())
80
81
82if __name__ == '__main__':
83    main()
Note: See TracBrowser for help on using the repository browser.