# HG changeset patch # User Goffi # Date 1309260643 -7200 # Node ID 1c75fd97baf9d56748159d75184dde4e5c6e96fb # Parent 8f9d306722250e6249990f6f7553a7e83ba8c8c5 browser side: widgets' setting: mouse wheel can now be used to change values diff -r 8f9d30672225 -r 1c75fd97baf9 browser_side/dialog.py --- a/browser_side/dialog.py Tue Jun 28 04:06:25 2011 +0200 +++ b/browser_side/dialog.py Tue Jun 28 13:30:43 2011 +0200 @@ -31,6 +31,7 @@ from pyjamas.ui.Frame import Frame from pyjamas.ui import HasAlignment from pyjamas.ui.KeyboardListener import KEY_ESCAPE, KEY_ENTER +from pyjamas.ui.MouseListener import MouseWheelHandler from pyjamas import DOM class ContactsChooser(DialogBox): @@ -250,6 +251,14 @@ sender.setText('') self.list_box.setItemSelected(self.list_box.getItemCount()-1, "selected") +class WheelTextBox(TextBox, MouseWheelHandler): + + def __init__(self, *args, **kwargs): + TextBox.__init__(self, *args, **kwargs) + MouseWheelHandler.__init__(self) + + + class IntSetter(HorizontalPanel): """This class show a bar with button to set an int value""" @@ -265,10 +274,11 @@ self.add(_label) self.setCellWidth(_label, "100%") minus_button = Button("-", self.onMinus) - self.box = TextBox() + self.box = WheelTextBox() self.box.setVisibleLength(visible_len) self.box.setText(str(value)) self.box.addInputListener(self) + self.box.addMouseWheelListener(self) plus_button = Button("+", self.onPlus) self.add(minus_button) self.add(self.box) @@ -292,13 +302,13 @@ self.box.setText(str(value)) self._callListeners() - def onMinus(self, sender): - self.value=max(0,self.value-1) + def onMinus(self, sender, step=1): + self.value=max(0,self.value-step) self.box.setText(str(self.value)) self._callListeners() - def onPlus(self, sender): - self.value+=1 + def onPlus(self, sender, step=1): + self.value+=step if self.value_max: self.value = min(self.value,value_max) self.box.setText(str(self.value)) @@ -314,3 +324,9 @@ self.value = min(self.value,value_max) self.box.setText(str(self.value)) self._callListeners() + + def onMouseWheel(self, sender, velocity): + if velocity>0: + self.onMinus(sender, 10) + else: + self.onPlus(sender, 10)