def do_process_queue(self): """Queue processing""" try: while 1: data = self.queue.get_nowait() cmd, args, kw = data do_save = kw.get('save', True) if cmd == 'add_playlist': pl = kw['playlist'] if do_save: DB.playlist_save(pl) try: iid = self.pltree.insert('', tk.END, iid=pl['id'], text=pl['title'], tags='pl') see_func = lambda: self.pltree.see(iid) self.mainwindow.after_idle(see_func) except Exception as e: msg = 'Failed to execute cmd {0}, {1}'.format(cmd, str(args)) logger.warning(msg) logger.debug(str(e)) if cmd == 'add_video': plid = kw['playlist_id'] video = kw['video'] if do_save: DB.video_save(video) DB.playlist_add_video(plid, video['id']) try: iid = self.pltree.insert(plid, tk.END, iid=video['id'], text=video['title'], values=('✖', video['id'],), tags='video') see_func = lambda: self.pltree.see(iid) self.mainwindow.after_idle(see_func) except Exception as e: msg = 'Failed to execute cmd {0}, {1}'.format(cmd, str(args)) logger.warning(msg) if cmd == 'downloading_video': msg = 'Downloading video: {0}'.format(kw['name']) self.task_msg.configure(text=msg) # ✔ if cmd == 'task_start': self.task_msg.configure(text=kw['message']) self.task_progress.configure(mode='indeterminate') self.task_progress.start(20) self.taskdialog.run() if cmd == 'task_stop': self.task_msg.configure(text=kw['message']) self.task_progress.stop() self.task_progress.configure(mode='determinate') self.taskdialog.close() self.mainwindow.update() except queue.Empty: pass self.mainwindow.after(100, self.do_process_queue)