def main(): window = impl_glfw_init() impl = GlfwRenderer(window) font_scaling_factor = fb_to_window_factor(window) io = impl.io # clear font atlas to avoid downscaled default font # on highdensity screens. First font added to font # atlas will become default font. io.fonts.clear() # set global font scaling io.font_global_scale = 1. / font_scaling_factor # dictionary of font objects from our font directory fonts = { os.path.split(font_path)[-1]: io.fonts.add_font_from_file_ttf( font_path, FONT_SIZE_IN_PIXELS * font_scaling_factor, io.fonts.get_glyph_ranges_latin()) for font_path in FONTS_DIR } secondary_window_main_font = random.choice(list(fonts.values())) impl.refresh_font_texture() while not glfw.window_should_close(window): glfw.poll_events() impl.process_inputs() imgui.new_frame() imgui.begin("Window with multiple custom fonts", True) imgui.text("This example showcases font usage on text() widget") for font_name, font in fonts.items(): imgui.separator() imgui.text("Font:{}".format(font_name)) with imgui.font(font): imgui.text("This text uses '{}' font.".format(font_name)) imgui.end() with imgui.font(secondary_window_main_font): imgui.begin("Window one main custom font", True) imgui.text("This window uses same custom font for all widgets") 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()
def draw(self): imgui.begin("Font") imgui.text("Text displayed using default font") with imgui.font(self.new_font): imgui.text("Text displayed using custom font") imgui.end()
def draw(self): if self.GUI_STATE: with imgui.font(self.new_font): imgui.begin("Test") imgui.set_scroll_here() self.vanilla_view_props() self.kernel_props() self.light_props() imgui.end()
def ProgramInfoPopup(): with imgui.font(largefont): imgui.text("軟體資訊") imgui.separator() imgui.bullet_text("版本: 0.1 alpha") imgui.bullet_text("開發: PUF STUDIO") imgui.bullet_text("Email: [email protected]") imgui.bullet_text("Git Repo: https://github.com/even311379/PdfParserGUI")
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 ParserStaticsWidget(): imgui.push_text_wrap_position(600) if os.path.isfile('ParseResult.log'): with imgui.font(largefont): imgui.text("結果") with open('ParseResult.log', 'r') as f: imgui.text(f.read()) imgui.separator() imgui.text("Run a hierarchical clustering to check how many potential groups?") if imgui.button("RUN"): subprocess.run(["python","Subprocesses/CheckGroup.py"]) else: imgui.text("尚未解析推甄資料中的成績單內容")
def draw(self): imgui.new_frame() imgui.begin("Font") imgui.text("Text displayed using default font") with imgui.font(self.new_font): imgui.text("Text displayed using custom font") imgui.end() imgui.end_frame() imgui.render() self.renderer.render(imgui.get_draw_data())
def FileWindow(): ''' string wdir, path to project folder ''' global WDIR global LoadedFile global InstIndex global PersonIndex global ReloadPDF if not WDIR: imgui.dummy(50, 0) imgui.same_line() if imgui.button("選擇推甄資料目錄"): WDIR = TkFileDialog() else: imgui.text("現行推甄資料目錄:") imgui.push_text_wrap_position(150) imgui.text(WDIR) imgui.dummy(80,0) imgui.same_line() if imgui.button("變更"): WDIR = TkFileDialog() imgui.separator() if GF.CheckWDIR(WDIR): imgui.text('目前系所:') IList = os.listdir(WDIR) _, InstIndex = imgui.combo("", InstIndex, IList) imgui.text('學生編號:') PersonList = os.listdir(WDIR+'/'+IList[InstIndex]) _, PersonIndex = imgui.listbox("", PersonIndex, PersonList, 15) imgui.text(f"目前檔案: {PersonList[PersonIndex]}") if imgui.button("查看檔案"): os.startfile(f'{WDIR}/{IList[InstIndex]}/{PersonList[PersonIndex]}/{PersonList[PersonIndex]}.pdf') else: with imgui.font(largefont): imgui.text('目錄錯誤,請重選!')
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 use_font(self, tag=None): '进行imgui字体的临时引用,用于with语法' if tag is None: tag = self.font_tag_zh return imgui.font(self.fonts[tag])
def ParsePdfWidget(): ''' Use subprocess.Popen to run another script in background ''' global WDIR global ODIR global N_Group global AllFileStatus with imgui.font(largefont): imgui.text("Step 1: 設定工作目錄") imgui.bullet_text("設定好推甄資料的目錄。") if WDIR: imgui.separator() with imgui.font(largefont): imgui.text("Step 2: 檢查各別檔案") imgui.push_text_wrap_position(450) imgui.bullet_text("檔案命名有些錯誤,需要額外調整,如: 10054818.pdf 變為10054818_1.pdf") imgui.dummy(50, 0) imgui.same_line() if imgui.button("檢查檔案"): AllFileStatus = GF.CheckAllFiles(WDIR) imgui.push_text_wrap_position(450) imgui.text(AllFileStatus) imgui.separator() with imgui.font(largefont): imgui.text("Step 3: 執行程式-解析成績單內容") imgui.dummy(50, 0) imgui.same_line() if imgui.button("設定輸出目錄"): ODIR = TkFileDialog() if ODIR != "": imgui.text("輸出目錄位置:") imgui.push_text_wrap_position(250) imgui.text(ODIR) imgui.dummy(50, 0) imgui.same_line() if imgui.button("開始解析"): if WDIR == "": imgui.text("請設定檔案目錄") else: subprocess.run(["python","Subprocesses/ParseScoreSheet.py", WDIR, ODIR]) imgui.separator() if os.path.isfile('ManualFiles.log'): with imgui.font(largefont): imgui.text("Step 4: 執行程式-手動檔案分類") imgui.push_item_width(150) changed, N_Group = imgui.slider_int("幾群?", N_Group, min_value = 2, max_value = 20) imgui.text(f"分成{N_Group}群") if imgui.button("開始分群"): subprocess.run(["python","Subprocesses/GroupPdf.py", ODIR, str(N_Group)]) imgui.separator() if os.path.isdir(ODIR+"/Manual"): with imgui.font(largefont): imgui.text("Step 5: 手動處理") imgui.push_text_wrap_position(250) imgui.text(""" 恭喜~~~ 只剩下一咪咪手動的作業就能完工了!! 祝你有美好的一天!! 你現在可以關閉這個程式。 """)