def example_one(): """ Creates window plus execution callback ready to take input commands """ def execute(*_args): """ Executes arbitrary command input in running program :param _args: This catches sender and data arguments that we aren't using here :return: None, executes command """ command = c.get_value("command##input") exec(command) with s.window( name="command##window", autosize=True, x_pos=0, y_pos=0, ): c.add_input_text( name="command##input", width=500, height=300, multiline=True, on_enter=True, callback=execute, ) c.start_dearpygui()
def create_new_project(self, *_args): """ Defines a simple window that takes inputs for creating a new project :return: On save inserts project data into database """ with s.window("Create New Project", autosize=True): c.add_input_text("project_name##new_project", label="Project Name") c.add_input_text("client##new_project", label="Client") c.add_slider_int( "rate##new_project", label="Billing Rate per hour", max_value=100, tip="ctrl+click to directly type the number", ) c.add_slider_int( "monthly_frequency##new_project", label="Pay Frequency per Month", default_value=2, max_value=8, tip="How frequently pay is given, default twice a month", ) c.add_slider_int( "weekly_hour_allotment##new_project", label="Weekly Hours", max_value=80, default_value=20, tip="Hours per week for project.", ) c.add_button("Save##SaveProject", callback=self.save_new_project)
def run(self): """ A very basic stand-aloen run method to show what this looks like by default :return: General number display example """ window_args = dict( autosize=False, height=200, width=200, x_pos=0, y_pos=0, ) with s.window("Drawing", **window_args): c.add_drawing(self.name, width=90, height=150) with s.window( "command##window", autosize=True, y_pos=200, x_pos=0, ): c.add_input_text( name="command##input", width=600, height=300, multiline=True, on_enter=True, callback=self.execute, ) c.start_dearpygui()
def show(self): """Start the gui.""" dpg.set_main_window_size(550, 550) dpg.set_main_window_resizable(False) dpg.set_main_window_title("Dearpygui Todo App") dpg.add_text("Todo App") dpg.add_text( "Add a todo by writing a title and clicking" " the add todo button", bullet=True) dpg.add_text("Toggle a todo by clicking on its table row", bullet=True) dpg.add_text( "Remove a todo by clicking on its table row and clicking" " the remove todo button", bullet=True) dpg.add_separator() dpg.add_spacing(count=10) dpg.add_input_text("New Todo Title", source="new-todo-title") dpg.add_button("Add todo", callback=self.__add_todo) dpg.add_spacing(count=10) dpg.add_separator() dpg.add_table('Todos', ['ID', 'Content', 'Done'], height=200, callback=self.__toggle_todo) dpg.add_separator() dpg.add_text("Selected todo:") dpg.add_button("Remove todo", callback=self.__remove_todo) dpg.add_button("Clear todos", callback=self.__clear_todos) # Render Callback and Start gui dpg.set_render_callback(self.__render) dpg.start_dearpygui()
def add_db(): simple.hide_item("Create Document from Template") with simple.window("Add Variable to DB", **default_window()): core.add_text("Variable Name".ljust(23)) core.add_same_line(spacing=10) core.add_text("Variable Content") core.add_input_text( "name_db_add", label="", width=150, ) core.add_same_line(spacing=10) core.add_input_text( "content_db_add", label="", width=300, ) core.add_button( "button_db_add", label="Add Variable", callback=add_variable_gui, callback_data=("name_db_add", "content_db_add"), ) core.add_button( "button_db_close", label="Close Window", callback=close_popup, )
def __init__(self): core.set_style_frame_padding(3, 3) core.set_style_window_padding(3, 3) core.set_main_window_size(650, 450) core.set_global_font_scale(1.5) with simple.window("main", autosize=True): with simple.group("panel", width=210): count = max(22, len(_fontnames)) core.add_input_text("regex", label='', default_value=" ") core.add_listbox("font", label='', items=_fontnames, num_items=count, width=210, callback=self.__changed) core.add_same_line() with simple.group("text"): core.add_text( "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\ Phasellus in mollis mauris. Donec tempor felis eget libero accumsan sagittis.\ Integer efficitur urna sed nibh auctor, non hendrerit libero pulvinar.\ Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere\ cubilia curae; In hac habitasse platea dictumst. Vestibulum consectetur,\ sem vitae tristique rhoncus, sem ex maximus ligula, vitae egestas lorem libero\ nec libero. Pellentesque habitant morbi tristique senectus et netus et malesuada\ fames ac turpis egestas. Praesent gravida laoreet pharetra. Ut nec vulputate purus.\ Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos\ himenaeos. Maecenas malesuada neque vel ipsum imperdiet, et lobortis justo sollicitudin.", wrap=560) simple.show_style_editor()
def search_db(sender, data): simple.hide_item("Create Document from Template") session = Session() vars = session.query(Variable).order_by(Variable.name.asc()) with simple.window(f"Search in DB ({data.split('_')[0]})", **default_window()): core.add_text("All variables") for var in vars: core.add_input_text( f"{var.name}_name_search", label="", width=150, enabled=False, default_value=var.name, ) core.add_same_line(spacing=10) core.add_input_text( f"{var.name}_content_search", label="", width=300, enabled=False, default_value=var.content, ) core.add_same_line(spacing=10) core.add_button( f"{var.name}_update_button_search", label="Use this value", callback=use_value, callback_data=((data, var.content)), ) core.add_button( "button_db_close", label="Close Window", callback=close_popup, )
def create_server_input(dimensions): with simple.window( "server_input", width=dimensions.width, height=dimensions.height, x_pos=dimensions.x, y_pos=dimensions.y, no_resize=True, no_move=True, no_title_bar=True, ): #DEBUG TEXT core.add_text("Server Input") #Add input text core.add_value("input_text_value", "") core.add_input_text("input_text", label="", on_enter=True, callback=enter_button, source="input_text_value") core.add_button("input_button", label="Send to Server", callback=enter_button)
def place(self, same_line=False): if same_line: add_same_line() add_input_text(self.name, callback=self.on_text_changed, callback_data=self.callback_data, **self.default_config) return self
def multiple_accounts(sender, data): core.delete_item('Account Email') core.delete_item('Account Password') core.add_input_text('Accounts File', default_value='accs_to_level.txt', before='Login', width=200)
def show(self): """Start the gui.""" with sdpg.window("Main Window"): dpg.set_main_window_size(550, 600) dpg.set_main_window_resizable(False) dpg.set_main_window_title("Stockify") dpg.add_text("Stockify: The Future of Stocks") dpg.add_text( "Predict a stock by typing in its ticker and clicking" " the predict stock button", bullet=True, ) dpg.add_text( "Remove a stock by clicking on its table row and clicking" " the remove stock button", bullet=True, ) dpg.add_text( "All predictions will predict a stocks value " "in 30 days", bullet=True, ) dpg.add_text( "Confidence is the degree that Stockify" " is sure about its prediction", bullet=True, ) dpg.add_separator() dpg.add_spacing(count=10) dpg.add_input_text("Stock Ticker", source="stock-ticker") dpg.add_button("Predict Stock", callback=self.__add_stock) dpg.add_spacing(count=10) dpg.add_separator() dpg.add_table( "Stocks", ["Stock", "Prediction", "Confidence"], height=200, callback=self.__toggle_stock, ) dpg.add_separator() dpg.add_text("Selected stock:") dpg.add_button("Remove stock", callback=self.__remove_stock) dpg.add_button("Clear stocks", callback=self.__clear_stocks) # Render Callback and Start gui dpg.set_render_callback(self.__render) dpg.start_dearpygui(primary_window="Main Window")
def create_login(): #get main window size window_size = core.get_main_window_size() #Setup server status window size status_width = 250 status_height = 150 #Setup login status login_width = 300 login_height = 100 #Setup Positions for login login_x = int((window_size[0] / 2) - ((login_width / 2) + (status_width / 2))) login_y = int((window_size[1] / 2) - ((login_height / 2) + (status_height / 4))) #Setup positions for status status_x = int((window_size[0] / 2) - ((login_width / 2) - (status_width / 2))) status_y = int((window_size[1] / 2) - ((login_height / 2) + (status_height / 2))) #Setup Status create_status(status_x, status_y) #Build window size with simple.window("login_window", no_title_bar=True, no_close=True, no_resize=True, autosize=True, x_pos=login_x, y_pos=login_y): core.add_text("LOGIN") core.add_input_text("login_input", hint="auth key", on_enter=True, password=True, label="") core.add_text("login_error_text", default_value=" ", before="login_button") core.add_button("login_button", label="Login Button", callback=request_login)
def add_category(self, sender, data): random_id = util.generate_random_string() with simple.group(f"newcategory{random_id}", parent=f"categories{self.id}"): dpg.add_input_text(f"catlabel{random_id}", label="") dpg.add_same_line(spacing=10) dpg.add_button(f"catdone{random_id}", callback=self.submit_category, label="Done") dpg.add_color_picker4( f"catcolor{random_id}", default_value=[255, 0, 0, 255], height=200, width=200, label="", )
def window_crud_maintenance(sender, data): log_info(f'Function: CRUD Maintenance Window, {sender}, {data}') if does_item_exist(f'{data}##window'): log_info(f'Already exist {data}##window') pass else: if data == 'Key Values': table_headers = ['Key', 'Value', 'Comment'] elif data == 'Plex Shows': table_headers = ['Show Name', 'Show Id', 'Cleaned Show Name'] elif data == 'Plex Episodes': table_headers = [ 'Show Name', 'Season', 'Episode', 'Date Watched', 'TVM Updated', 'TVM Update Status' ] else: table_headers = ['Unknown'] with window(name=f'{data}##window', width=2130, height=650, x_pos=5, y_pos=45): add_input_text(name=f'{data}_input', no_spaces=True, multiline=False, decimal=False, label=data, width=200) add_same_line(spacing=10) add_button(name=f'Search##{data}', callback=func_crud_search, callback_data=data) if data == 'Key Values' or data == 'Plex Shows': add_same_line(spacing=10) add_button(name=f"Add New##{data}") add_same_line(spacing=10) add_button(name=f"Edit##{data}") if data == 'Key Values': add_same_line(spacing=10) add_button(name=f"Delete##{data}") add_same_line(spacing=10) add_button(name=f"Clear##{data}", callback=func_crud_clear, callback_data=f'Table##{data}') add_separator(name=f'##{data}SEP1') add_table(name=f'Table##{data}', headers=table_headers) add_separator(name=f'##{data}SEP1')
def create_node(self, node_type: str = "Root Prompt"): ''' Creates a node ''' node_name = "{}##{}".format(node_type, self.node_index) with simple.node(node_name): # Id num with simple.node_attribute("ID##{0}".format(self.node_index), static=True): core.add_text("ID: {}".format(self.node_index)) # Input connection core.add_node_attribute("Input##{}".format(self.node_index)) # Text input field with simple.node_attribute("TextBox##{}".format(self.node_index), static=True): core.add_input_text("##Text_{}".format(self.node_index), width=200, height=50, multiline=True) # Output connection core.add_node_attribute("Output##{}".format(self.node_index), output=True) # Checkbox for callback condition with simple.node_attribute("HasCallback##{}".format( self.node_index), static=True): core.add_checkbox("Has Callback##{}".format(self.node_index)) # Checkbox for end condition with simple.node_attribute("IsEnd##{}".format(self.node_index), static=True): core.add_checkbox("Is End##{}".format(self.node_index)) self.nodes[self.node_index] = node_name if node_type == "Response": self.tree.add_response() else: self.tree.add_prompt() self.node_index += 1
def main(): # env = gym.make('Trajectory-v0') # episodes = collect_data(env, num_episodes, steps_per_episode, RandomPolicy(env), render) # show_demo() def save_callback(sender, data): print("Save Clicked") with simple.window("Generate Dataset"): core.add_text("Hello world") core.add_button("Save", callback=save_callback) core.add_input_text("string") core.add_slider_float("float") core.start_dearpygui()
def add_var_line(var, parent): session = Session() db_var = session.query(Variable).filter(Variable.name == var.name).first() default = "" if db_var: default = db_var.content core.add_input_text( f"{var.name}_name", label="", width=150, enabled=False, default_value=var.name, parent=parent, ) core.add_same_line(spacing=10, parent=parent) if db_var and db_var.content and len(db_var.content) > 80: height = 80 multiline = True else: height = 0 multiline = False core.add_input_text( f"{var.name}_input", label="", width=300, default_value=default, parent=parent, multiline=multiline, height=height, ) core.add_same_line(spacing=10, parent=parent) core.add_button( f"{var.name}_search_button", label="Search in DB", callback=search_db, callback_data=f"{var.name}_input", parent=parent, ) core.add_same_line(spacing=10, parent=parent) core.add_button( f"{var.name}_update_button", label="Save/Update", callback=save_or_update_db, callback_data=(f"{var.name}_name", f"{var.name}_input"), parent=parent, )
def __init__(self): core.set_style_item_spacing(1, 1) core.set_style_window_padding(0, 0) with simple.window("main"): with simple.group("controls", width=520): with simple.group("buttons"): for x in range(6): core.add_button(f"id-{x}", label=f"button {x}") core.add_color_button("bcolor", (196, 128, 155, 255)) core.add_radio_button("radio") core.add_checkbox("checkbox") core.add_same_line() with simple.group("misc"): core.add_date_picker("date") with simple.group("text"): core.add_text("text") core.add_input_text( "input_text", label="", default_value= "Call me Ish-meal. Tasty like an ashen log.") core.add_label_text("label", label="", default_value="label") core.add_same_line() with simple.group("dropdown"): core.add_listbox("listbox", label="", items=(1, 2, 3)) core.add_combo("combo", label="", items=(1, 2, 3)) for x in ["float", "int"]: with simple.group(x): for what in ["add_drag_", "add_input_"]: for y in ['', 2, 3, 4]: n = f"{what}{x}{y}" cmd = getattr(core, n) cmd(n, label="", width=200) core.add_same_line() manager.ThemeManager()
def add_login_els(self): core.add_input_text("Username##login", on_enter=True, parent="login_els") core.add_input_text( "Password##login", password=True, on_enter=True, parent="login_els", ) core.add_button("Log in", callback=self.log_in, parent="login_els") core.add_button("Create an account", callback=self.show_signup_els, parent="login_els") core.add_text("Incorrect Password", color=[255, 0, 0]) core.add_text("Please, fill all the inputs", color=[255, 0, 0]) simple.hide_item("Incorrect Password") simple.hide_item("Please, fill all the inputs")
def checkCustomNodes(sender, data): # colect and process the names of nodes nodes_list = core.get_value("##nodes_list_input") nodes_list = list(item.strip(" ") for item in nodes_list.split(",")) gui.arbitrary_node_list = nodes_list # transition the window to the next state core.delete_item('node creation##90') core.configure_item('connection creation##100', show=True) for node_name in nodes_list: core.add_input_text( "connections to node {}##node_connection_{}".format( node_name, node_name), width=380, parent="connection creation##100") core.add_button("Enter##b", callback=checkCustomConnections, parent="connection creation##100")
def __init__(self): self.log_level = 0 self._auto_scroll = True self.filter_id = None self.window_id = dpg.add_window(label="mvLogger") self.count = 0 self.flush_count = 1000 with cxt.group(horizontal=True, parent=self.window_id): dpg.add_checkbox(label="Auto-scroll", default_value=True, callback=lambda sender: self.auto_scroll( dpg.get_value(sender))) dpg.add_button(label="Clear", callback=lambda: dpg.delete_item( self.filter_id, children_only=True)) dpg.add_input_text(label="Filter", callback=lambda sender: dpg.set_value( self.filter_id, dpg.get_value(sender)), parent=self.window_id) self.child_id = dpg.add_child(parent=self.window_id, autosize_x=True, autosize_y=True) self.filter_id = dpg.add_filter_set(parent=self.child_id) with cxt.theme() as self.trace_theme: dpg.add_theme_color(dpg.mvThemeCol_Text, (0, 255, 0, 255)) with cxt.theme() as self.debug_theme: dpg.add_theme_color(dpg.mvThemeCol_Text, (64, 128, 255, 255)) with cxt.theme() as self.info_theme: dpg.add_theme_color(dpg.mvThemeCol_Text, (255, 255, 255, 255)) with cxt.theme() as self.warning_theme: dpg.add_theme_color(dpg.mvThemeCol_Text, (255, 255, 0, 255)) with cxt.theme() as self.error_theme: dpg.add_theme_color(dpg.mvThemeCol_Text, (255, 0, 0, 255)) with cxt.theme() as self.critical_theme: dpg.add_theme_color(dpg.mvThemeCol_Text, (255, 0, 0, 255))
def _command_window(self, exec_command=None): """ Creates execution window with execute callback """ callback = (self.execute if exec_command is None else exec_command) with s.window( name="command##window", autosize=True, x_pos=485, y_pos=0, ): c.add_input_text( name="command##input", width=500, height=300, multiline=True, on_enter=True, callback=callback, )
def debug_get_location_gui(logger="log"): """ Simple text input + location window for checking default config x/y pos """ with window("Location", autosize=True, y_pos=0): add_text( """ On enter will give all window config locations. Window name will look for all windows that name contains the string, caps insensitive. """ ) add_input_text( name="Window Name##input", callback=debug_get_window_pos, on_enter=True, callback_data=logger, ) add_checkbox("Print invisible", default_value=False)
def create_new_user_gui(): with window("Main"): gg.add_input_text( name="##user_name", hint="User name", tip="Your username", parent="Main" ) gg.add_input_int( name="##balance_input", default_value=500, tip="Your starting balance", parent="Main" ) def create_new_user_data(sender, data) -> None: initial_data = { "User Name": gg.get_value("##user_name"), "Start Balance": gg.get_value("##balance_input") } if not initial_data["User Name"].isalpha(): gg.add_label_text("Error", color=[255, 0, 0], before="##balance_input", label="Username must be alphabetical") gg.log_error("User-name must be only alphabets") return elif initial_data["User Name"] + ".db" in os.listdir(): gg.add_label_text("Error", color=[255, 0, 0], before="##balance_input",label="Username already exists!") gg.log_error("User-name must be unique") return if initial_data["Start Balance"] <= 0: gg.add_label_text("Error_start_balance", color=[255, 0, 0], before="Proceed",label="Balance must be greater than 0$") gg.log_error("Balance must be greater than 0$!") return create_database(initial_data["User Name"] + ".db", initial_data["Start Balance"]) gg.delete_item("Main") initial_screen() gg.add_button("Proceed", callback=create_new_user_data)
def edit_db(): simple.hide_item("Create Document from Template") session = Session() vars = session.query(Variable).order_by(Variable.name.asc()) with simple.window("Edit Variable DB", **default_window()): core.add_text("All variables") for var in vars: with simple.group(f"{var.name}_group"): core.add_input_text( f"{var.name}_name_db", label="", width=150, enabled=False, default_value=var.name, ) core.add_same_line(spacing=10) core.add_input_text( f"{var.name}_content_db", label="", width=300, default_value=get_content(var.content), ) core.add_same_line(spacing=10) core.add_button( f"{var.name}_update_button_db", label="Update", callback=save_or_update_db, callback_data=(f"{var.name}_name_db", f"{var.name}_content_db"), ) core.add_same_line(spacing=10) core.add_button( f"{var.name}_delete_button_db", label="Delete", callback=remove_variable_gui, callback_data=argparse.Namespace(name=var.name), ) core.add_button( "close_button_db", label="Close Window", callback=close_popup, )
def show_server_selection(): #Server Selection core.add_text("server_selection_title", default_value="Select server", parent="status_window") core.add_listbox( "server_selection", items = console_client.client.host_list, default_value = 0, label = "", parent = "status_window", width = 230 ) core.add_text("server_selection_padding1", default_value="\n", parent="status_window") core.add_text("port_input_title", default_value="Change Port", parent="status_window") #Port Selection core.add_input_text( "port_input", parent = "status_window", scientific = True, default_value = str(console_client.client.port), label = "" ) #Padding core.add_text("server_selection_padding2", default_value="\n", parent="status_window") #Connect button core.add_button( "server_connect_button", label = "Connect", callback = connect_to_server, parent = "status_window" )
def create_widget(): #If this widget exists, kill it if core.does_item_exist("edit_token"): core.delete_item("edit_token") #Create widget with simple.window("edit_token"): core.add_text("Use dis to edit token") core.add_text("token_display", default_value="Current token: {}...".format( console_client.client.auth_token[:10])) core.add_input_text("key_input", hint="auth key", password=True, label="") core.add_text("key_error_text", default_value=" ", before="edit_button") core.add_button("edit_button", label="Edit", callback=edit_request)
def add_task(self, sender, data): random_id = util.generate_random_string() parent = dpg.get_item_parent(sender) with simple.group( f"newtask{random_id}", parent=parent.replace("newtask", ""), before=f"taskspace{data.get('category')}", ): dpg.add_indent() dpg.add_input_text(f"tasklabel{random_id}", label="") dpg.add_same_line(spacing=10) dpg.add_button( f"taskdone{random_id}", label="Done", callback=self.submit_task, callback_data={ "parent": parent, "category": data["category"] }, ) dpg.unindent()
def __init__(self, logger=logging.getLogger(__name__)): self.logger = logger self.converter = Converter(logger=logger) self.translator: MultiTranslator = MultiTranslator( TRANSLATOR_TYPES.translator, logger=logger) self.current_uid = 0 self.control_window = simple.window("Control", x_pos=0, y_pos=0, height=800) self.convert_window_list = [ ] # todo: this stores windows indefinitely. Figure out a way to delete them. self.data_to_save = '' # this is the data that will be written to the disk by self.save_text with self.control_window: # allow user to select image to convert core.add_text("Select an Image or PDF") core.add_button("Select file", callback=lambda *_: core.open_file_dialog( callback=self.select_file)) language_list = list(lang.keys()) core.add_text("Default Source Language:") core.add_combo(f'default_source_language', label='', items=language_list, default_value='German') core.add_text("Default Destiation Language:") core.add_combo(f'default_destination_language', label='', items=language_list, default_value='French') core.add_text("Translation Method:") core.add_combo(f'translation_method', label='', items=list(TRANSLATOR_TYPES.__dict__.values()), default_value=TRANSLATOR_TYPES.translator) core.add_text('API token (if using IBM)') core.add_input_text(f'api_token', label='', password=True)
def __init__(self): # row header names to preserve for re-posting table on searching self.__headers = [] # the rows to filter during a search self.__rows = [] cwd = os.path.dirname(__file__) os.chdir(cwd) core.set_main_window_size(800, 750) with simple.window("main"): with simple.group("control"): core.add_button("load", callback=lambda: core.open_file_dialog( callback=self.__load, extensions='.csv')) core.add_input_text("filter", default_value=".*", callback=self.__tableRefresh) with simple.group("panel"): ...