def draw(self): imgui.begin("Example: popup context view") imgui.text("Right-click to set value.") if imgui.begin_popup_context_item("Item Context Menu"): imgui.selectable("Set to Zero") imgui.end_popup() imgui.end()
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_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 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_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 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 on_gui(self): # --------------------------------------------------- # Scene Hierarchy # --------------------------------------------------- imgui.begin("Scene Hierarchy") # draw all entities for entity in self.scene: self._draw_entity_node(entity) # clear selection if imgui.is_mouse_down(0) and imgui.is_window_hovered(): self.selected_entity = None # create new entity if imgui.begin_popup_context_window(): if menu_item_clicked("Create Empty Entity"): self.scene.create_entity("Empty Entity") imgui.end_popup() imgui.end() # --------------------------------------------------- # Properties # --------------------------------------------------- imgui.begin("Properties") if self.selected_entity: self._draw_entity_components(self.selected_entity) imgui.end()
def _draw_entity_node(self, entity): tag = entity.tag flags = imgui.TREE_NODE_SELECTED if self.selected_entity == entity else 0 opened = imgui.tree_node(tag, flags) if imgui.is_item_clicked(): self.selected_entity = entity entityDeleted = False # get delete entity if imgui.begin_popup_context_item(): if menu_item_clicked("Delete Entity"): entityDeleted = True imgui.end_popup() # handle opened if opened: # flags = imgui.TREE_NODE_OPEN_ON_ARROW # pass # TODO draw sub object HERE # if imgui.tree_node(tag, flags): # imgui.tree_pop() imgui.tree_pop() # handle delete entity if entityDeleted: self.scene.destroy_entity(entity) if self.selected_entity == entity: self.selected_entity = None
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 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 _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 _show_custom_ui(self): super()._show_custom_ui() if imgui.button("choose file"): imgui.open_popup("choose_file") if imgui.begin_popup("choose_file"): for i, path in enumerate(self._files): if imgui.menu_item(path, "", False, True)[0]: self.set_state({"index": i}) imgui.end_popup()
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(self, value, read_only): clicked, self.show_texture = imgui.checkbox("Show", self.show_texture) if not self.show_texture: return texture = value.value if texture is None: self.texture_aspect = None else: h, w, _ = texture.shape self.texture_aspect = w / h cursor_pos = imgui.get_cursor_screen_pos() imgui.set_next_window_size(500, 500, imgui.ONCE) imgui.set_next_window_size_constraints((0.0, 0.0), (float("inf"), float("inf")), self.window_size_callback) imgui.set_next_window_position(*imgui.get_io().mouse_pos, imgui.ONCE, pivot_x=0.5, pivot_y=0.5) expanded, opened = imgui.begin( "Texture of %s###%s%s" % (self.node.spec.name, id(self.node), id(self)), True, imgui.WINDOW_NO_SCROLLBAR) if not opened: self.show_texture = False if expanded: if texture is None: imgui.text("No texture associated") else: # [::-1] reverses list texture_size = texture.shape[:2][::-1] texture_aspect = texture_size[0] / texture_size[1] window_size = imgui.get_content_region_available() imgui.image(texture._handle, window_size[0], window_size[0] / texture_aspect) if imgui.is_item_hovered() and imgui.is_mouse_clicked(1): # little hack to have first context menu entry under cursor io = imgui.get_io() pos = io.mouse_pos io.mouse_pos = pos[0] - 20, pos[1] - 20 imgui.open_popup("context") io.mouse_pos = pos if imgui.begin_popup("context"): if imgui.menu_item("save")[0]: util.image.save_screenshot(texture.get()) imgui.menu_item("texture handle: %s" % texture._handle, None, False, False) imgui.menu_item("texture dtype: %s" % str(texture.dtype), None, False, False) imgui.menu_item("texture shape: %s" % str(texture.shape), None, False, False) imgui.end_popup() imgui.end()
def _show_custom_context(self): # called from ui-node to add custom entries in nodes context menu # called only when that context menu is visible has_state = len(self.spec.initial_state) != 0 has_presets = len(self.spec.presets) != 0 if has_state: imgui.separator() if imgui.button("reset state"): self.reset_state(force=True) imgui.same_line() if imgui.button("randomize state"): self.randomize_state(force=True) changed, self.allow_state_randomization = imgui.checkbox( "allow state randomization", self.allow_state_randomization) if has_presets: imgui.separator() if imgui.button("default preset"): self.reset_preset(force=True) imgui.same_line() if imgui.button("random preset"): self.randomize_preset(force=True) imgui.same_line() if imgui.button("choose preset..."): imgui.open_popup("choose_preset") if imgui.begin_popup("choose_preset"): for name, values in self.spec.presets: if imgui.button(name): self.set_preset(values) imgui.end_popup() changed, self.allow_preset_randomization = imgui.checkbox( "allow preset randomization", self.allow_preset_randomization) if imgui.button("copy current as preset"): # copy only keys that are contained in (first) preset # TODO see how this behavior works keys = None if not has_presets else list( self.spec.presets[0][1].keys()) values = OrderedDict() for port_id, value in self.values.items(): if not is_input(port_id): continue name = port_name(port_id) if keys is not None and name not in keys: continue values[name] = value.value preset = ["name", values] clipboard.copy(json.dumps(preset))
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 imgui_image_menu(path): filename = path.split("/")[-1] if filename.split(".")[-1] == "bin": imgui.text(filename) if imgui.begin_popup_context_item("Convert "+filename, 2): if imgui.button("Convert to 8x8 images"): tools.bin2png.bin2png(path,8) img_manager.reload_img(path.replace(".bin", ".png")) if imgui.button("Convert to 16x16 images"): tools.bin2png.bin2png(path, 16) img_manager.reload_img(path.replace(".bin", ".png")) if imgui.button("Convert to 32x32 images"): tools.bin2png.bin2png(path, 32) img_manager.reload_img(path.replace(".bin", ".png")) 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 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: popup context window") if imgui.begin_popup_context_window(mouse_button=0): imgui.selectable("Clear") imgui.end_popup() imgui.end() imgui.end_frame() imgui.render() self.renderer.render(imgui.get_draw_data())
def draw(self): imgui.begin("Example: simple popup") if imgui.button("select"): imgui.open_popup("select-popup") imgui.same_line() if imgui.begin_popup("select-popup"): imgui.text("Select one") imgui.separator() imgui.selectable("One") imgui.selectable("Two") imgui.selectable("Three") imgui.end_popup() imgui.end()
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: popup context view") imgui.text("Right-click to set value.") if imgui.begin_popup_context_item("Item Context Menu", mouse_button=0): imgui.selectable("Set to Zero") imgui.end_popup() imgui.end() imgui.end_frame() imgui.render() self.renderer.render(imgui.get_draw_data())
def show(self, value, read_only): # don't show it as read-only for now # as the color picker dialog might be nice for inspecting the color r, g, b, a = value.value[:] flags = imgui.COLOR_EDIT_NO_INPUTS | imgui.COLOR_EDIT_NO_LABEL | imgui.COLOR_EDIT_ALPHA_PREVIEW if imgui.color_button("color %s" % id(self), r, g, b, a, flags, 50, 50): imgui.open_popup("picker %s" % id(self)) if imgui.begin_popup("picker %s" % id(self)): changed, color = imgui.color_picker4( "color", r, g, b, a, imgui.COLOR_EDIT_ALPHA_PREVIEW) if changed: if not read_only: # careful here! update it safely (with numpy-assignment) # but also set it properly so it is regarded as changed v = value.value v[:] = color value.value = v imgui.end_popup()
def main(): renderer = NXRenderer() # My stuff MudData = { 'Player_text': '', 'Player_text_changed': False, 'Player_text_changed1': False, 'World_text': 'Please Enter the server info like this: serverhost.port', 'World_text_changed': False, 'server_host': '', 'server_port': 0, 'Entered_server_data': False, 'Clear_Player_data': False, 'Shift_enabled': False } keyboardInner = Keyboard2(MudData) TelnetSetup = TelnetBackend(MudData) # End Of my stuff 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) MudClientWindow(MudData) GuiProcess(MudData, TelnetSetup) if imgui.begin_popup("select-popup"): keyboardInner.create_frames_and_buttons() imgui.end_popup() imgui.end() imgui.render() renderer.render() PostGuiStuff(MudData) renderer.shutdown()
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_log_detail_info_panel(self, idx, log): if idx != self.detail_idx: return popup_id = "detail_log_%s" % self.detail_idx win_size = imgui.get_window_size() item_size = (win_size.x * 0.94, win_size.y * 0.5) imgui.set_next_window_size(item_size[0], item_size[1]) imgui.set_next_window_position((win_size.x - item_size[0]) * 0.5, (win_size.y - item_size[1]) * 0.5) if imgui.begin_popup(popup_id): msg = log.detail_info utils.get_win_size() btn_height = 22 padding = imgui.get_style().window_padding area_size = (item_size[0] * 0.98, item_size[1] * 0.94 - btn_height - padding.y * 0.6) imgui.input_text_multiline("##hidden", msg, len(msg) + 1, area_size[0], area_size[1], imgui.INPUT_TEXT_READ_ONLY) if imgui.button("复制", area_size[0], btn_height): print("复制") imgui.end_popup()
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_plugins_ui(window): "Draw UI windows for all plugins active for the current drawing." if not window.drawing: return drawing = window.drawing deactivated = set() for name, args in window.drawing.active_plugins.items(): plugin, sig = window.plugins[name] _, opened = imgui.begin(f"{ name } ##{ drawing.path or drawing.uuid }", True) if not opened: deactivated.add(name) imgui.columns(2) for param_name, param_sig in islice(sig.items(), 4, None): if param_sig.annotation == inspect._empty: continue imgui.text(param_name) imgui.next_column() default_value = args.get(param_name) if default_value is not None: value = default_value else: value = param_sig.default label = f"##{param_name}_val" if param_sig.annotation == int: changed, args[param_name] = imgui.drag_int(label, value) elif param_sig.annotation == float: changed, args[param_name] = imgui.drag_float(label, value) elif param_sig.annotation == str: changed, args[param_name] = imgui.input_text(label, value, 20) elif param_sig.annotation == bool: changed, args[param_name] = imgui.checkbox(label, value) imgui.next_column() imgui.columns(1) texture_and_size = getattr(plugin, "texture", None) if texture_and_size: texture, size = texture_and_size w, h = size ww, wh = imgui.get_window_size() scale = max(1, (ww - 10) // w) imgui.image(texture.name, w * scale, h * scale, border_color=(1, 1, 1, 1)) if hasattr(plugin, "ui"): result = plugin.ui(oldpaint, imgui, window.drawing, window.brush, **args) if result: args.update(result) last_run = getattr(plugin, "last_run", 0) period = getattr(plugin, "period", None) t = time() # TODO I've seen more readable if-statements in my days... if callable(plugin) and ((period and t > last_run + period) or (not period and imgui.button("Execute"))): plugin.last_run = t try: result = plugin(oldpaint, imgui, window.drawing, window.brush, **args) if result: args.update(result) except Exception: # We don't want crappy plugins to ruin everything # Still probably probably possible to crash opengl though... logger.error(f"Plugin {name}: {format_exc()}") imgui.button("Help") if imgui.begin_popup_context_item("Help", mouse_button=0): if plugin.__doc__: imgui.text(inspect.cleandoc(plugin.__doc__)) else: imgui.text("No documentation available.") imgui.end_popup() imgui.end() for name in deactivated: window.drawing.active_plugins.pop(name, None)
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 main(): window, gl_context = impl_pysdl2_init() renderer = SDL2Renderer(window) # My stuff MudData = { 'Player_text': '', 'Player_text_changed': False, 'Player_text_changed1': False, 'World_text': 'Please Enter the server info like this: serverhost.port', 'World_text_changed': False, 'server_host': '', 'server_port': 0, 'Entered_server_data': False, 'Clear_Player_data': False, 'Shift_enabled': False } keyboardInner = Keyboard2(MudData) TelnetSetup = TelnetBackend(MudData) # End Of my stuff running = True event = SDL_Event() while running: while SDL_PollEvent(ctypes.byref(event)) != 0: if event.type == SDL_QUIT: running = False break renderer.process_event(event) renderer.process_inputs() imgui.new_frame() if imgui.begin_main_menu_bar(): if imgui.begin_menu("File", True): clicked_quit, selected_quit = imgui.menu_item( "Quit", 'Cmd+Q', False, True ) if clicked_quit: exit(1) imgui.end_menu() imgui.end_main_menu_bar() # imgui.show_test_window() imgui.begin("Mudlet Window") MudClientWindow(MudData) GuiProcess(MudData, TelnetSetup) if imgui.begin_popup("select-popup"): keyboardInner.create_frames_and_buttons() imgui.end_popup() imgui.end() gl.glClearColor(1., 1., 1., 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() SDL_GL_SwapWindow(window) PostGuiStuff(MudData) renderer.shutdown() SDL_GL_DeleteContext(gl_context) SDL_DestroyWindow(window) SDL_Quit()