summaryrefslogtreecommitdiff
path: root/lib/taurus/qt/qtgui/util/tauruswidget_template
blob: 3cab2f00b60f135b8a8c838f905f8c47a4407c07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env python

""" module containing the Tau Widget: <_TauClass_> """

from taurus.qt import QtGui, QtCore
import tau.core
from tau.widget import TauBaseWidget

class <_TauClass_>(<_SuperClass_>, TauBaseWidget):
    """ <_TauClass_> is a Tau widget designed to represent..."""
    
    #---------------------------------------------------------------------------
    # Write your own code here to define the signals generated by this widget
    #
    __pyqtSignals__ = ("modelChanged(const QString &)",)
    
    def __init__(self, parent = None, designMode = False):
        name = self.__class__.__name__
        
        self.call__init__wo_kw(<_SuperClass_>, parent)
        self.call__init__(TauBaseWidget, name, parent, designMode=designMode)

        self.defineStyle()
    
    def defineStyle(self):
        """ Defines the initial style for the widget """
        #-----------------------------------------------------------------------
        # Write your own code here to set the initial style of your widget
        #
        self.updateStyle()

    def sizeHint(self):
        return <_SuperClass_>.sizeHint(self)

    def minimumSizeHint(self):
        return <_SuperClass_>.minimumSizeHint(self)
    
    #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
    # TauBaseWidget over writing
    #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
    
    def getModelClass(self):
        #-----------------------------------------------------------------------
        # [MANDATORY]
        # Replace your own code here
        # ex.: return tau.core.Attribute
        raise RuntimeError("Forgot to overwrite %s.getModelClass" % str(self)) 
            
    
    def attach(self):
        """Attaches the widget to the model"""
        
        if self.isAttached():
            return True
        
        #-----------------------------------------------------------------------
        # Write your own code here before attaching widget to attribute connect 
        # the proper signal so that the first event is correctly received by the
        # widget
        #
        # Typical code is:
        #self.connect(self, QtCore.SIGNAL('valueChangedDueToEvent(QString)'), 
        #             self.setTextValue)
        
        
        ret = TauBaseWidget.attach(self)
        
        # by default enable/disable widget according to attach state
        self.setEnabled(ret)
        return ret

    def detach(self):
        """Detaches the widget from the model"""
        
        TauBaseWidget.detach(self)

        #-----------------------------------------------------------------------
        # Write your own code here after detaching the widget from the model 
        #
        # Typical code is:
        #self.emit(QtCore.SIGNAL('valueChangedDueToEvent(QString)'), 
        #          QtCore.QString(value_str))
        #self.disconnect(self, QtCore.SIGNAL('valueChangedDueToEvent(QString)'),
        #                self.setTextValue)
        
        # by default disable widget when dettached
        self.setEnabled(False)

    def eventReceived(self, src, type, data):
        """ eventReceived(src, TauEventType type, data) -> None
        
            Called by the model when an event is fired.
            
            Parameters:
              src: Source of the event. Usually a tau.core.Attribute or 
                   tau.core.Device object
              type: a TauEventType describing the type of event.
              data: A PyTango object with the event data. It can be None.
                    - For TauEventType.change events is a PyTango.AttributeValue 
                    object or None;
                    - For TauEventType.attr_conf events is a 
                    PyTango.AttrConfEventData object or None.
            Return:
              None
        """
        #-----------------------------------------------------------------------
        # Write your own code here to handle event
        pass
    
    #---------------------------------------------------------------------------
    # [MANDATORY]
    # Uncomment the following method if your superclass does not provide with a 
    # isReadOnly() method or if you need to change its behavior
    
    #def isReadOnly(self):
    #    return True
    
    def updateStyle(self):
        #-----------------------------------------------------------------------
        # Write your own code here to update your widget style
        
        # send a repaint in the end
        self.repaint()
        
    #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
    # QT properties 
    #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-

    model = QtCore.pyqtProperty("QString", TauBaseWidget.getModel, 
                                TauBaseWidget.setModel, 
                                TauBaseWidget.resetModel)
                                
    useParentModel = QtCore.pyqtProperty("bool",
                                         TauBaseWidget.getUseParentModel, 
                                         TauBaseWidget.setUseParentModel,
                                         TauBaseWidget.resetUseParentModel)

    #---------------------------------------------------------------------------
    # Write your own code here for your own widget properties