diff options
author | Aneesh Dogra <lionaneesh@gmail.com> | 2012-12-20 20:05:16 (GMT) |
---|---|---|
committer | Aneesh Dogra <lionaneesh@gmail.com> | 2012-12-20 20:05:16 (GMT) |
commit | f752f77382cd84c9f2f058efb06f5a03d49daded (patch) | |
tree | 7f30ddcf3a1f641c7123ff975faddbeea7431dfe | |
parent | 4ed4972f6f9bf9d581b7378208930a1c3933a84f (diff) |
Start Gtk3 Port.
-rwxr-xr-x | ConstellationsFlashCards.py | 220 | ||||
-rwxr-xr-x | setup.py | 2 |
2 files changed, 124 insertions, 98 deletions
diff --git a/ConstellationsFlashCards.py b/ConstellationsFlashCards.py index 6938fa4..f888c9b 100755 --- a/ConstellationsFlashCards.py +++ b/ConstellationsFlashCards.py @@ -78,16 +78,20 @@ # =================================== IMPORTS =================================== -import pygtk -pygtk.require('2.0') -import gtk +from gi.repository import Gtk +from gi.repository import Gdk import sys import os -import gobject from math import sin, cos, tan, asin, acos, atan, pi, sqrt, atan2 import random -from sugar.activity import activity -from sugar.activity.activity import get_bundle_path +import cairo +from sugar3.activity import activity +from sugar3.graphics.style import Color +from sugar3.activity.widgets import ActivityToolbarButton +from sugar3.activity.widgets import StopButton +from sugar3.activity.activity import get_bundle_path +from sugar3.graphics.toolbarbox import ToolbarButton +from sugar3.graphics.toolbarbox import ToolbarBox import logging from gettext import gettext @@ -123,22 +127,22 @@ figures = constellations.data # ------------------------------------------------------------------------------- # # controls on second menubar ("Quiz"): -labelq1 = gtk.Label(_("Name")) -cbq1 = gtk.combo_box_new_text() -buttonq1 = gtk.Button(_("Tell me")) -buttonq2 = gtk.Button(_("Another")) +labelq1 = Gtk.Label(_("Name")) +cbq1 = Gtk.ComboBoxText() +buttonq1 = Gtk.Button(_("Tell me")) +buttonq2 = Gtk.Button(_("Another")) # controls on third menubar ("Results"): -containerr1 = gtk.VBox() -labelr1 = gtk.Label(_(" constellations seen.")) -labelr2 = gtk.Label(" ") -labelr3 = gtk.Label(_(" correct on first try.")) -labelr4 = gtk.Label(_(" correct on second try.")) +containerr1 = Gtk.VBox() +labelr1 = Gtk.Label(_(" constellations seen.")) +labelr2 = Gtk.Label(" ") +labelr3 = Gtk.Label(_(" correct on first try.")) +labelr4 = Gtk.Label(_(" correct on second try.")) # controls on last menubar ("About"): -containera1 = gtk.VBox() -labela1 = gtk.Label(_("Version 1.0 (build 10) of 2010.05.19.1500 UT")) -labela2 = gtk.Label(" ") -labela3 = gtk.Label(_("See http://wiki.laptop.org/go/ConstellationsFlashCards for help.")) -labela4 = gtk.Label(" ") +containera1 = Gtk.VBox() +labela1 = Gtk.Label(_("Version 1.0 (build 10) of 2010.05.19.1500 UT")) +labela2 = Gtk.Label(" ") +labela3 = Gtk.Label(_("See http://wiki.laptop.org/go/ConstellationsFlashCards for help.")) +labela4 = Gtk.Label(" ") name_from_abbrev = {} constellations = [] @@ -179,15 +183,16 @@ def rtod(r): # ============================== ChartDisplay Object ============================ -class ChartDisplay(gtk.DrawingArea): +class ChartDisplay(Gtk.DrawingArea): def __init__(self, context): super(ChartDisplay, self).__init__() self.context = context self.colors = {} self.canplot = False self.pangolayout = self.create_pango_layout("") - self.add_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON1_MOTION_MASK | - gtk.gdk.BUTTON2_MOTION_MASK) + self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK | \ + Gdk.ModifierType.BUTTON1_MASK | \ + Gdk.ModifierType.BUTTON2_MASK) self.id = "" self.cname = "" self.points = 5 @@ -210,13 +215,11 @@ class ChartDisplay(gtk.DrawingArea): # Establish color selections (need only do this once). if (len(self.colors) == 0): - self.gc = self.style.fg_gc[gtk.STATE_NORMAL] - self.colormap = self.gc.get_colormap() - self.colors[0] = self.colormap.alloc_color('white') - self.colors[1] = self.colormap.alloc_color('black') - self.colors[2] = self.colormap.alloc_color('red') - self.colors[3] = self.colormap.alloc_color('gray') - self.colors[4] = self.colormap.alloc_color('green') + self.colors[0] = '#FFFFFF' + self.colors[1] = '#000000' + self.colors[2] = '#FF0000' + self.colors[3] = '#C0C0C0' + self.colors[4] = '#00FF00' self.canplot = True self.plotchart(True) else: @@ -341,44 +344,44 @@ class ChartDisplay(gtk.DrawingArea): if (not self.canplot): return self.cleararea() - self.gc.set_foreground(self.colors[0]) - self.window.draw_rectangle(self.gc, - True, - self.xoffset + self.margin - 2, - self.yoffset + self.margin - 2, - self.diameter + 4, - self.diameter + 4) + color_rgb = Color(self.colors[0]).get_rgba()[:-1] # we don't need alpha + ctx = self.get_window().cairo_create() + ctx.set_source_rgb(*color_rgb) + ctx.rectangle(self.xoffset + self.margin - 2, + self.yoffset + self.margin - 2, + self.diameter + 4, + self.diameter + 4) + ctx.fill() # Plot sky square - self.gc.set_foreground(self.colors[1]) - self.window.draw_rectangle(self.gc, - False, - self.xoffset + self.margin - 2, - self.yoffset + self.margin - 2, - self.diameter + 4, - self.diameter + 4) + color_rgb = Color(self.colors[1]).get_rgba()[:-1] # we don't need alpha + ctx = self.get_window().cairo_create() + ctx.set_source_rgb(*color_rgb) + ctx.rectangle(self.xoffset + self.margin - 2, + self.yoffset + self.margin - 2, + self.diameter + 4, + self.diameter + 4) # label the cardinal points. - self.gc.set_foreground(self.colors[1]) - self.pangolayout.set_text(_("N")) - self.window.draw_layout(self.gc, - self.xoffset + self.margin + self.diameter / 2 - 10, - self.margin - 30, self.pangolayout) - self.pangolayout.set_text(_("S")) - self.window.draw_layout(self.gc, - self.xoffset + self.margin + self.diameter / 2 - 10, - 2 * self.margin + self.diameter - 30, self.pangolayout) - self.pangolayout.set_text(_("E")) - self.window.draw_layout(self.gc, - self.xoffset + self.margin - 30, - self.margin + self.diameter / 2 - 10, self.pangolayout) - self.pangolayout.set_text(_("W")) - self.window.draw_layout(self.gc, - self.xoffset + self.margin + self.diameter + 10, - self.margin + self.diameter / 2 - 10, self.pangolayout) - self.gc.set_foreground(self.colors[1]) + color_rgb = Color(self.colors[1]).get_rgba()[:-1] # we don't need alpha + ctx = self.get_window().cairo_create() + ctx.set_source_rgb(*color_rgb) + ctx.move_to(self.xoffset + self.margin + self.diameter / 2 - 10, + self.margin - 30) + ctx.show_text(_("N")) + + ctx.move_to(self.xoffset + self.margin + self.diameter / 2 - 10, + 2 * self.margin + self.diameter - 20) + ctx.show_text(_("S")) + + ctx.move_to(self.xoffset + self.margin - 30, + self.margin + self.diameter / 2 - 10) + ctx.show_text(_("E")) + ctx.move_to(self.xoffset + self.margin + self.diameter + 10, + self.margin + self.diameter / 2 - 10) + ctx.show_text(_("W")) return True @@ -397,7 +400,7 @@ class ChartDisplay(gtk.DrawingArea): if (choose): self.fill_names_combobox() - + """ def plot_stars(self, id): # Plot the stars. @@ -650,18 +653,20 @@ class ChartDisplay(gtk.DrawingArea): for i in range(5): cbq1.append_text(names[i]) + """ def cleararea(self): # Clear the drawing surface - self.gc.set_foreground(self.colors[3]) - self.window.draw_rectangle(self.gc, - True, - 1, - 1, - self.screensize[0], - self.screensize[1]) + color_rgb = Color(self.colors[3]).get_rgba()[:-1] # we don't need alpha + ctx = self.get_window().cairo_create() + ctx.set_source_rgb(*color_rgb) + ctx.rectangle(self.xoffset + self.margin - 2, + self.yoffset + self.margin - 2, + self.screensize[0], + self.screensize[1]) + ctx.fill() # ========================= ConstellationsFlashCards Object ========================== @@ -689,46 +694,74 @@ class ConstellationsFlashCards(activity.Activity): # Create toolbox - toolbox = activity.ActivityToolbox(self) - self.set_toolbox(toolbox) - self.quiz_toolbar = gtk.Toolbar() + toolbar_box = ToolbarBox() + + # Activity Toolbar + activity_button = ActivityToolbarButton(self) + toolbar_box.toolbar.insert(activity_button, -1) + + # Quiz Toolbar + self.quiz_toolbar = Gtk.Toolbar() self.quiz_toolbar.add(labelq1) self.quiz_toolbar.add(cbq1) self.quiz_toolbar.add(buttonq1) self.quiz_toolbar.add(buttonq2) + self.quiz_toolbar.show() + + quiz_toolbar_button = ToolbarButton( + page=self.quiz_toolbar, + label='Quiz') + toolbar_box.toolbar.insert(quiz_toolbar_button, -1) + + # Result Toolbar - self.result_toolbar = gtk.Toolbar() + + self.result_toolbar = Gtk.Toolbar() containerr1.add(labelr1) containerr1.add(labelr2) containerr1.add(labelr3) containerr1.add(labelr4) self.result_toolbar.add(containerr1) - self.about_toolbar = gtk.Toolbar() + quiz_toolbar_button = ToolbarButton( + page=self.result_toolbar, + label='Result') + toolbar_box.toolbar.insert(quiz_toolbar_button, -1) + + # About toolbar + self.about_toolbar = Gtk.Toolbar() containera1.add(labela1) containera1.add(labela2) containera1.add(labela3) containera1.add(labela4) self.about_toolbar.add(containera1) - -# Fill the toolbox bars + self.about_toolbar.show_all() + + about_toolbar_button = ToolbarButton( + page=self.about_toolbar, + label='About') + toolbar_box.toolbar.insert(about_toolbar_button, -1) - toolbox.add_toolbar(_("Quiz"), self.quiz_toolbar) - toolbox.add_toolbar(_("Results"), self.result_toolbar) - toolbox.add_toolbar(_("About"), self.about_toolbar) + # The stop button + stop_button = StopButton(self) + stop_button.props.accelerator = '<Ctrl><Shift>Q' + toolbar_box.toolbar.insert(stop_button, -1) + stop_button.show() + + self.set_toolbar_box(toolbar_box) + toolbar_box.show_all() # Create the GUI objects. - scrolled = gtk.ScrolledWindow() - scrolled.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) - scrolled.props.shadow_type = gtk.SHADOW_NONE + scrolled = Gtk.ScrolledWindow() + scrolled.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) self.chart = ChartDisplay(self) - eb = gtk.EventBox() - vbox = gtk.VBox(False) - self.identifyobject = gtk.Label("") - vbox.pack_start(self.identifyobject, expand=False) - vbox.pack_start(self.chart) - eb.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("gray")) + eb = Gtk.EventBox() + vbox = Gtk.VBox() + self.identifyobject = Gtk.Label("") + vbox.pack_start(self.identifyobject, False, True, 0) + vbox.pack_start(self.chart, True, True, 0) + eb.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("gray")) # Stack the GUI objects. @@ -736,7 +769,7 @@ class ConstellationsFlashCards(activity.Activity): # Connect the event handlers - self.chart.connect("expose_event", self.chart.area_expose_cb) + self.chart.connect("draw", self.chart.area_expose_cb) buttonq1.connect("clicked", self.chart.callback, "tell_me") buttonq2.connect("clicked", self.chart.callback, "another") cbq1.connect("changed", self.chart.callback, "select_name") @@ -749,18 +782,11 @@ class ConstellationsFlashCards(activity.Activity): # Show the GUI stack. - toolbox.show() - toolbox.set_current_toolbar(1) self.chart.show() eb.show() scrolled.show() self.show_all() -# FIXME: We can't do sharing yet, so hide the control for it. - - toolbar = toolbox.get_activity_toolbar() - toolbar.share.hide() - # If C_FC.cfg exists, get the previous scores. self.read_file(self.datafile) @@ -1,5 +1,5 @@ #!/usr/bin/env python -from sugar.activity import bundlebuilder +from sugar3.activity import bundlebuilder if __name__ == "__main__": bundlebuilder.start() |