def cb_indicator(n, msg): global Indicates item = Indicates[n] if msg.data: timeout.set(functools.partial(cb_turnon, n), 0) else: if "sto" in item: timeout.clear(item["sto"]) timeout.set(functools.partial(cb_turnoff, n), 0)
def cb_edit_stat(msg): global statcheck flg = not msg.data if statcheck: timeout.clear(statcheck) statcheck = 0 if msg.data: if "stat_timeout" in Config: statcheck = timeout.set(cb_button_normal, Config["stat_timeout"]) if check_button_chenge(flg): timeout.set(functools.partial(cb_button_enable, flg), 0)
def cb_display(n): global Displays item = Displays[n] widget = item["tag"] val = item["label"] try: val_name = str(rospy.get_param(item["name"])) if val_name == "": val_name = '---' val += val_name except Exception: val += '---' if val != widget["text"]: widget.configure(text=val) n = n + 1 if n >= len(Displays): n = 0 timeout.set(functools.partial(cb_display, n), 0.5)
def cb_turnon(n): global Indicates item = Indicates[n] item["tag"]["foreground"] = litcolor item["tag"]["font"] = boldfont if "sto" in item: timeout.clear(item["sto"]) item["sto"] = timeout.set(functools.partial(cb_turnoff, n), item["timeout"])
def cb_load(msg): global Param, RecipeName if wRecipe is None: return Param["recipe"] = msg.data recipe = msg.data.split(':') RecipeName = recipe[0] timeout.set(functools.partial(cb_wRecipe, Param["recipe"]), 0) if os.system("ls " + dirpath + "/" + RecipeName) == 0: set_param_sync("/dashboard", Param) commands.getoutput("rm " + linkpath) commands.getoutput("ln -s " + dirpath + "/" + RecipeName + " " + linkpath) commands.getoutput("rosparam load " + linkpath + "/param.yaml") if len(recipe) > 1: commands.getoutput("rosparam load " + linkpath + "/" + str(recipe[1]) + ".yaml") pub_Y3.publish(mTrue) else: pub_E3.publish(mFalse)
def cb_button_enable(n, enable): if enable: item["button"]['state'] = tk.NORMAL item["button"]["background"] = litcolor if "sto" in item: timeout.clear(item["sto"]) item["sto"] = timeout.set( functools.partial(cb_button_enable, n, False), item["timeout"]) else: item["button"]['state'] = tk.DISABLED item["button"]["background"] = maskcolor if "sto" in item: item.pop("sto")
def cb_runstat(n): global Launches item = Launches[n] if item["state"] == 1: item["state"] = 2 timeout.set(functools.partial(cb_runstat, n), 1) elif item["state"] == 2: if item["process"].poll() is None: timeout.set(functools.partial(cb_runstat, n), 1) else: item["state"] = 3 timeout.set(functools.partial(cb_stop, n), 0)
def cb_mbox_push(n, msg): if n == 0: timeout.set(functools.partial(mbox.push, msg), 0) else: timeout.set(functools.partial(ebox.push, msg), 0)
def cb_butt_enable(n, msg): timeout.set(functools.partial(cb_button_enable, n, msg.data), 0)
def cb_redraw(): timeout.set(lambda: pub_redraw.publish(mTrue), 0)
def cb_run(n): global Launches, msgBox, msgBoxWait if msgBoxWait is not None: return item = Launches[n] if item["state"] == 0: fg = True if "pass" in item: fg = False alert = "" w = item["tag"] msgBox = tk.Toplevel() geom = "300x130+" + str( w.winfo_rootx()) + "+" + str(w.winfo_rooty() + 25) msgBox.geometry(geom) msgBoxWait = msgBox.after(1000, cb_wait_nop) msg = "Enter password" result = pymsgbox.password(root=msgBox, text=msg, geom=geom) if result[0].startswith('O'): #OK if result[1] == Config["password"]: fg = True else: alert = "password is incorrect" elif not result[0].startswith("C"): #Cancel alert = "enter password error" if alert: msgBox.after_cancel(msgBoxWait) msgBox.destroy() msgBox = tk.Toplevel() msgBox.geometry("250x100+" + str(w.winfo_rootx()) + "+" + str(w.winfo_rooty())) msgBoxWait = msgBox.after(500, cb_lift) pymsgbox.alert(root=msgBox, text=alert) msgBox.after_cancel(msgBoxWait) msgBoxWait = None msgBox.destroy() if fg: if ".launch" in item["file"]: cmd = ["roslaunch", item["package"], item["file"]] else: cmd = ["xterm", "-e", "rosrun", item["package"], item["file"]] if "args" in item: for k in item["args"]: cmd.append(k + ":=" + str(item["args"][k])) proc = subprocess.Popen(cmd) item["tag"]["foreground"] = litcolor item["tag"]["font"] = boldfont item["button"]["image"] = stopicon item["process"] = proc item["state"] = 1 timeout.set(functools.partial(cb_runstat, n), 3) if "pre" in item: print "dash pre", item["pre"] subprocess.Popen(item["pre"].split()) elif item["state"] == 2: if "confirm" in item: if item["confirm"]: w = item["tag"] msgBox = tk.Toplevel() msgBox.geometry("250x100+" + str(w.winfo_rootx()) + "+" + str(w.winfo_rooty())) msgBoxWait = msgBox.after(500, cb_lift) msg = item["label"] + Config["confirm"] if "message" in Config: if "halt" in Config["message"]: msg = Config["message"]["halt"] elif "launch" in Config["message"]: msg = Config["message"]["launch"] elif "label" in Config: if "confirm" in Config["label"]: msg = Config["label"]["confirm"] msg = item["label"] + msg f = pymsgbox.confirm(root=msgBox, text=msg, buttons=['OK', 'CANCEL']) msgBox.after_cancel(msgBoxWait) msgBoxWait = None msgBox.destroy() if f.startswith("C"): #Cancel return item["process"].terminate() item["state"] = 3 timeout.set(functools.partial(cb_stop, n), 1)
background=maskcolor, foreground=unlitcolor) wlabel.pack(side='left', fill='y', anchor='w') wbtn = tk.Button(root, image=starticon, background=bgcolor, bd=0, highlightthickness=0, command=functools.partial(cb_run, n)) wbtn.pack(side='left', fill='y', anchor='w', padx=(0, 10)) item["tag"] = wlabel item["button"] = wbtn item["state"] = 0 if "auto" in item: if item["auto"] >= 0: timeout.set(functools.partial(cb_run, n), item["auto"]) Launches.append(item) tk.Button(root, image=redrawicon, bd=0, background=bgcolor, highlightthickness=0, command=cb_redraw).pack(side='right', anchor='nw', padx=(0, 0)) #ckeys.sort(reverse=True) for key in ckeys: if key.startswith('indic'): item = Config[key] n = len(Indicates) wlabel = tk.Label(root, text=item["label"],
def cb_report(s): ss = s.data[-1:-1] dic = eval(s.data) timeout.set(functools.partial(to_report, dic), 0)
def cb_update(s): timeout.set(to_update, 0)