Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/titlescene.py
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@gmail.com>2011-11-25 13:33:48 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2011-11-25 14:06:00 (GMT)
commit49f8f957d54ee5f8dca902548e47333216beece2 (patch)
tree63aaae08dbe5fa1c6c94a79bc5d96916d54e67d8 /titlescene.py
parentd55d138f7acd2af018ea1ce779a11637f36722fc (diff)
Avoid redrawing all the screen and remove timeout when title is displayed
The title scene was using a timeout to display the letters in the title one by one, and adding a random delay to simulate a human typing. That timeout was never stoped, and continued running while the activity was used. Also to add every letter, all the background image was updated, and that is slow in the xo-1.75. This patch stop the timeout when is not needed anymore and update only the title text in the presentation screen. Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
Diffstat (limited to 'titlescene.py')
-rw-r--r--titlescene.py43
1 files changed, 20 insertions, 23 deletions
diff --git a/titlescene.py b/titlescene.py
index ea3dd7d..7cc2d68 100644
--- a/titlescene.py
+++ b/titlescene.py
@@ -49,9 +49,6 @@ class TitleScene(gtk.DrawingArea):
self.title_original = _('Typing Turtle')
self.title_src = self.title_original
self.title_text = ''
- self.title_counter = 50
-
- gobject.timeout_add(10, self.timer_cb)
def expose_cb(self, area, event):
bounds = self.get_allocation()
@@ -63,30 +60,30 @@ class TitleScene(gtk.DrawingArea):
self.window.draw_pixbuf(
gc, self.backgroundpixbuf, 0, 0,
x, 0, self.backgroundpixbuf.get_width(), self.backgroundpixbuf.get_height())
-
- # Animated Typing Turtle title.
pc = self.create_pango_context()
- layout = self.create_pango_layout('')
- layout.set_font_description(pango.FontDescription(TitleScene.TITLE_FONT))
-
- layout.set_text(self.title_original)
- original_size = layout.get_size()
+ self.layout = self.create_pango_layout('')
+ self.layout.set_font_description(pango.FontDescription(TitleScene.TITLE_FONT))
- x = (bounds.width-original_size[0]/pango.SCALE)-TitleScene.TITLE_OFFSET[0]
- y = TitleScene.TITLE_OFFSET[1]
+ self.layout.set_text(self.title_original)
+ original_size = self.layout.get_size()
+ self.x_text = (bounds.width-original_size[0]/pango.SCALE)-TitleScene.TITLE_OFFSET[0]
+ self.y_text = TitleScene.TITLE_OFFSET[1]
+ gobject.timeout_add(50, self.timer_cb)
- layout.set_text(self.title_text)
- self.window.draw_layout(gc, x, y, layout)
+ def draw_text(self):
+ # Animated Typing Turtle title.
+ gc = self.get_style().fg_gc[gtk.STATE_NORMAL]
+ self.layout.set_text(self.title_text)
+ self.window.draw_layout(gc, self.x_text, self.y_text, self.layout)
def timer_cb(self):
- self.title_counter -= 1
- if self.title_counter == 0:
- if len(self.title_src) > 0:
- self.title_text += self.title_src[0]
- self.title_src = self.title_src[1:]
- self.queue_draw()
-
- self.title_counter = random.randint(1, 5)
-
+ if len(self.title_src) > 0:
+ self.title_text += self.title_src[0]
+ self.title_src = self.title_src[1:]
+ self.draw_text()
+ else:
+ self.draw_text()
+ return False
+
return True