def waiter(Iconobject, stdout): for line in stdout: # this is executed, each time we receive a message from YAD for i in Iconobject.items: if line == i[0] + "\n": # print("execute: "+str(i[1])) launch.thread(i[1]) if Iconobject.left_click: Iconobject.left_click()
def start(self): self.child_process = self.adaptor.start(self) if self.couple: self.couple_process = launch.CoupleProcess(self.child_process) if self.queue is not None: if not isinstance(self.queue, multiprocessing.queues.Queue): raise ValueError # this happens if the start method defined a corresponding # queue object launch.thread(self.run_menu_funcs, initial_time_delay=1)
def run_menu_funcs(self): while self.child_process.is_running(): obj = self.queue.get() if isinstance(obj, int): func = self.items[obj][1] elif isinstance(obj, str): print(obj) for i in self.items: if obj == i[0]: # print("execute: "+str(i[1])) func = i[1] else: raise TypeError launch.thread(func)
def event(self, k): #print(k) self.recent_events.append(k) if len(self.recent_events) > self.buffer: self.recent_events.popleft() recent_events = self.recent_events.copy() for event,action in self.eventdict.items(): members = event.members for i in range(1,min(len(members),len(recent_events))+1): #_print(i, recent_events) if members[-i] != recent_events[-i]: break else: launch.thread(self.runscript, action, event) # this means that for each member event, the suiting recent # event has been found self.recent_events.clear()
def start(self, *args, wait=None, **kwargs): if self.active: raise RuntimeError("TimedObject %s cannot be started as it " "is already active." % str(self)) self.active = True ret = self._start_action(*args, **kwargs) if self.measure_duration: self.starttime = time.time() if self.timeout: self._timeout_thread = launch.thread( self._timeout_stop, initial_time_delay=self.timeout) self.start_flag.set() self.start_flag.clear() if wait is None and self.wait or wait is True: self.join() if ret is None: ret = self #usually the case return ret
def edit(self, wait=False, keep_timestamps=True): if self.locked: raise RuntimeError(f"ExternalDict {self} already " f"opened for editing") self.locked = True editable = dict() num = 0 for profile in self.profiles: dic = self.load_profile(profile) if not dic: dic = self._default_profile_dic.copy() k = f"PROFILE {num} -- '{profile}'" editable[k] = dic num += 1 editable[f"EXTERNAL OBJECT '{self.name}'"] = { "basefolder": self.basefolder, } after_thread = launch.thread(self.after_edit, editable, keep_timestamps) if wait: after_thread.join() return after_thread
def set_temp_store_key(self, keyname, value, timeout=60 * 30): self.store[keyname] = value if timeout: launch.thread(self.remove_temp_store_key, keyname, timeout)
def unblock(cls, delay=None): if delay: launch.thread(cls._unblock, initial_time_delay=delay) else: cls._unblock()
def start(IconObject): cmd = tuple(create_yad_cmd(IconObject)) #print(cmd) child = launch(cmd, stdout=True) launch.thread(waiter, IconObject, child.stdout) return child.pid