def handle_event(self, event): """ File menu event handler :param event: event to handle """ if not self.visible: return if event.type == USER_EVENT_TYPE and event.sub_type == SUB_TYPE_KEYBOARD and event.action == pygame.KEYUP: if event.keyboard_key == kbd_keys[KEY_LEFT]: if (self.filelist.current_item_index_in_page == 0 and self.filelist.current_item_index != 0) or self.filelist.current_item_index == 0: if self.filelist.length <= self.filelist.items_per_page: self.select_item_on_page(self.filelist.length - 1) else: self.turn_page_left() else: self.select_item_on_page(self.filelist.current_item_index - 1) elif event.keyboard_key == kbd_keys[KEY_RIGHT]: if self.filelist.current_item_index == self.filelist.length - 1 or self.filelist.current_item_index_in_page == self.filelist.items_per_page - 1: if self.filelist.length <= self.filelist.items_per_page: self.select_item_on_page(0) else: self.turn_page_right() else: self.select_item_on_page(self.filelist.current_item_index + 1) elif event.keyboard_key == kbd_keys[KEY_UP] or event.keyboard_key == kbd_keys[KEY_DOWN]: Menu.handle_event(self, event) self.filelist.set_current_item(self.selected_index) self.notify_menu_navigation_listeners(self.empty_state) elif event.keyboard_key == kbd_keys[KEY_SELECT]: Menu.handle_event(self, event) else: Menu.handle_event(self, event)
def handle_event(self, event): """ Handle menu events :param event: event object """ if not self.visible: return if event.type == USER_EVENT_TYPE and event.sub_type == SUB_TYPE_KEYBOARD and event.action == pygame.KEYUP: i = self.get_selected_index() k = event.keyboard_key if k == kbd_keys[KEY_LEFT]: if i == None: return if i == 0 and self.current_page == 1: pass elif i == 0 and self.current_page != 1: s = State() s.select_last = True self.previous_page(s) self.unselect() self.select_by_index(len(self.buttons) - 1) else: self.unselect() self.select_by_index(i - 1) elif k == kbd_keys[KEY_RIGHT]: if i == None: return if i == len(self.buttons) - 1: self.next_page(None) else: self.unselect() self.select_by_index(i + 1) elif k == kbd_keys[KEY_UP] or k == kbd_keys[KEY_DOWN]: Menu.handle_event(self, event) elif k == kbd_keys[KEY_SELECT] and not self.start_page_num: Menu.handle_event(self, event) elif k in kbd_num_keys: self.start_page_num = True self.current_page_num += self.get_num_str(k) self.set_title(int(self.current_page_num)) elif k == kbd_keys[KEY_SELECT] and self.start_page_num: self.start_page_num = False self.go_to_page(int(self.current_page_num)) self.current_page_num = "" self.select_by_index(0) elif k == kbd_keys[KEY_PARENT] and self.start_page_num: self.start_page_num = False self.current_page_num = "" self.reset_title() else: Menu.handle_event(self, event)
def handle_event(self, event): """ Station menu event handler :param event: event to handle """ if not self.visible: return if self.current_mode == self.STATION_MODE: self.station_button.handle_event(event) else: if event.type == USER_EVENT_TYPE and event.sub_type == SUB_TYPE_KEYBOARD and event.action == pygame.KEYUP: l = len(self.components) selection = self.components[l - 1] key_event = False col = int(selection.selection_index % self.cols) row = int(selection.selection_index / self.cols) if event.keyboard_key == kbd_keys[KEY_LEFT]: if col == 0 and row == 0: self.switch_to_previous_page(None) l = len(self.components) selection.selection_index = l - 4 else: selection.selection_index = selection.selection_index - 1 key_event = True elif event.keyboard_key == kbd_keys[KEY_RIGHT]: if col == self.cols - 1 and row == self.rows - 1: self.switch_to_next_page(None) selection.selection_index = 0 l = len(self.components) else: m = selection.selection_index + 1 if self.get_button_by_index_in_page(m): selection.selection_index = m else: self.switch_to_next_page(None) selection.selection_index = 0 l = len(self.components) key_event = True elif event.keyboard_key == kbd_keys[KEY_UP]: if row == 0: for n in range(self.rows): m = selection.selection_index + (self.rows - 1 - n) * self.cols if self.get_button_by_index_in_page(m): selection.selection_index = m else: selection.selection_index = selection.selection_index - self.cols key_event = True elif event.keyboard_key == kbd_keys[KEY_DOWN]: if row == self.rows - 1: selection.selection_index = int( selection.selection_index % self.cols) else: m = selection.selection_index + self.cols if self.get_button_by_index_in_page(m): selection.selection_index = m else: selection.selection_index = int( selection.selection_index % self.cols) key_event = True elif event.keyboard_key == kbd_keys[KEY_BACK]: self.init_station(self.station_button.state.index) self.switch_mode(self.station_button.state) self.draw() key_event = False if key_event: next_selected_button = self.get_button_by_index_in_page( selection.selection_index) self.components[l - 1] = self.get_selection_frame( next_selected_button) self.draw() if event.keyboard_key == kbd_keys[KEY_SELECT]: selected_button = self.get_button_by_index_in_page( selection.selection_index) self.item_selected(selected_button.state) self.switch_mode(selected_button.state) self.notify_menu_click_listeners(event) else: Menu.handle_event(self, event) if self.visible and event.type == pygame.MOUSEBUTTONUP and self.bounding_box.collidepoint( event.pos): self.notify_menu_click_listeners(event)
def handle_event(self, event): """ Station menu event handler :param event: event to handle """ if not self.visible: return if self.current_mode == self.STATION_MODE: self.station_button.handle_event(event) else: if event.type == USER_EVENT_TYPE and event.sub_type == SUB_TYPE_KEYBOARD and event.action == pygame.KEYUP: self.keyboard_navigation = True l = len(self.components) selection = self.components[l - 1] key_event = False col = int(selection.selection_index % self.cols) row = int(selection.selection_index / self.cols) if event.keyboard_key == kbd_keys[KEY_LEFT]: if col == 0 and row == 0: self.switch_to_previous_page(None) l = len(self.components) selection.selection_index = l - 4 else: selection.selection_index = selection.selection_index - 1 key_event = True elif event.keyboard_key == kbd_keys[KEY_RIGHT]: if col == self.cols - 1 and row == self.rows - 1: self.switch_to_next_page(None) selection.selection_index = 0 l = len(self.components) else: m = selection.selection_index + 1 if self.get_button_by_index_in_page(m): selection.selection_index = m else: self.switch_to_next_page(None) selection.selection_index = 0 l = len(self.components) key_event = True elif event.keyboard_key == kbd_keys[KEY_UP]: if row == 0: for n in range(self.rows): m = selection.selection_index + (self.rows - 1 - n) * self.cols if self.get_button_by_index_in_page(m): selection.selection_index = m else: selection.selection_index = selection.selection_index - self.cols key_event = True elif event.keyboard_key == kbd_keys[KEY_DOWN]: if row == self.rows - 1: selection.selection_index = int(selection.selection_index % self.cols) else: m = selection.selection_index + self.cols if self.get_button_by_index_in_page(m): selection.selection_index = m else: selection.selection_index = int(selection.selection_index % self.cols) key_event = True elif event.keyboard_key == kbd_keys[KEY_BACK]: self.init_station(self.station_button.state.index) self.switch_mode(self.station_button.state) self.draw() key_event = False if key_event: next_selected_button = self.get_button_by_index_in_page(selection.selection_index) self.components[l - 1] = self.get_selection_frame(next_selected_button) self.draw() if event.keyboard_key == kbd_keys[KEY_SELECT]: selected_button = self.get_button_by_index_in_page(selection.selection_index) self.item_selected(selected_button.state) self.switch_mode(selected_button.state) self.keyboard_navigation = False self.notify_menu_click_listeners(event) else: Menu.handle_event(self, event) if self.visible and event.type == pygame.MOUSEBUTTONUP and self.bounding_box.collidepoint(event.pos): self.notify_menu_click_listeners(event)