class WakeUpMenu(Container): """ Wake up menu """ def __init__(self, util, bb, gap, digits, listener, timer_lock, clock_change_callback, change_codes): """ Initializer :param util: utility object :param bb: menu bounding box :param gap: gap between hours and minutes :param digits: clock digits 0-9 :param listener: the listener :param timer_lock: lock object :param clock_change_callback: callback function :param change_codes: change codes """ self.util = util self.name = WAKE_UP self.config = self.util.config self.factory = Factory(util) icon_size = 0.43 Container.__init__(self, util, bb.CENTER) self.bgr = (0, 0, 0, 0) self.clock = Clock(self.util, WAKE_UP, WAKE_UP_TIME, digits, bb, gap, icon_size, timer_lock, clock_change_callback, change_codes) self.add_component(self.clock) border_x = bb.RIGHT.x d = {} d["name"] = WAKE_UP d["bounding_box"] = pygame.Rect(border_x + 1, bb.y + 1, bb.w - border_x, bb.h - 1) d["keyboard_key"] = kbd_keys[KEY_BACK] d["image_size_percent"] = icon_size switch_on = self.config[TIMER][WAKE_UP] self.button_selected = switch_on self.button = self.factory.create_timer_button(**d) self.button.set_selected(switch_on) self.button.add_release_listener(listener) self.add_component(self.button) def set_parent_screen(self, scr): """ Add parent screen :param scr: parent screen """ self.button.set_parent_screen(scr) def add_menu_observers(self, update_observer, redraw_observer=None): """ Add menu observer :param update_observer: observer for updating menu :param redraw_observer: observer to redraw the whole screen """ self.clock.add_menu_observers(update_observer, redraw_observer) self.button.add_release_listener(redraw_observer)
def __init__(self, util, bb, gap, digits, listener, timer_lock, clock_change_callback, change_codes): """ Initializer :param util: utility object :param bb: menu bounding box :param gap: gap between hours and minutes :param digits: clock digits 0-9 :param listener: the listener :param timer_lock: lock object :param clock_change_callback: callback function :param change_codes: change codes """ self.util = util self.name = SLEEP + "_" + POWEROFF self.config = self.util.config self.factory = Factory(util) sleep_icon_size = 0.64 poweroff_icon_size = 0.56 Container.__init__(self, util, bb.CENTER) border_x = bb.RIGHT.x c = GridLayout(Rect(border_x + 1, bb.y + 1, bb.w - border_x, bb.h - 1)) c.set_pixel_constraints(2, 1) self.bgr = (0, 0, 0, 0) self.sleep_selected = self.config[TIMER][SLEEP] self.poweroff_selected = self.config[TIMER][POWEROFF] self.clock = Clock(self.util, SLEEP, SLEEP_TIME, digits, bb, timer_lock, clock_change_callback, change_codes) self.add_component(self.clock) s = c.get_next_constraints() self.sleep_button = self.add_button(SLEEP, s, kbd_keys[KEY_SETUP], self.sleep_selected, sleep_icon_size, listener) n = c.get_next_constraints() h = bb.h - s.height - 2 r = Rect(n.x, n.y + 1, n.w, h) self.poweroff_button = self.add_button(POWEROFF, r, kbd_keys[KEY_END], self.poweroff_selected, poweroff_icon_size, listener) self.bounding_box = bb.CENTER
def __init__(self, util, bb, gap, digits, listener, timer_lock, clock_change_callback, change_codes): """ Initializer :param util: utility object :param bb: menu bounding box :param gap: gap between hours and minutes :param digits: clock digits 0-9 :param listener: the listener :param timer_lock: lock object :param clock_change_callback: callback function :param change_codes: change codes """ self.util = util self.name = WAKE_UP self.config = self.util.config self.factory = Factory(util) icon_size = 0.43 Container.__init__(self, util, bb) self.bgr = (0, 0, 0, 0) self.clock = Clock(self.util, WAKE_UP, WAKE_UP_TIME, digits, bb, gap, icon_size, timer_lock, clock_change_callback, change_codes) self.add_component(self.clock) border_x = bb.RIGHT.x d = {} d["name"] = WAKE_UP d["bounding_box"] = pygame.Rect(border_x + 1, bb.y + 1, bb.w - border_x, bb.h - 1) d["keyboard_key"] = kbd_keys[KEY_BACK] d["image_size_percent"] = icon_size d["bgr"] = self.config[COLORS][COLOR_DARK] switch_on = self.config[TIMER][WAKE_UP] self.button_selected = switch_on self.button = self.factory.create_timer_button(**d) self.button.set_selected(switch_on) self.button.add_release_listener(listener) self.add_component(self.button)
class SleepMenu(Container): """ Sleep menu """ def __init__(self, util, bb, gap, digits, listener, timer_lock, clock_change_callback, change_codes): """ Initializer :param util: utility object :param bb: menu bounding box :param gap: gap between hours and minutes :param digits: clock digits 0-9 :param listener: the listener :param timer_lock: lock object :param clock_change_callback: callback function :param change_codes: change codes """ self.util = util self.name = SLEEP + "_" + POWEROFF self.config = self.util.config self.factory = Factory(util) sleep_icon_size = 0.64 poweroff_icon_size = 0.56 Container.__init__(self, util, bb.CENTER) border_x = bb.RIGHT.x c = GridLayout(Rect(border_x + 1, bb.y + 1, bb.w - border_x, bb.h - 1)) c.set_pixel_constraints(2, 1) self.bgr = (0, 0, 0, 0) self.sleep_selected = self.config[TIMER][SLEEP] self.poweroff_selected = self.config[TIMER][POWEROFF] self.clock = Clock(self.util, SLEEP, SLEEP_TIME, digits, bb, timer_lock, clock_change_callback, change_codes) self.add_component(self.clock) s = c.get_next_constraints() self.sleep_button = self.add_button(SLEEP, s, kbd_keys[KEY_SETUP], self.sleep_selected, sleep_icon_size, listener) n = c.get_next_constraints() h = bb.h - s.height - 2 r = Rect(n.x, n.y + 1, n.w, h) self.poweroff_button = self.add_button(POWEROFF, r, kbd_keys[KEY_END], self.poweroff_selected, poweroff_icon_size, listener) self.bounding_box = bb.CENTER def add_button(self, name, layout, kbd_key, switch_on, icon_size, listener): """ Add button :param name: component name :param layout: button layout :param kbd_key: keyboard key assigned to the button :param switch_on: flag showing if button is selected :param icon_size: button icon size :param listener: button listener """ d = {} d["name"] = name d["bounding_box"] = layout d["keyboard_key"] = kbd_key d["image_size_percent"] = icon_size button = self.factory.create_timer_button(**d) button.add_release_listener(listener) button.set_selected(switch_on) self.add_component(button) return button def set_parent_screen(self, scr): """ Add parent screen :param scr: parent screen """ self.sleep_button.set_parent_screen(scr) self.poweroff_button.set_parent_screen(scr) def add_menu_observers(self, update_observer, redraw_observer=None): """ Add menu observer :param update_observer: observer for updating menu :param redraw_observer: observer to redraw the whole screen """ self.clock.add_menu_observers(update_observer, redraw_observer) self.sleep_button.add_release_listener(redraw_observer) self.poweroff_button.add_release_listener(redraw_observer)