Changeset 840


Ignore:
Timestamp:
Apr 27, 2012 11:37:35 AM (10 years ago)
Author:
jemian
Message:

develop the first PV-aware widget

Location:
moxy/trunk/src/moxy/qtlib
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • moxy/trunk/src/moxy/qtlib/pv.py

    r838 r840  
    4141'''
    4242
    43 import epics
     43
    4444import sys
    4545import PySide.QtGui
     46from CaQLabel import CaQLabel
    4647
    47 
    48 class SignalBgColorChange(PySide.QtCore.QObject):
    49     '''
    50     signal that the background color on the
    51     value widget must change
    52     '''
    53     # see: http://zetcode.com/gui/pysidetutorial/eventsandsignals/
    54     # TODO: there must be an easier way to do this!
    55     # Some way that does not cache the event data and
    56     # receiver apart from the emitter.
    57    
    58     newBgColor = PySide.QtCore.Signal()
    5948
    6049class DemoView(PySide.QtGui.QWidget):
     
    6453    This is a variation of EPICS PV Probe.
    6554    '''
    66    
    67     _cb_counter = 0         # change background color on each update
    6855
    6956    def __init__(self, parent=None, pvname=''):
     
    7461        self.pvname.setText(pvname)
    7562        value_label = PySide.QtGui.QLabel("PV Value:")
    76         self.value  = PySide.QtGui.QLabel(" "*4)
    77 
    78         self.ev = SignalBgColorChange()
    79         self.ev.newBgColor.connect(self.SetWidgetBackgroundColor)       
     63        self.value  = CaQLabel(" "*4)     
    8064
    8165        self.pvname.returnPressed.connect(self.onPVNameReturn)
     
    9478
    9579    def onPVNameReturn(self):
    96         if self.pv is not None:
    97             self.pv.remove_callback()
    98             self.pv.disconnect()
    99         self.pv = epics.PV(self.pvname.text(), callback=self.onPVChange)
    100 
    101     def onPVChange(self, pvname=None, char_value=None, **kws):
    102         self.value.setText(char_value)
    103         self._cb_counter += 1   # change the color every update event
    104         self.ev.newBgColor.emit()   # threadsafe call
    105 
    106     def SetWidgetBackgroundColor(self, *args, **kw):
    107         ''''color is a string in #RRGGBB format'''
    108         color = self.ColorSelector(self._cb_counter)
    109         bgStyle = "QFrame {background-color: %s}" % color
    110         self.value.setStyleSheet(bgStyle)
    111 
    112     def ColorSelector(self, index):
    113         # this makes a gaudy display
    114         clut = [ "#ff0000", "#00ffff", "#f00000",
    115                  "#00ff00", "#ff00ff",
    116                  "#0000ff", "#ffff00", ]
    117         return clut[index % len(clut)]
     80        self.value.connect(self.pvname.text())
    11881
    11982
  • moxy/trunk/src/moxy/qtlib/pyside_probe.py

    • Property svn:keywords changed from Date Revision Author HeadURL Id to Author Date Id Revision URL
Note: See TracChangeset for help on using the changeset viewer.