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 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 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 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 _begin_popup_modal(*args, **kwargs): global _frames_without_modal result = ig.begin_popup_modal(*args, **kwargs) if result[0]: _stack.append(('begin_popup_modal', (args, kwargs))) _push_logical_id(args) _frames_without_modal = 0 return result
def _render_gui(self): w, h = self.get_size() imgui.new_frame() if self.stroke_tool and self.stroke_tool.show_rect: if self.stroke_tool.rect: rect = self.stroke_tool.rect p0 = self._to_window_coords(*rect.topleft) p1 = self._to_window_coords(*rect.bottomright) ui.render_selection_rectangle(self, p0, p1) with imgui.font(self._font): ui.render_menu(self) if self.drawing: imgui.set_next_window_size(115, h - 20) imgui.set_next_window_position(w - 115, 20) imgui.begin("Sidebar", False, flags=(imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE)) ui.render_tools(self.tools, self.icons) imgui.separator() ui.render_palette(self.drawing) imgui.separator() ui.render_layers(self.view) imgui.end() ui.render_unsaved_exit(self) ui.render_unsaved_close_drawing(self) render_plugins_ui(self.drawing) ui.render_new_drawing_popup(self) if self._error: imgui.open_popup("Error") if imgui.begin_popup_modal("Error")[0]: imgui.text(self._error) if imgui.button("Doh!"): self._error = None imgui.close_current_popup() imgui.end_popup() imgui.render() imgui.end_frame() data = imgui.get_draw_data() self.imgui_renderer.render(data)
def render_errors(window): if window._error: imgui.open_popup("Error") if imgui.begin_popup_modal("Error")[0]: imgui.text(window._error) if imgui.button("Doh!"): window._error = None imgui.close_current_popup() imgui.end_popup()
def show_outputs_popup(iggraph): if imgui.begin_popup_modal("Outputs")[0]: output_nodes = iggraph.get_output_nodes() for output_node in output_nodes: if imgui.tree_node(output_node.inputs["parameter name"].text): value = output_node.outputs["output"] display_parameter(value,True) imgui.tree_pop() imgui.separator() if imgui.button("ok"): imgui.close_current_popup() imgui.end_popup()
def draw(self): 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()
def show_inputs_popup(iggraph): show_result = False if imgui.begin_popup_modal("User Input")[0]: input_nodes = iggraph.get_input_nodes() for input_node in input_nodes: if imgui.tree_node(input_node.inputs["parameter name"].text): default_value = input_node.inputs["default value"] display_parameter(default_value,True) imgui.tree_pop() imgui.separator() if imgui.button("run workflow"): imgui.close_current_popup() # iggraph.reset() iggraph.run() show_result = True imgui.same_line() if imgui.button("cancel"): iggraph.reset() iggraph.set_state(iggraph.STATE_IDLE) imgui.close_current_popup() imgui.end_popup() return show_result
def main(): # Theme Index THEME_INDEX = 2 # window visible params bShowInfoPopUp = False bShowFiles = True bShowParsePdf = True bShowParserStatics = True bShowImg = False bShowTestWindow = True #delete cache files if os.path.isfile('ParseResult.log'): os.remove('ParseResult.log') if os.path.isfile('ManualFiles.log'): os.remove('ManualFiles.log') if os.path.isfile('Cluster.png'): os.remove('Cluster.png') pygame.init() size = 1280, 720 # 720p # size = 1920, 1080 # 1080p pygame.display.set_mode( size, pygame.DOUBLEBUF | pygame.OPENGL | pygame.RESIZABLE) pygame.display.set_caption("PDF成績單解析器") clock = pygame.time.Clock() favicon = pygame.image.load('asset\\Logo.png') pygame.display.set_icon(favicon) imgui.create_context() impl = PygameRenderer() io = imgui.get_io() smallfont = io.fonts.add_font_from_file_ttf( "asset\\NotoSansTC-Black.otf", 12, io.fonts.get_glyph_ranges_chinese_full()) normalfont = io.fonts.add_font_from_file_ttf( "asset\\NotoSansTC-Black.otf", 16, io.fonts.get_glyph_ranges_chinese_full()) largefont = io.fonts.add_font_from_file_ttf( "asset\\NotoSansTC-Black.otf", 28, io.fonts.get_glyph_ranges_chinese_full()) io.fonts.add_font_default() impl.refresh_font_texture() io.display_size = size style = imgui.get_style() if THEME_INDEX == 1: GF.SetCustomStyle1(style) elif THEME_INDEX == 2: GF.SetCustomStyle2(style) elif THEME_INDEX == 3: GF.SetCustomStyle3(style) CV = 0 MV = 200 while 1: clock.tick(30) # fixed 15 fps for event in pygame.event.get(): if event.type == pygame.QUIT: # remove cache here sys.exit() if event.type == pygame.VIDEORESIZE: print('resize is triggered!') # shortcut bindings if event.type == pygame.KEYDOWN: if event.mod == pygame.KMOD_LCTRL and event.key == pygame.K_q: sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_F1: GF.OpenHelper() impl.process_event(event) imgui.push_style_var(imgui.STYLE_FRAME_PADDING, (10, 12.5)) imgui.new_frame() # Main menu region if imgui.begin_main_menu_bar(): with imgui.font(normalfont): if imgui.begin_menu("設定", True): if imgui.begin_menu(label="主題", enabled=True): if THEME_INDEX == 1: imgui.menu_item("默認", None, True, True) else: c, _ = imgui.menu_item("默認", None, False, True) if c: GF.SetCustomStyle1(style) THEME_INDEX = 1 if THEME_INDEX == 2: imgui.menu_item("CorporateGrey", None, True, True) else: c, _ = imgui.menu_item("CorporateGrey", None, False, True) if c: GF.SetCustomStyle2(style) THEME_INDEX = 2 if THEME_INDEX == 3: imgui.menu_item("Light", None, True, True) else: c, _ = imgui.menu_item("Light", None, False, True) if c: GF.SetCustomStyle3(style) THEME_INDEX = 3 imgui.end_menu() clicked_quit, selected_quit = imgui.menu_item( "Quit", "L-Ctrl + Q", False, True) if clicked_quit: sys.exit() imgui.end_menu() if imgui.begin_menu("視窗", True): if not bShowFiles: F, _ = imgui.menu_item(label="選擇目錄", shortcut=None, selected=False, enabled=True) else: F, _ = imgui.menu_item(label="選擇目錄", shortcut=None, selected=True, enabled=True) if F: bShowFiles = not bShowFiles if not bShowParsePdf: o, _ = imgui.menu_item(label="解析成績單", shortcut=None, selected=False, enabled=True) else: o, _ = imgui.menu_item(label="解析成績單", shortcut=None, selected=True, enabled=True) if o: bShowParsePdf = not bShowParsePdf if not bShowParserStatics: r, _ = imgui.menu_item(label="解析結果", shortcut=None, selected=False, enabled=True) else: r, _ = imgui.menu_item(label="解析結果", shortcut=None, selected=True, enabled=True) if r: bShowParserStatics = not bShowParserStatics imgui.end_menu() if imgui.begin_menu("資訊", True): I, _ = imgui.menu_item("關於", None, selected=False, enabled=True) h, _ = imgui.menu_item("幫助", shortcut="F1", selected=False, enabled=True) if I: bShowInfoPopUp = True if h: GF.OpenHelper() imgui.end_menu() #imgui.pop_style_var(1) imgui.end_main_menu_bar() # Conditional windows if bShowFiles: imgui.set_next_window_position(0, 35, imgui.ONCE) imgui.set_next_window_size(230, 685, imgui.ONCE) with imgui.font(normalfont): bFileWindow = imgui.begin("選擇目錄", True, flags=imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_COLLAPSE) if not bFileWindow[1]: bShowFiles = False GE.FileWindow() imgui.end() if bShowParsePdf: imgui.set_next_window_position(230, 35, imgui.ONCE) imgui.set_next_window_size(450, 685, imgui.ONCE) with imgui.font(normalfont): bParsePdf = imgui.begin("解析成績單", True) if not bParsePdf[1]: bShowParsePdf = False GE.ParsePdfWidget() imgui.end() if bShowParserStatics: imgui.set_next_window_position(680, 35, imgui.ONCE) imgui.set_next_window_size(600, 685, imgui.ONCE) with imgui.font(normalfont): bParserStats = imgui.begin("解析結果", True) if not bParserStats[1]: bShowParserStatics = False GE.ParserStaticsWidget() if os.path.isfile('Cluster.png'): img_info = GF.loadImage('Cluster.png') imgui.image(img_info[0], img_info[1], img_info[2]) imgui.end() if (bShowInfoPopUp): imgui.open_popup("資訊") imgui.set_next_window_size(600, 300) imgui.font(normalfont) if imgui.begin_popup_modal(title="資訊", visible=True, flags=0)[0]: GE.ProgramInfoPopup() imgui.separator() bShowInfoPopUp = False imgui.end_popup() if THEME_INDEX == 1: gl.glClearColor(0.1, 0.1, 0.1, 1) # for default theme elif THEME_INDEX == 2: gl.glClearColor(0.45, 0.55, 0.6, 1) # for light theme elif THEME_INDEX == 3: gl.glClearColor(0.25, 0.25, 0.25, 1.00) imgui.pop_style_var() gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() impl.render(imgui.get_draw_data()) pygame.display.flip() CV += 1
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 main(): loadFlightData() imgui.create_context() window = impl_glfw_init() impl = GlfwRenderer(window) while not glfw.window_should_close(window): glfw.poll_events() impl.process_inputs() # get the style object and edit the object to make it look decent with GLFW style = imgui.get_style() style.window_rounding = 0 style.frame_rounding = 0 #create the main ImGuI frame to then use to display the actual GUI on imgui.new_frame() flags = imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_COLLAPSE | imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_MENU_BAR imgui.set_next_window_size(window_width, window_height) imgui.set_next_window_position(0, 0) # Start the beginning of the ImGui window, drone flight logger being an ID imgui.begin("Drone Flight Logger", False, flags=flags) if imgui.button("Add new Flight"): imgui.open_popup("test") imgui.same_line() imgui.text("Total Flight Time: " + str(flights.getTotalFlightTime()) + "h") imgui.same_line() imgui.text("| Total Batteries Used: " + str(flights.getTotalBatteriesUsed())) # Main Menu Bar Code mainMenuBar() # create a child window in the inital window to divide the window up so there can be a preview on the left imgui.begin_child("flight_selector", width=window_width / 5 * 2, border=True) # loop through all flights and assign flight as the key value for flight in flights.getFlights(): # get the flight data based off the flight name flight_data = flights.getFlights()[flight] # if the flight location is in the List variable of currently selected locations show it if currentSelectedLocations[flight_data.getLocationName()]: # flight drop down code, passing in the flight name and flight data flightDropDown(flight, flight_data) imgui.end_child() imgui.same_line() # create the preview sidepane of the main window imgui.begin_child("flight_info", border=True) # if there is the key preview in currentviewingflightdata show the image. Done this way as I will eventually add in the flight location and other stats to the sidepane as well if "preview" in currentViewingFlightData: imgui.image(currentViewingFlightData["preview"]['image'], currentViewingFlightData["preview"]['width'] / 6, currentViewingFlightData["preview"]['height'] / 6) imgui.end_child() if imgui.begin_popup_modal("test")[0]: addNewFlightData["date"] = imgui.input_text( "Flight date", addNewFlightData["date"], 2046)[1] addNewFlightData["batteries_used"] = imgui.input_int( 'Batteries used', addNewFlightData["batteries_used"])[1] addNewFlightData["flight_time"] = imgui.input_int( 'Flight time in minutes', addNewFlightData["flight_time"])[1] addNewFlightData["location_name"] = imgui.input_text( "Flight location", addNewFlightData["location_name"], 2046)[1] addNewFlightData["copyFromFolder"] = imgui.input_text( "Folder with new flight media", addNewFlightData["copyFromFolder"], 2046)[1] if imgui.button("test"): handleAddNewFlight() imgui.close_current_popup() # imgui.text("Select an option:") # imgui.separator() # imgui.selectable("One") # imgui.selectable("Two") # imgui.selectable("Three") imgui.end_popup() imgui.end() gl.glClearColor(1., 1., 1., 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() impl.render(imgui.get_draw_data()) glfw.swap_buffers(window) impl.shutdown() glfw.terminate()