def for_delay_loop(): if delay and not self._mutex('DELAY'): model_gate.exception_data.set_data("已经存在延迟任务\n如需重置,请先点击'停止'") return if loop and not self._mutex('LOOP'): model_gate.exception_data.set_data("已经存在循环任务\n如需重置,请先点击'停止'") return if delay: start_time = Common.time() while True: if self.is_break: return Common.sleep(1) left_sec = delay * 60 - int(Common.time() - start_time) left_sec = 0 if left_sec < 0 else left_sec model_gate.delay_loop_timer_data.set_data( [left_sec, left_sec]) if left_sec == 0: self._mutex('DELAY', False) break _execute_now() if loop: start_time = Common.time() while True: if self.is_break: return Common.sleep(1) left_sec = loop * 60 - int(Common.time() - start_time) left_sec = 0 if left_sec < 0 else left_sec model_gate.delay_loop_timer_data.set_data([0, left_sec]) if left_sec == 0: _execute_now() start_time = Common.time()
def onLeftButtonUp(event): self.sel = False deleteLastDraw() Common.sleep(0.1) # 考虑鼠标左键从右下方按下而从左上方抬起的截图 left, right = sorted([self.X.get(), event.x]) top, bottom = sorted([self.Y.get(), event.y]) pic = ImageGrab.grab((left+1, top+1, right, bottom)) save_name = "ScreenShot-{0}.png".format(Common.get_time(format=False)) pic.save(save_name) self.top.destroy() Common.remove(self.temp_png) WidgetTip.info("截图成功: {0}\n截图保存在工具家目录下".format(save_name))
def check_result(self, ssh, ip, offset): progress_cmd = "{0} get_task_progress {1}".format( self.inner_caller, self.task) print_cmd = "{0} get_task_stdout {1}".format(self.inner_caller, self.task) progress, last, retry, result = 0, 0, 1, "" timeout, consume, period = 10, 0, 0.5 while True: Common.sleep(period) try: result = self.execute_out(ssh, progress_cmd) if not result: if consume > timeout: raise Exception("Timeout for result") consume += period continue progress, status, info = result.split('|') progress = int(int(progress) * (1 - offset / 100) + offset) result = self.execute_out(ssh, print_cmd) if status == 'FAILED': raise Exception(info) self.return_exec_start_result(ip, progress, result, True) if last == progress: continue last = progress self.insert_text_info(ip, progress, info) if progress == 100: if not self.download_file(ssh, ip, info): raise Exception("Download {} failed !".format(info)) break except Exception as e: retry += 1 if retry < model_gate.settings_data.retry_times: continue if not isinstance(progress, int): progress = 2 self.return_exec_start_result(ip, progress, result, False) self.insert_text_info(ip, progress, "{}, retry:{}".format(str(e), retry), 'ERROR') break
def update_thread(): while not is_done: self.return_exec_start_result(ip, get_progress(), '', True) Common.sleep(0.2)