class SPGreeter: """Starts a login screen, this will be a window, not fullscreen. """ def __init__(self, cmd_options, theme='default', vtkb=None, fullscr=None): global ACTIVITYDATADIR self.logger = logging.getLogger("childsplay.SPgdm.SPGreeter") self.logger.debug("Starting") self.cmd_options = cmd_options self.__name = '' captxt = _("Childsplay_sp login") if self.cmd_options.theme != 'default': captxt = captxt.replace('Childsplay_sp', self.cmd_options.theme) ICONPATH = os.path.join(ACTIVITYDATADIR, 'SPData', 'themes', self.cmd_options.theme) DEFAULTICONPATH = os.path.join(ACTIVITYDATADIR, 'SPData', 'themes', 'default') self.vtkb = vtkb # is used in the _run_loop # setup screen size = (800, 600) if fullscr: self.screen = pygame.display.set_mode(size, FULLSCREEN) else: self.screen = pygame.display.set_mode(size) p = os.path.join(ICONPATH, 'spgdm_back.png') if not os.path.exists(p): p = os.path.join(DEFAULTICONPATH, 'spgdm_back.png') back = load_image(p) self.screen.blit(back, (0, 0)) # get the version image vs = "Childsplay_sp version: %s" % Version.version if self.cmd_options.theme != 'default': vs = vs.replace('Childsplay_sp', self.cmd_options.theme) if self.cmd_options.adminmode: vs = vs + " (Adminmode)" vsurf = char2surf(vs, TTFSIZE - 4, (0, 0, 0), ttf=TTF, bold=True, antialias=False) self.screen.blit(vsurf, (300, 0)) self.actives = SPInit(self.screen, self.screen.convert()) pygame.display.set_caption(captxt.encode('utf-8')) # setup our SP widgets label = SPLabel(_("Username:"******"Login") but.set_text(t) # we set the fontsize below but.child.create_style() but.child.style["font"]["size"] = TTFSIZE but.child.style['bgcolor'][ocwc.STATE_NORMAL] = KOBALT_LIGHT_BLUE but.create_style()['bgcolor'][ocwc.STATE_NORMAL] = KOBALT_LIGHT_BLUE but.connect_signal(ocwc.SIG_CLICKED, self._login_button_callback, self.entry) #but.opacity = 255 but.topleft = (340, 320) # We clear the event queue as we sometimes get an crash with the message # error: Event queue full # Nothing to be found on Google so I've put a clear before the error # was generated. pygame.event.clear() self.renderer.add_widget(but) # logout button p = os.path.join(ICONPATH, 'spgdm_quit_button.png') if not os.path.exists(p): p = os.path.join(DEFAULTICONPATH, 'spgdm_quit_button.png') but = ocw.ImageButton(p) but.create_style()['bgcolor'][ocwc.STATE_NORMAL] = KOBALT_LIGHT_BLUE but.connect_signal(ocwc.SIG_CLICKED, self._quit_button_callback, but) #but.opacity = 180 but.topleft = (720, 520) self.renderer.add_widget(but) # info button p = os.path.join(ICONPATH, 'spgdm_info_button.png') if not os.path.exists(p): p = os.path.join(DEFAULTICONPATH, 'spgdm_info_button.png') but = ocw.ImageButton(p) #but.set_text(_("Quit")) #but.child.create_style()["font"]["size"] = 36 but.create_style()['bgcolor'][ocwc.STATE_NORMAL] = KOBALT_LIGHT_BLUE but.connect_signal(ocwc.SIG_CLICKED, self._info_button_callback, but) #but.opacity = 180 but.topleft = (20, 520) self.renderer.add_widget(but) self.clock = pygame.time.Clock() self.runloop = True pygame.display.update() # run the virtual keyboard if we have one. if self.vtkb: self._run_vtkb_loop(self.renderer) else: # else we run a 'normal' loop. self._run_loop() def _run_loop(self): #self.runloop=0 # Used when profiling this module while self.runloop: self.clock.tick(30) pygame.event.pump() events = pygame.event.get() for event in events: if event.type is KEYDOWN and event.key is K_ESCAPE or event.type is QUIT: self.run_event_loop = False self._quit_button_callback(None) elif event.type is KEYDOWN: if self.actives.refresh(event): self._login_button_callback(self.entry) self.renderer.distribute_events(*events) def _run_vtkb_loop(self, parent_re=None): self.vtkb.show() kb = self.vtkb.echo_run(parent_re=[parent_re, self.renderer]) word = [] while self.runloop: try: k = kb.next() # this will return a string or none if k and k not in ( 'quit', 'enter' ): # user hits anything but None, enter or escape word.append(k) self.entry.set_text(''.join(word)) elif k == 'quit': # user hits escape self._quit_button_callback() break elif k == 'enter': break except (StopIteration, VTKEscapeKeyException): self._quit_button_callback() break def _login_button_callback(self, entry): self.logger.debug("_login_button_callback called with %s" % entry) self.__name = entry.text self.runloop = False def _quit_button_callback(self, *args): self.logger.debug("_quit_button_callback called") if not self.cmd_options.noexitquestion: dlg = ExitDialog(self.renderer) c = dlg.run() else: c = 0 if c == 0: self.logger.info("User wants exit") raise GDMEscapeKeyException # let schoolsplay.py decide what next def _info_button_callback(self, but): self.logger.debug("_info_button_callback called") d = InfoDialog(self.renderer, SPHelpText.SPgdm._info_button_callback) d.run() def get_loginname(self): return self.__name
def cbf(sprite, event, data): print 'cb called with sprite %s, event %s and data %s' % (sprite, event, data) print 'sprite name: %s' % sprite.get_name() print 'data is %s' % data scr = pygame.display.set_mode((800, 600)) scr.fill(LIGHTSKYBLUE1) pygame.display.flip() back = scr.convert() actives = SPInit(scr, back) Init('braintrainer') db = Debugscreen('none_act', 'BT2.1', scr) actives.add(db.get_actives()) runloop = 1 while runloop: pygame.time.wait(100) pygame.event.pump() events = pygame.event.get() for event in events: if event.type is KEYDOWN: if event.key == K_ESCAPE: runloop = 0 elif event.key == K_F1: print "F1" result = actives.update(event) if result and result[0][1] == -2: runloop = False
class SPGreeter: """Starts a login screen, this will be a window, not fullscreen. """ def __init__(self, cmd_options, theme='default', vtkb=None, fullscr=None): global ACTIVITYDATADIR self.logger = logging.getLogger("childsplay.SPgdm.SPGreeter") self.logger.debug("Starting") self.cmd_options = cmd_options self.__name = '' captxt = _("Childsplay_sp login") if self.cmd_options.theme != 'default': captxt = captxt.replace('Childsplay_sp', self.cmd_options.theme) ICONPATH = os.path.join(ACTIVITYDATADIR, 'SPData', 'themes', self.cmd_options.theme) DEFAULTICONPATH = os.path.join(ACTIVITYDATADIR, 'SPData', 'themes', 'default') self.vtkb = vtkb# is used in the _run_loop # setup screen size = (800, 600) if fullscr: self.screen = pygame.display.set_mode(size, FULLSCREEN) else: self.screen = pygame.display.set_mode(size) p = os.path.join(ICONPATH, 'spgdm_back.png') if not os.path.exists(p): p = os.path.join(DEFAULTICONPATH, 'spgdm_back.png') back = load_image(p) self.screen.blit(back, (0, 0)) # get the version image vs = "Childsplay_sp version: %s" % Version.version if self.cmd_options.theme != 'default': vs = vs.replace('Childsplay_sp', self.cmd_options.theme) if self.cmd_options.adminmode: vs = vs + " (Adminmode)" vsurf = char2surf(vs, TTFSIZE-4, (0, 0, 0), ttf=TTF, bold=True, antialias=False) self.screen.blit(vsurf, (300, 0)) self.actives = SPInit(self.screen, self.screen.convert()) pygame.display.set_caption(captxt.encode('utf-8')) # setup our SP widgets label = SPLabel(_("Username:"******"Login") but.set_text(t)# we set the fontsize below but.child.create_style() but.child.style["font"]["size"] = TTFSIZE but.child.style['bgcolor'][ocwc.STATE_NORMAL] = KOBALT_LIGHT_BLUE but.create_style()['bgcolor'][ocwc.STATE_NORMAL] = KOBALT_LIGHT_BLUE but.connect_signal(ocwc.SIG_CLICKED, self._login_button_callback, self.entry) #but.opacity = 255 but.topleft = (340, 320) # We clear the event queue as we sometimes get an crash with the message # error: Event queue full # Nothing to be found on Google so I've put a clear before the error # was generated. pygame.event.clear() self.renderer.add_widget(but) # logout button p = os.path.join(ICONPATH, 'spgdm_quit_button.png') if not os.path.exists(p): p = os.path.join(DEFAULTICONPATH, 'spgdm_quit_button.png') but = ocw.ImageButton(p) but.create_style()['bgcolor'][ocwc.STATE_NORMAL] = KOBALT_LIGHT_BLUE but.connect_signal(ocwc.SIG_CLICKED, self._quit_button_callback, but) #but.opacity = 180 but.topleft = (720, 520) self.renderer.add_widget(but) # info button p = os.path.join(ICONPATH, 'spgdm_info_button.png') if not os.path.exists(p): p = os.path.join(DEFAULTICONPATH, 'spgdm_info_button.png') but = ocw.ImageButton(p) #but.set_text(_("Quit")) #but.child.create_style()["font"]["size"] = 36 but.create_style()['bgcolor'][ocwc.STATE_NORMAL] = KOBALT_LIGHT_BLUE but.connect_signal(ocwc.SIG_CLICKED, self._info_button_callback, but) #but.opacity = 180 but.topleft = (20, 520) self.renderer.add_widget(but) self.clock = pygame.time.Clock() self.runloop = True pygame.display.update() # run the virtual keyboard if we have one. if self.vtkb: self._run_vtkb_loop(self.renderer) else: # else we run a 'normal' loop. self._run_loop() def _run_loop(self): #self.runloop=0 # Used when profiling this module while self.runloop: self.clock.tick(30) pygame.event.pump() events = pygame.event.get() for event in events: if event.type is KEYDOWN and event.key is K_ESCAPE or event.type is QUIT: self.run_event_loop = False self._quit_button_callback(None) elif event.type is KEYDOWN: if self.actives.refresh(event): self._login_button_callback(self.entry) self.renderer.distribute_events( * events) def _run_vtkb_loop(self, parent_re=None): self.vtkb.show() kb = self.vtkb.echo_run(parent_re=[parent_re, self.renderer]) word = [] while self.runloop: try: k = kb.next()# this will return a string or none if k and k not in ('quit', 'enter'):# user hits anything but None, enter or escape word.append(k) self.entry.set_text(''.join(word)) elif k == 'quit':# user hits escape self._quit_button_callback() break elif k == 'enter': break except (StopIteration, VTKEscapeKeyException): self._quit_button_callback() break def _login_button_callback(self, entry): self.logger.debug("_login_button_callback called with %s" % entry) self.__name = entry.text self.runloop = False def _quit_button_callback(self, * args): self.logger.debug("_quit_button_callback called") if not self.cmd_options.noexitquestion: dlg = ExitDialog(self.renderer) c = dlg.run() else: c = 0 if c == 0: self.logger.info("User wants exit") raise GDMEscapeKeyException # let schoolsplay.py decide what next def _info_button_callback(self, but): self.logger.debug("_info_button_callback called") d = InfoDialog(self.renderer, SPHelpText.SPgdm._info_button_callback) d.run() def get_loginname(self): return self.__name
from SPWidgets import Init def cbf(sprite, event, data): print 'cb called with sprite %s, event %s and data %s' % (sprite, event, data) print 'sprite name: %s' % sprite.get_name() print 'data is %s' % data scr = pygame.display.set_mode((800, 600)) scr.fill(LIGHTSKYBLUE1) pygame.display.flip() back = scr.convert() actives = SPInit(scr, back) Init('braintrainer') db = Debugscreen('none_act', 'BT2.1', scr) actives.add(db.get_actives()) runloop = 1 while runloop: pygame.time.wait(100) pygame.event.pump() events = pygame.event.get() for event in events: if event.type is KEYDOWN: if event.key == K_ESCAPE: runloop = 0 elif event.key == K_F1: print "F1" result = actives.update(event) if result and result[0][1] == -2: runloop = False