1
2
3
4 """ Control Base
5
6 """
7
8 from PyQt4 import uic, QtGui, QtCore
9 import pyforms.Utils.tools as tools
10
11 __author__ = "Ricardo Ribeiro"
12 __copyright__ = ""
13 __credits__ = "Ricardo Ribeiro"
14 __license__ = "MIT"
15 __version__ = "0.0"
16 __maintainer__ = ["Ricardo Ribeiro", "Carlos Mão de Ferro"]
17 __email__ = ["ricardojvr at gmail.com", "cajomferro at gmail.com"]
18 __status__ = "Development"
22 """
23 This class represents the most basic control that can exist
24 A Control is a Widget or a group of widgets that can be reused from application to application
25
26 @undocumented: __repr__
27 """
28
29 - def __init__(self, label='', defaultValue='', helptext=''):
39
49
50
51
53
54
55
56
57
58 - def load(self, data):
59 """
60 Load a value from the dict variable
61 @param data: dictionary with the value of the Control
62 """
63 if 'value' in data:
64 self.value = data['value']
65
66 - def save(self, data):
67 """
68 Save a value to dict variable
69 @param data: dictionary with to where the value of the Control will be added
70 """
71 if self.value:
72 data['value'] = self.value
73
75 """
76 Show the control
77 """
78 self.form.show()
79
81 """
82 Hide the control
83 """
84 self.form.hide()
85
87 """
88 Add an option to the Control popup menu
89 @param label: label of the option.
90 @param functionAction: function called when the option is selected.
91 @param key: shortcut key
92 """
93 if not self._popupMenu:
94 self.form.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
95 self.form.customContextMenuRequested.connect(self.__openPopupMenu)
96 self._popupMenu = QtGui.QMenu()
97 self._popupMenu.aboutToShow.connect(
98 self.aboutToShowContextMenuEvent)
99
100 if label == "-":
101 return self._popupMenu.addSeparator()
102 else:
103 action = QtGui.QAction(label, self.form)
104 if key != None:
105 action.setShortcut(QtGui.QKeySequence(key))
106 if functionAction:
107 action.triggered.connect(functionAction)
108 self._popupMenu.addAction(action)
109 return action
110
112 """
113 Add submenu options to the Control popup menu
114 @param label: submenu label of the option.
115 @param options: dictionary representing the submenu. ex: { 'Example': event function, ... }.
116 @param keys: shortcut keys. ex: { 'Example': shortcut key, ... }.
117 """
118 if not self._popupMenu:
119 self.form.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
120 self.form.customContextMenuRequested.connect(self.__openPopupMenu)
121 self._popupMenu = QtGui.QMenu()
122 self._popupMenu.aboutToShow.connect(
123 self.aboutToShowContextMenuEvent)
124
125 submenu = QtGui.QMenu(label, self._popupMenu)
126 for text, func in options.items():
127 if text == "-":
128 submenu.addSeparator()
129 else:
130 action = QtGui.QAction(text, self.form)
131 if text in keys:
132 action.setShortcut(QtGui.QKeySequence(keys[text]))
133
134 if func:
135 action.triggered.connect(func)
136 submenu.addAction(action)
137 self._popupMenu.addMenu(submenu)
138
139
140
141
142
144 """
145 Function called when ever the Control value is changed
146 """
147 pass
148
150 """
151 Function called before open the Control popup menu
152 """
153 pass
154
156 if self._popupMenu:
157 self._popupMenu.exec_(self.form.mapToGlobal(position))
158
159
160
161
162
163
164
165
166 @property
168 return self.form.isEnabled()
169
170 @enabled.setter
172 """@type value: boolean"""
173 self.form.setEnabled(value)
174
175
176
177
178 @property
181
182 @value.setter
184 """
185 This property return and set what the control should manage or store.
186 @type value: string
187 """
188 oldvalue = self._value
189 self._value = value
190 if oldvalue != value:
191 self.changed()
192
193 @property
195 return self.form.objectName()
196
197 @name.setter
198 - def name(self, value):
199 """
200 This property return and set the name of the control
201 @type value: string
202 """
203 self.form.setObjectName(value)
204
205
206
207
208 @property
211
212 @label.setter
214 """
215 Label of the control, if applies
216 @type value: string
217 """
218 self._label = value
219
220
221
222
223 @property
230
231
232
233
234 @property
235 - def parent(self): return self._parent
236
237 @parent.setter
239 """
240 Returns or set the parent basewidget where the Control is
241 @type value: BaseWidget
242 """
243 self._parent = value
244
245
246 @property
247 - def help(self): return self._help if self._help else ''
248