def add_key(self, x, y, keycode, on_key): self.add( ButtonComponent(self.images.button(Images.BUTTON_OFS_KEY + keycode)).set_event_listener( UiEvent.MOUSE_CLICK_EVENT, on_key).set_pos(x, y))
def __init__(self, screen, images, framebuilder, fonts, sizes, colors): UiComponent.__init__(self) self.screen = screen self.images = images self.framebuilder = framebuilder self.fonts = fonts self.sizes = sizes self.colors = colors self.handle_select_up = self.default_handler self.handle_select_down = self.default_handler self.handle_select_wlan = self.default_select_handler self.handle_change_password = self.default_handler self.handle_return_key = self.default_handler self.handle_scan_wlan = self.default_handler self.add( ImageComponent(self.images.label(Images.LABEL_RADIO_PI)).set_pos( 40, 0)) self.add( ImageComponent(self.images.label(Images.LABEL_WAVE)).set_pos( 160, 0)) self.handle_push_clock = lambda: print("select clock pushed") self.clock = ClockComponent(self.images).on_push(self.on_push_clock) self.clock.set_pos(0, 0).set_size(40, 40) self.add(self.clock) self.framebuilder.frame(self, 0, 2, 9, 3) self.framebuilder.frame(self, 0, 5, 9, 3) self.framebuilder.frame(self, 9, 2, 7, 6) self.ssid = "" self.pw = "" self.edit_pw = True self.lan_ip = "unknown" self.wlan_ip = "unknown" self.wlan_list = [] self.framebuilder.frame(self, 0, 8, 16, 4) self.add(ButtonComponent(self.images.button(Images.BUTTON_SMALL_UP))\ .set_pos(188, 50)\ .set_event_listener(UiEvent.MOUSE_CLICK_EVENT, lambda event, source: self.handle_select_up()) ) self.add(ButtonComponent(self.images.button(Images.BUTTON_SCAN))\ .set_pos(188, 90)\ .set_event_listener(UiEvent.MOUSE_CLICK_EVENT, lambda event, source: self.handle_scan_wlan()) ) self.add(ButtonComponent(self.images.button(Images.BUTTON_SMALL_DOWN))\ .set_pos(188, 130)\ .set_event_listener(UiEvent.MOUSE_CLICK_EVENT, lambda event, source: self.handle_select_down()) ) self.network_status_label = TextlabelComponent("", self.fonts, self.sizes, self.colors) self.network_status_label.set_pos(10, 55).set_size(170, 50) self.add(self.network_status_label) self.network_ssid_label = TextlabelComponent("", self.fonts, self.sizes, self.colors) self.network_ssid_label.set_pos(10, 115).set_size(170, 18) self.network_ssid_label.set_event_listener(UiEvent.MOUSE_CLICK_EVENT, self.on_edit_ssid_field) self.add(self.network_ssid_label) self.network_pw_field = TextlabelComponent("", self.fonts, self.sizes, self.colors) self.network_pw_field.set_pos(10, 130).set_size(140, 18) self.network_pw_field.set_event_listener(UiEvent.MOUSE_CLICK_EVENT, self.on_edit_pw_field) self.add(self.network_pw_field) self.add(ButtonComponent(self.images.button(Images.BUTTON_OFS_KEY + 0x3d))\ .set_pos(150, 130)\ .set_event_listener(UiEvent.MOUSE_CLICK_EVENT, lambda event, source: self.handle_change_password()) ) self.wlan_level_icons = [ ImageComponent(self.images.label(Images.LABEL_WLAN_0)), ImageComponent(self.images.label(Images.LABEL_WLAN_1)), ImageComponent(self.images.label(Images.LABEL_WLAN_2)), ImageComponent(self.images.label(Images.LABEL_WLAN_3)), ] self.wlan_list_view = ListViewComponent(self.fonts, self.sizes, self.colors) self.wlan_list_view.set_size(100, 100, 17).set_pos(210, 50) self.wlan_list_view.set_to_string( lambda item: self.wlan_item_to_string(item)) self.wlan_list_view.set_to_icon( lambda item: self.wlan_item_to_icon(item)) self.wlan_list_view.set_handle_select( lambda item: self.handle_select_wlan(item)) self.wlan_list_view.set_empty_message("_- no signal -") self.wlan_list_view.set_items(self.wlan_list) self.add(self.wlan_list_view) self.keyboard = KeyboardComponent(self.images) self.keyboard.set_pos(10, 170).set_size(300, 60) self.keyboard.set_keyboard_handler( lambda keycode: self.handle_select_key(keycode)) self.keyboard.disable_favourite_button() self.add(self.keyboard) self.set_ips("", "") self.set_pw("") self.set_ssid("")
def __init__(self, screen, images, framebuilder, fonts, sizes, colors): UiComponent.__init__(self) self.screen = screen self.images = images self.framebuilder = framebuilder self.fonts = fonts self.sizes = sizes self.colors = colors self.keyboard_mode = 0 # 0 = num, 1 = numeric self.filter = "" self.handle_select_up = self.default_key_handler self.handle_select_down = self.default_key_handler self.handle_select_music_key = self.default_key_handler self.handle_play_station = self.default_play_file_handler self.handle_select_station = self.default_key_handler self.handle_push_clock = lambda: print("select clock pushed") self.favourite_icon = ButtonComponent( self.images.button(Images.BUTTON_OFS_KEY + 0x2e)) self.add( ImageComponent(self.images.label(Images.LABEL_RADIO_PI)).set_pos( 40, 0)) self.add( ImageComponent(self.images.label(Images.LABEL_WAVE)).set_pos( 160, 0)) self.clock = ClockComponent(self.images).on_push(self.on_push_clock) self.clock.set_pos(0, 0).set_size(40, 40) self.add(self.clock) self.framebuilder.frame(self, 0, 2, 14, 6) self.framebuilder.frame(self, 14, 2, 2, 6) self.framebuilder.frame(self, 0, 8, 16, 4) self.add(ButtonComponent(self.images.button(Images.BUTTON_SELECT_UP))\ .set_pos(280, 45)\ .set_event_listener(UiEvent.MOUSE_CLICK_EVENT, lambda event, source: self.handle_select_up()) ) self.add(ButtonComponent(self.images.button(Images.BUTTON_SELECT_DOWN))\ .set_pos(280, 95)\ .set_event_listener(UiEvent.MOUSE_CLICK_EVENT, lambda event, source: self.handle_select_down()) ) self.file_list_view = ListViewComponent(self.fonts, self.sizes, self.colors) self.file_list_view.set_size(260, 100, 35).set_pos(10, 50) self.file_list_view.set_to_string( lambda file: self.get_file_string(file)) self.file_list_view.set_to_icon(lambda file: self.get_file_icon(file)) self.file_list_view.set_handle_select( lambda file: self.handle_play_file(file)) self.file_list_view.set_empty_message("-- no data --") self.add(self.file_list_view) self.keyboard = KeyboardComponent(self.images) self.keyboard.set_pos(10, 170).set_size(300, 60) self.keyboard.set_keyboard_handler( lambda keycode: self.handle_select_music_key(keycode)) self.add(self.keyboard)
def __init__(self, screen, images, framebuilder, fonts, sizes, colors): UiComponent.__init__(self) self.screen = screen self.images = images self.framebuilder = framebuilder self.show_start_button = False self.station = None self.favourite = False self.add( ImageComponent(self.images.label(Images.LABEL_RADIO_PI)).set_pos( 40, 0)) self.add( ImageComponent(self.images.label(Images.LABEL_WAVE)).set_pos( 160, 0)) self.handle_push_clock = lambda: print("select clock pushed") self.clock = ClockComponent(self.images).on_push(self.on_push_clock) self.clock.set_pos(0, 0).set_size(40, 40) self.add(self.clock) self.framebuilder.frame(self, 0, 2, 16, 7) self.framebuilder.frame(self, 0, 9, 2, 3) self.framebuilder.frame(self, 2, 9, 2, 3) self.framebuilder.frame(self, 4, 9, 3, 3) self.framebuilder.frame(self, 7, 9, 3, 3) self.framebuilder.frame(self, 10, 9, 3, 3) self.framebuilder.frame(self, 13, 9, 3, 3) self.handle_volume_down = self.default_key_handler self.handle_volume_up = self.default_key_handler self.handle_start = self.default_key_handler self.handle_stop = self.default_key_handler self.handle_select_station = self.default_key_handler self.handle_select_music = self.default_key_handler self.handle_setup = self.default_key_handler self.handle_favourite = self.default_favourite_handler self.volume_up_button = ButtonComponent(self.images.button(Images.BUTTON_VOLUME_DOWN))\ .set_pos(0, 180)\ .set_event_listener(UiEvent.MOUSE_CLICK_EVENT, lambda event, source: self.handle_volume_down()) self.add(self.volume_up_button) self.volume_down_button = ButtonComponent(self.images.button(Images.BUTTON_VOLUME_UP))\ .set_pos(40, 180)\ .set_event_listener(UiEvent.MOUSE_CLICK_EVENT, lambda event, source: self.handle_volume_up()) self.add(self.volume_down_button) self.start_stop_button = ButtonComponent(self.images.button(Images.BUTTON_STOP))\ .set_pos(80, 180)\ .set_event_listener(UiEvent.MOUSE_CLICK_EVENT, lambda event, source: self.handle_start_stop()) self.add(self.start_stop_button) self.add(ButtonComponent(self.images.button(Images.BUTTON_SELECT_MUSIC))\ .set_pos(140, 180)\ .set_event_listener(UiEvent.MOUSE_CLICK_EVENT, lambda event, source: self.handle_select_music()) ) self.add(ButtonComponent(self.images.button(Images.BUTTON_SELECT_STATION))\ .set_pos(200, 180)\ .set_event_listener(UiEvent.MOUSE_CLICK_EVENT, lambda event, source: self.handle_select_station()) ) self.add(ButtonComponent(self.images.button(Images.BUTTON_SETUP))\ .set_pos(260, 180)\ .set_event_listener(UiEvent.MOUSE_CLICK_EVENT, lambda event, source: self.handle_setup()) ) self.stationlabel = TextlabelComponent("---", fonts, sizes, colors) self.stationlabel.set_pos(10, 50).set_size(300, 120) self.add(self.stationlabel) # favourite self.favourite_button = ButtonComponent( self.images.button(Images.BUTTON_OFS_KEY + 0x2f)) self.favourite_button.set_event_listener( UiEvent.MOUSE_CLICK_EVENT, lambda event, source: self.switch_favourite()).set_pos(290, 50) self.add(self.favourite_button) self.set_station(None)
class RadioPlayView(UiComponent): def __init__(self, screen, images, framebuilder, fonts, sizes, colors): UiComponent.__init__(self) self.screen = screen self.images = images self.framebuilder = framebuilder self.show_start_button = False self.station = None self.favourite = False self.add( ImageComponent(self.images.label(Images.LABEL_RADIO_PI)).set_pos( 40, 0)) self.add( ImageComponent(self.images.label(Images.LABEL_WAVE)).set_pos( 160, 0)) self.handle_push_clock = lambda: print("select clock pushed") self.clock = ClockComponent(self.images).on_push(self.on_push_clock) self.clock.set_pos(0, 0).set_size(40, 40) self.add(self.clock) self.framebuilder.frame(self, 0, 2, 16, 7) self.framebuilder.frame(self, 0, 9, 2, 3) self.framebuilder.frame(self, 2, 9, 2, 3) self.framebuilder.frame(self, 4, 9, 3, 3) self.framebuilder.frame(self, 7, 9, 3, 3) self.framebuilder.frame(self, 10, 9, 3, 3) self.framebuilder.frame(self, 13, 9, 3, 3) self.handle_volume_down = self.default_key_handler self.handle_volume_up = self.default_key_handler self.handle_start = self.default_key_handler self.handle_stop = self.default_key_handler self.handle_select_station = self.default_key_handler self.handle_select_music = self.default_key_handler self.handle_setup = self.default_key_handler self.handle_favourite = self.default_favourite_handler self.volume_up_button = ButtonComponent(self.images.button(Images.BUTTON_VOLUME_DOWN))\ .set_pos(0, 180)\ .set_event_listener(UiEvent.MOUSE_CLICK_EVENT, lambda event, source: self.handle_volume_down()) self.add(self.volume_up_button) self.volume_down_button = ButtonComponent(self.images.button(Images.BUTTON_VOLUME_UP))\ .set_pos(40, 180)\ .set_event_listener(UiEvent.MOUSE_CLICK_EVENT, lambda event, source: self.handle_volume_up()) self.add(self.volume_down_button) self.start_stop_button = ButtonComponent(self.images.button(Images.BUTTON_STOP))\ .set_pos(80, 180)\ .set_event_listener(UiEvent.MOUSE_CLICK_EVENT, lambda event, source: self.handle_start_stop()) self.add(self.start_stop_button) self.add(ButtonComponent(self.images.button(Images.BUTTON_SELECT_MUSIC))\ .set_pos(140, 180)\ .set_event_listener(UiEvent.MOUSE_CLICK_EVENT, lambda event, source: self.handle_select_music()) ) self.add(ButtonComponent(self.images.button(Images.BUTTON_SELECT_STATION))\ .set_pos(200, 180)\ .set_event_listener(UiEvent.MOUSE_CLICK_EVENT, lambda event, source: self.handle_select_station()) ) self.add(ButtonComponent(self.images.button(Images.BUTTON_SETUP))\ .set_pos(260, 180)\ .set_event_listener(UiEvent.MOUSE_CLICK_EVENT, lambda event, source: self.handle_setup()) ) self.stationlabel = TextlabelComponent("---", fonts, sizes, colors) self.stationlabel.set_pos(10, 50).set_size(300, 120) self.add(self.stationlabel) # favourite self.favourite_button = ButtonComponent( self.images.button(Images.BUTTON_OFS_KEY + 0x2f)) self.favourite_button.set_event_listener( UiEvent.MOUSE_CLICK_EVENT, lambda event, source: self.switch_favourite()).set_pos(290, 50) self.add(self.favourite_button) self.set_station(None) def on_push_clock(self): self.handle_push_clock() def switch_favourite(self): self.favourite = not self.favourite self.set_favourite_button(self.favourite) self.handle_favourite(self.favourite) def set_favourite_button(self, favourite): if self.favourite: self.favourite_button.set_images( self.images.button(Images.BUTTON_OFS_KEY + 0x2e)) else: self.favourite_button.set_images( self.images.button(Images.BUTTON_OFS_KEY + 0x2f)) def set_station(self, station): self.station = station if self.station == None: self.stationlabel.set_text(" \n \n^° --- no audio stream ---°_") self.favourite_button.deactivate() self.start_stop_button.deactivate() self.volume_up_button.deactivate() self.volume_down_button.deactivate() else: self.stationlabel.set_text("^*%s*_\n*%s*\n%s\n_~%s~\n~%s~^" % ( self.station.get_name(), # self.station.get_votes(), # self.station.get_negative_votes(), " ".join(self.station.get_tags()), self.station.get_location(), self.station.get_codec(), self.station.get_homepage())) self.favourite = self.station.get_favourite() self.set_favourite_button(self.favourite) self.favourite_button.activate() self.start_stop_button.activate() self.volume_up_button.activate() self.volume_down_button.activate() self.set_changed() def default_key_handler(self): print("default button handler") def default_favourite_handler(self, favourite): print("default favourite handler: %s" % favourite) def handle_start_stop(self): if self.show_start_button: self.show_start_button = False self.start_stop_button.set_images( self.images.button(Images.BUTTON_STOP)) self.handle_start() else: self.show_start_button = True self.start_stop_button.set_images( self.images.button(Images.BUTTON_START)) self.handle_stop()
def __init__(self, image, keycode): ButtonComponent.__init__(self, image) self.keycode = keycode