示例#1
0
    def _link_callback(sender, app_data, user_data):
        output_attr_uuid, input_attr_uuid = app_data

        input_attr = dpg.get_item_user_data(input_attr_uuid)
        output_attr = dpg.get_item_user_data(output_attr_uuid)

        output_attr.add_child(sender, input_attr)
示例#2
0
def disconnect(a, b):
    sender_node = dpg.get_item_parent(a)
    sender_class = dpg.get_item_user_data(sender_node)
    receiver_node = dpg.get_item_parent(b)
    receiver_class = dpg.get_item_user_data(receiver_node)

    # search attribute
    for attr in vars(receiver_class):
        if len(attr) > len('_id') and attr.endswith('_id') and b == getattr(
                receiver_class, attr):
            setattr(receiver_class, attr[:-3], None)
            receiver_class.update()

    sender_class.disconnect_output(receiver_node)
示例#3
0
    def submit(self, parent):

        with dpg.node_editor(parent=parent, id=self.uuid, user_data=self, callback=NodeEditor._link_callback,
                             width=-160, height=-1, drop_callback=lambda s, a, u: dpg.get_item_user_data(s).on_drop(s, a, u)):

            for node in self._nodes:
                node.submit(self.uuid)
示例#4
0
def on_link(sender, link):
    """
    When a link is created it is stored as a topic_out in the node with the output and as a topic_in in the
    node with the input
    :param sender: The node editor (not used)
    :param link: The link list
    :return: Nothing
    """
    global links_dict

    link0_name = dpg.get_item_label(link[0])
    link1_name = dpg.get_item_label(link[1])

    if link0_name in links_dict:
        inputs = links_dict[link0_name]
        if link1_name not in links_dict[link0_name]:
            inputs.append(link1_name)
    else:
        inputs = [link1_name]

    link_id = dpg.add_node_link(link[0], link[1], parent=sender, user_data={})

    links_dict[link0_name] = inputs

    output_node_label = dpg.get_item_label(link[0])
    input_node_label = dpg.get_item_label(link[1])
    output_node = output_node_label.split('##')[-2] + '##' + output_node_label.split('##')[-1]
    input_node = input_node_label.split('##')[-2] + '##' + input_node_label.split('##')[-1]
    for n in nodes_list:
        if output_node == n.name:
            topic_out = '{}->{}'.format(output_node_label, input_node_label)
            n.add_topic_out(topic_out)
            n.links_list.append(link_id)
            user_data = dpg.get_item_user_data(link_id)
            user_data['topic_out'] = topic_out
            user_data['node_id_out'] = n.id
            dpg.set_item_user_data(link_id, user_data)
        if input_node == n.name:
            topic_in = '{}->{}'.format(output_node_label, input_node_label)
            n.add_topic_in(topic_in)
            n.links_list.append(link_id)
            user_data = dpg.get_item_user_data(link_id)
            user_data['topic_in'] = topic_in
            user_data['node_id_in'] = n.id
            dpg.set_item_user_data(link_id, user_data)
示例#5
0
def add_distance(parent):
    pid = dpg.generate_uuid()
    with dpg.node(label="Distance A to B",
                  pos=[10, 10],
                  parent=parent,
                  user_data=DistanceNode(pid),
                  id=pid):
        _add_inputs_and_outputs(dpg.get_item_user_data(pid),
                                node_layouts[DistanceNode])
示例#6
0
def add_current_price(parent):
    pid = dpg.generate_uuid()
    with dpg.node(label="Current Price",
                  pos=[10, 10],
                  parent=parent,
                  user_data=CurrentPriceNode(pid),
                  id=pid):
        _add_inputs_and_outputs(dpg.get_item_user_data(pid),
                                node_layouts[CurrentPriceNode])
示例#7
0
def connect(a, b):
    global node_connections

    sender_node = dpg.get_item_parent(a)
    sender_class = dpg.get_item_user_data(sender_node)
    receiver_node = dpg.get_item_parent(b)
    receiver_class = dpg.get_item_user_data(receiver_node)

    # check
    a_key = (type(sender_class), dpg.get_item_label(a))
    b_key = (type(receiver_class), dpg.get_item_label(b))

    if a_key in node_connections and b_key in node_connections[a_key]:
        setattr(receiver_class, dpg.get_item_label(b), sender_class)
        sender_class.connect_output(receiver_node)
        receiver_class.update()
        return True

    return False
示例#8
0
def add_dealer(parent, dealer):
    pid = dpg.generate_uuid()
    with dpg.node(label="Dealer",
                  pos=[10, 10],
                  parent=parent,
                  user_data=DealerNode(pid, dealer),
                  id=pid):
        with dpg.node_attribute(attribute_type=dpg.mvNode_Attr_Static):
            dpg.add_text('BINANCE')
        _add_inputs_and_outputs(dpg.get_item_user_data(pid),
                                node_layouts[DealerNode])
示例#9
0
def add_symbol(parent):
    pid = dpg.generate_uuid()
    with dpg.node(label="Symbol",
                  pos=[10, 10],
                  parent=parent,
                  user_data=SymbolNode(pid),
                  id=pid):
        with dpg.node_attribute(label='symbol',
                                attribute_type=dpg.mvNode_Attr_Output):
            dpg.add_combo(('BTC', 'ETH'),
                          default_value='BTC',
                          callback=lambda s, a: dpg.get_item_user_data(pid).
                          update_symbol(a),
                          width=100)
示例#10
0
def add_rlines(parent):
    pid = dpg.generate_uuid()
    with dpg.node(label="Resistance Lines",
                  pos=[10, 10],
                  parent=parent,
                  user_data=ResistanceLinesNode(pid),
                  id=pid):
        _add_inputs_and_outputs(dpg.get_item_user_data(pid),
                                node_layouts[ResistanceLinesNode])
        with dpg.node_attribute(attribute_type=dpg.mvNode_Attr_Static):
            dpg.add_slider_float(label='threshold',
                                 default_value=2,
                                 min_value=0.1,
                                 max_value=5,
                                 callback=lambda s, a, u: dpg.
                                 get_item_user_data(pid).update_threshold(a),
                                 width=50)
            dpg.add_slider_int(label='min strength',
                               default_value=0,
                               min_value=0,
                               max_value=50,
                               callback=lambda s, a, u: dpg.get_item_user_data(
                                   pid).update_min_strength(a),
                               width=50)
示例#11
0
def add_rolling_mean(parent):
    pid = dpg.generate_uuid()
    with dpg.node(label="Rolling Mean",
                  pos=[10, 10],
                  parent=parent,
                  user_data=RollingMeanNode(pid),
                  id=pid):
        _add_inputs_and_outputs(dpg.get_item_user_data(pid),
                                node_layouts[RollingMeanNode])
        with dpg.node_attribute(attribute_type=dpg.mvNode_Attr_Static):
            dpg.add_combo(('SMA', 'EMA'),
                          label='type',
                          default_value='SMA',
                          user_data=pid,
                          callback=lambda s, a, u: dpg.get_item_user_data(pid).
                          update_type(a),
                          width=50)
            dpg.add_slider_int(label='window size',
                               default_value=7,
                               min_value=3,
                               max_value=200,
                               callback=lambda s, a, u: dpg.get_item_user_data(
                                   pid).update_window_size(a),
                               width=50)
示例#12
0
def add_history(parent):
    pid = dpg.generate_uuid()
    with dpg.node(label="History",
                  pos=[10, 10],
                  parent=parent,
                  user_data=HistoryNode(pid),
                  id=pid):
        _add_inputs_and_outputs(dpg.get_item_user_data(pid),
                                node_layouts[HistoryNode])
        with dpg.node_attribute(attribute_type=dpg.mvNode_Attr_Static):
            dpg.add_combo(('1y', '6m', '1m', '1w', '1d'),
                          label='period',
                          default_value='1w',
                          user_data=pid,
                          callback=lambda s, a, u: dpg.get_item_user_data(pid).
                          update_period(a),
                          width=50)
            dpg.add_combo(('1d', '1h', '30m', '15m'),
                          label='interval',
                          default_value='1h',
                          user_data=pid,
                          callback=lambda s, a, u: dpg.get_item_user_data(pid).
                          update_interval(a),
                          width=50)
示例#13
0
文件: main.py 项目: filipecn/maldives
def _delink_node(sender, app_data, user_data):
    nodes.disconnect(dpg.get_item_user_data(app_data)[0], dpg.get_item_user_data(app_data)[1])
    dpg.delete_item(app_data)
示例#14
0
 def update(self):
     if self.update_internal():
         for i in self.output_node_ids:
             dpg.get_item_user_data(i).update()