Ticket #3772: 0002-Port-to-Gtk3-SL-3772.patch
File 0002-Port-to-Gtk3-SL-3772.patch, 96.2 KB (added by humitos, 12 years ago) |
---|
-
balloongame.py
From 3ddcd1a55d20d5d90169927be32427dbebf7cace Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann <humitos@gmail.com> Date: Thu, 2 Aug 2012 10:42:16 -0300 Subject: [PATCH TypingTurtle 2/2] Port to Gtk3 SL #3772 This commit ports Typing Turtle to its Gtk3 version. Signed-off-by: Manuel Kaufmann <humitos@gmail.com> --- balloongame.py | 161 +++++++++++++------------ editlessonlistscreen.py | 100 ++++++++-------- editlessonscreen.py | 309 ++++++++++++++++++++++++------------------------ keyboard.py | 127 ++++++++++---------- keybuilder.py | 30 ++--- lessonbuilder.py | 8 +- lessonscreen.py | 94 ++++++++------- mainscreen.py | 101 ++++++++-------- medalscreen.py | 86 +++++++------- port/chooser.py | 8 +- setup.py | 2 +- titlescene.py | 54 +++++---- typingturtle.py | 99 ++++++++-------- 13 files changed, 600 insertions(+), 579 deletions(-) diff --git a/balloongame.py b/balloongame.py index 7224893..2380e95 100644
a b 16 16 17 17 import math 18 18 import random, datetime 19 import pangocairo20 19 21 20 from gettext import gettext as _ 22 21 23 import gobject, pygtk, gtk, pango 22 from gi.repository import Gtk 23 from gi.repository import Gdk 24 from gi.repository import GObject 25 from gi.repository import Pango 26 from gi.repository import PangoCairo 24 27 25 28 import medalscreen 26 29 … … class Balloon: 41 44 self.size = max(100, 50 + len(word) * 20) 42 45 self.color = random.choice(BALLOON_COLORS) 43 46 44 class BalloonGame( gtk.VBox):47 class BalloonGame(Gtk.VBox): 45 48 def __init__(self, lesson, activity): 46 gtk.VBox.__init__(self)49 GObject.GObject.__init__(self) 47 50 48 51 self.lesson = lesson 49 52 self.activity = activity 50 53 51 54 # Build title bar. 52 title = gtk.Label()55 title = Gtk.Label() 53 56 title.set_markup("<span size='20000'><b>" + lesson['name'] + "</b></span>") 54 57 title.set_alignment(1.0, 0.0) 55 58 56 stoplabel = gtk.Label(_('Go Back'))57 stopbtn = gtk.Button()59 stoplabel = Gtk.Label(label=_('Go Back')) 60 stopbtn = Gtk.Button() 58 61 stopbtn.add(stoplabel) 59 62 stopbtn.connect('clicked', self.stop_cb) 60 63 61 hbox = gtk.HBox()64 hbox = Gtk.HBox() 62 65 hbox.pack_start(stopbtn, False, False, 10) 63 66 hbox.pack_end(title, False, False, 10) 64 67 65 68 # Build the game drawing area. 66 self.area = gtk.DrawingArea()67 self. area.connect("expose-event", self.expose_cb)69 self.area = Gtk.DrawingArea() 70 self.draw_cb_id = self.area.connect("draw", self.draw_cb) 68 71 69 72 # Connect keyboard grabbing and releasing callbacks. 70 73 self.area.connect('realize', self.realize_cb) 71 74 self.area.connect('unrealize', self.unrealize_cb) 72 75 73 76 self.pack_start(hbox, False, False, 10) 74 self.pack_start(self.area, True, True )77 self.pack_start(self.area, True, True, 0) 75 78 76 79 self.show_all() 77 80 … … class BalloonGame(gtk.VBox): 88 91 self.finished = False 89 92 90 93 # Start the animation loop running. 91 self.update_timer = gobject.timeout_add(20, self.tick, priority=gobject.PRIORITY_HIGH_IDLE+30)94 self.update_timer = GObject.timeout_add(20, self.tick, priority=GObject.PRIORITY_HIGH_IDLE+30) 92 95 93 96 def realize_cb(self, widget): 94 self.activity.add_events( gtk.gdk.KEY_PRESS_MASK)97 self.activity.add_events(Gdk.EventMask.KEY_PRESS_MASK) 95 98 self.key_press_cb_id = self.activity.connect('key-press-event', self.key_cb) 96 99 97 100 # Clear the mouse cursor. 98 #pixmap = gtk.gdk.Pixmap(widget.window, 10, 10)99 #color = gtk.gdk.Color()100 #cursor = gtk.gdk.Cursor(pixmap, pixmap, color, color, 5, 5)101 #pixmap = Gdk.Pixmap(widget.window, 10, 10) 102 #color = Gdk.Color() 103 #cursor = Gdk.Cursor.new(pixmap, pixmap, color, color, 5, 5) 101 104 #widget.window.set_cursor(cursor) 102 105 103 106 def unrealize_cb(self, widget): … … class BalloonGame(gtk.VBox): 106 109 def stop_cb(self, widget): 107 110 # Stop the animation loop. 108 111 if self.update_timer: 109 gobject.source_remove(self.update_timer)112 GObject.source_remove(self.update_timer) 110 113 111 114 self.activity.pop_screen() 112 115 113 116 def key_cb(self, widget, event): 114 117 # Ignore hotkeys. 115 if event. state & (gtk.gdk.CONTROL_MASK | gtk.gdk.MOD1_MASK):118 if event.get_state() & (Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.MOD1_MASK): 116 119 return False 117 120 118 121 # Extract information about the key pressed. 119 key = gtk.gdk.keyval_to_unicode(event.keyval)122 key = Gdk.keyval_to_unicode(event.keyval) 120 123 if key != 0: key = unichr(key) 121 124 122 125 if self.finished: 123 key_name = gtk.gdk.keyval_name(event.keyval)126 key_name = Gdk.keyval_name(event.keyval) 124 127 if key_name == 'Return': 125 128 self.activity.pop_screen() 126 129 … … class BalloonGame(gtk.VBox): 159 162 160 163 def tick(self): 161 164 if self.finished: 162 return 165 return False 163 166 164 167 self.bounds = self.area.get_allocation() 165 168 … … class BalloonGame(gtk.VBox): 213 216 # Draw text 214 217 title = _('You finished!') + '\n' 215 218 216 pango_cr = pangocairo.CairoContext(cr) 217 pango_cr.set_source_rgb(0, 0, 0) 218 pango_layout = cr.create_layout() 219 pango_layout.set_font_description(pango.FontDescription('Serif Bold 16')) 220 pango_layout.set_text(title) 219 cr.set_source_rgb(0, 0, 0) 220 pango_layout = PangoCairo.create_layout(cr) 221 fd = Pango.FontDescription('Serif Bold') 222 fd.set_size(16 * Pango.SCALE) 223 pango_layout.set_font_description(fd) 224 pango_layout.set_text(title.encode('utf-8'), 225 len(title.encode('utf-8'))) 221 226 size = pango_layout.get_size() 222 tx = x + (w / 2) - (size[0] / pango.SCALE) / 2227 tx = x + (w / 2) - (size[0] / Pango.SCALE) / 2 223 228 ty = y + 100 224 pango_cr.move_to(tx, ty)225 pango_cr.show_layout(pango_layout)226 pango_cr.stroke()229 cr.move_to(tx, ty) 230 PangoCairo.update_layout(cr, pango_layout) 231 PangoCairo.show_layout(cr, pango_layout) 227 232 228 233 report = '' 229 234 report += _('Your score was %(score)d.') % { 'score': self.score } + '\n' … … class BalloonGame(gtk.VBox): 232 237 report += '\n' 233 238 report += _('Press the ENTER key to continue.') 234 239 235 pango_cr = pangocairo.CairoContext(cr) 236 pango_cr.set_source_rgb(0, 0, 0) 237 pango_layout = cr.create_layout() 238 pango_layout.set_font_description(pango.FontDescription('Times 12')) 239 pango_layout.set_text(report) 240 cr.set_source_rgb(0, 0, 0) 241 pango_layout = PangoCairo.create_layout(cr) 242 fd = Pango.FontDescription('Times') 243 fd.set_size(12 * Pango.SCALE) 244 pango_layout.set_font_description(fd) 245 pango_layout.set_text(report, len(report)) 240 246 size = pango_layout.get_size() 241 sx = x + w / 2 - (size[0] / pango.SCALE) / 2247 sx = x + w / 2 - (size[0] / Pango.SCALE) / 2 242 248 sy = y + 200 243 pango_cr.move_to(sx, sy) 244 pango_cr.show_layout(pango_layout) 245 pango_cr.stroke() 246 249 cr.move_to(sx, sy) 250 PangoCairo.update_layout(cr, pango_layout) 251 PangoCairo.show_layout(cr, pango_layout) 247 252 248 253 def finish_game(self): 249 254 self.finished = True … … class BalloonGame(gtk.VBox): 323 328 cr.fill() 324 329 cr.restore() 325 330 326 pango_cr = pangocairo.CairoContext(cr) 327 pango_cr.set_source_rgb(0, 0, 0) 328 pango_layout = cr.create_layout() 329 pango_layout.set_font_description(pango.FontDescription('Sans 12')) 330 pango_layout.set_text(unicode(b.word)) 331 cr.set_source_rgb(0, 0, 0) 332 333 pango_layout = PangoCairo.create_layout(cr) 334 fd = Pango.FontDescription('Sans') 335 fd.set_size(12 * Pango.SCALE) 336 pango_layout.set_font_description(fd) 337 pango_layout.set_text(b.word, len(b.word)) 331 338 size = pango_layout.get_size() 332 x = x - (size[0] / pango.SCALE) / 2333 y = y - (size[1] / pango.SCALE) / 2334 pango_cr.move_to(x, y)335 pango_cr.show_layout(pango_layout)336 pango_cr.stroke()339 x = x - (size[0] / Pango.SCALE) / 2 340 y = y - (size[1] / Pango.SCALE) / 2 341 cr.move_to(x, y) 342 PangoCairo.update_layout(cr, pango_layout) 343 PangoCairo.show_layout(cr, pango_layout) 337 344 338 345 def add_score(self, num): 339 346 self.score += num … … class BalloonGame(gtk.VBox): 341 348 342 349 def queue_draw_score(self): 343 350 layout = self.area.create_pango_layout(_('SCORE: %d') % self.score) 344 layout.set_font_description( pango.FontDescription('Times 14'))351 layout.set_font_description(Pango.FontDescription('Times 14')) 345 352 size = layout.get_size() 346 x = self.bounds.width-20-size[0]/ pango.SCALE353 x = self.bounds.width-20-size[0]/Pango.SCALE 347 354 y = 20 348 355 self.queue_draw_area(x, y, x+size[0], y+size[1]) 349 356 350 357 def draw_score(self, cr): 351 pango_cr = pangocairo.CairoContext(cr) 352 pango_cr.set_source_rgb(0, 0, 0) 353 pango_layout = cr.create_layout() 354 pango_layout.set_font_description(pango.FontDescription('Times 14')) 355 pango_layout.set_text(_('SCORE: %d') % self.score) 358 cr.set_source_rgb(0, 0, 0) 359 pango_layout = PangoCairo.create_layout(cr) 360 fd = Pango.FontDescription('Times') 361 fd.set_size(14 * Pango.SCALE) 362 pango_layout.set_font_description(fd) 363 text = _('SCORE: %d') % self.score 364 pango_layout.set_text(text, len(text)) 365 356 366 size = pango_layout.get_size() 357 x = self.bounds.width - 20 - size[0] / pango.SCALE367 x = self.bounds.width - 20 - size[0] / Pango.SCALE 358 368 y = 20 359 pango_cr.move_to(x, y)360 pango_cr.show_layout(pango_layout)361 pango_cr.stroke()369 cr.move_to(x, y) 370 PangoCairo.update_layout(cr, pango_layout) 371 PangoCairo.show_layout(cr, pango_layout) 362 372 363 373 def draw_instructions(self, cr): 364 374 # Draw instructions. 365 pango_cr = pangocairo.CairoContext(cr)366 pango_ cr.set_source_rgb(0, 0, 0)367 pango_layout = cr.create_layout()368 pango_layout.set_font_description(pango.FontDescription('Times 14'))369 pango_layout.set_text( _('Type the words to pop the balloons!'))375 cr.set_source_rgb(0, 0, 0) 376 pango_layout = PangoCairo.create_layout(cr) 377 pango_layout.set_font_description(Pango.FontDescription('Times 14')) 378 text = _('Type the words to pop the balloons!') 379 pango_layout.set_text(text, len(text)) 370 380 size = pango_layout.get_size() 371 x = (self.bounds.width - size[0] / pango.SCALE) / 2372 y = self.bounds.height - 20 - size[1] / pango.SCALE373 pango_cr.move_to(x, y)374 pango_cr.show_layout(pango_layout)375 pango_cr.stroke()381 x = (self.bounds.width - size[0] / Pango.SCALE) / 2 382 y = self.bounds.height - 20 - size[1] / Pango.SCALE 383 cr.move_to(x, y) 384 PangoCairo.update_layout(cr, pango_layout) 385 PangoCairo.show_layout(cr, pango_layout) 376 386 377 def draw(self ):387 def draw(self, cr): 378 388 self.bounds = self.area.get_allocation() 379 389 380 cr = self.area.window.cairo_create()381 382 390 # Draw background. 383 391 cr.set_source_rgb(0.915, 0.915, 1) 384 392 cr.rectangle(0, 0, self.bounds.width, self.bounds.height) … … class BalloonGame(gtk.VBox): 390 398 391 399 if self.finished: 392 400 self.draw_results(cr) 393 394 401 else: 395 402 self.draw_instructions(cr) 396 403 397 404 self.draw_score(cr) 398 405 399 def expose_cb(self, area, event):400 self.draw( )406 def draw_cb(self, area, cr): 407 self.draw(cr) -
editlessonlistscreen.py
diff --git a/editlessonlistscreen.py b/editlessonlistscreen.py index af67020..6ac2c34 100644
a b from gettext import gettext as _ 22 22 from port import json 23 23 from port import chooser 24 24 25 # Import PyGTK. 26 import gobject, pygtk, gtk, pango 25 from gi.repository import Gtk 26 from gi.repository import GObject 27 27 28 28 # Import Sugar UI modules. 29 import sugar .activity.activity30 import sugar .graphics.style31 import sugar .graphics.alert32 import sugar .mime33 import sugar .datastore.datastore29 import sugar3.activity.activity 30 import sugar3.graphics.style 31 import sugar3.graphics.alert 32 import sugar3.mime 33 import sugar3.datastore.datastore 34 34 35 35 # Import activity modules. 36 36 import editlessonscreen 37 37 38 class EditLessonListScreen( gtk.VBox):38 class EditLessonListScreen(Gtk.VBox): 39 39 def __init__(self, activity, lessons): 40 gtk.VBox.__init__(self)40 GObject.GObject.__init__(self) 41 41 42 42 self.activity = activity 43 43 self.lessons = lessons 44 44 45 45 # Add the header. 46 title = gtk.Label()46 title = Gtk.Label() 47 47 title.set_markup("<span size='20000'><b>" + _("Edit Lessons") + "</b></span>") 48 48 title.set_alignment(1.0, 0.0) 49 49 50 stoplabel = gtk.Label(_('Go Back'))51 stopbtn = gtk.Button()50 stoplabel = Gtk.Label(label=_('Go Back')) 51 stopbtn = Gtk.Button() 52 52 stopbtn.add(stoplabel) 53 53 stopbtn.connect('clicked', self.stop_clicked_cb) 54 54 55 titlebox = gtk.HBox()55 titlebox = Gtk.HBox() 56 56 titlebox.pack_start(stopbtn, False, False, 10) 57 57 titlebox.pack_end(title, False, False, 10) 58 58 59 59 # Add the lesson list. 60 self.treeview = gtk.TreeView()60 self.treeview = Gtk.TreeView() 61 61 self.treeview.set_rules_hint(True) 62 62 self.treeview.set_enable_search(False) 63 63 … … class EditLessonListScreen(gtk.VBox): 66 66 67 67 # Note that the only thing we store in our liststore is the lesson id. 68 68 # All the actual data is in the lessons list. 69 self.liststore = gtk.ListStore(gobject.TYPE_INT)69 self.liststore = Gtk.ListStore(GObject.TYPE_INT) 70 70 self.treeview.set_model(self.liststore) 71 71 72 72 # Construct the columns. 73 renderer = gtk.CellRendererText()74 col = gtk.TreeViewColumn(_('Name'), renderer)73 renderer = Gtk.CellRendererText() 74 col = Gtk.TreeViewColumn(_('Name'), renderer) 75 75 col.set_cell_data_func(renderer, self.name_render_cb) 76 76 self.treeview.append_column(col) 77 77 78 renderer = gtk.CellRendererText()79 col = gtk.TreeViewColumn(_('Description'), renderer)78 renderer = Gtk.CellRendererText() 79 col = Gtk.TreeViewColumn(_('Description'), renderer) 80 80 col.set_cell_data_func(renderer, self.description_render_cb) 81 81 col.set_expand(True) 82 82 self.treeview.append_column(col) 83 83 84 renderer = gtk.CellRendererText()85 col = gtk.TreeViewColumn(_('Type'), renderer)84 renderer = Gtk.CellRendererText() 85 col = Gtk.TreeViewColumn(_('Type'), renderer) 86 86 col.set_cell_data_func(renderer, self.type_render_cb) 87 87 col.set_expand(False) 88 88 self.treeview.append_column(col) 89 89 90 scroll = gtk.ScrolledWindow()91 scroll.set_policy( gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)90 scroll = Gtk.ScrolledWindow() 91 scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) 92 92 scroll.add(self.treeview) 93 93 94 importlabel = gtk.Label(_('Import Lessons from Journal'))95 self.importbtn = gtk.Button()94 importlabel = Gtk.Label(label=_('Import Lessons from Journal')) 95 self.importbtn = Gtk.Button() 96 96 self.importbtn.add(importlabel) 97 97 self.importbtn.connect('clicked', self.import_clicked_cb) 98 98 99 exportlabel = gtk.Label(_('Export Lessons to Journal'))100 self.exportbtn = gtk.Button()99 exportlabel = Gtk.Label(label=_('Export Lessons to Journal')) 100 self.exportbtn = Gtk.Button() 101 101 self.exportbtn.add(exportlabel) 102 102 self.exportbtn.connect('clicked', self.export_clicked_cb) 103 103 104 exportlabel = gtk.Label(_('Save Lessons to Activity'))105 self.defaultsbtn = gtk.Button()104 exportlabel = Gtk.Label(label=_('Save Lessons to Activity')) 105 self.defaultsbtn = Gtk.Button() 106 106 self.defaultsbtn.add(exportlabel) 107 107 self.defaultsbtn.connect('clicked', self.set_default_clicked_cb) 108 108 109 self.addbtn = gtk.Button()110 self.addbtn.add(sugar .graphics.icon.Icon(icon_name='list-add'))109 self.addbtn = Gtk.Button() 110 self.addbtn.add(sugar3.graphics.icon.Icon(icon_name='list-add')) 111 111 self.addbtn.connect('clicked', self.add_lesson_clicked_cb) 112 self.delbtn = gtk.Button()113 self.delbtn.add(sugar .graphics.icon.Icon(icon_name='list-remove'))112 self.delbtn = Gtk.Button() 113 self.delbtn.add(sugar3.graphics.icon.Icon(icon_name='list-remove')) 114 114 self.delbtn.connect('clicked', self.del_lesson_clicked_cb) 115 115 self.delbtn.set_sensitive(False) 116 self.moveupbtn = gtk.Button()117 self.moveupbtn.add(sugar .graphics.icon.Icon(icon_name='go-up'))116 self.moveupbtn = Gtk.Button() 117 self.moveupbtn.add(sugar3.graphics.icon.Icon(icon_name='go-up')) 118 118 self.moveupbtn.connect('clicked', self.move_lesson_up_clicked_cb) 119 119 self.moveupbtn.set_sensitive(False) 120 self.movedownbtn = gtk.Button()121 self.movedownbtn.add(sugar .graphics.icon.Icon(icon_name='go-down'))120 self.movedownbtn = Gtk.Button() 121 self.movedownbtn.add(sugar3.graphics.icon.Icon(icon_name='go-down')) 122 122 self.movedownbtn.connect('clicked', self.move_lesson_down_clicked_cb) 123 123 self.movedownbtn.set_sensitive(False) 124 124 125 btnbox = gtk.HBox()125 btnbox = Gtk.HBox() 126 126 btnbox.pack_start(self.importbtn, False, False, 10) 127 btnbox.pack_start(self.exportbtn, False, False )127 btnbox.pack_start(self.exportbtn, False, False, 0) 128 128 btnbox.pack_start(self.defaultsbtn, False, False, 10) 129 btnbox.pack_end(self.addbtn, False, False )130 btnbox.pack_end(self.delbtn, False, False )131 btnbox.pack_end(self.moveupbtn, False, False )132 btnbox.pack_end(self.movedownbtn, False, False )129 btnbox.pack_end(self.addbtn, False, False, 0) 130 btnbox.pack_end(self.delbtn, False, False, 0) 131 btnbox.pack_end(self.moveupbtn, False, False, 0) 132 btnbox.pack_end(self.movedownbtn, False, False, 0) 133 133 134 134 self.pack_start(titlebox, False, False, 10) 135 self.pack_start( gtk.HSeparator(), False, False, 0)135 self.pack_start(Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL), False, False, 0) 136 136 self.pack_start(scroll, True, True, 10) 137 137 self.pack_start(btnbox, False, False, 10) 138 138 … … class EditLessonListScreen(gtk.VBox): 197 197 if len(self.lessons) > 1: 198 198 path = self.treeview.get_cursor()[0] 199 199 if path: 200 msg = sugar .graphics.alert.ConfirmationAlert()200 msg = sugar3.graphics.alert.ConfirmationAlert() 201 201 msg.props.title = _('Delete Lesson?') 202 202 msg.props.msg = _('Deleting the lesson will erase the lesson content.') 203 203 204 204 def alert_response_cb(alert, response_id, self, id): 205 205 self.activity.remove_alert(alert) 206 if response_id is gtk.RESPONSE_OK:206 if response_id is Gtk.ResponseType.OK: 207 207 self.lessons.pop(id) 208 208 del self.liststore[id] 209 209 self.treeview.get_selection().select_path(id) … … class EditLessonListScreen(gtk.VBox): 294 294 295 295 def export_clicked_cb(self, btn): 296 296 # Create the new journal entry 297 fileObject = sugar .datastore.datastore.create()297 fileObject = sugar3.datastore.datastore.create() 298 298 299 299 meta = self.activity.metadata 300 300 fileObject.metadata['title'] = meta['title'] + _(' (Exported Lessons)') … … class EditLessonListScreen(gtk.VBox): 312 312 finally: 313 313 fd.close() 314 314 315 sugar .datastore.datastore.write(fileObject, transfer_ownership=True)315 sugar3.datastore.datastore.write(fileObject, transfer_ownership=True) 316 316 fileObject.destroy() 317 317 del fileObject 318 318 319 319 def set_default_clicked_cb(self, btn): 320 320 code = locale.getdefaultlocale()[0] or 'en_US' 321 path = sugar .activity.activity.get_bundle_path() + '/lessons/%s.lessons' % code321 path = sugar3.activity.activity.get_bundle_path() + '/lessons/%s.lessons' % code 322 322 323 323 fd = open(path, 'w') 324 324 … … class EditLessonListScreen(gtk.VBox): 328 328 329 329 finally: 330 330 fd.close() 331 332 No newline at end of file 331 -
editlessonscreen.py
diff --git a/editlessonscreen.py b/editlessonscreen.py index 4c7ef0b..e5ce0b4 100644
a b 20 20 import logging, os, math, time, copy, locale, datetime, random, re 21 21 from gettext import gettext as _ 22 22 23 # Import PyGTK. 24 import gobject, pygtk, gtk, pango 23 from gi.repository import Gtk 24 from gi.repository import GObject 25 from gi.repository import Pango 25 26 26 27 # Import Sugar UI modules. 27 import sugar .activity.activity28 import sugar .graphics.style29 import sugar .graphics.icon28 import sugar3.activity.activity 29 import sugar3.graphics.style 30 import sugar3.graphics.icon 30 31 31 32 # Import lessonbuilder functions. 32 33 import lessonbuilder 33 34 34 class EditLessonScreen( gtk.VBox):35 class EditLessonScreen(Gtk.VBox): 35 36 def __init__(self, activity, lesson): 36 gtk.VBox.__init__(self)37 GObject.GObject.__init__(self) 37 38 self.set_border_width(10) 38 39 39 40 self.activity = activity … … class EditLessonScreen(gtk.VBox): 42 43 self.in_build = False 43 44 44 45 # Add the header. 45 title = gtk.Label()46 title = Gtk.Label() 46 47 title.set_markup("<span size='20000'><b>" + _("Edit a Lesson") + "</b></span>") 47 48 title.set_alignment(1.0, 0.0) 48 49 49 stoplabel = gtk.Label(_('Go Back'))50 stopbtn = gtk.Button()50 stoplabel = Gtk.Label(label=_('Go Back')) 51 stopbtn = Gtk.Button() 51 52 stopbtn.add(stoplabel) 52 53 stopbtn.connect('clicked', self.stop_clicked_cb) 53 54 54 titlebox = gtk.HBox()55 titlebox = Gtk.HBox() 55 56 titlebox.pack_start(stopbtn, False, False, 10) 56 57 titlebox.pack_end(title, False, False, 10) 57 58 58 self.vp = gtk.Viewport()59 self.vp = Gtk.Viewport() 59 60 60 self.scroll = gtk.ScrolledWindow()61 self.scroll.set_policy( gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)61 self.scroll = Gtk.ScrolledWindow() 62 self.scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) 62 63 self.scroll.add(self.vp) 63 64 64 65 self.pack_start(titlebox, False, False, 10) 65 self.pack_start( gtk.HSeparator(), False, False, 0)66 self.pack_start(Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL), False, False, 0) 66 67 self.pack_start(self.scroll, True, True, 0) 67 68 68 69 self.build() … … class EditLessonScreen(gtk.VBox): 70 71 self.show_all() 71 72 72 73 def build_generate(self): 73 generatebox = gtk.VBox()74 generatebox = Gtk.VBox() 74 75 generatebox.set_spacing(5) 75 76 76 newlabel = gtk.Label(_('New keys'))77 knownlabel = gtk.Label(_('Known keys'))78 lengthlabel = gtk.Label(_('Length'))77 newlabel = Gtk.Label(label=_('New keys')) 78 knownlabel = Gtk.Label(label=_('Known keys')) 79 lengthlabel = Gtk.Label(label=_('Length')) 79 80 80 generatebox.newkeysent = gtk.Entry()81 generatebox.newkeysent = Gtk.Entry() 81 82 generatebox.newkeysent.set_width_chars(8) 82 generatebox.knownkeysent = gtk.Entry()83 generatebox.knownkeysent = Gtk.Entry() 83 84 generatebox.knownkeysent.set_width_chars(15) 84 generatebox.lengthent = gtk.Entry()85 generatebox.lengthent = Gtk.Entry() 85 86 generatebox.lengthent.set_width_chars(5) 86 87 generatebox.lengthent.set_text('60') 87 88 88 oklabel = gtk.Label()89 oklabel = Gtk.Label() 89 90 oklabel.set_markup(_('Generate!')) 90 okbtn = gtk.Button()91 okbtn = Gtk.Button() 91 92 okbtn.add(oklabel) 92 93 okbtn.connect('clicked', self.generate_ok_clicked_cb, generatebox) 93 94 okbtn.set_alignment(0.5, 0.5) 94 95 95 box = gtk.HBox()96 box = Gtk.HBox() 96 97 box.set_spacing(10) 97 box.pack_start(newlabel, expand=False)98 box.pack_start(generatebox.newkeysent, expand=False)99 box.pack_start(knownlabel, expand=False)100 box.pack_start(generatebox.knownkeysent, expand=False)101 box.pack_start(lengthlabel, expand=False)102 box.pack_start(generatebox.lengthent, expand=False)103 box.pack_end(okbtn, expand=False)98 box.pack_start(newlabel, False, True, 0) 99 box.pack_start(generatebox.newkeysent, False, True, 0) 100 box.pack_start(knownlabel, False, True, 0) 101 box.pack_start(generatebox.knownkeysent, False, True, 0) 102 box.pack_start(lengthlabel, False, True, 0) 103 box.pack_start(generatebox.lengthent, False, True, 0) 104 box.pack_end(okbtn, False, True, 0) 104 105 box.show_all() 105 106 106 wordslabel = gtk.Label()107 wordslabel = Gtk.Label() 107 108 wordslabel.set_markup(_('Edit Word List')) 108 wordsbtn = gtk.Button()109 wordsbtn = Gtk.Button() 109 110 wordsbtn.add(wordslabel) 110 111 wordsbtn.connect('clicked', self.generate_words_clicked_cb) 111 112 wordsbtn.set_alignment(0.5, 0.5) 112 113 113 generatebox.pack_start(box )114 generatebox.pack_start(wordsbtn, expand=False, fill=False )114 generatebox.pack_start(box, True, True, 0) 115 generatebox.pack_start(wordsbtn, expand=False, fill=False, padding=0) 115 116 116 117 return generatebox 117 118 118 119 def build_step(self, step, idx): 119 stepbox = gtk.VBox()120 stepbox = Gtk.VBox() 120 121 stepbox.set_spacing(5) 121 122 122 steplabel = gtk.Label()123 steplabel = Gtk.Label() 123 124 steplabel.set_markup("<span size='x-large' weight='bold'>" + (_('Step #%d') % (idx+1)) + "</span>") 124 125 steplabel.set_alignment(0.0, 0.5) 125 126 steplabel.set_padding(10, 0) 126 127 127 128 # Build the step type combo box. 128 stepbox.typecombo = gtk.combo_box_new_text()129 stepbox.typecombo = Gtk.ComboBoxText() 129 130 stepbox.typecombo.append_text(_('Keys')) 130 131 stepbox.typecombo.append_text(_('Words')) 131 132 … … class EditLessonScreen(gtk.VBox): 136 137 stepbox.typecombo.set_active(1) 137 138 138 139 # Build the tool buttons. 139 delstepbtn = gtk.Button()140 delstepbtn.add(sugar .graphics.icon.Icon(icon_name='list-remove'))140 delstepbtn = Gtk.Button() 141 delstepbtn.add(sugar3.graphics.icon.Icon(icon_name='list-remove')) 141 142 delstepbtn.connect('clicked', self.del_step_clicked_cb, idx) 142 addstepbtn = gtk.Button()143 addstepbtn.add(sugar .graphics.icon.Icon(icon_name='list-add'))143 addstepbtn = Gtk.Button() 144 addstepbtn.add(sugar3.graphics.icon.Icon(icon_name='list-add')) 144 145 addstepbtn.connect('clicked', self.add_step_clicked_cb, idx) 145 moveupbtn = gtk.Button()146 moveupbtn.add(sugar .graphics.icon.Icon(icon_name='go-up'))146 moveupbtn = Gtk.Button() 147 moveupbtn.add(sugar3.graphics.icon.Icon(icon_name='go-up')) 147 148 moveupbtn.connect('clicked', self.move_step_up_clicked_cb, idx) 148 movedownbtn = gtk.Button()149 movedownbtn.add(sugar .graphics.icon.Icon(icon_name='go-down'))149 movedownbtn = Gtk.Button() 150 movedownbtn.add(sugar3.graphics.icon.Icon(icon_name='go-down')) 150 151 movedownbtn.connect('clicked', self.move_step_down_clicked_cb, idx) 151 152 152 153 if idx == 0: … … class EditLessonScreen(gtk.VBox): 154 155 if idx == len(self.lesson['steps']) - 1: 155 156 movedownbtn.set_sensitive(False) 156 157 157 btnbox = gtk.HBox()158 btnbox.pack_start(steplabel, False, False )158 btnbox = Gtk.HBox() 159 btnbox.pack_start(steplabel, False, False, 0) 159 160 btnbox.pack_start(stepbox.typecombo, expand=False, padding=10) 160 btnbox.pack_end(addstepbtn, False, False )161 btnbox.pack_end(delstepbtn, False, False )162 btnbox.pack_end(moveupbtn, False, False )163 btnbox.pack_end(movedownbtn, False, False )161 btnbox.pack_end(addstepbtn, False, False, 0) 162 btnbox.pack_end(delstepbtn, False, False, 0) 163 btnbox.pack_end(moveupbtn, False, False, 0) 164 btnbox.pack_end(movedownbtn, False, False, 0) 164 165 165 166 # Build the instructions entry. 166 instlabel = gtk.Label()167 instlabel = Gtk.Label() 167 168 instlabel.set_markup("<span size='large' weight='bold'>" + _('Instructions') + "</span>") 168 169 instlabel.set_alignment(0.0, 0.5) 169 170 instlabel.set_padding(20, 0) 170 171 171 172 self.labelsizegroup.add_widget(instlabel) 172 173 173 stepbox.insttext = gtk.TextView(gtk.TextBuffer())174 stepbox.insttext.props.wrap_mode = gtk.WRAP_WORD175 stepbox.insttext.modify_font( pango.FontDescription('Monospace'))176 instscroll = gtk.ScrolledWindow()177 instscroll.set_policy( gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)174 stepbox.insttext = Gtk.TextView(Gtk.TextBuffer()) 175 stepbox.insttext.props.wrap_mode = Gtk.WrapMode.WORD 176 stepbox.insttext.modify_font(Pango.FontDescription('Monospace')) 177 instscroll = Gtk.ScrolledWindow() 178 instscroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) 178 179 instscroll.add(stepbox.insttext) 179 180 instscroll.set_size_request(-1, 75) 180 181 stepbox.insttext.get_buffer().set_text(step['instructions']) 181 182 182 instbox = gtk.HBox()183 instbox.pack_start(instlabel, False, False )184 instbox.pack_start(instscroll, True, True )183 instbox = Gtk.HBox() 184 instbox.pack_start(instlabel, False, False, 0) 185 instbox.pack_start(instscroll, True, True, 0) 185 186 186 187 # Build the text entry. 187 textlabel = gtk.Label()188 textlabel = Gtk.Label() 188 189 textlabel.set_markup("<span size='large' weight='bold'>" + _('Text') + "</span>") 189 190 textlabel.set_alignment(0.0, 0.5) 190 191 textlabel.set_padding(20, 0) 191 192 192 193 self.labelsizegroup.add_widget(textlabel) 193 194 194 stepbox.texttext = gtk.TextView(gtk.TextBuffer())195 stepbox.texttext.props.wrap_mode = gtk.WRAP_WORD196 stepbox.texttext.modify_font( pango.FontDescription('monospace'))197 textscroll = gtk.ScrolledWindow()198 textscroll.set_policy( gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)195 stepbox.texttext = Gtk.TextView(Gtk.TextBuffer()) 196 stepbox.texttext.props.wrap_mode = Gtk.WrapMode.WORD 197 stepbox.texttext.modify_font(Pango.FontDescription('monospace')) 198 textscroll = Gtk.ScrolledWindow() 199 textscroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) 199 200 textscroll.add(stepbox.texttext) 200 201 textscroll.set_size_request(-1, 100) 201 202 stepbox.texttext.get_buffer().set_text(step['text']) 202 203 203 textbox = gtk.HBox()204 textbox.pack_start(textlabel, expand=False)205 textbox.pack_start(textscroll )204 textbox = Gtk.HBox() 205 textbox.pack_start(textlabel, False, True, 0) 206 textbox.pack_start(textscroll, True, True, 0) 206 207 207 sizegroup = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)208 sizegroup = Gtk.SizeGroup(Gtk.SizeGroupMode.HORIZONTAL) 208 209 sizegroup.add_widget(instlabel) 209 210 sizegroup.add_widget(textlabel) 210 211 211 stepbox.pack_start(btnbox, expand=False)212 stepbox.pack_start(instbox, expand=False)213 stepbox.pack_start(textbox, expand=False)212 stepbox.pack_start(btnbox, False, True, 0) 213 stepbox.pack_start(instbox, False, True, 0) 214 stepbox.pack_start(textbox, False, True, 0) 214 215 215 216 return stepbox 216 217 217 218 def build_medal(self, medal, name): 218 box = gtk.HBox()219 box = Gtk.HBox() 219 220 220 label = gtk.Label()221 label = Gtk.Label() 221 222 label.set_markup("<span size='large' weight='bold'>" + name + "</span>") 222 223 label.set_alignment(0.0, 0.5) 223 224 label.set_padding(20, 0) 224 225 225 226 self.labelsizegroup.add_widget(label) 226 227 227 box.pack_start(label, False, False )228 box.pack_start(label, False, False, 0) 228 229 229 230 if self.lesson['type'] == 'normal': 230 acclabel = gtk.Label(_('Accuracy'))231 wpmlabel = gtk.Label(_('WPM'))231 acclabel = Gtk.Label(label=_('Accuracy')) 232 wpmlabel = Gtk.Label(label=_('WPM')) 232 233 233 box.accent = gtk.Entry()234 box.wpment = gtk.Entry()234 box.accent = Gtk.Entry() 235 box.wpment = Gtk.Entry() 235 236 236 237 box.accent.set_text(str(medal['accuracy'])) 237 238 box.wpment.set_text(str(medal['wpm'])) 238 239 239 240 box.pack_start(acclabel, False, False, 10) 240 box.pack_start(box.accent, False, False )241 box.pack_start(box.accent, False, False, 0) 241 242 box.pack_start(wpmlabel, False, False, 10) 242 box.pack_start(box.wpment, False, False )243 box.pack_start(box.wpment, False, False, 0) 243 244 244 245 elif self.lesson['type'] == 'balloon': 245 scorelabel = gtk.Label(_('Score'))246 scorelabel = Gtk.Label(label=_('Score')) 246 247 247 box.scoreent = gtk.Entry()248 box.scoreent = Gtk.Entry() 248 249 box.scoreent.set_text(str(medal['score'])) 249 250 250 251 box.pack_start(scorelabel, False, False, 10) 251 box.pack_start(box.scoreent, False, False )252 box.pack_start(box.scoreent, False, False, 0) 252 253 253 254 return box 254 255 255 256 def build(self): 256 257 self.in_build = True 257 258 258 self.vbox = gtk.VBox()259 self.vbox = Gtk.VBox() 259 260 self.vbox.set_border_width(20) 260 261 self.vbox.set_spacing(5) 261 262 262 self.labelsizegroup = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)263 self.labelsizegroup = Gtk.SizeGroup(Gtk.SizeGroupMode.HORIZONTAL) 263 264 264 265 # Lesson details widgets. 265 detailslabel = gtk.Label()266 detailslabel = Gtk.Label() 266 267 detailslabel.set_markup("<span size='x-large'><b>" + _('Lesson Details') + "</b></span>") 267 268 detailslabel.set_alignment(0.0, 0.5) 268 269 detailslabel.set_padding(10, 0) 269 270 270 namelabel = gtk.Label()271 namelabel = Gtk.Label() 271 272 namelabel.set_markup("<span size='large' weight='bold'>" + _('Name') + "</span>") 272 273 namelabel.set_alignment(0.0, 0.5) 273 274 namelabel.set_padding(20, 0) 274 275 275 self.nameent = gtk.Entry()276 self.nameent = Gtk.Entry() 276 277 self.nameent.set_text(self.lesson['name']) 277 278 278 namebox = gtk.HBox()279 namebox.pack_start(namelabel, expand=False)280 namebox.pack_start(self.nameent )279 namebox = Gtk.HBox() 280 namebox.pack_start(namelabel, False, True, 0) 281 namebox.pack_start(self.nameent, True, True, 0) 281 282 282 typelabel = gtk.Label()283 typelabel = Gtk.Label() 283 284 typelabel.set_markup("<span size='large' weight='bold'>" + _('Type') + "</span>") 284 285 typelabel.set_alignment(0.0, 0.5) 285 286 typelabel.set_padding(20, 0) 286 287 287 self.textradio = gtk.RadioButton(None, _('Normal Lesson'))288 self.textradio = Gtk.RadioButton(None, _('Normal Lesson')) 288 289 self.textradio.connect('toggled', self.type_toggled_cb) 289 290 290 self.balloonradio = gtk.RadioButton(self.textradio, _('Balloon Game'))291 self.balloonradio = Gtk.RadioButton(self.textradio, _('Balloon Game')) 291 292 self.balloonradio.connect('toggled', self.type_toggled_cb) 292 293 293 294 self.textradio.set_active(self.lesson['type'] == 'normal') 294 295 self.balloonradio.set_active(self.lesson['type'] == 'balloon') 295 296 296 typebox = gtk.HBox()297 typebox.pack_start(typelabel, expand=False)298 typebox.pack_start(self.textradio, expand=False)299 typebox.pack_start(self.balloonradio, expand=False)297 typebox = Gtk.HBox() 298 typebox.pack_start(typelabel, False, True, 0) 299 typebox.pack_start(self.textradio, False, True, 0) 300 typebox.pack_start(self.balloonradio, False, True, 0) 300 301 301 desclabel = gtk.Label()302 desclabel = Gtk.Label() 302 303 desclabel.set_markup("<span size='large' weight='bold'>" + _('Description') + "</span>") 303 304 desclabel.set_alignment(0.0, 0.5) 304 305 desclabel.set_padding(20, 0) 305 306 306 self.desctext = gtk.TextView(gtk.TextBuffer())307 self.desctext.props.wrap_mode = gtk.WRAP_WORD308 descscroll = gtk.ScrolledWindow()309 descscroll.set_policy( gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)307 self.desctext = Gtk.TextView(Gtk.TextBuffer()) 308 self.desctext.props.wrap_mode = Gtk.WrapMode.WORD 309 descscroll = Gtk.ScrolledWindow() 310 descscroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) 310 311 descscroll.add(self.desctext) 311 312 descscroll.set_size_request(-1, 75) 312 313 self.desctext.get_buffer().set_text(self.lesson['description']) 313 314 314 descbox = gtk.HBox()315 descbox.pack_start(desclabel, expand=False)316 descbox.pack_start(descscroll )315 descbox = Gtk.HBox() 316 descbox.pack_start(desclabel, False, True, 0) 317 descbox.pack_start(descscroll, True, True, 0) 317 318 318 319 # Build the options. 319 optslabel = gtk.Label()320 optslabel = Gtk.Label() 320 321 optslabel.set_markup("<span size='large' weight='bold'>" + _('Options') + "</span>") 321 322 optslabel.set_alignment(0.0, 0.5) 322 323 optslabel.set_padding(20, 0) 323 324 324 self.mistakescheck = gtk.CheckButton(_('Allow Mistakes'))325 self.mistakescheck = Gtk.CheckButton(_('Allow Mistakes')) 325 326 self.mistakescheck.set_active(self.lesson.get('options', {}).get('mistakes', True)) 326 self.backspacecheck = gtk.CheckButton(_('Allow Backspace'))327 self.backspacecheck = Gtk.CheckButton(_('Allow Backspace')) 327 328 self.backspacecheck.set_active(self.lesson.get('options', {}).get('backspace', True)) 328 329 329 optsbox = gtk.HBox()330 optsbox.pack_start(optslabel, expand=False)331 optsbox.pack_start(self.backspacecheck, expand=False)332 optsbox.pack_start(self.mistakescheck, expand=False)330 optsbox = Gtk.HBox() 331 optsbox.pack_start(optslabel, False, True, 0) 332 optsbox.pack_start(self.backspacecheck, False, True, 0) 333 optsbox.pack_start(self.mistakescheck, False, True, 0) 333 334 334 335 self.labelsizegroup.add_widget(namelabel) 335 336 self.labelsizegroup.add_widget(typelabel) 336 337 self.labelsizegroup.add_widget(desclabel) 337 338 self.labelsizegroup.add_widget(optslabel) 338 339 339 self.vbox.pack_start(detailslabel, expand=False)340 self.vbox.pack_start(namebox, expand=False)341 self.vbox.pack_start(typebox, expand=False)342 self.vbox.pack_start(descbox, expand=False)343 self.vbox.pack_start(optsbox, expand=False)340 self.vbox.pack_start(detailslabel, False, True, 0) 341 self.vbox.pack_start(namebox, False, True, 0) 342 self.vbox.pack_start(typebox, False, True, 0) 343 self.vbox.pack_start(descbox, False, True, 0) 344 self.vbox.pack_start(optsbox, False, True, 0) 344 345 345 346 # Build the generator. 346 generatelabel = gtk.Label()347 generatelabel = Gtk.Label() 347 348 generatelabel.set_markup("<span size='x-large'><b>" + _('Automatic Lesson Generator') + "</b></span>") 348 349 generatelabel.set_alignment(0.0, 0.5) 349 350 generatelabel.set_padding(10, 0) 350 351 351 352 generatebox = self.build_generate() 352 353 self.vbox.pack_start(generatelabel, expand=False, padding=10) 353 self.vbox.pack_start(generatebox, expand=False)354 self.vbox.pack_start(generatebox, False, True, 0) 354 355 355 356 self.has_normal_widgets = False 356 357 self.has_balloon_widgets = False … … class EditLessonScreen(gtk.VBox): 369 370 stepbox = self.build_step(step, len(self.stepboxes)) 370 371 self.stepboxes.append(stepbox) 371 372 372 self.vbox.pack_start(stepbox, expand=False)373 self.vbox.pack_start(stepbox, False, True, 0) 373 374 374 375 if self.lesson['type'] == 'balloon': 375 376 self.has_balloon_widgets = True … … class EditLessonScreen(gtk.VBox): 377 378 if not self.lesson.has_key('words') or len(self.lesson['words']) == 0: 378 379 self.lesson['words'] = [] 379 380 380 textlabel = gtk.Label()381 textlabel = Gtk.Label() 381 382 textlabel.set_markup("<span size='large' weight='bold'>" + _('Words') + "</span>") 382 383 textlabel.set_alignment(0.0, 0.5) 383 384 textlabel.set_padding(20, 0) 384 385 385 386 self.labelsizegroup.add_widget(textlabel) 386 387 387 self.wordstext = gtk.TextView(gtk.TextBuffer())388 self.wordstext.props.wrap_mode = gtk.WRAP_WORD389 self.wordstext.modify_font( pango.FontDescription('Monospace'))390 textscroll = gtk.ScrolledWindow()391 textscroll.set_policy( gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)388 self.wordstext = Gtk.TextView(Gtk.TextBuffer()) 389 self.wordstext.props.wrap_mode = Gtk.WrapMode.WORD 390 self.wordstext.modify_font(Pango.FontDescription('Monospace')) 391 textscroll = Gtk.ScrolledWindow() 392 textscroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) 392 393 textscroll.add(self.wordstext) 393 394 textscroll.set_size_request(-1, 200) 394 395 self.wordstext.get_buffer().set_text(' '.join(self.lesson['words'])) 395 396 396 textbox = gtk.HBox()397 textbox.pack_start(textlabel, expand=False)398 textbox.pack_start(textscroll )397 textbox = Gtk.HBox() 398 textbox.pack_start(textlabel, False, True, 0) 399 textbox.pack_start(textscroll, True, True, 0) 399 400 400 self.vbox.pack_start(textbox, expand=False)401 self.vbox.pack_start(textbox, False, True, 0) 401 402 402 403 # Medal requirements widgets. 403 medalslabel = gtk.Label()404 medalslabel = Gtk.Label() 404 405 medalslabel.set_markup("<span size='x-large'><b>" + _('Medal Requirements') + "</b></span>") 405 406 medalslabel.set_alignment(0.0, 0.5) 406 407 medalslabel.set_padding(10, 0) … … class EditLessonScreen(gtk.VBox): 412 413 self.medalboxes.append(self.build_medal(self.lesson['medals'][1], _('Silver'))) 413 414 self.medalboxes.append(self.build_medal(self.lesson['medals'][2], _('Gold'))) 414 415 415 self.vbox.pack_start(self.medalboxes[0], expand=False)416 self.vbox.pack_start(self.medalboxes[1], expand=False)417 self.vbox.pack_start(self.medalboxes[2], expand=False)416 self.vbox.pack_start(self.medalboxes[0], False, True, 0) 417 self.vbox.pack_start(self.medalboxes[1], False, True, 0) 418 self.vbox.pack_start(self.medalboxes[2], False, True, 0) 418 419 419 420 self.vbox.show_all() 420 421 … … class EditLessonScreen(gtk.VBox): 555 556 def generate_words_clicked_cb(self, btn): 556 557 self.activity.push_screen(WordListScreen(self.activity)) 557 558 558 class WordListScreen( gtk.VBox):559 class WordListScreen(Gtk.VBox): 559 560 def __init__(self, activity): 560 gtk.VBox.__init__(self)561 GObject.GObject.__init__(self) 561 562 self.set_border_width(10) 562 563 563 564 self.activity = activity 564 565 565 566 # Add the header. 566 title = gtk.Label()567 title = Gtk.Label() 567 568 title.set_markup("<span size='20000'><b>" + _("Edit Word List") + "</b></span>") 568 569 title.set_alignment(1.0, 0.0) 569 570 570 stoplabel = gtk.Label(_('Go Back'))571 stopbtn = gtk.Button()571 stoplabel = Gtk.Label(label=_('Go Back')) 572 stopbtn = Gtk.Button() 572 573 stopbtn.add(stoplabel) 573 574 stopbtn.connect('clicked', self.stop_clicked_cb) 574 575 575 titlebox = gtk.HBox()576 titlebox = Gtk.HBox() 576 577 titlebox.pack_start(stopbtn, False, False, 10) 577 578 titlebox.pack_end(title, False, False, 10) 578 579 579 subtitle = gtk.Label()580 subtitle = Gtk.Label() 580 581 subtitle.set_markup("<span size='10000'>" + _("Type or paste words here, for the Automatic Lesson Generator. If empty, the dictionary will be used.") + "</span>") 581 582 subtitle.set_alignment(1.0, 0.0) 582 583 583 self.wordlisttext = gtk.TextView(gtk.TextBuffer())584 self.wordlisttext.props.wrap_mode = gtk.WRAP_WORD585 wordlistscroll = gtk.ScrolledWindow()586 wordlistscroll.set_policy( gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)584 self.wordlisttext = Gtk.TextView(Gtk.TextBuffer()) 585 self.wordlisttext.props.wrap_mode = Gtk.WrapMode.WORD 586 wordlistscroll = Gtk.ScrolledWindow() 587 wordlistscroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) 587 588 wordlistscroll.add(self.wordlisttext) 588 589 wordlistscroll.set_size_request(-1, 75) 589 590 self.wordlisttext.get_buffer().set_text(' '.join(self.activity.wordlist)) 590 591 591 self.pack_start(titlebox, expand=False)592 self.pack_start(subtitle, expand=False)593 self.pack_start( gtk.HSeparator(), expand=False)594 self.pack_start(wordlistscroll )592 self.pack_start(titlebox, False, True, 0) 593 self.pack_start(subtitle, False, True, 0) 594 self.pack_start(Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL), expand=False, padding=0) 595 self.pack_start(wordlistscroll, True, True, 0) 595 596 596 597 self.show_all() 597 598 -
keyboard.py
diff --git a/keyboard.py b/keyboard.py index 25e870e..90cbf98 100644
a b 16 16 #!/usr/bin/env python 17 17 # vi:sw=4 et 18 18 19 import gtk20 19 import cairo 21 20 import copy 22 import rsvg23 21 import os, glob, re 24 import pango 25 import pangocairo 22 23 from gi.repository import Gtk 24 from gi.repository import Pango 25 from gi.repository import PangoCairo 26 from gi.repository import Gdk 27 from gi.repository import GObject 28 from gi.repository import GdkPixbuf 29 26 30 import StringIO 27 31 from port import json 28 32 import subprocess … … class KeyboardImages: 132 136 scale_width = int(scale_width * 1.1625) 133 137 134 138 for filename in glob.iglob('images/OLPC*.svg'): 135 image = rsvg.Handle(file=filename) 139 image = GdkPixbuf.Pixbuf.new_from_file_at_scale( 140 filename, scale_width, self.height, False) 136 141 name = os.path.basename(filename) 137 142 self.images[name] = image 138 143 … … class KeyboardData: 145 150 self.letter_map = {} 146 151 147 152 # Access the current GTK keymap. 148 self.keymap = gtk.gdk.keymap_get_default()153 self.keymap = Gdk.Keymap.get_default() 149 154 150 155 def set_layout(self, layout): 151 156 self._build_key_list(layout) … … class KeyboardData: 235 240 236 241 def format_key_sig(self, scan, state, group): 237 242 sig = 'scan%d' % scan 238 if state & gtk.gdk.SHIFT_MASK:243 if state & Gdk.ModifierType.SHIFT_MASK: 239 244 sig += ' shift' 240 if state & gtk.gdk.MOD5_MASK:245 if state & Gdk.ModifierType.MOD5_MASK: 241 246 sig += ' altgr' 242 247 if group != 0: 243 248 sig += ' group%d' % group … … class KeyboardData: 250 255 251 256 state = 0 252 257 if m.group('shift'): 253 state |= gtk.gdk.SHIFT_MASK258 state |= Gdk.ModifierType.SHIFT_MASK 254 259 if m.group('altgr'): 255 state |= gtk.gdk.MOD5_MASK260 state |= Gdk.ModifierType.MOD5_MASK 256 261 257 262 scan = int(m.group('scan')) 258 263 … … class KeyboardData: 278 283 best_result = None 279 284 280 285 for sig, l in self.letter_map.items(): 281 if unicode(l) == unicode(letter):286 if l == letter: 282 287 scan, state, group = self.parse_key_sig(sig) 283 288 284 289 # Choose the key with the fewest modifiers. 285 290 score = 0 286 if state & gtk.gdk.SHIFT_MASK: score += 1287 if state & gtk.gdk.MOD5_MASK: score += 1291 if state & Gdk.ModifierType.SHIFT_MASK: score += 1 292 if state & Gdk.ModifierType.MOD5_MASK: score += 1 288 293 if score < best_score: 289 294 best_score = score 290 295 best_result = scan, state, group … … class KeyboardData: 295 300 return k, best_result[1], best_result[2] 296 301 297 302 # Try the GDK keymap. 298 keyval = gtk.gdk.unicode_to_keyval(ord(letter))299 entries = self.keymap.get_entries_for_keyval(keyval)303 keyval = Gdk.unicode_to_keyval(ord(letter)) 304 valid, entries = self.keymap.get_entries_for_keyval(keyval) 300 305 for e in entries: 301 306 for k in self.keys: 302 if k['key-scan'] == e [0]:307 if k['key-scan'] == e.keycode: 303 308 # TODO: Level -> state calculations are hardcoded to what the XO keyboard does. 304 309 # They were discovered through experimentation. 305 310 state = 0 306 if e [2] & 1:307 state |= gtk.gdk.SHIFT_MASK308 if e [2] & 2:309 state |= gtk.gdk.MOD5_MASK310 return k, state, e [1]311 if e.level & 1: 312 state |= Gdk.ModifierType.SHIFT_MASK 313 if e.level & 2: 314 state |= Gdk.ModifierType.MOD5_MASK 315 return k, state, e.group 311 316 312 317 # Fail! 313 318 return None, None, None … … class KeyboardData: 317 322 if self.letter_map.has_key(sig): 318 323 return self.letter_map[sig] 319 324 else: 320 t = self.keymap.translate_keyboard_state(key['key-scan'], self.active_state, self.active_group) 321 if t: 322 return unichr(gtk.gdk.keyval_to_unicode(t[0])) 325 success, keyval, effective_group, level, consumed_modifiers = \ 326 self.keymap.translate_keyboard_state( 327 key['key-scan'], self.active_state, self.active_group) 328 if success: 329 return unichr(Gdk.keyval_to_unicode(keyval)).encode('utf-8') 323 330 324 331 return '' 325 332 326 class KeyboardWidget(KeyboardData, gtk.DrawingArea):333 class KeyboardWidget(KeyboardData, Gtk.DrawingArea): 327 334 """A GTK widget which implements an interactive visual keyboard, with support 328 335 for custom data driven layouts.""" 329 336 330 337 def __init__(self, image, root_window, poll_keys=False): 331 338 KeyboardData.__init__(self) 332 gtk.DrawingArea.__init__(self)339 GObject.GObject.__init__(self) 333 340 334 341 self.image = image 335 342 self.root_window = root_window … … class KeyboardWidget(KeyboardData, gtk.DrawingArea): 337 344 # Match the image cache in dimensions. 338 345 self.set_size_request(image.width, image.height) 339 346 340 self.connect(" expose-event", self._expose_cb)347 self.connect("draw", self._draw_cb) 341 348 342 #self.modify_font( pango.FontDescription('Monospace 10'))349 #self.modify_font(Pango.FontDescription('Monospace 10')) 343 350 344 351 # Active language group and modifier state. 345 352 # See http://www.pygtk.org/docs/pygtk/class-gdkkeymap.html for more … … class KeyboardWidget(KeyboardData, gtk.DrawingArea): 354 361 355 362 self.draw_hands = False 356 363 357 self.modify_bg( gtk.STATE_NORMAL, self.get_colormap().alloc_color('#d0d0d0'))364 self.modify_bg(Gtk.StateType.NORMAL, Gdk.Color.parse('#d0d0d0')[1]) 358 365 359 366 # Connect keyboard grabbing and releasing callbacks. 360 367 if poll_keys: … … class KeyboardWidget(KeyboardData, gtk.DrawingArea): 363 370 364 371 def _realize_cb(self, widget): 365 372 # Setup keyboard event snooping in the root window. 366 self.root_window.add_events( gtk.gdk.KEY_PRESS_MASK | gtk.gdk.KEY_RELEASE_MASK)373 self.root_window.add_events(Gdk.EventMask.KEY_PRESS_MASK | Gdk.EventMask.KEY_RELEASE_MASK) 367 374 self.key_press_cb_id = self.root_window.connect('key-press-event', self.key_press_release_cb) 368 375 self.key_release_cb_id = self.root_window.connect('key-release-event', self.key_press_release_cb) 369 376 … … class KeyboardWidget(KeyboardData, gtk.DrawingArea): 412 419 (x1 + corner, y2), 413 420 (x1, y2 - corner), 414 421 (x1, y1 + corner) 415 422 ] 416 423 417 cr.save()418 424 cr.new_path() 419 425 cr.set_source_rgb(0.396, 0.698, 0.392) 420 426 cr.set_line_width(2) 421 cr.move_to(*points[0])422 427 for point in points: 423 428 cr.line_to(*point) 424 cr.line_to(*points[0])425 429 cr.close_path() 426 430 cr.fill_preserve() 427 431 cr.stroke() 428 cr.restore()429 432 430 433 text = '' 431 434 if k['key-label']: … … class KeyboardWidget(KeyboardData, gtk.DrawingArea): 434 437 text = self.get_letter_for_key_state_group( 435 438 k, self.active_state, self.active_group) 436 439 437 pango_context = pangocairo.CairoContext(cr) 438 pango_context.set_source_rgb(0, 0, 0) 440 cr.set_source_rgb(0, 0, 0) 441 pango_layout = PangoCairo.create_layout(cr) 442 fd = Pango.FontDescription('Monospace') 443 fd.set_size(10 * Pango.SCALE) 444 pango_layout.set_font_description(fd) 445 pango_layout.set_text(text, len(text)) 439 446 440 pango_layout = pango_context.create_layout() 441 pango_layout.set_font_description(pango.FontDescription('Monospace')) 442 pango_layout.set_text(unicode(text)) 443 444 pango_context.move_to(x1 + 8, y2 - 23) 445 pango_context.show_layout(pango_layout) 446 cr.stroke() 447 cr.move_to(x1 + 8, y2 - 23) 448 PangoCairo.update_layout(cr, pango_layout) 449 PangoCairo.show_layout(cr, pango_layout) 447 450 448 451 def _expose_hands(self, cr): 449 452 lhand_image = self.image.images['OLPC_Lhand_HOMEROW.svg'] … … class KeyboardWidget(KeyboardData, gtk.DrawingArea): 463 466 rhand_image = handle 464 467 465 468 # Put the other hand on the SHIFT key if needed. 466 if state & gtk.gdk.SHIFT_MASK:469 if state & Gdk.ModifierType.SHIFT_MASK: 467 470 if finger[0] == 'L': 468 471 rhand_image = self.image.images['OLPC_Rhand_SHIFT.svg'] 469 472 else: … … class KeyboardWidget(KeyboardData, gtk.DrawingArea): 471 474 472 475 # TODO: Do something about ALTGR. 473 476 474 # bounds = self.get_allocation() 475 # screen_x = int(bounds.width-self.image.width)/2 476 # screen_y = int(bounds.height-self.image.height)/2 477 bounds = self.get_allocation() 477 478 478 # README: these values (cairo.Matrix) are taken seeing the image on the479 # screen, I think we should find a way to calculate them480 479 cr.save() 481 matrix = cairo.Matrix(xx=0.3, yy=0.2, x0=10, y0=-20) 482 cr.transform(matrix) 483 lhand_image.render_cairo(cr) 480 Gdk.cairo_set_source_pixbuf(cr, lhand_image, 0, 0) 481 cr.rectangle(0, 0, lhand_image.get_width(), 482 lhand_image.get_height()) 483 cr.paint() 484 484 485 485 cr.restore() 486 matrix = cairo.Matrix(xx=0.325, yy=0.2, x0=-5, y0=-20) 487 cr.transform(matrix) 488 rhand_image.render_cairo(cr) 489 490 def _expose_cb(self, area, event): 491 cr = self.window.cairo_create() 486 Gdk.cairo_set_source_pixbuf(cr, rhand_image, 0, 0) 487 cr.rectangle(0, 0, rhand_image.get_width(), 488 rhand_image.get_height()) 489 cr.paint() 492 490 491 def _draw_cb(self, area, cr): 493 492 # Draw the keys. 494 493 for k in self.keys: 495 494 self._draw_key(k, cr) … … class KeyboardWidget(KeyboardData, gtk.DrawingArea): 502 501 def key_press_release_cb(self, widget, event): 503 502 key = self.key_scan_map.get(event.hardware_keycode) 504 503 if key: 505 key['key-pressed'] = event.type == gtk.gdk.KEY_PRESS504 key['key-pressed'] = event.type == Gdk.EventType.KEY_PRESS 506 505 507 506 # Hack to get the current modifier state - which will not be represented by the event. 508 state = gtk.gdk.device_get_core_pointer().get_state(self.window)[1]507 # state = Gdk.device_get_core_pointer().get_state(self.get_window())[1] 509 508 510 if self.active_group != event.group or self.active_state != state:509 if self.active_group != event.group or self.active_state != event.state: 511 510 self.active_group = event.group 512 self.active_state = state511 self.active_state = event.state 513 512 514 513 self.queue_draw() 515 514 … … class KeyboardWidget(KeyboardData, gtk.DrawingArea): 556 555 # Convert cairo.Surface to Pixbuf 557 556 pixbuf_data = StringIO.StringIO() 558 557 surface.write_to_png(pixbuf_data) 559 pxb_loader = gtk.gdk.PixbufLoader(image_type='png')558 pxb_loader = GdkPixbuf.PixbufLoader.new_with_type('png') 560 559 pxb_loader.write(pixbuf_data.getvalue()) 561 560 temp_pix = pxb_loader.get_pixbuf() 562 561 pxb_loader.close() -
keybuilder.py
diff --git a/keybuilder.py b/keybuilder.py index bceab0d..28f6f97 100755
a b 19 19 import sys 20 20 import keyboard 21 21 22 import gtk22 from gi.repository import Gtk 23 23 24 window = gtk.Window(gtk.WINDOW_TOPLEVEL)24 window = Gtk.Window(Gtk.WindowType.TOPLEVEL) 25 25 window.set_title("keyboard widget") 26 window.connect("destroy", lambda w: gtk.main_quit())26 window.connect("destroy", lambda w: Gtk.main_quit()) 27 27 window.show_all() 28 28 window.realize() 29 29 … … except: 37 37 pass 38 38 k.set_layout(keyboard.get_layout()) 39 39 40 savebtn = gtk.Button()41 savebtn.add( gtk.Label('Save Keys'))40 savebtn = Gtk.Button() 41 savebtn.add(Gtk.Label(label='Save Keys')) 42 42 savebtn.connect('clicked', lambda w: k.save_letter_map(sys.argv[1])) 43 43 44 quitbtn = gtk.Button()45 quitbtn.add( gtk.Label('Quit'))46 quitbtn.connect('clicked', lambda w: gtk.main_quit())44 quitbtn = Gtk.Button() 45 quitbtn.add(Gtk.Label(label='Quit')) 46 quitbtn.connect('clicked', lambda w: Gtk.main_quit()) 47 47 48 hbox = gtk.HBox()49 hbox.pack_start(savebtn )50 hbox.pack_start(quitbtn )48 hbox = Gtk.HBox() 49 hbox.pack_start(savebtn, True, True, 0) 50 hbox.pack_start(quitbtn, True, True, 0) 51 51 52 vbox = gtk.VBox()53 vbox.pack_start(k )54 vbox.pack_start(hbox )52 vbox = Gtk.VBox() 53 vbox.pack_start(k, True, True, 0) 54 vbox.pack_start(hbox, True, True, 0) 55 55 56 56 window.add(vbox) 57 57 window.show_all() 58 58 59 gtk.main()59 Gtk.main() 60 60 -
lessonbuilder.py
diff --git a/lessonbuilder.py b/lessonbuilder.py index b33a34e..c7c4d1a 100755
a b from gettext import gettext as _ 21 21 from port import json 22 22 23 23 # For modifier constants. 24 import gtk24 from gi.repository import Gtk 25 25 26 26 # Set up remote debugging. 27 27 #import dbgp.client … … def build_key_steps( 338 338 # except: 339 339 # error("The '%s' letter (scan code %x) does not have a finger assigned." % (letter, key['key-scan'])) 340 340 # 341 # if state == gtk.gdk.SHIFT_MASK:341 # if state == Gdk.ModifierType.SHIFT_MASK: 342 342 # # Choose the finger to press the SHIFT key with. 343 343 # if key['key-finger'][0] == 'R': 344 344 # shift_finger = FINGERS['LP'] … … def build_key_steps( 348 348 # instructions = _('Press and hold the SHIFT key with your %(finger)s finger, ') % { 'finger': shift_finger } 349 349 # instructions += _('then press the %(letter)s key with your %(finger)s finger.') % { 'letter': letter, 'finger': finger } 350 350 # 351 # elif state == gtk.gdk.MOD5_MASK:351 # elif state == Gdk.ModifierType.MOD5_MASK: 352 352 # instructions = _('Press and hold the ALTGR key, ') 353 353 # instructions += _('then press the %(letter)s key with your %(finger)s finger.') % { 'letter': letter, 'finger': finger } 354 354 # 355 # elif state == gtk.gdk.SHIFT_MASK | gtk.gdk.MOD5_MASK:355 # elif state == Gdk.ModifierType.SHIFT_MASK | Gdk.ModifierType.MOD5_MASK: 356 356 # instructions = _('Press and hold the ALTGR and SHIFT keys, ') 357 357 # instructions += _('then press the %(letter)s key with your %(finger)s finger.') % { 'letter': letter, 'finger': finger } 358 358 # -
lessonscreen.py
diff --git a/lessonscreen.py b/lessonscreen.py index cc75ef4..fb38bff 100644
a b 19 19 import logging, os, math, time, copy, locale, datetime, random, re 20 20 from gettext import gettext as _ 21 21 22 # Import PyGTK. 23 import gobject, pygtk, gtk, pango 22 from gi.repository import Gtk 23 from gi.repository import Gdk 24 from gi.repository import GObject 24 25 25 26 # Import Sugar UI modules. 26 import sugar .activity.activity27 from sugar .graphics import *27 import sugar3.activity.activity 28 from sugar3.graphics import * 28 29 29 30 # Import activity modules. 30 31 import keyboard, medalscreen … … FINGERS = { 48 49 'RT': _('right thumb'), 49 50 } 50 51 51 class LessonScreen( gtk.VBox):52 class LessonScreen(Gtk.VBox): 52 53 def __init__(self, lesson, keyboard_images, activity): 53 gtk.VBox.__init__(self)54 GObject.GObject.__init__(self) 54 55 55 56 self.lesson = lesson 56 57 self.keyboard_images = keyboard_images 57 58 self.activity = activity 58 59 59 60 # Build the user interface. 60 title = gtk.Label()61 title = Gtk.Label() 61 62 title.set_markup("<span size='x-large' weight='bold'>" + lesson['name'] + "</span>") 62 63 title.set_alignment(1.0, 0.0) 63 64 64 stoplabel = gtk.Label(_('Go Back'))65 stopbtn = gtk.Button()65 stoplabel = Gtk.Label(label=_('Go Back')) 66 stopbtn = Gtk.Button() 66 67 stopbtn.add(stoplabel) 67 68 stopbtn.connect('clicked', self.stop_cb) 68 69 69 # TODO- These will be replaced by graphical displays using gtk.DrawingArea.70 # TODO- These will be replaced by graphical displays using Gtk.DrawingArea. 70 71 self.wpm = 0 71 72 self.accuracy = 0 72 73 73 self.wpmlabel = gtk.Label()74 self.accuracylabel = gtk.Label()74 self.wpmlabel = Gtk.Label() 75 self.accuracylabel = Gtk.Label() 75 76 76 #self.wpmarea = gtk.DrawingArea()77 #self.wpmarea = Gtk.DrawingArea() 77 78 #self.wpmarea.connect('expose-event', self.wpm_expose_cb) 78 #self.accuracyarea = gtk.DrawingArea()79 #self.accuracyarea = Gtk.DrawingArea() 79 80 #self.accuracyarea.connect('expose-event', self.accuracy_expose_cb) 80 81 81 hbox = gtk.HBox()82 hbox = Gtk.HBox() 82 83 hbox.pack_start(stopbtn, False, False, 10) 83 84 hbox.pack_start(self.wpmlabel, True, False, 10) 84 85 hbox.pack_start(self.accuracylabel, True, False, 10) 85 86 hbox.pack_end(title, False, False, 10) 86 87 87 88 # Set up font styles. 88 self.tagtable = gtk.TextTagTable()89 instructions_tag = gtk.TextTag('instructions')90 instructions_tag.props.justification = gtk.JUSTIFY_CENTER89 self.tagtable = Gtk.TextTagTable() 90 instructions_tag = Gtk.TextTag.new('instructions') 91 instructions_tag.props.justification = Gtk.Justification.CENTER 91 92 self.tagtable.add(instructions_tag) 92 93 93 text_tag = gtk.TextTag('text')94 text_tag = Gtk.TextTag.new('text') 94 95 text_tag.props.family = 'Monospace' 95 96 self.tagtable.add(text_tag) 96 97 97 spacer_tag = gtk.TextTag('spacer')98 spacer_tag = Gtk.TextTag.new('spacer') 98 99 spacer_tag.props.size = 3000 99 100 self.tagtable.add(spacer_tag) 100 101 101 image_tag = gtk.TextTag('image')102 image_tag.props.justification = gtk.JUSTIFY_CENTER102 image_tag = Gtk.TextTag.new('image') 103 image_tag.props.justification = Gtk.Justification.CENTER 103 104 self.tagtable.add(image_tag) 104 105 105 correct_copy_tag = gtk.TextTag('correct-copy')106 correct_copy_tag = Gtk.TextTag.new('correct-copy') 106 107 correct_copy_tag.props.family = 'Monospace' 107 108 correct_copy_tag.props.foreground = '#0000ff' 108 109 self.tagtable.add(correct_copy_tag) 109 110 110 incorrect_copy_tag = gtk.TextTag('incorrect-copy')111 incorrect_copy_tag = Gtk.TextTag.new('incorrect-copy') 111 112 incorrect_copy_tag.props.family = 'Monospace' 112 113 incorrect_copy_tag.props.foreground = '#ff0000' 113 114 self.tagtable.add(incorrect_copy_tag) 114 115 115 116 # Set up the scrolling lesson text view. 116 self.lessonbuffer = gtk.TextBuffer(self.tagtable)117 self.lessontext = gtk.TextView(self.lessonbuffer)117 self.lessonbuffer = Gtk.TextBuffer.new(self.tagtable) 118 self.lessontext = Gtk.TextView.new_with_buffer(self.lessonbuffer) 118 119 self.lessontext.set_editable(False) 119 120 self.lessontext.set_left_margin(20) 120 121 self.lessontext.set_right_margin(20) 121 self.lessontext.set_wrap_mode( gtk.WRAP_WORD)122 self.lessontext.modify_base( gtk.STATE_NORMAL, self.get_colormap().alloc_color('#ffffcc'))122 self.lessontext.set_wrap_mode(Gtk.WrapMode.WORD) 123 self.lessontext.modify_base(Gtk.StateType.NORMAL, Gdk.Color.parse('#ffffcc')[1]) 123 124 124 self.lessonscroll = gtk.ScrolledWindow()125 self.lessonscroll.set_policy( gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)125 self.lessonscroll = Gtk.ScrolledWindow() 126 self.lessonscroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.ALWAYS) 126 127 self.lessonscroll.add(self.lessontext) 127 128 128 frame = gtk.Frame()129 frame = Gtk.Frame() 129 130 frame.add(self.lessonscroll) 130 131 131 132 self.keyboard = keyboard.KeyboardWidget(self.keyboard_images, self.activity) … … class LessonScreen(gtk.VBox): 140 141 self.keyboard.set_layout(keyboard.get_layout()) 141 142 142 143 self.pack_start(hbox, False, False, 10) 143 self.pack_start(frame, True, True )144 self.pack_start(self.keyboard, False )144 self.pack_start(frame, True, True, 0) 145 self.pack_start(self.keyboard, False, True, 0) 145 146 146 147 # Connect keyboard grabbing and releasing callbacks. 147 148 self.connect('realize', self.realize_cb) … … class LessonScreen(gtk.VBox): 154 155 self.begin_lesson() 155 156 156 157 def realize_cb(self, widget): 157 self.activity.add_events( gtk.gdk.KEY_PRESS_MASK|gtk.gdk.KEY_RELEASE_MASK)158 self.activity.add_events(Gdk.EventMask.KEY_PRESS_MASK|Gdk.EventMask.KEY_RELEASE_MASK) 158 159 self.key_press_cb_id = self.activity.connect('key-press-event', self.key_cb) 159 160 self.key_release_cb_id = self.activity.connect('key-release-event', self.key_cb) 160 161 … … class LessonScreen(gtk.VBox): 164 165 165 166 def start_timer(self): 166 167 self.start_time = time.time() 167 self.timer_id = gobject.timeout_add(1000, self.timer_cb)168 self.timer_id = GObject.timeout_add(1000, self.timer_cb) 168 169 169 170 def stop_timer(self): 170 171 if self.timer_id: 171 gobject.source_remove(self.timer_id)172 GObject.source_remove(self.timer_id) 172 173 self.start_time = None 173 174 self.timer_id = None 174 175 … … class LessonScreen(gtk.VBox): 349 350 350 351 # Extract information about the key pressed. 351 352 key = event.string 352 key_name = gtk.gdk.keyval_name(event.keyval)353 key_name = Gdk.keyval_name(event.keyval) 353 354 354 355 # Ignore events which don't produce a character, except backspace. 355 356 if not (key_name == 'BackSpace' or key): 356 357 return True 357 358 358 359 # Ignore either press or release events, depending on mode. 359 if self.mode == 'key' and event.type == gtk.gdk.KEY_PRESS:360 if self.mode == 'key' and event.type == Gdk.EventType.KEY_PRESS: 360 361 return True 361 if self.mode != 'key' and event.type == gtk.gdk.KEY_RELEASE:362 if self.mode != 'key' and event.type == Gdk.EventType.KEY_RELEASE: 362 363 return True 363 364 364 365 # Ignore hotkeys. 365 if event. state & (gtk.gdk.CONTROL_MASK | gtk.gdk.MOD1_MASK):366 if event.get_state() & (Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.MOD1_MASK): 366 367 return True 367 368 368 369 # Convert Return keys to paragraph symbols. … … class LessonScreen(gtk.VBox): 474 475 self.lessontext.grab_focus() 475 476 476 477 # Scroll the TextView so the cursor is on screen. 477 self.lessontext.scroll_to_mark(self.lessonbuffer.get_insert(), 0) 478 self.lessontext.scroll_to_mark(self.lessonbuffer.get_insert(), 0, 479 use_align=False, xalign=0.5, yalign=0.5) 478 480 479 481 # In Key mode, display the finger hint and the key image. 480 482 if self.mode == 'key': … … class LessonScreen(gtk.VBox): 499 501 except: 500 502 finger = '' 501 503 502 if state == gtk.gdk.SHIFT_MASK:504 if state == Gdk.ModifierType.SHIFT_MASK: 503 505 # Choose the finger to press the SHIFT key with. 504 506 if key['key-finger'][0] == 'R': 505 507 shift_finger = FINGERS['LP'] … … class LessonScreen(gtk.VBox): 509 511 instructions = _('Press and hold the shift key with your %(finger)s, ') % { 'finger': shift_finger } 510 512 instructions += _('then press the %(letter)s key with your %(finger)s.') % { 'letter': letter, 'finger': finger } 511 513 512 elif state == gtk.gdk.MOD5_MASK:514 elif state == Gdk.ModifierType.MOD5_MASK: 513 515 instructions = _('Press and hold the altgr key, ') 514 516 instructions += _('then press the %(letter)s key with your %(finger)s.') % { 'letter': letter, 'finger': finger } 515 517 516 elif state == gtk.gdk.SHIFT_MASK | gtk.gdk.MOD5_MASK:518 elif state == Gdk.ModifierType.SHIFT_MASK | Gdk.ModifierType.MOD5_MASK: 517 519 instructions = _('Press and hold the altgr and shift keys, ') 518 520 instructions += _('then press the %(letter)s key with your %(finger)s.') % { 'letter': letter, 'finger': finger } 519 521 … … class LessonScreen(gtk.VBox): 522 524 523 525 self.lessonbuffer.insert(self.lessonbuffer.get_end_iter(), instructions + '\n\n') 524 526 525 if state & gtk.gdk.SHIFT_MASK:527 if state & Gdk.ModifierType.SHIFT_MASK: 526 528 shift_key = self.keyboard.find_key_by_label('shift') 527 529 pixbuf = self.keyboard.get_key_pixbuf(shift_key, scale=1) 528 530 self.lessonbuffer.insert_pixbuf(self.lessonbuffer.get_end_iter(), pixbuf) 529 531 self.lessonbuffer.insert(self.lessonbuffer.get_end_iter(), ' ') 530 532 531 if state & gtk.gdk.MOD5_MASK:533 if state & Gdk.ModifierType.MOD5_MASK: 532 534 altgr_key = self.keyboard.find_key_by_label('altgr') 533 535 pixbuf = self.keyboard.get_key_pixbuf(altgr_key, scale=1) 534 536 self.lessonbuffer.insert_pixbuf(self.lessonbuffer.get_end_iter(), pixbuf) -
mainscreen.py
diff --git a/mainscreen.py b/mainscreen.py index 2762baf..7f540f0 100644
a b import logging, os, math, time, copy, locale, datetime, random, re, glob 19 19 from gettext import gettext as _ 20 20 from port import json 21 21 22 # Import PyGTK. 23 import gobject, pygtk, gtk, pango 22 from gi.repository import Gtk 23 from gi.repository import Gdk 24 from gi.repository import GdkPixbuf 25 from gi.repository import GObject 24 26 25 27 # Import Sugar UI modules. 26 import sugar .activity.activity27 from sugar .graphics import *28 import sugar3.activity.activity 29 from sugar3.graphics import * 28 30 29 31 # Import activity modules. 30 32 import lessonscreen, medalscreen … … import keyboard 38 40 # http://commons.wikimedia.org/wiki/File:Silver_medal_world_centered.svg 39 41 # http://commons.wikimedia.org/wiki/File:Bronze_medal_world_centered.svg 40 42 41 class MainScreen( gtk.VBox):43 class MainScreen(Gtk.VBox): 42 44 def __init__(self, activity): 43 gtk.VBox.__init__(self)45 GObject.GObject.__init__(self) 44 46 45 47 self.activity = activity 46 48 … … class MainScreen(gtk.VBox): 48 50 self.titlescene = titlescene.TitleScene() 49 51 50 52 # Build lessons list. 51 self.lessonbox = gtk.HBox()53 self.lessonbox = Gtk.HBox() 52 54 53 #nexticon = sugar .graphics.icon.Icon(icon_name='go-next')55 #nexticon = sugar3.graphics.icon.Icon(icon_name='go-next') 54 56 #self.nextlessonbtn.add(nexticon) 55 nextlabel = gtk.Label()57 nextlabel = Gtk.Label() 56 58 nextlabel.set_markup("<span size='large'>" + _('Next') + "</span>") 57 59 58 self.nextlessonbtn = gtk.Button()60 self.nextlessonbtn = Gtk.Button() 59 61 self.nextlessonbtn.add(nextlabel) 60 62 self.nextlessonbtn.connect('clicked', self.next_lesson_clicked_cb) 61 63 62 #previcon = sugar .graphics.icon.Icon(icon_name='go-previous')64 #previcon = sugar3.graphics.icon.Icon(icon_name='go-previous') 63 65 #self.prevlessonbtn.add(previcon) 64 prevlabel = gtk.Label()66 prevlabel = Gtk.Label() 65 67 prevlabel.set_markup("<span size='large'>" + _('Previous') + "</span>") 66 68 67 self.prevlessonbtn = gtk.Button()69 self.prevlessonbtn = Gtk.Button() 68 70 self.prevlessonbtn.add(prevlabel) 69 71 self.prevlessonbtn.connect('clicked', self.prev_lesson_clicked_cb) 70 72 71 lessonlabel = gtk.Label()73 lessonlabel = Gtk.Label() 72 74 lessonlabel.set_markup("<span size='x-large' weight='bold'>" + _('Start Lesson') + "</span>") 73 75 74 lessonbtn = gtk.Button()76 lessonbtn = Gtk.Button() 75 77 lessonbtn.add(lessonlabel) 76 78 lessonbtn.connect('clicked', self.lesson_clicked_cb) 77 lessonbtn.modify_bg( gtk.STATE_NORMAL, self.get_colormap().alloc_color('#60b060'))79 lessonbtn.modify_bg(Gtk.StateType.NORMAL, Gdk.Color.parse('#60b060')[1]) 78 80 79 81 # Load lessons for this language. 80 82 code = locale.getdefaultlocale()[0] or 'en_US' 81 lessons_path = os.path.join(sugar .activity.activity.get_bundle_path(), 'lessons')83 lessons_path = os.path.join(sugar3.activity.activity.get_bundle_path(), 'lessons') 82 84 lessons_file = os.path.join(lessons_path, code + '.lessons') 83 85 if os.path.isfile(lessons_file): 84 86 self.load_lessons(lessons_file) … … class MainScreen(gtk.VBox): 99 101 self.lessons.sort(lambda x, y: x.get('order', 0) - y.get('order', 0)) 100 102 101 103 # Load all the keyboard images. 102 width = int(gtk.gdk.screen_width()) 103 height = int(gtk.gdk.screen_height()*0.3) 104 width = int(Gdk.Screen.width()) 105 height = int(Gdk.Screen.height()*0.3) 106 104 107 self.keyboard_images = keyboard.KeyboardImages(width, height) 105 108 self.keyboard_images.load_images() 106 109 107 navbox = gtk.HBox()110 navbox = Gtk.HBox() 108 111 navbox.set_spacing(10) 109 navbox.pack_start(self.prevlessonbtn, True )110 navbox.pack_start(lessonbtn, True )111 navbox.pack_start(self.nextlessonbtn, True )112 navbox.pack_start(self.prevlessonbtn, True, True, 0) 113 navbox.pack_start(lessonbtn, True, True, 0) 114 navbox.pack_start(self.nextlessonbtn, True, True, 0) 112 115 113 lessonbox = gtk.VBox()116 lessonbox = Gtk.VBox() 114 117 lessonbox.set_spacing(10) 115 lessonbox.pack_start(navbox, False )116 lessonbox.pack_start(self.lessonbox )118 lessonbox.pack_start(navbox, False, True, 0) 119 lessonbox.pack_start(self.lessonbox, True, True, 0) 117 120 118 121 self.pack_start(self.titlescene, False, True, 10) 119 self.pack_start(lessonbox, True )122 self.pack_start(lessonbox, True, True, 0) 120 123 121 124 self.show_next_lesson() 122 125 … … class MainScreen(gtk.VBox): 165 168 medal_type = self.activity.data['medals'][lesson['name']]['type'] 166 169 167 170 # Create the lesson button. 168 namelabel = gtk.Label()171 namelabel = Gtk.Label() 169 172 namelabel.set_alignment(0.5, 0.5) 170 173 namelabel.set_markup("<span size='x-large' weight='bold'>" + lesson['name'] + "</span>") 171 desclabel = gtk.Label()174 desclabel = Gtk.Label() 172 175 desclabel.set_alignment(0.5, 0.5) 173 176 desclabel.set_markup("<span size='large' color='#606060'>" + lesson['description'] + "</span>") 174 177 … … class MainScreen(gtk.VBox): 177 180 else: 178 181 hint = '' 179 182 180 #hintlabel = gtk.Label()183 #hintlabel = Gtk.Label() 181 184 #hintlabel.set_alignment(0.0, 0.8) 182 185 #hintlabel.set_markup("<span size='8000' color='#606020'>" + hint + "</span>") 183 186 184 labelbox = gtk.VBox()187 labelbox = Gtk.VBox() 185 188 labelbox.set_spacing(10) 186 189 labelbox.set_border_width(20) 187 labelbox.pack_start(namelabel, False )188 labelbox.pack_start(desclabel, False )189 #labelbox.pack_start(hintlabel )190 labelbox.pack_start(namelabel, False, True, 0) 191 labelbox.pack_start(desclabel, False, True, 0) 192 #labelbox.pack_start(hintlabel, True, True, 0) 190 193 191 194 # Create the medal image. 192 195 images = { … … class MainScreen(gtk.VBox): 196 199 'gold': 'images/gold-medal.svg' 197 200 } 198 201 199 medal_size = int(2.0 * sugar .graphics.style.GRID_CELL_SIZE)200 medalpixbuf = gtk.gdk.pixbuf_new_from_file(images[medal_type])201 medalpixbuf = medalpixbuf.scale_simple(medal_size, medal_size, gtk.gdk.INTERP_BILINEAR)202 medal_size = int(2.0 * sugar3.graphics.style.GRID_CELL_SIZE) 203 medalpixbuf = GdkPixbuf.Pixbuf.new_from_file(images[medal_type]) 204 medalpixbuf = medalpixbuf.scale_simple(medal_size, medal_size, GdkPixbuf.InterpType.BILINEAR) 202 205 203 medalimage = gtk.Image()206 medalimage = Gtk.Image() 204 207 medalimage.set_from_pixbuf(medalpixbuf) 205 208 206 209 names = { … … class MainScreen(gtk.VBox): 209 212 'silver': _('Silver Medal'), 210 213 'gold': _('Gold Medal'), 211 214 } 212 medallabel = gtk.Label(names[medal_type])215 medallabel = Gtk.Label(label=names[medal_type]) 213 216 214 medalbox = gtk.VBox()215 medalbox.pack_start(medalimage )216 medalbox.pack_start(medallabel )217 medalbox = Gtk.VBox() 218 medalbox.pack_start(medalimage, True, True, 0) 219 medalbox.pack_start(medallabel, True, True, 0) 217 220 218 medalbtn = gtk.Button()221 medalbtn = Gtk.Button() 219 222 medalbtn.add(medalbox) 220 223 medalbtn.connect('clicked', self.medal_clicked_cb) 221 224 222 225 # Hilite the button in the direction of the first unmedaled lesson. 223 226 next_index = self.get_next_lesson() 224 227 if next_index > self.lesson_index and index < len(self.lessons)-1: 225 self.nextlessonbtn.modify_bg( gtk.STATE_NORMAL, self.get_colormap().alloc_color('#ff8080'))228 self.nextlessonbtn.modify_bg(Gtk.StateType.NORMAL, Gdk.Color.parse('#ff8080')[1]) 226 229 else: 227 self.nextlessonbtn.modify_bg( gtk.STATE_NORMAL, self.get_colormap().alloc_color('#40a040'))230 self.nextlessonbtn.modify_bg(Gtk.StateType.NORMAL, Gdk.Color.parse('#40a040')[1]) 228 231 if next_index < self.lesson_index and index > 0: 229 self.prevlessonbtn.modify_bg( gtk.STATE_NORMAL, self.get_colormap().alloc_color('#ff8080'))232 self.prevlessonbtn.modify_bg(Gtk.StateType.NORMAL, Gdk.Color.parse('#ff8080')[1]) 230 233 else: 231 self.prevlessonbtn.modify_bg( gtk.STATE_NORMAL, self.get_colormap().alloc_color('#40a040'))234 self.prevlessonbtn.modify_bg(Gtk.StateType.NORMAL, Gdk.Color.parse('#40a040')[1]) 232 235 233 self.lessonbox.pack_start(labelbox, True )236 self.lessonbox.pack_start(labelbox, True, True, 0) 234 237 if medal_type != 'none': 235 self.lessonbox.pack_start(medalbtn, False )238 self.lessonbox.pack_start(medalbtn, False, True, 0) 236 239 237 240 self.lessonbox.show_all() 238 241 -
medalscreen.py
diff --git a/medalscreen.py b/medalscreen.py index a1d881a..d9cf410 100644
a b 18 18 import logging, os, math, time, copy, locale, datetime, random, re 19 19 from gettext import gettext as _ 20 20 21 # Import PyGTK. 22 import gobject, pygtk, gtk, pango 21 from gi.repository import Gtk 22 from gi.repository import Gdk 23 from gi.repository import GdkPixbuf 24 from gi.repository import GObject 23 25 24 26 # Import Sugar UI modules. 25 import sugar .activity.activity26 import sugar .graphics.style27 import sugar3.activity.activity 28 import sugar3.graphics.style 27 29 28 class MedalScreen( gtk.EventBox):29 MEDAL_SIZE = int(4.5 * sugar .graphics.style.GRID_CELL_SIZE)30 class MedalScreen(Gtk.EventBox): 31 MEDAL_SIZE = int(4.5 * sugar3.graphics.style.GRID_CELL_SIZE) 30 32 31 33 def __init__(self, medal, activity): 32 gtk.EventBox.__init__(self)34 GObject.GObject.__init__(self) 33 35 34 self.modify_bg( gtk.STATE_NORMAL, self.get_colormap().alloc_color('#ffffff'))36 self.modify_bg(Gtk.StateType.NORMAL, Gdk.Color.parse('#ffffff')[1]) 35 37 36 38 self.medal = medal 37 39 self.activity = activity … … class MedalScreen(gtk.EventBox): 43 45 'silver': 'images/silver-medal.svg', 44 46 'gold': 'images/gold-medal.svg' 45 47 } 46 medalpixbuf = gtk.gdk.pixbuf_new_from_file(images[medal_type])47 medalpixbuf = medalpixbuf.scale_simple(MedalScreen.MEDAL_SIZE, MedalScreen.MEDAL_SIZE, gtk.gdk.INTERP_BILINEAR)48 medalpixbuf = GdkPixbuf.Pixbuf.new_from_file(images[medal_type]) 49 medalpixbuf = medalpixbuf.scale_simple(MedalScreen.MEDAL_SIZE, MedalScreen.MEDAL_SIZE, GdkPixbuf.InterpType.BILINEAR) 48 50 49 medalimage = gtk.Image()51 medalimage = Gtk.Image() 50 52 medalimage.set_from_pixbuf(medalpixbuf) 51 53 52 54 # Certifications section. 53 title = gtk.Label()55 title = Gtk.Label() 54 56 title.set_markup(_("<span font_desc='Serif Bold Italic 28'>Certificate of Achievement</span>")) 55 57 56 text0 = gtk.Label()58 text0 = Gtk.Label() 57 59 text0.set_markup(_("<span font_desc='Sans 16'>This certifies that</span>")) 58 60 59 text1 = gtk.Label()61 text1 = Gtk.Label() 60 62 text1.set_markup(_("<span font_desc='Sans 16'><b><u><i>%(nick)s</i></u></b></span>") % medal) 61 63 62 text2 = gtk.Label()64 text2 = Gtk.Label() 63 65 text2.set_markup(_("<span font_desc='Sans 16'>earned a %(type)s medal in </span>") % medal) 64 66 65 text3 = gtk.Label()67 text3 = Gtk.Label() 66 68 text3.set_markup(_("<span font_desc='Sans 16'>in <b><u><i>%(lesson)s</i></u></b></span>") % medal) 67 69 68 text4 = gtk.Label()70 text4 = Gtk.Label() 69 71 text4.set_markup(_("<span font_desc='Sans 16'>on <b><u><i>%(date)s</i></u></b>.</span>") % medal) 70 72 71 textbox = gtk.VBox()72 textbox.pack_start(text0 )73 textbox.pack_start(text1 )74 textbox.pack_start(text2 )75 textbox.pack_start(text3 )76 textbox.pack_start(text4 )73 textbox = Gtk.VBox() 74 textbox.pack_start(text0, True, True, 0) 75 textbox.pack_start(text1, True, True, 0) 76 textbox.pack_start(text2, True, True, 0) 77 textbox.pack_start(text3, True, True, 0) 78 textbox.pack_start(text4, True, True, 0) 77 79 78 medalbox = gtk.HBox()79 medalbox.pack_start(textbox )80 medalbox.pack_end(medalimage )80 medalbox = Gtk.HBox() 81 medalbox.pack_start(textbox, True, True, 0) 82 medalbox.pack_end(medalimage, True, True, 0) 81 83 82 84 # Stats section. 83 statbox = gtk.HBox()85 statbox = Gtk.HBox() 84 86 if medal.has_key('wpm'): 85 stat1 = gtk.Label()87 stat1 = Gtk.Label() 86 88 stat1.set_markup("<span size='18000'>" + (_('<b>Words Per Minute:</b> %(wpm)d') % medal) + "</span>" ) 87 statbox.pack_start(stat1, True )89 statbox.pack_start(stat1, True, True, 0) 88 90 89 stat2 = gtk.Label()91 stat2 = Gtk.Label() 90 92 stat2.set_markup("<span size='18000'>" + (_('<b>Accuracy:</b> %(accuracy)d%%') % medal) + "</span>" ) 91 statbox.pack_start(stat2, True )93 statbox.pack_start(stat2, True, True, 0) 92 94 93 95 elif medal.has_key('score'): 94 stat1 = gtk.Label()96 stat1 = Gtk.Label() 95 97 stat1.set_markup("<span size='18000'>" + (_('<b>SCORE:</b> %(score)d') % medal) + "</span>" ) 96 statbox.pack_start(stat1, True )98 statbox.pack_start(stat1, True, True, 0) 97 99 98 oklabel = gtk.Label()100 oklabel = Gtk.Label() 99 101 oklabel.set_markup("<span size='10000'>" + _('Press the ENTER key to continue.') + '</span>') 100 self.okbtn = gtk.Button()102 self.okbtn = Gtk.Button() 101 103 self.okbtn.add(oklabel) 102 104 self.okbtn.connect('clicked', self.ok_cb) 103 105 104 btnbox = gtk.HBox()106 btnbox = Gtk.HBox() 105 107 btnbox.pack_start(self.okbtn, True, True, 100) 106 108 107 vbox = gtk.VBox()109 vbox = Gtk.VBox() 108 110 109 111 vbox.pack_start(title, False, False, 0) 110 112 vbox.pack_start(medalbox, True, False, 0) 111 vbox.pack_start( gtk.HSeparator(), False, False, 20)113 vbox.pack_start(Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL), False, False, 20) 112 114 vbox.pack_start(statbox, False, False, 0) 113 115 114 frame = gtk.Frame()116 frame = Gtk.Frame() 115 117 frame.add(vbox) 116 118 frame.set_border_width(10) 117 119 118 box = gtk.VBox()119 box.pack_start(frame, True, True )120 box = Gtk.VBox() 121 box.pack_start(frame, True, True, 0) 120 122 box.pack_start(btnbox, False, False, 40) 121 123 122 124 self.add(box) … … class MedalScreen(gtk.EventBox): 127 129 128 130 def realize_cb(self, widget): 129 131 # For some odd reason, if I do this in the constructor, nothing happens. 130 self.okbtn.set_ flags(gtk.CAN_DEFAULT)132 self.okbtn.set_can_default(True) 131 133 self.okbtn.grab_default() 132 134 133 135 def ok_cb(self, widget): -
port/chooser.py
diff --git a/port/chooser.py b/port/chooser.py index e2df259..1391942 100644
a b 14 14 15 15 """Object chooser method""" 16 16 17 import gtk17 from gi.repository import Gtk 18 18 import logging 19 19 20 from sugar import mime21 from sugar .graphics.objectchooser import ObjectChooser20 from sugar3 import mime 21 from sugar3.graphics.objectchooser import ObjectChooser 22 22 23 23 TEXT = hasattr(mime, 'GENERIC_TYPE_TEXT') and mime.GENERIC_TYPE_TEXT or None 24 24 IMAGE = hasattr(mime, 'GENERIC_TYPE_IMAGE') and mime.GENERIC_TYPE_IMAGE or None … … def pick(cb=None, default=None, parent=None, what=None): 45 45 out = None 46 46 47 47 try: 48 if chooser.run() == gtk.RESPONSE_ACCEPT:48 if chooser.run() == Gtk.ResponseType.ACCEPT: 49 49 jobject = chooser.get_selected_object() 50 50 logging.debug('ObjectChooser: %r' % jobject) 51 51 -
setup.py
diff --git a/setup.py b/setup.py index 77fda74..c17ead5 100755
a b 1 1 #!/usr/bin/env python 2 from sugar .activity import bundlebuilder2 from sugar3.activity import bundlebuilder 3 3 if __name__ == "__main__": 4 4 bundlebuilder.start() -
titlescene.py
diff --git a/titlescene.py b/titlescene.py index 4dc6ae4..9739152 100644
a b 18 18 import random 19 19 from gettext import gettext as _ 20 20 21 # Import PyGTK. 22 import gobject, pygtk, gtk, pango 23 import pangocairo 21 from gi.repository import Gtk 22 from gi.repository import Gdk 23 from gi.repository import GObject 24 from gi.repository import Pango 25 from gi.repository import PangoCairo 26 from gi.repository import GdkPixbuf 24 27 25 28 26 class TitleScene( gtk.DrawingArea):29 class TitleScene(Gtk.DrawingArea): 27 30 # Maximum portion of the screen the background can fill vertically. 28 31 BACKGROUND_HEIGHT_RATIO = 0.6 29 32 … … class TitleScene(gtk.DrawingArea): 34 37 TITLE_FONT = 'Times 45' 35 38 36 39 def __init__(self): 37 gtk.DrawingArea.__init__(self)40 Gtk.DrawingArea.__init__(self) 38 41 39 pbuf = gtk.gdk.pixbuf_new_from_file('images/main-background.jpg')42 pbuf = GdkPixbuf.Pixbuf.new_from_file('images/main-background.jpg') 40 43 41 width_ratio = float( gtk.gdk.screen_width()) / pbuf.get_width()42 height_ratio = float( gtk.gdk.screen_height()*TitleScene.BACKGROUND_HEIGHT_RATIO) / pbuf.get_height()44 width_ratio = float(Gdk.Screen.width()) / pbuf.get_width() 45 height_ratio = float(Gdk.Screen.height()*TitleScene.BACKGROUND_HEIGHT_RATIO) / pbuf.get_height() 43 46 44 47 ratio = min(width_ratio, height_ratio) 45 self.backgroundpixbuf = pbuf.scale_simple(int(pbuf.get_width()*ratio), int(pbuf.get_height()*ratio), gtk.gdk.INTERP_BILINEAR)48 self.backgroundpixbuf = pbuf.scale_simple(int(pbuf.get_width()*ratio), int(pbuf.get_height()*ratio), GdkPixbuf.InterpType.BILINEAR) 46 49 47 50 self.set_size_request(self.backgroundpixbuf.get_width(), self.backgroundpixbuf.get_height()) 48 51 49 self.connect(" expose-event", self.expose_cb)52 self.connect("draw", self.draw_cb) 50 53 51 54 self.title_original = _('Typing Turtle') 52 55 self.title_src = self.title_original 53 56 self.title_text = '' 54 57 55 def expose_cb(self, area, event):58 def draw_cb(self, area, cr): 56 59 bounds = self.get_allocation() 57 60 58 cr = self.window.cairo_create()59 60 61 # Background picture. 61 62 x = (bounds.width - self.backgroundpixbuf.get_width())/2 62 cr.set_source_pixbuf(self.backgroundpixbuf, 0, 0) 63 64 Gdk.cairo_set_source_pixbuf(cr, self.backgroundpixbuf, 0, 0) 63 65 cr.rectangle(x, 0, self.backgroundpixbuf.get_width(), 64 66 self.backgroundpixbuf.get_height()) 65 67 cr.paint() 66 68 67 cr = pangocairo.CairoContext(cr)68 69 cr.set_source_rgb(0, 0, 0) 69 self.pango_layout = cr.create_layout()70 self.pango_layout = PangoCairo.create_layout(cr) 70 71 self.pango_layout.set_font_description( 71 pango.FontDescription(TitleScene.TITLE_FONT)) 72 self.pango_layout.set_text(unicode(self.title_original)) 72 Pango.FontDescription(TitleScene.TITLE_FONT)) 73 self.pango_layout.set_text(unicode(self.title_original), 74 len(self.title_original)) 73 75 74 76 original_size = self.pango_layout.get_size() 75 self.x_text = (bounds.width - original_size[0] / pango.SCALE) - \77 self.x_text = (bounds.width - original_size[0] / Pango.SCALE) - \ 76 78 TitleScene.TITLE_OFFSET[0] 77 79 self.y_text = TitleScene.TITLE_OFFSET[1] 78 80 79 gobject.timeout_add(50, self.timer_cb)81 GObject.timeout_add(50, self.timer_cb) 80 82 81 83 def draw_text(self): 82 84 # Animated Typing Turtle title. 83 cr = self.window.cairo_create() 85 window = self.get_window() 86 if window is None: 87 return 88 cr = window.cairo_create() 84 89 85 90 cr.move_to(self.x_text, self.y_text) 86 self.pango_layout.set_text(unicode(self.title_text)) 87 cr.show_layout(self.pango_layout) 88 cr.stroke() 91 self.pango_layout.set_text(unicode(self.title_text), 92 len(self.title_text)) 93 PangoCairo.update_layout(cr, self.pango_layout) 94 PangoCairo.show_layout(cr, self.pango_layout) 89 95 90 96 def timer_cb(self): 91 97 if len(self.title_src) > 0: -
typingturtle.py
diff --git a/typingturtle.py b/typingturtle.py index ad6c6cb..78d2fe6 100755
a b from port import json 25 25 #dbgp.client.brkOnExcept(host='192.168.1.104', port=12900) 26 26 27 27 # there is need to set up localization. 28 # since sugar .activity.main already seted up gettext envronment28 # since sugar3.activity.main already seted up gettext envronment 29 29 #locale.setlocale(locale.LC_ALL, '') 30 30 31 # Import PyGTK. 32 import gobject, pygtk, gtk, pango 31 32 from gi.repository import Gtk 33 33 34 34 # Import Sugar UI modules. 35 import sugar.activity.activity 36 from sugar.graphics import * 37 from sugar.graphics import toolbutton 38 from sugar import profile 39 40 OLD_TOOLBAR = False 41 try: 42 from sugar.graphics.toolbarbox import ToolbarBox 43 from sugar.activity.widgets import StopButton 44 from sugar.activity.widgets import ActivityToolbarButton 45 except ImportError: 46 OLD_TOOLBAR = True 35 import sugar3.activity.activity 36 from sugar3.graphics import * 37 from sugar3.graphics import toolbutton 38 from sugar3 import profile 39 40 from sugar3.graphics.toolbarbox import ToolbarBox 41 from sugar3.activity.widgets import StopButton 42 from sugar3.activity.widgets import ActivityToolbarButton 47 43 48 44 # Initialize logging. 49 45 log = logging.getLogger('Typing Turtle') … … log.setLevel(logging.DEBUG) 51 47 logging.basicConfig() 52 48 53 49 # Change to bundle directory. 54 bundle_path = sugar .activity.activity.get_bundle_path()50 bundle_path = sugar3.activity.activity.get_bundle_path() 55 51 os.chdir(bundle_path) 56 52 53 # Set correct DPI for Rsvg and Screen 54 from gi.repository import PangoCairo 55 56 def _get_screen_dpi(): 57 xft_dpi = Gtk.Settings.get_default().get_property('gtk-xft-dpi') 58 dpi = float(xft_dpi / 1024) 59 logging.debug('Setting dpi to: %f', dpi) 60 # HACK: if the DPI detected is 200.0 it seems we are on an XO, so 61 # we return 133 because the XO manage its resolution in a complex 62 # way. More information here: 63 # http://wiki.laptop.org/go/Display 64 if 200 == int(dpi): 65 return 133 66 return dpi 67 68 dpi = _get_screen_dpi() 69 font_map_default = PangoCairo.font_map_get_default() 70 font_map_default.set_resolution(dpi) 71 57 72 # Import activity modules. 58 73 import mainscreen, editlessonlistscreen 59 74 … … import mainscreen, editlessonlistscreen 61 76 # 62 77 # It owns the main application window, and all the various toolbars and options. 63 78 # Activity Screens are stored in a stack, with the currently active screen on top. 64 class TypingTurtle(sugar .activity.activity.Activity):79 class TypingTurtle(sugar3.activity.activity.Activity): 65 80 def __init__ (self, handle): 66 sugar .activity.activity.Activity.__init__(self, handle)81 sugar3.activity.activity.Activity.__init__(self, handle) 67 82 self.set_title(_("Typing Turtle")) 68 83 self.max_participants = 1 69 84 70 85 self.build_toolbox() 71 86 72 87 self.screens = [] 73 self.screenbox = gtk.VBox()88 self.screenbox = Gtk.VBox() 74 89 75 90 self.nick = profile.get_nick_name() 76 91 … … class TypingTurtle(sugar.activity.activity.Activity): 92 107 93 108 self.show_all() 94 109 95 self.editorbtn = sugar .graphics.toolbutton.ToolButton('view-source')110 self.editorbtn = sugar3.graphics.toolbutton.ToolButton('view-source') 96 111 self.editorbtn.set_tooltip(_("Edit Lessons")) 97 112 self.editorbtn.connect('clicked', self.editor_clicked_cb) 98 113 99 if OLD_TOOLBAR: 100 # Hide the sharing button from the activity toolbar since 101 # we don't support sharing. 102 activity_toolbar = self.tbox.get_activity_toolbar() 103 activity_toolbar.share.props.visible = False 104 105 share_idx = activity_toolbar.get_item_index(activity_toolbar.share) 106 activity_toolbar.insert(self.editorbtn, share_idx) 107 else: 108 activity_toolbar = self.toolbar_box.toolbar 109 activity_toolbar.insert(self.editorbtn, 1) 114 activity_toolbar = self.toolbar_box.toolbar 115 activity_toolbar.insert(self.editorbtn, 1) 110 116 111 117 self.editorbtn.show_all() 112 118 113 119 def build_toolbox(self): 114 if OLD_TOOLBAR: 115 self.tbox = sugar.activity.activity.ActivityToolbox(self) 116 self.tbox.show_all() 117 self.set_toolbox(self.tbox) 118 else: 119 self.toolbar_box = ToolbarBox() 120 self.toolbar_box = ToolbarBox() 120 121 121 122 123 122 activity_button = ActivityToolbarButton(self) 123 self.toolbar_box.toolbar.insert(activity_button, 0) 124 activity_button.show() 124 125 125 separator = gtk.SeparatorToolItem()126 127 128 126 separator = Gtk.SeparatorToolItem() 127 separator.props.draw = False 128 separator.set_expand(True) 129 self.toolbar_box.toolbar.insert(separator, -1) 129 130 130 131 self.toolbar_box.toolbar.insert(StopButton(self), -1) 131 132 132 133 133 self.set_toolbar_box(self.toolbar_box) 134 self.toolbar_box.show_all() 134 135 135 136 def editor_clicked_cb(self, btn): 136 137 self.push_screen(editlessonlistscreen.EditLessonListScreen(self, self.mainscreen.lessons)) … … class TypingTurtle(sugar.activity.activity.Activity): 146 147 147 148 self.screenbox.remove(oldscreen) 148 149 149 self.screenbox.pack_start(screen, True, True )150 self.screenbox.pack_start(screen, True, True, 0) 150 151 self.screens.append(screen) 151 152 152 153 try: … … class TypingTurtle(sugar.activity.activity.Activity): 172 173 except: 173 174 pass 174 175 175 self.screenbox.pack_start(screen )176 self.screenbox.pack_start(screen, True, True, 0) 176 177 177 178 def add_history(self, entry): 178 179 self.data['history'].append(entry)