Пример #1
0
def _add_inputs_and_outputs(obj, layout: {}):
    for attr in layout['inputs']:
        with dpg.node_attribute(label=attr[0],
                                attribute_type=dpg.mvNode_Attr_Input):
            setattr(obj, attr[0] + '_id', dpg.last_item())
            dpg.add_text(attr[1])
    for attr in layout['outputs']:
        with dpg.node_attribute(label=attr[0],
                                attribute_type=dpg.mvNode_Attr_Output):
            dpg.add_text(attr[1])
Пример #2
0
    def submit(self, parent):

        with dpg.node(parent=parent, label=self.label, id=self.uuid):

            with dpg.node_attribute(attribute_type=dpg.mvNode_Attr_Static):
                dpg.add_button(label="Execute", user_data=self, callback=lambda s, a, u: u.execute())

            for attribute in self._input_attributes:
                attribute.submit(self.uuid)

            with dpg.node_attribute(parent=self.uuid, attribute_type=dpg.mvNode_Attr_Static,
                                    user_data=self, id=self.static_uuid):
                self.custom()

            for attribute in self._output_attributes:
                attribute.submit(self.uuid)
Пример #3
0
    def create_ui_node(self, parent):

        y = IncludeNode.levels[self.level]
        IncludeNode.levels[self.level] += 80

        with dpg.node(label=self.name, pos=(250*self.level, y), parent=editor_id):
            if self.level > 0:
                with dpg.node_attribute(label=self.name + "-in") as node_from_id:
                    dpg.add_text("from")
            if len(self.links) > 0:
                with dpg.node_attribute(label=self.name + "-out", attribute_type=dpg.mvNode_Attr_Output) as node_out_id:
                    dpg.add_text("Includes:")

            if parent != 0:
                dpg.add_node_link(parent, node_from_id, parent=editor_id)

        for i in range(0, len(self.links)):
            self.links[i].create_ui_node(node_out_id)
Пример #4
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])
Пример #5
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)
Пример #6
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)
Пример #7
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)
Пример #8
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)
Пример #9
0
    def submit(self, parent):

        with dpg.node_attribute(parent=parent, attribute_type=dpg.mvNode_Attr_Output,
                                user_data=self, id=self.uuid):
            dpg.add_text(self._label)
Пример #10
0
    def submit(self, parent):

        with dpg.node_attribute(parent=parent, user_data=self, id=self.uuid):
            dpg.add_text(self._label)
Пример #11
0
    def extra_input_window(self):
        attr = 'Extra_Input'
        attribute_name = attr + '##{}##{}'.format(self.operation.name,
                                                  self.node_index)
        with dpg.node_attribute(
                label=attribute_name,
                parent=self.id,
                attribute_type=dpg.mvNode_Attr_Static) as attr_id:

            image_file = os.path.join(
                os.path.dirname(os.path.realpath(__file__)), os.path.pardir,
                'resources', 'Blue_glass_button_square_34x34.png')

            width, height, channels, data = dpg.load_image(image_file)

            with dpg.texture_registry():
                texture_id = dpg.add_static_texture(width, height, data)

            image_button = dpg.add_image_button(
                texture_tag=texture_id,
                label='##' + attr +
                ' Name{}##{}'.format(self.operation.name, self.node_index),
                callback=self.update_ssh_combo_boxes)

            with dpg.window(
                    label='##Window#Extra input##{}##{}'.format(
                        self.operation.name, self.node_index),
                    width=450,
                    height=250,
                    pos=[self.coordinates[0] + 400, self.coordinates[1] + 200],
                    show=False,
                    popup=True) as self.extra_window_id:

                # Add the local ssh input
                dpg.add_spacer(height=10)

                with dpg.group(horizontal=True):
                    dpg.add_spacer(width=10)
                    dpg.add_text('SSH local server')
                    dpg.add_spacer(width=80)
                    dpg.add_text('SSH remote server')

                with dpg.group(horizontal=True):
                    dpg.add_spacer(width=10)
                    id = dpg.add_combo(
                        label='##SSH local server##Extra input##{}##{}'.format(
                            self.operation.name, self.node_index),
                        items=self.ssh_server_id_and_names,
                        width=140,
                        default_value=self.ssh_local_server,
                        callback=self.assign_local_server)
                    self.parameter_inputs_ids['SSH local server'] = id
                    dpg.add_spacer(width=40)
                    id = dpg.add_combo(
                        label='##SSH remote server ##Extra input##{}##{}'.
                        format(self.operation.name, self.node_index),
                        items=self.ssh_server_id_and_names,
                        width=140,
                        default_value=self.ssh_remote_server,
                        callback=self.assign_remote_server)
                    self.parameter_inputs_ids['SSH remote server'] = id

                dpg.add_spacer(height=10)
                with dpg.group(horizontal=True):
                    dpg.add_spacer(width=10)
                    dpg.add_text(
                        'Python script of worker process OR Python.exe and script:'
                    )

                with dpg.group(horizontal=True):
                    dpg.add_spacer(width=10)
                    dpg.add_input_text(
                        label='##Worker executable##Extra input##{}##{}'.
                        format(self.operation.name, self.node_index),
                        width=400,
                        default_value=self.worker_executable,
                        callback=self.assign_worker_executable)

                # Add the verbocity input
                dpg.add_spacer(height=6)
                with dpg.group(horizontal=True):
                    dpg.add_spacer(width=10)
                    attr = 'Log file or Verbosity level:'
                    attribute_name = attr + '##{}##{}'.format(
                        self.operation.name, self.node_index)
                    self.verbosity_id = dpg.add_text(
                        label='##' + attr + ' Name{}##{}'.format(
                            self.operation.name, self.node_index),
                        default_value=attr)
                with dpg.group(horizontal=True):
                    dpg.add_spacer(width=10)
                    dpg.add_input_text(
                        label='##{}'.format(attribute_name),
                        default_value=self.com_verbosity,
                        callback=self.update_verbosity,
                        width=400,
                        hint='Log file name or verbosity level integer.',
                        tag='verb#{}#{}'.format(self.operation.name,
                                                self.node_index))

                if importlib.util.find_spec('reliquery') is not None:
                    # Create the relic input only if reliquery is present
                    with dpg.group(horizontal=True):
                        dpg.add_spacer(width=10)
                        dpg.add_text(default_value='Save Relic to directory:')

                    with dpg.group(horizontal=True):
                        dpg.add_spacer(width=10)
                        dpg.add_input_text(
                            default_value=self.relic_verbosity,
                            callback=self.update_verbosity,
                            hint=
                            'The path where the Relic for this worker process will be saved',
                            tag='relic#{}#{}'.format(self.operation.name,
                                                     self.node_index))
Пример #12
0
    def spawn_node_on_editor(self):
        self.context = zmq.Context()
        self.initialise_parameters_socket()

        with dpg.node(label=self.name,
                      parent=self.parent,
                      pos=[self.coordinates[0],
                           self.coordinates[1]]) as self.id:
            colour = choose_color_according_to_operations_type(
                self.operation.parent_dir)
            with dpg.theme() as self.theme_id:
                with dpg.theme_component(0):
                    dpg.add_theme_color(dpg.mvNodeCol_TitleBar,
                                        colour,
                                        category=dpg.mvThemeCat_Nodes)
                    dpg.add_theme_color(dpg.mvNodeCol_TitleBarSelected,
                                        colour,
                                        category=dpg.mvThemeCat_Nodes)
                    dpg.add_theme_color(dpg.mvNodeCol_TitleBarHovered,
                                        colour,
                                        category=dpg.mvThemeCat_Nodes)
                    dpg.add_theme_color(dpg.mvNodeCol_NodeBackgroundSelected,
                                        [120, 120, 120, 255],
                                        category=dpg.mvThemeCat_Nodes)
                    dpg.add_theme_color(dpg.mvNodeCol_NodeBackground,
                                        [70, 70, 70, 255],
                                        category=dpg.mvThemeCat_Nodes)
                    dpg.add_theme_color(dpg.mvNodeCol_NodeBackgroundHovered,
                                        [80, 80, 80, 255],
                                        category=dpg.mvThemeCat_Nodes)
                    dpg.add_theme_color(dpg.mvNodeCol_NodeOutline,
                                        [50, 50, 50, 255],
                                        category=dpg.mvThemeCat_Nodes)
                    dpg.add_theme_style(dpg.mvNodeStyleVar_NodeBorderThickness,
                                        x=4,
                                        category=dpg.mvThemeCat_Nodes)
            dpg.bind_item_theme(self.id, self.theme_id)

            # Loop through all the attributes defined in the operation (as seen in the *_com.py file) and put them on
            # the node
            same_line_widget_ids = []
            for i, attr in enumerate(self.operation.attributes):

                if self.operation.attribute_types[i] == 'Input':
                    attribute_type = dpg.mvNode_Attr_Input
                elif self.operation.attribute_types[i] == 'Output':
                    attribute_type = dpg.mvNode_Attr_Output
                elif self.operation.attribute_types[i] == 'Static':
                    attribute_type = dpg.mvNode_Attr_Static

                attribute_name = attr + '##{}##{}'.format(
                    self.operation.name, self.node_index)

                with dpg.node_attribute(label=attribute_name,
                                        parent=self.id,
                                        attribute_type=attribute_type):
                    if attribute_type == 1:
                        dpg.add_spacer()
                    dpg.add_text(label='##' + attr + ' Name{}##{}'.format(
                        self.operation.name, self.node_index),
                                 default_value=attr)

                    if 'Parameters' in attr:
                        for k, parameter in enumerate(
                                self.operation.parameters):
                            if self.operation.parameter_types[k] == 'int':
                                id = dpg.add_input_int(
                                    label='{}##{}'.format(
                                        parameter, attribute_name),
                                    default_value=self.node_parameters[k],
                                    callback=self.update_parameters,
                                    width=100,
                                    min_clamped=False,
                                    max_clamped=False,
                                    min_value=int(-1e8),
                                    max_value=int(1e8),
                                    on_enter=True)
                            elif self.operation.parameter_types[k] == 'str':
                                id = dpg.add_input_text(
                                    label='{}##{}'.format(
                                        parameter, attribute_name),
                                    default_value=self.node_parameters[k],
                                    callback=self.update_parameters,
                                    width=100,
                                    on_enter=True)
                            elif self.operation.parameter_types[k] == 'float':
                                id = dpg.add_input_float(
                                    label='{}##{}'.format(
                                        parameter, attribute_name),
                                    default_value=self.node_parameters[k],
                                    callback=self.update_parameters,
                                    width=100,
                                    min_clamped=False,
                                    max_clamped=False,
                                    min_value=-1e10,
                                    max_value=1e10,
                                    on_enter=True)
                            elif self.operation.parameter_types[k] == 'bool':
                                id = dpg.add_checkbox(
                                    label='{}##{}'.format(
                                        parameter, attribute_name),
                                    default_value=self.node_parameters[k],
                                    callback=self.update_parameters)
                            elif self.operation.parameter_types[k] == 'list':
                                default_value = self.node_parameters[k][0]
                                if type(self.node_parameters[k]) == str:
                                    default_value = self.node_parameters[k]
                                id = dpg.add_combo(
                                    label='{}##{}'.format(
                                        parameter, attribute_name),
                                    items=self.node_parameters_combos_items[k],
                                    default_value=default_value,
                                    callback=self.update_parameters,
                                    width=100)

                            self.parameter_inputs_ids[parameter] = id

                    dpg.add_spacer(label='##Spacing##' + attribute_name,
                                   indent=3)

            # Add the extra input button with its popup window for extra inputs like ssh and verbosity
            self.extra_input_window()