Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mayer <christian.mayer@student.tugraz.at>2010-05-17 13:31:02 (GMT)
committer Christian Mayer <christian.mayer@student.tugraz.at>2010-05-17 13:31:02 (GMT)
commit3eb55e01ced648331f0480c8d2e2f630c7faa591 (patch)
tree42cd8253b95c1e764eb74713a60a5decda047742
parent738fbfcc6ce11553c01fb53c2fa62d2d3a0f8d26 (diff)
switch Learner/Author
-rw-r--r--ReckonPrimer.activity/ReckonPrimerActivity.py64
-rw-r--r--ReckonPrimer.activity/display.py73
-rw-r--r--ReckonPrimer.activity/session.py61
-rw-r--r--ReckonPrimer.activity/toolbar.py59
4 files changed, 93 insertions, 164 deletions
diff --git a/ReckonPrimer.activity/ReckonPrimerActivity.py b/ReckonPrimer.activity/ReckonPrimerActivity.py
index 20f2e1d..89fc045 100644
--- a/ReckonPrimer.activity/ReckonPrimerActivity.py
+++ b/ReckonPrimer.activity/ReckonPrimerActivity.py
@@ -4,13 +4,12 @@ from time import strftime
import pygtk
import gtk
+
from sugar.activity import activity
-#from sugar.activity.widgets import * # needs a more recent Sugar (see below)
from sugar.datastore import datastore
-#from sugar.graphics.toolbarbox import ToolbarBox # needs recent Sugar
from sugar import profile
from session import Session
-#from toolbar import Toolbar
+from toolbar import Toolbar
class ReckonPrimerActivity(activity.Activity):
@@ -18,29 +17,10 @@ class ReckonPrimerActivity(activity.Activity):
activity.Activity.__init__(self, handle)
-# toolbox = activity.ActivityToolbox(self)
-# self.set_toolbox(toolbox)
-# toolbox.show()
-# toolbar = Toolbar(self)
-# toolbar.show()
- # the source below needs a more recent version of Sugar
- # advantage would be: free to more freely name "activity" etc
- #toolbar_box = ToolbarBox()
- #self.set_toolbar_box(toolbar_box)
- #toolbar_box.toolbar.insert(ActivityButton(self), -1)
- #toolbar_box.toolbar.insert(TitleEntry(self), -1)
-
- #share_button = ShareButton(self)
- #toolbar_box.toolbar.insert(share_button, -1)
- #toolbar_box.toolbar.insert(KeepButton(self), -1)
-
- #separator = gtk.SeparatorToolItem()
- #separator.props.draw = False
- #separator.set_expand(True)
- #toolbar_box.toolbar.insert(separator, -1)
- #toolbar_box.toolbar.insert(StopButton(self), -1)
- #toolbar_box.show_all()
-
+ toolbar = Toolbar(self)
+ toolbar.show()
+
+
file_location = activity.get_activity_root() + \
"/data/reckonprimer_report.txt"
file_handle = open(file_location, 'w')
@@ -71,36 +51,6 @@ class ReckonPrimerActivity(activity.Activity):
def run_session(self):
session = Session("xo-user-name", self)
+ session.setMode("Learner")
session.run()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/ReckonPrimer.activity/display.py b/ReckonPrimer.activity/display.py
index 6ec3737..a1939a7 100644
--- a/ReckonPrimer.activity/display.py
+++ b/ReckonPrimer.activity/display.py
@@ -34,7 +34,6 @@ class Display:
self._from = None # dragposition on treeview
self._to = None # dropposition on treeview
self._to_spec = None # specific for dropposition
- self._permanent_gui_elements(window)
self.total_calcs = 0 #number of calculations in one exercise
self.errors = 0
# TODO: imprive information hiding
@@ -43,7 +42,7 @@ class Display:
self._coll_key = None # semaphore for self.finish_collect_callback
# and Collection.select_exerc_callback
self._testvar = 'FOUND'
-
+ self._window = window
def register(self, sess, co, learner, exstore):
"""register _after_ Session and Coach have been instantiated"""
@@ -51,8 +50,9 @@ class Display:
self._co = co
self._learner = learner
self.current_exercisestore = exstore
+ self._permanent_gui_elements()
- def _permanent_gui_elements(self, window):
+ def _permanent_gui_elements(self):
# The display is partitioned as follows
#
# table:
@@ -69,7 +69,7 @@ class Display:
# | info_table, etc | _table |
#5+-------------------------+------------------------+
- self.main_window = window # Save the sugar main window
+ self.main_window = self._window # Save the sugar main window
# whole window with 5 lines and 2 columns
self.table = gtk.Table(5, 2, True)
@@ -127,38 +127,41 @@ class Display:
self.feedback_table.set_col_spacings(2)
# info_table is showen in the left_bottom area
self.info_table = gtk.Table(7, 20, True)
- #title
- self.label0 = gtk.Label("Title: ")
- self.label0.modify_font(pango.FontDescription("sans bold 12"))
- self.label0.set_alignment(0, 0.5)
- self.info_table.attach(self.label0, 1, 10, 0, 1)
- self.label0.show()
+
self._title_buffer = gtk.TextBuffer()
- self._title = gtk.TextView(self._title_buffer)
- self._title.modify_font(pango.FontDescription('sans 12'))
- self._title.set_editable(False)
- self._title.set_cursor_visible(False)
- self.info_table.attach(self._title, 1, 19, 1, 2)
- self._title.show()
- #description
- self.label1 = gtk.Label("Description: ")
- self.label1.modify_font(pango.FontDescription("sans bold 12"))
- self.label1.set_alignment(0, 0.5)
- self.info_table.attach(self.label1, 1, 10, 2, 3)
- self.label1.show()
- self._desc_buffer = gtk.TextBuffer()
- self._desc = gtk.TextView(self._desc_buffer)
- self._desc.modify_font(pango.FontDescription('sans 12'))
- self._desc.set_editable(False)
- self._desc.set_cursor_visible(False)
- self.desc_scrolled_window = gtk.ScrolledWindow()
- self.desc_scrolled_window.set_policy(gtk.POLICY_NEVER,
- gtk.POLICY_ALWAYS)
- self.info_table.attach(self.desc_scrolled_window, 1, 19, 3, 6)
- self.desc_scrolled_window.add(self._desc)
- self._desc.set_wrap_mode(gtk.WRAP_WORD)
- self._desc.show()
- self.desc_scrolled_window.show()
+ self._desc_buffer = gtk.TextBuffer()
+ if self._sess.getMode() == "Author":
+ #title
+ self.label0 = gtk.Label("Title: ")
+ self.label0.modify_font(pango.FontDescription("sans bold 12"))
+ self.label0.set_alignment(0, 0.5)
+ self.info_table.attach(self.label0, 1, 10, 0, 1)
+ self.label0.show()
+ self._title = gtk.TextView(self._title_buffer)
+ self._title.modify_font(pango.FontDescription('sans 12'))
+ self._title.set_editable(False)
+ self._title.set_cursor_visible(False)
+ self.info_table.attach(self._title, 1, 19, 1, 2)
+ self._title.show()
+
+ #description
+ self.label1 = gtk.Label("Description: ")
+ self.label1.modify_font(pango.FontDescription("sans bold 12"))
+ self.label1.set_alignment(0, 0.5)
+ self.info_table.attach(self.label1, 1, 10, 2, 3)
+ self.label1.show()
+ self._desc = gtk.TextView(self._desc_buffer)
+ self._desc.modify_font(pango.FontDescription('sans 12'))
+ self._desc.set_editable(False)
+ self._desc.set_cursor_visible(False)
+ self.desc_scrolled_window = gtk.ScrolledWindow()
+ self.desc_scrolled_window.set_policy(gtk.POLICY_NEVER,
+ gtk.POLICY_ALWAYS)
+ self.info_table.attach(self.desc_scrolled_window, 1, 19, 3, 6)
+ self.desc_scrolled_window.add(self._desc)
+ self._desc.set_wrap_mode(gtk.WRAP_WORD)
+ self._desc.show()
+ self.desc_scrolled_window.show()
#calculations
self.ex_name_label = gtk.Label("Calculations: ")
self.ex_name_label.modify_font(pango.FontDescription("sans bold 12"))
diff --git a/ReckonPrimer.activity/session.py b/ReckonPrimer.activity/session.py
index 1b05408..9a218ff 100644
--- a/ReckonPrimer.activity/session.py
+++ b/ReckonPrimer.activity/session.py
@@ -20,56 +20,31 @@ class Session:
self._learner = Learner(self._dis, self._co)
self._author = Author()
self._exstore = ExStore(self._dis, self._co)
- self._co.register(self, self._dis, self._exstore, self._learner)
- #print("in session, before _dis.register")
- self._dis.register(self, self._co, self._learner, self._exstore)
#self._co.create_exercises() #TODO.WN091101 replace by storing Exerc.s
self._calcs = None #pop !
+
+ def setMode(self, mode):
+ self.mode = mode
+
+ def getMode(self):
+ return self.mode
+
+
def run(self):
"""
Start execution of RP.
Execution of RP is terminated by the user going bach to the OS.
"""
+ self._co.register(self, self._dis, self._exstore, self._learner)
+ #print("in session, before _dis.register")
+ self._dis.register(self, self._co, self._learner, self._exstore)
+
#print("in Session.run")
- if False: # TODO choice according to menu CM
- pass # self._author.run()
- else:
- self._learner.run()
- #self._co.request_exercise()
- #self._dis.init_calc() #TODOWN091101 take Exercise as argument
+ # if self.mode == "Author"
+ # pass # self._author.run()
+ # else:
+ self._learner.run()
+ #self._co.request_exercise()
+ #self._dis.init_calc() #TODOWN091101 take Exercise as argument
-# def notify(self, (msg, data)):
-# '''called by the observed objects'''
-# #print('in Session.notify: msg=,data=', msg, data)
-# if msg == 'setting-done': # from Coach
-# self._ex = data
-# self._calcs = data._generate_calcs()
-# self._key = data.get_topic()
-# (self._calcs).reverse()
-# _calc = (self._calcs).pop()
-# #print('in Session.notify: calc=', _calc)
-# _lines, self._input = data.format(_calc)
-# self._dis.display_calc(_lines)
-# self._curr_in = self._input.pop() #need _curr_in in notify
-# self._dis.create_entryline(self._curr_in)
-# # create_entryline sets the callback from gtk to Display
-# if msg == 'digit-done': # from Display
-# #print('in Session.notify, digit-done: _input=', self._input)
-# (lino, pos, dig, proterr, protok, li) = self._curr_in
-# self._dis.create_entryline((lino, -1, dig, proterr, protok, li))
-# if len(self._input) > 0:
-# self._curr_in = self._input.pop()
-# self._dis.create_entryline(self._curr_in)
-# else: # start new calc
-# self._dis.show_progress()
-# if len(self._calcs) > 0:
-# _calc = (self._calcs).pop()
-# print('in Session.notify: calc=', _calc)
-# _lines, self._input = self._ex.format(_calc)
-# self._dis.display_calc(_lines)
-# self._curr_in = self._input.pop() #need _curr_in in notify
-# self._dis.create_entryline(self._curr_in)
-# # create_entryline sets the callback from gtk to Display
-# else:
-# self._dis.finish_calc()
diff --git a/ReckonPrimer.activity/toolbar.py b/ReckonPrimer.activity/toolbar.py
index d4eff8e..64219f5 100644
--- a/ReckonPrimer.activity/toolbar.py
+++ b/ReckonPrimer.activity/toolbar.py
@@ -1,44 +1,45 @@
import gtk
-try:
- from sugar.activity.widgets import ActivityToolbarButton
- from sugar.activity.widgets import StopButton
- from sugar.graphics.toolbarbox import ToolbarButton, ToolbarBox
-except ImportError:
- pass
+from sugar.activity import activity
from sugar.graphics.toolbutton import ToolButton
+from session import Session
+
+
class Toolbar:
def __init__(self, parent):
self._parent = parent
def show(self):
- toolbar_box = ToolbarBox()
- activity_button = ActivityToolbarButton(self._parent)
- toolbar_box.toolbar.insert(activity_button, 0)
+ mytoolbox = gtk.Toolbar()
+
+ learner_button = ToolButton('help')
+ learner_button.set_tooltip("Learner")
+ learner_button.connect('clicked', self.toggle_mode, "Learner")
- separator = gtk.SeparatorToolItem()
- separator.show()
- toolbar_box.toolbar.insert(separator, -1)
-
- learner_button = ToolButton()
- learner_button.set_tooltip('Learner')
- toolbar_box.toolbar.insert(learner_button, -1)
+ author_button = ToolButton('help')
+ author_button.set_tooltip("Author")
+ author_button.connect('clicked', self.toggle_mode, "Author")
- authour_button = ToolButton()
- authour_button.set_tooltip('Author')
- toolbar_box.toolbar.insert(authour_button, -1)
- separator = gtk.SeparatorToolItem()
- separator.props.draw = False
- separator.set_expand(True)
- separator.show()
- toolbar_box.toolbar.insert(separator, -1)
-
- stop = StopButton(self._parent)
- toolbar_box.toolbar.insert(stop, -1)
- toolbar_box.show_all()
- self._parent.set_toolbar_box(toolbar_box)
+ mytoolbox.insert(author_button, -1)
+ author_button.show()
+
+ mytoolbox.insert(learner_button, -1)
+ learner_button.show()
+ mytoolbox.show()
+
+ toolbox = activity.ActivityToolbox(self._parent)
+ toolbox.add_toolbar("User",mytoolbox)
+ self._parent.set_toolbox(toolbox)
+ toolbox.show()
+
+ def toggle_mode(self, args, mode):
+ # self._parent._session.close()
+ session = Session("xo-user-name", self._parent)
+ session.setMode(mode)
+ session.run()
+ \ No newline at end of file