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 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 add_data_option(self, sender, data): """ Creates the data input window for the add data window """ with s.window( "Add Data Window", autosize=True, x_pos=0, y_pos=350, ): # Title text c.add_text("Add a new data row:") c.add_text( name=f"Idx: \t{len(self.table_data)}", tip="This is created automatically", ) # Text divider c.add_text("-" * 30) # input sliders c.add_slider_int(name=": x_val") c.add_slider_int(name=": y_val") # Action buttons c.add_button( "Cancel", callback=lambda *args: c.delete_item("Add Data Window"), ) c.add_same_line() c.add_button("Add Row", callback=self.save_new_row)
def pick_maple_window(self, sender, data): def callback_on_picking_window(sender, data): self.window_title = sender self.send_to_pipes(f'WINDOW\\{sender}') set_value('Currently doing nothing. Pick MapleStory window.', f'Will work on {sender} window') delete_item('Pick Maple Window##1') def callback_on_refresh(sender, data): delete_item('Pick Maple Window##1') self.pick_maple_window(None, None) add_window("Pick Maple Window##1") add_text("Please make sure that your MapleStory") add_text("window is open. If your MapleStory") add_text("window is closed, click on refresh button") add_text("after opening your MapleStory window.") add_button('Refresh the windows', callback=callback_on_refresh) add_spacing(count=6) titles = get_active_windows() if len(titles) == 0: add_text('No active MapleStory windows') else: add_text('Please select one:') for window_title in titles: add_button(window_title, callback=callback_on_picking_window) end()
def choose_user_screen(): with window("Choose User",width=600): gg.add_separator() with managed_columns("row", 5): gg.add_text("USERNAME") gg.add_text("STARTING BALANCE") gg.add_text("CURRENT BALANCE") gg.add_text("DATE CREATED") gg.add_text("") gg.add_separator() def load_user(sender, data): user = User(data["file_name"] + ".db") gg.delete_item("Choose User") MainGui(user) count = 1 for file in os.listdir(): if(file[-3:]) == ".db": user_name = file[:-3] initial_balance, current_balance, date_created = get_user_data(file) with managed_columns(f"row{count}", 5): gg.add_text(f"{user_name}") gg.add_text(f"{initial_balance}") gg.add_text(f"{current_balance}") gg.add_text(f"{date_created}") gg.add_button(f"load {user_name}", callback=load_user, callback_data={"file_name": user_name}) gg.add_separator() count += 1
def watchlist_stocks(self): with window("Watchlist Window", width=500, height=500): self.menu(False, False, False, True) watchlist_data = get_user_watchlist_data(self.user.file) gg.add_separator() with managed_columns("headers", 4): gg.add_text("TICKER") gg.add_text("PRICE WHEN ADDED") gg.add_text("DATE ADDED") gg.add_text("") def remove_from_watchlist(sender, data): self.user.remove_from_watchlist(data["Ticker"]) gg.delete_item(f"{data['Ticker']} row") for row in watchlist_data: ticker_name, price_when_added, str_date_added = row[0], row[1], row[2] gg.add_separator() with managed_columns(f"{ticker_name} row", 4): gg.add_button(name=ticker_name, callback=self.change_to_window, callback_data={"Scene Function": self.info_single_stock, "kwargs": {"Ticker": ticker_name}}) s = f"{price_when_added} | " s += f"{get_percent_change(float(price_when_added), yfs.get_live_price(ticker_name))}%" gg.add_text(s) gg.add_text(str_date_added) gg.add_button(f"Remove {ticker_name}", label="Remove", callback=remove_from_watchlist, callback_data={"Ticker": ticker_name}) gg.add_separator()
def init_ui(self): """Initialize the main window's UI The main window has save and load buttons and a tab bar for the profiles. """ with dpg_simple.window("Main Window"): dpg_core.add_button(self._save_id, callback=self.save) dpg_core.add_same_line() dpg_core.add_button(self._load_id, callback=self.load) dpg_core.add_same_line(name=self._status_id_same_line, show=False) dpg_core.add_text(self._status_id, default_value="", show=False) main_window_tab_bar_ctx = dpg_simple.tab_bar( "##MainWindow-tabbar", parent="Main Window", reorderable=True, callback=self.remove_tab, ) with main_window_tab_bar_ctx: self.add_tab() dpg_core.add_tab_button( "+##MainWindow-btn", parent="##MainWindow-tabbar", callback=self.add_tab, trailing=True, no_tooltip=True, )
def generate_workout_tab(self): core.add_spacing(count=10) core.add_group(name="workout_execution_group") core.add_group(name="workout_composition_group") core.add_combo( "Equipment##widget", items=workout_services.get_criterias_by_name("Equipment"), parent="workout_composition_group", ) core.add_spacing(count=4, parent="workout_composition_group") core.add_combo( "Exercise Type##widget", items=workout_services.get_criterias_by_name("Exercise Type"), parent="workout_composition_group", ) core.add_spacing(count=4, parent="workout_composition_group") core.add_combo( "Muscle Group##widget", items=workout_services.get_criterias_by_name("Major Muscle"), parent="workout_composition_group", ) core.add_spacing(count=4, parent="workout_composition_group") core.add_button( "Compose Workout##widget", parent="workout_composition_group", callback=self.compose_workout, ) core.add_text( "Fill all the inputs, please.", color=[255, 0, 0], parent="workout_composition_group", ) simple.hide_item("Fill all the inputs, please.")
def render(self): with simple.group( self.group, parent=f"cattasks{self.category_id}" ): dpg.add_indent() dpg.add_checkbox( self.id, label=self.label, default_value=self.complete, callback=self.checkbox_check, ) dpg.add_same_line(spacing=10) dpg.add_button( f"up{self.id}", arrow=True, direction=2, callback=self.move_task_up, callback_data={"item": self.group} ) dpg.add_same_line() dpg.add_button( f"down{self.id}", arrow=True, direction=3, callback=self.move_task_down, callback_data={"item": self.group} ) dpg.unindent()
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 construct(self): with simple.group(self.name, parent=self.parent): # GUI elements for the initial coordinate ######################### core.add_text("Initial coordinate (latitude, longitude)") core.add_group("init_input", horizontal=True, horizontal_spacing=0) core.add_input_float2("init_coordinate", label="", format="%f°", width=390) core.add_button( "Sample##input", callback=self.sample_by_mouse, callback_data=("init_coordinate"), ) core.end() # init_input core.add_spacing(count=5) # GUI elements for the destination coordinate ##################### core.add_text("Destination coordinate (latitude, longitude)") core.add_group("destination_input", horizontal=True, horizontal_spacing=0) core.add_input_float2("destination_coordinate", format="%f°", label="", width=390) core.add_button( "Sample##destination", callback=self.sample_by_mouse, callback_data=("destination_coordinate"), ) core.end() # destination_input core.add_spacing(count=5)
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_main_window_size(720, 540) with simple.window("main"): with simple.group("group"): core.add_button("thread", label='Add Thread', callback=lambda s, d: self.__buttonThread()) self.__bars = {} core.set_render_callback(lambda s, d: self.__render()) core.set_resize_callback(lambda s, d: self.__resize())
def next_round(self): core.configure_item("next_round", enabled=False) self.round += 1 core.set_value("round", str(self.round)) for stock in self.stocks: core.configure_item(f"stock.{stock.name}.owned", enabled=False) stock.new_price() self.player.apply_market_changes() core.set_value("cash", self.player.cash) bankrupted = [] share_issued = [] for stock in self.stocks: if stock.is_bankcrupted(): bankrupted.append(stock) stock.price = 10 stock.dividend = 0 stock.change = 0 stock.previous_price = 0 if stock.is_share_issued(): share_issued.append(stock) core.set_value(f"stock.{stock.name}.price", f"{stock.price:0.2f}") core.set_value(f"stock.{stock.name}.previous_price", f"{stock.previous_price:0.2f}") core.set_value(f"stock.{stock.name}.change", f"{stock.change:0.2f}") core.set_value(f"stock.{stock.name}.dividend", f"{stock.dividend:0.2f}") if bankrupted or share_issued: with simple.window( "Stock news!", autosize=True, no_collapse=True, no_move=True, on_close=self.news_close, ): if bankrupted: core.add_text("The following stocks are gone bankruptcy:") for stock in bankrupted: core.add_text(f"{stock.name}") core.add_spacing(count=5) if share_issued: core.add_text( "The following stocks are giving share issue:") for stock in share_issued: core.add_text(f"{stock.name}") core.add_spacing(count=5) core.add_button( "Close", callback=lambda: self.news_close("Stock news!")) else: self.news_close("")
def save_page_dialog(self, sender, data): tabs = [{ "name": tab.tab_name, "id": tab.id } for tab in self.tab_tracker.tabs] dialog_height = 30 * (len(tabs) + 2) with simple.child("SavePopup", height=dialog_height): dpg.add_text("Choose which tab to save:") dpg.add_radio_button("SaveRadio", items=[tab["name"] for tab in tabs]) dpg.add_spacing(count=2) dpg.add_button("SaveButton", label="Save", callback=self.save_page)
def initial_screen(): with window("Main"): def change_to_choosing_user(sender, data): gg.delete_item("Main") choose_user_screen() gg.add_button("Load", callback=change_to_choosing_user) def change_to_new_user(sender, data): gg.delete_item("Main") create_new_user_gui() gg.add_button("New", callback=change_to_new_user)
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 compose_workout(self): equipment_val = core.get_value("Equipment##widget") exercise_type_val = core.get_value("Exercise Type##widget") muscle_group_val = core.get_value("Muscle Group##widget") if not equipment_val or not exercise_type_val or not muscle_group_val: simple.show_item("Fill all the inputs, please.") else: self.composed_workout = get_composed_workout( equipment_val, exercise_type_val, muscle_group_val) simple.hide_item("workout_composition_group") core.add_table("Workout", ["Exercise", "Sets", "Reps", "Example"], callback=self.toggle) for el in self.composed_workout: core.add_row("Workout", list(el.values())) core.add_button("Cancel##widget") core.add_button("Save##widget")
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 __init__(self): # turn off the sync to measure FPS core.set_vsync(False) self.__vsync = False with simple.window("main"): with simple.group("group", width=150): core.add_label_text("FPS") core.add_button("vsync", label="Toggle V-Sync On", callback=self.__toggleVsync) core.set_item_color("vsync", core.mvGuiCol_Button, (200, 96, 96, 255)) core.set_render_callback(self.__render) # maximum average the last XX ticks... self.__avgCountMax = 240 self.__avg = []
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 __init__(self): with simple.window(self.windowName, width=self.xSize, height=self.ySize, x_pos=self.xPos, y_pos=self.yPos): core.add_button(self.importButtonName, callback=self.open_file_dialog) core.add_label_text(name=self.fileStatus, label='##' + self.fileMissing, default_value=self.fileMissing) core.add_separator() core.add_same_line() core.add_plot(self.plotName) super().__init__()
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 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 __init__(self): core.set_vsync(False) core.set_style_item_spacing(1, 1) self.__timeline = Timeline() self.__timeline.callback(self.__timelineRender) self.__fps = 0 cmds = { '<<': lambda: self.__timeline.seek(0), '<-': lambda: self.__timeline.play(-1), '||': self.__timeline.stop, '->': lambda: self.__timeline.play(1), '>>': lambda: self.__timeline.seek(-1), '@@': self.__timeline.loop } _width = 60 _size = len(cmds.keys()) * _width with simple.window("main"): with simple.group("MediaBar"): with simple.group("Shuttle"): for k, v in cmds.items(): core.add_button(f"Shuttle#{k}", label=k, width=_width, height=25, callback=v) core.add_same_line() core.add_text("ShuttleFPS") core.add_drag_float("MediabarIndex", label="", width=_size, callback=self.__cbSeek) core.add_color_button("TEST BUTTON", [255, 255, 255], width=400, height=400) self.__timeline.keyEdit("TEST BUTTON", 'width', 0, 400) self.__timeline.keyEdit("TEST BUTTON", 'width', 2., 10) self.__timeline.keyEdit("TEST BUTTON", 'width', 3.75, 400) core.set_render_callback(self.__render)
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 user_stock_dash(self): with window("User stock dashboard", width=500, height=500): self.menu(False, False, True, False) gg.add_separator() with managed_columns("Header", 5): gg.add_text("TICKER") gg.add_text("DATE") gg.add_text("BUY $ / SELL $") gg.add_text("QUANTITY") gg.add_text("SELL") def sell_stock(sender, data): buy_data = data["Purchase Data"] purchaseid, date_bought, time_bought, buy_price, quantity_buy = buy_data quantity_sell = round(gg.get_value(sender), 2) label = f"Message" if quantity_sell > quantity_buy: set_item_label(label, f"Cannot sell more than {quantity_buy}!") else: self.user.sell_share(data["Ticker"], purchaseid, quantity_sell, data["Sell Price"]) self.change_to_window(sender, {"Scene Function": self.user_stock_dash}) set_item_label(label, f"Sold {quantity_sell} shares at {data['Sell Price']}$") for ticker in self.user.share_by_name: ticker_buy_data = self.user.share_by_name[ticker] current_price = round(yfs.get_live_price(ticker), 2) for event in ticker_buy_data: purchaseid, date, time, buy_price, qty = event gg.add_separator() with managed_columns(f"Data {ticker}{purchaseid}", columns=5, border=True): gg.add_text(ticker) gg.add_text(date) gg.add_text(f"{buy_price} / {current_price}") gg.add_label_text(name=f"{purchaseid} qty", label=str(qty)) with group(f"Sell{ticker}{purchaseid}"): gg.add_input_float(name=f"##Sell {ticker}{purchaseid} input", default_value=0, on_enter=True, callback=sell_stock, callback_data={"Ticker": ticker, "Purchase Data": event, "Sell Price": current_price}, format="%.2f", width=80) gg.add_separator() gg.add_button("Message", label="")
def init_ui(self): """Initialize the container's UI""" # the monitor profile is in a tab with dpg_simple.tab(self._tab_id, parent=self.parent, no_tooltip=True): # Create 2 groups and put them on the same line with dpg_simple.group(self._left_panel_id, parent=self._tab_id): # The grid input dpg_core.add_input_int2( self._input_id, parent=self._left_panel_id, callback=self.input_callback, default_value=[1, 1], ) # snap button dpg_core.add_button(self._snap_id, parent=self._left_panel_id, callback=self.snap) # Customize grid with the plot dpg_core.add_plot( self._plot_id, parent=self._left_panel_id, height=-1, xaxis_lock_min=True, xaxis_lock_max=True, y2axis_lock_min=True, y2axis_lock_max=True, yaxis_no_tick_marks=True, yaxis_no_tick_labels=True, xaxis_no_tick_marks=True, xaxis_no_tick_labels=True, xaxis_no_gridlines=True, yaxis_no_gridlines=True, ) # Ensure the plot's limits are the work area dpg_core.set_plot_xlimits(self._plot_id, xmin=self.monitor.work.left, xmax=self.monitor.work.right) dpg_core.set_plot_ylimits(self._plot_id, ymin=self.monitor.work.top, ymax=self.monitor.work.bottom) # Put the application table on the right dpg_core.add_same_line(parent=self._tab_id) with dpg_simple.group(self._right_panel_id, parent=self._tab_id): self._app_table = AppTable(parent=self._right_panel_id)
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): core.set_style_item_spacing(29, 4) core.set_style_window_padding(0, 0) core.set_main_window_size(1920, 1080) self.__column = 7 self.__row = 58 with simple.window("main"): with simple.group("test", width=187): core.add_button("THE DPG HERO WE NEED...", callback=self.__generate) for c in range(self.__column): core.add_same_line() with simple.group(f"col-{c}", width=187): x = c * self.__row for r in range(self.__row): core.add_text(str(x + r), default_value=" ")