Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLive System User <liveuser@localhost.localdomain>2009-02-26 01:52:06 (GMT)
committer Live System User <liveuser@localhost.localdomain>2009-02-26 01:52:06 (GMT)
commit1a6c518673dc43062b37459efe942479911c53b7 (patch)
tree0f8095deaa7774b8b5d80322180cac181bee92fc
parent5ede2990f222d762cf047dccaee2ec988984ab8e (diff)
TitleScene separated into its own module and resolution independent.
-rw-r--r--activity/activity.info2
-rw-r--r--keyboard.py6
-rw-r--r--mainscreen.py75
-rw-r--r--titlescene.py92
-rwxr-xr-xtypingturtle.py19
5 files changed, 114 insertions, 80 deletions
diff --git a/activity/activity.info b/activity/activity.info
index c1f4638..3e03a06 100644
--- a/activity/activity.info
+++ b/activity/activity.info
@@ -1,6 +1,6 @@
[Activity]
name = Typing Turtle
-activity_version = 11
+activity_version = 12
host_version = 1
service_name = org.laptop.community.TypingTurtle
icon = Activity-typingturtle
diff --git a/keyboard.py b/keyboard.py
index 81eaa5e..c4bbfb5 100644
--- a/keyboard.py
+++ b/keyboard.py
@@ -23,8 +23,6 @@ import rsvg
import os, glob
import pango
-import sugar.activity.activity
-
# Tweaking variables.
KEYBOARD_SCALE = 1.25
HAND_SCALE = 1.4
@@ -229,9 +227,7 @@ class KeyboardImages:
self.images = {}
def load_images(self):
- bundle_path = sugar.activity.activity.get_bundle_path()
- path = os.path.join(bundle_path, 'images')
- for filename in glob.iglob(path + '/*.svg'):
+ for filename in glob.iglob('images/OLPC_*.svg'):
image = gtk.gdk.pixbuf_new_from_file_at_size(filename, self.width, self.height)
name = os.path.basename(filename)
self.images[name] = image
diff --git a/mainscreen.py b/mainscreen.py
index 3771c91..1c82f3e 100644
--- a/mainscreen.py
+++ b/mainscreen.py
@@ -27,6 +27,7 @@ from sugar.graphics import *
# Import activity modules.
import lessonscreen, medalscreen, balloongame
+import titlescene
import keyboard
# Temporary SVGs of medals from Wikimedia Commons.
@@ -35,61 +36,6 @@ import keyboard
# http://commons.wikimedia.org/wiki/File:Silver_medal_world_centered.svg
# http://commons.wikimedia.org/wiki/File:Bronze_medal_world_centered.svg
-class TitleScene(gtk.DrawingArea):
- def __init__(self):
- gtk.DrawingArea.__init__(self)
-
- bundle = sugar.activity.activity.get_bundle_path()
- self.backgroundpixbuf = gtk.gdk.pixbuf_new_from_file(bundle + '/images/main-background.jpg')
-
- self.set_size_request(self.backgroundpixbuf.get_width(), self.backgroundpixbuf.get_height())
-
- self.connect("expose-event", self.expose_cb)
-
- 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()
-
- gc = self.get_style().fg_gc[gtk.STATE_NORMAL]
-
- self.window.draw_pixbuf(
- gc, self.backgroundpixbuf,
- event.area.x, event.area.y,
- event.area.x, event.area.y, event.area.width, event.area.height)
-
- # Animated Typing Turtle title.
- pc = self.create_pango_context()
-
- layout = self.create_pango_layout('')
- layout.set_font_description(pango.FontDescription('Times 45'))
-
- layout.set_text(self.title_original)
- original_size = layout.get_size()
-
- x = (bounds.width-original_size[0]/pango.SCALE)-20
- y = 30
-
- layout.set_text(self.title_text)
- self.window.draw_layout(gc, x, y, 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)
-
- return True
-
class MainScreen(gtk.VBox):
def __init__(self, activity):
gtk.VBox.__init__(self)
@@ -97,7 +43,7 @@ class MainScreen(gtk.VBox):
self.activity = activity
# Build background.
- self.titlescene = TitleScene()
+ self.titlescene = titlescene.TitleScene()
# Build lessons list.
self.lessonbox = gtk.HBox()
@@ -129,14 +75,12 @@ class MainScreen(gtk.VBox):
lessonbtn.modify_bg(gtk.STATE_NORMAL, self.get_colormap().alloc_color('#60b060'))
# Load lessons for this language.
- bundle_path = sugar.activity.activity.get_bundle_path()
code = locale.getdefaultlocale()[0]
- path = bundle_path + '/lessons/' + code
- self.load_lessons(path)
+ self.load_lessons('lessons/' + code)
# Fallback to en_US lessons if none found.
if not len(self.lessons):
- self.load_lessons(bundle_path + '/lessons/en_US')
+ self.load_lessons('lessons/en_US')
# We cannot run without lessons/
if not len(self.lessons):
@@ -201,7 +145,7 @@ class MainScreen(gtk.VBox):
self.lesson_index = index
self.visible_lesson = lesson
-
+
medal_type = 'none'
if self.activity.data['medals'].has_key(lesson['name']):
medal_type = self.activity.data['medals'][lesson['name']]['type']
@@ -231,12 +175,11 @@ class MainScreen(gtk.VBox):
#labelbox.pack_start(hintlabel)
# Create the medal image.
- bundle = sugar.activity.activity.get_bundle_path()
images = {
- 'none': bundle+'/images/no-medal.svg',
- 'bronze': bundle+'/images/bronze-medal.svg',
- 'silver': bundle+'/images/silver-medal.svg',
- 'gold': bundle+'/images/gold-medal.svg'
+ 'none': 'images/no-medal.svg',
+ 'bronze': 'images/bronze-medal.svg',
+ 'silver': 'images/silver-medal.svg',
+ 'gold': 'images/gold-medal.svg'
}
medalpixbuf = gtk.gdk.pixbuf_new_from_file(images[medal_type])
medalpixbuf = medalpixbuf.scale_simple(200, 200, gtk.gdk.INTERP_BILINEAR)
diff --git a/titlescene.py b/titlescene.py
new file mode 100644
index 0000000..297f633
--- /dev/null
+++ b/titlescene.py
@@ -0,0 +1,92 @@
+# Copyright 2008 by Kate Scheppke and Wade Brainerd.
+# This file is part of Typing Turtle.
+#
+# Typing Turtle is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Typing Turtle is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Typing Turtle. If not, see <http://www.gnu.org/licenses/>.
+
+# Import standard Python modules.
+import random
+from gettext import gettext as _
+
+# Import PyGTK.
+import gobject, pygtk, gtk, pango
+
+class TitleScene(gtk.DrawingArea):
+ # Maximum portion of the screen the background can fill vertically.
+ BACKGROUND_HEIGHT_RATIO = 0.6
+
+ # Border from top right of screen to draw title at.
+ TITLE_OFFSET = (20, 30)
+
+ # Font used to display the title.
+ TITLE_FONT = 'Times 45'
+
+ def __init__(self):
+ gtk.DrawingArea.__init__(self)
+
+ pbuf = gtk.gdk.pixbuf_new_from_file('images/main-background.jpg')
+
+ width_ratio = float(gtk.gdk.screen_width()) / pbuf.get_width()
+ height_ratio = float(gtk.gdk.screen_height()*TitleScene.BACKGROUND_HEIGHT_RATIO) / pbuf.get_height()
+
+ ratio = min(width_ratio, height_ratio)
+ self.backgroundpixbuf = pbuf.scale_simple(pbuf.get_width()*ratio, pbuf.get_height()*ratio, gtk.gdk.INTERP_BILINEAR)
+
+ self.set_size_request(self.backgroundpixbuf.get_width(), self.backgroundpixbuf.get_height())
+
+ self.connect("expose-event", self.expose_cb)
+
+ 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()
+
+ gc = self.get_style().fg_gc[gtk.STATE_NORMAL]
+
+ # Background picture.
+ x = (bounds.width - self.backgroundpixbuf.get_width())/2
+ 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()
+
+ x = (bounds.width-original_size[0]/pango.SCALE)-TitleScene.TITLE_OFFSET[0]
+ y = TitleScene.TITLE_OFFSET[1]
+
+ layout.set_text(self.title_text)
+ self.window.draw_layout(gc, x, y, 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)
+
+ return True
diff --git a/typingturtle.py b/typingturtle.py
index 8f5fdb2..e9c2f9e 100755
--- a/typingturtle.py
+++ b/typingturtle.py
@@ -40,12 +40,13 @@ log = logging.getLogger('Typing Turtle')
log.setLevel(logging.DEBUG)
logging.basicConfig()
+# Change to bundle directory.
+bundle_path = sugar.activity.activity.get_bundle_path()
+os.chdir(bundle_path)
+
# Import activity modules.
import mainscreen, lessonscreen, medalscreen
-# Set to True to allow access to all lessons.
-DEBUG_LESSONS = True
-
# This is the main Typing Turtle activity class.
#
# It owns the main application window, and all the various toolbars and options.
@@ -65,15 +66,11 @@ class TypingTurtle(sugar.activity.activity.Activity):
# All data which is saved in the Journal entry is placed in this dictionary.
self.data = {
'motd': 'welcome',
- 'level': 0,
'history': [],
'medals': {}
}
- if DEBUG_LESSONS:
- self.data['level'] = 1000
-
- # This has to happen last, because it calls the read_file method when restoring from the Journal.
+ # This calls the read_file method when restoring from the Journal.
self.set_canvas(self.screenbox)
# Start with the main screen.
@@ -109,6 +106,8 @@ class TypingTurtle(sugar.activity.activity.Activity):
self.data['history'].append(entry)
def read_file(self, file_path):
+ print 'read_file'
+
if self.metadata['mime_type'] != 'text/plain':
return
@@ -120,7 +119,11 @@ class TypingTurtle(sugar.activity.activity.Activity):
finally:
fd.close()
+ self.mainscreen.show_next_lesson()
+
def write_file(self, file_path):
+ print 'write_file'
+
if not self.metadata['mime_type']:
self.metadata['mime_type'] = 'text/plain'