def _show_custom_ui(self): width = 250 height = 100 draw_list = imgui.get_window_draw_list() plot_start = imgui.get_cursor_screen_pos() imgui.push_style_color(imgui.COLOR_PLOT_LINES, 0.8, 0.8, 0.8, 1.0) imgui.plot_lines("", self._beat_value_buffer.contents * self.get("gain"), 0.0, 1.0, (width, height)) imgui.pop_style_color() plot_size = imgui.get_item_rect_size() beat_risings = self._beat_rising_buffer.contents count = self._beat_rising_buffer.size for i, beat_rising in enumerate(beat_risings): if not beat_rising: continue x = i / (count - 1) * width line_start = plot_start[0] + x, plot_start[1] line_end = plot_start[0] + x, plot_start[1] + height draw_list.add_line(line_start, line_end, imgui.get_color_u32_rgba(0.0, 0.8, 0.0, 0.8)) threshold = min(1.0, max(0.0, self.get("threshold"))) threshold_start = plot_start[0], plot_start[1] + (1.0 - threshold) * height threshold_end = plot_start[0] + width, threshold_start[1] draw_list.add_line(threshold_start, threshold_end, imgui.get_color_u32_rgba(0.8, 0.0, 0.0, 0.8))
def to_imgui(self, file_entry: FileEntry, padding: int): for entry in file_entry.entries: start, end = self.range_for_entry(entry, padding) for i in range(start, end + 1): if i >= self.max_line: break text = self.content[i] in_range = i in range(entry.begin_line, entry.end_line + 1) if in_range: imgui.push_style_color(imgui.COLOR_TEXT, 0.0, 1.0, 0.0) imgui.text("{0:03d} {1}".format(i, text)) if in_range: imgui.pop_style_color(1) if entry is not file_entry.entries[-1]: imgui.spacing() imgui.separator() imgui.spacing()
def placeholder(self): # Give a style to the button imgui.push_style_color(imgui.COLOR_BUTTON, *self.KEY_COLOR_BLACK) # Create a button "PLACEHOLDER" if imgui.button("...", width=self.BTN_WIDTH, height=self.BTN_HEIGHT): # Execute code when button is pressed pass # PLACEHOLDER # push style imgui.pop_style_color(1)
def _show_custom_ui(self): imgui.push_item_width(widget.WIDGET_WIDTH) if self.duplicate: imgui.push_style_color(imgui.COLOR_TEXT, 1.0, 0.0, 0.0) changed, v = imgui.input_text("", self.get("name"), 255, imgui.INPUT_TEXT_ENTER_RETURNS_TRUE) if self.duplicate: imgui.pop_style_color() if imgui.is_item_hovered(): imgui.set_tooltip("Name is a duplicate!") if changed: self.name = v
def disableable_button(*args, **kwargs): disabled = not kwargs.pop('enabled') if disabled: ig.push_style_var(ig.STYLE_ALPHA, 0.5) ig.push_style_color(ig.COLOR_BUTTON_HOVERED, *ig.get_style().colors[ig.COLOR_BUTTON]) ig.push_style_color(ig.COLOR_BUTTON_ACTIVE, *ig.get_style().colors[ig.COLOR_BUTTON]) result = ig.button(*args, **kwargs) if disabled: ig.pop_style_color() ig.pop_style_color() ig.pop_style_var() return result
def highlighted_button(text, start_time, time): highlight = time > start_time and (time - start_time) < 5 if highlight: imgui.push_id(str(3)) r, g, b = colorsys.hsv_to_rgb(0 / 7.0, 0.6, 0.6) imgui.push_style_color(imgui.COLOR_BUTTON, r, g, b) r, g, b = colorsys.hsv_to_rgb(0 / 7.0, 0.7, 0.7) imgui.push_style_color(imgui.COLOR_BUTTON_HOVERED, r, g, b) r, g, b = colorsys.hsv_to_rgb(0 / 7.0, 0.8, 0.8) imgui.push_style_color(imgui.COLOR_BUTTON_ACTIVE, r, g, b) return_value = imgui.button(label=text) if highlight: imgui.pop_style_color(3) imgui.pop_id() return return_value
def do_gui(self): imgui.new_frame() imgui.set_next_window_position(self.width, 0, pivot_x=1.0) imgui.begin("win", closable=False, flags=imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_RESIZE) changed, self.time_per_div_selected = imgui.combo( "TIME/DIV", self.time_per_div_selected, [str(option) for option in TIME_PER_DIV_OPTIONS]) if changed: self.time_per_div = TIME_PER_DIV_OPTIONS[ self.time_per_div_selected] changed, self.y_per_div_selected = imgui.combo( "Y/DIV", self.y_per_div_selected, [str(option) for option in Y_PER_DIV_OPTIONS]) if changed: self.y_per_div = Y_PER_DIV_OPTIONS[self.y_per_div_selected] imgui.text("Values") for addr in self.addresses: color_changed = False if addr in self.lines: # Change text color to indicate the color of plot r, g, b = self.line_colors[addr] imgui.push_style_color(imgui.COLOR_TEXT, r, g, b) color_changed = True changed, selected = imgui.selectable(addr, addr in self.lines) if changed and selected: self.lines[addr] = collections.deque(maxlen=MAX_POINTS) elif changed and not selected: del self.lines[addr] if color_changed: imgui.pop_style_color() self.gui_width = imgui.get_window_width() imgui.end() # imgui.render() in on_draw caused a "newFrame is not called" error on Windows, # therefore we invoke it here imgui.render()
def main(): renderer = NXRenderer() currentDir = os.getcwd() while True: renderer.handleinputs() imgui.new_frame() width, height = renderer.io.display_size imgui.set_next_window_size(width, height) imgui.set_next_window_position(0, 0) imgui.begin("", flags=imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_SAVED_SETTINGS) imgui.text("Welcome to PyNX!") imgui.text("Touch is supported. Only showing python scripts.") imgui.text("Current dir: " + os.getcwd()) if os.getcwd() != "sdmc:/": imgui.push_style_color(imgui.COLOR_BUTTON, *FOLDER_COLOR) if imgui.button("../", width=200, height=60): os.chdir("..") imgui.pop_style_color(1) files = [] for e in os.listdir(): if os.path.isfile(e) and e.endswith(".py") and e != "main.py": files.append(e) files = sorted(files) for e in files: imgui.push_style_color(imgui.COLOR_BUTTON, *PYFILE_COLOR) if imgui.button(e, width=200, height=60) and e.endswith(".py"): run_python_module(e) imgui.pop_style_color(1) imgui.end() imgui.render() renderer.render() renderer.shutdown()
def _show(self, value, read_only): active = value.value or time.time( ) - self._last_active < Button.ACTIVE_TIME if value.value: self._last_active = time.time() imgui.push_style_color(imgui.COLOR_BUTTON_ACTIVE, 1.0, 0.0, 0.0, 1.0) if active: imgui.push_style_color(imgui.COLOR_BUTTON, 1.0, 0.0, 0.0, 1.0) imgui.push_style_color(imgui.COLOR_BUTTON_HOVERED, 1.0, 0.0, 0.0, 1.0) imgui.push_item_width(self.width) clicked = imgui.button("Click me") if active: imgui.pop_style_color(2) imgui.pop_style_color(1) # TODO this might be a problem # events are reset by this widget! # events are a special case!! # this widget gets InputValueHolder value even when an input is connected # (to make sure that event trigger is displayed on the button) # when button is pressed even though a value is connected: # -> set force flag on manual value, don't forget to reset it value_to_set = value if isinstance(value, ConnectedValue): value_to_set = value.manual_value # set on click if clicked: value_to_set.value = 1.0 if read_only: value_to_set.force_value = True self._reset_force_value = True elif self._reset_force_value: value_to_set.force_value = False self._reset_force_value = False # reset otherwise if still active if not clicked and value.value: value_to_set.value = 0.0
def create_frames_and_buttons(self): # take section one by one for key_section in keys: # create Sperate Frame For Every Section # store_section = Tkinter.Frame(self) # store_section.pack(side='left', expand='yes', fill='both', padx=10, pady=10, ipadx=10, ipady=10) # imgui.begin_group() for layer_name, layer_properties, layer_keys in key_section: # store_layer = Tkinter.LabelFrame(store_section) # , text=layer_name) # store_layer.pack(side='top',expand='yes',fill='both') # store_layer.pack(layer_properties) for key_bunch in layer_keys: # store_key_frame = Tkinter.Frame(store_layer) # store_key_frame.pack(side='top', expand='yes', fill='both') imgui.begin_group() for k in key_bunch: k = k.capitalize() if len(k) <= 3: imgui.push_style_color(imgui.COLOR_BUTTON, *FILE_COLOR) if not self.InnerMudData['Shift_enabled']: k = k.lower() if imgui.button(k): self.button_command(k) imgui.pop_style_color(1) else: imgui.push_style_color(imgui.COLOR_BUTTON, *FILE_COLOR) if imgui.button(k.center(5, ' ')): self.button_command(k) imgui.pop_style_color(1) imgui.same_line() # store_button['relief'] = BUTTON_LOOK # store_button['bg'] = BUTTON_BACKGROUND # store_button['fg'] = FONT_COLOR # store_button['command'] = lambda q=k.lower(): self.button_command(q) # store_button.pack(side='left', fill='both', expand='yes') imgui.end_group()
def main(): global state global debugger current_batch_mod = "" ctime = 0 renderer = NXRenderer() if os.path.isdir("sdmc:/ReiNX"): currentDir = "sdmc:/ReiNX/titles/01006A800016E000/romfs" os.chdir(currentDir) else: currentDir = "sdmc:/Atmosphere/titles/01006A800016E000/romfs" os.chdir(currentDir) while True: while state == "file_manager": renderer.handleinputs() imgui.new_frame() width, height = renderer.io.display_size imgui.set_next_window_size(width, height) imgui.set_next_window_position(0, 0) imgui.begin("", flags=imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_SAVED_SETTINGS) imgui.text( " __________ ____ __ __ __ _______ ____ _____ ________________ __ __ __________ " ) imgui.text( " / ___/ ___// __ )/ / / / / |/ / __ \/ __ \ / _/ | / / ___/_ __/ | / / / / / ____/ __ \ " ) imgui.text( " \__ \\__ \/ __ / / / / / /|_/ / / / / / / / / // |/ /\__ \ / / / /| | / / / / / __/ / /_/ / " ) imgui.text( " ___/ /__/ / /_/ / /_/ / / / / / /_/ / /_/ / _/ // /| /___/ // / / ___ |/ /___/ /___/ /___/ _, _/ " ) imgui.text( "/____/____/_____/\____/ /_/ /_/\____/_____/ /___/_/ |_//____//_/ /_/ |_/_____/_____/_____/_/ |_| " ) imgui.text("") imgui.text("Created by NyxTheShield") imgui.text("Based on jam1garner Mod Installer") imgui.text("") imgui.text("Select the Mod to Install!") dirs = [] files = [] backups = [] for e in os.listdir(): if os.path.isdir(e): dirs.append(e) else: if not e.endswith(".exe") and not e.endswith( ".bat") and not e.endswith( ".backup") and not e.endswith( ".arc") and not e.endswith(".txt"): files.append(e) if e.endswith(".backup"): backups.append(e) dirs = sorted(dirs) files = sorted(files) backups = sorted(backups) for e in dirs: flag = False added_text = "" batch_files = os.listdir(e) for file in batch_files: if ".backup" in file: imgui.push_style_color(imgui.COLOR_BUTTON, *FOLDER_COLOR) flag = True added_text = "Uninstall " break if flag == False: imgui.push_style_color(imgui.COLOR_BUTTON, *PYFILE_COLOR) added_text = "Install " if imgui.button(added_text + e + "/", width=200, height=60): ctime = time.time() current_batch_mod = e batch_install(e) imgui.pop_style_color(1) for e in files: if not e.endswith(".exe") and not e.endswith( ".bat") and not e.endswith( ".backup") and not e.endswith(".arc"): imgui.push_style_color(imgui.COLOR_BUTTON, *PYFILE_COLOR) if imgui.button( "Install " + e, width=400, height=60 ) and not e.endswith(".exe") and not e.endswith( ".bat") and not e.endswith( ".backup") and not e.endswith(".arc"): ctime = time.time() run_python_module(e, 1) imgui.pop_style_color(1) for e in backups: if e.endswith(".backup"): imgui.push_style_color(imgui.COLOR_BUTTON, *FOLDER_COLOR) if imgui.button("Uninstall " + e, width=400, height=60) and e.endswith(".backup"): ctime = time.time() run_python_module(e, 2) imgui.pop_style_color(1) imgui.end() imgui.render() renderer.render() while state == "installed": imgui.new_frame() width, height = renderer.io.display_size imgui.set_next_window_size(width, height) imgui.set_next_window_position(0, 0) imgui.begin("", flags=imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_SAVED_SETTINGS) if time.time() - ctime > 5: state = "file_manager" ctime = 0 imgui.text( " __ ___ __ ____ __ ____ __ _____ ____ ____ ____" ) imgui.text( " / |/ /___ ____/ / / _/___ _____/ /_____ _/ / /__ ____/ / / ___/__ _______________ __________/ __/_ __/ / /_ __/ / /" ) imgui.text( " / /|_/ / __ \/ __ / / // __ \/ ___/ __/ __ `/ / / _ \/ __ / \__ \/ / / / ___/ ___/ _ \/ ___/ ___/ /_/ / / / / / / / / / /" ) imgui.text( " / / / / /_/ / /_/ / _/ // / / (__ ) /_/ /_/ / / / __/ /_/ / ___/ / /_/ / /__/ /__/ __(__ |__ ) __/ /_/ / / / /_/ /_/_/" ) imgui.text( "/_/ /_/\____/\__,_/ /___/_/ /_/____/\__/\__,_/_/_/\___/\__,_/ /____/\__,_/\___/\___/\___/____/____/_/ \__,_/_/_/\__, (_|_)" ) imgui.text( " /____/ " ) imgui.end() imgui.render() renderer.render() while state == "batch_i": imgui.new_frame() width, height = renderer.io.display_size imgui.set_next_window_size(width, height) imgui.set_next_window_position(0, 0) imgui.begin("", flags=imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_SAVED_SETTINGS) if time.time() - ctime > 5: state = "file_manager" ctime = 0 imgui.text("Batch Mod Sucesfully Installed") imgui.end() imgui.render() renderer.render() while state == "batch_u": imgui.new_frame() width, height = renderer.io.display_size imgui.set_next_window_size(width, height) imgui.set_next_window_position(0, 0) imgui.begin("", flags=imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_SAVED_SETTINGS) if time.time() - ctime > 5: state = "file_manager" ctime = 0 imgui.text("Batch Mod Uninstalled") imgui.end() imgui.render() renderer.render()
def main(self): """ This is the main loop. Most action happens here """ # This is the loop I was talking about while True: # Look for any user input self.renderer.handleinputs() # Create a new frame imgui.new_frame() # Get screen width and height self.width, self.height = self.renderer.io.display_size # Set the frame as big as the screen resolution imgui.set_next_window_size(self.width, self.height) # Put the frame in the top left corner imgui.set_next_window_position(0, 0) # Create a window in the frame we created ( Ignore pep8 for this line) imgui.begin("", flags=imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_SAVED_SETTINGS) # Version placeholder imgui.text("PyNx Terminal By PuffDip" + " - V" + str(self.version_number) + str(self.currentDir)) # This check looks if any menu is open # If so the terminal rescales so the menu fits on screen if \ self.keyboard_toggled or\ self.setting_toggle: # end check # Set the region so a new menu can fit imgui.begin_child("region", -5, -430, border=True) else: # Set terminal fullscreen if no menu has been found imgui.begin_child("region", -5, -110, border=True) # Show interpreter output on screen # If this is the first time the console need to show text if self.just_booted: # set boot bool to false if len(self.input) > 0: self.just_booted = False # Show version number imgui.text(self.CONSOLE_TEXT) else: #imgui.push_font(self.font) if self.cli_history: imgui.text("{}\n\n>>>\n{}".format( "\n".join(self.cli_history), self.input)) else: imgui.text(">>>\n{}".format(self.input)) #imgui.pop_font() # Make sure the screen stays fullscreen imgui.end_child() """ If the setting menu not is selected, most likely the user is in his keyboard layout We first want to check if the user is using the setting menu. After that we check if the user uses its keyboard. If so we render the keyboard. """ # Check if the setting page is toggled if not self.setting_toggle: # Render keyboard self.krender() # If the setting page is active show the setting page instead of rendering the keyboard else: self.srender() # Command line imgui.text("Keyboard: {} | Shift: {} | SYS: {}".format( self.keyboard_toggled, self.CAPS, self.SYS)) # Give a style to the button imgui.push_style_color(imgui.COLOR_BUTTON, *self.KEY_COLOR_LGRAY) # Create a button "Import" if imgui.button("Import", width=200, height=60): # Toggle Keyboard if not already if not self.keyboard_toggled: self.keyboard_toggled = True #self.input = "https://pastebin.com/" self.input = "dpaste:>>" # push style imgui.pop_style_color(1) imgui.same_line() # Give a style to the button imgui.push_style_color(imgui.COLOR_BUTTON, *self.KEY_COLOR_LGRAY) # Create a button "Export" if imgui.button("Export", width=200, height=60): export_check = "".join(self.utils.export(self.cli_history)) self.cli_history.append(export_check) # push style imgui.pop_style_color(1) imgui.same_line() # Give a style to the button imgui.push_style_color(imgui.COLOR_BUTTON, *self.KEY_COLOR_BLACK) # Create a button "Cursor" if imgui.button("...", width=200, height=60): pass # TODO Import a cursor method # push style imgui.pop_style_color(1) # Create the keyboard toggle button imgui.same_line() self.toggleKeyboard() # If settings was already opened close setting page if self.keyboard_toggled and self.setting_toggle: self.setting_toggle = False imgui.same_line() # Give a style to the button imgui.push_style_color(imgui.COLOR_BUTTON, *self.KEY_COLOR_LGRAY) # Create a button "Confirm" if the input from the user is higher then 0 if imgui.button("Confirm", width=200, height=60) and len(self.input) > 0: # If pastebin is used if self.input.startswith("dpaste:>>"): # Make a usable url url_redirecter = self.input.split(sep=":>>")[1] # Clear user input # generate url url = "http://dpaste.com/" + url_redirecter + ".txt" # Start to fetch the data self.input = self.utils.import_url(url) else: # Execute user command out, err, exc = self.python.execute(self.input) # Append user command to history self.input += "\n" self.cli_history.append(self.input) # Check whatever the result was of the command if out: self.input = out if err: self.input = err if exc: self.input = exc # total character limit on screen limit = 160 # Make sure history doesn't go off screen if len(self.input) >= limit: result = "" tmp_list = self.input.split("\n") for sentence in tmp_list: if len(sentence) >= limit: sentence = "\n".join([ sentence[i:i + limit] for i in range(0, len(sentence), limit) ]) result += sentence result += "\n" else: result += sentence result += "\n" self.input = result # Append result to history self.cli_history.append(self.input) # Clear variable to get used once more self.input = "" # Push style of the button imgui.pop_style_color(1) # On the same line we want our next object imgui.same_line() # Create a style for a new button imgui.push_style_color(imgui.COLOR_BUTTON, *self.KEY_COLOR_BGRAY) # Create a button "Settings" if imgui.button("S", width=40, height=40): # If the keyboard was toggled turn it off if self.keyboard_toggled: self.keyboard_toggled = False self.CAPS = False self.SYS = False # Finally render the settings self.toggle() # Push style of the button imgui.pop_style_color(1) imgui.end() imgui.render() self.renderer.render() # This function is needed else the switch crashes self.renderer.shutdown()
def main(): global ERROR renderer = NXRenderer() currentDir = os.getcwd() while True: renderer.handleinputs() imgui.new_frame() width, height = renderer.io.display_size imgui.set_next_window_size(width, height) imgui.set_next_window_position(0, 0) imgui.begin("", flags=imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_SAVED_SETTINGS) imgui.begin_group() imgui.text("Welcome to PyNX!") imgui.text("Touch is supported") imgui.text("Current dir: " + os.getcwd()) if os.getcwd() != "sdmc:/": imgui.push_style_color(imgui.COLOR_BUTTON, *FOLDER_COLOR) if imgui.button("../", width=200, height=60): os.chdir("..") imgui.pop_style_color(1) dirs = [] files = [] for e in os.listdir(): if os.path.isdir(e): dirs.append(e) else: files.append(e) dirs = sorted(dirs) files = sorted(files) for e in dirs: imgui.push_style_color(imgui.COLOR_BUTTON, *FOLDER_COLOR) if imgui.button(e + "/", width=200, height=60): os.chdir(e) imgui.pop_style_color(1) for e in files: if e.endswith(".py"): imgui.push_style_color(imgui.COLOR_BUTTON, *PYFILE_COLOR) else: imgui.push_style_color(imgui.COLOR_BUTTON, *FILE_COLOR) if imgui.button(e, width=200, height=60) and e.endswith(".py"): run_python_module(e) imgui.pop_style_color(1) imgui.end_group() # end of file picker imgui.same_line(spacing=50) imgui.begin_group() imgui.text("Utils:") imgui.push_style_color(imgui.COLOR_BUTTON, *APP_COLOR) if imgui.button("Interactive Python", width=200, height=60): t = Terminal() t.main() imgui.pop_style_color(1) imgui.end_group() imgui.end() if ERROR: imgui.set_next_window_size(width, height) imgui.set_next_window_position(0, 0) imgui.begin("ERROR", flags=imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_SAVED_SETTINGS) imgui.text(str(ERROR)) if imgui.button("OK", width=200, height=60): ERROR = "" imgui.end() imgui.render() renderer.render() renderer.shutdown()
def main(): import imgui import imguihelper import _nx import runpy from imgui.integrations.nx import NXRenderer renderer = NXRenderer() currentDir = os.getcwd() while True: renderer.handleinputs() imgui.new_frame() width, height = renderer.io.display_size imgui.set_next_window_size(width, height) imgui.set_next_window_position(0, 0) imgui.begin("PyLaylist Maker", flags=imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_SAVED_SETTINGS ) imgui.set_window_font_scale(2.0) imgui.begin_group() imgui.text("Welcome to Pylaylist Maker for RetroArch!\nTouch is supported\nSettings:") imgui.text("RetroArch Path: {}\nRoms Path: {}\nPlaylists Path: {}" .format(Settings["retroarchPATH"],Settings["romsPaths"][Settings["indexRomPathUsed"]],Settings["playlistsPath"])) imgui.push_style_color(imgui.COLOR_BUTTON, *STRING_COLOR) if imgui.button("Toggle Roms Path"): Settings["indexRomPathUsed"] = 0 if Settings["indexRomPathUsed"]==1 else 1 updateSettings() imgui.pop_style_color(1) imgui.same_line() if Settings["useAllExtentions"]: imgui.push_style_color(imgui.COLOR_BUTTON, *BOOL_TRUE_COLOR ) else: imgui.push_style_color(imgui.COLOR_BUTTON, *BOOL_FALSE_COLOR ) if imgui.button("Use All Extentions: "+("True" if Settings["useAllExtentions"] else "False")): Settings["useAllExtentions"] = not Settings["useAllExtentions"] updateSettings() imgui.pop_style_color(1) if Settings["useShorthandName"]: imgui.push_style_color(imgui.COLOR_BUTTON, *BOOL_TRUE_COLOR ) else: imgui.push_style_color(imgui.COLOR_BUTTON, *BOOL_FALSE_COLOR ) if imgui.button("Use Shorthand Name: "+("True" if Settings["useShorthandName"] else "False")): Settings["useShorthandName"] = not Settings["useShorthandName"] updateSettings() imgui.pop_style_color(1) imgui.same_line() if Settings["makeJsonPlaylists"]: imgui.push_style_color(imgui.COLOR_BUTTON, *BOOL_TRUE_COLOR ) else: imgui.push_style_color(imgui.COLOR_BUTTON, *BOOL_FALSE_COLOR ) if imgui.button("Generate Json Playlists: "+("True" if Settings["makeJsonPlaylists"] else "False")): Settings["makeJsonPlaylists"] = not Settings["makeJsonPlaylists"] updateSettings() imgui.pop_style_color(1) imgui.end_group() imgui.separator() imgui.begin_group() imgui.text("Commands") imgui.push_style_color(imgui.COLOR_BUTTON, *STRING_COLOR) if imgui.button("Validate/Generate Folders"): validateFolders() logger.info("Folders Validated") imgui.pop_style_color(1) imgui.text("THIS WILL ADD A BUNCH OF FOLDERS TO YOUR ROM PATH!") imgui.push_style_color(imgui.COLOR_BUTTON, *STRING_COLOR) if imgui.button("Generate/Update Playlists"): generatePlaylist() logger.info("Complete") imgui.pop_style_color(1) imgui.text("THIS WILL MODIFY PLAYLISTS, MAKE BACKUPS FIRST!") imgui.text("State: "+state+"\n\n\n") quitme = False """imgui.push_style_color(imgui.COLOR_BUTTON, *STRING_COLOR) if imgui.button("Quit"): quitme = True imgui.pop_style_color(1) """ imgui.end_group() imgui.end() imgui.render() renderer.render() if quitme: break renderer.shutdown() return 0
def render_palette(drawing: Drawing): global color_editor_open # Need a persistent way to keep track of the popup being closed... global current_color_page palette = drawing.palette fg = palette.foreground bg = palette.background fg_color = palette.foreground_color bg_color = palette.background_color imgui.begin_child("Palette", border=False, height=460) # Edit foreground color if imgui.color_button(f"Foreground (#{fg})", *as_float(fg_color), 0, 30, 30): io = imgui.get_io() w, h = io.display_size imgui.open_popup("Edit foreground color") imgui.set_next_window_position(w - 115 - 120, 200) color_editor_open = True if imgui.begin_popup("Edit foreground color", flags=(imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_SCROLL_WITH_MOUSE)): done, cancelled, new_color = render_color_editor( palette.colors[fg], fg_color) if done and new_color != fg_color: drawing.change_colors(fg, new_color) palette.clear_overlay() elif cancelled: palette.clear_overlay() else: palette.set_overlay(fg, new_color) imgui.end_popup() elif color_editor_open: # The popup was closed by clicking outside, keeping the change (same as OK) drawing.change_colors(fg, fg_color) palette.clear_overlay() color_editor_open = False imgui.same_line() imgui.color_button(f"Background (#{bg})", *as_float(bg_color), 0, 30, 30) max_pages = len(palette.colors) // 64 - 1 imgui.push_item_width(100) _, current_color_page = imgui.slider_int("Page", current_color_page, min_value=0, max_value=max_pages) start_color = 64 * current_color_page imgui.begin_child("Colors", border=False) imgui.push_style_var(imgui.STYLE_ITEM_SPACING, (0, 0)) # Make layout tighter width = int(imgui.get_window_content_region_width()) // 20 imgui.push_style_color(imgui.COLOR_FRAME_BACKGROUND, 0, 0, 0) colors = palette.colors # Order the colors by column instead of by row (which is the order we draw them) for i, c in enumerate( chain.from_iterable( zip(range(0, 16), range(16, 32), range(32, 48), range(48, 64)))): color = colors[start_color + c] is_foreground = c == fg is_background = (c == bg) * 2 selection = is_foreground | is_background color = as_float(color) if color[3] == 0 or selection: x, y = imgui.get_cursor_screen_pos() if imgui.color_button(f"color {i}", *color[:3], 1, 0, 25, 25): # io = imgui.get_io() # if io.key_shift: # if "spread_start" in temp_vars: # temp_vars["spread_end"] = i # else: # temp_vars["spread_start"] = i # else: fg = c if i % width != width - 1: imgui.same_line() draw_list = imgui.get_window_draw_list() if color[3] == 0: # Mark transparent color draw_list.add_line(x + 1, y + 1, x + 24, y + 24, imgui.get_color_u32_rgba(0, 0, 0, 1), 1) draw_list.add_line(x + 1, y + 2, x + 23, y + 24, imgui.get_color_u32_rgba(1, 1, 1, 1), 1) if is_foreground: # Mark foregroupd color draw_list.add_rect_filled(x + 2, y + 2, x + 10, y + 10, imgui.get_color_u32_rgba(1, 1, 1, 1)) draw_list.add_rect(x + 2, y + 2, x + 10, y + 10, imgui.get_color_u32_rgba(0, 0, 0, 1)) if is_background: # Mark background color draw_list.add_rect_filled(x + 15, y + 2, x + 23, y + 10, imgui.get_color_u32_rgba(0, 0, 0, 1)) draw_list.add_rect(x + 15, y + 2, x + 23, y + 10, imgui.get_color_u32_rgba(1, 1, 1, 1)) if imgui.core.is_item_clicked(2): # Right button sets background bg = c # Drag and drop (currently does not accomplish anything though) if imgui.begin_drag_drop_source(): imgui.set_drag_drop_payload('start_index', c.to_bytes(1, sys.byteorder)) imgui.color_button(f"color {c}", *color[:3], 1, 0, 20, 20) imgui.end_drag_drop_source() if imgui.begin_drag_drop_target(): start_index = imgui.accept_drag_drop_payload('start_index') if start_index is not None: start_index = int.from_bytes(start_index, sys.byteorder) io = imgui.get_io() image_only = io.key_shift drawing.swap_colors(start_index, c, image_only=image_only) palette.clear_overlay() imgui.end_drag_drop_target() imgui.pop_style_color(1) imgui.pop_style_var(1) imgui.end_child() imgui.end_child() if imgui.is_item_hovered(): io = imgui.get_io() delta = int(io.mouse_wheel) current_color_page = min(max(current_color_page - delta, 0), max_pages) palette.foreground = fg palette.background = bg
def srender(self): # Create a GUI group imgui.begin_group() """ NEW ROW STARTS HERE ROW #1 """ for i in range(5): self.placeholder() imgui.same_line() self.placeholder() """ NEW ROW STARTS HERE ROW #2 """ for i in range(5): self.placeholder() imgui.same_line() self.placeholder() """ NEW ROW STARTS HERE ROW #3 """ for i in range(5): self.placeholder() imgui.same_line() self.placeholder() """ NEW ROW STARTS HERE ROW #4 """ for i in range(5): self.placeholder() imgui.same_line() self.placeholder() """ NEW ROW STARTS HERE ROW #5 """ # TESTS """ Give code for a long list, test long outputs """ # Give a style to the button imgui.push_style_color(imgui.COLOR_BUTTON, *self.KEY_COLOR_LGRAY) # Create a button "Long Output" if imgui.button("Long Output", width=self.BTN_WIDTH, height=self.BTN_HEIGHT): # Execute code when button is pressed self.input = "dpaste:>>070KVYA" # push style imgui.pop_style_color(1) imgui.same_line() """ Test SSL """ # Give a style to the button imgui.push_style_color(imgui.COLOR_BUTTON, *self.KEY_COLOR_LGRAY) # Create a button "Test SSL" if imgui.button("Test SSL", width=self.BTN_WIDTH, height=self.BTN_HEIGHT): # Execute code when button is pressed self.input = "dpaste:>>0P6AH88" # push style imgui.pop_style_color(1) imgui.same_line() """ import this """ # Give a style to the button imgui.push_style_color(imgui.COLOR_BUTTON, *self.KEY_COLOR_LGRAY) # Create a button "Import this" if imgui.button("Import this", width=self.BTN_WIDTH, height=self.BTN_HEIGHT): # Execute code when button is pressed self.input = "dpaste:>>1441C4D" # push style imgui.pop_style_color(1) imgui.same_line() """ for loop """ # Give a style to the button imgui.push_style_color(imgui.COLOR_BUTTON, *self.KEY_COLOR_LGRAY) # Create a button "For loop this" if imgui.button("For loop", width=self.BTN_WIDTH, height=self.BTN_HEIGHT): # Execute code when button is pressed self.input = "dpaste:>>2BTR5CV" # push style imgui.pop_style_color(1) for i in range(2): imgui.same_line() self.placeholder() imgui.end_group()
def render_palette_popup(drawing: Drawing): global edit_color global color_editor_open palette = drawing.palette fg = palette.foreground bg = palette.background fg_color = palette.foreground_color bg_color = palette.background_color open_color_editor = False _, opened = imgui.begin("Color popup", True) imgui.begin_child("Colors", height=0) imgui.push_style_var(imgui.STYLE_ITEM_SPACING, (0, 0)) # Make layout tighter width = int(imgui.get_window_content_region_width()) // 25 for i, color in enumerate(palette.colors, 0): is_foreground = i == fg is_background = (i == bg) * 2 selection = is_foreground | is_background if i in palette.overlay: color = as_float(palette.overlay[i]) else: color = as_float(color) imgui.push_style_color(imgui.COLOR_FRAME_BACKGROUND, *SELECTABLE_FRAME_COLORS[selection]) if imgui.color_button(f"color {i}", *color[:3], 1, 0, 25, 25): # io = imgui.get_io() # if io.key_shift: # if "spread_start" in temp_vars: # temp_vars["spread_end"] = i # else: # temp_vars["spread_start"] = i # else: fg = i imgui.pop_style_color(1) if imgui.core.is_item_clicked(1): edit_color = i color_editor_open = True imgui.open_popup("Edit foreground color") # imgui.set_next_window_position(w - 115 - 120, 200) if imgui.core.is_item_clicked(2): # Detect right button clicks on the button bg = i if imgui.begin_drag_drop_source(): imgui.set_drag_drop_payload('start_index', i.to_bytes(1, sys.byteorder)) imgui.color_button(f"color {i}", *color[:3], 1, 0, 20, 20) imgui.end_drag_drop_source() if imgui.begin_drag_drop_target(): start_index = imgui.accept_drag_drop_payload('start_index') if start_index is not None: start_index = int.from_bytes(start_index, sys.byteorder) io = imgui.get_io() image_only = io.key_shift # drawing.swap_colors(start_index, i, image_only=image_only) # palette.clear_overlay() imgui.end_drag_drop_target() # if imgui.is_item_hovered(): # io = imgui.get_io() # delta = int(io.mouse_wheel) if i % width != width - 1: imgui.same_line() imgui.pop_style_var(1) #color_editor_open = render_color_editor_popup(drawing, edit_color, color_editor_open) imgui.end_child() imgui.end() palette.foreground = fg palette.background = bg return opened, open_color_editor
def main(collections): global ERROR renderer = NXRenderer() while True: renderer.handleinputs() imgui.new_frame() width, height = renderer.io.display_size imgui.set_next_window_size(width, height) imgui.set_next_window_position(0, 0) imgui.begin("", flags=imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_SAVED_SETTINGS) imgui.push_style_color(imgui.COLOR_TEXT, *TEXT_COLOR) imgui.push_style_color(imgui.COLOR_BUTTON_HOVERED, *MENU_BUTTON_COLOR) imgui.push_style_color(imgui.COLOR_BUTTON_ACTIVE, *MENU_BUTTON_COLOR) imgui.begin_group() imgui.text("NX-Rom-Market") # Create ROMS folder if it doesn't exist directory = "Roms" parent_dir = "sdmc:/" path = os.path.join(parent_dir, directory) try: os.makedirs(path, exist_ok=True) except OSError as error: print("Directory '%s' can not be created" % directory) for idx, collectionName in enumerate(sorted([*collections])): idx % 3 == 0 and imgui.new_line() or imgui.same_line() imgui.push_style_color(imgui.COLOR_BUTTON, *COLLECTION_COLOR) if imgui.button(collectionName, width=390, height=150): rom_list(collections, collectionName) imgui.pop_style_color(1) imgui.end_group() imgui.end() if ERROR: imgui.set_next_window_size(width, height) imgui.set_next_window_position(0, 0) imgui.begin("ERROR", flags=imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_SAVED_SETTINGS) imgui.text(str(ERROR)) if imgui.button("OK", width=200, height=60): ERROR = "" imgui.end() imgui.render() renderer.render() renderer.shutdown()
def rom_list(collections, console_selected, prefix='A', checkbox_extract=False): # clear both buffers imguihelper.clear() _nx.gfx_set_mode(TILED_DOUBLE) clear_terminal() imguihelper.initialize() renderer = NXRenderer() # TODO fetcing indicator roms = fetch_roms(collections[console_selected], prefix) # create collection rom folder directory = "Roms" parent_dir = "sdmc:/" path = os.path.join(parent_dir, directory, console_selected) try: os.makedirs(path, exist_ok=True) except OSError as error: print("Directory '%s' can not be created" % path) os.chdir(path) dir_content = os.listdir() while True: renderer.handleinputs() imgui.new_frame() width, height = renderer.io.display_size imgui.set_next_window_size(width, height) imgui.set_next_window_position(0, 0) imgui.begin("", flags=imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_SAVED_SETTINGS) imgui.begin_group() imgui.push_style_color(imgui.COLOR_BUTTON, *MENU_BUTTON_COLOR_SELECTED) if imgui.button("< Back", width=70, height=50): main(collections) imgui.pop_style_color(1) imgui.same_line(spacing=50) _, checkbox_extract = imgui.checkbox("EXTRACT .ZIP AFTER DOWNLOAD", checkbox_extract) imgui.text("Collection: " + console_selected) imgui.new_line() for letter in '#' + string.ascii_uppercase: button_color = MENU_BUTTON_COLOR_SELECTED if prefix == letter else MENU_BUTTON_COLOR imgui.same_line() imgui.push_style_color(imgui.COLOR_BUTTON, *button_color) if imgui.button(letter, width=28, height=28): rom_list(collections, console_selected, letter, checkbox_extract) imgui.pop_style_color(1) imgui.new_line() imgui.begin_child("region", -0, -0, border=True) for rom in roms: folder_name = os.path.splitext(rom['title'])[0] is_downloaded = any(x in dir_content for x in [rom['title'], folder_name]) button_color = ROM_COLOR_DOWNLOADED if is_downloaded else ROM_COLOR imgui.push_style_color(imgui.COLOR_BUTTON, *button_color) if imgui.button(rom['title'] + " " + rom['size'], width=1240, height=30): download(rom, console_selected, checkbox_extract) imgui.pop_style_color(1) imgui.end_child() imgui.end_group() imgui.end() imgui.render() renderer.render() renderer.shutdown()
def __exit__(imc, *args) -> IMGui[None]: imgui.pop_style_color(len(imc.colors))
async def signal_plot(plot_box_state: PlotState, m_signal: Maybe[Signal], width: float, height: float, ui_settings) -> Eff[[ACTIONS], IMGui[None]]: # TODO: try using IMGui::PlotLines? # m_signal = box_inputs[plot_box_state.id_][0] assert ((type(m_signal.val) == Signal) if m_signal.is_Just() else True), repr(m_signal) drag_state = plot_box_state.drag_state im.push_style_color(im.COLOR_CHILD_BACKGROUND, 1., 1., 1., 0.05) with draggable(name="signal_plot##" + str(plot_box_state.id_), was_down=drag_state.is_Dragging(), width=width, height=height) as (status, is_down): if status == 'pressed': # and plot_box_state.plot_state.is_WithTimeRange(): await emit(DragAction.StartDrag(id_=plot_box_state.id_)) elif status == 'released': # and plot_box_state.plot_state.is_WithTimeRange(): await emit(DragAction.EndDrag(id_=plot_box_state.id_)) # im.text("{!r:<10} {!r:<5}".format(status, is_held)) if m_signal.is_Nothing() or plot_box_state.plot_state.is_NoTimeRange(): im.text("Not ready") elif m_signal.is_Just(): signal = m_signal.val plot_draw_area = get_window_rect() if ui_settings['plot_draw_function'] == 'manual': draw_list = im.get_window_draw_list() show_full_plot(plot_box_state, signal, plot_draw_area, draw_list, ui_settings) else: show_imgui_plot(plot_box_state, signal, width=-1, height=-1, ui_settings=ui_settings) if status == 'held': # Unfortunately, a DragAction.[StartDrag/EndDrag] will only be processed after draw() # So without this if, the drag code is called once before, and once after a drag ends, # without being reflected in the drag_state. # In the latter case, If the mouse isn't dragging, drag_delta == (0,0) # So effectively, the state is set as if the mouse never moved. assert plot_box_state.drag_state.is_Dragging() drag_delta = im.get_mouse_drag_delta(button=0, lock_threshold=1.) drag_origin = point_subtract_offset(get_mouse_position(), drag_delta) updated_time_range = time_range_after_drag( plot_box_state.drag_state.time_range_before_drag, signal, plot_draw_area, drag_origin, drag_delta) if plot_box_state.plot_state.time_range != updated_time_range: await emit( PlotAction.SetTimeRange(id_=plot_box_state.id_, time_range=updated_time_range)) im.pop_style_color()