hamster-applet r791 - in trunk: data hamster



Author: tbaugis
Date: Mon Feb 23 15:12:58 2009
New Revision: 791
URL: http://svn.gnome.org/viewvc/hamster-applet?rev=791&view=rev

Log:
simple preview of activites. 
will have to use system colors, and maybe we can catch drag 
motion!

Modified:
   trunk/data/edit_activity.glade
   trunk/hamster/edit_activity.py

Modified: trunk/data/edit_activity.glade
==============================================================================
--- trunk/data/edit_activity.glade	(original)
+++ trunk/data/edit_activity.glade	Mon Feb 23 15:12:58 2009
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--Generated with glade3 3.4.5 on Wed Feb 18 21:16:49 2009 -->
+<!--Generated with glade3 3.4.5 on Mon Feb 23 13:24:28 2009 -->
 <glade-interface>
   <widget class="GtkWindow" id="custom_fact_window">
     <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
@@ -16,80 +16,64 @@
         <child>
           <widget class="GtkTable" id="table1">
             <property name="visible">True</property>
-            <property name="n_rows">3</property>
+            <property name="n_rows">4</property>
             <property name="n_columns">2</property>
             <property name="column_spacing">4</property>
             <property name="row_spacing">8</property>
             <child>
-              <widget class="GtkScrolledWindow" id="scrolledwindow2">
+              <widget class="GtkEventBox" id="day_preview">
+                <property name="height_request">40</property>
                 <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="hscrollbar_policy">GTK_POLICY_NEVER</property>
-                <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
-                <property name="shadow_type">GTK_SHADOW_IN</property>
                 <child>
-                  <widget class="GtkTextView" id="description">
-                    <property name="height_request">50</property>
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="wrap_mode">GTK_WRAP_WORD_CHAR</property>
-                  </widget>
+                  <placeholder/>
                 </child>
               </widget>
               <packing>
                 <property name="left_attach">1</property>
                 <property name="right_attach">2</property>
-                <property name="top_attach">2</property>
-                <property name="bottom_attach">3</property>
+                <property name="top_attach">3</property>
+                <property name="bottom_attach">4</property>
               </packing>
             </child>
             <child>
-              <widget class="GtkAlignment" id="alignment5">
+              <widget class="GtkAlignment" id="alignment6">
                 <property name="visible">True</property>
                 <property name="xalign">1</property>
+                <property name="yalign">0</property>
                 <property name="xscale">0</property>
                 <property name="yscale">0</property>
                 <child>
-                  <widget class="GtkLabel" id="label1">
+                  <widget class="GtkLabel" id="label4">
                     <property name="visible">True</property>
-                    <property name="label" translatable="yes">Activity:</property>
-                  </widget>
-                </child>
-              </widget>
-            </child>
-            <child>
-              <widget class="GtkAlignment" id="alignment4">
-                <property name="visible">True</property>
-                <property name="xalign">1</property>
-                <property name="xscale">0</property>
-                <child>
-                  <widget class="GtkLabel" id="label2">
-                    <property name="visible">True</property>
-                    <property name="label" translatable="yes">Time:</property>
+                    <property name="label" translatable="yes">Preview:</property>
                   </widget>
                 </child>
               </widget>
               <packing>
-                <property name="top_attach">1</property>
-                <property name="bottom_attach">2</property>
+                <property name="top_attach">3</property>
+                <property name="bottom_attach">4</property>
               </packing>
             </child>
             <child>
-              <widget class="GtkAlignment" id="alignment3">
+              <widget class="GtkAlignment" id="alignment2">
                 <property name="visible">True</property>
-                <property name="xalign">1</property>
-                <property name="yalign">0</property>
-                <property name="yscale">0</property>
+                <property name="xalign">0</property>
                 <child>
-                  <widget class="GtkLabel" id="Description:">
+                  <widget class="GtkComboBoxEntry" id="activity_combo">
                     <property name="visible">True</property>
-                    <property name="label" translatable="yes">Description:</property>
+                    <signal name="changed" handler="on_activity_combo_changed"/>
+                    <child internal-child="entry">
+                      <widget class="GtkEntry" id="activity_text">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                      </widget>
+                    </child>
                   </widget>
                 </child>
               </widget>
               <packing>
-                <property name="top_attach">2</property>
-                <property name="bottom_attach">3</property>
+                <property name="left_attach">1</property>
+                <property name="right_attach">2</property>
               </packing>
             </child>
             <child>
@@ -198,25 +182,75 @@
               </packing>
             </child>
             <child>
-              <widget class="GtkAlignment" id="alignment2">
+              <widget class="GtkAlignment" id="alignment3">
                 <property name="visible">True</property>
-                <property name="xalign">0</property>
+                <property name="xalign">1</property>
+                <property name="yalign">0</property>
+                <property name="yscale">0</property>
                 <child>
-                  <widget class="GtkComboBoxEntry" id="activity_combo">
+                  <widget class="GtkLabel" id="Description:">
                     <property name="visible">True</property>
-                    <signal name="changed" handler="on_activity_combo_changed"/>
-                    <child internal-child="entry">
-                      <widget class="GtkEntry" id="activity_text">
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                      </widget>
-                    </child>
+                    <property name="label" translatable="yes">Description:</property>
+                  </widget>
+                </child>
+              </widget>
+              <packing>
+                <property name="top_attach">2</property>
+                <property name="bottom_attach">3</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkAlignment" id="alignment4">
+                <property name="visible">True</property>
+                <property name="xalign">1</property>
+                <property name="xscale">0</property>
+                <child>
+                  <widget class="GtkLabel" id="label2">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Time:</property>
+                  </widget>
+                </child>
+              </widget>
+              <packing>
+                <property name="top_attach">1</property>
+                <property name="bottom_attach">2</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkAlignment" id="alignment5">
+                <property name="visible">True</property>
+                <property name="xalign">1</property>
+                <property name="xscale">0</property>
+                <property name="yscale">0</property>
+                <child>
+                  <widget class="GtkLabel" id="label1">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Activity:</property>
+                  </widget>
+                </child>
+              </widget>
+            </child>
+            <child>
+              <widget class="GtkScrolledWindow" id="scrolledwindow2">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="hscrollbar_policy">GTK_POLICY_NEVER</property>
+                <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+                <property name="shadow_type">GTK_SHADOW_IN</property>
+                <child>
+                  <widget class="GtkTextView" id="description">
+                    <property name="height_request">50</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="wrap_mode">GTK_WRAP_WORD_CHAR</property>
                   </widget>
                 </child>
               </widget>
               <packing>
                 <property name="left_attach">1</property>
                 <property name="right_attach">2</property>
+                <property name="top_attach">2</property>
+                <property name="bottom_attach">3</property>
               </packing>
             </child>
           </widget>

Modified: trunk/hamster/edit_activity.py
==============================================================================
--- trunk/hamster/edit_activity.py	(original)
+++ trunk/hamster/edit_activity.py	Mon Feb 23 15:12:58 2009
@@ -31,9 +31,119 @@
 
 import time
 import datetime
+import colorsys
 
 GLADE_FILE = "edit_activity.glade"
 
+import cairo, pango
+class Dayline(gtk.DrawingArea):
+    def __init__(self, **args):
+        gtk.DrawingArea.__init__(self)
+        self.context = None
+        self.layout = None
+        self.connect("expose_event", self._expose)
+        self.highlight = None
+
+    def draw(self, day_facts, highlight = None):
+        """Draw chart with given data"""
+        self.facts = day_facts
+        self.highlight = highlight
+        self.show()
+        self._invalidate()
+
+
+    def _invalidate(self):
+        """Force graph redraw"""
+        if self.window:    #this can get called before expose    
+            alloc = self.get_allocation()
+            rect = gtk.gdk.Rectangle(alloc.x, alloc.y, alloc.width, alloc.height)
+            self.window.invalidate_rect(rect, True)
+            self.window.process_updates(True)            
+
+
+    def _expose(self, widget, event):
+        """expose is when drawing's going on, like on _invalidate"""
+        self.context = widget.window.cairo_create()
+        self.context.set_antialias(cairo.ANTIALIAS_NONE)
+
+        self.context.rectangle(event.area.x, event.area.y,
+                               event.area.width, event.area.height)
+        self.context.clip()
+        
+        alloc = self.get_allocation()  #x, y, width, height
+        self.width = alloc.width
+        self.height = alloc.height
+        self._draw(self.context)
+
+        return False
+
+    def _draw(self, context):
+        #TODO - use system colors and fonts
+ 
+        context.set_line_width(1)
+        
+        minute_pixel = self.width / float(60 *24)
+        
+        #run from end to beginning so the rectangle fillings do not erase text
+        self.facts.reverse()
+
+        graph_y = 1
+        graph_height = self.height - 15
+
+
+        
+        context.set_source_rgb(1, 1, 1)
+        context.rectangle(0, graph_y-1, self.width, graph_height)
+        context.fill()
+        context.set_source_rgb(0.7, 0.7, 0.7)
+        context.rectangle(0, graph_y-1, self.width-1, graph_height)
+        context.stroke()
+
+        
+        context.set_source_rgb(0.86, 0.86, 0.86)
+        for fact in self.facts:
+            start_minutes = fact["start_time"].hour * 60 \
+                                                    + fact["start_time"].minute
+
+            if fact["end_time"]:
+                end_minutes = fact["end_time"].hour * 60 \
+                                                      + fact["end_time"].minute
+            else:
+                end_minutes = start_minutes
+            
+            context.rectangle(minute_pixel * start_minutes, graph_y,
+                              minute_pixel * (end_minutes - start_minutes), graph_height - 1)
+        context.fill()
+
+
+        #highlight rectangle
+        if self.highlight:
+            start_minutes = self.highlight[0].hour * 60 + self.highlight[0].minute
+            end_minutes = self.highlight[1].hour * 60 + self.highlight[1].minute
+            
+            rgb = colorsys.hls_to_rgb(.6, .7, .5)
+            context.set_source_rgba(rgb[0], rgb[1], rgb[2], 0.5)
+
+            context.rectangle(minute_pixel * start_minutes, graph_y-1,
+                              minute_pixel * (end_minutes - start_minutes), graph_height)
+            context.fill_preserve()
+            context.set_source_rgb(*rgb)
+            context.stroke()
+            
+
+        #scale labels
+        context.set_source_rgb(0, 0, 0)
+        for i in range(0, 24, 4):
+            context.move_to(minute_pixel * i * 60, graph_height + 12)
+
+            context.show_text("%s:00" % i)
+
+        context.stroke()
+
+
+
+
+
 class CustomFactController:
     def __init__(self,  fact_date = None, fact_id = None):
         self.glade = gtk.glade.XML(os.path.join(SHARED_DATA_DIR, GLADE_FILE))
@@ -86,8 +196,13 @@
                                                   fact_date.day,
                                                   8)
         else:
-            end_date = start_date = datetime.datetime.now()
+            start_date = datetime.datetime.now()
+            end_date = start_date + datetime.timedelta(minutes = 30)
 
+        self.dayline = Dayline()
+        self.glade.get_widget("day_preview").add(self.dayline)
+
+        self.draw_preview(start_date.date())
 
         self.get_widget('start_date').set_text(self.format_date(start_date))
         self.get_widget('start_time').set_text(self.format_time(start_date))
@@ -102,6 +217,11 @@
 
         self.glade.signal_autoconnect(self)
 
+    def draw_preview(self, date, highlight = None):
+        day_facts = storage.get_facts(date)
+        self.dayline.draw(day_facts, highlight)
+        
+        
     def init_calendar_window(self):
         self.calendar_window = self.glade.get_widget('calendar_window')
         self.date_calendar = gtk.Calendar()
@@ -275,10 +395,8 @@
         
         if time and date:
             return datetime.datetime.combine(date, time.time())
-        elif not date:
-            return None
         else:
-            return date
+            return None
     
     def figure_description(self):
         activity = self.get_widget("activity_text").get_text().decode("utf-8")
@@ -570,6 +688,11 @@
         end_time = self._get_datetime("end")
         if self.get_widget("in_progress").get_active():
             end_time = datetime.datetime.now()
+
+        if start_time:
+            self.draw_preview(start_time.date(), [start_time, end_time])
+
+
         
         looks_good = False
         if activity_text != "" and start_time and end_time and \



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