From f068c4d5c1709c6b282eee7c9196f6a77227fc88 Mon Sep 17 00:00:00 2001 From: Aneesh Dogra Date: Sat, 22 Dec 2012 16:20:50 +0000 Subject: Fixes. --- diff --git a/ConstellationsFlashCards.py b/ConstellationsFlashCards.py index 66c87e6..2e133b6 100644 --- a/ConstellationsFlashCards.py +++ b/ConstellationsFlashCards.py @@ -155,6 +155,7 @@ constellations = [] # a session starts, we multiply the point score for each constellation by 0.8 as it is # read in. # +colors = ['#FFFFFF', '#000000', '#CCCCCC'] score = {} seen = [] session_count = 1 @@ -182,7 +183,6 @@ 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(Gdk.EventMask.BUTTON_PRESS_MASK | \ @@ -207,20 +207,10 @@ class ChartDisplay(Gtk.DrawingArea): self.xoffset = (self.screensize[0] - self.diameter) / 2 - self.margin self.yoffset = (self.screensize[1] - self.diameter) / 2 - self.margin self.ctx = self.get_window().cairo_create() + self.canplot = True + self.plotchart(False) -# Establish color selections (need only do this once). - - if (len(self.colors) == 0): - self.colors[0] = '#FFFFFF' - self.colors[1] = '#000000' - self.colors[2] = '#C0C0C0' - self.canplot = True - self.plotchart(True) - else: - self.plotchart(False) - - - def callback(self, widget, data=None, activity_instance=None): + def callback(self, widget, data=None): global score global seen global quiz_count @@ -231,6 +221,7 @@ class ChartDisplay(Gtk.DrawingArea): if (data == None): pass + elif (data == "tell_me"): self.context.identifyobject.set_label(_("This constellation is named ") + \ self.cname) @@ -239,6 +230,7 @@ class ChartDisplay(Gtk.DrawingArea): labelr4.set_label(str(correct_second_count) + _(" correct on second try.")) cbq1.set_sensitive(False) buttonq1.set_sensitive(False) + elif (data == "another"): self.context.identifyobject.set_label("") cbq1.set_sensitive(True) @@ -249,6 +241,7 @@ class ChartDisplay(Gtk.DrawingArea): labelr3.set_label(str(correct_first_count) + _(" correct on first try. ")) labelr4.set_label(str(correct_second_count) + _(" correct on second try.")) self.plotchart(True) + elif (data == "select_name"): if (cbq1.get_active() >= 0): name = cbq1.get_active_text() @@ -272,7 +265,8 @@ class ChartDisplay(Gtk.DrawingArea): labelr1.set_label(str(quiz_count) + _(" constellations seen. ")) labelr3.set_label(str(correct_first_count) + _(" correct on first try. ")) labelr4.set_label(str(correct_second_count) + _(" correct on second try.")) - elif data == 'reset_results' and activity_instance: + + elif data == 'reset_results': quiz_count = 0 correct_first_count = 0 correct_second_count = 0 @@ -280,11 +274,12 @@ class ChartDisplay(Gtk.DrawingArea): labelr1.set_label(str(quiz_count) + _(" constellations seen. ")) labelr3.set_label(str(correct_first_count) + _(" correct on first try. ")) labelr4.set_label(str(correct_second_count) + _(" correct on second try.")) - activity_instance.write_file(activity_instance.datafile) + self.context.write_file(self.context.datafile) + else: pass - return False + return False # Convert equatorial coordinates to pixel position(x, y) in normalized form on a square # of self.diameter pixels. RA is in hours; dec is in degrees. @@ -335,11 +330,8 @@ class ChartDisplay(Gtk.DrawingArea): # Methods for drawing the chart: def plotchart(self, newplot): - if (self.canplot): - self.plot_field() - self.plot_sky(newplot) - return True - + self.plot_field() + self.plot_sky(newplot) def plot_field(self): @@ -348,7 +340,7 @@ class ChartDisplay(Gtk.DrawingArea): if (not self.canplot): return self.cleararea() - color_rgb = Color(self.colors[0]).get_rgba()[:-1] # we don't need alpha + color_rgb = Color(colors[0]).get_rgba()[:-1] # we don't need alpha self.ctx.set_source_rgb(*color_rgb) self.ctx.rectangle(self.xoffset + self.margin - 2, self.yoffset + self.margin - 2, @@ -356,7 +348,7 @@ class ChartDisplay(Gtk.DrawingArea): self.diameter + 4) self.ctx.fill() # Plot sky square - color_rgb = Color(self.colors[1]).get_rgba()[:-1] # we don't need alpha + color_rgb = Color(colors[1]).get_rgba()[:-1] # we don't need alpha self.ctx.set_source_rgb(*color_rgb) self.ctx.rectangle(self.xoffset + self.margin - 2, self.yoffset + self.margin - 2, @@ -380,11 +372,10 @@ class ChartDisplay(Gtk.DrawingArea): self.ctx.move_to(self.xoffset + self.margin + self.diameter + 10, self.margin + self.diameter / 2 - 10) self.ctx.show_text(_("W")) - color_rgb = Color(self.colors[1]).get_rgba()[:-1] # we don't need alpha + color_rgb = Color(colors[1]).get_rgba()[:-1] # we don't need alpha self.ctx.set_source_rgb(*color_rgb) return True - def plot_sky(self, choose): if (choose): self.cnumber = random.randrange(len(constellations)) @@ -470,6 +461,7 @@ class ChartDisplay(Gtk.DrawingArea): else: # never skip pass seen[self.cnumber] = 5 + print "Picking : ", id return id @@ -649,14 +641,13 @@ class ChartDisplay(Gtk.DrawingArea): cbq1.append_text(names[i]) def cleararea(self): - # Clear the drawing surface - color_rgb = Color(self.colors[2]).get_rgba()[:-1] # we don't need alpha + color_rgb = Color(colors[2]).get_rgba()[:-1] # we don't need alpha self.ctx = self.get_window().cairo_create() self.ctx.set_source_rgb(*color_rgb) - self.ctx.rectangle(self.xoffset + self.margin - 2, - self.yoffset + self.margin - 2, + self.ctx.rectangle(0, + 0, self.screensize[0], self.screensize[1]) self.ctx.fill() @@ -705,6 +696,8 @@ class ConstellationsFlashCards(activity.Activity): self.quiz_toolbar.insert(label_container, -1) self.quiz_toolbar.insert(buttonq1, -1) self.quiz_toolbar.insert(buttonq2, -1) + buttonq1.show() + buttonq2.show() label_container = Gtk.ToolItem() self.answer_status = Gtk.Label(_("")) @@ -712,11 +705,8 @@ class ConstellationsFlashCards(activity.Activity): label_container.show_all() self.quiz_toolbar.insert(label_container, -1) self.answer_status.show() - buttonq1.show() - buttonq2.show() self.quiz_toolbar.show_all() - quiz_toolbar_button = ToolbarButton( page=self.quiz_toolbar, icon_name='ConstellationNewGame') @@ -726,7 +716,7 @@ class ConstellationsFlashCards(activity.Activity): # Reset Results reset_button = ToolButton('system-restart') reset_button.set_tooltip(_('Reset Results')) - reset_button.connect('clicked', self.chart.callback, 'reset_results', self) + reset_button.connect('clicked', self.chart.callback, 'reset_results') toolbar_box.toolbar.insert(reset_button, -1) reset_button.show() @@ -768,7 +758,8 @@ class ConstellationsFlashCards(activity.Activity): 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")) + self.identifyobject.override_background_color(Gtk.StateType.NORMAL, + Gdk.RGBA(*Color(colors[2]).get_rgba())) # Stack the GUI objects. @@ -803,9 +794,9 @@ class ConstellationsFlashCards(activity.Activity): # Establish initial state of controls and do a plot. + self.chart.area_expose_cb(None, None) # make sure we have the surface ready self.chart.plotchart(True) - def read_file(self, filename=""): global score global quiz_count -- cgit v0.9.1