[hamster-applet] some minor cleanup



commit fd8a93a8fd064226cac6e59f504f970b2c803dbf
Author: Toms Bauģis <toms baugis gmail com>
Date:   Fri Nov 27 11:52:53 2009 +0000

    some minor cleanup

 hamster/stats.py            |    2 +-
 hamster/widgets/dayline.py  |   13 +++++++++----
 hamster/widgets/tags.py     |    2 +-
 hamster/widgets/timeline.py |   19 ++++++++++++-------
 4 files changed, 23 insertions(+), 13 deletions(-)
---
diff --git a/hamster/stats.py b/hamster/stats.py
index b4216cc..178921a 100644
--- a/hamster/stats.py
+++ b/hamster/stats.py
@@ -216,7 +216,7 @@ class StatsViewer(object):
                 self.text = text
                 self.redraw_canvas()
                 
-            def _render(self):
+            def on_expose(self):
                 if self.background:
                     self.fill_area(0, 0, self.width, self.height, self.background)
 
diff --git a/hamster/widgets/dayline.py b/hamster/widgets/dayline.py
index c648f8e..310594f 100644
--- a/hamster/widgets/dayline.py
+++ b/hamster/widgets/dayline.py
@@ -61,12 +61,12 @@ class DayLine(graphics.Area):
         if not self.x_factor:
             self.x_factor = 1
             if self.value_boundaries and self.value_boundaries[0] != None and self.value_boundaries[1] != None:
-                self.x_factor = float(self.graph_width or self.width) / abs(self.value_boundaries[1] - self.value_boundaries[0])
+                self.x_factor = float(self.width) / abs(self.value_boundaries[1] - self.value_boundaries[0])
                 
         if not self.y_factor:            
             self.y_factor = 1
             if self.value_boundaries and self.value_boundaries[2] != None and self.value_boundaries[3] != None:
-                self.y_factor = float(self.graph_height or self.height) / abs(self.value_boundaries[3] - self.value_boundaries[2])
+                self.y_factor = float(self.height) / abs(self.value_boundaries[3] - self.value_boundaries[2])
 
         return self.x_factor, self.y_factor        
 
@@ -139,7 +139,12 @@ class DayLine(graphics.Area):
         self.range_start = None
         self.in_motion = False
         self.days = []
-        
+
+        # TODO - get rid of these
+        self.value_boundaries = None #x_min, x_max, y_min, y_max
+        self.x_factor, self.y_factor = None, None        
+        # use these to mark area where the "real" drawing is going on
+        self.graph_x, self.graph_y = 0, 0
 
     def draw(self, day_facts, highlight = None):
         """Draw chart with given data"""
@@ -307,7 +312,7 @@ class DayLine(graphics.Area):
             delta = (date - self.range_start.value)
             return delta.days * 24 * 60 + delta.seconds / 60
             
-    def _render(self):
+    def on_expose(self):
         context = self.context
         #TODO - use system colors and fonts
  
diff --git a/hamster/widgets/tags.py b/hamster/widgets/tags.py
index ee73389..207e538 100644
--- a/hamster/widgets/tags.py
+++ b/hamster/widgets/tags.py
@@ -279,7 +279,7 @@ class TagBox(graphics.Area):
             cur_x += w + 8 #some padding too, please
         return cur_y + h + 6
     
-    def _render(self):
+    def on_expose(self):
         cur_x, cur_y = 4, 4
         for tag in self.tags:
             w, h = self.tag_size(tag)
diff --git a/hamster/widgets/timeline.py b/hamster/widgets/timeline.py
index 74dd694..637faee 100644
--- a/hamster/widgets/timeline.py
+++ b/hamster/widgets/timeline.py
@@ -30,6 +30,11 @@ class TimeLine(graphics.Area):
         self.start_date, self.end_date = None, None
         self.draw_mode = None
         self.max_hours = None
+
+        # TODO - get rid of these
+        self.value_boundaries = None #x_min, x_max, y_min, y_max
+        self.x_factor, self.y_factor = None, None        
+
         
     #TODO remove these obsolete functions with in-house transformations
     def set_value_range(self, x_min = None, x_max = None, y_min = None, y_max = None):
@@ -63,12 +68,12 @@ class TimeLine(graphics.Area):
         if not self.x_factor:
             self.x_factor = 1
             if self.value_boundaries and self.value_boundaries[0] != None and self.value_boundaries[1] != None:
-                self.x_factor = float(self.graph_width or self.width) / abs(self.value_boundaries[1] - self.value_boundaries[0])
+                self.x_factor = float(self.width) / abs(self.value_boundaries[1] - self.value_boundaries[0])
                 
         if not self.y_factor:            
             self.y_factor = 1
             if self.value_boundaries and self.value_boundaries[2] != None and self.value_boundaries[3] != None:
-                self.y_factor = float(self.graph_height or self.height) / abs(self.value_boundaries[3] - self.value_boundaries[2])
+                self.y_factor = float(self.height) / abs(self.value_boundaries[3] - self.value_boundaries[2])
 
         return self.x_factor, self.y_factor        
 
@@ -91,7 +96,7 @@ class TimeLine(graphics.Area):
                 else: #case when min is larger than max (flipped)
                     x_value = self.value_boundaries[1] - x_value * x_factor
             if y_value is None:
-                return x_value + self.graph_x
+                return x_value
 
         if y_value != None:
             if self.value_boundaries and self.value_boundaries[2] != None:
@@ -102,18 +107,18 @@ class TimeLine(graphics.Area):
             if x_value is None:
                 return y_value + self.graph_y
             
-        return x_value + self.graph_x, y_value + self.graph_y
+        return x_value, y_value
 
     def get_value_at_pos(self, x = None, y = None):
         """returns mapped value at the coordinates x,y"""
         x_factor, y_factor = self._get_factors()
         
         if x != None:
-            x = (x - self.graph_x)  / x_factor
+            x = x  / x_factor
             if y is None:
                 return x
         if y != None:
-            y = (y - self.graph_x) / y_factor
+            y = y / y_factor
             if x is None:
                 return y
         return x, y            
@@ -159,7 +164,7 @@ class TimeLine(graphics.Area):
         self.redraw_canvas()
         
         
-    def _render(self):
+    def on_expose(self):
         import calendar
         
         if self.draw_mode != self.MODE_YEAR:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]