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 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 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 open_about_window(sender, data): """ Opens new window with credentials """ with simple.window('About##window', width=700, height=300, on_close=delete_items(['About##window'])): core.add_text('Developers:') core.add_text( '* Valeriy Novossyolov [Computer Science senior student, Nazarbayev University]' ) core.add_text( '* Saadat Nursultan [Computer Science senior student, Nazarbayev University]' ) core.add_spacing(name='##space10', count=5) core.add_text('Adviser:') core.add_text( '* Martin Lukac [Associate Professor, Dep. of Computer Science, Nazarbayev University]' ) core.add_spacing(name='##space10', count=5) core.add_text('Developed to support the scientific paper') core.add_text( "'Geometric Refactoring of Quantum and Reversible Circuits: Quantum Layout'" ) core.add_text( 'by Martin Lukac, Saadat Nursultan, Georgiy Krylov and Oliver Keszocze' )
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 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 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 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 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 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 run_gui(self): with window("Auto Pots"): set_start_callback(self.read_default_preferences) set_main_window_title('Auto Pots') set_window_pos("Auto Pots", 0, 0) add_spacing(count=12) add_button('Pick Maple Window', callback=self.pick_maple_window) add_text('Currently doing nothing. Pick MapleStory window.') add_spacing(count=12) add_text('Take HP Pot When Reaching', color=[232, 163, 33]) add_slider_int("% HP", default_value=45, max_value=99, width=int(SCREEN_WIDTH * 0.8), callback=self.change_hp_percentage) with menu('Select HP button on keyboard'): add_menu_item("Insert", callback=self.change_hp_keyboard_button) add_menu_item("Delete", callback=self.change_hp_keyboard_button) add_menu_item("Home", callback=self.change_hp_keyboard_button) add_menu_item("End", callback=self.change_hp_keyboard_button) add_menu_item("PgUp", callback=self.change_hp_keyboard_button) add_menu_item("PgDn", callback=self.change_hp_keyboard_button) add_spacing(count=12) add_text('Take MP Pot When Reaching', color=[232, 163, 33]) add_slider_int("% MP", default_value=30, max_value=99, width=int(SCREEN_WIDTH * 0.8), callback=self.change_mp_percentage) with menu('Select MP button on keyboard'): add_menu_item("Insert##1", callback=self.change_mp_keyboard_button) add_menu_item("Delete##1", callback=self.change_mp_keyboard_button) add_menu_item("Home##1", callback=self.change_mp_keyboard_button) add_menu_item("End##1", callback=self.change_mp_keyboard_button) add_menu_item("PgUp##1", callback=self.change_mp_keyboard_button) add_menu_item("PgDn##1", callback=self.change_mp_keyboard_button) add_spacing(count=12) add_button('Save Preferences As Default', callback=self.save_preferences) with popup("Save Preferences As Default", 'Save Popup', modal=True, mousebutton=mvMouseButton_Left): add_text('Your preferences has been saved') add_button("OK!", callback=lambda x, y: close_popup(item="Save Popup")) add_spacing(count=12) add_text('Currently doing nothing on HP. Pick button.') add_text('Currently doing nothing on MP. Pick button.') self.read_default_preferences() start_dearpygui(primary_window='Auto Pots')
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 render(self): """ Draw the Category to the screen """ parent_id = self.parent.replace("categories", "") with simple.group( self.group, parent=self.parent, before=f"catspace{parent_id}" ): # Render the Category group dpg.add_spacing(count=2) dpg.add_checkbox( self.id, label="", default_value=self.complete, callback=self.checkbox_check, ) dpg.add_same_line(spacing=10) dpg.add_text(self.label, color=self.color)
def submit_category(self, sender, data): if data: category_label = data["label"] category_color = data["color"] else: parent = dpg.get_item_parent(sender) input_id = parent.replace("newcategory", "") category_label = dpg.get_value(f"catlabel{input_id}") category_color = dpg.get_value(f"catcolor{input_id}") dpg.delete_item(parent) category = trackers.Category(parent=f"categories{self.id}") self.category_tracker.add_category(category) category.label = category_label category.color = category_color if data: category.complete = data["complete"] category.render() if not self.changes: item = dpg.get_item_configuration(self.parent) dpg.configure_item(self.parent, label="!" + item["label"]) self.changes = True # Render the Add Task button with simple.group(f"catitems{category.id}", parent=f"catgroup{category.id}"): dpg.add_group(f"cattasks{category.id}", parent=f"catitems{category.id}") dpg.end() dpg.add_indent() dpg.add_spacing(name=f"taskspace{category.id}") dpg.add_button( f"addtask{category.id}", label="Add New Task", callback=self.add_task, callback_data={"category": category.id}, ) dpg.unindent() return category.id
def render(self, page_data=None): # Initiate page with simple.group(f"categories{self.id}", parent=self.parent): dpg.add_spacing(name=f"catspace{self.id}", count=1) dpg.add_button( f"addcat{self.id}", callback=self.add_category, label="Add New Category", ) dpg.add_spacing(name="", count=10) if page_data: self.page_name = page_data.get("pagename") self.path = page_data.get("path") self.filename = page_data.get("filename") for category in page_data.get("categories"): category_id = self.submit_category( "", { "label": category["label"], "color": category["color"], "complete": category["complete"], }, ) for task in category["tasks"]: self.submit_task( category_id, { "label": task["label"], "complete": task["complete"], "parent": f"cattasks{category_id}", "category": category_id }, ) item = dpg.get_item_configuration(self.parent) dpg.configure_item(self.parent, label=item["label"].replace("!", "")) self.changes = False
class Menu: def theme_setting(sender, data): core.set_theme(data) def dump_db(): user_services.delete_records_by_username() with simple.window("Main Window", no_title_bar=True, autosize=True, no_resize=True): with simple.menu_bar(name="Main Menu"): with simple.menu(name="Settings"): with simple.menu("Theme"): core.add_menu_item("Dark", callback=theme_setting, callback_data="Dark") core.add_menu_item("Light", callback=theme_setting, callback_data="Light") core.add_menu_item("Classic", callback=theme_setting, callback_data="Classic") core.add_menu_item("Dark 2", callback=theme_setting, callback_data="Dark 2") core.add_menu_item("Grey", callback=theme_setting, callback_data="Grey") core.add_menu_item("Dark Grey", callback=theme_setting, callback_data="Dark Grey") core.add_menu_item("Cherry", callback=theme_setting, callback_data="Cherry") core.add_menu_item("Purple", callback=theme_setting, callback_data="Purple") core.add_menu_item("Gold", callback=theme_setting, callback_data="Gold") core.add_menu_item("Red", callback=theme_setting, callback_data="Red") with simple.menu(name="Database"): core.add_menu_item("Dump database", callback=dump_db) core.add_spacing(count=10) simple.hide_item("Main Menu")
class Menu: def theme_setting(sender, data): core.set_theme(data) with simple.window("Main Window"): with simple.menu_bar(name="Main Menu"): with simple.menu(name="Notifications"): with simple.menu("Set notifications"): core.add_menu_item("Every 30 minutes") core.add_menu_item("Every 1 hour") core.add_menu_item("Every 2 hours") core.add_menu_item("Disable") with simple.menu(name="Settings"): with simple.menu("Theme"): core.add_menu_item("Dark##Theme 1", callback=theme_setting, callback_data="Dark") core.add_menu_item("Light##Theme 2", callback=theme_setting, callback_data="Light") core.add_spacing(count=10)
def main(): center_items = [] core.add_data('item_center_list', center_items) with simple.window(TITLE): with simple.menu_bar('##menu_bar'): with simple.menu('File'): # core.add_menu_item('Import', callback=None) # core.add_menu_item('Export', callback=None) with simple.menu('Theme'): themes = ['Dark', 'Light', 'Classic', 'Dark 2', 'Grey', 'Dark Grey', 'Cherry', 'Purple', 'Gold', 'Red'] for theme in themes: core.add_menu_item(theme, callback=menu.update_theme) # core.add_menu_item('Exit', callback=None) with simple.menu('About'): core.add_menu_item('Version', callback=menu.show_version) with simple.group('##input_group'): # Title input core.add_text('Title:') core.add_input_text(TITLE_ID, hint='Enter title', width=WIDGET_WIDTH) core.add_spacing(count=2) # Identifier input core.add_text('Identifier:') core.add_input_text(IDENTIFIER_ID, hint='Enter identifier', width=WIDGET_WIDTH) core.add_spacing(count=2) # Password input core.add_text('Password:'******'Enter password', width=WIDGET_WIDTH) core.add_spacing(count=2) # Note input core.add_text('Note:') core.add_input_text(NOTE_ID, hint='Enter note info', width=WIDGET_WIDTH) core.add_spacing(count=10) # Save button save_clear_spacing = 50 core.add_button('##save', label='Save', callback=input_field.save_password, width=WIDGET_HALF_WIDTH - (save_clear_spacing // 2)) core.set_item_color('##save', core.mvGuiCol_Button, color=GREEN) core.add_same_line(spacing=save_clear_spacing) # Clear input entry button core.add_button('##clear_input', label='Clear input', callback=input_field.clear_input, width=WIDGET_HALF_WIDTH - (save_clear_spacing // 2)) core.add_spacing(count=20) with simple.group('##log_group'): # Logger core.add_logger('##log_message', auto_scroll_button=False, copy_button=False, filter=False, clear_button=False, width=WIDGET_WIDTH, height=80) core.set_log_level(core.mvTRACE, logger='##log_message') core.add_spacing(count=10) # Clear log button core.add_button('##clear_log', label='Clear log', callback=logger.clear_log, width=WIDGET_WIDTH) core.add_spacing(count=10) with simple.group('##password_table_group'): # Password table header = ['No', 'Title', 'Identifier', 'Password', 'Note'] core.add_table('##password_table', header, callback=table.table_printer, height=int(WINDOW_HEIGHT * 0.45), width=WIDGET_WIDTH) core.add_spacing(count=10) table.update_password_table() # Update password table button update_delete_spacing = 20 core.add_button('##update_table', label='Update table', callback=table.update_password_table, width=WIDGET_HALF_WIDTH - (update_delete_spacing // 2)) core.set_item_color('##update_table', core.mvGuiCol_Button, color=BLUE) core.add_same_line(spacing=update_delete_spacing) # Delete password table button core.add_button('##delete_table', label='Delete table', width=WIDGET_HALF_WIDTH - (update_delete_spacing // 2)) core.set_item_color('##delete_table', core.mvGuiCol_Button, color=RED) with simple.popup('##delete_table', '##ask_delete', mousebutton=core.mvMouseButton_Left, modal=True): with simple.group('##delete_table_button_group'): delete_table_spacing = 10 delete_table_half_width = core.get_main_window_size()[1] // 5 - delete_table_spacing core.add_text('##delete_table_button', default_value='Are you sure to delete all data?') core.add_spacing(count=delete_table_spacing) core.add_button('##delete_table_button_yes', label='Yes', callback=table.delete_password_table, callback_data=True, width=delete_table_half_width) core.add_same_line(spacing=delete_table_spacing) core.add_button('##delete_table_button_no', label='No', callback=table.delete_password_table, callback_data=False, width=delete_table_half_width) # TODO WONT WORK NEED TO FIX center_item FUNCTION # center_item('##delete_table_button') # center_item('##delete_table_button_yes') # center_item('##delete_table_button_no') # center_item('##delete_table_button_group') if DEBUG_MODE: # core.show_logger() simple.show_debug() # simple.show_documentation() # Common Configuration core.set_theme(DEFAULT_THEME) core.add_additional_font(FONT, FONT_SIZE) core.set_main_window_title(TITLE) core.set_main_window_size(WINDOW_WIDTH, WINDOW_HEIGHT) core.set_main_window_resizable(RESIZABLE) core.set_style_window_padding(WINDOW_PADDING, WINDOW_PADDING) core.set_exit_callback(model.close_connection) # core.set_render_callback(apply_centering) core.start_dearpygui(primary_window=TITLE)
dpg.set_style_scrollbar_rounding(12.00) # add child to enable scrollbars with dpgs.child('center-group-tiles', autosize_x=True, autosize_y=True, no_scrollbar=False, menubar=False, border=False, horizontal_scrollbar=False): dpg.add_dummy(name='left-spacer-tiles', width=0) dpg.add_same_line() with dpgs.group('item-to-center-tiles'): dpg.add_spacing(count=10) # # TILE BLOCK 1 # group added for consistent horizontal placement # with dpgs.group(name='button group 1', horizontal=True, horizontal_spacing=0): with dpgs.group(name='Tile 1', horizontal=False, horizontal_spacing=0): dpg.add_image_button('Demo 1', value='resources/tile_01.png',
def info_single_stock(self, data: dict): ticker = data["Ticker"] with window(ticker + "##window", width=500, height=500, no_scrollbar=False): self.menu(False, False, False, False) ticker_data = yfs.get_quote_table(ticker, dict_result=True) date_time = datetime.datetime.now() time = date_time.time() date = date_time.date() price = round(ticker_data["Quote Price"], 2) with group("heading", horizontal=True): with group("day_info"): gg.add_text("Date: " + str(date), color=[255, 0, 0]) gg.add_text("Time: " + str(time), color=[255, 0, 0]) try: gg.add_label_text("Current Shares", label=f"Number of shares: {self.user.share_quantity[ticker]}", color=[0, 255, 0]) except KeyError: gg.add_label_text("Current Shares", label=f"Number of shares: 0", color=[0, 255, 0]) with menu_bar("local_info"): gg.add_menu_item("ticker", label=ticker, enabled=False) gg.add_label_text("Current Balance", label=f"Current Balance: {self.user.current_balance}", color=[255, 0, 0]) gg.add_separator() gg.add_text("Today") gg.add_separator() with managed_columns("day_info_ticker", columns=3): gg.add_text("Last close: " + str(ticker_data["Previous Close"])) gg.add_text("Open price: " + str(ticker_data["Open"])) gg.add_text("Current price: " + str(price)) gg.add_separator() with group("Extra info", horizontal=True): with group("Extra Info##1"): gg.add_text("Volume: " + str(ticker_data["Volume"]), bullet=True) gg.add_text("Market Cap: " + str(ticker_data["Market Cap"]), bullet=True) with group("Extra info##2"): gg.add_text("52 Week Range: " + str(ticker_data["52 Week Range"]), bullet=True) one_year_estimate = ticker_data["1y Target Est"] percent_change = get_percent_change(price, one_year_estimate) if one_year_estimate > price: colour = [0, 255, 0] else: colour = [255, 0, 0] with group("1Y estimate", horizontal=True): gg.add_text(f"1y Target Estimate: {ticker_data['1y Target Est']} |", bullet=True) gg.add_text(f"{percent_change}%", color=colour) gg.add_spacing(count=5) # Table of share data on first day of each month since 365 days ago date_data_since = date - datetime.timedelta(365) table_monthly_interval_data = yfs.get_data(ticker, start_date=date_data_since, interval="1mo") gg.add_table("monthly_data", headers=["date"] + [header for header in table_monthly_interval_data]) for date_index in table_monthly_interval_data.index: list_values = [str(date_index)[:10]] list_values.extend(list(table_monthly_interval_data.loc[date_index])) for i in range(len(list_values)): if type(list_values[i]) == str: continue else: list_values[i] = str(round(list_values[i], 3)) gg.add_row("monthly_data", list_values) gg.add_spacing(count=2) def make_plot(): date_data_since = date - datetime.timedelta(30) scatter_plot_weekly_data = yfs.get_data(ticker, start_date=date_data_since, interval="1d") indecis = [x for x in scatter_plot_weekly_data.index] start_date = indecis[0] x_axis = [(x - start_date).days for x in indecis] y_axis_max = [scatter_plot_weekly_data.loc[x]['high'] for x in indecis] y_axis_min = [scatter_plot_weekly_data.loc[x]['low'] for x in indecis] gg.add_plot("30 Day Price Fluctuation", height=300, scale_max=.5, x_axis_name=f"Days since {start_date}", y_axis_name="Single share price") gg.add_scatter_series("30 Day Price Fluctuation", "Day High", x=x_axis, y=y_axis_max, size=3) gg.add_scatter_series("30 Day Price Fluctuation", "Day Low", x=x_axis, y=y_axis_min, marker=1, size=3) # Set initial plot view gg.set_plot_xlimits("30 Day Price Fluctuation", 0, 30) gg.set_plot_ylimits("30 Day Price Fluctuation", min(y_axis_min)*.97, max(y_axis_max)*1.03) gg.set_plot_ylimits_auto("30 Day Price Fluctuation") gg.set_plot_xlimits_auto("30 Day Price Fluctuation") make_plot() # Create purchase button and what not def purchase_stocks(sender, data): quantity = round(gg.get_value("Quantity"), 2) total_price = quantity * price gg.set_item_color("Message", style=1, color=[255, 0, 0]) if self.user.current_balance < total_price: set_item_label("Message", "Cannot purchase, insufficient funds") elif 0 >= total_price: set_item_label("Message", "Must spend more than 0$") else: set_item_label("Message", f"Purchase of {quantity} {ticker} shares at {price} made") gg.set_item_color("Message", style=1, color=[0, 255, 0]) self.user.buy_share(quantity, price, ticker, str(date), str(time)) set_item_label("Current Balance", f"Current Balance: {self.user.current_balance}") set_item_label("Current Shares", f"Number of shares: {self.user.share_quantity[ticker]}") def add_to_watchlist(sender, data): self.user.add_to_watchlist(ticker, price, database=True) set_item_label(sender, "Remove From Watchlist") gg.set_item_callback(sender, remove_from_watchlist) def remove_from_watchlist(sender, data): self.user.remove_from_watchlist(ticker) set_item_label(sender, "Add To Watchlist") gg.set_item_callback(sender, add_to_watchlist) with group("footer", horizontal=True): with group("Buy Stock Group"): def get_dynamic_cost(sender, data): # TODO dynamic colouring cost = round(gg.get_value("Quantity") * price, 2) set_item_label("Stock volume", f"Total Cost: {cost}") gg.add_input_float("Stock volume", default_value=0, width=100, source="Quantity", label="Total cost: 0", callback=get_dynamic_cost, on_enter=True) gg.add_label_text("Message", label="", color=[255, 0, 0]) gg.add_button("Buy Shares", callback=purchase_stocks) with group("Stock Watchlist"): if ticker not in self.user.watchlist: gg.add_button("Watchlist Button", callback=add_to_watchlist, label="Add To Watchlist") else: gg.add_button("Watchlist Button", callback=remove_from_watchlist, label="Remove From Watchlist")
def start(): """ Renders main window elements. """ with open('token.txt', 'r') as token_file: token = token_file.readline() try: # Connect to IBM core.run_async_function(get_backends_async, data=token) core.set_render_callback(show_button) # Progress bar with simple.window('Please wait', no_scrollbar=True, height=70, width=400, x_pos=500, y_pos=200): core.add_progress_bar('progress', value=0.0, overlay='Connecting to IBM...', width=400) core.run_async_function(progress_async, 0) # Menu bar with simple.menu_bar("Main Menu Bar"): with simple.menu("File"): core.add_menu_item("Save", callback=print_me) core.add_menu_item("Save As", callback=print_me) core.add_menu_item("Help", callback=open_help_window) core.add_menu_item("About", callback=open_about_window) # Parameters group with simple.group('left group', width=350): # Select file button core.add_child('##file_block', width=350, height=180, show=False) core.add_button('File Selector', callback=file_picker) core.add_spacing(name='##space2', count=3) core.add_text('File location:') core.add_label_text('##filedir', value='None Selected', source='directory') core.add_spacing(name='##space3', count=3) core.add_text('File name:') core.add_label_text('##file', value='None Selected', source='file_directory') core.end() core.add_spacing(name='##space4', count=3) # Architecture type radio button core.add_child('##settings_block', width=350, height=450, show=False) core.add_text('Architecture type:') core.add_radio_button('radio##1', items=[ 'IBM simulator', 'IBM quantum computer', 'Arbitrary computer coupling' ], callback=show_architecture_list, source='device_type') core.add_spacing(name='##space5', count=3) # "Create arbitrary coupling" button core.add_button('Create custom architecture', callback=create_architecture, show=False) core.add_spacing(name='##space11', count=3) # Layout radio button core.add_text('Quantum circuit layout method:') core.add_radio_button( 'radio##2', items=['Original IBM layout', 'Advanced SWAP placement'], source='layout_type') core.add_spacing(name='##space6', count=3) # Optimization level slider core.add_text('Optimization level:') core.add_slider_int( '##optimization_lvl', default_value=1, min_value=0, max_value=3, tip='drag the slider to select an optimization level', width=300, source='opt_level') core.add_spacing(name='##space7', count=3) # Number of iterations slider core.add_text('Number of iterations:') core.add_input_int('##num_of_iter', width=300, callback=check_iteration_num, default_value=100) core.add_spacing(name='##space8', count=3) # Default settings button core.add_button('Set Default', callback=set_default) core.end() core.add_spacing(name='##space9', count=3) # Process button core.add_button('Process', callback=process, show=False) # graph images core.add_same_line(name='line##3', xoffset=370) with simple.group('center group'): core.add_child('##images_block', width=640, show=False) # Input circuit preview core.add_text('Input circuit:') core.add_drawing('input_circuit', width=600, height=500) core.draw_rectangle('input_circuit', [0, 150], [600, 500], [255, 255, 255, 0], [255, 255, 255, 50]) # Output circuit view core.add_text('Output circuit:') core.add_drawing('output_circuit', width=600, height=500) core.draw_rectangle('output_circuit', [0, 150], [600, 500], [255, 255, 255, 0], [255, 255, 255, 50]) core.end() # program output core.add_same_line(name='line##3', xoffset=1020) with simple.group('right group'): core.add_child('##output_block1', width=460, height=300, show=False) core.add_button('Open qasm file', callback=open_qasm) core.add_text('Path to IBM circuit representation') core.add_label_text('##circuitImage') core.add_button('Mapping', callback=show_mapping) core.end() core.add_text('Program output:', show=False) core.add_child('##output_block2', width=460, height=180, show=False) core.add_text('Program output will be displayed here', wrap=440) core.end() except Exception as exc: print("[ERROR]: {}".format(exc))
def _setup_add_widget(self, dpg_args) -> None: dpgcore.add_spacing(name=self.id, **dpg_args)
def start(self): available_out_ports = mido.get_output_names() available_in_ports = mido.get_input_names() if len(available_in_ports) > 0: status.current_in_port = mido.open_input( available_in_ports[0], callback=self.get_midi_input) if len(available_out_ports) > 0: self.out_port = mido.open_output(available_out_ports[0]) core.set_main_window_size(350, 550) core.set_main_window_title('Fractal Melody Machine') core.set_theme('Gold') with simple.window('Fractal Melody Machine', width=500, height=300): core.add_text('MIDI Input Port') core.add_combo('ComboInPort', items=mido.get_input_names( ), default_value=status.current_in_port.name, label='', width=100, callback=self.change_midi_in_port) core.add_text('MIDI Output Port') core.add_combo('ComboOutPort', items=mido.get_output_names( ), default_value=self.out_port.name, label='', width=100, callback=self.change_midi_out_port) core.add_spacing(count=10) core.add_text('BPM') core.add_slider_int('SliderBPM', default_value=60, min_value=20, max_value=200, label='', width=100, callback=self.change_bpm) core.add_text('Depth') core.add_slider_int('SliderDepth', default_value=4, min_value=1, max_value=16, label='', width=100, callback=self.change_depth) core.add_same_line(spacing=45) core.add_text('DetectedKey', default_value='Detected Key: ') core.add_text('Branching Factor') core.add_slider_int('SliderBF', default_value=2, min_value=2, max_value=4, label='', width=100, callback=self.change_bf) core.add_text('Octave Spread') core.add_child('OctaveWindow', width=300, height=150) core.end() core.add_text('Figures') core.add_child('FigureWindow', width=300, height=150) core.add_table('FigureTable', [], hide_headers=True, height=10) core.add_columns('FigureTableCols', 2, border=False) core.add_checkbox(str(theory.FIGURE_WHOLE_NOTE), label='Whole note', callback=self.change_figures) core.add_checkbox(str(theory.FIGURE_QUARTER_NOTE), label='Quarter note', callback=self.change_figures, default_value=True) core.add_checkbox(str(theory.FIGURE_16TH_NOTE), label='16th note', callback=self.change_figures) core.add_checkbox(str(theory.FIGURE_64TH_NOTE), label='64th note', callback=self.change_figures) core.add_next_column() core.add_checkbox(str(theory.FIGURE_HALF_NOTE), label='Half note', callback=self.change_figures) core.add_checkbox(str(theory.FIGURE_8TH_NOTE), label='8th note', callback=self.change_figures, default_value=True) core.add_checkbox(str(theory.FIGURE_32ND_NOTE), label='32nd note', callback=self.change_figures) core.end() # Initialize octave spread sliders self.change_depth() core.start_dearpygui(primary_window='Fractal Melody Machine')
def show_main(): logging.info("start show_main") global start_threading heigh, iCountMatch, iCountFaceit = config_functions.check_for_layout() name = config_functions.get_faceit_name_from_db() with simple.window(f"{name} Elo", height=heigh, width=190, no_title_bar=True, no_resize=True, on_close=lambda: delete_item("FACEIT Elo Overlay"), x_pos=200): logging.info("Build the window") simple.set_window_pos(f"{name} Elo", 0, 0) core.set_main_window_title(f"{name} Elo") core.set_main_window_size(width=250, height=heigh) # Now the magic happens ! core.set_style_frame_rounding(6.00) with simple.group("##Loading"): core.add_spacing(count=20) core.add_text("##LoadingText", default_value="Getting data from Faceit servers") """ Get Data from the API """ winLoss = config_functions.get_win_loss() if winLoss[0][0] == "1": mode = 0 else: mode = 1 logging.info("Get data from the API") iElo, acEloToday, iRank, \ acResult, acScore, acKd, \ acMap, iStreak, iMatches, \ iMatchesWon, acEloDiff, iKills, \ iDeath, iWin, iLoss = faceit_api.get_faceit_data_from_api(mode) """ Build the Faceit Header and Data """ if iCountFaceit > 0: logging.info("Build the window for Faceit stats") add_faceit(iElo, iRank, acEloToday, iStreak, iMatches, iMatchesWon, iWin, iLoss) """ Build the Last Game Header and Data """ if iCountMatch > 0: logging.info("Build the window for Match stats") add_last_game(acMap, acResult, acScore, acKd, acEloDiff, iKills, iDeath) """ ! Add some promotion ! """ core.add_spacing(count=1) core.add_text("powered by Dear PyGui") core.add_same_line() core.add_image("image##DPG", "resources/6727dpg.ico") simple.hide_item("##Loading") core.enable_docking(dock_space=False) hwnd = win32gui.GetForegroundWindow() win32gui.SetWindowText(hwnd, f"{name} Elo") start_threading = 1 long_process()
def create_convert_window(self, payload: Payload): """ Creates a convert window. This window represents a file. From this window you can convert the file to text. Then translate the text. And finally you can save it to a file. The window has 3 tabs. The first tab contains all the controls for: - converting the file - translated the converted file - save the text to disk - save ethe translation to disk :param payload: Payload object :return: """ unique_id = self._get_uid() window_title = f'{payload.file_name}_{str(unique_id)}' convert_window = simple.window(window_title, width=450, height=600, y_pos=0 + (20 * unique_id), x_pos=200 + (20 * unique_id)) with convert_window: # widget ids top_spacer = f'top_{unique_id}' bottom_spacer = f'bottom_{unique_id}' convert_button = f'convert_{unique_id}' translate_button = f'translate_{unique_id}' save_text_button = f'save_text_{unique_id}' save_translation_button = f'save_translation_{unique_id}' text_spacer = f'text_spacer_{unique_id}' translated_text_spacer = f'translated_text_spacer_{unique_id}' tab_bar_name = f'tab_bar_{unique_id}' tab_names = [ f'controls_{unique_id}', f'text_{unique_id}', f'translated_{unique_id}' ] tabs = [] text_value_name = f'text_{unique_id}' # the name of the value holding the text gathered from OCR source_lang_combo_name = f'text_language{unique_id}' destination_lang_combo_name = f'destination_language{unique_id}' translated_text_value_name = f'translated_text_{unique_id}' # the name of the value holding the translation core.add_value(text_value_name, '') # the value that stores the OCR text core.add_value(translated_text_value_name, '') # the value that stores the translated text # Creating widgets tab_bar = simple.tab_bar(tab_bar_name) with tab_bar: tabs += [simple.tab(tab_names[0], label="Controls")] tabs += [simple.tab(tab_names[1], label="Text")] tabs += [simple.tab(tab_names[2], label="Translation")] # creating the control tab with tabs[0]: core.add_text(payload.file_name) core.add_spacing(count=1, name=top_spacer) core.add_spacing(count=1, name=bottom_spacer) language_list = list(lang.keys()) core.add_combo(source_lang_combo_name, label='Source Language', items=language_list, default_value=core.get_value( 'default_source_language')) core.add_combo(destination_lang_combo_name, label='Destination Language', items=language_list, default_value=core.get_value( 'default_destination_language')) # Creating payload for the convert button convert_payload = Payload() convert_payload.value_name = text_value_name convert_payload.file_path = payload.file_path convert_payload.parent = window_title convert_payload.disable = [convert_button] convert_payload.enable = [ translate_button, save_text_button ] core.add_button(convert_button, label='Convert to Text', callback=self.convert_file, callback_data=convert_payload) translate_payload = Payload() translate_payload.value_name = text_value_name translate_payload.destination_value_name = translated_text_value_name translate_payload.source_language_value = source_lang_combo_name translate_payload.destination_language_value = destination_lang_combo_name translate_payload.disable = [translate_button] translate_payload.enable = [ translate_button, save_translation_button ] core.add_button(translate_button, label='Translate Text', enabled=False, callback=self.translate_text, callback_data=translate_payload) save_text_payload = Payload() save_text_payload.value_name = text_value_name core.add_button(save_text_button, label='Save Text', callback=self.save_prompt, callback_data=save_text_payload, enabled=False) save_translation_payload = Payload() save_translation_payload.value_name = translated_text_value_name core.add_button(save_translation_button, label='Save Translation', callback=self.save_prompt, callback_data=save_translation_payload, enabled=False) # creating the Text tab with tabs[1]: core.add_text('File Text:') core.add_spacing(count=1, name=text_spacer) # this is the text box that holds the text extracted with OCR core.add_text(f'text_box_{unique_id}', source=text_value_name) # creating the Translation tab with tabs[2]: core.add_text('Translated text:') core.add_spacing(count=1, name=translated_text_spacer) # this is the text box that holds the translated text response core.add_text(f'translated_text_box_{unique_id}', source=translated_text_value_name) # add the window to the window list self.convert_window_list += [convert_window]
def open_help_window(sender, data): """ Opens new window with help annotations """ with simple.window('Help##window', width=1000, height=600, on_close=delete_items(['Help##window'])): with simple.tab_bar("Help tabs"): with simple.tab('Architectures##help'): core.add_drawing('armonk', width=72, height=75) core.draw_image('armonk', './backends/armonk.png', [72, 72]) core.add_text('ibmq_armonk: 1 qubit.') core.add_spacing(name='##space10', count=10) core.add_drawing('athens', width=518, height=75) core.draw_image('athens', './backends/athens-santiago.png', [0, 72]) core.add_text('ibmq_athens and ibmq_santiago: 5 qubits.') core.add_spacing(name='##space12', count=10) core.add_drawing('yorktown', width=373, height=400) core.draw_image('yorktown', './backends/ibmqx2.png', [0, 400]) core.add_text('ibmqx2: 5 qubits.') core.add_spacing(name='##space13', count=10) core.add_drawing('melb', width=1000, height=196) core.draw_image('melb', './backends/melbourne.png', [0, 196]) core.add_text('ibmq_16_melbourne: 15 qubits.') core.add_spacing(name='##space14', count=10) with simple.tab('Instructions##help'): core.add_text( '1. In the Selector block a user can select optimization parameters:' ) core.add_spacing(name='##text_spacing1', count=5) core.add_text( '* the level of optimization provided by IBM Q (ranging from 0 to 3)' ) core.add_text( '* IBM Original layout or advanced SWAP placement') core.add_text('* location of placement') core.add_text('* number of iterations.') core.add_spacing(name='##text_spacing2', count=5) core.add_text( '2. In the Hardware & Circuit block choose between testing the circuit on a quantum computer (IBM Q) and simulator (Qasm).', wrap=900) core.add_spacing(name='##text_spacing3', count=5) core.add_text( '3. Choose quantum coupling (quantum computer architecture) - IBM Q or Qasm.', wrap=900) core.add_spacing(name='##text_spacing4', count=5) core.add_text( '4. Upload an input file. After selection, the file name will be displayed in the Hardware & Circuit block and the circuit representation will be displayed in the Circuit before the reduction block.', wrap=900) core.add_spacing(name='##text_spacing5', count=5) core.add_text( '5. When pressing on the Process button the tool will find the optimal mapping of the circuit onto the quantum computer architecture.', wrap=900) core.add_spacing(name='##text_spacing6', count=5) core.add_text( '6. The resulting mapping will appear in the Circuit after the reduction block.', wrap=900)
def start_build_dpg(): with simple.window("FACEIT Elo Overlay", on_close=lambda: delete_item("FACEIT Elo Overlay"), no_title_bar=True, no_resize=True): """ Set window configurations """ simple.set_window_pos("FACEIT Elo Overlay", 0, 0) core.set_main_window_title("FACEIT Elo Overlay") core.set_main_window_size(492, 830) core.set_style_frame_rounding(6.00) core.add_additional_font("resources/OpenSans-Bold.ttf", size=14.5) """ Initial loads """ db_create.create_database(DBNAME) COLOR_List = config_functions.get_color() """ Set some Background and Font Colors also the frame rounding and the window size """ core.set_theme_item(mvGuiCol_Text, COLOR_List[1][0], COLOR_List[1][1], COLOR_List[1][2], COLOR_List[1][3]) core.set_theme_item(mvGuiCol_WindowBg, COLOR_List[3][0], COLOR_List[3][1], COLOR_List[3][2], COLOR_List[3][3]) core.set_theme_item(mvGuiCol_Border, COLOR_List[4][0], COLOR_List[4][1], COLOR_List[4][2], COLOR_List[4][3]) core.set_style_frame_border_size(1.00) core.set_theme_item(mvGuiCol_Button, COLOR_List[0][0], COLOR_List[0][1], COLOR_List[0][2], COLOR_List[0][3]) core.set_theme_item(mvGuiCol_ButtonHovered, COLOR_List[0][0], COLOR_List[0][1], COLOR_List[0][2], COLOR_List[0][3]) core.set_theme_item(mvGuiCol_ButtonActive, COLOR_List[2][0], COLOR_List[2][1], COLOR_List[2][2], COLOR_List[2][3]) core.set_theme_item(mvGuiCol_BorderShadow, COLOR_List[0][0], COLOR_List[0][1], COLOR_List[0][2] - 50, COLOR_List[0][3]) with simple.window('##Overlay', no_collapse=True, no_resize=True, no_move=True, no_close=True, x_pos=30, y_pos=0, width=445, height=790, no_title_bar=True): """ Set a Header """ bool_list_faceit, bool_list_match, name, acEloGoal = startup() core.add_button("FACEIT Overlay Menu") core.set_item_style_var("FACEIT Overlay Menu", mvGuiStyleVar_FramePadding, [5 * 27, 5 * 3]) core.add_spacing(count=5) """ Build up the FACEIT Stats configuration """ with simple.group("##GroupStats"): core.add_button("Default Configurations##STATS") core.set_item_style_var("Default Configurations##STATS", mvGuiStyleVar_FramePadding, [5 * 20, 5 * 3]) core.add_spacing(count=5) core.add_text("##TextFaceitName", default_value="FACEIT Name:", color=(255, 255, 0, -1)) core.add_input_text("##FaceitName", hint="FACEIT Name Case sensitive", default_value=name, callback=changes_detected) core.add_spacing(count=2) core.add_text("##TextEloGoal", default_value="FACEIT Elo goal:") core.add_input_text("##EloGoal", hint="Set your Elo goal, empty = disabled", default_value=str(acEloGoal), callback=changes_detected) core.add_spacing(count=5) """ Faceit Stats header """ core.add_button("FACEIT Stats") core.set_item_style_var("FACEIT Stats", mvGuiStyleVar_FramePadding, [5 * 26, 5 * 3]) core.add_spacing(count=2) """ Checkbox group """ core.add_checkbox( "Disable All##stats", default_value=False, callback=lambda sender, data: disable_all(sender)) core.add_same_line() core.add_checkbox("Enable All##stats", default_value=False, callback=lambda sender, data: enable_all(sender)) core.add_spacing(count=3) """ Checkbox group """ core.add_checkbox("Current Elo##stats", default_value=bool_list_faceit[0], callback=changes_detected) core.add_same_line(xoffset=250) core.add_checkbox("Faceit Rank##stats", default_value=bool_list_faceit[1], callback=changes_detected) """ Checkbox group """ core.add_checkbox("Elo Gained today##stats", default_value=bool_list_faceit[2], callback=changes_detected) core.add_same_line(xoffset=250) core.add_checkbox("Win Streak##stats", default_value=bool_list_faceit[3], callback=changes_detected) """ Checkbox group """ core.add_checkbox("Total Matches##stats", default_value=bool_list_faceit[4], callback=changes_detected) core.add_same_line(xoffset=250) core.add_checkbox("Matches Won##stats", default_value=bool_list_faceit[5], callback=changes_detected) core.add_spacing(count=2) win_loss = config_functions.get_win_loss() print(win_loss) if win_loss[0][0] is None: win_loss = [(0, 0)] core.add_text("##TextWinLoss", default_value="Win/Loss Stats:") core.add_checkbox("Day##WinLoss", default_value=int(win_loss[0][0]), callback=lambda sender, data: win_los(sender)) core.add_same_line() core.add_checkbox("Week##WinLoss", default_value=int(win_loss[0][1]), callback=lambda sender, data: win_los(sender)) core.add_spacing(count=5) """ Last Match header """ core.add_button("Last Match") core.set_item_style_var("Last Match", mvGuiStyleVar_FramePadding, [5 * 26.5, 5 * 3]) core.add_spacing(count=2) """ Checkbox group """ core.add_checkbox( "Disable All##match", default_value=False, callback=lambda sender, data: disable_all(sender)) core.add_same_line() core.add_checkbox("Enable All##match", default_value=False, callback=lambda sender, data: enable_all(sender)) core.add_spacing(count=3) """ Checkbox group """ core.add_checkbox("Score##match", default_value=bool_list_match[0], callback=changes_detected) core.add_same_line(xoffset=250) core.add_checkbox("Result (W/L)##match", default_value=bool_list_match[1], callback=changes_detected) """ Checkbox group """ core.add_checkbox("Map##match", default_value=bool_list_match[2], callback=changes_detected) core.add_same_line(xoffset=250) core.add_checkbox("K/D##match", default_value=bool_list_match[3], callback=changes_detected) """ Checkbox group """ core.add_checkbox("Elo Diff##match", default_value=bool_list_match[4], callback=changes_detected) core.add_same_line(xoffset=250) core.add_checkbox("Kills##match", default_value=bool_list_match[5], callback=changes_detected) """ Checkbox group """ core.add_checkbox("Death##match", default_value=bool_list_match[6], callback=changes_detected) core.add_spacing(count=5) """ Apply Configuration to the database Button """ core.add_button("Apply Configuration", callback=save_data) """ Start the Overlay with the current configuration """ core.add_spacing(count=3) core.add_button("Start", callback=open_overlay) core.set_item_style_var("Start", mvGuiStyleVar_FramePadding, [5 * 29.5, 5 * 3]) with simple.window('##Config', no_collapse=True, no_resize=True, no_move=True, no_close=True, x_pos=0, y_pos=1, width=20, height=790, no_title_bar=True): core.set_item_color("##Config", mvGuiCol_Text, color=(COLOR_List[1][0], COLOR_List[1][1], COLOR_List[1][2], COLOR_List[1][3])) core.set_item_color("##Config", mvGuiCol_WindowBg, color=(COLOR_List[3][0], COLOR_List[3][1], COLOR_List[3][2], COLOR_List[3][3] - 10)) core.set_item_style_var("##Config", mvGuiStyleVar_WindowRounding, value=[6]) core.set_item_color("##Config", mvGuiCol_Border, color=(COLOR_List[4][0], COLOR_List[4][1], COLOR_List[4][2], COLOR_List[4][3])) core.add_image_button("##ConfigPlus", value="resources/cfg_wheel.png", callback=animation_config_color, frame_padding=1, tip="Settings & Colors") core.add_same_line(xoffset=50) with simple.group("##Config_Colors", show=False): COLOR_List = config_functions.get_color() core.add_text( "You can type in the RBG Values or click on the right Color Button" ) core.add_color_edit4(name="Header#Color", default_value=[ COLOR_List[0][0], COLOR_List[0][1], COLOR_List[0][2], COLOR_List[0][3] ], label="Header") core.add_color_edit4(name="Text#Color", default_value=[ COLOR_List[1][0], COLOR_List[1][1], COLOR_List[1][2], COLOR_List[1][3] ], label="Text") core.add_color_edit4(name="ButtonActive#Color", default_value=[ COLOR_List[2][0], COLOR_List[2][1], COLOR_List[2][2], COLOR_List[2][3] ], label="Button Active") core.add_color_edit4(name="BG#Color", default_value=[ COLOR_List[3][0], COLOR_List[3][1], COLOR_List[3][2], COLOR_List[3][3] ], label="Background") core.add_color_edit4(name="Outline#Color", default_value=[ COLOR_List[4][0], COLOR_List[4][1], COLOR_List[4][2], COLOR_List[4][3] ], label="Outline") core.add_separator() core.add_button("Test Colors", callback=test_colors) core.add_same_line() core.add_button("Reset", callback=reset_colors) core.add_button("Save Colors", callback=save_colors) core.add_spacing(count=2) core.add_separator() core.add_separator() core.add_spacing(count=2) scale = config_functions.get_scale() core.set_global_font_scale(scale) core.add_text("Change The Global Font Size") core.add_drag_float( "Global Scale", default_value=scale, format="%0.2f", speed=0.01, callback=lambda sender, data: core.set_global_font_scale( core.get_value("Global Scale"))) core.add_button("Reset##1", callback=reset_scale) core.add_button("Save Size##1", callback=save_scale) core.add_spacing(count=2) core.add_separator() core.add_separator() core.add_spacing(count=2) refresh = config_functions.get_refresh() refreshSymbol = config_functions.get_refresh_sign() core.add_text( "Change The refresh time for the Overlay ( in seconds )") core.add_input_int("##RefreshTime", default_value=refresh, min_value=5, step=0) core.add_button("Save refresh time##1", callback=save_refresh_time) if refreshSymbol in "True": refreshSymbol = True else: refreshSymbol = False core.add_spacing(count=2) core.add_text("Enable, Disable the refresh sign in the overlay") core.add_checkbox("Refresh Symbol##RefreshTime", default_value=refreshSymbol, callback=refresh_symbol) core.add_separator() core.add_separator() core.add_button("Close##Color", callback=animation_config_color) core.add_spacing(count=3) core.add_image_button("##ConfigWeb", value="resources/web.png", callback=animation_config_web, frame_padding=1, tip="Web") core.add_spacing(count=2) core.add_image_button("##ConfigQuestion", value="resources/q.png", callback=animation_config_help, frame_padding=1, tip="Help") core.add_same_line(xoffset=50) with simple.group("##Web", show=False): web = webFunctions.get_web() web_parameters = webHandler.get_web_parameters() print(web_parameters) bgimage = "" core.add_text("Browser Settings") core.add_checkbox("Open in Browser Only##Browser", default_value=web[0], callback=lambda sender, data: save_web()) core.add_same_line() core.add_checkbox("Open in Browser and App##Browser", default_value=web[1], callback=lambda sender, data: save_web()) core.add_spacing(count=2) core.add_text("Text Size (pixel)") core.add_input_int("##BrowserTextSize", default_value=web_parameters[0][0], min_value=5, step=0, callback=save_font) core.add_text("Text Font:") core.add_combo("Font Family##Web", items=WEB_FONT, default_value=web_parameters[0][1], callback=save_font) core.add_spacing(count=2) core.add_text(name="Background Image##Web", default_value="Background Image") core.add_input_text("##BgImage", default_value=web_parameters[0][2], readonly=True) core.add_button("Search Background Image##Web", callback=openFileDialog.get_background_image, callback_data=bgimage) core.add_same_line() core.add_button( "Delete Background Image##Web", callback=lambda sender, data: core.set_value("##BgImage", "")) core.add_separator() core.add_separator() core.add_button("Close##Web", callback=animation_config_web) with simple.group("##Help", show=False): core.add_text("OUTDATED, WILL BE UPDATED IN THE NEXT RELEASE") core.add_input_text( "##HelpIntroText", multiline=True, readonly=True, height=110, width=340, default_value="Welcome to the help page of the Faceit Overlay\n" "here the options and different possibilities are\n" "explained to you.\n" "Here is a small overview;\n" "1: Start menu\n" "2: Color configuration\n" "3: Overlay") core.add_spacing(count=2) core.add_text("1: Start menu") core.add_image("##StartmenuImage", value="resources/start_menu.png") core.add_input_text( "##HelpStartMenuText", multiline=True, height=70, width=340, readonly=True, default_value="The start menu is the configuration menu\n" "Here you can change colors, global size\n" "Enable / disable stats you want to see\n" "and start the Overlay") core.add_spacing(count=2) core.add_text("2: Color configuration") core.add_image("##ColorconfImage", value="resources/color_config.png") core.add_input_text( "##HelpColorConfigText", multiline=True, height=220, width=340, readonly=True, default_value= "Here you can adjust the colors according to your own taste.\n" "The buttons have the following functions:\n\n" "Test Color: Sets the color for the menu so that you can check it.\n" "Reset Color: Sets the colors back to the default value.\n" "Save Color: Saves the colors so that they will be kept\n" "\t\t\t\t\t on the next startup.\n\n" "To adjust the global size of the texts and heads you can move \n" "the slider to the left or right and then use the buttons \n" "to perform the following functions:\n\n" "Reset: Set the size back to 1.0\n" "Save Size: Save the global size for the next start up") core.add_spacing(count=2) core.add_text("3: Overlay") core.add_image("##OverlayImage", value="resources/overlay.png") core.add_input_text( "##HelpOverlayText", multiline=True, height=100, width=340, readonly=True, default_value= "The overlay has basically no functionalities except \n" "that it updates itself regularly (every 60 seconds) \n" "and thus adjusts the values.\n" "But if you click on the headers \n" "FACEIT STATS | LAST GAME you get back to the start screen.\n" ) core.add_button("Close##Help", callback=animation_config_help) """ --------------------------------------------------------------------------------------------------------------- START DPG -------------------------------------------------------------------------------------------------------------""" core.enable_docking(dock_space=False) core.start_dearpygui(primary_window="FACEIT Elo Overlay")
def build(self): with simple.window("game_win", autosize=True): with simple.group("player"): left_label_text("Round: ", "round", default_value=str(self.round)) left_label_text("Player: ", "player", default_value=self.player.name) left_label_text("Cash: ", "cash", default_value=str(self.player.cash)) core.add_spacing(count=5) core.add_button("next_round", label="Next round", callback=self.next_round) core.add_spacing(count=5) core.add_separator() core.add_spacing(count=5) with simple.group("stocks"): # Titles core.add_text("Company") core.add_same_line(xoffset=stock_table_offsets[1]) core.add_text("Price") core.add_same_line(xoffset=stock_table_offsets[2]) core.add_text("Owned") core.add_same_line(xoffset=stock_table_offsets[3]) core.add_text("Change") core.add_same_line(xoffset=stock_table_offsets[4]) core.add_text("Old price") core.add_same_line(xoffset=stock_table_offsets[5]) core.add_text("New price") core.add_same_line(xoffset=stock_table_offsets[6]) core.add_text("Dividend") for stock in self.stocks: core.add_text(stock.name) core.add_same_line(xoffset=stock_table_offsets[1]) core.add_text(f"stock.{stock.name}.price", default_value=str(stock.price)) core.add_same_line(xoffset=stock_table_offsets[2]) # Buy / Sell functionality core.add_input_int( f"stock.{stock.name}.owned", label="", default_value=self.player.get_owned_stocks(stock), max_value=int(self.player.cash / stock.price), min_clamped=True, max_clamped=True, callback=self.buy_or_sell, callback_data=[ stock, ], width=100, ) core.add_same_line(xoffset=stock_table_offsets[3]) core.add_text(f"stock.{stock.name}.change", default_value=str(stock.change)) core.add_same_line(xoffset=stock_table_offsets[4]) core.add_text( f"stock.{stock.name}.previous_price", default_value=str(stock.previous_price), ) core.add_same_line(xoffset=stock_table_offsets[5]) core.add_text(f"stock.{stock.name}.price2", default_value=str(stock.price)) core.add_same_line(xoffset=stock_table_offsets[6]) core.add_text( f"stock.{stock.name}.dividend", default_value=str(stock.dividend), ) core.set_main_window_title("Stock Trader") core.set_main_window_size(650, 450) core.set_main_window_resizable(False)
def show(self): """Start the gui.""" with sdpg.window("Main Window"): dpg.set_main_window_size(550, 650) dpg.set_main_window_resizable(False) dpg.add_spacing() dpg.set_main_window_title("Dearpygui File Zip") dpg.add_spacing() dpg.add_text("File Zip App") dpg.add_spacing() dpg.add_text("Select files to zip by adding them to the table", bullet=True) dpg.add_text("Set the output directory", bullet=True) dpg.add_text("Click on the table to remove a file", bullet=True) dpg.add_text("Click on the zip files button to zip all the files", bullet=True) dpg.add_text( "If you do not choose a directory, it will by default be" "the same directory from where you've run this script.", bullet=True) dpg.add_spacing() dpg.add_separator() dpg.add_spacing(count=10) dpg.add_button("Select output directory", width=250, callback=self.__select_output_directory) dpg.add_same_line() dpg.add_button("Add file", width=250, callback=self.__select_file) dpg.add_spacing(count=10) dpg.add_separator() dpg.add_text("Selected output directory:") dpg.add_table('Files', ['Path', 'Name'], height=200, callback=self.__remove_file) dpg.add_separator() dpg.add_progress_bar('Zip Progress', width=-1) dpg.add_separator() dpg.add_button("Clear files", width=250, callback=self.__clear_files) dpg.add_same_line() dpg.add_button("Zip Files", width=250, callback=self.__zip_files) dpg.add_spacing() dpg.add_label_text('##warnings') # Render Callback and Start gui dpg.set_render_callback(self.__render) dpg.start_dearpygui(primary_window="Main Window")
def run(self, width: int = 700, height: int = 800, **kwargs): # pylint: disable=arguments-differ """ GUI definition and runs dearpygui :param width: pixel width of main window :param height: pixel height of main window :param kwargs: any simple.window kwargs :return:GUI although more probably 'void' """ if self.development: x_pos = 300 else: x_pos = 0 with s.window( name="Timer", x_pos=x_pos, y_pos=0, width=width, height=height, no_close=True, no_title_bar=True, no_resize=not self.development, no_move=not self.development, no_bring_to_front_on_focus=True, **kwargs, ): with s.menu_bar("Main Menu Bar"): with s.menu("Projects##ProjectMenu"): for name in self.db.get_project_names(): c.add_menu_item(name=name, callback=self.select_project, callback_data=name) c.add_menu_item("Add project", callback=self.create_new_project) with s.menu("Range##FilterMenu"): c.add_menu_item(name="Today", callback=self.filter_entries, check=False) c.add_menu_item(name="All Time", callback=self.filter_entries, check=True) settings_menu.create_menu() c.add_spacing(count=40) c.add_input_text(name="Description", default_value="coding", label="Description") c.add_button(name="Start Timer", callback=self.flip_timer_state) c.add_same_line() c.add_button(name="Switch Task", callback=self.switch_task, show=False) c.add_spacing() entry_table.create_table(input_data=self.entries) c.add_spacing() task_chart.create_chart(data=[0.2, 0.5, 0.3], labels=self.db.get_project_names()) timer_display.create_timer(x_pos=(x_pos + 60), y_pos=20) c.set_render_callback(self.render) c.start_dearpygui()