Mercurial > libervia-web
comparison browser_side/dialog.py @ 95:1c75fd97baf9
browser side: widgets' setting: mouse wheel can now be used to change values
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 28 Jun 2011 13:30:43 +0200 |
parents | 8f9d30672225 |
children | f9d63624699f |
comparison
equal
deleted
inserted
replaced
94:8f9d30672225 | 95:1c75fd97baf9 |
---|---|
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.ui.MouseListener import MouseWheelHandler | |
34 from pyjamas import DOM | 35 from pyjamas import DOM |
35 | 36 |
36 class ContactsChooser(DialogBox): | 37 class ContactsChooser(DialogBox): |
37 | 38 |
38 def __init__(self, host, callback, nb_contact=None, text='Please select contacts'): | 39 def __init__(self, host, callback, nb_contact=None, text='Please select contacts'): |
248 def onGroupInput(self, sender): | 249 def onGroupInput(self, sender): |
249 self.list_box.addItem(sender.getText()) | 250 self.list_box.addItem(sender.getText()) |
250 sender.setText('') | 251 sender.setText('') |
251 self.list_box.setItemSelected(self.list_box.getItemCount()-1, "selected") | 252 self.list_box.setItemSelected(self.list_box.getItemCount()-1, "selected") |
252 | 253 |
254 class WheelTextBox(TextBox, MouseWheelHandler): | |
255 | |
256 def __init__(self, *args, **kwargs): | |
257 TextBox.__init__(self, *args, **kwargs) | |
258 MouseWheelHandler.__init__(self) | |
259 | |
260 | |
261 | |
253 class IntSetter(HorizontalPanel): | 262 class IntSetter(HorizontalPanel): |
254 """This class show a bar with button to set an int value""" | 263 """This class show a bar with button to set an int value""" |
255 | 264 |
256 def __init__(self, label, value=0, value_max=None, visible_len=3): | 265 def __init__(self, label, value=0, value_max=None, visible_len=3): |
257 """initialize the intSetter | 266 """initialize the intSetter |
263 self.value_max = value_max | 272 self.value_max = value_max |
264 _label = Label(label) | 273 _label = Label(label) |
265 self.add(_label) | 274 self.add(_label) |
266 self.setCellWidth(_label, "100%") | 275 self.setCellWidth(_label, "100%") |
267 minus_button = Button("-", self.onMinus) | 276 minus_button = Button("-", self.onMinus) |
268 self.box = TextBox() | 277 self.box = WheelTextBox() |
269 self.box.setVisibleLength(visible_len) | 278 self.box.setVisibleLength(visible_len) |
270 self.box.setText(str(value)) | 279 self.box.setText(str(value)) |
271 self.box.addInputListener(self) | 280 self.box.addInputListener(self) |
281 self.box.addMouseWheelListener(self) | |
272 plus_button = Button("+", self.onPlus) | 282 plus_button = Button("+", self.onPlus) |
273 self.add(minus_button) | 283 self.add(minus_button) |
274 self.add(self.box) | 284 self.add(self.box) |
275 self.add(plus_button) | 285 self.add(plus_button) |
276 self.valueChangedListener = [] | 286 self.valueChangedListener = [] |
290 """Change the value and fire valueChange listeners""" | 300 """Change the value and fire valueChange listeners""" |
291 self.value = value | 301 self.value = value |
292 self.box.setText(str(value)) | 302 self.box.setText(str(value)) |
293 self._callListeners() | 303 self._callListeners() |
294 | 304 |
295 def onMinus(self, sender): | 305 def onMinus(self, sender, step=1): |
296 self.value=max(0,self.value-1) | 306 self.value=max(0,self.value-step) |
297 self.box.setText(str(self.value)) | 307 self.box.setText(str(self.value)) |
298 self._callListeners() | 308 self._callListeners() |
299 | 309 |
300 def onPlus(self, sender): | 310 def onPlus(self, sender, step=1): |
301 self.value+=1 | 311 self.value+=step |
302 if self.value_max: | 312 if self.value_max: |
303 self.value = min(self.value,value_max) | 313 self.value = min(self.value,value_max) |
304 self.box.setText(str(self.value)) | 314 self.box.setText(str(self.value)) |
305 self._callListeners() | 315 self._callListeners() |
306 | 316 |
312 pass | 322 pass |
313 if self.value_max: | 323 if self.value_max: |
314 self.value = min(self.value,value_max) | 324 self.value = min(self.value,value_max) |
315 self.box.setText(str(self.value)) | 325 self.box.setText(str(self.value)) |
316 self._callListeners() | 326 self._callListeners() |
327 | |
328 def onMouseWheel(self, sender, velocity): | |
329 if velocity>0: | |
330 self.onMinus(sender, 10) | |
331 else: | |
332 self.onPlus(sender, 10) |