def onModuleLoad(self): print "inside onModuleLoad" self.remote_py = JSONService() self.mainPanel.add(sampleBallot.title) self.mainPanel.add(sampleBallot.instructions) self.mainPanel.add(sampleBallot.contest) self.mainPanel.add(sampleBallot.candidate) self.mainPanel.add(sampleBallot.selection) self.mainPanel.add(sampleBallot.status) panel = FocusPanel(Widget=self.mainPanel) gp = RootPanelListener(panel) manageRootPanel(gp) RootPanel().add(panel) panel.setFocus(True) self.remote_py.passBallot(self)
def onModuleLoad(self): self.remote_py = JSONService() h = HTML("<b />Contest: ") self.contest.add(h) l = HTML("<b />Selection: ") self.selection.add(l) # self.mainPanel.add(self.button) self.mainPanel.add(self.contest) self.mainPanel.add(self.selection) self.mainPanel.add(self.status) panel = FocusPanel(Widget=self.mainPanel) gp = RootPanelListener(panel) manageRootPanel(gp) RootPanel().add(panel) panel.setFocus(True) # self.remote_py.uppercase('yay', self) self.remote_py.passBallot(self)
class PjBallot: def __init__(self): self.mainPanel = VerticalPanel() self.button = Button('test', self.test) self.status = Label('hi') self.x = 1 self.srace = Race('', '', [], '') def test(self): self.button.setText("No, really click me!") self.contest.add(HTML('yay')) def onKeyDown(self, sender, keycode, modifiers): #print "inside onKeyDown, self is", self, "sender is", sender, "keycode is", keycode #self.mainPanel.add(keycode) pass def onKeyUp(self, sender, keycode, modifiers): pass def onModuleLoad(self): print "inside onModuleLoad" self.remote_py = JSONService() self.mainPanel.add(sampleBallot.title) self.mainPanel.add(sampleBallot.instructions) self.mainPanel.add(sampleBallot.contest) self.mainPanel.add(sampleBallot.candidate) self.mainPanel.add(sampleBallot.selection) self.mainPanel.add(sampleBallot.status) panel = FocusPanel(Widget=self.mainPanel) gp = RootPanelListener(panel) manageRootPanel(gp) RootPanel().add(panel) panel.setFocus(True) self.remote_py.passBallot(self) def onRemoteResponse(self, response, request_info): print "inside onRemoteResponse" print response self.srace = response sampleBallot.sendRace(self.srace) #sampleBallot.instructions.clear() #sampleBallot.title.add(HTML('Name: %s' % self.srace.name)) #sampleBallot.instructions.add(HTML('Instruction: %s' % self.srace.instructions)) #inst = sampleBallot.getInstruction() #self.mainPanel.add(HTML() sampleBallot.fsm.startVoting() sampleBallot.currObj = sampleBallot.race.selectionList[0] #sampleBallot.playAudio() sampleBallot.setContest() def onRemoteError(self, code, errobj, request_info): # onRemoteError gets the HTTP error code or 0 and # errobj is an jsonrpc 2.0 error dict: # { # 'code': jsonrpc-error-code (integer) , # 'message': jsonrpc-error-message (string) , # 'data' : extra-error-data # } message = errobj['message'] if code != 0: self.status.setText("HTTP error %d: %s" % (code, message)) print "HTTP error %d: %s" % (code, message) else: code = errobj['code'] self.status.setText("JSONRPC Error %s: %s" % (code, message)) print "JSONRPC Error %s: %s: %s" % (code, message, data)
class pjBallot: def __init__(self): self.mainPanel = VerticalPanel() self.contest = HorizontalPanel() self.contest.setStyleName('words') self.selection = HorizontalPanel() self.selection.setStyleName('words') self.button = Button('test', self.test) self.status = Label('hi') self.x = 1 def test(self): self.button.setText("No, really click me!") # Window.alert("Hello, AJAAAX!") self.contest.add(HTML('yay')) def nextContest(self): self.x += 1 self.contest.clear() self.contest.add(HTML('<b /> Contest: %d' % self.x)) def nextSelection(self): self.x += 1 self.selection.clear() self.selection.add(HTML('<b /> Selection: %d' % self.x)) def onKeyDown(self, sender, keycode, modifiers): pass def onKeyUp(self, sender, keycode, modifiers): pass def onKeyPress(self, sender, keycode, modifiers): DOM.eventPreventDefault(DOM.eventGetCurrentEvent()) #not needed if keycode == KeyboardListener.KEY_UP: self.nextContest() if keycode == KeyboardListener.KEY_DOWN: self.nextContest() if keycode == KeyboardListener.KEY_LEFT: self.nextSelection() if keycode == KeyboardListener.KEY_RIGHT: self.nextSelection() def onModuleLoad(self): self.remote_py = JSONService() h = HTML("<b />Contest: ") self.contest.add(h) l = HTML("<b />Selection: ") self.selection.add(l) # self.mainPanel.add(self.button) self.mainPanel.add(self.contest) self.mainPanel.add(self.selection) self.mainPanel.add(self.status) panel = FocusPanel(Widget=self.mainPanel) gp = RootPanelListener(panel) manageRootPanel(gp) RootPanel().add(panel) panel.setFocus(True) # self.remote_py.uppercase('yay', self) self.remote_py.passBallot(self) # encoded_object = '[{"__jsonclass__": "Candidate.Candidate", "name": "Barack Obama"}]' ## test = json2.loads(encoded_object) ## self.mainPanel.add(HTML("%s" % test))#json.loads(encoded_object)))#, object_hook=self.dict_to_object))) # foo = '["foo", {"bar":["baz", null, 1.0, 2]}]' # bar = loads(foo, object_hook=tester) # self.mainPanel.add(HTML(bar)) def dict_to_object(self,d): Window.alert("Hello, AJAAAX!") self.mainPanel.add(HTML('whatevs: %s' % 12)) if '__class__' in d: # import pdb # pdb.set_trace() class_name = d.pop('__class__') module_name = d.pop('__module__') module = __import__(module_name) print 'MODULE:', module class_ = getattr(module.ballotTree, class_name) #because module was just audioBallot print 'CLASS:', class_ args = dict( (key.encode('ascii'), value) for key, value in d.items()) print 'INSTANCE ARGS:', args inst = class_(**args) else: inst = d return inst def onRemoteResponse(self, response, request_info): race = response name = race.works self.mainPanel.add(HTML('pleasework %s' % name)) # self.mainPanel.add(HTML('pleasework2 %s' % JSONResponseTextHandler(response))) # test = JSONResponseTextHandler(response) # test.request # self.mainPanel.add(HTML('pleasework3 %s' % test.name)) # encoded_object = '[{"__jsonclass__": "Candidate.Candidate", "name": "Barack Obama"}]' # foo = loads(response) # self.mainPanel.add(HTML(foo)) # self.mainPanel.add(HTML("not working %s" % 12 ))#loads(response)))#, object_hook=self.dict_to_object))) # bar = loads('["foo", {"bar":["baz", null, 1.0, 2]}]', object_hook=tester) # self.mainPanel.add(HTML(bar)) # self.status.setText(request_info.method) def onRemoteError(self): pass