def _thread_run(self, mode, **kwargs): method = getattr(self._chooser_window, mode) selection = method(**kwargs) if not self._window: return self._selection = selection mainthread(self.dismiss)()
def discover(self, timeout): mainthread(self.start_scan)() self.state = "scan" try: toast(self.state) except: print(self.state) self.scanned.wait(timeout) mainthread(self.stop_scan)()
def on_focus(self, _arg, is_focused: bool) -> None: if self.was_focused ^ is_focused: if self.was_focused: self.text = str(self.root.validated_qty) if is_focused: mainthread(self.select_all)() else: mainthread(self.cancel_selection)() self.was_focused = is_focused super().on_focus(_arg, is_focused)
def _get_defs(source, func, line=None, column=None): error = None try: num_lines = len(source.split('\n')) if line is None: line = num_lines s = Script(source, line=line, column=column) defs = s.goto_definitions() sigs = s.call_signatures() except: print('Exception in defs thread') traceback.print_exc() defs = [] sigs = [] error = 'Could not retrieve docstring' mainthread(WrappablePartial(func, defs, sigs, error=error))()
def _get_completions(source, func, line=None, column=None): try: num_lines = len(source.split('\n')) if line is None: line = num_lines s = Script(source, line=line, column=column) completions = s.completions() # print('### input:') # print(source) # print('### completions:') # print('\n'.join([c.name for c in completions])) except: print('Exception in completions thread') traceback.print_exc() completions = [] mainthread(WrappablePartial(func, [c for c in completions]))()
def __init__(self): super().__init__() self._thread = threading.Thread(target=self._run_loop, daemon=True) self.loop = None # the following are for the pulse() coroutine, see below self._default_pulse = ['tick!', 'tock!'] self._pulse = None self._pulse_task = None self.dispatch = mainthread(self.dispatch)
def __init__(self, runner_callback: Callable, worker_callback: Callable, loop=None, **kwargs): """ Args: runner_callback: Callback for main event loop entry point worker_callback: Callback to process work items loop: Event loop to use (separate from main kivy event loop) """ # Schedule all events to run on the main thread self.dispatch = mainthread(self.dispatch) self.register_event_type('on_progress') self.register_event_type('on_load') self.register_event_type('on_complete') super().__init__(**kwargs) self.loop = loop or get_app().bg_loop self.thread = None self.queues = [] self.worker_tasks = [] self.runner_callback = runner_callback self.worker_callback = worker_callback
def add_widget(self, widget: Widget, parent: Widget): """ Add a ModelListItem to its parent list and bind its click event """ super().add_widget(widget, parent) mainthread(get_app().bind_to_select_model)(widget)