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 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 gui(self): if imgui.begin_popup(self.name): imgui.label_text(self.name, self.name) if imgui.button('Ok'): self.callback() imgui.close_current_popup() imgui.end_popup()
def gui(self): if imgui.begin_popup(self.name): self.form.gui() if imgui.button(self.name): self.callback(self.form.context) imgui.close_current_popup() self.form.init() imgui.end_popup()
def imgui_pick_file(name, base_path, wildcard="*"): if imgui.begin_popup(name): path = _imgui_pick_file_menu(base_path, wildcard) if path is not None: imgui.close_current_popup() imgui.end_popup() return path imgui.end_popup()
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 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 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 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 _draw_entity_components(self, entity): ValueEdit(entity, "tag", "input_text", "Tag")() # --------------------------------------------------- # add component # --------------------------------------------------- imgui.same_line() imgui.push_item_width(-1) if imgui.button("Add Component"): imgui.open_popup("AddComponent") if imgui.begin_popup("AddComponent"): if menu_item_clicked("Transform"): entity.add_component("transform") imgui.close_current_popup() if menu_item_clicked("Camera"): print "add component camera" imgui.close_current_popup() if menu_item_clicked("Sprite Renderer"): print "add component sprite renderer" imgui.close_current_popup() if menu_item_clicked("Physics"): entity.add_component("physics") imgui.close_current_popup() imgui.end_popup() imgui.pop_item_width() # --------------------------------------------------- # draw components # --------------------------------------------------- self._draw_component(entity, "transform", "Transform") self._draw_component(entity, "camera", "Camera") self._draw_component(entity, "sprite_renderer", "Sprite Renderer") self._draw_component(entity, "physics", "Physics")
def render_color_editor(orig, color): r, g, b, a = color io = imgui.get_io() delta = 0 imgui.push_id("R") # TODO find a less verbose way to do something like this: # imgui.push_style_color(imgui.COLOR_FRAME_BACKGROUND, r/255, 0, 0) # imgui.push_style_color(imgui.COLOR_FRAME_BACKGROUND_HOVERED, r/255, 0, 0) # imgui.push_style_color(imgui.COLOR_FRAME_BACKGROUND_ACTIVE, r/255, 0, 0) # imgui.push_style_color(imgui.COLOR_SLIDER_GRAB, 1, 1, 1) # imgui.push_style_color(imgui.COLOR_SLIDER_GRAB_ACTIVE, 1, 1, 1) _, r = imgui.v_slider_int("", 30, 255, r, min_value=0, max_value=255) # imgui.pop_style_color() # imgui.pop_style_color() # imgui.pop_style_color() # imgui.pop_style_color() # imgui.pop_style_color() if imgui.is_item_hovered(): delta = int(io.mouse_wheel) if not io.key_shift: r = _change_channel(r, delta) imgui.pop_id() imgui.same_line() imgui.push_id("G") _, g = imgui.v_slider_int("", 30, 255, g, min_value=0, max_value=255) if imgui.is_item_hovered(): delta = int(io.mouse_wheel) if not io.key_shift: g = _change_channel(g, delta) imgui.pop_id() imgui.same_line() imgui.push_id("B") _, b = imgui.v_slider_int("", 30, 255, b, min_value=0, max_value=255) if imgui.is_item_hovered(): delta = int(io.mouse_wheel) if not io.key_shift: b = _change_channel(b, delta) imgui.pop_id() if delta and io.key_shift: r = _change_channel(r, delta) g = _change_channel(g, delta) b = _change_channel(b, delta) if imgui.checkbox("Transp.", a == 0)[1]: a = 0 else: a = 255 imgui.color_button("Current color", *as_float(orig)) imgui.same_line() imgui.text("->") imgui.same_line() imgui.color_button("Current color", *as_float(color)) if imgui.button("OK"): imgui.close_current_popup() return True, False, (r, g, b, a) imgui.same_line() if imgui.button("Cancel"): imgui.close_current_popup() return False, True, (r, g, b, a) return False, False, (r, g, b, a)
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()