diff 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
line wrap: on
line diff
--- 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)