comparison browser_side/dialog.py @ 90:9729ed7171a6

browser side: Widgets' setting (col & row span can be changed
author Goffi <goffi@goffi.org>
date Tue, 28 Jun 2011 01:54:36 +0200
parents 9d8e79ac4c9c
children dd54bc13ac81
comparison
equal deleted inserted replaced
89:8d2c7be09eef 90:9729ed7171a6
29 from pyjamas.ui.Label import Label 29 from pyjamas.ui.Label import Label
30 from pyjamas.ui.HTML import HTML 30 from pyjamas.ui.HTML import HTML
31 from pyjamas.ui.Frame import Frame 31 from pyjamas.ui.Frame import Frame
32 from pyjamas.ui import HasAlignment 32 from pyjamas.ui import HasAlignment
33 from pyjamas.ui.KeyboardListener import KEY_ESCAPE, KEY_ENTER 33 from pyjamas.ui.KeyboardListener import KEY_ESCAPE, KEY_ENTER
34 from pyjamas import DOM
34 35
35 class ContactsChooser(DialogBox): 36 class ContactsChooser(DialogBox):
36 37
37 def __init__(self, host, callback, nb_contact=None, text='Please select contacts'): 38 def __init__(self, host, callback, nb_contact=None, text='Please select contacts'):
38 """ 39 """
247 def onGroupInput(self, sender): 248 def onGroupInput(self, sender):
248 self.list_box.addItem(sender.getText()) 249 self.list_box.addItem(sender.getText())
249 sender.setText('') 250 sender.setText('')
250 self.list_box.setItemSelected(self.list_box.getItemCount()-1, "selected") 251 self.list_box.setItemSelected(self.list_box.getItemCount()-1, "selected")
251 252
253 class IntSetter(HorizontalPanel):
254 """This class show a bar with button to set an int value"""
255
256 def __init__(self, label, value=0, value_max=None, visible_len=3):
257 """initialize the intSetter
258 @param label: text shown in front of the setter
259 @param value: initial value
260 @param value_max: limit value, None or 0 for unlimited"""
261 HorizontalPanel.__init__(self)
262 self.value = value
263 self.value_max = value_max
264 _label = Label(label)
265 self.add(_label)
266 self.setCellWidth(_label, "100%")
267 minus_button = Button("-", self.onMinus)
268 self.box = TextBox()
269 self.box.setVisibleLength(visible_len)
270 self.box.setText(str(value))
271 self.box.addInputListener(self)
272 plus_button = Button("+", self.onPlus)
273 self.add(minus_button)
274 self.add(self.box)
275 self.add(plus_button)
276 self.valueChangedListener = []
277
278 def addValueChangeListener(self, listener):
279 self.valueChangedListener.append(listener)
280
281 def removeValueChangeListener(self, listener):
282 if listener in self.valueChangedListener:
283 self.valueChangedListener.remove(listener)
284
285 def _callListeners(self):
286 for listener in self.valueChangedListener:
287 listener(self.value)
288
289 def onMinus(self, sender):
290 self.value=max(0,self.value-1)
291 self.box.setText(str(self.value))
292 self._callListeners()
293
294 def onPlus(self, sender):
295 self.value+=1
296 if self.value_max:
297 self.value = min(self.value,value_max)
298 self.box.setText(str(self.value))
299 self._callListeners()
300
301 def onInput(self, sender):
302 """Accept only valid integer && normalize print (no leading 0)"""
303 try:
304 self.value = int(self.box.getText())
305 except ValueError:
306 pass
307 if self.value_max:
308 self.value = min(self.value,value_max)
309 self.box.setText(str(self.value))
310 self._callListeners()