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)
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)
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)
def configure_pygui(renderer, widgets, update=True): if not dearpygui_imported: raise RuntimeError( "Attempted to use DearPyGUI when it isn't imported.") if update: dpg.delete_item(window) else: dpg.setup_viewport() dpg.set_viewport_title(title=f"Manim Community v{__version__}") dpg.set_viewport_width(1015) dpg.set_viewport_height(540) def rerun_callback(sender, data): renderer.scene.queue.put(("rerun_gui", [], {})) def continue_callback(sender, data): renderer.scene.queue.put(("exit_gui", [], {})) def scene_selection_callback(sender, data): config["scene_names"] = (dpg.get_value(sender), ) renderer.scene.queue.put(("rerun_gui", [], {})) scene_classes = scene_classes_from_file(Path(config["input_file"]), full_list=True) scene_names = [scene_class.__name__ for scene_class in scene_classes] with dpg.window( id=window, label="Manim GUI", pos=[config["gui_location"][0], config["gui_location"][1]], width=1000, height=500, ): dpg.set_global_font_scale(2) dpg.add_button(label="Rerun", callback=rerun_callback) dpg.add_button(label="Continue", callback=continue_callback) dpg.add_combo( label="Selected scene", items=scene_names, callback=scene_selection_callback, default_value=config["scene_names"][0], ) dpg.add_separator() if len(widgets) != 0: with dpg.collapsing_header( label=f"{config['scene_names'][0]} widgets", default_open=True): for widget_config in widgets: widget_config_copy = widget_config.copy() name = widget_config_copy["name"] widget = widget_config_copy["widget"] if widget != "separator": del widget_config_copy["name"] del widget_config_copy["widget"] getattr(dpg, f"add_{widget}")(name, **widget_config_copy) else: dpg.add_separator() if not update: dpg.start_dearpygui()
def __setup_add_widget__(self, dpg_args) -> None: dpgcore.add_combo(self.id, **dpg_args)
with dpg.theme() as our_theme: dpg.add_theme_color(dpg.mvThemeCol_Button, (0, 255, 0, 255)) dpg.add_theme_color(dpg.mvThemeCol_ButtonHovered, (0, 255, 255, 255)) dpg.add_theme_color(dpg.mvThemeCol_Text, (255, 0, 0, 255)) # Some styles use only one variable "x" and some use 2 "x,"y" looking at the style editor can help dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 20) dpg.add_theme_style(dpg.mvStyleVar_FramePadding, 10, 10) with dpg.window(label="Tutorial", width=500, height=500): dpg.add_button(label="Default Theme") # Setting theme at start up our_button = dpg.add_button(label="Set At Start-up") dpg.set_item_theme(our_button, our_theme) # Themes can be set at runtime using a lambda dpg.add_button( label="Set Theme at Runtime", callback=lambda sender: dpg.set_item_theme(sender, our_theme)) # Themes can be set to all items of a specific type at runtime using a callback def set_theme(): dpg.set_item_type_theme(dpg.mvButton, our_theme) dpg.add_button(label="Theme all items of a specified type", callback=set_theme) dpg.add_combo(label="Combo") dpg.start_dearpygui()
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))
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()
dpg.add_theme_color(dpg.mvThemeCol_TitleBg, (100, 150, 0, 255)) dpg.add_theme_color(dpg.mvThemeCol_ScrollbarGrab, (0, 255, 0, 255)) # Some styles use only one variable "x" and some use 2 "x,"y" looking at the style editor can help dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 20) dpg.add_theme_style(dpg.mvStyleVar_FramePadding, 10, 10) # Themes applied to containers and will propagate to any children that use that theme constant with dpg.window(label="Theme applied to child that propagates", width=300, height=300): dpg.add_button(label="Default Theme Because above theme") with dpg.child() as top_container: dpg.add_button(label="Button") dpg.add_combo(label="recursive theme Radio Button") with dpg.child(): dpg.add_button(label="recursive theme Button") dpg.add_combo(label="recursive theme Radio Button") with dpg.group(): dpg.add_button(label="Button") dpg.add_combo(label=" Radio Button") dpg.set_item_theme(top_container, our_theme) # Themes applied to all container types will apply and propigate to all container types across windows with dpg.window(label="Theme applied to all group containers", width=300, height=150): dpg.add_button(label="Default Theme Because above theme") with dpg.group(): dpg.add_button(label="Button")