def handleNotificationCommand(command, ctx): """ Shows notification according to command's parameters """ type = SM_TYPE.lookup(command.type) if type is None: raise WebCommandException("Unknown notification's type: %s!" % command.type) if command.hasMessage(): pushMessage(command.message, type=type, messageData=command.message_data) elif command.hasI18nKey(): parameters = command.i18n_data params = {'type': type, 'key': command.i18n_key, 'messageData': command.message_data} for key, value in parameters.iteritems(): params[key] = value pushI18nMessage(**params) elif command.hasKey(): custom_parameters = command.custom_parameters params = {'type': type, 'key': command.key, 'messageData': command.message_data} for key, value in custom_parameters.iteritems(): params[key] = value pushI18nMessage(**params) else: raise WebCommandException("'i18n_key' or 'message' parameter are missing!") return
def notification(self, cmd): smType = SM_TYPE.lookup(cmd.type) if smType is None: raise WebCommandException("Unknown notification's type: %s!" % cmd.type) if cmd.hasMessage(): pushMessage(cmd.message, type=smType, messageData=cmd.message_data) elif cmd.hasI18nKey(): parameters = cmd.i18n_data params = {'type': smType, 'key': cmd.i18n_key, 'messageData': cmd.message_data} for key, value in parameters.iteritems(): params[key] = value pushI18nMessage(**params) elif cmd.hasKey(): custom_parameters = cmd.custom_parameters params = {'type': smType, 'key': cmd.key, 'messageData': cmd.message_data} for key, value in custom_parameters.iteritems(): params[key] = value pushI18nMessage(**params) return
def userMenu(self, cmd, ctx): context = {'dbID': cmd.spa_id, 'userName': cmd.user_name, 'customItems': cmd.custom_items, 'excludedItems': cmd.excluded_items} callback = ctx.get('callback') browserView = ctx.get('browser_view') app = g_appLoader.getApp() try: browserView.as_showContextMenuS(CONTEXT_MENU_HANDLER_TYPE.CUSTOM_USER, context) cmHandler = app.contextMenuManager.getCurrentHandler() except AttributeError as ex: raise WebCommandException('Failed to show context menu: %s' % ex) if cmHandler is not None and isinstance(cmHandler, CustomUserCMHandler): webBrowser = self.browserController.getBrowser(ctx.get('browser_id')) webBrowser.allowMouseWheel = False def onSelectedCallback(optionId): callback({'menu_type': 'user_menu', 'selected_item': optionId, 'spa_id': cmd.spa_id}) webBrowser.allowMouseWheel = True cmHandler.onSelected += onSelectedCallback else: return {'menu_type': 'user_menu', 'selected_item': None, 'spa_id': cmd.spa_id} return
def browser(self, cmd, ctx): app = g_appLoader.getApp() if app is not None and app.containerManager is not None: browserView = app.containerManager.getView(ViewTypes.LOBBY_SUB, criteria={POP_UP_CRITERIA.VIEW_ALIAS: ctx.get('browser_alias')}) if browserView is not None: browserView.onCloseView() return raise WebCommandException('Unable to find BrowserView!') return
def handleRankedBattlesCommand(command, ctx): """ Executes ranked battles specific actions """ if command.action in RANKED_BATTLES_ACTIONS: RANKED_BATTLES_ACTIONS[command.action](ctx) else: raise WebCommandException('Unknown ranked battles action: %s!' % command.action)
def handleVehiclesCommand(command, ctx): """ Returns vehicles info """ if command.action in VEHICLES_ACTIONS: handler = VEHICLES_ACTIONS[command.action] handler(command, ctx.get('callback')) else: raise WebCommandException('Unknown vehicles action: %s!' % command.action)
def handleOpenTabCommand(command, ctx): """ Opens tab by id """ if command.tab_id in OPEN_TAB_INFO: tabId, elementsList = OPEN_TAB_INFO[command.tab_id] ctx = None if not elementsList else elementsList.get(command.selected_id) g_eventBus.handleEvent(events.LoadViewEvent(tabId, ctx=ctx), scope=EVENT_BUS_SCOPE.LOBBY) else: raise WebCommandException('Unknown tab id: %s!' % command.tab_id) return
def handleCloseWindowCommand(onBrowserClose, command, ctx, isWindow = True): """ Closes window by id """ if isWindow: closeWindowSubCommands = {'browser': partial(_closeBrowserWindow, onBrowserClose)} else: closeWindowSubCommands = {'browser': _closeBrowserView} if command.window_id in closeWindowSubCommands: handler = closeWindowSubCommands[command.window_id] handler(ctx) else: raise WebCommandException('Unknown window: %s!' % command.window_id)
def handleOpenWindowCommand(command, ctx): """ Opens window by id """ if command.window_id in subCommands: cls, handler = subCommands[command.window_id] if cls: subCommand = instantiateObject(cls, command.custom_parameters) handler(subCommand) else: handler() else: raise WebCommandException('Unknown window: %s!' % command.window_id)
def handleStrongholdsBattleCommand(command, ctx): """ Executes battle specific actions """ if command.action in STRONGHOLD_BATTLE_ACTIONS: subCommand, handler = STRONGHOLD_BATTLE_ACTIONS[command.action] if subCommand: subCommandInstance = instantiateObject(subCommand, command.custom_parameters) handler(subCommandInstance) else: handler() else: raise WebCommandException('Unknown strongholds battle action: %s!' % command.action)
def _handlerCloseBrowserWindow(onBrowserClose, command, ctx): if 'browser_id' in ctx: windowAlias = getViewName(ctx['browser_alias'], ctx['browser_id']) app = g_appLoader.getApp() if app is not None and app.containerManager is not None: browserWindow = app.containerManager.getView( ViewTypes.WINDOW, criteria={POP_UP_CRITERIA.UNIQUE_NAME: windowAlias}) if browserWindow is not None: browserWindow.destroy() else: raise WebCommandException("Browser window can't be found!") if onBrowserClose is not None: onBrowserClose() return
def handleRequestCommand(command, ctx): """ Makes request according to request_id """ if command.request_id in REQUEST_COMMANDS: def onCallback(data): data['request_id'] = command.request_id callback = ctx.get('callback') if callable(callback): callback(data) REQUEST_COMMANDS[command.request_id](onCallback) else: raise WebCommandException('Unknown request id: %s!' % command.request_id)
def browser(self, cmd, ctx): if 'browser_id' in ctx: windowAlias = getViewName(ctx['browser_alias'], ctx['browser_id']) app = g_appLoader.getApp() if app is not None and app.containerManager is not None: supportedBrowserViewTypes = (ViewTypes.WINDOW, ViewTypes.OVERLAY) browserWindow = None for viewType in supportedBrowserViewTypes: browserWindow = app.containerManager.getView(viewType, criteria={POP_UP_CRITERIA.UNIQUE_NAME: windowAlias}) if browserWindow is not None: break if browserWindow is not None: browserWindow.destroy() else: raise WebCommandException('Browser window could not be found! May be alias "{}" is wrong or probably browser has unsupported viewType.'.format(windowAlias)) self._onBrowserClose() return
def handleContextMenuCommand(command, ctx): """ Shows context menu by type """ if command.menu_type in CONTEXT_MENU_TYPES: subCommand, handler = CONTEXT_MENU_TYPES[command.menu_type] subCommandInstance = instantiateObject(subCommand, command.custom_parameters) def onCallback(data): data['menu_type'] = command.menu_type data['spa_id'] = subCommandInstance.spa_id callback = ctx.get('callback') if callable(callback): callback(data) handler(subCommandInstance, ctx, onCallback) else: raise WebCommandException('Unknown context menu type: %s!' % command.menu_type)
def handleClanManagementCommand(command, ctx): """ Executes clan management actions """ if command.action in CLAN_MANAGEMENT_ACTIONS: def onCallback(data): data['action'] = command.action callback = ctx.get('callback') if callable(callback): callback(data) subCommand, handler = CLAN_MANAGEMENT_ACTIONS[command.action] if subCommand: subCommandInstance = instantiateObject(subCommand, command.custom_parameters) handler(subCommandInstance, onCallback) else: handler(onCallback) else: raise WebCommandException('Unknown clan management action: %s!' % command.action)
def handleRequestCommand(command, ctx): """ Makes request according to request_id """ if command.request_id in REQUEST_COMMANDS: def onCallback(data): data['request_id'] = command.request_id callback = ctx.get('callback') if callable(callback): callback(data) cls, handler = REQUEST_COMMANDS[command.request_id] if cls is not None: subCommand = instantiateObject(cls, command.custom_parameters) handler(subCommand, onCallback) else: handler(onCallback) else: raise WebCommandException('Unknown request id: %s!' % command.request_id) return
def _itemTypeValidator(itemType): if not ItemPackType.hasValue(itemType): raise WebCommandException( 'unsupported item type "{}"'.format(itemType)) return True