Attachments you submit will be routed for moderation. If you have an account, please log in first.

Ticket #3772: cairo_gtk3__almost-ported.diff

File cairo_gtk3__almost-ported.diff, 103.3 KB (added by humitos, 10 months ago)

Backup of my port progress

  • activity/activity.info

    diff --git a/activity/activity.info b/activity/activity.info
    index 71729d2..869c1cc 100644
    a b  
    11[Activity] 
    2 name = Typing Turtle 
    3 activity_version = 29 
     2name = Gtk3 Typing Turtle 
     3activity_version = 31 
    44host_version = 1 
    5 bundle_id = org.laptop.community.TypingTurtle 
     5bundle_id = gtk3.TypingTurtle 
    66icon = Activity-typingturtle 
    77exec = sugar-activity typingturtle.TypingTurtle 
  • balloongame.py

    diff --git a/balloongame.py b/balloongame.py
    index 56a6a34..2380e95 100644
    a b  
    1414# You should have received a copy of the GNU General Public License 
    1515# along with Typing Turtle.  If not, see <http://www.gnu.org/licenses/>. 
    1616 
     17import math 
    1718import random, datetime 
     19 
    1820from gettext import gettext as _ 
    1921 
    20 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 
    2127 
    2228import medalscreen 
    2329 
     
    3844        self.size = max(100, 50 + len(word) * 20)  
    3945        self.color = random.choice(BALLOON_COLORS) 
    4046 
    41 class BalloonGame(gtk.VBox): 
     47class BalloonGame(Gtk.VBox): 
    4248    def __init__(self, lesson, activity): 
    43         gtk.VBox.__init__(self) 
     49        GObject.GObject.__init__(self) 
    4450         
    4551        self.lesson = lesson 
    4652        self.activity = activity 
    4753         
    4854        # Build title bar. 
    49         title = gtk.Label() 
     55        title = Gtk.Label() 
    5056        title.set_markup("<span size='20000'><b>" + lesson['name'] + "</b></span>") 
    5157        title.set_alignment(1.0, 0.0) 
    5258         
    53         stoplabel = gtk.Label(_('Go Back')) 
    54         stopbtn =  gtk.Button() 
     59        stoplabel = Gtk.Label(label=_('Go Back')) 
     60        stopbtn =  Gtk.Button() 
    5561        stopbtn.add(stoplabel) 
    5662        stopbtn.connect('clicked', self.stop_cb) 
    5763         
    58         hbox = gtk.HBox() 
     64        hbox = Gtk.HBox() 
    5965        hbox.pack_start(stopbtn, False, False, 10) 
    6066        hbox.pack_end(title, False, False, 10) 
    6167         
    6268        # Build the game drawing area. 
    63         self.area = gtk.DrawingArea() 
    64         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) 
    6571 
    6672        # Connect keyboard grabbing and releasing callbacks.         
    6773        self.area.connect('realize', self.realize_cb) 
    6874        self.area.connect('unrealize', self.unrealize_cb) 
    6975 
    7076        self.pack_start(hbox, False, False, 10) 
    71         self.pack_start(self.area, True, True) 
     77        self.pack_start(self.area, True, True, 0) 
    7278         
    7379        self.show_all() 
    7480         
     
    8591        self.finished = False 
    8692 
    8793        # Start the animation loop running.         
    88         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) 
    8995     
    9096    def realize_cb(self, widget): 
    91         self.activity.add_events(gtk.gdk.KEY_PRESS_MASK) 
     97        self.activity.add_events(Gdk.EventMask.KEY_PRESS_MASK) 
    9298        self.key_press_cb_id = self.activity.connect('key-press-event', self.key_cb) 
    9399 
    94100        # Clear the mouse cursor.  
    95         #pixmap = gtk.gdk.Pixmap(widget.window, 10, 10) 
    96         #color = gtk.gdk.Color() 
    97         #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) 
    98104        #widget.window.set_cursor(cursor) 
    99105         
    100106    def unrealize_cb(self, widget): 
     
    103109    def stop_cb(self, widget): 
    104110        # Stop the animation loop. 
    105111        if self.update_timer: 
    106             gobject.source_remove(self.update_timer) 
     112            GObject.source_remove(self.update_timer) 
    107113         
    108114        self.activity.pop_screen() 
    109115 
    110116    def key_cb(self, widget, event): 
    111117        # Ignore hotkeys. 
    112         if event.state & (gtk.gdk.CONTROL_MASK | gtk.gdk.MOD1_MASK): 
     118        if event.get_state() & (Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.MOD1_MASK): 
    113119            return False 
    114120 
    115121        # Extract information about the key pressed. 
    116         key = gtk.gdk.keyval_to_unicode(event.keyval) 
     122        key = Gdk.keyval_to_unicode(event.keyval) 
    117123        if key != 0: key = unichr(key) 
    118124 
    119125        if self.finished: 
    120             key_name = gtk.gdk.keyval_name(event.keyval) 
     126            key_name = Gdk.keyval_name(event.keyval) 
    121127            if key_name == 'Return': 
    122128                self.activity.pop_screen() 
    123129 
     
    156162     
    157163    def tick(self): 
    158164        if self.finished: 
    159             return 
     165            return False 
    160166 
    161167        self.bounds = self.area.get_allocation() 
    162168             
     
    192198  
    193199        return True 
    194200 
    195     def draw_results(self, gc): 
     201    def draw_results(self, cr): 
    196202        # Draw background. 
    197203        w = self.bounds.width - 400 
    198204        h = self.bounds.height - 200 
    199205        x = self.bounds.width/2 - w/2 
    200206        y = self.bounds.height/2 - h/2 
    201207 
    202         gc.foreground = self.area.get_colormap().alloc_color(50000,50000,50000) 
    203         self.area.window.draw_rectangle(gc, True, x, y, w, h) 
    204         gc.foreground = self.area.get_colormap().alloc_color(0,0,0) 
    205         self.area.window.draw_rectangle(gc, False, x, y, w, h) 
     208        cr.set_source_rgb(0.762, 0.762, 0.762) 
     209        cr.rectangle(x, y, w, h) 
     210        cr.fill() 
    206211 
    207         # Draw text 
    208         gc.foreground = self.area.get_colormap().alloc_color(0,0,0) 
     212        cr.set_source_rgb(0, 0, 0) 
     213        cr.rectangle(x, y, w, h) 
     214        cr.stroke() 
    209215 
     216        # Draw text 
    210217        title = _('You finished!') + '\n' 
    211         layout = self.area.create_pango_layout(title) 
    212         layout.set_font_description(pango.FontDescription('Serif Bold 16'))     
    213         size = layout.get_size() 
    214         tx = x+w/2-(size[0]/pango.SCALE)/2 
     218 
     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'))) 
     226        size = pango_layout.get_size() 
     227        tx = x + (w / 2) - (size[0] / Pango.SCALE) / 2 
    215228        ty = y + 100 
    216         self.area.window.draw_layout(gc, tx, ty, layout) 
     229        cr.move_to(tx, ty) 
     230        PangoCairo.update_layout(cr, pango_layout) 
     231        PangoCairo.show_layout(cr, pango_layout) 
    217232 
    218233        report = '' 
    219234        report += _('Your score was %(score)d.') % { 'score': self.score } + '\n' 
     
    222237        report += '\n' 
    223238        report += _('Press the ENTER key to continue.') 
    224239     
    225         layout = self.area.create_pango_layout(report) 
    226         layout.set_font_description(pango.FontDescription('Times 12'))     
    227         size = layout.get_size() 
    228         tx = x+w/2-(size[0]/pango.SCALE)/2 
    229         ty = y + 200 
    230         self.area.window.draw_layout(gc, tx, ty, layout) 
     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)) 
     246        size = pango_layout.get_size() 
     247        sx = x + w / 2 - (size[0] / Pango.SCALE) / 2 
     248        sy = y + 200 
     249        cr.move_to(sx, sy) 
     250        PangoCairo.update_layout(cr, pango_layout) 
     251        PangoCairo.show_layout(cr, pango_layout) 
    231252 
    232253    def finish_game(self): 
    233254        self.finished = True 
     
    290311        h = int(b.size*1.5 + 10) 
    291312        self.area.queue_draw_area(x, y, w, h) 
    292313 
    293     def draw_balloon(self, gc, b): 
     314    def draw_balloon(self, cr, b): 
    294315        x = int(b.x) 
    295316        y = int(b.y) 
    296          
     317 
    297318        # Draw the string. 
    298         gc.foreground = self.area.get_colormap().alloc_color(0,0,0) 
    299         self.area.window.draw_line(gc,  
    300             int(b.x), int(b.y+b.size/2),  
    301             int(b.x), int(b.y+b.size)) 
    302          
     319        cr.set_source_rgb(0, 0, 0) 
     320        cr.move_to(int(b.x), int(b.y + b.size / 2)) 
     321        cr.line_to(int(b.x), int(b.y + b.size)) 
     322        cr.stroke() 
     323 
    303324        # Draw the balloon. 
    304         gc.foreground = self.area.get_colormap().alloc_color(b.color[0],b.color[1],b.color[2]) 
    305         self.area.window.draw_arc(gc, True, x-b.size/2, y-b.size/2, b.size, b.size, 0, 360*64) 
    306      
    307         # Draw the text. 
    308         gc.foreground = self.area.get_colormap().alloc_color(0,0,0) 
    309         layout = self.area.create_pango_layout(b.word) 
    310         layout.set_font_description(pango.FontDescription('Sans 12'))     
    311         size = layout.get_size() 
    312         tx = x-(size[0]/pango.SCALE)/2 
    313         ty = y-(size[1]/pango.SCALE)/2 
    314         self.area.window.draw_layout(gc, tx, ty, layout) 
    315      
     325        cr.save() 
     326        cr.set_source_rgb(b.color[0], b.color[1], b.color[2]) 
     327        cr.arc(b.x, b.y, b.size / 2, 0, 2 * math.pi) 
     328        cr.fill() 
     329        cr.restore() 
     330 
     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)) 
     338        size = pango_layout.get_size() 
     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) 
     344 
    316345    def add_score(self, num): 
    317346        self.score += num 
    318347        self.queue_draw_score() 
    319348 
    320349    def queue_draw_score(self): 
    321350        layout = self.area.create_pango_layout(_('SCORE: %d') % self.score) 
    322         layout.set_font_description(pango.FontDescription('Times 14'))     
     351        layout.set_font_description(Pango.FontDescription('Times 14')) 
    323352        size = layout.get_size() 
    324         x = self.bounds.width-20-size[0]/pango.SCALE 
     353        x = self.bounds.width-20-size[0]/Pango.SCALE 
    325354        y = 20 
    326355        self.queue_draw_area(x, y, x+size[0], y+size[1]) 
    327356 
    328     def draw_score(self, gc): 
    329         layout = self.area.create_pango_layout(_('SCORE: %d') % self.score) 
    330         layout.set_font_description(pango.FontDescription('Times 14'))     
    331         size = layout.get_size() 
    332         x = self.bounds.width-20-size[0]/pango.SCALE 
     357    def draw_score(self, cr): 
     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 
     366        size = pango_layout.get_size() 
     367        x = self.bounds.width - 20 - size[0] / Pango.SCALE 
    333368        y = 20 
    334         self.area.window.draw_layout(gc, x, y, layout) 
     369        cr.move_to(x, y) 
     370        PangoCairo.update_layout(cr, pango_layout) 
     371        PangoCairo.show_layout(cr, pango_layout) 
    335372 
    336     def draw_instructions(self, gc): 
     373    def draw_instructions(self, cr): 
    337374        # Draw instructions. 
    338         gc.foreground = self.area.get_colormap().alloc_color(0,0,0) 
    339  
    340         layout = self.area.create_pango_layout(_('Type the words to pop the balloons!')) 
    341         layout.set_font_description(pango.FontDescription('Times 14'))     
    342         size = layout.get_size() 
    343         x = (self.bounds.width - size[0]/pango.SCALE)/2 
    344         y = self.bounds.height-20 - size[1]/pango.SCALE  
    345         self.area.window.draw_layout(gc, x, y, layout) 
    346  
    347     def draw(self): 
     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)) 
     380        size = pango_layout.get_size() 
     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) 
     386 
     387    def draw(self, cr): 
    348388        self.bounds = self.area.get_allocation() 
    349389 
    350         gc = self.area.window.new_gc() 
    351          
    352390        # Draw background. 
    353         gc.foreground = self.area.get_colormap().alloc_color(60000,60000,65535) 
    354         self.area.window.draw_rectangle(gc, True, 0, 0, self.bounds.width, self.bounds.height) 
     391        cr.set_source_rgb(0.915, 0.915, 1) 
     392        cr.rectangle(0, 0, self.bounds.width, self.bounds.height) 
     393        cr.fill() 
    355394 
    356395        # Draw the balloons. 
    357396        for b in self.balloons: 
    358             self.draw_balloon(gc, b) 
     397            self.draw_balloon(cr, b) 
    359398 
    360399        if self.finished: 
    361             self.draw_results(gc) 
    362  
     400            self.draw_results(cr) 
    363401        else: 
    364             self.draw_instructions(gc) 
     402            self.draw_instructions(cr) 
    365403 
    366             self.draw_score(gc) 
     404            self.draw_score(cr) 
    367405 
    368     def expose_cb(self, area, event): 
    369         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  
    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 
     
    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 
     
    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) 
     
    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)') 
     
    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         
     
    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..b2b955a 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 
     
    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() 
     
    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 
     
    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: 
     
    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 
     
    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 
     
    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) 
     
    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         
     
    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 35daeed..2936fb7 100644
    a b  
    1616#!/usr/bin/env python 
    1717# vi:sw=4 et  
    1818 
    19 import pygtk 
    20 pygtk.require('2.0') 
    21 import gtk 
    22 import rsvg 
     19import cairo 
     20import copy 
    2321import os, glob, re 
    24 import pango 
     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 
     29from gi.repository import Rsvg 
     30 
     31import StringIO 
    2532from port import json 
    2633import subprocess 
    2734from layouts.olpc import OLPC_LAYOUT 
     
    125132 
    126133        # This is for not changing all the numbers of olpcm layout, 
    127134        # that was made based on the original olpc layout. 
     135 
     136        # FIXME FIXME 
    128137        scale_width = self.width 
    129138        if _is_olpcm_model(): 
    130139            scale_width = int(scale_width * 1.1625) 
    131140 
    132141        for filename in glob.iglob('images/OLPC*.svg'): 
    133             image = gtk.gdk.pixbuf_new_from_file_at_scale(filename, scale_width, 
    134                                                           self.height, False) 
     142            image = Rsvg.Handle.new_from_file(filename) 
    135143            name = os.path.basename(filename) 
    136144            self.images[name] = image 
    137145 
     
    144152        self.letter_map = {} 
    145153         
    146154        # Access the current GTK keymap. 
    147         self.keymap = gtk.gdk.keymap_get_default() 
     155        self.keymap = Gdk.Keymap.get_default() 
    148156 
    149157    def set_layout(self, layout):  
    150158        self._build_key_list(layout) 
     
    234242 
    235243    def format_key_sig(self, scan, state, group): 
    236244        sig = 'scan%d' % scan 
    237         if state & gtk.gdk.SHIFT_MASK: 
     245        if state & Gdk.ModifierType.SHIFT_MASK: 
    238246            sig += ' shift' 
    239         if state & gtk.gdk.MOD5_MASK: 
     247        if state & Gdk.ModifierType.MOD5_MASK: 
    240248            sig += ' altgr' 
    241249        if group != 0: 
    242250            sig += ' group%d' % group 
     
    249257 
    250258        state = 0 
    251259        if m.group('shift'): 
    252             state |= gtk.gdk.SHIFT_MASK 
     260            state |= Gdk.ModifierType.SHIFT_MASK 
    253261        if m.group('altgr'): 
    254             state |= gtk.gdk.MOD5_MASK 
     262            state |= Gdk.ModifierType.MOD5_MASK 
    255263 
    256264        scan = int(m.group('scan')) 
    257265 
     
    277285        best_result = None 
    278286         
    279287        for sig, l in self.letter_map.items(): 
    280             if unicode(l) == unicode(letter): 
     288            if l == letter: 
    281289                scan, state, group = self.parse_key_sig(sig) 
    282290                 
    283291                # Choose the key with the fewest modifiers. 
    284292                score = 0 
    285                 if state & gtk.gdk.SHIFT_MASK: score += 1 
    286                 if state & gtk.gdk.MOD5_MASK: score += 1 
     293                if state & Gdk.ModifierType.SHIFT_MASK: score += 1 
     294                if state & Gdk.ModifierType.MOD5_MASK: score += 1 
    287295                if score < best_score: 
    288296                    best_score = score 
    289297                    best_result = scan, state, group 
     
    294302                    return k, best_result[1], best_result[2] 
    295303 
    296304        # Try the GDK keymap. 
    297         keyval = gtk.gdk.unicode_to_keyval(ord(letter)) 
    298         entries = self.keymap.get_entries_for_keyval(keyval) 
     305        keyval = Gdk.unicode_to_keyval(ord(letter)) 
     306        valid, entries = self.keymap.get_entries_for_keyval(keyval) 
    299307        for e in entries: 
    300308            for k in self.keys: 
    301                 if k['key-scan'] == e[0]: 
     309                if k['key-scan'] == e.keycode: 
    302310                    # TODO: Level -> state calculations are hardcoded to what the XO keyboard does. 
    303311                    # They were discovered through experimentation. 
    304312                    state = 0 
    305                     if e[2] & 1:  
    306                         state |= gtk.gdk.SHIFT_MASK 
    307                     if e[2] & 2:  
    308                         state |= gtk.gdk.MOD5_MASK 
    309                     return k, state, e[1] 
     313                    if e.level & 1: 
     314                        state |= Gdk.ModifierType.SHIFT_MASK 
     315                    if e.level & 2: 
     316                        state |= Gdk.ModifierType.MOD5_MASK 
     317                    return k, state, e.group 
    310318 
    311319        # Fail! 
    312320        return None, None, None 
     
    316324        if self.letter_map.has_key(sig): 
    317325            return self.letter_map[sig] 
    318326        else: 
    319             t = self.keymap.translate_keyboard_state(key['key-scan'], self.active_state, self.active_group) 
    320             if t: 
    321                 return unichr(gtk.gdk.keyval_to_unicode(t[0])) 
     327            success, keyval, effective_group, level, consumed_modifiers = \ 
     328                self.keymap.translate_keyboard_state( 
     329                    key['key-scan'], self.active_state, self.active_group) 
     330            if success: 
     331                return unichr(Gdk.keyval_to_unicode(keyval)).encode('utf-8') 
    322332 
    323333        return '' 
    324334 
    325 class KeyboardWidget(KeyboardData, gtk.DrawingArea): 
     335class KeyboardWidget(KeyboardData, Gtk.DrawingArea): 
    326336    """A GTK widget which implements an interactive visual keyboard, with support 
    327337       for custom data driven layouts.""" 
    328338 
    329339    def __init__(self, image, root_window, poll_keys=False): 
    330340        KeyboardData.__init__(self) 
    331         gtk.DrawingArea.__init__(self) 
     341        GObject.GObject.__init__(self) 
    332342         
    333343        self.image = image 
    334344        self.root_window = root_window 
     
    336346        # Match the image cache in dimensions. 
    337347        self.set_size_request(image.width, image.height) 
    338348 
    339         self.connect("expose-event", self._expose_cb) 
     349        self.connect("draw", self._draw_cb) 
    340350         
    341         #self.modify_font(pango.FontDescription('Monospace 10')) 
     351        #self.modify_font(Pango.FontDescription('Monospace 10')) 
    342352         
    343353        # Active language group and modifier state. 
    344354        # See http://www.pygtk.org/docs/pygtk/class-gdkkeymap.html for more 
     
    353363         
    354364        self.draw_hands = False 
    355365         
    356         self.modify_bg(gtk.STATE_NORMAL, self.get_colormap().alloc_color('#d0d0d0')) 
     366        self.modify_bg(Gtk.StateType.NORMAL, Gdk.Color.parse('#d0d0d0')[1]) 
    357367 
    358368        # Connect keyboard grabbing and releasing callbacks.         
    359369        if poll_keys: 
     
    362372 
    363373    def _realize_cb(self, widget): 
    364374        # Setup keyboard event snooping in the root window. 
    365         self.root_window.add_events(gtk.gdk.KEY_PRESS_MASK | gtk.gdk.KEY_RELEASE_MASK) 
     375        self.root_window.add_events(Gdk.EventMask.KEY_PRESS_MASK | Gdk.EventMask.KEY_RELEASE_MASK) 
    366376        self.key_press_cb_id = self.root_window.connect('key-press-event', self.key_press_release_cb) 
    367377        self.key_release_cb_id = self.root_window.connect('key-release-event', self.key_press_release_cb) 
    368378 
     
    383393            k['key-width'] = int(k['key-width'] * width_scale) 
    384394            k['key-height'] = int(k['key-height'] * height_scale) 
    385395 
    386         self._make_all_key_images() 
    387  
    388     def _make_key_images(self, key): 
    389         key['key-images'] = {} 
    390         for group in [0, 1]: 
    391             for state in [0, gtk.gdk.SHIFT_MASK, gtk.gdk.MOD5_MASK, gtk.gdk.SHIFT_MASK|gtk.gdk.MOD5_MASK]: 
    392                 key['key-images'][(state, group)] = self.get_key_image(key, state, group) 
     396    def _draw_key(self, k, cr): 
     397        bounds = self.get_allocation() 
    393398 
    394     def _make_all_key_images(self): 
    395         for key in self.keys: 
    396             self._make_key_images(key) 
     399        # HACK: this is a hack used when the widget is not shown yet, 
     400        # in that case bounds will be gtk.gdk.Rectangle(-1, -1, 1, 1) 
     401        # and the key will be outside the canvas. This is used only 
     402        # for the first key that appears below the instructions 
     403        if bounds.x == -1: 
     404            screen_x = screen_y = 0 
     405        else: 
     406            screen_x = int(bounds.width - self.image.width) / 2 
     407            screen_y = int(bounds.height - self.image.height) / 2 
    397408 
    398     def _draw_key(self, k, draw, gc, for_pixmap, w=0, h=0): 
    399         x1 = 0  
    400         y1 = 0 
    401         x2 = w 
    402         y2 = h 
     409        x1 = k['key-x'] + screen_x 
     410        y1 = k['key-y'] + screen_y 
     411        x2 = x1 + k['key-width'] 
     412        y2 = y1 + k['key-height'] 
    403413 
    404         # Outline rounded box. 
    405         gc.foreground = self.get_colormap().alloc_color(int(0.4*65536),int(0.7*65536),int(0.4*65536)) 
    406          
    407414        corner = 5 
    408415        points = [ 
    409             (x1 + corner, y1),  
     416            (x1 + corner, y1), 
    410417            (x2 - corner, y1), 
    411418            (x2, y1 + corner), 
    412419            (x2, y2 - corner), 
     
    414421            (x1 + corner, y2), 
    415422            (x1, y2 - corner), 
    416423            (x1, y1 + corner) 
    417         ] 
    418         draw.draw_polygon(gc, True, points) 
    419          
    420         # Inner text. 
    421         gc.foreground = self.get_colormap().alloc_color(int(1.0*65536),int(1.0*65536),int(1.0*65536)) 
     424            ] 
     425 
     426        cr.new_path() 
     427        cr.set_source_rgb(0.396, 0.698, 0.392) 
     428        cr.set_line_width(2) 
     429        for point in points: 
     430            cr.line_to(*point) 
     431        cr.close_path() 
     432        cr.fill_preserve() 
     433        cr.stroke() 
    422434 
    423435        text = '' 
    424436        if k['key-label']: 
    425437            text = k['key-label'] 
    426438        else: 
    427             text = self.get_letter_for_key_state_group(k, self.active_state, self.active_group) 
    428          
    429         try: 
    430             layout = self.create_pango_layout(unicode(text)) 
    431             layout.set_font_description(pango.FontDescription('Monospace')) 
    432             draw.draw_layout(gc, x1+8, y2-23, layout) 
    433         except: 
    434             pass 
    435  
    436     def _expose_hands(self, gc): 
     439            text = self.get_letter_for_key_state_group( 
     440                k, self.active_state, self.active_group) 
     441 
     442        cr.set_source_rgb(0, 0, 0) 
     443        pango_layout = PangoCairo.create_layout(cr) 
     444        fd = Pango.FontDescription('Monospace') 
     445        fd.set_size(10 * Pango.SCALE) 
     446        pango_layout.set_font_description(fd) 
     447        pango_layout.set_text(text, len(text)) 
     448 
     449        cr.move_to(x1 + 8, y2 - 23) 
     450        PangoCairo.update_layout(cr, pango_layout) 
     451        PangoCairo.show_layout(cr, pango_layout) 
     452 
     453    def _expose_hands(self, cr): 
    437454        lhand_image = self.image.images['OLPC_Lhand_HOMEROW.svg'] 
    438455        rhand_image = self.image.images['OLPC_Rhand_HOMEROW.svg'] 
    439456 
     
    451468                        rhand_image = handle 
    452469 
    453470                # Put the other hand on the SHIFT key if needed. 
    454                 if state & gtk.gdk.SHIFT_MASK: 
     471                if state & Gdk.ModifierType.SHIFT_MASK: 
    455472                    if finger[0] == 'L': 
    456473                        rhand_image = self.image.images['OLPC_Rhand_SHIFT.svg'] 
    457474                    else: 
     
    460477                # TODO: Do something about ALTGR. 
    461478 
    462479        bounds = self.get_allocation() 
    463         screen_x = int(bounds.width-self.image.width)/2 
    464         screen_y = int(bounds.height-self.image.height)/2 
    465  
    466         self.window.draw_pixbuf(gc, lhand_image, 0, 0, screen_x, screen_y + HAND_YOFFSET) 
    467         self.window.draw_pixbuf(gc, rhand_image, 0, 0, screen_x, screen_y + HAND_YOFFSET) 
    468  
    469     def _expose_cb(self, area, event): 
    470         gc = self.window.new_gc() 
    471          
    472         bounds = self.get_allocation() 
    473         screen_x = int(bounds.width-self.image.width)/2 
    474         screen_y = int(bounds.height-self.image.height)/2 
    475480 
     481        cr.save() 
     482        xx = bounds.width / float(lhand_image.props.width) 
     483        yy = bounds.height / float(lhand_image.props.height) 
     484        # matrix = cairo.Matrix(xx=xx, yy=yy) 
     485        cr.scale(xx, yy) 
     486        lhand_image.set_dpi(250) 
     487        lhand_image.render_cairo(cr) 
     488 
     489        cr.restore() 
     490        xx = bounds.width / float(rhand_image.props.width) 
     491        yy = bounds.height / float(rhand_image.props.height) 
     492        # matrix = cairo.Matrix(xx=xx, yy=yy) 
     493        # cr.transform(matrix) 
     494        cr.scale(xx, yy) 
     495        rhand_image.render_cairo(cr) 
     496 
     497    def _draw_cb(self, area, cr): 
    476498        # Draw the keys. 
    477499        for k in self.keys: 
    478             x1 = k['key-x'] + screen_x 
    479             y1 = k['key-y'] + screen_y 
    480             x2 = x1 + k['key-width'] 
    481             y2 = y1 + k['key-height'] 
    482  
    483             # Index cached key images by state and group. 
    484             state = self.active_state & (gtk.gdk.SHIFT_MASK|gtk.gdk.MOD5_MASK) 
    485             index = (state, self.active_group) 
    486             image = k['key-images'].get(index) 
    487  
    488             if image: 
    489                 self.window.draw_image(gc, image, 0, 0, x1, y1, x2-x1, y2-y1)  
    490          
     500            self._draw_key(k, cr) 
     501 
    491502        # Draw overlay images. 
    492503        if self.draw_hands: 
    493             self._expose_hands(gc) 
    494          
     504            self._expose_hands(cr) 
    495505        return True 
    496506 
    497507    def key_press_release_cb(self, widget, event): 
    498508        key = self.key_scan_map.get(event.hardware_keycode) 
    499509        if key: 
    500             key['key-pressed'] = event.type == gtk.gdk.KEY_PRESS 
     510            key['key-pressed'] = event.type == Gdk.EventType.KEY_PRESS 
    501511 
    502512        # Hack to get the current modifier state - which will not be represented by the event. 
    503         state = gtk.gdk.device_get_core_pointer().get_state(self.window)[1] 
     513        # state = Gdk.device_get_core_pointer().get_state(self.get_window())[1] 
    504514 
    505         if self.active_group != event.group or self.active_state != state: 
     515        if self.active_group != event.group or self.active_state != event.state: 
    506516            self.active_group = event.group 
    507             self.active_state = state 
     517            self.active_state = event.state 
    508518 
    509519            self.queue_draw() 
    510520 
     
    512522            sig = self.format_key_sig(event.hardware_keycode, event.state, event.group) 
    513523            if not self.letter_map.has_key(sig): 
    514524                self.letter_map[sig] = event.string 
    515                 self._make_key_images(key) 
    516525                self.queue_draw() 
    517526 
    518527        return False 
    519528 
    520     def _keys_changed_cb(self, keymap): 
    521         self._make_key_images() 
    522  
    523529    def clear_hilite(self): 
    524530        self.hilite_letter = None 
    525531        self.queue_draw() 
     
    535541    def get_key_pixbuf(self, key, state=0, group=0, scale=1): 
    536542        w = int(key['key-width'] * scale) 
    537543        h = int(key['key-height'] * scale) 
    538          
     544 
    539545        old_state, old_group = self.active_state, self.active_group 
    540546        self.active_state, self.active_group = state, group 
    541          
    542         pixmap = gtk.gdk.Pixmap(self.root_window.window, w, h) 
    543         gc = pixmap.new_gc() 
    544          
    545         gc.foreground = self.get_colormap().alloc_color('#d0d0d0') 
    546         pixmap.draw_rectangle(gc, True, 0, 0, w, h) 
    547547 
    548         self._draw_key(key, pixmap, gc, True, w, h) 
    549          
    550         pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, w, h) 
    551         pb.get_from_drawable(pixmap, self.root_window.window.get_colormap(), 0, 0, 0, 0,w, h) 
    552          
    553         self.active_state, self.active_group = old_state, old_group 
     548        surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w, h) 
     549        cr = cairo.Context(surface) 
     550        cr.set_source_rgb(1, 1, 1) 
     551        cr.rectangle(0, 0, w, h) 
     552        cr.fill() 
    554553 
    555         return pb 
     554        # Duplicate the Key to be able to change its position values 
     555        key = copy.deepcopy(key) 
     556        key['key-x'] = 0 
     557        key['key-y'] = 0 
    556558 
    557     def get_key_image(self, key, state=0, group=0, scale=1): 
    558         w = int(key['key-width'] * scale) 
    559         h = int(key['key-height'] * scale) 
    560          
    561         old_state, old_group = self.active_state, self.active_group 
    562         self.active_state, self.active_group = state, group 
    563          
    564         pixmap = gtk.gdk.Pixmap(self.root_window.window, w, h) 
    565         gc = pixmap.new_gc() 
    566          
    567         gc.foreground = self.get_colormap().alloc_color('#d0d0d0') 
    568         pixmap.draw_rectangle(gc, True, 0, 0, w, h) 
     559        self._draw_key(key, cr) 
     560 
     561        # Convert cairo.Surface to Pixbuf 
     562        pixbuf_data = StringIO.StringIO() 
     563        surface.write_to_png(pixbuf_data) 
     564        pxb_loader = GdkPixbuf.PixbufLoader.new_with_type('png') 
     565        pxb_loader.write(pixbuf_data.getvalue()) 
     566        temp_pix = pxb_loader.get_pixbuf() 
     567        pxb_loader.close() 
    569568 
    570         self._draw_key(key, pixmap, gc, True, w, h) 
    571          
    572         image = pixmap.get_image(0, 0, w, h) 
    573          
    574569        self.active_state, self.active_group = old_state, old_group 
    575570 
    576         return image 
    577      
     571        return temp_pix 
  • 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 
     
    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  
    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 
     
    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'] 
     
    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 
     
    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) 
     
    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) 
     
    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         
     
    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 
     
    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. 
     
    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': 
     
    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'] 
     
    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         
     
    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..dbc85c6 100644
    a b  
    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 
     
    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         
     
    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) 
     
    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) 
    104106        self.keyboard_images = keyboard.KeyboardImages(width, height) 
    105107        self.keyboard_images.load_images() 
    106108         
    107         navbox = gtk.HBox() 
     109        navbox = Gtk.HBox() 
    108110        navbox.set_spacing(10) 
    109         navbox.pack_start(self.prevlessonbtn, True) 
    110         navbox.pack_start(lessonbtn, True) 
    111         navbox.pack_start(self.nextlessonbtn, True) 
     111        navbox.pack_start(self.prevlessonbtn, True, True, 0) 
     112        navbox.pack_start(lessonbtn, True, True, 0) 
     113        navbox.pack_start(self.nextlessonbtn, True, True, 0) 
    112114         
    113         lessonbox = gtk.VBox() 
     115        lessonbox = Gtk.VBox() 
    114116        lessonbox.set_spacing(10) 
    115         lessonbox.pack_start(navbox, False) 
    116         lessonbox.pack_start(self.lessonbox) 
     117        lessonbox.pack_start(navbox, False, True, 0) 
     118        lessonbox.pack_start(self.lessonbox, True, True, 0) 
    117119         
    118120        self.pack_start(self.titlescene, False, True, 10) 
    119         self.pack_start(lessonbox, True) 
     121        self.pack_start(lessonbox, True, True, 0) 
    120122         
    121123        self.show_next_lesson() 
    122124 
     
    165167            medal_type = self.activity.data['medals'][lesson['name']]['type'] 
    166168         
    167169        # Create the lesson button. 
    168         namelabel = gtk.Label() 
     170        namelabel = Gtk.Label() 
    169171        namelabel.set_alignment(0.5, 0.5) 
    170172        namelabel.set_markup("<span size='x-large' weight='bold'>" + lesson['name'] + "</span>") 
    171         desclabel = gtk.Label() 
     173        desclabel = Gtk.Label() 
    172174        desclabel.set_alignment(0.5, 0.5) 
    173175        desclabel.set_markup("<span size='large' color='#606060'>" + lesson['description'] + "</span>") 
    174176         
     
    177179        else: 
    178180            hint = '' 
    179181                 
    180         #hintlabel = gtk.Label() 
     182        #hintlabel = Gtk.Label() 
    181183        #hintlabel.set_alignment(0.0, 0.8) 
    182184        #hintlabel.set_markup("<span size='8000' color='#606020'>" + hint + "</span>") 
    183185         
    184         labelbox = gtk.VBox() 
     186        labelbox = Gtk.VBox() 
    185187        labelbox.set_spacing(10) 
    186188        labelbox.set_border_width(20) 
    187         labelbox.pack_start(namelabel, False) 
    188         labelbox.pack_start(desclabel, False) 
    189         #labelbox.pack_start(hintlabel) 
     189        labelbox.pack_start(namelabel, False, True, 0) 
     190        labelbox.pack_start(desclabel, False, True, 0) 
     191        #labelbox.pack_start(hintlabel, True, True, 0) 
    190192 
    191193        # Create the medal image. 
    192194        images = { 
     
    196198            'gold':   'images/gold-medal.svg' 
    197199        } 
    198200 
    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) 
     201        medal_size = int(2.0 * sugar3.graphics.style.GRID_CELL_SIZE) 
     202        medalpixbuf = GdkPixbuf.Pixbuf.new_from_file(images[medal_type]) 
     203        medalpixbuf = medalpixbuf.scale_simple(medal_size, medal_size, GdkPixbuf.InterpType.BILINEAR) 
    202204         
    203         medalimage = gtk.Image() 
     205        medalimage = Gtk.Image() 
    204206        medalimage.set_from_pixbuf(medalpixbuf) 
    205207         
    206208        names = { 
     
    209211            'silver': _('Silver Medal'), 
    210212            'gold':   _('Gold Medal'), 
    211213        } 
    212         medallabel = gtk.Label(names[medal_type]) 
     214        medallabel = Gtk.Label(label=names[medal_type]) 
    213215         
    214         medalbox = gtk.VBox() 
    215         medalbox.pack_start(medalimage) 
    216         medalbox.pack_start(medallabel) 
     216        medalbox = Gtk.VBox() 
     217        medalbox.pack_start(medalimage, True, True, 0) 
     218        medalbox.pack_start(medallabel, True, True, 0) 
    217219         
    218         medalbtn = gtk.Button() 
     220        medalbtn = Gtk.Button() 
    219221        medalbtn.add(medalbox) 
    220222        medalbtn.connect('clicked', self.medal_clicked_cb) 
    221223         
    222224        # Hilite the button in the direction of the first unmedaled lesson. 
    223225        next_index = self.get_next_lesson() 
    224226        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')) 
     227            self.nextlessonbtn.modify_bg(Gtk.StateType.NORMAL, Gdk.Color.parse('#ff8080')[1]) 
    226228        else: 
    227             self.nextlessonbtn.modify_bg(gtk.STATE_NORMAL, self.get_colormap().alloc_color('#40a040')) 
     229            self.nextlessonbtn.modify_bg(Gtk.StateType.NORMAL, Gdk.Color.parse('#40a040')[1]) 
    228230        if next_index < self.lesson_index and index > 0: 
    229             self.prevlessonbtn.modify_bg(gtk.STATE_NORMAL, self.get_colormap().alloc_color('#ff8080')) 
     231            self.prevlessonbtn.modify_bg(Gtk.StateType.NORMAL, Gdk.Color.parse('#ff8080')[1]) 
    230232        else: 
    231             self.prevlessonbtn.modify_bg(gtk.STATE_NORMAL, self.get_colormap().alloc_color('#40a040')) 
     233            self.prevlessonbtn.modify_bg(Gtk.StateType.NORMAL, Gdk.Color.parse('#40a040')[1]) 
    232234         
    233         self.lessonbox.pack_start(labelbox, True) 
     235        self.lessonbox.pack_start(labelbox, True, True, 0) 
    234236        if medal_type != 'none': 
    235             self.lessonbox.pack_start(medalbtn, False) 
     237            self.lessonbox.pack_start(medalbtn, False, True, 0) 
    236238 
    237239        self.lessonbox.show_all() 
    238240     
  • 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 
     
    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) 
     
    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 
     
    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 7cc2d68..9739152 100644
    a b  
    1818import random 
    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 GObject 
     24from gi.repository import Pango 
     25from gi.repository import PangoCairo 
     26from gi.repository import GdkPixbuf 
    2327 
    24 class TitleScene(gtk.DrawingArea): 
     28 
     29class TitleScene(Gtk.DrawingArea): 
    2530    # Maximum portion of the screen the background can fill vertically. 
    2631    BACKGROUND_HEIGHT_RATIO = 0.6 
    2732 
    2833    # Border from top right of screen to draw title at. 
    29     TITLE_OFFSET = (20, 30) 
     34    TITLE_OFFSET = (20, 50) 
    3035 
    3136    # Font used to display the title. 
    3237    TITLE_FONT = 'Times 45' 
    3338 
    3439    def __init__(self): 
    35         gtk.DrawingArea.__init__(self) 
     40        Gtk.DrawingArea.__init__(self) 
    3641 
    37         pbuf = gtk.gdk.pixbuf_new_from_file('images/main-background.jpg') 
     42        pbuf = GdkPixbuf.Pixbuf.new_from_file('images/main-background.jpg') 
    3843 
    39         width_ratio = float(gtk.gdk.screen_width()) / pbuf.get_width() 
    40         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() 
    4146 
    4247        ratio = min(width_ratio, height_ratio) 
    43         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) 
    4449  
    4550        self.set_size_request(self.backgroundpixbuf.get_width(), self.backgroundpixbuf.get_height()) 
    4651         
    47         self.connect("expose-event", self.expose_cb) 
     52        self.connect("draw", self.draw_cb) 
    4853         
    4954        self.title_original = _('Typing Turtle') 
    5055        self.title_src = self.title_original 
    5156        self.title_text = '' 
    5257 
    53     def expose_cb(self, area, event): 
     58    def draw_cb(self, area, cr): 
    5459        bounds = self.get_allocation() 
    55          
    56         gc = self.get_style().fg_gc[gtk.STATE_NORMAL] 
    5760 
    5861        # Background picture. 
    5962        x = (bounds.width - self.backgroundpixbuf.get_width())/2 
    60         self.window.draw_pixbuf( 
    61             gc, self.backgroundpixbuf, 0, 0,  
    62             x, 0, self.backgroundpixbuf.get_width(), self.backgroundpixbuf.get_height()) 
    63         pc = self.create_pango_context() 
    64          
    65         self.layout = self.create_pango_layout('') 
    66         self.layout.set_font_description(pango.FontDescription(TitleScene.TITLE_FONT)) 
    67          
    68         self.layout.set_text(self.title_original) 
    69         original_size = self.layout.get_size() 
    70         self.x_text = (bounds.width-original_size[0]/pango.SCALE)-TitleScene.TITLE_OFFSET[0] 
     63 
     64        Gdk.cairo_set_source_pixbuf(cr, self.backgroundpixbuf, 0, 0) 
     65        cr.rectangle(x, 0, self.backgroundpixbuf.get_width(), 
     66                     self.backgroundpixbuf.get_height()) 
     67        cr.paint() 
     68 
     69        cr.set_source_rgb(0, 0, 0) 
     70        self.pango_layout = PangoCairo.create_layout(cr) 
     71        self.pango_layout.set_font_description( 
     72            Pango.FontDescription(TitleScene.TITLE_FONT)) 
     73        self.pango_layout.set_text(unicode(self.title_original), 
     74                                   len(self.title_original)) 
     75 
     76        original_size = self.pango_layout.get_size() 
     77        self.x_text = (bounds.width - original_size[0] / Pango.SCALE) - \ 
     78            TitleScene.TITLE_OFFSET[0] 
    7179        self.y_text = TitleScene.TITLE_OFFSET[1] 
    72         gobject.timeout_add(50, self.timer_cb) 
     80 
     81        GObject.timeout_add(50, self.timer_cb) 
    7382 
    7483    def draw_text(self): 
    7584        # Animated Typing Turtle title. 
    76         gc = self.get_style().fg_gc[gtk.STATE_NORMAL] 
    77         self.layout.set_text(self.title_text) 
    78         self.window.draw_layout(gc, self.x_text, self.y_text, self.layout) 
     85        window = self.get_window() 
     86        if window is None: 
     87            return 
     88        cr = window.cairo_create() 
     89 
     90        cr.move_to(self.x_text, self.y_text) 
     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) 
    7995 
    8096    def timer_cb(self): 
    8197        if len(self.title_src) > 0: 
  • typingturtle.py

    diff --git a/typingturtle.py b/typingturtle.py
    index ad6c6cb..b6ad2de 100755
    a b  
    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') 
     
    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 
    5753# Import activity modules. 
    5854import mainscreen, editlessonlistscreen 
    5955 
     56from gi.repository import PangoCairo 
     57 
     58 
     59def _get_screen_dpi(): 
     60    xft_dpi = Gtk.Settings.get_default().get_property('gtk-xft-dpi') 
     61    dpi = float(xft_dpi / 1024) 
     62    logging.debug('Setting dpi to: %f', dpi) 
     63    # HACK: if the DPI detected is 200.0 it seems we are on an XO, so 
     64    # we return 133 because the XO manage its resolution in a complex 
     65    # way. More information here: 
     66    #     http://wiki.laptop.org/go/Display 
     67    if 200 == int(dpi): 
     68        return 133 
     69    return dpi 
     70 
     71dpi = _get_screen_dpi() 
     72font_map_default = PangoCairo.font_map_get_default() 
     73font_map_default.set_resolution(dpi) 
     74 
     75from gi.repository import Rsvg 
     76Rsvg.set_default_dpi(200) 
     77 # This is the main Typing Turtle activity class. 
     78 #  
     79 # It owns the main application window, and all the various toolbars and options. 
     80 
     81 
     82 
    6083# This is the main Typing Turtle activity class. 
    6184#  
    6285# It owns the main application window, and all the various toolbars and options. 
    6386# Activity Screens are stored in a stack, with the currently active screen on top. 
    64 class TypingTurtle(sugar.activity.activity.Activity): 
     87class TypingTurtle(sugar3.activity.activity.Activity): 
    6588    def __init__ (self, handle): 
    66         sugar.activity.activity.Activity.__init__(self, handle) 
     89        sugar3.activity.activity.Activity.__init__(self, handle) 
    6790        self.set_title(_("Typing Turtle")) 
    6891        self.max_participants = 1 
    6992         
    7093        self.build_toolbox() 
    7194         
    7295        self.screens = [] 
    73         self.screenbox = gtk.VBox() 
     96        self.screenbox = Gtk.VBox() 
    7497         
    7598        self.nick = profile.get_nick_name() 
    7699         
     
    92115         
    93116        self.show_all() 
    94117         
    95         self.editorbtn = sugar.graphics.toolbutton.ToolButton('view-source') 
     118        self.editorbtn = sugar3.graphics.toolbutton.ToolButton('view-source') 
    96119        self.editorbtn.set_tooltip(_("Edit Lessons")) 
    97120        self.editorbtn.connect('clicked', self.editor_clicked_cb) 
    98121 
    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) 
     122        activity_toolbar = self.toolbar_box.toolbar 
     123        activity_toolbar.insert(self.editorbtn, 1) 
    110124 
    111125        self.editorbtn.show_all() 
    112126 
    113127    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() 
     128        self.toolbar_box = ToolbarBox() 
    120129 
    121             activity_button = ActivityToolbarButton(self) 
    122             self.toolbar_box.toolbar.insert(activity_button, 0) 
    123             activity_button.show() 
     130        activity_button = ActivityToolbarButton(self) 
     131        self.toolbar_box.toolbar.insert(activity_button, 0) 
     132        activity_button.show() 
    124133 
    125             separator = gtk.SeparatorToolItem() 
    126             separator.props.draw = False 
    127             separator.set_expand(True) 
    128             self.toolbar_box.toolbar.insert(separator, -1) 
     134        separator = Gtk.SeparatorToolItem() 
     135        separator.props.draw = False 
     136        separator.set_expand(True) 
     137        self.toolbar_box.toolbar.insert(separator, -1) 
    129138 
    130             self.toolbar_box.toolbar.insert(StopButton(self), -1) 
     139        self.toolbar_box.toolbar.insert(StopButton(self), -1) 
    131140 
    132             self.set_toolbar_box(self.toolbar_box) 
    133             self.toolbar_box.show_all() 
     141        self.set_toolbar_box(self.toolbar_box) 
     142        self.toolbar_box.show_all() 
    134143 
    135144    def editor_clicked_cb(self, btn): 
    136145        self.push_screen(editlessonlistscreen.EditLessonListScreen(self, self.mainscreen.lessons)) 
     
    146155             
    147156            self.screenbox.remove(oldscreen) 
    148157         
    149         self.screenbox.pack_start(screen, True, True) 
     158        self.screenbox.pack_start(screen, True, True, 0) 
    150159        self.screens.append(screen) 
    151160         
    152161        try: 
     
    172181            except: 
    173182                pass 
    174183             
    175             self.screenbox.pack_start(screen) 
     184            self.screenbox.pack_start(screen, True, True, 0) 
    176185             
    177186    def add_history(self, entry): 
    178187        self.data['history'].append(entry)