def table_tree(table: EntryGroup): for key, entry in table.items(): if isinstance(entry, NetworkTableEntry): imgui.text(entry_name(key) + ': ' + str(entry.value)) imgui.same_line() imgui.push_id(key) if imgui.button('Add'): active_widgets[key] = Widget(entry) imgui.pop_id() else: t = NetworkTables.getTable(key) if '.type' in t.getKeys(): name = t.getString('.name', '') imgui.text(name) imgui.same_line() imgui.push_id(key) if imgui.button('Add'): active_widgets[key] = Widget(t, EntryType.Chooser) imgui.pop_id() if show_sendable_debug: if imgui.tree_node('Chooser Debug (' + key + ')'): table_tree(entry) imgui.tree_pop() elif imgui.tree_node(entry_name(key), imgui.TREE_NODE_DEFAULT_OPEN): # nothing fancy, just a subtable table_tree(entry) imgui.tree_pop()
def draw(self): imgui.new_frame() imgui.set_next_window_position(16, 32, imgui.ONCE) imgui.set_next_window_size(512, 512, imgui.ONCE) imgui.begin("Example: simple popup modal") if imgui.button("Open Modal popup"): imgui.open_popup("select-popup") imgui.same_line() if imgui.begin_popup_modal("select-popup")[0]: imgui.text("Select an option:") imgui.separator() imgui.selectable("One") imgui.selectable("Two") imgui.selectable("Three") imgui.end_popup() imgui.end() imgui.end_frame() imgui.render() self.renderer.render(imgui.get_draw_data())
def draw_sector_mode(cur_state): if imgui.button("New sector"): cur_state.cur_sector = map_db.add_new_sector(cur_state.map_data) cur_sect = cur_state.cur_sector if cur_sect != -1: imgui.text("Sector {}".format(cur_sect)) set_sector_group = lambda val: map_db.set_sector_constant( cur_state.map_data, cur_sect, map_db.SECT_GROUP_IDX, val) input_int( "Sector group: ", "##sector{}_".format(cur_sect), map_db.get_sector_constant(cur_state.map_data, cur_sect, map_db.SECT_GROUP_IDX), set_sector_group) #type_getter = lambda: get_sector_type(cur_state, cur_sect) #type_setter = lambda val: set_sector_type(cur_state, cur_sect, val) #attr_getter = lambda attr: get_sector_attribute(cur_state, cur_sect, attr) #attr_setter = lambda attr: lambda val: set_sector_attribute(cur_state, cur_sect, attr, val) #param_getter = lambda param: get_sector_param(cur_state, cur_sect, param) #param_setter = lambda param: lambda val: set_sector_param(cur_state, cur_sect, param, val) imgui.same_line() imgui.text("Sector {}".format(cur_sect)) def set_cur_sector(idx): cur_state.cur_sector = idx draw_list(cur_state, "Sector", "Sector list", map_db.get_all_sectors(cur_state.map_data), set_cur_sector)
def render_unsaved_exit(window): "Popup to prevent exiting the application with unsaved work." if window.exit_unsaved_drawings: imgui.open_popup("Really exit?") imgui.set_next_window_size(500, 200) if imgui.begin_popup_modal("Really exit?")[0]: imgui.text("You have unsaved work in these drawing(s):") imgui.begin_child("unsaved", border=True, height=imgui.get_content_region_available()[1] - 26) for drawing in window.exit_unsaved_drawings: imgui.text(drawing.filename) if imgui.is_item_hovered(): pass # TODO popup thumbnail of the picture? imgui.end_child() if imgui.button("Yes, exit anyway"): imgui.close_current_popup() pyglet.app.exit() imgui.same_line() if imgui.button("Yes, but save first"): for drawing in window.exit_unsaved_drawings: window.save_drawing(drawing) pyglet.app.exit() imgui.same_line() if imgui.button("No, cancel"): window.exit_unsaved_drawings = None imgui.close_current_popup() imgui.end_popup()
def imgui_tabbar ( self, open_tab, tabs ): width = imgui.get_content_region_available_width() tab_width = ( width - imgui.get_style().item_spacing.x * ( len( tabs ) - 1 ) ) / len( tabs ) first = True open_panel = None for key, label, panel in tabs: if not first: imgui.same_line() if imgui.button( label, width = tab_width ): open_tab = key if open_tab == key: open_panel = panel first = False if open_panel != None: open_panel() return open_tab
def mediaDropDown(flight): # create a drop down for raw if imgui.tree_node("Raw ##" + str(flight.id)): # loop through all the 'raw' media in the flight for raw in flight.getFlightMedia().raw: # display the media name in the dropdown imgui.text(raw) imgui.tree_pop() # create a drop down for photos if imgui.tree_node("Photos ##" + str(flight.id)): # loop through all the 'photo' aka non raw media in the flight for photo in flight.getFlightMedia().images: # display the media name in the dropdown imgui.text(photo) # on the same line create the preview button for photos imgui.same_line() handlePhotoPreviewButtonClick(flight.flight_directory, photo) imgui.tree_pop() # create a drop down for videos if imgui.tree_node("Videos ##" + str(flight.id)): # loop through all the 'video' media in the flight for video in flight.getFlightMedia().video: # display the media name in the dropdown imgui.text(video) imgui.tree_pop()
def input_select(label, id_str, input_choices, cur_value, set_val): imgui.text(label) imgui.same_line() changed, new_val = imgui.core.combo(id_str, cur_value, input_choices) if changed: set_val(new_val)
def draw(self): imgui.begin(self.title) changed, self.text_val = imgui.input_text('Text', self.text_val, 256) imgui.text('You wrote:') imgui.same_line() imgui.text(self.text_val) imgui.end()
def input_int(label, id_str, input_val, set_val): imgui.text(label) imgui.same_line() changed, new_val = imgui.input_int(id_str, input_val) if changed: set_val(new_val)
def render_unsaved_close_drawing(window): "Popup to prevent accidentally closing a drawing with unsaved work." drawing = window.close_unsaved_drawing if drawing and drawing.unsaved: imgui.open_popup("Really close?") if imgui.begin_popup_modal("Really close?", flags=imgui.WINDOW_NO_RESIZE)[0]: imgui.text("The drawing contains unsaved work.") if imgui.button("Yes, close anyway"): window.drawings.remove(drawing) window.close_unsaved_drawing = None imgui.close_current_popup() imgui.same_line() if imgui.button("Yes, but save first"): window.save_drawing(drawing) window.drawings.remove(drawing) window.close_unsaved_drawing = None imgui.close_current_popup() imgui.same_line() if imgui.button("No, cancel"): window.close_unsaved_drawing = None imgui.close_current_popup() imgui.end_popup()
def draw_sector_mode(): if imgui.button("New sector"): cur_state.cur_sector = add_new_sector() if cur_state.cur_sector is not None: cur_sect = cur_state.cur_sector imgui.same_line() imgui.text("Sector {}".format(cur_sect.index)) input_int("Floor height: ", "##sector{}_floor_height".format(cur_sect.index), cur_sect.floor_height, lambda v: setattr(cur_sect, 'floor_height', v)) input_int("Floor color: ", "##sector{}_floor_color".format(cur_sect.index), cur_sect.floor_color, lambda v: setattr(cur_sect, 'floor_color', v)) input_int("Ceiling height: ", "##sector{}_ceil".format(cur_sect.index), cur_sect.ceil_height, lambda v: setattr(cur_sect, 'ceil_height', v)) input_int("Ceiling color: ", "##sector{}_ceil_color".format(cur_sect.index), cur_sect.ceil_color, lambda v: setattr(cur_sect, 'ceil_color', v)) def set_cur_sector(idx): cur_state.cur_sector = cur_state.map_data.sectors[idx] draw_list("Sectors", "Sector list", cur_state.map_data.sectors, set_cur_sector)
def dynamic_popup_button(self, label, error, tag=None): """ Validating button. Behaves in the same way as a regular `concur.widgets.button` when `error` is None. When `error` is a string, it displays an error popup instead of emitting an event. """ while True: if imgui.button(label): if error is not None: imgui.open_popup("Error Popup") else: return tag if tag is not None else label, None if imgui.begin_popup("Error Popup"): imgui.text(error) if self.is_continuable: if imgui.button("Continue anyway"): imgui.close_current_popup() imgui.end_popup() return tag if tag is not None else label, None imgui.same_line() if imgui.button("Cancel"): imgui.close_current_popup() imgui.end_popup() else: if imgui.button("OK"): imgui.close_current_popup() imgui.end_popup() yield
def draw_list(id_str, label, items, select_item, delete_callback=None): imgui.begin_child(id_str) imgui.text(label) cur_state.hovered_item = None for idx, item in enumerate(items): cur_id_str = "##list_{}_{}".format(id_str, idx) sel_btn_id = "Select {} {}".format(idx, cur_id_str) del_btn_id = "X{}".format(cur_id_str) imgui.begin_group() if imgui.button(sel_btn_id): print("clicked {}".format(idx)) select_item(idx) imgui.same_line() imgui.text(str(item)) if delete_callback is not None: imgui.same_line() if imgui.button(del_btn_id): delete_callback(item) print("delete!!") imgui.end_group() if imgui.is_item_hovered(): cur_state.hovered_item = item imgui.end_child()
def draw(self): imgui.new_frame() imgui.set_next_window_position(16, 32, imgui.ONCE) imgui.set_next_window_size(512, 512, imgui.ONCE) imgui.begin("Example: item groups") imgui.begin_group() imgui.text("First group (buttons):") imgui.button("Button A") imgui.button("Button B") imgui.end_group() imgui.same_line(spacing=50) imgui.begin_group() imgui.text("Second group (text and bullet texts):") imgui.bullet_text("Bullet A") imgui.bullet_text("Bullet B") imgui.end_group() imgui.end() imgui.end_frame() imgui.render() self.renderer.render(imgui.get_draw_data())
def draw_hand_gui(self): imgui.begin("Hand", True) changed, new_color = imgui.color_edit4('hand', *self.hand_color) if changed or self.load_hand: self.hand.set_color(np.array(new_color)) self.hand_color = new_color changed, new_color = imgui.color_edit4('baton', *self.baton_color) if changed or self.load_hand: self.baton.set_color(np.array(new_color)) self.baton_color = new_color imgui.text('state') dofs = self.system.get_state() for i in range(self.system.num_dofs()): changed, value = imgui.slider_float('b%d' % i, dofs[i], -np.pi, np.pi) if changed: dofs[i] = value if i < self.hand.num_dofs(): imgui.same_line() if imgui.button('step###%d'%i): self.close(i) dofs = self.system.get_state() self.system.set_state(dofs) self.load_hand = False imgui.end()
def draw(self): imgui.new_frame() pos_x = 10 pos_y = 10 sz = 20 draw_list = imgui.get_window_draw_list() for i in range(0, imgui.COLOR_COUNT): name = imgui.get_style_color_name(i) draw_list.add_rect_filled(pos_x, pos_y, pos_x + sz, pos_y + sz, imgui.get_color_u32_idx(i)) imgui.dummy(sz, sz) imgui.same_line() rgba_color = imgui.get_color_u32_rgba(1, 1, 0, 1) draw_list.add_rect_filled(pos_x, pos_y, pos_x + sz, pos_y + sz, rgba_color) imgui.end_frame() imgui.render() self.renderer.render(imgui.get_draw_data())
def input_int2(label, id_str, input_vals, set_vals): imgui.text(label) imgui.same_line() changed, new_vals = imgui.input_int2(id_str, *input_vals) if changed: set_vals(new_vals)
def render_new_drawing_popup(window): "Settings for creating a new drawing." if window._new_drawing: imgui.open_popup("New drawing") w, h = window.get_size() imgui.set_next_window_size(200, 120) imgui.set_next_window_position(w // 2 - 100, h // 2 - 60) if imgui.begin_popup_modal("New drawing")[0]: imgui.text("Creating a new drawing.") imgui.separator() changed, new_size = imgui.drag_int3("Shape", *window._new_drawing["shape"], min_value=1, max_value=2048) if changed: window._new_drawing["shape"] = new_size if imgui.button("OK"): window.really_create_drawing() imgui.close_current_popup() imgui.same_line() if imgui.button("Cancel"): window._new_drawing = None imgui.close_current_popup() imgui.end_popup()
def _draw_component(self, entity, component_name, component_name_display): if not entity.has_component(component_name): return treeNodeFlags = imgui.TREE_NODE_DEFAULT_OPEN | imgui.TREE_NODE_FRAMED | imgui.TREE_NODE_ALLOW_ITEM_OVERLAP | imgui.TREE_NODE_FRAME_PADDING component = entity.get_component(component_name) # contentRegionAvailable = imgui.get_content_region_available() # lineHeight = imgui.push_style_var(imgui.STYLE_FRAME_PADDING, (4, 4)) imgui.separator() open = imgui.tree_node(component_name_display, treeNodeFlags) imgui.pop_style_var() # TODO imgui.same_line(contentRegionAvailable.x - lin) imgui.same_line() if imgui.button("+"): imgui.open_popup("ComponentSettings") removeComponent = False if imgui.begin_popup("ComponentSettings"): if menu_item_clicked("Remove component"): removeComponent = True imgui.end_popup() if open: getattr(self, "_draw_component_%s" % component_name)(component) imgui.tree_pop() if removeComponent: entity.remove_component(component_name)
def draw(self): imgui.begin(self.title) changed, self.text_val = imgui.input_text_multiline( 'Message', self.text_val, 2056) imgui.text('You wrote:') imgui.same_line() imgui.text(self.text_val) imgui.end()
def draw(self): imgui.begin("Scope") self.begin_input(self.input) imgui.button('input') self.end_input() imgui.same_line(spacing=16) imgui.plot_lines("Sin(t)", np.array(self.values).astype(np.float32), graph_size=imgui.get_content_region_available()) imgui.end()
def draw(self): #imgui.set_next_window_position(self.window.width - 256 - 16, 32, imgui.ONCE) #imgui.set_next_window_size(256, 256, imgui.ONCE) imgui.begin("Meter") self.mark_input(self.input) imgui.text('input') imgui.same_line(spacing=16) imgui.plot_lines("Sin(t)", self.values) imgui.end()
def draw(self): imgui.begin(self.title) clicked, self.current = imgui.listbox( "List", self.current, self.options ) imgui.text("selection: ") imgui.same_line() imgui.text(self.options[self.current]) imgui.end()
def _display_zoom_or_pan_buttons(im): # : ImageWithZoomInfo): # display zoom or pan radio buttons current_mode = im.zoom_info.zoom_or_pan if imgui.radio_button(imgui_ext.make_unique_label("drag to pan"), current_mode == ZoomOrPan.Pan): im.zoom_info.zoom_or_pan = ZoomOrPan.Pan imgui.same_line() if imgui.radio_button(imgui_ext.make_unique_label("drag to zoom"), current_mode == ZoomOrPan.Zoom): im.zoom_info.zoom_or_pan = ZoomOrPan.Zoom
def render ( self ): super().render() if imgui.begin( "Music Editor" ): ( width, height ) = imgui.get_content_region_available(); ( changed, value ) = imgui.input_text_multiline( "###Code", self.code, 1000, width = width, height = height / 2 ) if changed: self.code = value to_parse = False to_play = False if imgui.button( "Parse" ): to_parse = True imgui.same_line() if imgui.button( "Play" ): to_play = True try: if to_parse or to_play: self.player = Player() self.player.sequencers.append( FluidSynthSequencer() ) parser = Parser(); self.parsedTree = parser.parse( self.code ) self.context = self.create_context( self.player ) value = self.parsedTree.eval( self.context ) self.player.events = events = list( value ) if isinstance( value, Music ) else [] self.parsedException = None if to_play: self.player.play() except Exception as ex: self.parsedException = ex print(ex) traceback.print_tb(ex.__traceback__) if self.parsedException != None: imgui.text_colored( str( self.parsedException ), 1, 0, 0 ) self.expressionTab = self.imgui_tabbar( self.expressionTab, [ ( EXPRESSION_TAB_AST, "AST", self.render_inspector_ast ), ( EXPRESSION_TAB_EVENTS, "Events", self.render_inspector_events ), ( EXPRESSION_TAB_KEYBOARD, "Keyboard", self.render_inspector_keyboard ) ] ) imgui.end()
def gui(self): imgui.begin_child(self.name) for item, remove_button in zip(self.items, self.remove_buttons): if isinstance(item, Widget): item.gui() else: text = getattr(item, 'name', str(item)) imgui.label_text(text, text) imgui.same_line() remove_button.gui() imgui.end_child()
def _imgui_pick_file_menu(base_path, wildcard="*"): MAX_FILE_DISPLAY_LENGTH = 60 try: entries = [] for name in os.listdir(base_path): entries.append( (not os.path.isdir(os.path.join(base_path, name)), name)) imgui.text("New:") imgui.same_line() imgui.push_item_width(-1) changed, value = imgui.input_text("", "", 255, imgui.INPUT_TEXT_ENTER_RETURNS_TRUE) if changed: return os.path.join(base_path, value) imgui.separator() for w in WILDCARDS: if imgui.button(w): return os.path.join(base_path, w) imgui.same_line() imgui.dummy(0, 0) imgui.separator() if len(entries) == 0: imgui.dummy(200, 0) for not_is_dir, name in sorted(entries): display_name = name if len(display_name) > MAX_FILE_DISPLAY_LENGTH: display_name = display_name[:MAX_FILE_DISPLAY_LENGTH // 2] + "..." + display_name[ -MAX_FILE_DISPLAY_LENGTH // 2:] if not not_is_dir: if imgui.begin_menu(display_name): selected_path = _imgui_pick_file_menu( os.path.join(base_path, name), wildcard) imgui.end_menu() if selected_path is not None: return os.path.join(base_path, selected_path) else: if not fnmatch.fnmatch(name, wildcard): continue clicked, state = imgui.menu_item(display_name, None, False) if clicked: return os.path.join(base_path, name) imgui.separator() imgui.text("Pick: %s" % wildcard) except: imgui.text("Unable to open dir")
def draw_imgui(scene: Scene): if Settings.GuiEnabled: # Menu Bar if imgui.begin_main_menu_bar(): if imgui.begin_menu("File"): imgui.menu_item("Open") if imgui.menu_item("Exit")[0]: glfw.terminate() imgui.end_menu() if imgui.begin_menu("View"): if imgui.menu_item("Grid", shortcut='G', selected=Settings.GridEnabled)[0]: Settings.GridEnabled = not Settings.GridEnabled if imgui.menu_item("GUI", shortcut='TAB', selected=Settings.GuiEnabled)[0]: Settings.GuiEnabled = not Settings.GuiEnabled if imgui.menu_item("Stats", shortcut='P', selected=Settings.StatsEnabled)[0]: Settings.StatsEnabled = not Settings.StatsEnabled imgui.end_menu() if Settings.StatsEnabled: imgui.same_line(imgui.get_window_width() - 150) imgui.text("FPS: " + "%.2f" % Global.fps + " " + "%.2f" % Global.frametime + "ms") imgui.end_main_menu_bar() # imgui.show_demo_window() # Scene imgui.begin("Scene") draw_node_item(scene.nodelist[0], scene) imgui.end() imgui.begin("Properties") imgui.text("Model") imgui.end() else: pass
def _heartbeat(self): if not self.opened: return if self.current_image == "": self._select_first_image() imgui.set_next_window_position(self.position.x, self.position.y, imgui.APPEARING) imgui.set_next_window_size(self.actual_window_startup_size().x, self.actual_window_startup_size().y, imgui.APPEARING) expanded, self.opened = imgui.begin("Imgui Image Lister") self._show_list() imgui.same_line() self._show_image() imgui.end()
def draw(self): imgui.begin(self.title) if imgui.listbox_header("Custom List", 200, 100): for option in OPTIONS: clicked, selected = imgui.selectable(option, option == self.selected) if clicked: self.selected = option imgui.listbox_footer() imgui.text("selection: ") imgui.same_line() imgui.text(self.selected) imgui.end()
def main(): pygame.init() size = 800, 600 pygame.display.set_mode(size, pygame.DOUBLEBUF | pygame.OPENGL) pygame.display.set_caption("GBDev tool window") io = imgui.get_io() io.fonts.add_font_default() io.display_size = size renderer = PygameRenderer() while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() renderer.process_event(event) imgui.new_frame() if imgui.begin_main_menu_bar(): if imgui.begin_menu("Menu", True): open_gbtd, selected_none = imgui.menu_item("Open GBTD", None, False, True) open_gbtk, selected_none = imgui.menu_item("Open GBTK", None, False, True) export_json, selected_none = imgui.menu_item("Export Default Json", None, False, True) clicked_quit, selected_quit = imgui.menu_item("Quit", 'Cmd+Q', False, True) if clicked_quit: exit(1) if open_gbtd: os.system("wine tools/GBTD/GBTD.EXE &") if open_gbtk: os.system("wine tools/GBTK.exe &") if export_json: tools.json2c.default_use() imgui.end_menu() imgui.end_main_menu_bar() imgui.begin("Data", True) img_path = "data/img" onlyfiles = [f for f in listdir(img_path) if isfile(join(img_path, f))] #print(onlyfiles) for file in onlyfiles: imgui_image_menu(img_path+"/"+file) imgui.end() imgui.begin("Images", True) imgs_id = [] for img_filename in onlyfiles: if img_filename.split(".")[-1] == "png": imgs_id.append((img_path+"/"+img_filename, img_manager.load_image(img_path+"/"+img_filename))) for img in imgs_id: img_size = img_manager.get_image_size(img[0]) if img[1] is not 0 and img_size is not (): imgui.image(img[1], img_size[0]*2, img_size[1]*2, (0,1), (1,0)) imgui.same_line() imgui.end() # note: cannot use screen.fill((1, 1, 1)) because pygame's screen # does not support fill() on OpenGL sufraces gl.glClearColor(1, 1, 1, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() pygame.display.flip()