def update(self): self.window_size = pygame.display.get_surface().get_size() if self.use_base_window: imgui.set_next_window_position(0, 0) imgui.set_next_window_size(self.window_size[0], self.window_size[1]) imgui.begin("main", False, self.base_window_flags) if self.use_menu_bar and imgui.begin_menu_bar(): self.draw_menu() imgui.end_menu_bar() self.draw_base_window() imgui.end() else: if self.use_menu_bar and imgui.begin_main_menu_bar(): self.draw_menu() imgui.end_main_menu_bar() self.draw_windows() if self.show_style_window: self.show_style_window = imgui.begin("Style Editor", True)[1] imgui.show_style_editor() imgui.end() if self.show_demo_window: self.show_demo_window = imgui.show_demo_window(True)
def draw_menu(self): imgui.push_style_var(imgui.STYLE_WINDOW_PADDING, (8, 8)) if imgui.begin_menu_bar(): # first menu dropdown if imgui.begin_menu('菜单', True): if utils.is_menu_item_click('导出', 'Ctrl+O+P', False, True): print "暂不支持" if utils.is_menu_item_click('设置', 'Ctrl+Alt+S', False, True): print "设置" imgui.end_menu() if imgui.begin_menu("工具", True): if utils.is_menu_item_click("查找", "Ctrl+F", False, True): print "查找" if utils.is_menu_item_click("自定义GM", "Ctrl+G", False, True): print "自定义GM" imgui.end_menu() if imgui.begin_menu("帮助", True): if utils.is_menu_item_click("文档", "F1", False, True): print "文档" if utils.is_menu_item_click("快捷键", "Ctrl+M", False, True): print "快捷键" if utils.is_menu_item_click("关于...", None, False, True): print "关于" imgui.end_menu() imgui.end_menu_bar() imgui.pop_style_var()
def draw(self): flags = imgui.WINDOW_MENU_BAR imgui.begin("Child Window - File Browser", flags=flags) if imgui.begin_menu_bar(): if imgui.begin_menu('File'): imgui.menu_item('Close') imgui.end_menu() imgui.end_menu_bar() imgui.end()
def mainMenuBar(): if imgui.begin_menu_bar(): # Create a menu bar button for locations if imgui.begin_menu('Locations'): # Loop through all the locations to then be sorted for location in flights.getFlightLocations(): # create the menu item so we can check if clicked click, state = imgui.menu_item( location, selected=currentSelectedLocations[location]) if click: # if the button was clicked just toggle the boolean in the currentselected locations as this handles showing or hiding # in the loop below in the main GUi panel currentSelectedLocations[ location] = not currentSelectedLocations[location] imgui.end_menu() imgui.end_menu_bar()
def draw(self): imgui.new_frame() imgui.set_next_window_position(16, 32, imgui.ONCE) imgui.set_next_window_size(512, 512, imgui.ONCE) flags = imgui.WINDOW_MENU_BAR imgui.begin("Child Window - File Browser", flags=flags) if imgui.begin_menu_bar(): if imgui.begin_menu('File'): imgui.menu_item('Close') imgui.end_menu() imgui.end_menu_bar() imgui.end() imgui.end_frame() imgui.render() self.renderer.render(imgui.get_draw_data())
def frame_commands(): io = imgui.get_io() if io.key_ctrl and io.keys_down[glfw.KEY_Q]: sys.exit(0) with imgui.begin_main_menu_bar() as main_menu_bar: if main_menu_bar.opened: with imgui.begin_menu("File", True) as file_menu: if file_menu.opened: clicked_quit, selected_quit = imgui.menu_item( "Quit", "Ctrl+Q") if clicked_quit: sys.exit(0) # turn examples on/off with imgui.begin("Active examples"): for label, enabled in active.copy().items(): _, enabled = imgui.checkbox(label, enabled) active[label] = enabled if active["window"]: with imgui.begin("Hello, Imgui!"): imgui.text("Hello, World!") if active["child"]: with imgui.begin("Example: child region"): with imgui.begin_child("region", 150, -50, border=True): imgui.text("inside region") imgui.text("outside region") if active["tooltip"]: with imgui.begin("Example: tooltip"): imgui.button("Click me!") if imgui.is_item_hovered(): with imgui.begin_tooltip(): imgui.text("This button is clickable.") if active["menu bar"]: try: flags = imgui.WINDOW_MENU_BAR with imgui.begin("Child Window - File Browser", flags=flags): with imgui.begin_menu_bar() as menu_bar: if menu_bar.opened: with imgui.begin_menu('File') as file_menu: if file_menu.opened: clicked, state = imgui.menu_item('Close') if clicked: active["menu bar"] = False raise Exception except Exception: print("exception handled") if active["popup"]: with imgui.begin("Example: simple popup"): if imgui.button("select"): imgui.open_popup("select-popup") imgui.same_line() with imgui.begin_popup("select-popup") as popup: if popup.opened: imgui.text("Select one") imgui.separator() imgui.selectable("One") imgui.selectable("Two") imgui.selectable("Three") if active["popup modal"]: with imgui.begin("Example: simple popup modal"): if imgui.button("Open Modal popup"): imgui.open_popup("select-popup-modal") imgui.same_line() with imgui.begin_popup_modal("select-popup-modal") as popup: if popup.opened: imgui.text("Select an option:") imgui.separator() imgui.selectable("One") imgui.selectable("Two") imgui.selectable("Three") if active["popup context item"]: with imgui.begin("Example: popup context view"): imgui.text("Right-click to set value.") with imgui.begin_popup_context_item("Item Context Menu") as popup: if popup.opened: imgui.selectable("Set to Zero") if active["popup context window"]: with imgui.begin("Example: popup context window"): with imgui.begin_popup_context_window() as popup: if popup.opened: imgui.selectable("Clear") if active["popup context void"]: with imgui.begin_popup_context_void() as popup: if popup.opened: imgui.selectable("Clear") if active["drag drop"]: with imgui.begin("Example: drag and drop"): imgui.button('source') with imgui.begin_drag_drop_source() as src: if src.dragging: imgui.set_drag_drop_payload('itemtype', b'payload') imgui.button('dragged source') imgui.button('dest') with imgui.begin_drag_drop_target() as dst: if dst.hovered: payload = imgui.accept_drag_drop_payload('itemtype') if payload is not None: print('Received:', payload) if active["group"]: with imgui.begin("Example: item groups"): with imgui.begin_group(): imgui.text("First group (buttons):") imgui.button("Button A") imgui.button("Button B") imgui.same_line(spacing=50) with imgui.begin_group(): imgui.text("Second group (text and bullet texts):") imgui.bullet_text("Bullet A") imgui.bullet_text("Bullet B") if active["tab bar"]: with imgui.begin("Example Tab Bar"): with imgui.begin_tab_bar("MyTabBar") as tab_bar: if tab_bar.opened: with imgui.begin_tab_item("Item 1") as item1: if item1.opened: imgui.text("Here is the tab content!") with imgui.begin_tab_item("Item 2") as item2: if item2.opened: imgui.text("Another content...") global opened_state with imgui.begin_tab_item("Item 3", opened=opened_state) as item3: opened_state = item3.opened if item3.selected: imgui.text("Hello Saylor!") if active["list box"]: with imgui.begin("Example: custom listbox"): with imgui.begin_list_box("List", 200, 100) as list_box: if list_box.opened: imgui.selectable("Selected", True) imgui.selectable("Not Selected", False) if active["table"]: with imgui.begin("Example: table"): with imgui.begin_table("data", 2) as table: if table.opened: imgui.table_next_column() imgui.table_header("A") imgui.table_next_column() imgui.table_header("B") imgui.table_next_row() imgui.table_next_column() imgui.text("123") imgui.table_next_column() imgui.text("456") imgui.table_next_row() imgui.table_next_column() imgui.text("789") imgui.table_next_column() imgui.text("111") imgui.table_next_row() imgui.table_next_column() imgui.text("222") imgui.table_next_column() imgui.text("333")
def render(): global selected_index, selected_file, clones_for_file, padding imgui.set_next_window_position(10, 10) imgui.set_next_window_size(280, 375) imgui.begin( "Clone Classes", False, imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_COLLAPSE | imgui.WINDOW_MENU_BAR) if imgui.begin_menu_bar(): if imgui.begin_menu('Sort'): clicked, _ = imgui.menu_item('identifier (ascending)') if clicked: clones.sort(key=lambda x: x.class_identifier) clicked, _ = imgui.menu_item('identifier (descending)') if clicked: clones.sort(key=lambda x: x.class_identifier, reverse=True) clicked, _ = imgui.menu_item('clones (ascending)') if clicked: clones.sort(key=lambda x: x.num_clones) clicked, _ = imgui.menu_item('clones (descending)') if clicked: clones.sort(key=lambda x: x.num_clones, reverse=True) clicked, _ = imgui.menu_item('files (ascending)') if clicked: clones.sort(key=lambda x: len(x.files)) clicked, _ = imgui.menu_item('files (descending)') if clicked: clones.sort(key=lambda x: len(x.files), reverse=True) imgui.end_menu() imgui.end_menu_bar() for index, clone_class in enumerate(clones): if selected_index is clone_class.class_identifier: label = "--> Class {0:03d} ({1} files, {2} clones)".format( clone_class.class_identifier, len(clone_class.files), clone_class.num_clones) else: label = "Class {0:03d} ({1} files, {2} clones)".format( clone_class.class_identifier, len(clone_class.files), clone_class.num_clones) if imgui.button(label, width=260): select_clone(clone_class.class_identifier) imgui.end() imgui.set_next_window_position(10, 390) imgui.set_next_window_size(280, 380) imgui.begin( "Files", False, imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_COLLAPSE) for index, file_name in enumerate(unique_file_name): if selected_file is file_name: label = "--> {}".format(os.path.basename(file_name)) else: label = "{}".format(os.path.basename(file_name)) if imgui.button(label, width=260): select_file(file_name) imgui.end() imgui.set_next_window_position(300, 10) imgui.set_next_window_size(890, 760) imgui.begin( "Details", False, imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_COLLAPSE | imgui.WINDOW_HORIZONTAL_SCROLLING_BAR | imgui.WINDOW_MENU_BAR) if selected_file is not None and clones_for_file is not None: if imgui.begin_menu_bar(): if imgui.begin_menu('Actions'): clicked, _ = imgui.menu_item('Open in editor') if clicked: os.system("open \"{}\"".format(selected_file)) imgui.end_menu() imgui.end_menu_bar() file_buffer = file_buffers[selected_file] total_cloned_lines = 0 for _, file in clones_for_file: total_cloned_lines += file.num_cloned_lines imgui.begin_group() imgui.text("Information for this file") imgui.bullet_text("This file contains {} lines".format( file_buffer.max_line)) imgui.bullet_text("{} lines are cloned".format(total_cloned_lines)) imgui.bullet_text("That is {0:.2f}% of the total file".format( total_cloned_lines / file_buffer.max_line * 100)) imgui.end_group() imgui.same_line(300) imgui.push_item_width(200) imgui.begin_group() changed, value = imgui.slider_int("Lines of padding", padding, 0, 100) if changed: padding = value imgui.end_group() imgui.pop_item_width() imgui.spacing() imgui.spacing() imgui.spacing() imgui.spacing() for class_identifier, file in clones_for_file: expanded, visible = imgui.collapsing_header( "Clone class {0:03d}".format(class_identifier), None, imgui.TREE_NODE_DEFAULT_OPEN) if expanded: if imgui.button( "View all files for clone class {0:03d}".format( class_identifier)): select_clone(class_identifier) file_buffers[file.file_name].to_imgui(file, padding) if selected_index is not None: imgui.push_item_width(200) imgui.begin_group() changed, value = imgui.slider_int("Lines of padding", padding, 0, 100) if changed: padding = value imgui.end_group() imgui.pop_item_width() clone_class = None for clone in clones: if clone.class_identifier is selected_index: clone_class = clone for i, file in enumerate(clone_class.files): expanded, visible = imgui.collapsing_header( file.file_name, None, imgui.TREE_NODE_DEFAULT_OPEN) if expanded: if imgui.button("View all clones for \"{}\"".format( file.file_name)): select_file(file.file_name) file_buffers[file.file_name].to_imgui(file, padding) imgui.end()