Ejemplo n.º 1
0
class KeyboardScreen(MenuScreen):
    """ Keyboard Screen """
    def __init__(self, title, util, listeners, voice_assistant):
        """ Initializer

        :param util: utility object
        :param listeners: listeners
        :param voice_assistant: voice assistant
        """
        self.util = util
        self.listeners = listeners
        layout = BorderLayout(util.screen_rect)
        layout.set_percent_constraints(PERCENT_TOP_HEIGHT,
                                       PERCENT_BOTTOM_HEIGHT, 0, 0)

        MenuScreen.__init__(self, util, listeners, 1, 1, voice_assistant)
        self.screen_title.set_text(title)

        k_layout = BorderLayout(self.layout.CENTER)
        k_layout.set_percent_constraints(20, 0, 0, 0)

        font_size = int((k_layout.TOP.h * 50) / 100)
        fgr = util.config[COLORS][COLOR_BRIGHT]
        bgr = (0, 0, 0)
        bb = k_layout.TOP
        s = int(font_size / 2)
        self.input_text = self.factory.create_output_text("kbd.text",
                                                          bb,
                                                          bgr,
                                                          fgr,
                                                          font_size,
                                                          H_ALIGN_LEFT,
                                                          shift_x=s)
        self.input_text.obfuscate_flag = True
        self.add_component(self.input_text)

        keyboard_layout = k_layout.CENTER
        self.keyboard = Keyboard(util, keyboard_layout,
                                 listeners[KEY_CALLBACK])
        self.set_menu(self.keyboard)
        self.keyboard.add_text_listener(self.input_text.set_text)

        listeners[KEY_DELETE] = self.keyboard.delete
        listeners[KEY_VIEW] = self.input_text.obfuscate
        self.navigator = KeyboardNavigator(self.util, self.layout.BOTTOM,
                                           listeners)
        self.components.append(self.navigator)

    def add_screen_observers(self, update_observer, redraw_observer):
        """ Add screen observers

        :param update_observer: observer for updating the screen
        :param redraw_observer: observer to redraw the whole screen
        """
        MenuScreen.add_screen_observers(self, update_observer, redraw_observer)
        self.update_observer = update_observer
        self.redraw_observer = redraw_observer
        self.keyboard.add_menu_observers(update_observer, redraw_observer)
        for b in self.navigator.menu_buttons:
            self.add_button_observers(b, update_observer, redraw_observer)
Ejemplo n.º 2
0
    def __init__(self,
                 title,
                 util,
                 listeners,
                 voice_assistant,
                 show_visibility=True):
        """ Initializer

        :param util: utility object
        :param listeners: listeners
        :param voice_assistant: voice assistant
        """
        self.util = util
        self.listeners = listeners
        layout = BorderLayout(util.screen_rect)
        layout.set_percent_constraints(PERCENT_TOP_HEIGHT,
                                       PERCENT_BOTTOM_HEIGHT, 0, 0)

        MenuScreen.__init__(self, util, listeners, 1, 1, voice_assistant)
        self.screen_title.set_text(title)

        k_layout = BorderLayout(self.layout.CENTER)
        k_layout.set_percent_constraints(20, 0, 0, 0)

        font_size = int((k_layout.TOP.h * 50) / 100)
        fgr = util.config[COLORS][COLOR_BRIGHT]
        bgr = (0, 0, 0)
        bb = k_layout.TOP
        s = int(font_size / 2)
        self.input_text = self.factory.create_output_text("kbd.text",
                                                          bb,
                                                          bgr,
                                                          fgr,
                                                          font_size,
                                                          H_ALIGN_LEFT,
                                                          shift_x=s)
        self.input_text.obfuscate_flag = show_visibility
        self.add_component(self.input_text)

        keyboard_layout = k_layout.CENTER
        self.keyboard = Keyboard(util, keyboard_layout,
                                 listeners[KEY_CALLBACK], self)
        self.set_menu(self.keyboard)
        self.keyboard.add_text_listener(self.input_text.set_text)

        listeners[KEY_DELETE] = self.keyboard.delete
        listeners[KEY_VIEW] = self.input_text.obfuscate
        self.navigator = KeyboardNavigator(self.util, self.layout.BOTTOM,
                                           listeners, show_visibility)
        self.add_navigator(self.navigator)

        self.link_borders()