def run_button(mod=None): root = doc[doc["selection.root"]] txy = doc["editor.mouse_txy"] cui = doc['custom_ui'] if default_get(doc['custom_ui'], 'visible') else [] more = [] for child in chain(cui, reversed(root)): if collide(child, txy): print "clicked on", child["id"], "on_click" in child, mod if "on_click" in child and not mod: run_text(child["id"], "on_click") elif "on_shift_click" in child and mod == "shift": run_text(child["id"], "on_shift_click") elif child.get("button_group"): # Wrong. Should test children right away in reverse order. more.extend([(gc, child.transform) for gc in child]) print "Button group", len(more) #[n['id'] for n in more] continue return True # TODO: refactor for child, transform in more: if collide(child, txy, transform=transform): print "clicked on", child["id"], "on_click" in child, mod if "on_click" in child and not mod: run_text(child["id"], "on_click") elif "on_shift_click" in child and mod == "shift": run_text(child["id"], "on_shift_click") elif child.get("button_group"): more.extend([(gc, child.transform) for gc in child]) print "Button group", [n['id'] for n in more] continue return True return False
def edit_text(): root = doc[doc["selection.root"]] for child, transform in root.dfs(): if child.name == "text" and\ collide(child, doc["editor.mouse_xy"], transform=transform, tolerance=8): doc["editor.focus"] = child["id"] return True return False
def gui_select(): root = doc[doc["selection"]["root"]] xy = doc["editor.mouse_xy"] for child, transform in root.dfs(): if child.name not in ["group", "path"] and\ collide(child, xy, transform=transform, tolerance=8): print "gui elem selected", child["id"] doc["editor.gui_selected"] = exr("`%s" % child["id"]) break
def edit_text(): root = doc[doc["selection.root"]] for child, transform in root.dfs(): # Problem: dfs includes child's transform and so does bbox. if child.name == "text" and\ collide(child, doc["editor.mouse_xy"], transform=transform, tolerance=8): doc["editor.focus"] = child["id"] return True return False
def run_button(): root = doc[doc["selection.root"]] txy = doc["editor.mouse_txy"] for child in reversed(root): if collide(child, txy): print "clicked on", child["id"] if "on_click" in child: run_text(child["id"], "on_click") return True return False
def toggle_selection(): root = doc[doc["selection"]["root"]] txy = doc["editor.mouse_txy"] for child in reversed(root): if collide(child, txy): print "clicked on", child["id"] if child["id"] in doc["editor.selected"]: selection_del(doc, child) else: selection_add(doc, child) break
def run_button(): root = doc[doc["selection.root"]] txy = doc["editor.mouse_txy"] cui = doc['custom_ui'] if default_get(doc['custom_ui'], 'visible') else [] for child in chain(cui, reversed(root)): if collide(child, txy): print "clicked on", child["id"], "on_click" in child if "on_click" in child: run_text(child["id"], "on_click") return True return False
def grab_point(): root = doc[doc["selection"]["root"]] for child, transform in root.dfs(): if child.name == "point" and\ collide(child, doc["editor.mouse_xy"], transform=transform, tolerance=8): doc["editor.drag_start"] = doc["editor.mouse_txy"] doc["editor.grabbed"] = child["id"] child.transforms["editor"] = Ex( "('translate', `editor.mouse_txy - `editor.drag_start)", calc='on first read') return True return False
def toggle_selection(): root = doc[doc["selection"]["root"]] # Assumes root.combined_transform().dot(root.transform) is the identity. txy = doc["editor.mouse_txy"] for child in reversed(root): if collide(child, txy): print "clicked on", child["id"] if child["id"] in doc["editor.selected"]: selection_del(doc, child) else: selection_add(doc, child) break
def rectangle_lasso(): root = doc[doc["selection"]["root"]] txy = doc["editor.mouse_txy"] for rect in reversed(root): if collide(rect, txy): topleft, botright = rect.bbox() for child in reversed(root): topleft2, botright2 = child.bbox() if child['id'] != rect['id'] and (topleft <= topleft2).all( ) and (botright2 <= botright).all(): if child["id"] not in doc["editor.selected"]: selection_add(doc, child) break
def grab_point(): root = doc[doc["selection.root"]] cui = doc['custom_ui'].dfs() if default_get(doc['custom_ui'], 'visible') else [] for child, transform in chain(root.dfs(), cui): if child.name == "point" and\ collide(child, doc["editor.mouse_txy"], transform=transform, tolerance=8): doc["editor.drag_start"] = doc["editor.mouse_txy"] doc["editor.grabbed"] = child["id"] child.transforms["editor"] = Ex( "('translate', `editor.mouse_txy - `editor.drag_start)", calc='on first read') return True return False
def toggle_selection(): root = doc[doc["selection"]["root"]] # Assumes root.combined_transform().dot(root.transform) is the identity. txy = doc["editor.mouse_txy"] # Otherwise, use the alternative below. #_txy = doc["editor.mouse_txy"] #transform = numpy.linalg.inv(root.combined_transform().dot(root.transform)) #txy = transformed(Node("point", value=_txy), transform) for child in reversed(root): if collide(child, txy): print "clicked on", child["id"] if child["id"] in doc["editor.selected"]: selection_del(doc, child) else: selection_add(doc, child) break
def rectangle_lasso_points(): root = doc[doc["selection.root"]] cui = doc['custom_ui'].dfs() if default_get(doc['custom_ui'], 'visible') else [] root = doc[doc["selection"]["root"]] txy = doc["editor.mouse_txy"] for rect in reversed(root): if collide(rect, txy): topleft, botright = rect.bbox() print("Found rect", topleft, botright) for child, transform in chain(root.dfs(), cui): if child.name == "point" and\ (topleft <= child['value']).all() and\ (child['value'] <= botright).all(): if child["id"] not in doc["editor.selected"]: selection_add(doc, child) break