class Application(object): def __init__(self): pass def loadConf(self): pass def init(self): pygame.init() size = 800, 600 pygame.display.set_mode( size, pygame.DOUBLEBUF | pygame.OPENGL | pygame.RESIZABLE) imgui.create_context() self.impl = PygameRenderer() self.io = imgui.get_io() self.io.display_size = size def run(self): while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() self.impl.process_event(event) imgui.new_frame() # render game elements # render gui gl.glClearColor(1, 1, 1, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() self.impl.render(imgui.get_draw_data()) pygame.display.flip()
def main(): pygame.init() size = 800, 600 pygame.display.set_mode( size, pygame.DOUBLEBUF | pygame.OPENGL | pygame.RESIZABLE) imgui.create_context() impl = PygameRenderer() io = imgui.get_io() io.display_size = size while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() impl.process_event(event) imgui.new_frame() gl.glClearColor(1, 1, 1, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() impl.render(imgui.get_draw_data()) pygame.display.flip()
def main(): pygame.init() size = 1280, 960 pygame.display.set_mode( size, pygame.DOUBLEBUF | pygame.OPENGL | pygame.RESIZABLE) #imgui.create_context() imgui.create_context() impl = PygameRenderer() io = imgui.get_io() io.display_size = size while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() impl.process_event(event) interface() # 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() impl.render(imgui.get_draw_data()) pygame.display.flip()
def main(): pygame.init() size = 800, 600 pygame.display.set_mode(size, pygame.DOUBLEBUF | pygame.OPENGL | pygame.RESIZABLE) imgui.create_context() impl = PygameRenderer() io = imgui.get_io() io.display_size = size while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() impl.process_event(event) 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("Custom window", True) imgui.text("Bar") #imgui.same_line() imgui.text_colored("Eggs", 0.2, 1., 0.) #imgui.same_line() imgui.bullet_text("bullet_text") # 不换行 #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() impl.render(imgui.get_draw_data()) pygame.display.flip()
def main(): pygame.init() size = 800, 600 pygame.display.set_mode(size, pygame.DOUBLEBUF | pygame.OPENGL | pygame.RESIZABLE) imgui.create_context() impl = PygameRenderer() io = imgui.get_io() io.display_size = size while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() impl.process_event(event) imgui.new_frame() if imgui.begin_main_menu_bar(): if imgui.begin_menu("File", True): clicked_quit, selected_quit = imgui.menu_item("Quit", 'Alt+F4', False, True) clicked_save, selected_save = imgui.menu_item("Save", "", False, True) if clicked_save: print("Saved...") if clicked_quit: exit(1) imgui.end_menu() imgui.end_main_menu_bar() gl.glClearColor(1, 1, 1, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() impl.render(imgui.get_draw_data()) pygame.display.flip()
if entered: try: output = eval(command) if output is not None: console_text += "\n" + str(output) except BaseException as error: try: exec(command) except BaseException as error2: console_text += "\nError while attempting to evaluate expression: %s\nError while attempting to execute input as code: %s" % ( error, error2) command = "" imgui.end() gl.glClearColor(0.5, 0.5, 0.5, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() impl.render(imgui.get_draw_data()) pygame.display.flip() # TODO: Test remote motor connectivity support # TODO: Finish implementing servos (gui support and remote control) # TODO: Add adafruit motor library support on the Pi version # TODO: Add default constants for some *very* commonly set values (irrespective of config files, would need actual examples of this to implement properly) # TODO: Finish implementing all ROV Controllers into the gui # TODO: Somehow change stuff so that .apply isn't an assumed functional property of all controllers # TODO: Rewrite controller manager handling code so that they're handled like managers and not special controllers
def main(): pygame.init() display = (1000, 700) screen = pygame.display.set_mode(display, DOUBLEBUF | OPENGLBLIT) imgui.create_context() impl = PygameRenderer() io = imgui.get_io() io.display_size = display pygame.display.set_caption('solar panels') gluPerspective(45, (display[0] / display[1]), 0.1, 50.0) glTranslatef(0, 0, -10) glRotatef(25, 2, 1, 0) # Coordinates x = 0 y = 0 z = 0 a = 0 # Keystates KLEFT = False KRIGHT = False KUP = False KDOWN = False KJ = False KL = False KA = False KD = False KW = False KS = False KI = False KK = False KG = False KH = False b = 0 d = 0 c = 1 while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() # KEYEVENT KEYDOWN HANDLING if event.type == pygame.KEYDOWN: # TRANSLATE if event.key == pygame.K_LEFT: KLEFT = True if event.key == pygame.K_RIGHT: KRIGHT = True if event.key == pygame.K_UP: KUP = True if event.key == pygame.K_DOWN: KDOWN = True if event.key == pygame.K_j: KJ = True if event.key == pygame.K_l: KL = True # ROTATE if event.key == pygame.K_a: KA = True if event.key == pygame.K_d: KD = True if event.key == pygame.K_w: KW = True if event.key == pygame.K_s: KS = True if event.key == pygame.K_i: KI = True if event.key == pygame.K_k: KK = True # Arm Control # Optional key usage to move arm model if event.key == pygame.K_g: KG = True if event.key == pygame.K_h: KH = True # KEYEVENT KEYUP HANDLING if event.type == pygame.KEYUP: # TRANSLATE if event.key == pygame.K_LEFT: KLEFT = False if event.key == pygame.K_RIGHT: KRIGHT = False if event.key == pygame.K_UP: KUP = False if event.key == pygame.K_DOWN: KDOWN = False if event.key == pygame.K_j: KJ = False if event.key == pygame.K_l: KL = False # ROTATE if event.key == pygame.K_a: KA = False if event.key == pygame.K_d: KD = False if event.key == pygame.K_w: KW = False if event.key == pygame.K_s: KS = False if event.key == pygame.K_i: KI = False if event.key == pygame.K_k: KK = False # Arm Angle # Optional key usage to move arm model if event.key == pygame.K_g: KG = False if event.key == pygame.K_h: KH = False # KEY PRESS ACTIONS # TRANSLATE if KH == True: glTranslatef(0, -1, 0) y += 1 if KG == True: glTranslatef(0, 1, 0) y -= 1 if KJ == True: glTranslatef(0, 0, -1) z += 1 if KL == True: glTranslatef(0, 0, 1) z -= 1 # ROTATE if KI == True: glRotate(5, 0, 1, 0) if KK == True: glRotate(5, 0, 0, 1) # Arm Angle # Optional key usage to move arm model if KRIGHT == True: a += 1 if KLEFT == True: a -= 1 if KUP == True: b += 1 if KDOWN == True: b -= 1 if KA == True: c += 1 if KD == True: c -= 1 if KW == True: d += 1 if KS == True: d -= 1 impl.process_event(event) imgui.new_frame() imgui.begin("Controle du Mirroir", True) imgui.text("Les Angles") c = imgui.slider_int("Axe des x", c, -180., 180.)[1] a = imgui.slider_int("Axe des y", a, -180., 180.)[1] changed, c = imgui.input_int('Type coefficient:', c) imgui.text('The Va;ue you entered is: %f' % c) visible = True expanded, visible = imgui.collapsing_header("Expand me!", visible) if expanded: imgui.text("Now you see me qnd perhaps you don't !") imgui.show_style_editor() imgui.end() imgui.render() gl.glClearColor(1, 1, 1, 1) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) impl.render(imgui.get_draw_data()) glPushMatrix() house() glPopMatrix() glPushMatrix() house() Mirroir(c, a) glPopMatrix() glPushMatrix() mirroir2(c, a) glRotate(180, 0, 1, 0) glPopMatrix() glPushMatrix() support(c, a) glPopMatrix() support2() pygame.display.flip()
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
class RapidApp: clock: pygame.time.Clock refresh_rate_hz: int window_size: tuple window_flags: int impl: PygameRenderer io: imgui.core._IO context: imgui.core._ImGuiContext context: imgui.core.GuiStyle def __init__(self, p_refresh_rate_hz=60, p_size=(800, 600)): self.refresh_rate_hz = p_refresh_rate_hz self.window_size = p_size self.window_flags = pygame.DOUBLEBUF | pygame.OPENGL | pygame.RESIZABLE self.quit_on_close = True self.use_base_window = True self.use_menu_bar = True self.use_gl_clear = True self.use_style_file = False self.show_style_window = False self.show_demo_window = False self.base_window_flags = imgui.core.WINDOW_MENU_BAR self.base_window_flags += imgui.core.WINDOW_NO_MOVE self.base_window_flags += imgui.core.WINDOW_NO_RESIZE self.base_window_flags += imgui.core.WINDOW_NO_COLLAPSE self.base_window_flags += imgui.core.WINDOW_NO_BRING_TO_FRONT_ON_FOCUS self.base_window_flags += imgui.core.WINDOW_NO_FOCUS_ON_APPEARING self.base_window_flags += imgui.core.WINDOW_NO_TITLE_BAR self.clock = None self.context = None self.impl = None self.io = None self.style = None self.running = False self.on_init() def on_init(self): pass def start(self): if not pygame.get_init(): pygame.init() pygame.display.set_caption("RapidApp Window") pygame.display.set_mode(self.window_size, self.window_flags) gl.glClearColor(1, 1, 1, 1) self.context = imgui.create_context() self.impl = PygameRenderer() self.io = imgui.get_io() self.io.display_size = self.window_size self.style = imgui.get_style() self.style.window_rounding = 0 self.on_window_created() if self.use_style_file: load_style_json_file() self.clock = pygame.time.Clock() self.main_loop() def on_window_created(self): pass def main_loop(self): self.running = True while self.running: # Event Handling: for event in pygame.event.get(): if event.type == pygame.QUIT and self.quit_on_close: self.running = False self.impl.process_event(event) self.handle_event(event) # Drawing: imgui.new_frame() self.update() self.render() pygame.display.flip() self.clock.tick(self.refresh_rate_hz) if self.use_style_file: save_style_json_file() self.end() def handle_event(self, event: pygame.event.Event): pass 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): pass def draw_base_window(self): pass def draw_windows(self): pass def render(self): # gl.glClearColor(1, 1, 1, 1) if self.use_gl_clear: gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() self.impl.render(imgui.get_draw_data()) def end(self): pass
def run( gui_loop_function, params=Params(), on_init = None, on_exit = None): if params.windowed_full_screen: os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % ( params.windowed_full_screen_x_margin / 2, params.window_title_height) imgui.create_context() pygame.init() pygame.display.set_caption(params.win_title) win_size = params.win_size if params.windowed_full_screen: info = pygame.display.Info() screen_size = (info.current_w - params.windowed_full_screen_x_margin, info.current_h) win_size = (screen_size[0], screen_size[1] - params.window_title_height - params.windows_taskbar_height) pygame.display.set_mode(win_size, pygame.DOUBLEBUF | pygame.OPENGL | pygame.RESIZABLE) imgui_ext._load_fonts() io = imgui.get_io() io.display_size = win_size pygame_renderer = PygameRenderer() # if on_exit: # pygame.register_quit(on_exit) if on_init: on_init() while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: if on_exit: on_exit() try: sys.exit() except SystemExit as e: time.sleep(0.5) # sys.exit() # sys.terminate() os._exit(1) pygame_renderer.process_event(event) imgui.new_frame() if params.provide_default_window: imgui.set_next_window_position(0, 0) imgui.set_next_window_size(win_size[0], win_size[1]) imgui.begin("Default window") gui_loop_function() if params.provide_default_window: imgui.end() ImGuiImageLister._heartbeat() # note: cannot use screen.fill((1, 1, 1)) because pygame's screen # does not support fill() on OpenGL surfaces gl.glClearColor(1, 1, 1, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() pygame_renderer.render(imgui.get_draw_data()) pygame.display.flip() imgui_cv._clear_all_cv_textures() imgui_ext.__clear_all_unique_labels()