コード例 #1
0
def add_line_start():
    group = doc[doc['selection.root']][-1]
    line = Node("line",
                start=Ex("`self.parent.%s.end" % (len(group) - 1), "reeval"),
                p_end=doc["editor.mouse_txy"])
    group.append(line)
    doc["editor.drag_start"] = doc["editor.mouse_txy"]
    doc["editor.grabbed"] = line['end.id']
    line['end'].transforms["editor"] = Ex(
        "('translate', `editor.mouse_txy - `editor.drag_start)",
        calc='on first read')
コード例 #2
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
コード例 #3
0
ファイル: slides.py プロジェクト: asrp/maketheseslides
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")
コード例 #4
0
def add_line_group():
    line = Node("line",
                p_start=rounded(doc["editor.mouse_txy"]),
                p_end=doc["editor.mouse_txy"])
    doc[doc['selection.root']].append(Node("path", children=[line]))
    doc["editor.drag_start"] = doc["editor.mouse_txy"]
    doc["editor.grabbed"] = line['end.id']
    line['end'].transforms["editor"] = Ex(
        "('translate', `editor.mouse_txy - `editor.drag_start)",
        calc='on first read')
コード例 #5
0
ファイル: functions.py プロジェクト: abhi-jha/guitktk
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
コード例 #6
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")
    elif text.startswith("@"):
        node["filename"] = text[1:]
        # Child would actually be top left
        #node.L['transforms.move'] = ('translate', node['botleft.value'])
        node.L['botleft.child_id'] = 'topleft'
        node.L.change(name="image")
コード例 #7
0
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
コード例 #8
0
def finished_edit_formula():
    node = doc[doc["formula.node"]]
    text = doc["formula.value"]
    doc["formula.visible"] = False
    if text.startswith("!"):
        node[doc["formula.param"]] = text[1:]
    elif text.startswith("="):
        node["value"] = Ex(text[1:], calc="reeval")
    elif text.startswith("@"):
        node["filename"] = text[1:]
        # Child would actually be top left
        #node.L['transforms.move'] = ('translate', node['botleft.value'])
        node.L['botleft.child_id'] = 'topleft'
        node.L.change(name="image")
コード例 #9
0
ファイル: node.py プロジェクト: asrp/guitktk
 def deepcopy(self):
     params = dict(self.params.set('id', gen_id(self.doc, self["id"])))
     if "transforms" in params:
         transforms = dict(params['transforms'].dict_)
         del params['transforms']
     else:
         transforms = {}
     children = []
     for child in self:
         children.append(child.deepcopy())
         if "child_id" in child:
             #params = params.set(child["child_id"], Ex("`%s_copy" % child["id"]))
             params[child["child_id"]] = Ex("`%s" % children[-1]["id"])
     return Node(self.name,
                 params=params,
                 children=children,
                 transforms=transforms)
コード例 #10
0
def add_visualize():
    assert (len(doc["selection"]) == 1)
    node = doc["selection.0.ref"]
    #visualize_cb(node)
    pdocument.scope['visualize_cb'] = visualize_cb
    doc['editor.callbacks.visualize'] = Ex('visualize_cb(`%s)' % node['id'])
コード例 #11
0
def close_line_group():
    group = doc[doc['selection.root']][-1]
    if (group['-1.end.value'] == group['0.start.value']).all():
        print("Closed line")
        group[-1].remove(group[-1]['end'])
        group['-1.end'] = Ex("`self.parent.0.start", "reeval")
コード例 #12
0
def exc(expr):
    return Ex(expr, "on first read")
コード例 #13
0
def exr(expr):
    return Ex(expr, "reeval")
コード例 #14
0
ファイル: node.py プロジェクト: asrp/guitktk
    def __new__(cls,
                name=None,
                params=None,
                children=(),
                doc=None,
                parent=None,
                _parent=None,
                **kwargs):
        global node_num
        doc = doc if doc is not None else pdocument.default_doc
        params = kwargs if params is None else params
        children = list(children)
        if type(params) == map_type:
            params = params.evolver()
        if "id" not in params:
            params["id"] = "n_%s" % node_num
            node_num += 1
        if "child_id" in params and params["child_id"] is None:
            del params["child_id"]
        for key, value in kwargs.items():
            if key.startswith("p_"):
                children.append(Node("point", child_id=key[2:], value=value))
                del kwargs[key]
                params[key[2:]] = Ex("`%s" % children[-1]["id"], "reeval")
            elif key.startswith("px_"):
                # bp()
                child_id = key[3:]
                children.append(Node("point", child_id=child_id, value=value))
                del kwargs[key]
                params[child_id] = Ex("`%s" % children[-1]["id"],
                                      "on first read")
            elif key.startswith("r_"):
                raise Exception(
                    "ref nodes are depricated! Use expressions with a single id instead."
                )
            elif key == "transform":
                # Should not have both transform and transforms.
                params["transforms"] = TransformDict(
                    dict_={"singleton": value}, node=params["id"], doc=doc)
                del kwargs["transform"]
            elif key == "transforms":
                if type(value) not in [map_type, Ex]:
                    params["transforms"] = TransformDict(dict_=value,
                                                         node=params["id"],
                                                         doc=doc)
        if "transforms" not in params:
            params["transforms"] = TransformDict(node=params["id"],
                                                 dict_={},
                                                 doc=doc)
        # Had problem where this overwrote value passed by param!
        # Need to know if "children" is the intended change or
        # params is the intended change!
        # Setting to "params overwrites children" for now.
        # NO, there are bigger problems with children not synced to the
        # new param values
        # Could use the latest one of the two if we had timestamps

        # General problem: This loop is called at modification instead of
        # only at initialization
        # Should decide on the semantics of appending a node with
        # child_id (or removing one with child_id) means for params
        # anyways.
        for child_id in children:
            child = get_eval(child_id)
            if "child_id" in child and child["child_id"] not in params:
                # Want the wrapped version of the child!
                # params[child["child_id"]] = child
                params[child["child_id"]] = wrap_children(
                    params["id"], doc, [child])[0]
        if type(params).__name__ == '_Evolver':
            params = params.persistent()
        return FrozenNode.__new__(cls,
                                  name=name,
                                  params=params,
                                  children=children,
                                  doc=doc,
                                  parent=parent,
                                  _parent=_parent)