def _display(self, contentType): # print depending on the content type while True: try: if isinstance(contentType, InputText): contentType.run_callback(result=rlinput(contentType.content, contentType.default_input)) elif isinstance(contentType, LicenseAgreement): print(contentType.content) contentType.choose(answer=input(contentType.input)) elif isinstance(contentType, TextWithChoices): contentType.choose(answer=input(contentType.prompt)) elif isinstance(contentType, DisplayMessage): print(contentType.text) elif isinstance(contentType, UnknownProgress): if not contentType.bar: contentType.bar = ProgressBar(widgets=[BouncingBar()]) with suppress(StopIteration): # pulse and add a timeout callback contentType.bar(contentType._iterator()).next() UI.delayed_display(contentType) # don't recall the callback return False else: logger.error("Unexcepted content type to display to CLI UI: {}".format(contentType)) MainLoop().quit(status_code=1) break except InputError as e: logger.error(str(e)) continue
def test_call_delayed_display(self, mocksys): """We call the display method from the UIPlug in delayed_display with 50ms waiting""" UI.delayed_display(self.contentType) now = time() self.start_glib_mainloop() self.wait_for_mainloop_shutdown() self.assertTrue(self.mockUIPlug._display.called) self.assertIsNotNone(self.mainloop_thread) self.assertIsNotNone(self.display_thread) self.assertEquals(self.mainloop_thread, self.display_thread) self.assertTrue(self.time_display_call - now > 0.05)
def decompress_and_install_done(self, result): self._install_done = True error_detected = False for fd in result: if result[fd].error: logger.error(result[fd].error) error_detected = True fd.close() if error_detected: UI.return_main_screen() return # install desktop file if self.desktop_file_name: self.create_launcher() UI.delayed_display(DisplayMessage("Installation done")) UI.return_main_screen()
def remove(self): """Remove current framework if installed Not that we only remove desktop file, launcher icon and dir content, we do not remove packages as they might be in used for other framework""" # check if it's installed and so on. super().remove() UI.display(DisplayMessage("Removing {}".format(self.name))) if self.desktop_filename: with suppress(FileNotFoundError): os.remove(get_launcher_path(self.desktop_filename)) if self.icon_filename: with suppress(FileNotFoundError): os.remove(get_icon_path(self.icon_filename)) with suppress(FileNotFoundError): shutil.rmtree(self.install_path) self.remove_from_config() UI.delayed_display(DisplayMessage("Suppression done")) UI.return_main_screen()
def run_display(future): nonlocal now self.function_thread = threading.current_thread().ident now = time() UI.delayed_display(self.contentType)