[Commits] typing-turtle branch master updated.

Wade Brainerd wadetb at gmail.com
Thu Jan 29 23:47:03 EST 2009


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "/home/olpc-code/git/activities/typing-turtle".

The branch, master has been updated
       via  298b6d305f4cebeed03ddc5a4e49ddd58743d6e5 (commit)
       via  e32707f55e3614368e0498137b30a274194dd443 (commit)
       via  8c6509d046036a7db2be1e83ab7e591c1a02de0b (commit)
      from  27fbcc80d5435f943dcd63bbf375529fe39af3b3 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

 balloongame.py            |   13 +++----
 keyboard.py               |   80 +++++++++++++++++++++++++++------------------
 lessons/en_US/MAKELESSONS |    1 +
 lessonscreen.py           |   10 +++++-
 4 files changed, 64 insertions(+), 40 deletions(-)

- Log -----------------------------------------------------------------
commit 298b6d305f4cebeed03ddc5a4e49ddd58743d6e5
Author: Wade Brainerd <wadetb at gmail.com>
Date:   Fri Jan 30 04:46:33 2009 +0000

    WIP towards making hands actually work.

diff --git a/keyboard.py b/keyboard.py
index bab91ad..d837e54 100644
--- a/keyboard.py
+++ b/keyboard.py
@@ -323,6 +323,7 @@ class KeyboardData:
         """Sets the keyboard's layout from  a layout description."""
         self._build_key_list(layout)
         self._layout_keys()
+        self._make_key_images()
 
     def find_key_by_label(self, label):
         for k in self.keys:
@@ -421,14 +422,22 @@ class KeyboardWidget(KeyboardData, gtk.DrawingArea):
     def _load_image(self, name):
         bundle_path = sugar.activity.activity.get_bundle_path() 
         filename = os.path.join(bundle_path, 'images', name)
-        return rsvg.Handle(filename)
+        return gtk.gdk.pixbuf_new_from_file_at_size(filename, 775, 265)
+        #return rsvg.Handle(filename)
 
     def load_hand_images(self):
         for key in self.keys:
             if key['key-hand-image']:
                 key['key-hand-image-handle'] = self._load_image(key['key-hand-image']) 
-    
+
+    def _make_key_images(self):
+        for key in self.keys:
+            pb = self.get_key_image(key, 0, 0)
+            key['key-image'] = pb
+
     def _get_screen_ratio(self):
+        return 1.0
+
         bounds = self.get_allocation()
         
         # This calculates a ratio from layout coordinates to the DrawingArea's
@@ -440,13 +449,13 @@ class KeyboardWidget(KeyboardData, gtk.DrawingArea):
         
         # Pick the smaller ratio to fit while preserving aspect ratio.
         return min(ratio_x, ratio_y)
-    
+
     def _expose_key(self, k, draw, gc, for_pixmap, w=0, h=0):
         if for_pixmap:
-            x1 = 5 
-            y1 = 5
-            x2 = w - 5
-            y2 = h - 5
+            x1 = 0 
+            y1 = 0
+            x2 = w
+            y2 = h
 
         else:
             # Set up the screen transform.
@@ -460,6 +469,9 @@ class KeyboardWidget(KeyboardData, gtk.DrawingArea):
             x2 = int(x1 + k['key-width'] * screen_ratio)
             y2 = int(y1 + k['key-height'] * screen_ratio)
 
+            draw.draw_image(gc, k['key-image'], 0, 0, x1, y1, x2-x1, y2-y1) 
+            return
+
         # Outline rounded box.
         gc.foreground = self.get_colormap().alloc_color((0.4*65536),int(0.7*65536),int(0.4*65536))
         
@@ -505,22 +517,6 @@ class KeyboardWidget(KeyboardData, gtk.DrawingArea):
             pass
 
     def _expose_hands(self, gc):
-        # Hands are still rendered through cairo, sigh.
-        cr = self.window.cairo_create()
-
-        screen_ratio = self._get_screen_ratio()
-        bounds = self.get_allocation()
-        cr.translate(
-            (bounds.width - self.keys[0]['layout-width']*screen_ratio)/2,
-            (bounds.height - self.keys[0]['layout-height']*screen_ratio)/2)
-        
-        cr.scale(screen_ratio, screen_ratio)
-
-        # Transform based on the original SVG resolution.
-        ratio = self.keys[0]['layout-width'] / 3158.0
-        cr.scale(ratio, ratio)
-        cr.translate(0, -150)
-
         lhand_image = self.lhand_home
         rhand_image = self.rhand_home
 
@@ -546,15 +542,12 @@ class KeyboardWidget(KeyboardData, gtk.DrawingArea):
 
                 # TODO: Do something about ALTGR.
 
-        #pb = lhand_image.get_pixbuf()
-        #lhand_image.set_dpi(30)
-        #self.window.draw_pixbuf(gc, pb, 0, 0, 0, 0)
-        #pb = rhand_image.get_pixbuf()
-        #rhand_image.set_dpi(30)
-        #self.window.draw_pixbuf(gc, pb, 0, 0, 0, 0)
+        bounds = self.get_allocation()
+        screen_x = (bounds.width-self.keys[0]['layout-width'])/2
+        screen_y = (bounds.height-self.keys[0]['layout-height'])/2
 
-        lhand_image.render_cairo(cr)
-        rhand_image.render_cairo(cr)
+        self.window.draw_pixbuf(gc, lhand_image, 0, 0, screen_x, screen_y)
+        self.window.draw_pixbuf(gc, rhand_image, 0, 0, screen_x, screen_y)
 
     def _expose_cb(self, area, event):
         gc = self.window.new_gc()
@@ -590,7 +583,8 @@ class KeyboardWidget(KeyboardData, gtk.DrawingArea):
 
         else:
             if self.draw_hands:
-                self.queue_draw()
+                pass
+                #self.queue_draw()
                 #self.window.process_updates(True)
             else:
                 if key:
@@ -645,6 +639,28 @@ class KeyboardWidget(KeyboardData, gtk.DrawingArea):
         self.active_state, self.active_group = old_state, old_group
 
         return pb
+
+    def get_key_image(self, key, state=0, group=0, scale=1):
+        w = int(key['key-width'] * scale)
+        h = int(key['key-height'] * scale)
+        
+        old_state, old_group = self.active_state, self.active_group
+        self.active_state, self.active_group = state, group
+        
+        pixmap = gtk.gdk.Pixmap(self.root_window.window, w, h)
+        gc = pixmap.new_gc()
+        
+        gc.foreground = self.get_colormap().alloc_color('#d0d0d0')
+        pixmap.draw_rectangle(gc, True, 0, 0, w, h)
+
+        self._expose_key(key, pixmap, gc, True, w, h)
+        
+        image = pixmap.get_image(0, 0, w, h)
+        
+        self.active_state, self.active_group = old_state, old_group
+
+        return image
+
     
 if __name__ == "__main__":
     window = gtk.Window(gtk.WINDOW_TOPLEVEL)
diff --git a/lessons/en_US/MAKELESSONS b/lessons/en_US/MAKELESSONS
index 61c9fb5..29575cc 100755
--- a/lessons/en_US/MAKELESSONS
+++ b/lessons/en_US/MAKELESSONS
@@ -34,6 +34,7 @@
     --title="Welcome" \
     --desc="Click here to begin your typing adventure." \
     --bronze-wpm=0 --silver-wpm=0 --gold-wpm=0 \
+    --bronze-accuracy=25 --silver-accuracy=50 --gold-accuracy=100 \
     --order=0 \
     --output=intro.lesson
 
diff --git a/lessonscreen.py b/lessonscreen.py
index 6c032cc..1d41d64 100644
--- a/lessonscreen.py
+++ b/lessonscreen.py
@@ -331,7 +331,7 @@ class LessonScreen(gtk.VBox):
             self.lessontext.set_cursor_visible(True)
             
             # Hide hands for typing mode - performance is too slow to type.  Sigh for now.
-            self.keyboard.set_draw_hands(False)
+            #self.keyboard.set_draw_hands(False)
 
         self.line_idx = 0
         self.begin_line()

commit e32707f55e3614368e0498137b30a274194dd443
Author: Wade Brainerd <wadetb at gmail.com>
Date:   Fri Jan 30 03:42:16 2009 +0000

    Typo in last commit.  Non working attempt at space between lesson lines.

diff --git a/balloongame.py b/balloongame.py
index d714cb7..3dcf793 100644
--- a/balloongame.py
+++ b/balloongame.py
@@ -160,7 +160,7 @@ class BalloonGame(gtk.VBox):
             self.update_balloon(b)
 
         self.spawn_delay -= 1
-        if if self.count_left >= 0 && self.spawn_delay <= 0:
+        if self.count_left >= 0 and self.spawn_delay <= 0:
             self.count += 1
             self.count_left -= 1
 
diff --git a/lessonscreen.py b/lessonscreen.py
index 18c0737..6c032cc 100644
--- a/lessonscreen.py
+++ b/lessonscreen.py
@@ -87,6 +87,10 @@ class LessonScreen(gtk.VBox):
         text_tag.props.size = 9000
         self.tagtable.add(text_tag)
         
+        spacer_tag = gtk.TextTag('spacer')
+        spacer_tag.props.size = 10
+        self.tagtable.add(spacer_tag)
+        
         image_tag = gtk.TextTag('image')
         image_tag.props.justification = gtk.JUSTIFY_CENTER
         self.tagtable.add(image_tag)
@@ -311,6 +315,10 @@ class LessonScreen(gtk.VBox):
             self.line_marks = {} 
             line_idx = 0
             for l in self.lines:
+                # Add a little space between lines.  Not working atm.
+                #self.lessonbuffer.insert_with_tags_by_name(
+                #    self.lessonbuffer.get_end_iter(), '\n', 'spacer')
+
                 # Add the text to copy.
                 self.lessonbuffer.insert_with_tags_by_name(
                     self.lessonbuffer.get_end_iter(), '\n' + l.encode('utf-8') + '\n', 'text')

commit 8c6509d046036a7db2be1e83ab7e591c1a02de0b
Author: Wade Brainerd <wadetb at gmail.com>
Date:   Fri Jan 30 03:33:06 2009 +0000

    Balloon fixes.

diff --git a/balloongame.py b/balloongame.py
index 5caaef9..d714cb7 100644
--- a/balloongame.py
+++ b/balloongame.py
@@ -59,7 +59,6 @@ class BalloonGame(gtk.VBox):
         
         # Build the game drawing area.
         self.area = gtk.DrawingArea()
-        self.area.modify_bg(gtk.STATE_NORMAL, self.get_colormap().alloc_color('#c0c0ff'))
         self.area.connect("expose-event", self.expose_cb)
 
         # Connect keyboard grabbing and releasing callbacks.        
@@ -161,7 +160,7 @@ class BalloonGame(gtk.VBox):
             self.update_balloon(b)
 
         self.spawn_delay -= 1
-        if self.spawn_delay <= 0:
+        if if self.count_left >= 0 && self.spawn_delay <= 0:
             self.count += 1
             self.count_left -= 1
 
@@ -184,7 +183,7 @@ class BalloonGame(gtk.VBox):
                 delay = 40
             self.spawn_delay = random.randint(delay-20, delay+20)
 
-        if len(self.balloons) == 0 and self.count_left <= 0:
+        if self.count_left <= 0 and len(self.balloons) == 0:
             self.finish_game()
  
         return True
@@ -284,7 +283,7 @@ class BalloonGame(gtk.VBox):
         x1 = int(b.x - b.size/2)
         y1 = int(b.y - b.size/2)
         x2 = int(b.x + b.size/2)
-        y2 = int(b.y + b.size/2 - b.size*b.vy)
+        y2 = int(b.y + b.size/2)
         self.queue_draw_area(x1, y1, x2, y2)
 
     def draw_balloon(self, gc, b):
@@ -292,8 +291,8 @@ class BalloonGame(gtk.VBox):
         y = int(b.y)
         
         # Draw the string.
-        gc.foreground = self.area.get_colormap().alloc_color(0,0,0)
-        self.area.window.draw_line(gc, b.x, b.y+b.size/2, b.x-int(b.size/2*b.vx), b.y+b.size/2-int(b.size/2*b.vy))
+        #gc.foreground = self.area.get_colormap().alloc_color(0,0,0)
+        #self.area.window.draw_line(gc, b.x, b.y+b.size/2, b.x-int(b.size/2*b.vx), b.y+b.size/2-int(b.size/2*b.vy))
         
         # Draw the balloon.
         gc.foreground = self.area.get_colormap().alloc_color(b.color[0],b.color[1],b.color[2])
@@ -345,7 +344,7 @@ class BalloonGame(gtk.VBox):
         gc = self.area.window.new_gc()
         
         # Draw background.
-        gc.foreground = self.area.get_colormap().alloc_color(65535,65535,65535)
+        gc.foreground = self.area.get_colormap().alloc_color(60000,60000,65535)
         self.area.window.draw_rectangle(gc, True, 0, 0, self.bounds.width, self.bounds.height)
 
         # Draw the balloons.
-----------------------------------------------------------------------


--
/home/olpc-code/git/activities/typing-turtle


More information about the Commits mailing list