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  
    1616
    1717import math
    1818import random, datetime
    19 import pangocairo
    2019
    2120from gettext import gettext as _
    2221
    23 import gobject, pygtk, gtk, pango
     22from gi.repository import Gtk
     23from gi.repository import Gdk
     24from gi.repository import GObject
     25from gi.repository import Pango
     26from gi.repository import PangoCairo
    2427
    2528import medalscreen
    2629
    class Balloon: 
    4144        self.size = max(100, 50 + len(word) * 20)
    4245        self.color = random.choice(BALLOON_COLORS)
    4346
    44 class BalloonGame(gtk.VBox):
     47class BalloonGame(Gtk.VBox):
    4548    def __init__(self, lesson, activity):
    46         gtk.VBox.__init__(self)
     49        GObject.GObject.__init__(self)
    4750       
    4851        self.lesson = lesson
    4952        self.activity = activity
    5053       
    5154        # Build title bar.
    52         title = gtk.Label()
     55        title = Gtk.Label()
    5356        title.set_markup("<span size='20000'><b>" + lesson['name'] + "</b></span>")
    5457        title.set_alignment(1.0, 0.0)
    5558       
    56         stoplabel = gtk.Label(_('Go Back'))
    57         stopbtn =  gtk.Button()
     59        stoplabel = Gtk.Label(label=_('Go Back'))
     60        stopbtn =  Gtk.Button()
    5861        stopbtn.add(stoplabel)
    5962        stopbtn.connect('clicked', self.stop_cb)
    6063       
    61         hbox = gtk.HBox()
     64        hbox = Gtk.HBox()
    6265        hbox.pack_start(stopbtn, False, False, 10)
    6366        hbox.pack_end(title, False, False, 10)
    6467       
    6568        # 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)
    6871
    6972        # Connect keyboard grabbing and releasing callbacks.       
    7073        self.area.connect('realize', self.realize_cb)
    7174        self.area.connect('unrealize', self.unrealize_cb)
    7275
    7376        self.pack_start(hbox, False, False, 10)
    74         self.pack_start(self.area, True, True)
     77        self.pack_start(self.area, True, True, 0)
    7578       
    7679        self.show_all()
    7780       
    class BalloonGame(gtk.VBox): 
    8891        self.finished = False
    8992
    9093        # 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)
    9295   
    9396    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)
    9598        self.key_press_cb_id = self.activity.connect('key-press-event', self.key_cb)
    9699
    97100        # 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)
    101104        #widget.window.set_cursor(cursor)
    102105       
    103106    def unrealize_cb(self, widget):
    class BalloonGame(gtk.VBox): 
    106109    def stop_cb(self, widget):
    107110        # Stop the animation loop.
    108111        if self.update_timer:
    109             gobject.source_remove(self.update_timer)
     112            GObject.source_remove(self.update_timer)
    110113       
    111114        self.activity.pop_screen()
    112115
    113116    def key_cb(self, widget, event):
    114117        # 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):
    116119            return False
    117120
    118121        # Extract information about the key pressed.
    119         key = gtk.gdk.keyval_to_unicode(event.keyval)
     122        key = Gdk.keyval_to_unicode(event.keyval)
    120123        if key != 0: key = unichr(key)
    121124
    122125        if self.finished:
    123             key_name = gtk.gdk.keyval_name(event.keyval)
     126            key_name = Gdk.keyval_name(event.keyval)
    124127            if key_name == 'Return':
    125128                self.activity.pop_screen()
    126129
    class BalloonGame(gtk.VBox): 
    159162   
    160163    def tick(self):
    161164        if self.finished:
    162             return
     165            return False
    163166
    164167        self.bounds = self.area.get_allocation()
    165168           
    class BalloonGame(gtk.VBox): 
    213216        # Draw text
    214217        title = _('You finished!') + '\n'
    215218
    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')))
    221226        size = pango_layout.get_size()
    222         tx = x + (w / 2) - (size[0] / pango.SCALE) / 2
     227        tx = x + (w / 2) - (size[0] / Pango.SCALE) / 2
    223228        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)
    227232
    228233        report = ''
    229234        report += _('Your score was %(score)d.') % { 'score': self.score } + '\n'
    class BalloonGame(gtk.VBox): 
    232237        report += '\n'
    233238        report += _('Press the ENTER key to continue.')
    234239   
    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))
    240246        size = pango_layout.get_size()
    241         sx = x + w / 2 - (size[0] / pango.SCALE) / 2
     247        sx = x + w / 2 - (size[0] / Pango.SCALE) / 2
    242248        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)
    247252
    248253    def finish_game(self):
    249254        self.finished = True
    class BalloonGame(gtk.VBox): 
    323328        cr.fill()
    324329        cr.restore()
    325330
    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))
    331338        size = pango_layout.get_size()
    332         x = x - (size[0] / pango.SCALE) / 2
    333         y = y - (size[1] / pango.SCALE) / 2
    334         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)
    337344
    338345    def add_score(self, num):
    339346        self.score += num
    class BalloonGame(gtk.VBox): 
    341348
    342349    def queue_draw_score(self):
    343350        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'))
    345352        size = layout.get_size()
    346         x = self.bounds.width-20-size[0]/pango.SCALE
     353        x = self.bounds.width-20-size[0]/Pango.SCALE
    347354        y = 20
    348355        self.queue_draw_area(x, y, x+size[0], y+size[1])
    349356
    350357    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
    356366        size = pango_layout.get_size()
    357         x = self.bounds.width - 20 - size[0] / pango.SCALE
     367        x = self.bounds.width - 20 - size[0] / Pango.SCALE
    358368        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)
    362372
    363373    def draw_instructions(self, cr):
    364374        # 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))
    370380        size = pango_layout.get_size()
    371         x = (self.bounds.width - size[0] / pango.SCALE) / 2
    372         y = self.bounds.height - 20 - size[1] / pango.SCALE
    373         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)
    376386
    377     def draw(self):
     387    def draw(self, cr):
    378388        self.bounds = self.area.get_allocation()
    379389
    380         cr = self.area.window.cairo_create()
    381 
    382390        # Draw background.
    383391        cr.set_source_rgb(0.915, 0.915, 1)
    384392        cr.rectangle(0, 0, self.bounds.width, self.bounds.height)
    class BalloonGame(gtk.VBox): 
    390398
    391399        if self.finished:
    392400            self.draw_results(cr)
    393 
    394401        else:
    395402            self.draw_instructions(cr)
    396403
    397404            self.draw_score(cr)
    398405
    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 _ 
    2222from port import json
    2323from port import chooser
    2424
    25 # Import PyGTK.
    26 import gobject, pygtk, gtk, pango
     25from gi.repository import Gtk
     26from gi.repository import GObject
    2727
    2828# Import Sugar UI modules.
    29 import sugar.activity.activity
    30 import sugar.graphics.style
    31 import sugar.graphics.alert
    32 import sugar.mime
    33 import sugar.datastore.datastore
     29import sugar3.activity.activity
     30import sugar3.graphics.style
     31import sugar3.graphics.alert
     32import sugar3.mime
     33import sugar3.datastore.datastore
    3434
    3535# Import activity modules.
    3636import editlessonscreen
    3737
    38 class EditLessonListScreen(gtk.VBox):
     38class EditLessonListScreen(Gtk.VBox):
    3939    def __init__(self, activity, lessons):
    40         gtk.VBox.__init__(self)
     40        GObject.GObject.__init__(self)
    4141
    4242        self.activity = activity
    4343        self.lessons = lessons
    4444
    4545        # Add the header.
    46         title = gtk.Label()
     46        title = Gtk.Label()
    4747        title.set_markup("<span size='20000'><b>" + _("Edit Lessons") + "</b></span>")
    4848        title.set_alignment(1.0, 0.0)
    4949       
    50         stoplabel = gtk.Label(_('Go Back'))
    51         stopbtn = gtk.Button()
     50        stoplabel = Gtk.Label(label=_('Go Back'))
     51        stopbtn = Gtk.Button()
    5252        stopbtn.add(stoplabel)
    5353        stopbtn.connect('clicked', self.stop_clicked_cb)
    5454       
    55         titlebox = gtk.HBox()
     55        titlebox = Gtk.HBox()
    5656        titlebox.pack_start(stopbtn, False, False, 10)
    5757        titlebox.pack_end(title, False, False, 10)
    5858
    5959        # Add the lesson list.
    60         self.treeview = gtk.TreeView()
     60        self.treeview = Gtk.TreeView()
    6161        self.treeview.set_rules_hint(True)
    6262        self.treeview.set_enable_search(False)
    6363
    class EditLessonListScreen(gtk.VBox): 
    6666
    6767        # Note that the only thing we store in our liststore is the lesson id.
    6868        # 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)
    7070        self.treeview.set_model(self.liststore)
    7171
    7272        # Construct the columns.
    73         renderer = gtk.CellRendererText()
    74         col = gtk.TreeViewColumn(_('Name'), renderer)
     73        renderer = Gtk.CellRendererText()
     74        col = Gtk.TreeViewColumn(_('Name'), renderer)
    7575        col.set_cell_data_func(renderer, self.name_render_cb)
    7676        self.treeview.append_column(col)
    7777
    78         renderer = gtk.CellRendererText()
    79         col = gtk.TreeViewColumn(_('Description'), renderer)
     78        renderer = Gtk.CellRendererText()
     79        col = Gtk.TreeViewColumn(_('Description'), renderer)
    8080        col.set_cell_data_func(renderer, self.description_render_cb)
    8181        col.set_expand(True)
    8282        self.treeview.append_column(col)
    8383
    84         renderer = gtk.CellRendererText()
    85         col = gtk.TreeViewColumn(_('Type'), renderer)
     84        renderer = Gtk.CellRendererText()
     85        col = Gtk.TreeViewColumn(_('Type'), renderer)
    8686        col.set_cell_data_func(renderer, self.type_render_cb)
    8787        col.set_expand(False)
    8888        self.treeview.append_column(col)
    8989
    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)
    9292        scroll.add(self.treeview)
    9393
    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()
    9696        self.importbtn.add(importlabel)
    9797        self.importbtn.connect('clicked', self.import_clicked_cb)
    9898       
    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()
    101101        self.exportbtn.add(exportlabel)
    102102        self.exportbtn.connect('clicked', self.export_clicked_cb)
    103103       
    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()
    106106        self.defaultsbtn.add(exportlabel)
    107107        self.defaultsbtn.connect('clicked', self.set_default_clicked_cb)
    108108       
    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'))
    111111        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'))
    114114        self.delbtn.connect('clicked', self.del_lesson_clicked_cb)
    115115        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'))
    118118        self.moveupbtn.connect('clicked', self.move_lesson_up_clicked_cb)
    119119        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'))
    122122        self.movedownbtn.connect('clicked', self.move_lesson_down_clicked_cb)
    123123        self.movedownbtn.set_sensitive(False)
    124124
    125         btnbox = gtk.HBox()
     125        btnbox = Gtk.HBox()
    126126        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)
    128128        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)
    133133
    134134        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)
    136136        self.pack_start(scroll, True, True, 10)
    137137        self.pack_start(btnbox, False, False, 10)
    138138
    class EditLessonListScreen(gtk.VBox): 
    197197        if len(self.lessons) > 1:
    198198            path = self.treeview.get_cursor()[0]
    199199            if path:
    200                 msg = sugar.graphics.alert.ConfirmationAlert()
     200                msg = sugar3.graphics.alert.ConfirmationAlert()
    201201                msg.props.title = _('Delete Lesson?')
    202202                msg.props.msg = _('Deleting the lesson will erase the lesson content.')
    203203       
    204204                def alert_response_cb(alert, response_id, self, id):
    205205                    self.activity.remove_alert(alert)
    206                     if response_id is gtk.RESPONSE_OK:
     206                    if response_id is Gtk.ResponseType.OK:
    207207                        self.lessons.pop(id)
    208208                        del self.liststore[id]
    209209                        self.treeview.get_selection().select_path(id)
    class EditLessonListScreen(gtk.VBox): 
    294294   
    295295    def export_clicked_cb(self, btn):
    296296        # Create the new journal entry
    297         fileObject = sugar.datastore.datastore.create()
     297        fileObject = sugar3.datastore.datastore.create()
    298298
    299299        meta = self.activity.metadata
    300300        fileObject.metadata['title'] = meta['title'] + _(' (Exported Lessons)')
    class EditLessonListScreen(gtk.VBox): 
    312312        finally:
    313313            fd.close()
    314314       
    315         sugar.datastore.datastore.write(fileObject, transfer_ownership=True)
     315        sugar3.datastore.datastore.write(fileObject, transfer_ownership=True)
    316316        fileObject.destroy()
    317317        del fileObject
    318318
    319319    def set_default_clicked_cb(self, btn):
    320320        code = locale.getdefaultlocale()[0] or 'en_US'
    321         path = sugar.activity.activity.get_bundle_path() + '/lessons/%s.lessons' % code
     321        path = sugar3.activity.activity.get_bundle_path() + '/lessons/%s.lessons' % code
    322322       
    323323        fd = open(path, 'w')
    324324       
    class EditLessonListScreen(gtk.VBox): 
    328328           
    329329        finally:
    330330            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  
    2020import logging, os, math, time, copy, locale, datetime, random, re
    2121from gettext import gettext as _
    2222
    23 # Import PyGTK.
    24 import gobject, pygtk, gtk, pango
     23from gi.repository import Gtk
     24from gi.repository import GObject
     25from gi.repository import Pango
    2526
    2627# Import Sugar UI modules.
    27 import sugar.activity.activity
    28 import sugar.graphics.style
    29 import sugar.graphics.icon
     28import sugar3.activity.activity
     29import sugar3.graphics.style
     30import sugar3.graphics.icon
    3031
    3132# Import lessonbuilder functions.
    3233import lessonbuilder
    3334
    34 class EditLessonScreen(gtk.VBox):
     35class EditLessonScreen(Gtk.VBox):
    3536    def __init__(self, activity, lesson):
    36         gtk.VBox.__init__(self)
     37        GObject.GObject.__init__(self)
    3738        self.set_border_width(10)
    3839
    3940        self.activity = activity
    class EditLessonScreen(gtk.VBox): 
    4243        self.in_build = False
    4344       
    4445        # Add the header.
    45         title = gtk.Label()
     46        title = Gtk.Label()
    4647        title.set_markup("<span size='20000'><b>" + _("Edit a Lesson") + "</b></span>")
    4748        title.set_alignment(1.0, 0.0)
    4849       
    49         stoplabel = gtk.Label(_('Go Back'))
    50         stopbtn = gtk.Button()
     50        stoplabel = Gtk.Label(label=_('Go Back'))
     51        stopbtn = Gtk.Button()
    5152        stopbtn.add(stoplabel)
    5253        stopbtn.connect('clicked', self.stop_clicked_cb)
    5354               
    54         titlebox = gtk.HBox()
     55        titlebox = Gtk.HBox()
    5556        titlebox.pack_start(stopbtn, False, False, 10)
    5657        titlebox.pack_end(title, False, False, 10)
    5758
    58         self.vp = gtk.Viewport()
     59        self.vp = Gtk.Viewport()
    5960
    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)
    6263        self.scroll.add(self.vp)
    6364
    6465        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)
    6667        self.pack_start(self.scroll, True, True, 0)
    6768
    6869        self.build()
    class EditLessonScreen(gtk.VBox): 
    7071        self.show_all()
    7172
    7273    def build_generate(self):
    73         generatebox = gtk.VBox()
     74        generatebox = Gtk.VBox()
    7475        generatebox.set_spacing(5)
    7576
    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'))
    7980       
    80         generatebox.newkeysent = gtk.Entry()
     81        generatebox.newkeysent = Gtk.Entry()
    8182        generatebox.newkeysent.set_width_chars(8)
    82         generatebox.knownkeysent = gtk.Entry()
     83        generatebox.knownkeysent = Gtk.Entry()
    8384        generatebox.knownkeysent.set_width_chars(15)
    84         generatebox.lengthent = gtk.Entry()
     85        generatebox.lengthent = Gtk.Entry()
    8586        generatebox.lengthent.set_width_chars(5)
    8687        generatebox.lengthent.set_text('60')
    8788       
    88         oklabel = gtk.Label()
     89        oklabel = Gtk.Label()
    8990        oklabel.set_markup(_('Generate!'))
    90         okbtn = gtk.Button()
     91        okbtn = Gtk.Button()
    9192        okbtn.add(oklabel)
    9293        okbtn.connect('clicked', self.generate_ok_clicked_cb, generatebox)
    9394        okbtn.set_alignment(0.5, 0.5)
    9495
    95         box = gtk.HBox()
     96        box = Gtk.HBox()
    9697        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)
    104105        box.show_all()
    105106       
    106         wordslabel = gtk.Label()
     107        wordslabel = Gtk.Label()
    107108        wordslabel.set_markup(_('Edit Word List'))
    108         wordsbtn = gtk.Button()
     109        wordsbtn = Gtk.Button()
    109110        wordsbtn.add(wordslabel)
    110111        wordsbtn.connect('clicked', self.generate_words_clicked_cb)
    111112        wordsbtn.set_alignment(0.5, 0.5)
    112113
    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)
    115116       
    116117        return generatebox
    117118
    118119    def build_step(self, step, idx):
    119         stepbox = gtk.VBox()
     120        stepbox = Gtk.VBox()
    120121        stepbox.set_spacing(5)
    121122
    122         steplabel = gtk.Label()
     123        steplabel = Gtk.Label()
    123124        steplabel.set_markup("<span size='x-large' weight='bold'>" + (_('Step #%d') % (idx+1)) + "</span>")
    124125        steplabel.set_alignment(0.0, 0.5)
    125126        steplabel.set_padding(10, 0)
    126127
    127128        # Build the step type combo box.
    128         stepbox.typecombo = gtk.combo_box_new_text()
     129        stepbox.typecombo = Gtk.ComboBoxText()
    129130        stepbox.typecombo.append_text(_('Keys'))
    130131        stepbox.typecombo.append_text(_('Words'))
    131132
    class EditLessonScreen(gtk.VBox): 
    136137            stepbox.typecombo.set_active(1)
    137138       
    138139        # 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'))
    141142        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'))
    144145        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'))
    147148        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'))
    150151        movedownbtn.connect('clicked', self.move_step_down_clicked_cb, idx)
    151152
    152153        if idx == 0:
    class EditLessonScreen(gtk.VBox): 
    154155        if idx == len(self.lesson['steps']) - 1:
    155156            movedownbtn.set_sensitive(False)
    156157
    157         btnbox = gtk.HBox()
    158         btnbox.pack_start(steplabel, False, False)
     158        btnbox = Gtk.HBox()
     159        btnbox.pack_start(steplabel, False, False, 0)
    159160        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)
    164165
    165166        # Build the instructions entry.
    166         instlabel = gtk.Label()
     167        instlabel = Gtk.Label()
    167168        instlabel.set_markup("<span size='large' weight='bold'>" + _('Instructions') + "</span>")
    168169        instlabel.set_alignment(0.0, 0.5)
    169170        instlabel.set_padding(20, 0)
    170171
    171172        self.labelsizegroup.add_widget(instlabel)
    172173
    173         stepbox.insttext = gtk.TextView(gtk.TextBuffer())
    174         stepbox.insttext.props.wrap_mode = gtk.WRAP_WORD
    175         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)
    178179        instscroll.add(stepbox.insttext)
    179180        instscroll.set_size_request(-1, 75)
    180181        stepbox.insttext.get_buffer().set_text(step['instructions'])
    181182
    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)
    185186
    186187        # Build the text entry.
    187         textlabel = gtk.Label()
     188        textlabel = Gtk.Label()
    188189        textlabel.set_markup("<span size='large' weight='bold'>" + _('Text') + "</span>")
    189190        textlabel.set_alignment(0.0, 0.5)
    190191        textlabel.set_padding(20, 0)
    191192
    192193        self.labelsizegroup.add_widget(textlabel)
    193194
    194         stepbox.texttext = gtk.TextView(gtk.TextBuffer())
    195         stepbox.texttext.props.wrap_mode = gtk.WRAP_WORD
    196         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)
    199200        textscroll.add(stepbox.texttext)
    200201        textscroll.set_size_request(-1, 100)
    201202        stepbox.texttext.get_buffer().set_text(step['text'])
    202203
    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)
    206207
    207         sizegroup = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)   
     208        sizegroup = Gtk.SizeGroup(Gtk.SizeGroupMode.HORIZONTAL)
    208209        sizegroup.add_widget(instlabel)
    209210        sizegroup.add_widget(textlabel)   
    210211
    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)
    214215       
    215216        return stepbox
    216217
    217218    def build_medal(self, medal, name):
    218         box = gtk.HBox()
     219        box = Gtk.HBox()
    219220
    220         label = gtk.Label()
     221        label = Gtk.Label()
    221222        label.set_markup("<span size='large' weight='bold'>" + name + "</span>")
    222223        label.set_alignment(0.0, 0.5)
    223224        label.set_padding(20, 0)
    224225
    225226        self.labelsizegroup.add_widget(label)
    226227       
    227         box.pack_start(label, False, False)
     228        box.pack_start(label, False, False, 0)
    228229
    229230        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'))
    232233           
    233             box.accent = gtk.Entry()
    234             box.wpment = gtk.Entry()
     234            box.accent = Gtk.Entry()
     235            box.wpment = Gtk.Entry()
    235236
    236237            box.accent.set_text(str(medal['accuracy']))
    237238            box.wpment.set_text(str(medal['wpm']))
    238239       
    239240            box.pack_start(acclabel, False, False, 10)
    240             box.pack_start(box.accent, False, False)
     241            box.pack_start(box.accent, False, False, 0)
    241242            box.pack_start(wpmlabel, False, False, 10)
    242             box.pack_start(box.wpment, False, False)
     243            box.pack_start(box.wpment, False, False, 0)
    243244       
    244245        elif self.lesson['type'] == 'balloon':
    245             scorelabel = gtk.Label(_('Score'))
     246            scorelabel = Gtk.Label(label=_('Score'))
    246247           
    247             box.scoreent = gtk.Entry()
     248            box.scoreent = Gtk.Entry()
    248249            box.scoreent.set_text(str(medal['score']))
    249250       
    250251            box.pack_start(scorelabel, False, False, 10)
    251             box.pack_start(box.scoreent, False, False)
     252            box.pack_start(box.scoreent, False, False, 0)
    252253           
    253254        return box
    254255     
    255256    def build(self):
    256257        self.in_build = True
    257258       
    258         self.vbox = gtk.VBox()
     259        self.vbox = Gtk.VBox()
    259260        self.vbox.set_border_width(20)
    260261        self.vbox.set_spacing(5)
    261262       
    262         self.labelsizegroup = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)   
     263        self.labelsizegroup = Gtk.SizeGroup(Gtk.SizeGroupMode.HORIZONTAL)
    263264
    264265        # Lesson details widgets.
    265         detailslabel = gtk.Label()
     266        detailslabel = Gtk.Label()
    266267        detailslabel.set_markup("<span size='x-large'><b>" + _('Lesson Details') + "</b></span>")
    267268        detailslabel.set_alignment(0.0, 0.5)
    268269        detailslabel.set_padding(10, 0)
    269270
    270         namelabel = gtk.Label()
     271        namelabel = Gtk.Label()
    271272        namelabel.set_markup("<span size='large' weight='bold'>" + _('Name') + "</span>")
    272273        namelabel.set_alignment(0.0, 0.5)
    273274        namelabel.set_padding(20, 0)
    274275
    275         self.nameent = gtk.Entry()
     276        self.nameent = Gtk.Entry()
    276277        self.nameent.set_text(self.lesson['name'])
    277278
    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)
    281282       
    282         typelabel = gtk.Label()
     283        typelabel = Gtk.Label()
    283284        typelabel.set_markup("<span size='large' weight='bold'>" + _('Type') + "</span>")
    284285        typelabel.set_alignment(0.0, 0.5)
    285286        typelabel.set_padding(20, 0)
    286287
    287         self.textradio = gtk.RadioButton(None, _('Normal Lesson'))
     288        self.textradio = Gtk.RadioButton(None, _('Normal Lesson'))
    288289        self.textradio.connect('toggled', self.type_toggled_cb)
    289290       
    290         self.balloonradio = gtk.RadioButton(self.textradio, _('Balloon Game'))
     291        self.balloonradio = Gtk.RadioButton(self.textradio, _('Balloon Game'))
    291292        self.balloonradio.connect('toggled', self.type_toggled_cb)
    292293       
    293294        self.textradio.set_active(self.lesson['type'] == 'normal')
    294295        self.balloonradio.set_active(self.lesson['type'] == 'balloon')       
    295296
    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)
    300301       
    301         desclabel = gtk.Label()
     302        desclabel = Gtk.Label()
    302303        desclabel.set_markup("<span size='large' weight='bold'>" + _('Description') + "</span>")
    303304        desclabel.set_alignment(0.0, 0.5)
    304305        desclabel.set_padding(20, 0)
    305306
    306         self.desctext = gtk.TextView(gtk.TextBuffer())
    307         self.desctext.props.wrap_mode = gtk.WRAP_WORD
    308         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)
    310311        descscroll.add(self.desctext)
    311312        descscroll.set_size_request(-1, 75)
    312313        self.desctext.get_buffer().set_text(self.lesson['description'])
    313314
    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)
    317318
    318319        # Build the options.
    319         optslabel = gtk.Label()
     320        optslabel = Gtk.Label()
    320321        optslabel.set_markup("<span size='large' weight='bold'>" + _('Options') + "</span>")
    321322        optslabel.set_alignment(0.0, 0.5)
    322323        optslabel.set_padding(20, 0)
    323324
    324         self.mistakescheck = gtk.CheckButton(_('Allow Mistakes'))
     325        self.mistakescheck = Gtk.CheckButton(_('Allow Mistakes'))
    325326        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'))
    327328        self.backspacecheck.set_active(self.lesson.get('options', {}).get('backspace', True))
    328329
    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)
    333334           
    334335        self.labelsizegroup.add_widget(namelabel)
    335336        self.labelsizegroup.add_widget(typelabel)   
    336337        self.labelsizegroup.add_widget(desclabel)   
    337338        self.labelsizegroup.add_widget(optslabel)   
    338339 
    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)
    344345
    345346        # Build the generator.
    346         generatelabel = gtk.Label()
     347        generatelabel = Gtk.Label()
    347348        generatelabel.set_markup("<span size='x-large'><b>" + _('Automatic Lesson Generator') + "</b></span>")
    348349        generatelabel.set_alignment(0.0, 0.5)
    349350        generatelabel.set_padding(10, 0)
    350351
    351352        generatebox = self.build_generate()
    352353        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)
    354355       
    355356        self.has_normal_widgets = False
    356357        self.has_balloon_widgets = False
    class EditLessonScreen(gtk.VBox): 
    369370                stepbox = self.build_step(step, len(self.stepboxes))
    370371                self.stepboxes.append(stepbox)
    371372               
    372                 self.vbox.pack_start(stepbox, expand=False)
     373                self.vbox.pack_start(stepbox, False, True, 0)
    373374               
    374375        if self.lesson['type'] == 'balloon':
    375376            self.has_balloon_widgets = True
    class EditLessonScreen(gtk.VBox): 
    377378            if not self.lesson.has_key('words') or len(self.lesson['words']) == 0:
    378379                self.lesson['words'] = []
    379380           
    380             textlabel = gtk.Label()
     381            textlabel = Gtk.Label()
    381382            textlabel.set_markup("<span size='large' weight='bold'>" + _('Words') + "</span>")
    382383            textlabel.set_alignment(0.0, 0.5)
    383384            textlabel.set_padding(20, 0)
    384385
    385386            self.labelsizegroup.add_widget(textlabel)
    386387
    387             self.wordstext = gtk.TextView(gtk.TextBuffer())
    388             self.wordstext.props.wrap_mode = gtk.WRAP_WORD
    389             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)
    392393            textscroll.add(self.wordstext)
    393394            textscroll.set_size_request(-1, 200)
    394395            self.wordstext.get_buffer().set_text(' '.join(self.lesson['words']))
    395396   
    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)
    399400           
    400             self.vbox.pack_start(textbox, expand=False)
     401            self.vbox.pack_start(textbox, False, True, 0)
    401402
    402403        # Medal requirements widgets.
    403         medalslabel = gtk.Label()
     404        medalslabel = Gtk.Label()
    404405        medalslabel.set_markup("<span size='x-large'><b>" + _('Medal Requirements') + "</b></span>")
    405406        medalslabel.set_alignment(0.0, 0.5)
    406407        medalslabel.set_padding(10, 0)
    class EditLessonScreen(gtk.VBox): 
    412413        self.medalboxes.append(self.build_medal(self.lesson['medals'][1], _('Silver')))
    413414        self.medalboxes.append(self.build_medal(self.lesson['medals'][2], _('Gold')))
    414415       
    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)
    418419
    419420        self.vbox.show_all()
    420421       
    class EditLessonScreen(gtk.VBox): 
    555556    def generate_words_clicked_cb(self, btn):
    556557        self.activity.push_screen(WordListScreen(self.activity))
    557558
    558 class WordListScreen(gtk.VBox):
     559class WordListScreen(Gtk.VBox):
    559560    def __init__(self, activity):
    560         gtk.VBox.__init__(self)
     561        GObject.GObject.__init__(self)
    561562        self.set_border_width(10)
    562563
    563564        self.activity = activity
    564565       
    565566        # Add the header.
    566         title = gtk.Label()
     567        title = Gtk.Label()
    567568        title.set_markup("<span size='20000'><b>" + _("Edit Word List") + "</b></span>")
    568569        title.set_alignment(1.0, 0.0)
    569570       
    570         stoplabel = gtk.Label(_('Go Back'))
    571         stopbtn = gtk.Button()
     571        stoplabel = Gtk.Label(label=_('Go Back'))
     572        stopbtn = Gtk.Button()
    572573        stopbtn.add(stoplabel)
    573574        stopbtn.connect('clicked', self.stop_clicked_cb)
    574575       
    575         titlebox = gtk.HBox()
     576        titlebox = Gtk.HBox()
    576577        titlebox.pack_start(stopbtn, False, False, 10)
    577578        titlebox.pack_end(title, False, False, 10)
    578579
    579         subtitle = gtk.Label()
     580        subtitle = Gtk.Label()
    580581        subtitle.set_markup("<span size='10000'>" + _("Type or paste words here, for the Automatic Lesson Generator.  If empty, the dictionary will be used.") + "</span>")
    581582        subtitle.set_alignment(1.0, 0.0)
    582583
    583         self.wordlisttext = gtk.TextView(gtk.TextBuffer())
    584         self.wordlisttext.props.wrap_mode = gtk.WRAP_WORD
    585         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)
    587588        wordlistscroll.add(self.wordlisttext)
    588589        wordlistscroll.set_size_request(-1, 75)
    589590        self.wordlisttext.get_buffer().set_text(' '.join(self.activity.wordlist))
    590591
    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)
    595596       
    596597        self.show_all()
    597598
  • keyboard.py

    diff --git a/keyboard.py b/keyboard.py
    index 25e870e..90cbf98 100644
    a b  
    1616#!/usr/bin/env python
    1717# vi:sw=4 et
    1818
    19 import gtk
    2019import cairo
    2120import copy
    22 import rsvg
    2321import os, glob, re
    24 import pango
    25 import pangocairo
     22
     23from gi.repository import Gtk
     24from gi.repository import Pango
     25from gi.repository import PangoCairo
     26from gi.repository import Gdk
     27from gi.repository import GObject
     28from gi.repository import GdkPixbuf
     29
    2630import StringIO
    2731from port import json
    2832import subprocess
    class KeyboardImages: 
    132136            scale_width = int(scale_width * 1.1625)
    133137
    134138        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)
    136141            name = os.path.basename(filename)
    137142            self.images[name] = image
    138143
    class KeyboardData: 
    145150        self.letter_map = {}
    146151       
    147152        # Access the current GTK keymap.
    148         self.keymap = gtk.gdk.keymap_get_default()
     153        self.keymap = Gdk.Keymap.get_default()
    149154
    150155    def set_layout(self, layout):
    151156        self._build_key_list(layout)
    class KeyboardData: 
    235240
    236241    def format_key_sig(self, scan, state, group):
    237242        sig = 'scan%d' % scan
    238         if state & gtk.gdk.SHIFT_MASK:
     243        if state & Gdk.ModifierType.SHIFT_MASK:
    239244            sig += ' shift'
    240         if state & gtk.gdk.MOD5_MASK:
     245        if state & Gdk.ModifierType.MOD5_MASK:
    241246            sig += ' altgr'
    242247        if group != 0:
    243248            sig += ' group%d' % group
    class KeyboardData: 
    250255
    251256        state = 0
    252257        if m.group('shift'):
    253             state |= gtk.gdk.SHIFT_MASK
     258            state |= Gdk.ModifierType.SHIFT_MASK
    254259        if m.group('altgr'):
    255             state |= gtk.gdk.MOD5_MASK
     260            state |= Gdk.ModifierType.MOD5_MASK
    256261
    257262        scan = int(m.group('scan'))
    258263
    class KeyboardData: 
    278283        best_result = None
    279284       
    280285        for sig, l in self.letter_map.items():
    281             if unicode(l) == unicode(letter):
     286            if l == letter:
    282287                scan, state, group = self.parse_key_sig(sig)
    283288               
    284289                # Choose the key with the fewest modifiers.
    285290                score = 0
    286                 if state & gtk.gdk.SHIFT_MASK: score += 1
    287                 if state & gtk.gdk.MOD5_MASK: score += 1
     291                if state & Gdk.ModifierType.SHIFT_MASK: score += 1
     292                if state & Gdk.ModifierType.MOD5_MASK: score += 1
    288293                if score < best_score:
    289294                    best_score = score
    290295                    best_result = scan, state, group
    class KeyboardData: 
    295300                    return k, best_result[1], best_result[2]
    296301
    297302        # 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)
    300305        for e in entries:
    301306            for k in self.keys:
    302                 if k['key-scan'] == e[0]:
     307                if k['key-scan'] == e.keycode:
    303308                    # TODO: Level -> state calculations are hardcoded to what the XO keyboard does.
    304309                    # They were discovered through experimentation.
    305310                    state = 0
    306                     if e[2] & 1:
    307                         state |= gtk.gdk.SHIFT_MASK
    308                     if e[2] & 2:
    309                         state |= gtk.gdk.MOD5_MASK
    310                     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
    311316
    312317        # Fail!
    313318        return None, None, None
    class KeyboardData: 
    317322        if self.letter_map.has_key(sig):
    318323            return self.letter_map[sig]
    319324        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')
    323330
    324331        return ''
    325332
    326 class KeyboardWidget(KeyboardData, gtk.DrawingArea):
     333class KeyboardWidget(KeyboardData, Gtk.DrawingArea):
    327334    """A GTK widget which implements an interactive visual keyboard, with support
    328335       for custom data driven layouts."""
    329336
    330337    def __init__(self, image, root_window, poll_keys=False):
    331338        KeyboardData.__init__(self)
    332         gtk.DrawingArea.__init__(self)
     339        GObject.GObject.__init__(self)
    333340       
    334341        self.image = image
    335342        self.root_window = root_window
    class KeyboardWidget(KeyboardData, gtk.DrawingArea): 
    337344        # Match the image cache in dimensions.
    338345        self.set_size_request(image.width, image.height)
    339346
    340         self.connect("expose-event", self._expose_cb)
     347        self.connect("draw", self._draw_cb)
    341348       
    342         #self.modify_font(pango.FontDescription('Monospace 10'))
     349        #self.modify_font(Pango.FontDescription('Monospace 10'))
    343350       
    344351        # Active language group and modifier state.
    345352        # See http://www.pygtk.org/docs/pygtk/class-gdkkeymap.html for more
    class KeyboardWidget(KeyboardData, gtk.DrawingArea): 
    354361       
    355362        self.draw_hands = False
    356363       
    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])
    358365
    359366        # Connect keyboard grabbing and releasing callbacks.       
    360367        if poll_keys:
    class KeyboardWidget(KeyboardData, gtk.DrawingArea): 
    363370
    364371    def _realize_cb(self, widget):
    365372        # 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)
    367374        self.key_press_cb_id = self.root_window.connect('key-press-event', self.key_press_release_cb)
    368375        self.key_release_cb_id = self.root_window.connect('key-release-event', self.key_press_release_cb)
    369376
    class KeyboardWidget(KeyboardData, gtk.DrawingArea): 
    412419            (x1 + corner, y2),
    413420            (x1, y2 - corner),
    414421            (x1, y1 + corner)
    415             ]
     422        ]
    416423
    417         cr.save()
    418424        cr.new_path()
    419425        cr.set_source_rgb(0.396, 0.698, 0.392)
    420426        cr.set_line_width(2)
    421         cr.move_to(*points[0])
    422427        for point in points:
    423428            cr.line_to(*point)
    424         cr.line_to(*points[0])
    425429        cr.close_path()
    426430        cr.fill_preserve()
    427431        cr.stroke()
    428         cr.restore()
    429432
    430433        text = ''
    431434        if k['key-label']:
    class KeyboardWidget(KeyboardData, gtk.DrawingArea): 
    434437            text = self.get_letter_for_key_state_group(
    435438                k, self.active_state, self.active_group)
    436439
    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))
    439446
    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)
    447450
    448451    def _expose_hands(self, cr):
    449452        lhand_image = self.image.images['OLPC_Lhand_HOMEROW.svg']
    class KeyboardWidget(KeyboardData, gtk.DrawingArea): 
    463466                        rhand_image = handle
    464467
    465468                # Put the other hand on the SHIFT key if needed.
    466                 if state & gtk.gdk.SHIFT_MASK:
     469                if state & Gdk.ModifierType.SHIFT_MASK:
    467470                    if finger[0] == 'L':
    468471                        rhand_image = self.image.images['OLPC_Rhand_SHIFT.svg']
    469472                    else:
    class KeyboardWidget(KeyboardData, gtk.DrawingArea): 
    471474
    472475                # TODO: Do something about ALTGR.
    473476
    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()
    477478
    478         # README: these values (cairo.Matrix) are taken seeing the image on the
    479         # screen, I think we should find a way to calculate them
    480479        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()
    484484
    485485        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()
    492490
     491    def _draw_cb(self, area, cr):
    493492        # Draw the keys.
    494493        for k in self.keys:
    495494            self._draw_key(k, cr)
    class KeyboardWidget(KeyboardData, gtk.DrawingArea): 
    502501    def key_press_release_cb(self, widget, event):
    503502        key = self.key_scan_map.get(event.hardware_keycode)
    504503        if key:
    505             key['key-pressed'] = event.type == gtk.gdk.KEY_PRESS
     504            key['key-pressed'] = event.type == Gdk.EventType.KEY_PRESS
    506505
    507506        # 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]
    509508
    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:
    511510            self.active_group = event.group
    512             self.active_state = state
     511            self.active_state = event.state
    513512
    514513            self.queue_draw()
    515514
    class KeyboardWidget(KeyboardData, gtk.DrawingArea): 
    556555        # Convert cairo.Surface to Pixbuf
    557556        pixbuf_data = StringIO.StringIO()
    558557        surface.write_to_png(pixbuf_data)
    559         pxb_loader = gtk.gdk.PixbufLoader(image_type='png')
     558        pxb_loader = GdkPixbuf.PixbufLoader.new_with_type('png')
    560559        pxb_loader.write(pixbuf_data.getvalue())
    561560        temp_pix = pxb_loader.get_pixbuf()
    562561        pxb_loader.close()
  • keybuilder.py

    diff --git a/keybuilder.py b/keybuilder.py
    index bceab0d..28f6f97 100755
    a b  
    1919import sys
    2020import keyboard
    2121
    22 import gtk
     22from gi.repository import Gtk
    2323
    24 window = gtk.Window(gtk.WINDOW_TOPLEVEL)
     24window = Gtk.Window(Gtk.WindowType.TOPLEVEL)
    2525window.set_title("keyboard widget")
    26 window.connect("destroy", lambda w: gtk.main_quit())
     26window.connect("destroy", lambda w: Gtk.main_quit())
    2727window.show_all()
    2828window.realize()
    2929
    except: 
    3737    pass
    3838k.set_layout(keyboard.get_layout())
    3939
    40 savebtn = gtk.Button()
    41 savebtn.add(gtk.Label('Save Keys'))
     40savebtn = Gtk.Button()
     41savebtn.add(Gtk.Label(label='Save Keys'))
    4242savebtn.connect('clicked', lambda w: k.save_letter_map(sys.argv[1]))
    4343
    44 quitbtn = gtk.Button()
    45 quitbtn.add(gtk.Label('Quit'))
    46 quitbtn.connect('clicked', lambda w: gtk.main_quit())
     44quitbtn = Gtk.Button()
     45quitbtn.add(Gtk.Label(label='Quit'))
     46quitbtn.connect('clicked', lambda w: Gtk.main_quit())
    4747
    48 hbox = gtk.HBox()
    49 hbox.pack_start(savebtn)
    50 hbox.pack_start(quitbtn)
     48hbox = Gtk.HBox()
     49hbox.pack_start(savebtn, True, True, 0)
     50hbox.pack_start(quitbtn, True, True, 0)
    5151
    52 vbox = gtk.VBox()
    53 vbox.pack_start(k)
    54 vbox.pack_start(hbox)
     52vbox = Gtk.VBox()
     53vbox.pack_start(k, True, True, 0)
     54vbox.pack_start(hbox, True, True, 0)
    5555
    5656window.add(vbox)
    5757window.show_all()
    5858
    59 gtk.main()
     59Gtk.main()
    6060
  • lessonbuilder.py

    diff --git a/lessonbuilder.py b/lessonbuilder.py
    index b33a34e..c7c4d1a 100755
    a b from gettext import gettext as _ 
    2121from port import json
    2222
    2323# For modifier constants.
    24 import gtk
     24from gi.repository import Gtk
    2525
    2626# Set up remote debugging.
    2727#import dbgp.client
    def build_key_steps( 
    338338#        except:
    339339#            error("The '%s' letter (scan code %x) does not have a finger assigned." % (letter, key['key-scan']))
    340340#
    341 #        if state == gtk.gdk.SHIFT_MASK:
     341#        if state == Gdk.ModifierType.SHIFT_MASK:
    342342#            # Choose the finger to press the SHIFT key with.
    343343#            if key['key-finger'][0] == 'R':
    344344#                shift_finger = FINGERS['LP']
    def build_key_steps( 
    348348#            instructions = _('Press and hold the SHIFT key with your %(finger)s finger, ') % { 'finger': shift_finger }
    349349#            instructions += _('then press the %(letter)s key with your %(finger)s finger.') % { 'letter': letter, 'finger': finger }
    350350#
    351 #        elif state == gtk.gdk.MOD5_MASK:
     351#        elif state == Gdk.ModifierType.MOD5_MASK:
    352352#            instructions = _('Press and hold the ALTGR key, ')
    353353#            instructions += _('then press the %(letter)s key with your %(finger)s finger.') % { 'letter': letter, 'finger': finger }
    354354#
    355 #        elif state == gtk.gdk.SHIFT_MASK | gtk.gdk.MOD5_MASK:
     355#        elif state == Gdk.ModifierType.SHIFT_MASK | Gdk.ModifierType.MOD5_MASK:
    356356#            instructions = _('Press and hold the ALTGR and SHIFT keys, ')
    357357#            instructions += _('then press the %(letter)s key with your %(finger)s finger.') % { 'letter': letter, 'finger': finger }
    358358#
  • lessonscreen.py

    diff --git a/lessonscreen.py b/lessonscreen.py
    index cc75ef4..fb38bff 100644
    a b  
    1919import logging, os, math, time, copy, locale, datetime, random, re
    2020from gettext import gettext as _
    2121
    22 # Import PyGTK.
    23 import gobject, pygtk, gtk, pango
     22from gi.repository import Gtk
     23from gi.repository import Gdk
     24from gi.repository import GObject
    2425
    2526# Import Sugar UI modules.
    26 import sugar.activity.activity
    27 from sugar.graphics import *
     27import sugar3.activity.activity
     28from sugar3.graphics import *
    2829
    2930# Import activity modules.
    3031import keyboard, medalscreen
    FINGERS = { 
    4849    'RT': _('right thumb'),
    4950}
    5051
    51 class LessonScreen(gtk.VBox):
     52class LessonScreen(Gtk.VBox):
    5253    def __init__(self, lesson, keyboard_images, activity):
    53         gtk.VBox.__init__(self)
     54        GObject.GObject.__init__(self)
    5455       
    5556        self.lesson = lesson
    5657        self.keyboard_images = keyboard_images
    5758        self.activity = activity
    5859       
    5960        # Build the user interface.
    60         title = gtk.Label()
     61        title = Gtk.Label()
    6162        title.set_markup("<span size='x-large' weight='bold'>" + lesson['name'] + "</span>")
    6263        title.set_alignment(1.0, 0.0)
    6364       
    64         stoplabel = gtk.Label(_('Go Back'))
    65         stopbtn =  gtk.Button()
     65        stoplabel = Gtk.Label(label=_('Go Back'))
     66        stopbtn =  Gtk.Button()
    6667        stopbtn.add(stoplabel)
    6768        stopbtn.connect('clicked', self.stop_cb)
    6869       
    69         # TODO- These will be replaced by graphical displays using gtk.DrawingArea.
     70        # TODO- These will be replaced by graphical displays using Gtk.DrawingArea.
    7071        self.wpm = 0
    7172        self.accuracy = 0
    7273       
    73         self.wpmlabel = gtk.Label()
    74         self.accuracylabel = gtk.Label()
     74        self.wpmlabel = Gtk.Label()
     75        self.accuracylabel = Gtk.Label()
    7576       
    76         #self.wpmarea = gtk.DrawingArea()
     77        #self.wpmarea = Gtk.DrawingArea()
    7778        #self.wpmarea.connect('expose-event', self.wpm_expose_cb)
    78         #self.accuracyarea = gtk.DrawingArea()
     79        #self.accuracyarea = Gtk.DrawingArea()
    7980        #self.accuracyarea.connect('expose-event', self.accuracy_expose_cb)
    8081       
    81         hbox = gtk.HBox()
     82        hbox = Gtk.HBox()
    8283        hbox.pack_start(stopbtn, False, False, 10)
    8384        hbox.pack_start(self.wpmlabel, True, False, 10)
    8485        hbox.pack_start(self.accuracylabel, True, False, 10)
    8586        hbox.pack_end(title, False, False, 10)
    8687       
    8788        # Set up font styles.
    88         self.tagtable = gtk.TextTagTable()
    89         instructions_tag = gtk.TextTag('instructions')
    90         instructions_tag.props.justification = gtk.JUSTIFY_CENTER
     89        self.tagtable = Gtk.TextTagTable()
     90        instructions_tag = Gtk.TextTag.new('instructions')
     91        instructions_tag.props.justification = Gtk.Justification.CENTER
    9192        self.tagtable.add(instructions_tag)
    9293
    93         text_tag = gtk.TextTag('text')
     94        text_tag = Gtk.TextTag.new('text')
    9495        text_tag.props.family = 'Monospace'
    9596        self.tagtable.add(text_tag)
    9697       
    97         spacer_tag = gtk.TextTag('spacer')
     98        spacer_tag = Gtk.TextTag.new('spacer')
    9899        spacer_tag.props.size = 3000
    99100        self.tagtable.add(spacer_tag)
    100101       
    101         image_tag = gtk.TextTag('image')
    102         image_tag.props.justification = gtk.JUSTIFY_CENTER
     102        image_tag = Gtk.TextTag.new('image')
     103        image_tag.props.justification = Gtk.Justification.CENTER
    103104        self.tagtable.add(image_tag)
    104105       
    105         correct_copy_tag = gtk.TextTag('correct-copy')
     106        correct_copy_tag = Gtk.TextTag.new('correct-copy')
    106107        correct_copy_tag.props.family = 'Monospace'
    107108        correct_copy_tag.props.foreground = '#0000ff'
    108109        self.tagtable.add(correct_copy_tag)
    109110       
    110         incorrect_copy_tag = gtk.TextTag('incorrect-copy')
     111        incorrect_copy_tag = Gtk.TextTag.new('incorrect-copy')
    111112        incorrect_copy_tag.props.family = 'Monospace'
    112113        incorrect_copy_tag.props.foreground = '#ff0000'
    113114        self.tagtable.add(incorrect_copy_tag)
    114115       
    115116        # 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)
    118119        self.lessontext.set_editable(False)
    119120        self.lessontext.set_left_margin(20)
    120121        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])
    123124       
    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)
    126127        self.lessonscroll.add(self.lessontext)
    127128       
    128         frame = gtk.Frame()
     129        frame = Gtk.Frame()
    129130        frame.add(self.lessonscroll)
    130131       
    131132        self.keyboard = keyboard.KeyboardWidget(self.keyboard_images, self.activity)
    class LessonScreen(gtk.VBox): 
    140141        self.keyboard.set_layout(keyboard.get_layout())
    141142
    142143        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)
    145146       
    146147        # Connect keyboard grabbing and releasing callbacks.       
    147148        self.connect('realize', self.realize_cb)
    class LessonScreen(gtk.VBox): 
    154155        self.begin_lesson()
    155156       
    156157    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)
    158159        self.key_press_cb_id = self.activity.connect('key-press-event', self.key_cb)
    159160        self.key_release_cb_id = self.activity.connect('key-release-event', self.key_cb)
    160161       
    class LessonScreen(gtk.VBox): 
    164165
    165166    def start_timer(self):
    166167        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)
    168169
    169170    def stop_timer(self):
    170171        if self.timer_id:
    171             gobject.source_remove(self.timer_id)
     172            GObject.source_remove(self.timer_id)
    172173        self.start_time = None
    173174        self.timer_id = None
    174175
    class LessonScreen(gtk.VBox): 
    349350
    350351        # Extract information about the key pressed.
    351352        key = event.string
    352         key_name = gtk.gdk.keyval_name(event.keyval)
     353        key_name = Gdk.keyval_name(event.keyval)
    353354       
    354355        # Ignore events which don't produce a character, except backspace.
    355356        if not (key_name == 'BackSpace' or key):
    356357            return True
    357358
    358359        # 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:
    360361            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:
    362363            return True
    363364       
    364365        # 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):
    366367            return True
    367368       
    368369        # Convert Return keys to paragraph symbols.
    class LessonScreen(gtk.VBox): 
    474475            self.lessontext.grab_focus()
    475476           
    476477            # 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)
    478480
    479481        # In Key mode, display the finger hint and the key image.
    480482        if self.mode == 'key':
    class LessonScreen(gtk.VBox): 
    499501                except:
    500502                    finger = ''
    501503       
    502                 if state == gtk.gdk.SHIFT_MASK:
     504                if state == Gdk.ModifierType.SHIFT_MASK:
    503505                    # Choose the finger to press the SHIFT key with.
    504506                    if key['key-finger'][0] == 'R':
    505507                        shift_finger = FINGERS['LP']
    class LessonScreen(gtk.VBox): 
    509511                    instructions = _('Press and hold the shift key with your %(finger)s, ') % { 'finger': shift_finger }
    510512                    instructions += _('then press the %(letter)s key with your %(finger)s.') % { 'letter': letter, 'finger': finger }
    511513       
    512                 elif state == gtk.gdk.MOD5_MASK:
     514                elif state == Gdk.ModifierType.MOD5_MASK:
    513515                    instructions = _('Press and hold the altgr key, ')
    514516                    instructions += _('then press the %(letter)s key with your %(finger)s.') % { 'letter': letter, 'finger': finger }
    515517       
    516                 elif state == gtk.gdk.SHIFT_MASK | gtk.gdk.MOD5_MASK:
     518                elif state == Gdk.ModifierType.SHIFT_MASK | Gdk.ModifierType.MOD5_MASK:
    517519                    instructions = _('Press and hold the altgr and shift keys, ')
    518520                    instructions += _('then press the %(letter)s key with your %(finger)s.') % { 'letter': letter, 'finger': finger }
    519521       
    class LessonScreen(gtk.VBox): 
    522524
    523525                self.lessonbuffer.insert(self.lessonbuffer.get_end_iter(), instructions + '\n\n')
    524526
    525                 if state & gtk.gdk.SHIFT_MASK:
     527                if state & Gdk.ModifierType.SHIFT_MASK:
    526528                    shift_key = self.keyboard.find_key_by_label('shift')
    527529                    pixbuf = self.keyboard.get_key_pixbuf(shift_key, scale=1)
    528530                    self.lessonbuffer.insert_pixbuf(self.lessonbuffer.get_end_iter(), pixbuf)
    529531                    self.lessonbuffer.insert(self.lessonbuffer.get_end_iter(), ' ')
    530532               
    531                 if state & gtk.gdk.MOD5_MASK:
     533                if state & Gdk.ModifierType.MOD5_MASK:
    532534                    altgr_key = self.keyboard.find_key_by_label('altgr')
    533535                    pixbuf = self.keyboard.get_key_pixbuf(altgr_key, scale=1)
    534536                    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 
    1919from gettext import gettext as _
    2020from port import json
    2121
    22 # Import PyGTK.
    23 import gobject, pygtk, gtk, pango
     22from gi.repository import Gtk
     23from gi.repository import Gdk
     24from gi.repository import GdkPixbuf
     25from gi.repository import GObject
    2426
    2527# Import Sugar UI modules.
    26 import sugar.activity.activity
    27 from sugar.graphics import *
     28import sugar3.activity.activity
     29from sugar3.graphics import *
    2830
    2931# Import activity modules.
    3032import lessonscreen, medalscreen
    import keyboard 
    3840# http://commons.wikimedia.org/wiki/File:Silver_medal_world_centered.svg
    3941# http://commons.wikimedia.org/wiki/File:Bronze_medal_world_centered.svg
    4042
    41 class MainScreen(gtk.VBox):
     43class MainScreen(Gtk.VBox):
    4244    def __init__(self, activity):
    43         gtk.VBox.__init__(self)
     45        GObject.GObject.__init__(self)
    4446       
    4547        self.activity = activity
    4648       
    class MainScreen(gtk.VBox): 
    4850        self.titlescene = titlescene.TitleScene()
    4951       
    5052        # Build lessons list.
    51         self.lessonbox = gtk.HBox()
     53        self.lessonbox = Gtk.HBox()
    5254       
    53         #nexticon = sugar.graphics.icon.Icon(icon_name='go-next')
     55        #nexticon = sugar3.graphics.icon.Icon(icon_name='go-next')
    5456        #self.nextlessonbtn.add(nexticon)
    55         nextlabel = gtk.Label()
     57        nextlabel = Gtk.Label()
    5658        nextlabel.set_markup("<span size='large'>" + _('Next') + "</span>")
    5759
    58         self.nextlessonbtn = gtk.Button()
     60        self.nextlessonbtn = Gtk.Button()
    5961        self.nextlessonbtn.add(nextlabel)
    6062        self.nextlessonbtn.connect('clicked', self.next_lesson_clicked_cb)
    6163       
    62         #previcon = sugar.graphics.icon.Icon(icon_name='go-previous')
     64        #previcon = sugar3.graphics.icon.Icon(icon_name='go-previous')
    6365        #self.prevlessonbtn.add(previcon)
    64         prevlabel = gtk.Label()
     66        prevlabel = Gtk.Label()
    6567        prevlabel.set_markup("<span size='large'>" + _('Previous') + "</span>")
    6668
    67         self.prevlessonbtn = gtk.Button()
     69        self.prevlessonbtn = Gtk.Button()
    6870        self.prevlessonbtn.add(prevlabel)
    6971        self.prevlessonbtn.connect('clicked', self.prev_lesson_clicked_cb)
    7072       
    71         lessonlabel = gtk.Label()
     73        lessonlabel = Gtk.Label()
    7274        lessonlabel.set_markup("<span size='x-large' weight='bold'>" + _('Start Lesson') + "</span>")
    7375       
    74         lessonbtn = gtk.Button()
     76        lessonbtn = Gtk.Button()
    7577        lessonbtn.add(lessonlabel)
    7678        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])
    7880       
    7981        # Load lessons for this language.
    8082        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')
    8284        lessons_file = os.path.join(lessons_path, code + '.lessons')
    8385        if os.path.isfile(lessons_file):
    8486            self.load_lessons(lessons_file)
    class MainScreen(gtk.VBox): 
    99101        self.lessons.sort(lambda x, y: x.get('order', 0) - y.get('order', 0))
    100102
    101103        # 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
    104107        self.keyboard_images = keyboard.KeyboardImages(width, height)
    105108        self.keyboard_images.load_images()
    106109       
    107         navbox = gtk.HBox()
     110        navbox = Gtk.HBox()
    108111        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)
    112115       
    113         lessonbox = gtk.VBox()
     116        lessonbox = Gtk.VBox()
    114117        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)
    117120       
    118121        self.pack_start(self.titlescene, False, True, 10)
    119         self.pack_start(lessonbox, True)
     122        self.pack_start(lessonbox, True, True, 0)
    120123       
    121124        self.show_next_lesson()
    122125
    class MainScreen(gtk.VBox): 
    165168            medal_type = self.activity.data['medals'][lesson['name']]['type']
    166169       
    167170        # Create the lesson button.
    168         namelabel = gtk.Label()
     171        namelabel = Gtk.Label()
    169172        namelabel.set_alignment(0.5, 0.5)
    170173        namelabel.set_markup("<span size='x-large' weight='bold'>" + lesson['name'] + "</span>")
    171         desclabel = gtk.Label()
     174        desclabel = Gtk.Label()
    172175        desclabel.set_alignment(0.5, 0.5)
    173176        desclabel.set_markup("<span size='large' color='#606060'>" + lesson['description'] + "</span>")
    174177       
    class MainScreen(gtk.VBox): 
    177180        else:
    178181            hint = ''
    179182               
    180         #hintlabel = gtk.Label()
     183        #hintlabel = Gtk.Label()
    181184        #hintlabel.set_alignment(0.0, 0.8)
    182185        #hintlabel.set_markup("<span size='8000' color='#606020'>" + hint + "</span>")
    183186       
    184         labelbox = gtk.VBox()
     187        labelbox = Gtk.VBox()
    185188        labelbox.set_spacing(10)
    186189        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)
    190193
    191194        # Create the medal image.
    192195        images = {
    class MainScreen(gtk.VBox): 
    196199            'gold':   'images/gold-medal.svg'
    197200        }
    198201
    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)
    202205       
    203         medalimage = gtk.Image()
     206        medalimage = Gtk.Image()
    204207        medalimage.set_from_pixbuf(medalpixbuf)
    205208       
    206209        names = {
    class MainScreen(gtk.VBox): 
    209212            'silver': _('Silver Medal'),
    210213            'gold':   _('Gold Medal'),
    211214        }
    212         medallabel = gtk.Label(names[medal_type])
     215        medallabel = Gtk.Label(label=names[medal_type])
    213216       
    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)
    217220       
    218         medalbtn = gtk.Button()
     221        medalbtn = Gtk.Button()
    219222        medalbtn.add(medalbox)
    220223        medalbtn.connect('clicked', self.medal_clicked_cb)
    221224       
    222225        # Hilite the button in the direction of the first unmedaled lesson.
    223226        next_index = self.get_next_lesson()
    224227        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])
    226229        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])
    228231        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])
    230233        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])
    232235       
    233         self.lessonbox.pack_start(labelbox, True)
     236        self.lessonbox.pack_start(labelbox, True, True, 0)
    234237        if medal_type != 'none':
    235             self.lessonbox.pack_start(medalbtn, False)
     238            self.lessonbox.pack_start(medalbtn, False, True, 0)
    236239
    237240        self.lessonbox.show_all()
    238241   
  • medalscreen.py

    diff --git a/medalscreen.py b/medalscreen.py
    index a1d881a..d9cf410 100644
    a b  
    1818import logging, os, math, time, copy, locale, datetime, random, re
    1919from gettext import gettext as _
    2020
    21 # Import PyGTK.
    22 import gobject, pygtk, gtk, pango
     21from gi.repository import Gtk
     22from gi.repository import Gdk
     23from gi.repository import GdkPixbuf
     24from gi.repository import GObject
    2325
    2426# Import Sugar UI modules.
    25 import sugar.activity.activity
    26 import sugar.graphics.style
     27import sugar3.activity.activity
     28import sugar3.graphics.style
    2729
    28 class MedalScreen(gtk.EventBox):
    29     MEDAL_SIZE = int(4.5 * sugar.graphics.style.GRID_CELL_SIZE)
     30class MedalScreen(Gtk.EventBox):
     31    MEDAL_SIZE = int(4.5 * sugar3.graphics.style.GRID_CELL_SIZE)
    3032
    3133    def __init__(self, medal, activity):
    32         gtk.EventBox.__init__(self)
     34        GObject.GObject.__init__(self)
    3335       
    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])
    3537       
    3638        self.medal = medal
    3739        self.activity = activity
    class MedalScreen(gtk.EventBox): 
    4345            'silver': 'images/silver-medal.svg',
    4446            'gold':   'images/gold-medal.svg'
    4547        }
    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)
    4850       
    49         medalimage = gtk.Image()
     51        medalimage = Gtk.Image()
    5052        medalimage.set_from_pixbuf(medalpixbuf)
    5153
    5254        # Certifications section.
    53         title = gtk.Label()
     55        title = Gtk.Label()
    5456        title.set_markup(_("<span font_desc='Serif Bold Italic 28'>Certificate of Achievement</span>"))
    5557       
    56         text0 = gtk.Label()
     58        text0 = Gtk.Label()
    5759        text0.set_markup(_("<span font_desc='Sans 16'>This certifies that</span>"))
    5860
    59         text1 = gtk.Label()
     61        text1 = Gtk.Label()
    6062        text1.set_markup(_("<span font_desc='Sans 16'><b><u><i>%(nick)s</i></u></b></span>") % medal)
    6163
    62         text2 = gtk.Label()
     64        text2 = Gtk.Label()
    6365        text2.set_markup(_("<span font_desc='Sans 16'>earned a %(type)s medal in </span>") % medal)
    6466
    65         text3 = gtk.Label()
     67        text3 = Gtk.Label()
    6668        text3.set_markup(_("<span font_desc='Sans 16'>in <b><u><i>%(lesson)s</i></u></b></span>") % medal)
    6769
    68         text4 = gtk.Label()
     70        text4 = Gtk.Label()
    6971        text4.set_markup(_("<span font_desc='Sans 16'>on <b><u><i>%(date)s</i></u></b>.</span>") % medal)
    7072
    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)
    7779
    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)
    8183
    8284        # Stats section.
    83         statbox = gtk.HBox()
     85        statbox = Gtk.HBox()
    8486        if medal.has_key('wpm'):
    85             stat1 = gtk.Label()
     87            stat1 = Gtk.Label()
    8688            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)
    8890       
    89             stat2 = gtk.Label()
     91            stat2 = Gtk.Label()
    9092            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)
    9294
    9395        elif medal.has_key('score'):
    94             stat1 = gtk.Label()
     96            stat1 = Gtk.Label()
    9597            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)
    9799       
    98         oklabel = gtk.Label()
     100        oklabel = Gtk.Label()
    99101        oklabel.set_markup("<span size='10000'>" + _('Press the ENTER key to continue.') + '</span>')
    100         self.okbtn = gtk.Button()
     102        self.okbtn = Gtk.Button()
    101103        self.okbtn.add(oklabel)
    102104        self.okbtn.connect('clicked', self.ok_cb)
    103105
    104         btnbox = gtk.HBox()
     106        btnbox = Gtk.HBox()
    105107        btnbox.pack_start(self.okbtn, True, True, 100)
    106108       
    107         vbox = gtk.VBox()
     109        vbox = Gtk.VBox()
    108110       
    109111        vbox.pack_start(title, False, False, 0)
    110112        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)
    112114        vbox.pack_start(statbox, False, False, 0)
    113115       
    114         frame = gtk.Frame()
     116        frame = Gtk.Frame()
    115117        frame.add(vbox)
    116118        frame.set_border_width(10)
    117119
    118         box = gtk.VBox()
    119         box.pack_start(frame, True, True)
     120        box = Gtk.VBox()
     121        box.pack_start(frame, True, True, 0)
    120122        box.pack_start(btnbox, False, False, 40)
    121123
    122124        self.add(box)
    class MedalScreen(gtk.EventBox): 
    127129
    128130    def realize_cb(self, widget):
    129131        # 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)
    131133        self.okbtn.grab_default()
    132134
    133135    def ok_cb(self, widget):
  • port/chooser.py

    diff --git a/port/chooser.py b/port/chooser.py
    index e2df259..1391942 100644
    a b  
    1414
    1515"""Object chooser method"""
    1616
    17 import gtk
     17from gi.repository import Gtk
    1818import logging
    1919
    20 from sugar import mime
    21 from sugar.graphics.objectchooser import ObjectChooser
     20from sugar3 import mime
     21from sugar3.graphics.objectchooser import ObjectChooser
    2222
    2323TEXT  = hasattr(mime, 'GENERIC_TYPE_TEXT') and mime.GENERIC_TYPE_TEXT or None
    2424IMAGE = hasattr(mime, 'GENERIC_TYPE_IMAGE') and mime.GENERIC_TYPE_IMAGE or None
    def pick(cb=None, default=None, parent=None, what=None): 
    4545    out = None
    4646
    4747    try:
    48         if chooser.run() == gtk.RESPONSE_ACCEPT:
     48        if chooser.run() == Gtk.ResponseType.ACCEPT:
    4949            jobject = chooser.get_selected_object()
    5050            logging.debug('ObjectChooser: %r' % jobject)
    5151
  • setup.py

    diff --git a/setup.py b/setup.py
    index 77fda74..c17ead5 100755
    a b  
    11#!/usr/bin/env python
    2 from sugar.activity import bundlebuilder
     2from sugar3.activity import bundlebuilder
    33if __name__ == "__main__":
    44    bundlebuilder.start()
  • titlescene.py

    diff --git a/titlescene.py b/titlescene.py
    index 4dc6ae4..9739152 100644
    a b  
    1818import random
    1919from gettext import gettext as _
    2020
    21 # Import PyGTK.
    22 import gobject, pygtk, gtk, pango
    23 import pangocairo
     21from gi.repository import Gtk
     22from gi.repository import Gdk
     23from gi.repository import GObject
     24from gi.repository import Pango
     25from gi.repository import PangoCairo
     26from gi.repository import GdkPixbuf
    2427
    2528
    26 class TitleScene(gtk.DrawingArea):
     29class TitleScene(Gtk.DrawingArea):
    2730    # Maximum portion of the screen the background can fill vertically.
    2831    BACKGROUND_HEIGHT_RATIO = 0.6
    2932
    class TitleScene(gtk.DrawingArea): 
    3437    TITLE_FONT = 'Times 45'
    3538
    3639    def __init__(self):
    37         gtk.DrawingArea.__init__(self)
     40        Gtk.DrawingArea.__init__(self)
    3841
    39         pbuf = gtk.gdk.pixbuf_new_from_file('images/main-background.jpg')
     42        pbuf = GdkPixbuf.Pixbuf.new_from_file('images/main-background.jpg')
    4043
    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()
    4346
    4447        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)
    4649 
    4750        self.set_size_request(self.backgroundpixbuf.get_width(), self.backgroundpixbuf.get_height())
    4851       
    49         self.connect("expose-event", self.expose_cb)
     52        self.connect("draw", self.draw_cb)
    5053       
    5154        self.title_original = _('Typing Turtle')
    5255        self.title_src = self.title_original
    5356        self.title_text = ''
    5457
    55     def expose_cb(self, area, event):
     58    def draw_cb(self, area, cr):
    5659        bounds = self.get_allocation()
    5760
    58         cr = self.window.cairo_create()
    59 
    6061        # Background picture.
    6162        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)
    6365        cr.rectangle(x, 0, self.backgroundpixbuf.get_width(),
    6466                     self.backgroundpixbuf.get_height())
    6567        cr.paint()
    6668
    67         cr = pangocairo.CairoContext(cr)
    6869        cr.set_source_rgb(0, 0, 0)
    69         self.pango_layout = cr.create_layout()
     70        self.pango_layout = PangoCairo.create_layout(cr)
    7071        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))
    7375
    7476        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) - \
    7678            TitleScene.TITLE_OFFSET[0]
    7779        self.y_text = TitleScene.TITLE_OFFSET[1]
    7880
    79         gobject.timeout_add(50, self.timer_cb)
     81        GObject.timeout_add(50, self.timer_cb)
    8082
    8183    def draw_text(self):
    8284        # 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()
    8489
    8590        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)
    8995
    9096    def timer_cb(self):
    9197        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 
    2525#dbgp.client.brkOnExcept(host='192.168.1.104', port=12900)
    2626
    2727# there is need to set up localization.
    28 # since sugar.activity.main already seted up gettext envronment
     28# since sugar3.activity.main already seted up gettext envronment
    2929#locale.setlocale(locale.LC_ALL, '')
    3030
    31 # Import PyGTK.
    32 import gobject, pygtk, gtk, pango
     31
     32from gi.repository import Gtk
    3333
    3434# 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
     35import sugar3.activity.activity
     36from sugar3.graphics import *
     37from sugar3.graphics import toolbutton
     38from sugar3 import profile
     39
     40from sugar3.graphics.toolbarbox import ToolbarBox
     41from sugar3.activity.widgets import StopButton
     42from sugar3.activity.widgets import ActivityToolbarButton
    4743
    4844# Initialize logging.
    4945log = logging.getLogger('Typing Turtle')
    log.setLevel(logging.DEBUG) 
    5147logging.basicConfig()
    5248
    5349# Change to bundle directory.
    54 bundle_path = sugar.activity.activity.get_bundle_path()
     50bundle_path = sugar3.activity.activity.get_bundle_path()
    5551os.chdir(bundle_path)
    5652
     53# Set correct DPI for Rsvg and Screen
     54from gi.repository import PangoCairo
     55
     56def _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
     68dpi = _get_screen_dpi()
     69font_map_default = PangoCairo.font_map_get_default()
     70font_map_default.set_resolution(dpi)
     71
    5772# Import activity modules.
    5873import mainscreen, editlessonlistscreen
    5974
    import mainscreen, editlessonlistscreen 
    6176#
    6277# It owns the main application window, and all the various toolbars and options.
    6378# Activity Screens are stored in a stack, with the currently active screen on top.
    64 class TypingTurtle(sugar.activity.activity.Activity):
     79class TypingTurtle(sugar3.activity.activity.Activity):
    6580    def __init__ (self, handle):
    66         sugar.activity.activity.Activity.__init__(self, handle)
     81        sugar3.activity.activity.Activity.__init__(self, handle)
    6782        self.set_title(_("Typing Turtle"))
    6883        self.max_participants = 1
    6984       
    7085        self.build_toolbox()
    7186       
    7287        self.screens = []
    73         self.screenbox = gtk.VBox()
     88        self.screenbox = Gtk.VBox()
    7489       
    7590        self.nick = profile.get_nick_name()
    7691       
    class TypingTurtle(sugar.activity.activity.Activity): 
    92107       
    93108        self.show_all()
    94109       
    95         self.editorbtn = sugar.graphics.toolbutton.ToolButton('view-source')
     110        self.editorbtn = sugar3.graphics.toolbutton.ToolButton('view-source')
    96111        self.editorbtn.set_tooltip(_("Edit Lessons"))
    97112        self.editorbtn.connect('clicked', self.editor_clicked_cb)
    98113
    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)
    110116
    111117        self.editorbtn.show_all()
    112118
    113119    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()
    120121
    121             activity_button = ActivityToolbarButton(self)
    122             self.toolbar_box.toolbar.insert(activity_button, 0)
    123             activity_button.show()
     122        activity_button = ActivityToolbarButton(self)
     123        self.toolbar_box.toolbar.insert(activity_button, 0)
     124        activity_button.show()
    124125
    125             separator = gtk.SeparatorToolItem()
    126             separator.props.draw = False
    127             separator.set_expand(True)
    128             self.toolbar_box.toolbar.insert(separator, -1)
     126        separator = Gtk.SeparatorToolItem()
     127        separator.props.draw = False
     128        separator.set_expand(True)
     129        self.toolbar_box.toolbar.insert(separator, -1)
    129130
    130             self.toolbar_box.toolbar.insert(StopButton(self), -1)
     131        self.toolbar_box.toolbar.insert(StopButton(self), -1)
    131132
    132             self.set_toolbar_box(self.toolbar_box)
    133             self.toolbar_box.show_all()
     133        self.set_toolbar_box(self.toolbar_box)
     134        self.toolbar_box.show_all()
    134135
    135136    def editor_clicked_cb(self, btn):
    136137        self.push_screen(editlessonlistscreen.EditLessonListScreen(self, self.mainscreen.lessons))
    class TypingTurtle(sugar.activity.activity.Activity): 
    146147           
    147148            self.screenbox.remove(oldscreen)
    148149       
    149         self.screenbox.pack_start(screen, True, True)
     150        self.screenbox.pack_start(screen, True, True, 0)
    150151        self.screens.append(screen)
    151152       
    152153        try:
    class TypingTurtle(sugar.activity.activity.Activity): 
    172173            except:
    173174                pass
    174175           
    175             self.screenbox.pack_start(screen)
     176            self.screenbox.pack_start(screen, True, True, 0)
    176177           
    177178    def add_history(self, entry):
    178179        self.data['history'].append(entry)