def _response(self, user, choice): '''Handle response from a user.''' if callable(self.menuselect): params = { 'userid': user.userid, 'choice': choice, 'popup': self, 'previous': user.get_previous_popup(), } params.update(self.menuselect_args) params.update(self._menuselect_special) try: submenu = self.menuselect(params) except Exception: # print the exception as normal, but pretend nothing happened dbgmsg(1, 'Popuplib2: Called menuselect function raised:') sys.excepthook(*sys.exc_info()) sys.exc_clear() submenu = None if submenu is not None: try: user.queue[0] = submenu._get_userpopup(user) return False except AttributeError: dbgmsg(0, 'Popuplib2: got non-popup return value from callback function') dbgmsg_repr(0, submenu) return True
def display(self): '''Create a GUI panel and display it for the user.''' dbgmsg(1, 'Popuplib2: Template Userpopup building self') text_template = string.Template('\n'.join(self._popup)) text = text_template.substitute(*self._send_args, **self._send_kw) dbgmsg(2, 'Popuplib2: Calling es.menu(%f, %d, textlen=%d, %s)'%( 0, self._user.userid, len(text), self._popup.enable_keys)) es.menu(0, self._user.userid, text, self._popup.enable_keys)
def display(self): '''Create a GUI panel and display it for the user.''' self._being_hidden = False text = self.generate_text() if isinstance(text, unicode): text = text.encode('utf-8') dbgmsg(2, 'Popuplib2: Calling es.menu(%s, %s, textlen=%s, %s)'%( 0, self._user.userid, len(text), self._popup.enable_keys)) es.menu(0, self._user.userid, text, self._popup.enable_keys)
def get_game_data(module): global game_data data = load_game_data(module) # GJ HAX: gamename = str(es.ServerVar('eventscripts_gamedir')).replace('\\', '/').rpartition('/')[2].lower() dbgmsg(1, 'spmenu: game name is %s'%repr(gamename)) if gamename not in data: dbgmsg(1, 'spmenu: game not found, going default') gamename = 'default' this_game = data[gamename] game_data = { 'type': this_game['type'], 'refresh': this_game.as_int('refresh') if this_game['type'] == 'radio' else 0, } dbgmsg_repr(2, game_data) return game_data
def display(self): '''Create a GUI panel and display it for the user.''' pages = self.pages() or 1 language = self.get_language() tb = [] # add title tb.append('%-25s'%(self._popup.title)) # add description if self._popup.description: tb.append('%s\n'%self._popup.description) # add separating slashes if pages == 0: # empty menu tb.append(spmenu_resources.get_string('empty', language)) else: # add options self._add_options(tb) # add separating slashes tb.append(' ') # add page navigation links if pages > 1: s_prev = spmenu_resources.get_string('prev', language) s_next = spmenu_resources.get_string('next', language) if self.pagenum == 1: # tb.append('8. %s'%s_prev) tb.append(' ') else: tb.append('->8. %s\n'%s_prev) if self.pagenum == pages: # tb.append('9. %s\n'%s_next) tb.append(' ') else: tb.append('->9. %s\n'%s_next) else: tb.append(' ') tb.append(' ') # add exit button tb.append('0. %s'%spmenu_resources.get_string('cancel', language)) #display it text = '\n'.join(tb) dbgmsg(2, 'es.menu(%d, %d, textlen=%d, %s'%( 0, self._user.userid, len(text), self._popup.enable_keys)) es.menu(0, self._user.userid, text, self._popup.enable_keys)
def get_game_data(module): global game_data data = load_game_data(module) # GJ HAX: gamename = str(es.ServerVar('eventscripts_gamedir')).replace( '\\', '/').rpartition('/')[2].lower() dbgmsg(1, 'spmenu: game name is %s' % repr(gamename)) if gamename not in data: dbgmsg(1, 'spmenu: game not found, going default') gamename = 'default' this_game = data[gamename] game_data = { 'type': this_game['type'], 'refresh': this_game.as_int('refresh') if this_game['type'] == 'radio' else 0, } dbgmsg_repr(2, game_data) return game_data
def __del__(self): ''' No references to this popup. ''' dbgmsg(1, 'Popuplib2: Deleting popup') dbgmsg_repr(2, self)
def generate_text(self): ''' Generate the string that is to be displayed in the popup. ''' dbgmsg(1, 'Popuplib2: Userpopup building self') return '\n'.join(self._popup)
def pop(self, *args, **kw): return self._contents.pop(*args, **kw) def remove(self, line): return self._contents.remove(line) def display(self): self._contents = [] try: self._popup.build_callback(self._user.userid, self) except TypeError, e: warnings.warn('TypeError when calling build_callback: %s'%e) else: self._final_contents = list(self._popup) + self._contents self._being_hidden = False dbgmsg(1, 'Popuplib2: Userpopup building self') text = '\n'.join(self._final_contents) dbgmsg(2, 'Popuplib2: Calling es.menu(%s, %s, textlen=%s, %s)'%( 0, self._user.userid, len(text), self._popup.enable_keys)) es.menu(0, self._user.userid, text, self._popup.enable_keys) class UserPagedMenu(UserPopup): ''' A userpopup class for PagedMenu. A userpopup is a view to specific Popup, specific to a single user. Each user for each popup have their own userpopup instances. ''' def __init__(self, *args, **kw): '''Initialize a new Userpopup '''