def __init__(self, goto_inputscreen, greeting, **kwargs): # Init super super(ConsoleWindow, self).__init__(**kwargs) # Number of cols self.cols = 1 # Save greeting self.greeting = greeting # Screen transition hook self.goto_input_screen = goto_inputscreen # Create scrollable label for console output self.scroll_view = ConsoleScrollView() self.scroll_view.size_hint_y = 0.9 # Add scroll view widget self.add_widget(self.scroll_view) # Internal function-hook alias self.display_text = self.inputtext_gui_hook # Clear screen and print title self.display_text(greeting, clear=True) # Add progress bar self.progress_bar = ProgressBar(max=1000, size_hint_y=0.01) self.add_widget(self.progress_bar) # Input text box if not (constants.PLATFORM_ANDROID or constants.ENABLE_INPUT_SCREEN): self.console_input = ConsoleInput( # Goto console screen goto_consolescreen=lambda *args, **kwargs: None, # Size size_y=0.09 ) # Add widget self.add_widget(self.console_input) else: # Command input button self.enter_cmd_button = Button( text="Enter Command", size_hint_y=0.09, ) # Bind event - on_press self.enter_cmd_button.bind(on_press=self.goto_inputscreen) # Add button self.add_widget(self.enter_cmd_button)
def __init__(self, goto_consolescreen, **kwargs): # Construct screen super(InputScreen, self).__init__(**kwargs) # Console input self.console_input = ConsoleInput( goto_consolescreen=goto_consolescreen ) # Add the console input self.add_widget(self.console_input)
class InputScreen(Screen): def __init__(self, goto_consolescreen, **kwargs): # Construct screen super(InputScreen, self).__init__(**kwargs) # Console input self.console_input = ConsoleInput( goto_consolescreen=goto_consolescreen ) # Add the console input self.add_widget(self.console_input) def register_handleinput_cmd_hook(self, hook): self.console_input.register_handleinput_cmd_hook(hook) def register_getcommands_cmd_hook(self, hook): self.console_input.register_getcommands_cmd_hook(hook)
class ConsoleWindow(GridLayout): "Console window class." def __init__(self, goto_inputscreen, greeting, **kwargs): # Init super super(ConsoleWindow, self).__init__(**kwargs) # Number of cols self.cols = 1 # Save greeting self.greeting = greeting # Screen transition hook self.goto_input_screen = goto_inputscreen # Create scrollable label for console output self.scroll_view = ConsoleScrollView() self.scroll_view.size_hint_y = 0.9 # Add scroll view widget self.add_widget(self.scroll_view) # Internal function-hook alias self.display_text = self.inputtext_gui_hook # Clear screen and print title self.display_text(greeting, clear=True) # Add progress bar self.progress_bar = ProgressBar(max=1000, size_hint_y=0.01) self.add_widget(self.progress_bar) # Input text box if not (constants.PLATFORM_ANDROID or constants.ENABLE_INPUT_SCREEN): self.console_input = ConsoleInput( # Goto console screen goto_consolescreen=lambda *args, **kwargs: None, # Size size_y=0.09 ) # Add widget self.add_widget(self.console_input) else: # Command input button self.enter_cmd_button = Button( text="Enter Command", size_hint_y=0.09, ) # Bind event - on_press self.enter_cmd_button.bind(on_press=self.goto_inputscreen) # Add button self.add_widget(self.enter_cmd_button) # GUI Hooks----------------------- @mainthread def inputtext_gui_hook(self, text, clear=False): self.scroll_view.display_text(text, clear) @mainthread def getmaxwidth_gui_hook(self): return self.width @mainthread def cleardisplay_gui_hook(self): self.scroll_view.display_text(self.greeting, clear=True) @mainthread def cmdprog_gui_hook(self, status_val): self.progress_bar.value = status_val # --------------------------------- if not (constants.PLATFORM_ANDROID or constants.ENABLE_INPUT_SCREEN): def register_handleinput_cmd_hook(self, hook): self.console_input.register_handleinput_cmd_hook(hook) def register_getcommands_cmd_hook(self, hook): self.console_input.register_getcommands_cmd_hook(hook) def on_resize(self, instance, width, height): # New height and width instance.width = width instance.height = height def goto_inputscreen(self, instance): return self.goto_input_screen()