Пример #1
0
def rectangle1(topleft, botright):
    topleft = topleft["value"]
    bottomright = botright["value"]
    if (topleft >= bottomright).all():
        topleft, bottomright = bottomright, topleft
    topright = P(bottomright[0], topleft[1])
    bottomleft = P(topleft[0], bottomright[1])
    newnode = Node("path",
                   skip_points=True,
                   p_topleft=topleft,
                   p_botright=bottomright,
                   p_topright=topright,
                   p_botleft=bottomleft,
                   children=[
                       Node("line",
                            start=Ex("`self.parent.topleft", "reeval"),
                            end=Ex("`self.parent.topright", "reeval")),
                       Node("line",
                            start=Ex("`self.parent.topright", "reeval"),
                            end=Ex("`self.parent.botright", "reeval")),
                       Node("line",
                            start=Ex("`self.parent.botright", "reeval"),
                            end=Ex("`self.parent.botleft", "reeval")),
                       Node("line",
                            start=Ex("`self.parent.botleft", "reeval"),
                            end=Ex("`self.parent.topleft", "reeval")),
                   ])
    return newnode
Пример #2
0
def finished_edit_text():
    node = doc[doc["editor.focus"]]
    text = node["value"]
    if text.startswith("!"):
        node["on_click"] = text[1:]
    elif text.startswith("="):
        node["value"] = Ex(text[1:], calc="reeval")
Пример #3
0
def add_line_start():
    line = Node("line",
                p_start=doc["editor.mouse_txy"],
                p_end=doc["editor.mouse_txy"])
    doc["drawing"].append(Node("path", fill_color=None, children=[line]))
    doc["editor.drag_start"] = doc["editor.mouse_txy"]
    doc["editor.grabbed"] = line[1]["id"]
    line[1].transforms["editor"] = Ex(
        "('translate', `editor.mouse_txy - `editor.drag_start)",
        calc='on first read')
Пример #4
0
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
Пример #5
0
def add_visualize():
    assert (len(doc["selection"]) == 1)
    node = doc["selection.0.ref"]
    pdocument.scope['visualize_cb'] = visualize_cb
    doc['editor.callbacks.visualize'] = Ex('visualize_cb(`%s)' % node['id'])