Fix mousewheel.
authorRadek Brich <radek.brich@devl.cz>
Sun, 16 Dec 2012 21:04:03 +0100
changeset 35 f62c8269ded6
parent 34 e3beacd5e536
child 36 caf927c3f10b
Fix mousewheel.
tuikit/common.py
--- a/tuikit/common.py	Sun Dec 16 20:49:54 2012 +0100
+++ b/tuikit/common.py	Sun Dec 16 21:04:03 2012 +0100
@@ -2,9 +2,9 @@
 
 
 class Coords:
-    
+
     '''2D coordinates.'''
-    
+
     def __init__(self, x=0, y=0):
         self.x = x
         self.y = y
@@ -16,7 +16,7 @@
         except TypeError:
             pass
         return self.__dict__[key]
-    
+
     def __setitem__(self, key, value):
         if key == 0:
             self.x = value
@@ -28,18 +28,18 @@
 
 
 class Size:
-    
+
     '''Size class.
-    
+
     Implements attribute access (.w, .h), list-like access([0],[1])
     and dict-like access (['w'],['h']).
-    
+
     '''
-    
+
     def __init__(self, w=None, h=None):
         self.w = w
         self.h = h
-    
+
     def __getitem__(self, key):
         try:
             tupl = (self.w, self.h)
@@ -53,15 +53,15 @@
             self.w = value
         if key in [1, 'h']:
             self.h = value
-    
+
     def __repr__(self):
         return 'Size(w={0.w},h={0.h})'.format(self)
 
 
 class Rect:
-    
+
     '''Rectangle is defined by 2D coordinates and size.'''
-    
+
     def __init__(self, x=0, y=0, w=0, h=0):
         self.x = x
         self.y = y
@@ -73,15 +73,15 @@
 
 
 class Borders:
-    
+
     '''Borders are defined by left, top, right, bottom border size.
-    
+
     Ordering is clock-wise, starting with left. This may seem weird,
     but it corresponds to X/Y or W/H used elsewhere. Left and right are
     on X axis, so they are defined first.
-    
+
     '''
-    
+
     def __init__(self, l=0, t=0, r=0, b=0):
         self.l = l # left
         self.t = t # top
@@ -95,18 +95,18 @@
         except TypeError:
             pass
         return self.__dict__[key]
-    
+
     def __repr__(self):
         return 'Borders(l={0.l},t={0.t},r={0.r},b={0.b})'.format(self)
 
 
 class ClipStack:
-    
+
     '''Stack of clipping regions.'''
-    
+
     def __init__(self):
         self.stack = []
-    
+
     def push(self, x, y, w, h):
         newclip = Rect(x, y, w, h)
         if len(self.stack):
@@ -147,21 +147,21 @@
 
 
 class UnicodeGraphics:
-    
+
     '''Unicode graphics bank.
-    
+
     This class can be overriden to change graphics style (round corners etc.).'''
-    
+
     # http://en.wikipedia.org/wiki/List_of_Unicode_characters#Geometric_shapes
     UP_ARROW = '▲' #curses.ACS_UARROW
     DOWN_ARROW = '▼' #curses.ACS_DARROW
-    
+
     # http://en.wikipedia.org/wiki/Box-drawing_characters
     LIGHT_SHADE = '░' #curses.ACS_BOARD
     MEDIUM_SHADE = '▒'
     DARK_SHADE = '▓'
     BLOCK = '█'
-    
+
     COLUMN = '▁▂▃▄▅▆▇█'
     CORNER_ROUND = '╭╮╰╯'
     CORNER = '┌┐└┘'
@@ -178,24 +178,26 @@
 
 
 class MouseEvent:
-    def __init__(self, x=0, y=0):
+    def __init__(self, x=0, y=0, button=0):
         self.x = x   # global coordinates
         self.y = y
         self.wx = x  # local widget coordinates
         self.wy = y
         self.px = 0  # parent coordinates
         self.py = 0
-        self.button = 0
+        self.button = button
 
 
     def childevent(self, child):
-        ev = MouseEvent(self.x, self.y)
+        ev = MouseEvent(self.x, self.y, self.button)
         # original local coordinates are new parent coordinates
         ev.px = self.wx
         ev.py = self.wy
         # update local coordinates
         ev.wx = self.wx - child.x
         ev.wy = self.wy - child.y
-
         return ev
 
+    def __repr__(self):
+        return 'MouseEvent(x={0.x},y={0.y},button={0.button})'.format(self)
+