diff options
author | Alex <acj3840@rit.edu> | 2010-07-26 18:44:57 (GMT) |
---|---|---|
committer | Alex <acj3840@rit.edu> | 2010-07-26 18:44:57 (GMT) |
commit | f48f260556b794fd4ee969d397606eb3818facff (patch) | |
tree | 67af7b8df838b4c90a453f9e5a50e2dc5485e9e9 | |
parent | 0302212ba4e20d0d8ff21117e4215556941f3e59 (diff) |
added some networking code
changed the code so teacher and students are methods instead of classes
now call _update_canvas(new view here) for updating
see NEWS for more
-rw-r--r-- | NEWS | 5 | ||||
-rw-r--r-- | popquiz.py | 123 |
2 files changed, 67 insertions, 61 deletions
@@ -1,3 +1,8 @@ +7-26-2010 +added some code that i think is needed for networking. using hellomesh as well as ActivitiesGuideSugar to help guide this +reworked the code so teacher and student are no longer classes, they are methods that call appropriate _teacher methods or _student methods +now to update canvas just call _update_canvas(new view here) + 7-23-2010 fixed the screen changing, now whenever something needs to update the screen, just call the update method in PopQuiz class screens now transition for the teacher @@ -8,7 +8,12 @@ from sugar.activity import activity from sugar.activity.activity import Activity, ActivityToolbox from sugar.graphics.toolbarbox import ToolbarBox +from sugar.graphics.alert import NotifyAlert +from sugar.presence import presenceservice +from sugar.presence.tubeconn import TubeConnection from sugar.activity.widgets import * +from dbus.gobject_service import ExportedGObject +from dbus.service import method, signal import gtk import threading @@ -16,6 +21,11 @@ import logging import time import gobject import math +import telepathy + +SERVICE = "org.laptop.PopQuiz" +IFACE = SERVICE +PATH = "/org/laptop/PopQuiz" logging.debug('imported logging') @@ -32,14 +42,11 @@ WRONG3ANSWER = "wrong3answer" TIMER = 10 STUDENTS = [ [ "Student1" ], [ "Student2" ], [ "Student3" ], [ "Student4" ], [ "Student5" ] ] SELECTEDSTUDENT = "Student0" -POPQUIZ = "" class PopQuiz(activity.Activity): - @staticmethod - def update_canvas(): - global POPQUIZ - POPQUIZ.set_canvas(POPQUIZ.view.vboxholdsall) + def _update_canvas(self, newview): + self.set_canvas(newview) def __init__(self, handle): global POPQUIZ @@ -50,6 +57,14 @@ class PopQuiz(activity.Activity): logging.debug(self.shared_activity) logging.debug(self._share_id) logging.debug(self._join_id) + + #sugar toolbox + toolbox = ActivityToolbox(self) + activity_toolbar = toolbox.get_activity_toolbar() + activity_toolbar.keep.props.visible = False + self.set_toolbox(toolbox) + toolbox.show() + #if self._shared_activity: if False: logging.debug('joining an activity') @@ -60,45 +75,41 @@ class PopQuiz(activity.Activity): self._joined_cb() else: #creating own session - self.view = Teacher() + self.set_canvas(self._make_teacher()) logging.debug('teacher created') - self.set_canvas(self.view.vboxholdsall) - logging.debug('put teacher on screen') self.connect('shared', self._shared_cb) - #sugar toolbox - 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) - - 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() - POPQUIZ = self + #get presence service + self.pservice = presenceservice.get_instance() + owner = self.pservice.get_owner() + self.owner = owner + + def _shared_cb(self, activity): logging.debug('Popquiz was shared') + self.initiating = True self._setup() + id = self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].OfferDBusTube(SERVICE, {}) def _setup(self): logging.debug('setting up sharing') - #### set up actual connection here##### + if self.shared_activity is None: + logging.debug('error sharing or joining') + return + + self.conn = self.shared_activity.telepathy_conn + self.tubes_chan = self.shared_activity.telepathy_tubes_chan + self.text_chan = self.shared_activity.telepathy_text_chan + self.shared_activity.connect('buddy-joined', self._buddy_joined_cb) self.shared_activity.connect('buddy-left', self._buddy_left_cb) def _joined_cb(self, activity): logging.debug('joined a shared activity') #joining an activity means you're a student - self.view = Student() - self.set_canvas(self.view.viewboxholdsall) + self.set_canvase(self._make_student()) def _buddy_joined_cb(self, activity, buddy): logging.debug('buddy joined activity') @@ -108,11 +119,7 @@ class PopQuiz(activity.Activity): logging.debug('buddy left activity') ###remove buddy from storage### -class Student(): - - personaltimer = 9999999 - - def countdown(self): + def _student_countdown(self): logging.debug('countdown method') logging.debug(str(self.personaltimer)) logging.debug(time.time()) @@ -125,11 +132,10 @@ class Student(): else: logging.debug('time has run out') - def timesup(self): + def _student_timesup(self): logging.debug('time is up') - def __init__(self): - #activity.Activity.__init__(self, handle) + def _make_student(self): global QUESTION global CORRECTANSWER global WRONG1ANSWER @@ -256,14 +262,10 @@ class Student(): logging.debug('creating timer') self.starttime = time.time() logging.debug('timer started') - gobject.timeout_add(1000, self.countdown) - self.vboxholdsall = vboxholdsall - -class Teacher(): + gobject.timeout_add(1000, self._student_countdown) + return vboxholdsall - personaltimer = 999999999 - - def students_answered(self): + def _teacher_students_answered(self): global STUDENTS vboxholdsall = gtk.VBox() @@ -281,7 +283,7 @@ class Teacher(): #set up clist clist = gtk.CList(1, title) - clist.connect("select_row", self.student_selected) + clist.connect("select_row", self._teacher_student_selected) clist.show() #add students to clist @@ -299,32 +301,31 @@ class Teacher(): detailsbutton.show() nextquestionbutton = gtk.Button("Next Question") nextquestionbutton.show() - detailsbutton.connect("clicked", self.display_student) - nextquestionbutton.connect("clicked", self.next_question) + detailsbutton.connect("clicked", self._teacher_display_student) + nextquestionbutton.connect("clicked", self._teacher_next_question) hboxbuttons.pack_start(detailsbutton, True, True, 10) hboxbuttons.pack_start(nextquestionbutton, True, True, 10) vboxholdsall.pack_start(hboxbuttons, False, True, 10) self.vboxholdsall = vboxholdsall - PopQuiz.update_canvas() + self._update_canvas(self.vboxholdsall) - def student_selected(self, clist, row, column, event, data=None): + def _teacher_student_selected(self, clist, row, column, event, data=None): global STUDENTS global SELECTEDSTUDENT SELECTEDSTUDENT = clist.get_text(row, column) - def display_student(self, data): + def _teacher_display_student(self, data): global SELECTEDSTUDENT logging.debug(SELECTEDSTUDENT) #display info based on the SELECTEDSTUDENT - def next_question(self, data): - self.question_screen() - PopQuiz.update_canvas() + def _teacher_next_question(self, data): + self._update_canvas(self._teacher_question_screen()) - def countdown(self): + def _teacher_countdown(self): logging.debug('countdown method') logging.debug(str(self.personaltimer)) logging.debug(time.time()) @@ -333,12 +334,12 @@ class Teacher(): elapsed_time = time.time() - self.starttime self.personaltimer = int(math.ceil(TIMER - elapsed_time)) self.timerentry.set_text(str(self.personaltimer)) - gobject.timeout_add(1000, self.countdown) + gobject.timeout_add(1000, self._teacher_countdown) else: logging.debug('time has run out') - self.students_answered() + self._teacher_students_answered() - def send_question(self, widget, data = None): + def _teacher_send_question(self, widget, data = None): logging.debug('sendquestion method') global QUESTION global CORRECTANSWER @@ -375,18 +376,18 @@ class Teacher(): #store the starting time self.starttime = time.time() #call countdown every 1000ms (1 second) - gobject.timeout_add(1000, self.countdown) + gobject.timeout_add(1000, self._teacher_countdown) logging.debug('Timer started') - def __init__(self): + def _make_teacher(self): logging.debug('teacher init method') #activity.Activity.__init__(self, handle) - self.question_screen() + return self._teacher_question_screen() - def question_screen(self): + def _teacher_question_screen(self): #box for formatting vboxholdsall = gtk.VBox() @@ -482,7 +483,7 @@ class Teacher(): self.sendbutton.show() #connect button - self.sendbutton.connect("clicked", self.send_question) + self.sendbutton.connect("clicked", self._teacher_send_question) logging.debug('connected button in teacher') #pack hboxbottom @@ -496,4 +497,4 @@ class Teacher(): #set vboxholdsall to canvas #self.set_canvas(vboxholdsall) - self.vboxholdsall = vboxholdsall + return vboxholdsall |