[Sugar-devel] [PATCH Finance] Port to Gtk3 SL #3740

Manuel Kaufmann humitos at gmail.com
Mon Jul 2 12:46:12 EDT 2012


Migrated completely to Gtk3.

There is only one thing related to the Gtk3 theme that it's not
working properly. It happens when the mouse is over the icon selected
on the toolbar, view subtoolbar icons for example (SL #3739)

Signed-off-by: Manuel Kaufmann <humitos at gmail.com>
---
 budgetscreen.py   |   58 ++++++++---------
 chartscreen.py    |   58 +++++++++--------
 finance.py        |  184 ++++++++++++++++++++++-------------------------------
 registerscreen.py |   52 +++++++--------
 setup.py          |    2 +-
 5 files changed, 161 insertions(+), 193 deletions(-)

diff --git a/budgetscreen.py b/budgetscreen.py
index 41a1dbd..c38617e 100644
--- a/budgetscreen.py
+++ b/budgetscreen.py
@@ -21,31 +21,32 @@ from gettext import gettext as _
 # Set up localization.
 locale.setlocale(locale.LC_ALL, '')
 
-# Import PyGTK.
-import gobject, pygtk, gtk, pango, cairo
+from gi.repository import Gtk
+from gi.repository import Gdk
+from gi.repository import GObject
 
 # Import Sugar UI modules.
-import sugar.activity.activity
-from sugar.graphics import *
+import sugar3.activity.activity
+from sugar3.graphics import *
 
 # Import activity module
 import finance
 
 BUDGET_HELP = _('The Budget view allows you to set a monthly budget for each expense category, and to keep track of your\nbudgets.  To set a budget, type the amount in the box to the right of the category.')
 
-class BudgetScreen(gtk.VBox):
+class BudgetScreen(Gtk.VBox):
     def __init__(self, activity):
-        gtk.VBox.__init__(self)
+        GObject.GObject.__init__(self)
 
         self.activity = activity
 
         self.category_total = {}
         self.sorted_categories = []
  
-        self.budgetbox = gtk.VBox()
+        self.budgetbox = Gtk.VBox()
 
-        scroll = gtk.ScrolledWindow()
-        scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
+        scroll = Gtk.ScrolledWindow()
+        scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
         scroll.add_with_viewport(self.budgetbox)
 
         self.pack_start(scroll, True, True, 0)
@@ -72,26 +73,26 @@ class BudgetScreen(gtk.VBox):
             self.budgetbox.remove(w)
 
         # Build header.
-        catlabel = gtk.Label()
+        catlabel = Gtk.Label()
         catlabel.set_markup('<b><big>'+_('Category')+'</big></b>')
-        spentlabel = gtk.Label()
+        spentlabel = Gtk.Label()
         spentlabel.set_markup('<b><big>'+_('Spent')+'</big></b>')
-        budgetlabel = gtk.Label()
+        budgetlabel = Gtk.Label()
         budgetlabel.set_markup('<b><big>'+_('Budget')+'</big></b>')
         
-        headerbox = gtk.HBox()
+        headerbox = Gtk.HBox()
         headerbox.pack_start(catlabel, False, True, 20)
         headerbox.pack_start(spentlabel, True, True, 10)
         headerbox.pack_start(budgetlabel, False, True, 20)
         self.budgetbox.pack_start(headerbox, False, False, 10)
 
-        catgroup = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
+        catgroup = Gtk.SizeGroup(Gtk.SizeGroupMode.HORIZONTAL)
         catgroup.add_widget(catlabel)
 
-        spentgroup = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
+        spentgroup = Gtk.SizeGroup(Gtk.SizeGroupMode.HORIZONTAL)
         spentgroup.add_widget(spentlabel)
 
-        budgetgroup = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
+        budgetgroup = Gtk.SizeGroup(Gtk.SizeGroupMode.HORIZONTAL)
         budgetgroup.add_widget(budgetlabel)
         
         # Build categories.
@@ -100,22 +101,23 @@ class BudgetScreen(gtk.VBox):
             # If there is no category, display as Unknown
             if c is '':
                 description = _('Unknown')
-            catbox = gtk.Label(description)
+            catbox = Gtk.Label(label=description)
             catbox.set_padding(10, 0)
 
             color = finance.get_category_color_str(c)
 
-            ebox = gtk.EventBox()
-            ebox.modify_bg(gtk.STATE_NORMAL, ebox.get_colormap().alloc_color(color))
+            ebox = Gtk.EventBox()
+            parse, color = Gdk.Color.parse(color)
+            ebox.modify_bg(Gtk.StateType.NORMAL, color)
             ebox.add(catbox)
 
             catgroup.add_widget(ebox)
 
-            bar = gtk.DrawingArea()
-            bar.connect('expose-event', self.bar_expose_cb, c)
+            bar = Gtk.DrawingArea()
+            bar.connect('draw', self.bar_draw_cb, c)
             spentgroup.add_widget(bar)
 
-            budgetentry = gtk.Entry()
+            budgetentry = Gtk.Entry()
             budgetentry.connect('changed', self.budget_changed_cb, c)
             budgetentry.set_width_chars(10)
             if self.activity.data['budgets'].has_key(c):
@@ -123,18 +125,18 @@ class BudgetScreen(gtk.VBox):
                 budgetentry.set_text(locale.currency(b['amount'], False))
             budgetgroup.add_widget(budgetentry)
 
-            #freqcombo = gtk.combo_box_new_text()
+            #freqcombo = Gtk.ComboBoxText()
             #freqcombo.append_text(_('Daily'))
             #freqcombo.append_text(_('Weekly'))
             #freqcombo.append_text(_('Monthly'))
             #freqcombo.append_text(_('Annually'))
             #freqcombo.set_active(2)
 
-            hbox = gtk.HBox()
+            hbox = Gtk.HBox()
             hbox.pack_start(ebox, False, False, 20)
             hbox.pack_start(bar, True, True, 10)
             hbox.pack_start(budgetentry, False, False, 20)
-            #hbox.pack_start(freqcombo)
+            #hbox.pack_start(freqcombo, True, True, 0)
 
             self.budgetbox.pack_start(hbox, False, False, 5)
 
@@ -142,11 +144,7 @@ class BudgetScreen(gtk.VBox):
             
         self.activity.set_help(BUDGET_HELP)
 
-    def bar_expose_cb(self, widget, event, category):
-        cr = widget.window.cairo_create()
-        cr.rectangle(event.area.x, event.area.y, event.area.width, event.area.height)
-        cr.clip()
-
+    def bar_draw_cb(self, widget, cr, category):
         bounds = widget.get_allocation()
 
         # Draw amount of time spent in period if sensible.
diff --git a/chartscreen.py b/chartscreen.py
index b984b33..cf1a412 100644
--- a/chartscreen.py
+++ b/chartscreen.py
@@ -21,43 +21,47 @@ from gettext import gettext as _
 # Set up localization.
 locale.setlocale(locale.LC_ALL, '')
 
-# Import PyGTK.
-import gobject, pygtk, gtk, pango, cairo
+from gi.repository import Gtk
+from gi.repository import Gdk
+from gi.repository import GObject
 
 # Import Sugar UI modules.
-import sugar.activity.activity
-from sugar.graphics import *
+import sugar3.activity.activity
+from sugar3.graphics import *
 
 # Import activity module
 import finance
 
 CHART_HELP = _('The Chart view shows the proportion of your expenses that is in each category.\nYou can categorize transactions in the Register view.')
 
-class ChartScreen(gtk.HBox):
+class ChartScreen(Gtk.HBox):
     def __init__(self, activity):
-        gtk.HBox.__init__(self)
+        GObject.GObject.__init__(self)
 
         self.activity = activity
 
         self.category_total = {}
         self.sorted_categories = []
 
-        self.area = gtk.DrawingArea()
-        self.area.connect('expose-event', self.chart_expose_cb)
+        self.area = Gtk.DrawingArea()
+        self.area.connect('draw', self.chart_draw_cb)
 
-        label = gtk.Label()
+        label = Gtk.Label()
         label.set_markup('<b>'+_('Debit Categories')+'</b>')
 
-        self.catbox = gtk.VBox()
+        self.catbox = Gtk.VBox()
 
-        box = gtk.VBox()
-        box.pack_start(gtk.VBox(), False, False, 40)
-        box.pack_start(label, False, False)
-        box.pack_start(gtk.HSeparator(), False, False)
+        box = Gtk.VBox()
+        box.pack_start(Gtk.Box(orientation=Gtk.Orientation.VERTICAL),
+                       False, False, 40)
+        box.pack_start(label, False, False, 0)
+        box.pack_start(Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL),
+                       False, False, 0)
         box.pack_start(self.catbox, False, False, 10)
-        box.pack_start(gtk.VBox(), True, True)
+        box.pack_start(Gtk.Box(orientation=Gtk.Orientation.VERTICAL),
+                       True, True, 0)
  
-        self.pack_start(self.area, True, True)
+        self.pack_start(self.area, True, True, 0)
         self.pack_start(box, False, False, 40)
 
         self.show_all()
@@ -83,30 +87,32 @@ class ChartScreen(gtk.HBox):
         for w in self.catbox.get_children():
             self.catbox.remove(w)
 
-        catgroup = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
-        amountgroup = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
+        catgroup = Gtk.SizeGroup(Gtk.SizeGroupMode.HORIZONTAL)
+        amountgroup = Gtk.SizeGroup(Gtk.SizeGroupMode.HORIZONTAL)
         
         for c in self.sorted_categories:
-            hbox = gtk.HBox()
+            hbox = Gtk.HBox()
 
             description = c
             # If there is no category, display as Unknown
             if c is '':
                 description = _('Unknown')
-            catlabel = gtk.Label(description)
+            catlabel = Gtk.Label(label=description)
             catgroup.add_widget(catlabel)
 
             color = finance.get_category_color_str(c)
 
-            amountlabel = gtk.Label()
+            amountlabel = Gtk.Label()
             amountlabel.set_markup(locale.currency(self.category_total[c]))
             amountgroup.add_widget(amountlabel)
 
             hbox.pack_start(amountlabel, True, True, 20)
             hbox.pack_start(catlabel, True, True, 20)
 
-            ebox = gtk.EventBox()
-            ebox.modify_bg(gtk.STATE_NORMAL, ebox.get_colormap().alloc_color(color))
+            ebox = Gtk.EventBox()
+
+            parse, color = Gdk.Color.parse(color)
+            ebox.modify_bg(Gtk.StateType.NORMAL, color)
             ebox.add(hbox)
 
             self.catbox.pack_end(ebox, False, False, 5)
@@ -116,11 +122,7 @@ class ChartScreen(gtk.HBox):
         # Update the help text.
         self.activity.set_help(CHART_HELP)
 
-    def chart_expose_cb(self, widget, event):
-        context = widget.window.cairo_create()
-        context.rectangle(event.area.x, event.area.y, event.area.width, event.area.height)
-        context.clip()
-
+    def chart_draw_cb(self, widget, context):
         # Draw pie chart.
         bounds = widget.get_allocation()
 
diff --git a/finance.py b/finance.py
index a5626b8..3720873 100644
--- a/finance.py
+++ b/finance.py
@@ -25,25 +25,21 @@ from port import json
 # Set up localization.
 locale.setlocale(locale.LC_ALL, '')
 
-# Import PyGTK.
-import gobject, pygtk, gtk, pango, cairo
+from gi.repository import Gtk
+from gi.repository import Gdk
 
 # Import Sugar UI modules.
-import sugar.activity.activity
-from sugar.graphics.toggletoolbutton import ToggleToolButton
-from sugar.graphics.toolbutton import ToolButton
-from sugar.graphics.toolcombobox import ToolComboBox
-from sugar.graphics import *
-
-OLD_TOOLBAR = False
-try:
-    from sugar.graphics.toolbarbox import ToolbarBox
-    from sugar.graphics.toolbarbox import ToolbarButton
-    from sugar.graphics.radiotoolbutton import RadioToolButton
-    from sugar.activity.widgets import StopButton
-    from sugar.activity.widgets import ActivityToolbarButton
-except ImportError:
-    OLD_TOOLBAR = True
+import sugar3.activity.activity
+from sugar3.graphics.toggletoolbutton import ToggleToolButton
+from sugar3.graphics.toolbutton import ToolButton
+from sugar3.graphics.toolcombobox import ToolComboBox
+from sugar3.graphics import *
+
+from sugar3.graphics.toolbarbox import ToolbarBox
+from sugar3.graphics.toolbarbox import ToolbarButton
+from sugar3.graphics.radiotoolbutton import RadioToolButton
+from sugar3.activity.widgets import StopButton
+from sugar3.activity.widgets import ActivityToolbarButton
 
 # Initialize logging.
 log = logging.getLogger('Finance')
@@ -94,9 +90,9 @@ def get_category_color_str(catname):
 # 
 # It owns the main application window, and all the various toolbars and options.
 # Screens are stored in a stack, with the currently active screen on top.
-class Finance(sugar.activity.activity.Activity):
+class Finance(sugar3.activity.activity.Activity):
     def __init__ (self, handle):
-        sugar.activity.activity.Activity.__init__(self, handle)
+        sugar3.activity.activity.Activity.__init__(self, handle)
         self.set_title(_("Finance"))
         self.max_participants = 1
 
@@ -133,39 +129,41 @@ class Finance(sugar.activity.activity.Activity):
         self.build_toolbox()
   
         self.screens = []
-        self.screenbox = gtk.VBox()
+        self.screenbox = Gtk.VBox()
 
         # Add the context sensitive help.
-        self.helplabel = gtk.Label()
+        self.helplabel = Gtk.Label()
         self.helplabel.set_padding(10, 10)
-        self.helpbox = gtk.EventBox()
-        self.helpbox.modify_bg(gtk.STATE_NORMAL, self.helpbox.get_colormap().alloc_color('#000000'))
+        self.helpbox = Gtk.EventBox()
+        parse, color = Gdk.Color.parse('#000000')
+        self.helpbox.modify_bg(Gtk.StateType.NORMAL, color)
         self.helpbox.add(self.helplabel)
 
         # Add the header.
-        self.periodlabel = gtk.Label()
+        self.periodlabel = Gtk.Label()
         self.periodlabel.set_padding(10, 0)
 
-        headerbox = gtk.HBox()
-        headerbox.pack_end(self.periodlabel, False, False)
+        headerbox = Gtk.HBox()
+        headerbox.pack_end(self.periodlabel, False, False, 0)
 
         # Add the summary data.
-        self.startlabel = gtk.Label()
-        self.creditslabel = gtk.Label()
-        self.debitslabel = gtk.Label()
-        self.balancelabel = gtk.Label()
+        self.startlabel = Gtk.Label()
+        self.creditslabel = Gtk.Label()
+        self.debitslabel = Gtk.Label()
+        self.balancelabel = Gtk.Label()
 
-        summarybox = gtk.HBox()
-        summarybox.pack_start(self.startlabel, True, False)
-        summarybox.pack_start(self.creditslabel, True, False)
-        summarybox.pack_start(self.debitslabel, True, False)
-        summarybox.pack_start(self.balancelabel, True, False)
+        summarybox = Gtk.HBox()
+        summarybox.pack_start(self.startlabel, True, False, 0)
+        summarybox.pack_start(self.creditslabel, True, False, 0)
+        summarybox.pack_start(self.debitslabel, True, False, 0)
+        summarybox.pack_start(self.balancelabel, True, False, 0)
 
-        vbox = gtk.VBox()
+        vbox = Gtk.VBox()
 
         vbox.pack_start(self.helpbox, False, False, 10)
         vbox.pack_start(headerbox, False, False, 10)
-        vbox.pack_start(gtk.HSeparator(), False, False, 0)
+        vbox.pack_start(Gtk.Separator(orientation=Gtk.Orientation.VERTICAL),
+                        False, False, 0)
         vbox.pack_start(self.screenbox, True, True, 0)
         vbox.pack_start(summarybox, False, False, 10)
 
@@ -177,12 +175,6 @@ class Finance(sugar.activity.activity.Activity):
 
         self.show_all()
 
-        if OLD_TOOLBAR:
-            # Hide the sharing button from the activity toolbar since
-            # we don't support it.
-            activity_toolbar = self.tbox.get_activity_toolbar()
-            activity_toolbar.share.props.visible = False
-
     def build_toolbox(self):
         self.newcreditbtn = ToolButton('row-insert-credit')
         self.newcreditbtn.set_tooltip(_("New Credit"))
@@ -199,7 +191,7 @@ class Finance(sugar.activity.activity.Activity):
         self.eraseitembtn.props.accelerator = '<Ctrl>E'
         self.eraseitembtn.connect('clicked', self.register.eraseitem_cb)
 
-        transactionbar = gtk.Toolbar()
+        transactionbar = Gtk.Toolbar()
         transactionbar.insert(self.newcreditbtn, -1)
         transactionbar.insert(self.newdebitbtn, -1)
         transactionbar.insert(self.eraseitembtn, -1)
@@ -216,15 +208,15 @@ class Finance(sugar.activity.activity.Activity):
         self.nextperiodbtn.props.accelerator = '<Ctrl>Right'
         self.nextperiodbtn.connect('clicked', self.nextperiod_cb)
 
-        periodsep = gtk.SeparatorToolItem()
+        periodsep = Gtk.SeparatorToolItem()
         periodsep.set_expand(True)
         periodsep.set_draw(False)
 
-        periodlabel = gtk.Label(_('Period: '))
-        periodlabelitem = gtk.ToolItem()
+        periodlabel = Gtk.Label(label=_('Period: '))
+        periodlabelitem = Gtk.ToolItem()
         periodlabelitem.add(periodlabel)
 
-        periodcombo = gtk.combo_box_new_text()
+        periodcombo = Gtk.ComboBoxText()
         periodcombo.append_text(_('Day'))
         periodcombo.append_text(_('Week'))
         periodcombo.append_text(_('Month'))
@@ -261,7 +253,7 @@ class Finance(sugar.activity.activity.Activity):
         chartbtn.props.accelerator = '<Ctrl>3'
         chartbtn.connect('clicked', self.chart_cb)
 
-        viewbar = gtk.Toolbar()
+        viewbar = Gtk.Toolbar()
         viewbar.insert(registerbtn, -1)
         viewbar.insert(budgetbtn, -1)
         viewbar.insert(chartbtn, -1)
@@ -271,72 +263,48 @@ class Finance(sugar.activity.activity.Activity):
         helpbtn.set_tooltip(_("Show Help"))
         helpbtn.connect('clicked', self.help_cb)
 
-        if OLD_TOOLBAR:
-            periodbar = gtk.Toolbar()
-            periodbar.insert(self.prevperiodbtn, -1)
-            periodbar.insert(self.nextperiodbtn, -1)
-            periodbar.insert(self.thisperiodbtn, -1)
-            periodbar.insert(periodsep, -1)
-            periodbar.insert(periodlabelitem, -1)
-            periodbar.insert(perioditem, -1)
-
-            self.tbox = sugar.activity.activity.ActivityToolbox(self)
-            self.tbox.add_toolbar(_('Transaction'), transactionbar)
-            self.tbox.add_toolbar(_('Period'), periodbar)
-            self.tbox.add_toolbar(_('View'), viewbar)
-            self.tbox.show_all()
-
-            # Add help button in place of share:
-            activity_toolbar = self.tbox.get_activity_toolbar()
-            share_idx = activity_toolbar.get_item_index(activity_toolbar.share)
-            activity_toolbar.insert(helpbtn, share_idx)
-            helpbtn.show_all()
-
-            self.set_toolbox(self.tbox)
-
-        else:
-            self.toolbar_box = ToolbarBox()
+        self.toolbar_box = ToolbarBox()
 
-            activity_button = ActivityToolbarButton(self)
-            self.toolbar_box.toolbar.insert(activity_button, 0)
-            activity_button.show()
+        activity_button = ActivityToolbarButton(self)
+        self.toolbar_box.toolbar.insert(activity_button, 0)
+        activity_button.show()
 
-            transaction_toolbar_button = ToolbarButton(
-                    page=transactionbar,
-                    icon_name='transaction')
-            transactionbar.show_all()
+        transaction_toolbar_button = ToolbarButton(
+            page=transactionbar,
+            icon_name='transaction')
+        transactionbar.show_all()
 
-            view_toolbar_button = ToolbarButton(
-                    page=viewbar,
-                    icon_name='toolbar-view')
-            viewbar.show_all()
+        view_toolbar_button = ToolbarButton(
+            page=viewbar,
+            icon_name='toolbar-view')
+        viewbar.show_all()
 
-            self.toolbar_box.toolbar.insert(transaction_toolbar_button, -1)
-            transaction_toolbar_button.show()
+        self.toolbar_box.toolbar.insert(transaction_toolbar_button, -1)
+        transaction_toolbar_button.show()
 
-            self.toolbar_box.toolbar.view = view_toolbar_button
-            self.toolbar_box.toolbar.insert(view_toolbar_button, -1)
-            view_toolbar_button.show()
+        self.toolbar_box.toolbar.view = view_toolbar_button
+        self.toolbar_box.toolbar.insert(view_toolbar_button, -1)
+        view_toolbar_button.show()
 
-            separator = gtk.SeparatorToolItem()
-            separator.set_draw(True)
-            self.toolbar_box.toolbar.insert(separator, -1)
+        separator = Gtk.SeparatorToolItem()
+        separator.set_draw(True)
+        self.toolbar_box.toolbar.insert(separator, -1)
 
-            self.toolbar_box.toolbar.insert(periodlabelitem, -1)
-            self.toolbar_box.toolbar.insert(perioditem, -1)
-            self.toolbar_box.toolbar.insert(self.prevperiodbtn, -1)
-            self.toolbar_box.toolbar.insert(self.nextperiodbtn, -1)
-            self.toolbar_box.toolbar.insert(self.thisperiodbtn, -1)
+        self.toolbar_box.toolbar.insert(periodlabelitem, -1)
+        self.toolbar_box.toolbar.insert(perioditem, -1)
+        self.toolbar_box.toolbar.insert(self.prevperiodbtn, -1)
+        self.toolbar_box.toolbar.insert(self.nextperiodbtn, -1)
+        self.toolbar_box.toolbar.insert(self.thisperiodbtn, -1)
 
-            separator = gtk.SeparatorToolItem()
-            separator.props.draw = False
-            separator.set_expand(True)
-            self.toolbar_box.toolbar.insert(separator, -1)
+        separator = Gtk.SeparatorToolItem()
+        separator.props.draw = False
+        separator.set_expand(True)
+        self.toolbar_box.toolbar.insert(separator, -1)
 
-            self.toolbar_box.toolbar.insert(helpbtn, -1)
-            self.toolbar_box.toolbar.insert(StopButton(self), -1)
-            self.set_toolbar_box(self.toolbar_box)
-            self.toolbar_box.show_all()
+        self.toolbar_box.toolbar.insert(helpbtn, -1)
+        self.toolbar_box.toolbar.insert(StopButton(self), -1)
+        self.set_toolbar_box(self.toolbar_box)
+        self.toolbar_box.show_all()
 
     def set_help(self, text):
         if self.helplabel != None:
@@ -364,7 +332,7 @@ class Finance(sugar.activity.activity.Activity):
         if len(self.screens):
             self.screenbox.remove(self.screens[-1])
  
-        self.screenbox.pack_start(screen, True, True)
+        self.screenbox.pack_start(screen, True, True, 0)
         self.screens.append(screen)
 
         self.build_screen()
@@ -373,7 +341,7 @@ class Finance(sugar.activity.activity.Activity):
         self.screenbox.remove(self.screens[-1])
         self.screens.pop()
         if len(self.screens):
-            self.screenbox.pack_start(self.screens[-1])
+            self.screenbox.pack_start(self.screens[-1], True, True, 0)
 
     def build_screen(self):
         self.build_visible_transactions()
diff --git a/registerscreen.py b/registerscreen.py
index b7336d6..969a474 100644
--- a/registerscreen.py
+++ b/registerscreen.py
@@ -21,74 +21,74 @@ from gettext import gettext as _
 # Set up localization.
 locale.setlocale(locale.LC_ALL, '')
 
-# Import PyGTK.
-import gobject, pygtk, gtk, pango, cairo
+from gi.repository import Gtk
+from gi.repository import GObject
 
 # Import Sugar UI modules.
-import sugar.activity.activity
-from sugar.graphics import *
+import sugar3.activity.activity
+from sugar3.graphics import *
 
 # Import activity module
 import finance
 
 REGISTER_HELP = _('<b>Welcome to Finance!</b>   This activity keeps track of income and expenses for anything that earns\nor spends money, like a school club.  To get started, use the Transaction box to add credits and debits.\nOnce you have entered some transactions, visit the Chart and Budget views to see more.')
 
-class RegisterScreen(gtk.VBox):
+class RegisterScreen(Gtk.VBox):
     def __init__(self, activity):
-        gtk.VBox.__init__(self)
+        GObject.GObject.__init__(self)
 
         self.activity = activity
 
         # Build the transaction list.
-        self.treeview = gtk.TreeView()
+        self.treeview = Gtk.TreeView()
         self.treeview.set_rules_hint(True)
         self.treeview.set_enable_search(False)
 
         # Note that the only thing we store in our liststore is the transaction id.
         # All the actual data is in the activity database.
-        self.liststore = gtk.ListStore(gobject.TYPE_INT)
+        self.liststore = Gtk.ListStore(GObject.TYPE_INT)
         self.treeview.set_model(self.liststore)
 
         # Construct the columns.
-        renderer = gtk.CellRendererText()
+        renderer = Gtk.CellRendererText()
         renderer.props.editable = True
         renderer.connect('editing-started', self.description_editing_started_cb)
         renderer.connect('edited', self.description_edit_cb)
-        col = gtk.TreeViewColumn(_('Description'), renderer)
+        col = Gtk.TreeViewColumn(_('Description'), renderer)
         col.set_cell_data_func(renderer, self.description_render_cb) 
         col.set_expand(True)
         self.treeview.append_column(col)
 
-        renderer = gtk.CellRendererText()
+        renderer = Gtk.CellRendererText()
         renderer.props.editable = True
         renderer.connect('edited', self.amount_edit_cb)
-        col = gtk.TreeViewColumn(_('Amount'), renderer)
+        col = Gtk.TreeViewColumn(_('Amount'), renderer)
         col.set_cell_data_func(renderer, self.amount_render_cb) 
         col.set_alignment(0.5)
         col.set_min_width(120)
         self.treeview.append_column(col)
 
-        renderer = gtk.CellRendererText()
+        renderer = Gtk.CellRendererText()
         renderer.props.editable = True
         renderer.connect('edited', self.date_edit_cb)
-        col = gtk.TreeViewColumn(_('Date'), renderer)
+        col = Gtk.TreeViewColumn(_('Date'), renderer)
         col.set_alignment(0.5)
         col.set_cell_data_func(renderer, self.date_render_cb) 
         col.set_min_width(150)
         self.treeview.append_column(col)
 
-        renderer = gtk.CellRendererText()
+        renderer = Gtk.CellRendererText()
         renderer.props.editable = True
         renderer.connect('editing-started', self.category_editing_started_cb)
         renderer.connect('edited', self.category_edit_cb)
-        col = gtk.TreeViewColumn(_('Category'), renderer)
+        col = Gtk.TreeViewColumn(_('Category'), renderer)
         col.set_cell_data_func(renderer, self.category_render_cb) 
         col.set_alignment(0.5)
         col.set_min_width(300)
         self.treeview.append_column(col)
 
-        scroll = gtk.ScrolledWindow()
-        scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
+        scroll = Gtk.ScrolledWindow()
+        scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
         scroll.add(self.treeview)
 
         self.pack_start(scroll, True, True, 0)
@@ -102,17 +102,17 @@ class RegisterScreen(gtk.VBox):
         # Update the help text.
         self.activity.set_help(REGISTER_HELP)
 
-    def description_render_cb(self, column, cell_renderer, model, iter):
+    def description_render_cb(self, column, cell_renderer, model, iter, data):
         id = model.get_value(iter, 0)
         t = self.activity.transaction_map[id]
         cell_renderer.set_property('text', t['name'])
 
     def description_editing_started_cb(self, cell_renderer, editable, path):
-        completion = gtk.EntryCompletion()
+        completion = Gtk.EntryCompletion()
         completion.set_inline_completion(True)
         completion.set_popup_completion(True)
         completion.set_minimum_key_length(0)
-        store = gtk.ListStore(str)
+        store = Gtk.ListStore(str)
         for c in self.activity.transaction_names.keys():
             store.append([c])
         completion.set_model(store)
@@ -130,7 +130,7 @@ class RegisterScreen(gtk.VBox):
                 if ct['name'] == new_text and ct['category'] != '':
                     t['category'] = ct['category']
 
-    def amount_render_cb(self, column, cell_renderer, model, iter):
+    def amount_render_cb(self, column, cell_renderer, model, iter, data):
         id = model.get_value(iter, 0)
         t = self.activity.transaction_map[id]
         cell_renderer.set_property('xalign', 1.0)
@@ -147,7 +147,7 @@ class RegisterScreen(gtk.VBox):
         t['amount'] = abs(locale.atof(new_text))
         self.activity.update_summary()
 
-    def date_render_cb(self, column, cell_renderer, model, iter):
+    def date_render_cb(self, column, cell_renderer, model, iter, data):
         id = model.get_value(iter, 0)
         t = self.activity.transaction_map[id]
         when = datetime.date.fromordinal(t['date'])
@@ -162,18 +162,18 @@ class RegisterScreen(gtk.VBox):
         t['date'] = when.toordinal()
         self.activity.build_screen()
 
-    def category_render_cb(self, column, cell_renderer, model, iter):
+    def category_render_cb(self, column, cell_renderer, model, iter, data):
         id = model.get_value(iter, 0)
         t = self.activity.transaction_map[id]
         cell_renderer.set_property('text', t['category'])
         cell_renderer.set_property('background', finance.get_category_color_str(t['category']))
 
     def category_editing_started_cb(self, cell_renderer, editable, path):
-        completion = gtk.EntryCompletion()
+        completion = Gtk.EntryCompletion()
         completion.set_inline_completion(True)
         completion.set_popup_completion(True)
         completion.set_minimum_key_length(0)
-        store = gtk.ListStore(str)
+        store = Gtk.ListStore(str)
         for c in self.activity.category_names.keys():
             store.append([c])
         completion.set_model(store)
diff --git a/setup.py b/setup.py
index 77fda74..c17ead5 100755
--- a/setup.py
+++ b/setup.py
@@ -1,4 +1,4 @@
 #!/usr/bin/env python
-from sugar.activity import bundlebuilder
+from sugar3.activity import bundlebuilder
 if __name__ == "__main__":
     bundlebuilder.start()
-- 
1.7.10.4



More information about the Sugar-devel mailing list