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 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 make_gui(self): dpg.set_main_window_size(self.width, self.height) dpg.set_theme(self.theme) with simple.window("Main", no_title_bar=True): dpg.set_main_window_title("pytasker") with simple.menu_bar("Menu"): with simple.menu("File"): dpg.add_menu_item("New Page", callback=self.new_tab) dpg.add_menu_item("Load Page", callback=self.load_page) dpg.add_menu_item("Save Page", callback=self.save_page_dialog) dpg.add_separator() dpg.add_menu_item("Quit", callback=self.exit_program) with simple.menu("Themes"): dpg.add_menu_item("Dark", callback=self.theme_callback) dpg.add_menu_item("Light", callback=self.theme_callback) dpg.add_menu_item("Classic", callback=self.theme_callback) dpg.add_menu_item("Dark 2", callback=self.theme_callback) dpg.add_menu_item("Grey", callback=self.theme_callback) dpg.add_menu_item("Dark Grey", callback=self.theme_callback) dpg.add_menu_item("Cherry", callback=self.theme_callback) dpg.add_menu_item("Purple", callback=self.theme_callback) dpg.add_menu_item("Gold", callback=self.theme_callback) dpg.add_menu_item("Red", callback=self.theme_callback) dpg.add_tab_bar(name="tab_bar_1", parent="Main") with simple.group("inittext"): dpg.add_text("Hello! Select File - New to get started")
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 show(self) -> None: if core.does_item_exist(self._win_name): self.destroy(self._win_name) obj_name = self._entry.get_object_name() with simple.window(self._win_name, label=f"{obj_name}", on_close=self.destroy, width=400): ts = self._entry.get_timestamp_str() age = self._entry.get_age() core.add_label_text(self._win_name + "ts", label=f"Timestamp", default_value=f"{ts}") core.add_label_text(self._win_name + "age", label=f"Age", default_value=f"{age}") core.add_label_text(self._win_name + "freq", label=f"Frequency", default_value=f"0.0 Hz") core.add_text("") core.add_label_text(self._win_name + "content", default_value=str(self._entry.get_object()), label="") self._freq_thread.start()
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 init_ui(self): """Initialize the container's UI""" with dpg_simple.managed_columns(f"{self._id}_head", len(self.HEADER), parent=self.parent): for item in self.HEADER: dpg_core.add_text(item)
def draw(self): ''' Draws the MainMenu ''' with simple.window(self.title, **config.MENU_CONFIG): with simple.menu_bar('Main Menu'): with simple.menu('File'): core.add_menu_item('New', callback=self.new) core.add_menu_item('Open', callback=self.open_file) core.add_menu_item('Save', callback=self.save) core.add_menu_item('Save As', callback=self.save_as) with simple.menu('Settings'): with simple.menu('Theme'): for theme in config.THEMES: core.add_menu_item(theme, callback=self.set_theme, check=True) if self.dedit.get_name(): core.add_text("Tree: {}".format(self.dedit.get_name())) else: core.add_text("Tree: <unnamed>.json") self.dedit.draw()
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 left_label_text(label: str, name: str, xoffset=100, default_value: str = "") -> None: core.add_text(label) core.add_same_line(xoffset=xoffset) core.add_text(name, default_value=default_value)
def create_status(x, y): #Setup login window size width = 245 height = 220 #Build window size with simple.window( "status_window", no_title_bar = True, no_close = True, no_resize = True, no_move = True, autosize = False, width = width, height = height, x_pos = x, y_pos = y, ): #Title core.add_text("== SERVER STATUS ==") show_server_status()
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 __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 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 create_error_text(error): #Delete the current error text if it exists if core.does_item_exist("login_error_text"): core.delete_item("login_error_text") core.add_text("login_error_text", default_value=error, before="login_button", wrap=0)
def open_qasm(sender, data): """ Opens window with qasm code """ with simple.window('Qasm code', width=500, height=600, on_close=delete_items(['Qasm code'])): with open(gui.qasm_file, 'r') as f: core.add_text(f.read())
def add_IBM_computers_view(): """ Adds IBM architecture selector. """ core.add_spacing(name='##space9', count=2) core.add_text('Architecture name:', before='##space5') core.add_radio_button('radio##3', items=list(gui.backend_dict.values())[1:], source='architecture', before='##space5') gui.prev_architecture = 1
def show_version(): """Show version of this app. """ window_name = 'Version info##version_info_window' if not core.does_item_exist(window_name): with simple.window(window_name, on_close=lambda: core.delete_item(window_name), autosize=True, no_resize=True): core.add_text('##version_info_0', default_value=f'Password Manager v{VERSION}')
def __init__(self): self.__fontSize = 1. self.__fontSizeStep = .1 self.__fontSizeRange = (.8, 15.) core.set_global_font_scale(self.__fontSize) core.set_theme("Cherry") core.set_main_window_size(960, 540) with simple.window("MainWindow", autosize=True): core.add_text("HELLO WORLD!") core.set_mouse_wheel_callback(self.__cbMouseWheel)
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 set_warning(warningTxt): """ Warning handling ; set add a collapsing_header to display the Warning Message """ if not core.does_item_exist("Warning##Warning"): with simple.collapsing_header("Warning##Warning", parent="##GroupStats", default_open=True, closable=False, bullet=True): core.add_text("Warning", default_value=warningTxt, color=(255, 255, 0, 255))
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 set_default(sender, data): """ resets all running parameters to default. """ if core.get_value('device_type') == 0: core.add_spacing(name='##space9', count=2) core.add_text('Architecture name:', before='##space5') core.add_radio_button('radio##3', items=list(gui.backend_dict.values())[1:], source='architecture', before='##space5') core.set_value('device_type', 1) core.set_value('architecture', 1) core.set_value('layout_type', 1) core.set_value('opt_level', 1) core.set_value('##num_of_iter', 100)
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 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 _render_results_window(self) -> None: core.delete_item(item=self._window_name, children_only=True) self._render_results_scan_summary() self._render_results_group_operations() core.add_text( 'Results', color=self._control_text_color, parent=self._window_name) for dupicate_image in self._duplicates_list: self._draw_duplicates_set(dupicate_image)
def check_iteration_num(sender, data): """ Controls the number_of_iterations value so it will not be less than 1. If value is less than 1, a warning message is displayed and default value of 1 is set. """ if core.get_value(sender) > 1 and core.get_value( 'Number of iterations should not be less than 1.'): core.delete_item('Number of iterations should not be less than 1.') if core.get_value(sender) < 1: core.set_value('##num_of_iter', 1) if not core.get_value( 'Number of iterations should not be less than 1.'): core.add_text('Number of iterations should not be less than 1.', color=[255, 0, 0, 255], before='##num_of_iter', wrap=300)
def add_arbitrary_coupling_view(): # load arbitrary couplings from file try: with open('arbitrary_coupling.pickle', 'rb') as arbitrary_file: custom_dict = pickle.load(arbitrary_file) core.add_spacing(name='##space9', count=2) core.add_text('Architecture name:', before='##space5') core.add_radio_button('radio##3', items=list(custom_dict.keys()), source='architecture', before='##space5') gui.prev_architecture = 2 except: core.add_spacing(name='##space9', count=2) core.add_text('There are no arbitrary couplings.', before='##space5') gui.prev_architecture = 2
def __init__(self): core.set_main_window_size(720, 540) self.__width = 17 self.__height = 7 self.__total = self.__width * self.__height self.__board = {} size = core.get_main_window_size() self.__paddle = [size[0] * .475, size[1] * .85] self.__paddleSize = (80, 8) # x, y, angle (rads), speed self.__radius = 6 self.__speed = 300 self.__paddleSpeed = 1000 self.__speedMax = self.__speed * 3 self.__pos = (size[0] * .5, size[1] * .8, 0, -self.__speed) with simple.window("main"): with simple.group("scoreboard"): core.add_label_text("score") core.add_same_line() core.add_text("score-value") # core.add_same_line() core.add_label_text("time") core.add_same_line() core.add_text("time-value") core.add_drawing("canvas", width=size[0], height=size[1]) core.draw_circle("canvas", size, self.__radius, (255, 255, 255, 255), fill=(128, 128, 128, 255), tag="ball") core.draw_rectangle("canvas", [ self.__paddle[0] - self.__paddleSize[0], self.__paddle[1] - self.__paddleSize[1] ], [ self.__paddle[0] + self.__paddleSize[0], self.__paddle[1] + self.__paddleSize[1] ], (255, 255, 255, 255), fill=(128, 128, 128, 255), tag="paddle") core.set_resize_callback(self.__resize) core.set_render_callback(self.__render) core.set_key_down_callback(self.__keydown) core.set_mouse_wheel_callback(self.__mousewheel)
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)