def open_window(self): if not self._window: self.input = {'button':None, 'mouse':(0,0)} # get glfw started if self.run_independently: glfwInit() window = glfwGetCurrentContext() self._window = glfwCreateWindow(self.window_size[0], self.window_size[1], self.name, None, window) glfwMakeContextCurrent(self._window) if not self._window: exit() glfwSetWindowPos(self._window,0,0) # Register callbacks window glfwSetFramebufferSizeCallback(self._window,self.on_resize) glfwSetWindowIconifyCallback(self._window,self.on_iconify) glfwSetKeyCallback(self._window,self.on_key) glfwSetCharCallback(self._window,self.on_char) glfwSetMouseButtonCallback(self._window,self.on_button) glfwSetCursorPosCallback(self._window,self.on_pos) glfwSetScrollCallback(self._window,self.on_scroll) # get glfw started if self.run_independently: init() self.basic_gl_setup() self.glfont = fs.Context() self.glfont.add_font('opensans',get_opensans_font_path()) self.glfont.set_size(22) self.glfont.set_color_float((0.2,0.5,0.9,1.0)) self.on_resize(self._window,*glfwGetFramebufferSize(self._window)) glfwMakeContextCurrent(window)
def open_window(self): if not self._window: self.input = {'down':False, 'mouse':(0,0)} self.trackball = Trackball() # get glfw started glfwInit() self._window = glfwCreateWindow(width, height, self.name, None, None) glfwMakeContextCurrent(self._window) if not self._window: exit() glfwSetWindowPos(self._window,2000,0) # Register callbacks window glfwSetFramebufferSizeCallback(self._window,self.on_resize) glfwSetWindowIconifyCallback(self._window,self.on_iconify) glfwSetKeyCallback(self._window,self.on_key) glfwSetCharCallback(self._window,self.on_char) glfwSetMouseButtonCallback(self._window,self.on_button) glfwSetCursorPosCallback(self._window,self.on_pos) glfwSetScrollCallback(self._window,self.on_scroll) glfwSetWindowCloseCallback(self._window,self.on_close) init() glutInit() self.basic_gl_setup() self.gui = ui.UI() self.on_resize(self._window,*glfwGetFramebufferSize(self._window))
def open_window(self): if not self.window: self.input = {"button": None, "mouse": (0, 0)} # get glfw started if self.run_independently: glfw.init() glfw.window_hint(glfw.SCALE_TO_MONITOR, glfw.TRUE) self.window = glfw.create_window(self.window_size[0], self.window_size[1], self.name, None, None) else: self.window = glfw.create_window( self.window_size[0], self.window_size[1], self.name, None, glfw.get_current_context(), ) self.other_window = glfw.get_current_context() glfw.make_context_current(self.window) glfw.swap_interval(0) glfw.set_window_pos(self.window, window_position_default[0], window_position_default[1]) # Register callbacks window glfw.set_framebuffer_size_callback(self.window, self.on_resize) glfw.set_window_iconify_callback(self.window, self.on_iconify) glfw.set_key_callback(self.window, self.on_window_key) glfw.set_char_callback(self.window, self.on_window_char) glfw.set_mouse_button_callback(self.window, self.on_window_mouse_button) glfw.set_cursor_pos_callback(self.window, self.on_pos) glfw.set_scroll_callback(self.window, self.on_scroll) # get glfw started if self.run_independently: glutils.init() self.basic_gl_setup() self.sphere = glutils.Sphere(20) self.glfont = fs.Context() self.glfont.add_font("opensans", get_opensans_font_path()) self.glfont.set_size(18) self.glfont.set_color_float((0.2, 0.5, 0.9, 1.0)) self.on_resize(self.window, *glfw.get_framebuffer_size(self.window)) glfw.make_context_current(self.other_window)
def open_window(self): if not self.window: self.input = {"button": None, "mouse": (0, 0)} # get glfw started if self.run_independently: glfwInit() glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE) self.window = glfwCreateWindow(self.window_size[0], self.window_size[1], self.name, None) else: self.window = glfwCreateWindow( self.window_size[0], self.window_size[1], self.name, None, share=glfwGetCurrentContext(), ) self.other_window = glfwGetCurrentContext() glfwMakeContextCurrent(self.window) glfwSwapInterval(0) glfwSetWindowPos(self.window, window_position_default[0], window_position_default[1]) # Register callbacks window glfwSetFramebufferSizeCallback(self.window, self.on_resize) glfwSetWindowIconifyCallback(self.window, self.on_iconify) glfwSetKeyCallback(self.window, self.on_window_key) glfwSetCharCallback(self.window, self.on_window_char) glfwSetMouseButtonCallback(self.window, self.on_window_mouse_button) glfwSetCursorPosCallback(self.window, self.on_pos) glfwSetScrollCallback(self.window, self.on_scroll) # get glfw started if self.run_independently: glutils.init() self.basic_gl_setup() self.sphere = glutils.Sphere(20) self.glfont = fs.Context() self.glfont.add_font("opensans", get_opensans_font_path()) self.glfont.set_size(18) self.glfont.set_color_float((0.2, 0.5, 0.9, 1.0)) self.on_resize(self.window, *glfwGetFramebufferSize(self.window)) glfwMakeContextCurrent(self.other_window)
def open_window(self): if not self.window: self.input = {"button": None, "mouse": (0, 0)} # get glfw started if self.run_independently: glfwInit() self.window = glfwCreateWindow( self.window_size[0], self.window_size[1], self.name, None ) else: self.window = glfwCreateWindow( self.window_size[0], self.window_size[1], self.name, None, share=glfwGetCurrentContext(), ) self.other_window = glfwGetCurrentContext() glfwMakeContextCurrent(self.window) glfwSwapInterval(0) glfwSetWindowPos( self.window, window_position_default[0], window_position_default[1] ) # Register callbacks window glfwSetFramebufferSizeCallback(self.window, self.on_resize) glfwSetWindowIconifyCallback(self.window, self.on_iconify) glfwSetKeyCallback(self.window, self.on_window_key) glfwSetCharCallback(self.window, self.on_window_char) glfwSetMouseButtonCallback(self.window, self.on_window_mouse_button) glfwSetCursorPosCallback(self.window, self.on_pos) glfwSetScrollCallback(self.window, self.on_scroll) # get glfw started if self.run_independently: glutils.init() self.basic_gl_setup() self.sphere = glutils.Sphere(20) self.glfont = fs.Context() self.glfont.add_font("opensans", get_opensans_font_path()) self.glfont.set_size(18) self.glfont.set_color_float((0.2, 0.5, 0.9, 1.0)) self.on_resize(self.window, *glfwGetFramebufferSize(self.window)) glfwMakeContextCurrent(self.other_window)
def demo(): global quit quit = False # Callback functions def on_resize(window,w, h): h = max(h,1) w = max(w,1) hdpi_factor = glfwGetFramebufferSize(window)[0]/glfwGetWindowSize(window)[0] w,h = w*hdpi_factor,h*hdpi_factor gui.update_window(w,h) active_window = glfwGetCurrentContext() glfwMakeContextCurrent(active_window) # norm_size = normalize((w,h),glfwGetWindowSize(window)) # fb_size = denormalize(norm_size,glfwGetFramebufferSize(window)) adjust_gl_view(w,h,window) glfwMakeContextCurrent(active_window) def on_iconify(window,iconfied): pass def on_key(window, key, scancode, action, mods): gui.update_key(key,scancode,action,mods) if action == GLFW_PRESS: if key == GLFW_KEY_ESCAPE: on_close(window) if mods == GLFW_MOD_SUPER: if key == 67: # copy value to system clipboard # ideally copy what is in our text input area test_val = "copied text input" glfwSetClipboardString(window,test_val) print("set clipboard to: %s" %(test_val)) if key == 86: # copy from system clipboard clipboard = glfwGetClipboardString(window) print("pasting from clipboard: %s" %(clipboard)) def on_char(window,char): gui.update_char(char) def on_button(window,button, action, mods): gui.update_button(button,action,mods) # pos = normalize(pos,glfwGetWindowSize(window)) # pos = denormalize(pos,(frame.img.shape[1],frame.img.shape[0]) ) # Position in img pixels def on_pos(window,x, y): hdpi_factor = float(glfwGetFramebufferSize(window)[0]/glfwGetWindowSize(window)[0]) x,y = x*hdpi_factor,y*hdpi_factor gui.update_mouse(x,y) def on_scroll(window,x,y): gui.update_scroll(x,y) def on_close(window): global quit quit = True logger.info('Process closing from window') # get glfw started glfwInit() window = glfwCreateWindow(width, height, "pyglui demo", None, None) if not window: exit() glfwSetWindowPos(window,0,0) # Register callbacks for the window glfwSetWindowSizeCallback(window,on_resize) glfwSetWindowCloseCallback(window,on_close) glfwSetWindowIconifyCallback(window,on_iconify) glfwSetKeyCallback(window,on_key) glfwSetCharCallback(window,on_char) glfwSetMouseButtonCallback(window,on_button) glfwSetCursorPosCallback(window,on_pos) glfwSetScrollCallback(window,on_scroll) # test out new paste function glfwMakeContextCurrent(window) init() basic_gl_setup() print(glGetString(GL_VERSION)) class Temp(object): """Temp class to make objects""" def __init__(self): pass foo = Temp() foo.bar = 34 foo.sel = 'mi' foo.selection = ['€','mi', u"re"] foo.mytext = "some text" foo.T = True foo.L = False def set_text_val(val): foo.mytext = val # print 'setting to :',val def pr(): print("pyglui version: %s" %(ui.__version__)) gui = ui.UI() gui.scale = 1.0 thumbbar = ui.Scrolling_Menu("ThumbBar",pos=(-80,0),size=(0,0),header_pos='hidden') menubar = ui.Scrolling_Menu("MenueBar",pos=(-500,0),size=(-90,0),header_pos='left') gui.append(menubar) gui.append(thumbbar) T = ui.Growing_Menu("T menu",header_pos='headline') menubar.append(T) L = ui.Growing_Menu("L menu",header_pos='headline') menubar.append(L) M = ui.Growing_Menu("M menu",header_pos='headline') menubar.append(M) def toggle_menu(collapsed, menu): menubar.collapsed = collapsed for m in menubar.elements: m.collapsed = True menu.collapsed = collapsed thumbbar.append(ui.Thumb('collapsed',T,label='T',on_val=False, off_val=True,setter=lambda x:toggle_menu(x,T))) thumbbar.append(ui.Thumb('collapsed',L,label='L',on_val=False, off_val=True,setter=lambda x:toggle_menu(x,L))) thumbbar.append(ui.Thumb('collapsed',M,label='M',on_val=False, off_val=True,setter=lambda x:toggle_menu(x,M))) # thumbbar.elements[-1].order = -10.0 print('order'+str(thumbbar.elements[-1].order)) T.append(ui.Button("T test",pr)) T.append(ui.Info_Text("T best finerfpiwnesdco'n wfo;ineqrfo;inwefo'qefr voijeqfr'p9qefrp'i 'iqefr'ijqfr eqrfiqerfn'ioer")) L.append(ui.Button("L test",pr)) L.append(ui.Button("L best",pr)) M.append(ui.Button("M test",pr)) M.append(ui.Button("M best",pr)) MM = ui.Growing_Menu("MM menu",pos=(0,0),size=(0,400)) M.append(MM) for x in range(20): MM.append(ui.Button("M test%s"%x,pr)) M.append(ui.Button("M best",pr)) M.append(ui.Button("M best",pr)) M.append(ui.Button("M best",pr)) M.append(ui.Button("M best",pr)) M.append(ui.Button("M best",pr)) M.append(ui.Button("M best",pr)) M.append(ui.Button("M best",pr)) # label = 'Ï' # label = 'R' # gui.append( import os import psutil pid = os.getpid() ps = psutil.Process(pid) ts = time.time() from pyglui import graph print(graph.__version__) cpu_g = graph.Line_Graph() cpu_g.pos = (50,100) cpu_g.update_fn = ps.cpu_percent cpu_g.update_rate = 5 cpu_g.label = 'CPU %0.1f' fps_g = graph.Line_Graph() fps_g.pos = (50,100) fps_g.update_rate = 5 fps_g.label = "%0.0f FPS" fps_g.color[:] = .1,.1,.8,.9 on_resize(window,*glfwGetWindowSize(window)) while not quit: gui.update() # print(T.collapsed,L.collapsed,M.collapsed) # T.collapsed = True # glfwMakeContextCurrent(window) glfwSwapBuffers(window) glfwPollEvents() # adjust_gl_view(1280,720,window) glClearColor(.3,.4,.1,1) glClear(GL_COLOR_BUFFER_BIT) gui.terminate() glfwTerminate() logger.debug("Process done")
def demo(): global quit quit = False # Callback functions def on_resize(window, w, h): h = max(h, 1) w = max(w, 1) hdpi_factor = (glfw.get_framebuffer_size(window)[0] / glfw.get_window_size(window)[0]) w, h = w * hdpi_factor, h * hdpi_factor gui.update_window(w, h) active_window = glfw.get_current_context() glfw.make_context_current(active_window) # norm_size = normalize((w,h),glfw.get_window_size(window)) # fb_size = denormalize(norm_size,glfw.get_framebuffer_size(window)) adjust_gl_view(w, h, window) glfw.make_context_current(active_window) def on_iconify(window, iconfied): pass def on_key(window, key, scancode, action, mods): gui.update_key(key, scancode, action, mods) if action == glfw.PRESS: if key == glfw.KEY_ESCAPE: on_close(window) if mods == glfw.MOD_SUPER: if key == 67: # copy value to system clipboard # ideally copy what is in our text input area test_val = "copied text input" glfw.set_clipboard_string(window, test_val) print("set clipboard to: %s" % (test_val)) if key == 86: # copy from system clipboard clipboard = glfw.get_clipboard_string(window) print("pasting from clipboard: %s" % (clipboard)) def on_char(window, char): gui.update_char(char) def on_button(window, button, action, mods): gui.update_button(button, action, mods) # pos = normalize(pos,glfw.get_window_size(window)) # pos = denormalize(pos,(frame.img.shape[1],frame.img.shape[0]) ) # Position in img pixels def on_pos(window, x, y): hdpi_factor = float( glfw.get_framebuffer_size(window)[0] / glfw.get_window_size(window)[0]) x, y = x * hdpi_factor, y * hdpi_factor gui.update_mouse(x, y) def on_scroll(window, x, y): gui.update_scroll(x, y) def on_close(window): global quit quit = True logger.info("Process closing from window") # get glfw started glfw.init() window = glfw.create_window(width, height, "pyglui demo", None, None) if not window: exit() glfw.set_window_pos(window, 0, 0) # Register callbacks for the window glfw.set_window_size_callback(window, on_resize) glfw.set_window_close_callback(window, on_close) glfw.set_window_iconify_callback(window, on_iconify) glfw.set_key_callback(window, on_key) glfw.set_char_callback(window, on_char) glfw.set_mouse_button_callback(window, on_button) glfw.set_cursor_pos_callback(window, on_pos) glfw.set_scroll_callback(window, on_scroll) # test out new paste function glfw.make_context_current(window) init() basic_gl_setup() print(glGetString(GL_VERSION)) class Temp(object): """Temp class to make objects""" def __init__(self): pass foo = Temp() foo.bar = 34 foo.sel = "mi" foo.selection = ["€", "mi", u"re"] foo.mytext = "some text" foo.T = True foo.L = False def set_text_val(val): foo.mytext = val # print 'setting to :',val def pr(): print("pyglui version: %s" % (ui.__version__)) gui = ui.UI() gui.scale = 1.0 thumbbar = ui.Scrolling_Menu("ThumbBar", pos=(-80, 0), size=(0, 0), header_pos="hidden") menubar = ui.Scrolling_Menu("MenueBar", pos=(-500, 0), size=(-90, 0), header_pos="left") gui.append(menubar) gui.append(thumbbar) T = ui.Growing_Menu("T menu", header_pos="headline") menubar.append(T) L = ui.Growing_Menu("L menu", header_pos="headline") menubar.append(L) M = ui.Growing_Menu("M menu", header_pos="headline") menubar.append(M) def toggle_menu(collapsed, menu): menubar.collapsed = collapsed for m in menubar.elements: m.collapsed = True menu.collapsed = collapsed thumbbar.append( ui.Thumb( "collapsed", T, label="T", on_val=False, off_val=True, setter=lambda x: toggle_menu(x, T), )) thumbbar.append( ui.Thumb( "collapsed", L, label="L", on_val=False, off_val=True, setter=lambda x: toggle_menu(x, L), )) thumbbar.append( ui.Thumb( "collapsed", M, label="M", on_val=False, off_val=True, setter=lambda x: toggle_menu(x, M), )) # thumbbar.elements[-1].order = -10.0 print("order" + str(thumbbar.elements[-1].order)) T.append(ui.Button("T test", pr)) T.append( ui.Info_Text( "T best finerfpiwnesdco'n wfo;ineqrfo;inwefo'qefr voijeqfr'p9qefrp'i 'iqefr'ijqfr eqrfiqerfn'ioer" )) L.append(ui.Button("L test", pr)) L.append(ui.Button("L best", pr)) M.append(ui.Button("M test", pr)) M.append(ui.Button("M best", pr)) MM = ui.Growing_Menu("MM menu", pos=(0, 0), size=(0, 400)) M.append(MM) for x in range(20): MM.append(ui.Button("M test%s" % x, pr)) M.append(ui.Button("M best", pr)) M.append(ui.Button("M best", pr)) M.append(ui.Button("M best", pr)) M.append(ui.Button("M best", pr)) M.append(ui.Button("M best", pr)) M.append(ui.Button("M best", pr)) M.append(ui.Button("M best", pr)) # label = 'Ï' # label = 'R' # gui.append( import os import psutil pid = os.getpid() ps = psutil.Process(pid) ts = time.time() from pyglui import graph print(graph.__version__) cpu_g = graph.Line_Graph() cpu_g.pos = (50, 100) cpu_g.update_fn = ps.cpu_percent cpu_g.update_rate = 5 cpu_g.label = "CPU %0.1f" fps_g = graph.Line_Graph() fps_g.pos = (50, 100) fps_g.update_rate = 5 fps_g.label = "%0.0f FPS" fps_g.color[:] = 0.1, 0.1, 0.8, 0.9 on_resize(window, *glfw.get_window_size(window)) while not quit: gui.update() # print(T.collapsed,L.collapsed,M.collapsed) # T.collapsed = True # glfw.make_context_current(window) glfw.swap_buffers(window) glfw.poll_events() # adjust_gl_view(1280,720,window) glClearColor(0.3, 0.4, 0.1, 1) glClear(GL_COLOR_BUFFER_BIT) gui.terminate() glfw.terminate() logger.debug("Process done")
def demo(video_frame = None): user_input = {'down':False, 'mouse':(0,0)} # Callback functions def on_resize(window,w, h): h = max(h,1) w = max(w,1) gui.update_window(w,h) active_window = glfwGetCurrentContext() glfwMakeContextCurrent(window) # norm_size = normalize((w,h),glfwGetWindowSize(window)) # fb_size = denormalize(norm_size,glfwGetFramebufferSize(window)) adjust_gl_view(w,h) glfwMakeContextCurrent(active_window) track.set_window_size(w,h) def on_iconify(window,iconfied): pass def on_key(window, key, scancode, action, mods): gui.update_key(key,scancode,action,mods) def on_char(window,char): gui.update_char(char) def on_button(window,button, action, mods): gui.update_button(button,action,mods) if action == GLFW_PRESS: user_input['down'] = True user_input['mouse'] = glfwGetCursorPos(window) if action == GLFW_RELEASE: user_input['down'] = False # pos = normalize(pos,glfwGetWindowSize(window)) # pos = denormalize(pos,(frame.img.shape[1],frame.img.shape[0]) ) # Position in img pixels def on_pos(window,x, y): hdpi_factor = float(glfwGetFramebufferSize(window)[0]/glfwGetWindowSize(window)[0]) x,y = x*hdpi_factor,y*hdpi_factor gui.update_mouse(x,y) if user_input['down']: old_x,old_y = user_input['mouse'] track.drag_to(x-old_x,y-old_y) user_input['mouse'] = x,y def on_scroll(window,x,y): gui.update_scroll(x,y) track.zoom_to(y) # get glfw started glfwInit() window = glfwCreateWindow(width, height, "pyglui demo", None, None) glfwMakeContextCurrent(window) if not window: exit() glfwSetWindowPos(window,0,0) # Register callbacks window glfwSetFramebufferSizeCallback(window,on_resize) glfwSetWindowIconifyCallback(window,on_iconify) glfwSetKeyCallback(window,on_key) glfwSetCharCallback(window,on_char) glfwSetMouseButtonCallback(window,on_button) glfwSetCursorPosCallback(window,on_pos) glfwSetScrollCallback(window,on_scroll) init() glutInit() basic_gl_setup() gui = ui.UI() track = Trackball() on_resize(window,*glfwGetFramebufferSize(window)) if video_frame == None: video_frame = (np.linspace(0,1,num=(400*400*4))*255).astype(np.uint8).reshape((400,400,4)) #the randomized image test_sphere = geometry.Sphere([0,5,0],1) test_ellipse = geometry.Ellipse((0,3),5,3,0) #return window #def demo_update(window): while not glfwWindowShouldClose(window): clear_gl_screen() track.push() #glutils.draw_polyline3d([(0,0,2),(1,1,2)],color=RGBA(0.4,0.5,0.3,0.5)) draw_sphere(test_sphere) draw_ellipse(test_ellipse) draw_video_screen(video_frame) draw_coordinate_system(20) track.pop() glfwSwapBuffers(window) glfwPollEvents() #def demo_close(window): glfwDestroyWindow(window) glfwTerminate() logger.debug("Process done")
def demo(): global quit quit = False # Callback functions def on_resize(window, w, h): h = max(h, 1) w = max(w, 1) hdpi_factor = glfwGetFramebufferSize(window)[0] / glfwGetWindowSize( window)[0] w, h = w * hdpi_factor, h * hdpi_factor gui.update_window(w, h) active_window = glfwGetCurrentContext() glfwMakeContextCurrent(window) # norm_size = normalize((w,h),glfwGetWindowSize(window)) # fb_size = denormalize(norm_size,glfwGetFramebufferSize(window)) adjust_gl_view(w, h, window) glfwMakeContextCurrent(active_window) def on_iconify(window, iconfied): pass def on_key(window, key, scancode, action, mods): gui.update_key(key, scancode, action, mods) if action == GLFW_PRESS: if key == GLFW_KEY_ESCAPE: on_close(window) def on_char(window, char): gui.update_char(char) def on_button(window, button, action, mods): gui.update_button(button, action, mods) # pos = normalize(pos,glfwGetWindowSize(window)) # pos = denormalize(pos,(frame.img.shape[1],frame.img.shape[0]) ) # Position in img pixels def on_pos(window, x, y): hdpi_factor = float( glfwGetFramebufferSize(window)[0] / glfwGetWindowSize(window)[0]) x, y = x * hdpi_factor, y * hdpi_factor gui.update_mouse(x, y) def on_scroll(window, x, y): gui.update_scroll(x, y) def on_close(window): global quit quit = True logger.info('Process closing from window') # get glfw started glfwInit() window = glfwCreateWindow(width, height, "pyglui demo", None, None) if not window: exit() glfwSetWindowPos(window, 0, 0) # Register callbacks window glfwSetWindowSizeCallback(window, on_resize) glfwSetWindowCloseCallback(window, on_close) glfwSetWindowIconifyCallback(window, on_iconify) glfwSetKeyCallback(window, on_key) glfwSetCharCallback(window, on_char) glfwSetMouseButtonCallback(window, on_button) glfwSetCursorPosCallback(window, on_pos) glfwSetScrollCallback(window, on_scroll) glfwMakeContextCurrent(window) init() basic_gl_setup() class Temp(object): """Temp class to make objects""" def __init__(self): pass foo = Temp() foo.bar = 34 foo.bur = 4 foo.mytext = [203, 12] foo.myswitch = 10 foo.select = 'Tiger' foo.record = False foo.calibrate = False foo.stream = True foo.test = False d = {} d['one'] = 1 def print_hello(): foo.select = 'Cougar' gui.scale += .1 print 'hello' # m.configuration = sidebar.configuration def printer(val): print 'setting to :', val print "pyglui version: %s" % (ui.__version__) gui = ui.UI() gui.scale = 1.0 sidebar = ui.Scrolling_Menu("MySideBar", pos=(-300, 0), size=(0, 0), header_pos='left') sm = ui.Growing_Menu("SubMenu", pos=(0, 0), size=(0, 100)) sm.append(ui.Slider("bar", foo)) sm.append(ui.Text_Input('mytext', foo, setter=printer)) ssm = ui.Growing_Menu("SubSubMenu", pos=(0, 0), size=(0, 100)) ssm.append(ui.Slider("bar", foo)) ssm.append(ui.Text_Input('mytext', foo, setter=printer)) sm.append(ssm) sidebar.append(sm) sm.append( ui.Selector('select', foo, selection=['Tiger', 'Lion', 'Cougar', 'Hyena'])) sm.append(ui.Button("Say Hi!", print_hello)) gui.append(sidebar) m = ui.Scrolling_Menu("MyMenu", pos=(250, 30), size=(300, 500), header_pos='top') m.append( ui.Info_Text( "This is my multiline info text. I wonder if multilines break as designed... How does it look? Info Text with long label text to test multiline break handling." )) m.append( ui.Selector('select', foo, selection=['Tiger', 'Lion', 'Cougar', 'Hyena'], setter=printer)) m.append( ui.Slider( "bur", foo, step=50, min=1, max=1005, label="Slider label with long label text to test overflow handling" )) m.append(ui.Button("Say Hi!", print_hello)) m.append( ui.Switch("myswitch", foo, on_val=1000, off_val=10, label="Switch Me")) sm = ui.Growing_Menu("SubMenu", pos=(0, 0), size=(0, 100)) sm.append(ui.Slider("bar", foo)) sm.append(ui.Text_Input('mytext', foo)) m.append(sm) m.append(ui.Button("Say Hi!", print_hello)) rightbar = ui.Stretching_Menu('Right Bar', (0, 100), (150, -100)) rightbar.append(ui.Thumb("record", foo, label="Record")) rightbar.append(ui.Thumb("calibrate", foo, label="Calibrate")) rightbar.append(ui.Thumb("stream", foo, label="Stream")) rightbar.append(ui.Thumb("test", foo, label="Test")) gui.append(rightbar) gui.append(m) import os import psutil pid = os.getpid() ps = psutil.Process(pid) ts = time.time() from pyglui import graph print graph.__version__ cpu_g = graph.Line_Graph() cpu_g.pos = (50, 100) cpu_g.update_fn = ps.get_cpu_percent cpu_g.update_rate = 5 cpu_g.label = 'CPU %0.1f' fps_g = graph.Line_Graph() fps_g.pos = (50, 100) fps_g.update_rate = 5 fps_g.label = "%0.0f FPS" fps_g.color[:] = .1, .1, .8, .9 st_graph = graph.Averaged_Value() st_graph.pos = (200, 200) st_graph.update_rate = 5 st_graph.label = "Slider Value: %0.0f" st_graph.color[:] = 1., 0., .6, .9 on_resize(window, *glfwGetWindowSize(window)) while not quit: dt, ts = time.time() - ts, time.time() clear_gl_screen() cpu_g.update() cpu_g.draw() fps_g.add(1. / dt) fps_g.draw() st_graph.add(foo.bur) st_graph.draw() gui.update() glfwSwapBuffers(window) glfwPollEvents() glfwDestroyWindow(window) glfwTerminate() logger.debug("Process done")
def demo(): global quit quit = False # Callback functions def on_resize(window,w, h): h = max(h,1) w = max(w,1) hdpi_factor = glfwGetFramebufferSize(window)[0]/glfwGetWindowSize(window)[0] w,h = w*hdpi_factor,h*hdpi_factor gui.update_window(w,h) active_window = glfwGetCurrentContext() glfwMakeContextCurrent(window) # norm_size = normalize((w,h),glfwGetWindowSize(window)) # fb_size = denormalize(norm_size,glfwGetFramebufferSize(window)) adjust_gl_view(w,h,window) glfwMakeContextCurrent(active_window) def on_iconify(window,iconfied): pass def on_key(window, key, scancode, action, mods): gui.update_key(key,scancode,action,mods) if action == GLFW_PRESS: if key == GLFW_KEY_ESCAPE: on_close(window) if mods == GLFW_MOD_SUPER: if key == 67: # copy value to system clipboard # ideally copy what is in our text input area test_val = "copied text input" glfwSetClipboardString(window,test_val) print("set clipboard to: %s" %(test_val)) if key == 86: # copy from system clipboard clipboard = glfwGetClipboardString(window) print("pasting from clipboard: %s" %(clipboard)) def on_char(window,char): gui.update_char(char) def on_button(window,button, action, mods): gui.update_button(button,action,mods) # pos = normalize(pos,glfwGetWindowSize(window)) # pos = denormalize(pos,(frame.img.shape[1],frame.img.shape[0]) ) # Position in img pixels def on_pos(window,x, y): hdpi_factor = float(glfwGetFramebufferSize(window)[0]/glfwGetWindowSize(window)[0]) x,y = x*hdpi_factor,y*hdpi_factor gui.update_mouse(x,y) def on_scroll(window,x,y): gui.update_scroll(x,y) def on_close(window): global quit quit = True logger.info('Process closing from window') # get glfw started glfwInit() window = glfwCreateWindow(width, height, "pyglui demo", None, None) if not window: exit() glfwSetWindowPos(window,0,0) # Register callbacks for the window glfwSetWindowSizeCallback(window,on_resize) glfwSetWindowCloseCallback(window,on_close) glfwSetWindowIconifyCallback(window,on_iconify) glfwSetKeyCallback(window,on_key) glfwSetCharCallback(window,on_char) glfwSetMouseButtonCallback(window,on_button) glfwSetCursorPosCallback(window,on_pos) glfwSetScrollCallback(window,on_scroll) # test out new paste function glfwMakeContextCurrent(window) init() basic_gl_setup() print(glGetString(GL_VERSION)) class Temp(object): """Temp class to make objects""" def __init__(self): pass foo = Temp() foo.bar = 34 foo.sel = 'mi' foo.selection = ['€','mi', u"re"] foo.mytext = "some text" def set_text_val(val): foo.mytext = val # print 'setting to :',val print("pyglui version: %s" %(ui.__version__)) gui = ui.UI() gui.scale = 1.0 sidebar = ui.Scrolling_Menu("MySideBar",pos=(-300,0),size=(0,0),header_pos='left') sm = ui.Growing_Menu("SubMenu",pos=(0,0),size=(0,100)) sm.append(ui.Slider("bar",foo)) sm.append(ui.Text_Input('mytext',foo,setter=set_text_val)) sm.append(ui.Selector('sel',foo,selection=foo.selection)) sidebar.append(sm) gui.append(sidebar) menu = ui.Scrolling_Menu('My Window 1', pos=(200,100), size=(50, 200),header_pos='top') menu.append(ui.Slider("bar",foo)) gui.append(menu) menu = ui.Scrolling_Menu('My Window 2', pos=(200,100), size=(50, 200),header_pos='top') menu.append(ui.Text_Input('mytext',foo,setter=set_text_val)) gui.append(menu) label = 'Ï' # label = 'R' gui.append(ui.Thumb('mytext',foo,label=label,hotkey='r',label_font='fontawesome',label_offset_x=5,label_offset_y=0,label_offset_size=-20)) import os import psutil pid = os.getpid() ps = psutil.Process(pid) ts = time.time() from pyglui import graph print(graph.__version__) cpu_g = graph.Line_Graph() cpu_g.pos = (50,100) cpu_g.update_fn = ps.cpu_percent cpu_g.update_rate = 5 cpu_g.label = 'CPU %0.1f' fps_g = graph.Line_Graph() fps_g.pos = (50,100) fps_g.update_rate = 5 fps_g.label = "%0.0f FPS" fps_g.color[:] = .1,.1,.8,.9 on_resize(window,*glfwGetWindowSize(window)) while not quit: dt,ts = time.time()-ts,time.time() clear_gl_screen() draw_concentric_circles( (500,250), 200, 6 , 1.0 ) draw_concentric_circles( (600,250), 200, 7 , 1.0 ) draw_concentric_circles( (700,250), 200, 8 , 0.1 ) cpu_g.update() cpu_g.draw() fps_g.add(1./dt) fps_g.draw() gui.update() glfwSwapBuffers(window) glfwPollEvents() gui.terminate() glfwTerminate() logger.debug("Process done")
def runNDSIClient(): global quit quit = False # Callback functions def on_resize(window,w, h): h = max(h,1) w = max(w,1) hdpi_factor = glfwGetFramebufferSize(window)[0]/glfwGetWindowSize(window)[0] w,h = w*hdpi_factor,h*hdpi_factor gui.update_window(w,h) active_window = glfwGetCurrentContext() glfwMakeContextCurrent(window) # norm_size = normalize((w,h),glfwGetWindowSize(window)) # fb_size = denormalize(norm_size,glfwGetFramebufferSize(window)) adjust_gl_view(w,h,window) glfwMakeContextCurrent(active_window) def on_iconify(window,iconfied): pass def on_key(window, key, scancode, action, mods): gui.update_key(key,scancode,action,mods) if action == GLFW_PRESS: if key == GLFW_KEY_ESCAPE: on_close(window) if mods == GLFW_MOD_SUPER: if key == 67: # copy value to system clipboard # ideally copy what is in our text input area test_val = "copied text input" glfwSetClipboardString(window,test_val) logger.debug("set clipboard to: {}".format(test_val)) if key == 86: # copy from system clipboard clipboard = glfwGetClipboardString(window) logger.debug("pasting from clipboard: {}".format(clipboard)) def on_char(window,char): gui.update_char(char) def on_button(window,button, action, mods): # logger.debug "button: ", button # logger.debug "action: ", action gui.update_button(button,action,mods) # pos = normalize(pos,glfwGetWindowSize(window)) # pos = denormalize(pos,(frame.img.shape[1],frame.img.shape[0]) ) # Position in img pixels def on_pos(window,x, y): hdpi_factor = float(glfwGetFramebufferSize(window)[0]/glfwGetWindowSize(window)[0]) x,y = x*hdpi_factor,y*hdpi_factor gui.update_mouse(x,y) def on_scroll(window,x,y): gui.update_scroll(x,y) def on_close(window): global quit quit = True logger.info('Process closing from window') # get glfw started glfwInit() window = glfwCreateWindow(width, height, "pyglui demo", None, None) if not window: exit() glfwSetWindowPos(window,0,0) # Register callbacks for the window glfwSetWindowSizeCallback(window,on_resize) glfwSetWindowCloseCallback(window,on_close) glfwSetWindowIconifyCallback(window,on_iconify) glfwSetKeyCallback(window,on_key) glfwSetCharCallback(window,on_char) glfwSetMouseButtonCallback(window,on_button) glfwSetCursorPosCallback(window,on_pos) glfwSetScrollCallback(window,on_scroll) # test out new paste function glfwMakeContextCurrent(window) init() basic_gl_setup() logger.debug(glGetString(GL_VERSION)) class Temp(object): """Temp class to make objects""" def __init__(self): pass foo = Temp() foo.bar = 34 foo.mytext = "some text" def set_text_val(val): foo.mytext = val # logger.debug 'setting to :',val logger.debug("pyglui version: {}".format(ui.__version__)) gui = ui.UI() gui.scale = 1.0 sensors = {} def on_network_event(network, event): if event['subject'] == 'attach': # and event['sensor_type'] == 'video': wrapper = SensorUIWrapper(gui, n, event['sensor_uuid']) sensors[event['sensor_uuid']] = wrapper logger.info('Linking sensor {}...'.format(wrapper.sensor)) logger.debug(pprint.pformat(event)) if event['subject'] == 'detach': # and event['sensor_type'] == 'video': logger.info('Unlinking sensor {}...'.format(event['sensor_uuid'])) sensors[event['sensor_uuid']].cleanup() del sensors[event['sensor_uuid']] n = ndsi.Network(callbacks=(on_network_event,)) n.start() import os import psutil pid = os.getpid() ps = psutil.Process(pid) ts = time.time() from pyglui import graph logger.debug(graph.__version__) cpu_g = graph.Line_Graph() cpu_g.pos = (50,100) cpu_g.update_fn = ps.cpu_percent cpu_g.update_rate = 5 cpu_g.label = 'CPU %0.1f' fps_g = graph.Line_Graph() fps_g.pos = (50,100) fps_g.update_rate = 5 fps_g.label = "%0.0f FPS" fps_g.color[:] = .1,.1,.8,.9 on_resize(window,*glfwGetWindowSize(window)) while not quit: try: dt,ts = time.time()-ts,time.time() clear_gl_screen() cpu_g.update() cpu_g.draw() fps_g.add(1./dt) fps_g.draw() gui.update() glfwSwapBuffers(window) glfwPollEvents() # handle ndsi while n.has_events: n.handle_event() for s in sensors.values(): while s.sensor.has_notifications: s.sensor.handle_notification() except (KeyboardInterrupt, SystemExit): quit = True for sensor in sensors.values(): sensor.cleanup() sensors = None n.stop() gui.terminate() glfwTerminate() logger.debug("Process done")
def demo(): global quit quit = False # Callback functions def on_resize(window,w, h): h = max(h,1) w = max(w,1) hdpi_factor = glfwGetFramebufferSize(window)[0]/glfwGetWindowSize(window)[0] w,h = w*hdpi_factor,h*hdpi_factor gui.update_window(w,h) active_window = glfwGetCurrentContext() glfwMakeContextCurrent(window) # norm_size = normalize((w,h),glfwGetWindowSize(window)) # fb_size = denormalize(norm_size,glfwGetFramebufferSize(window)) adjust_gl_view(w,h,window) glfwMakeContextCurrent(active_window) def on_iconify(window,iconfied): pass def on_key(window, key, scancode, action, mods): gui.update_key(key,scancode,action,mods) if action == GLFW_PRESS: if key == GLFW_KEY_ESCAPE: on_close(window) def on_char(window,char): gui.update_char(char) def on_button(window,button, action, mods): gui.update_button(button,action,mods) # pos = normalize(pos,glfwGetWindowSize(window)) # pos = denormalize(pos,(frame.img.shape[1],frame.img.shape[0]) ) # Position in img pixels def on_pos(window,x, y): hdpi_factor = float(glfwGetFramebufferSize(window)[0]/glfwGetWindowSize(window)[0]) x,y = x*hdpi_factor,y*hdpi_factor gui.update_mouse(x,y) def on_scroll(window,x,y): gui.update_scroll(x,y) def on_close(window): global quit quit = True logger.info('Process closing from window') # get glfw started glfwInit() window = glfwCreateWindow(width, height, "pyglui demo", None, None) if not window: exit() glfwSetWindowPos(window,0,0) # Register callbacks window glfwSetWindowSizeCallback(window,on_resize) glfwSetWindowCloseCallback(window,on_close) glfwSetWindowIconifyCallback(window,on_iconify) glfwSetKeyCallback(window,on_key) glfwSetCharCallback(window,on_char) glfwSetMouseButtonCallback(window,on_button) glfwSetCursorPosCallback(window,on_pos) glfwSetScrollCallback(window,on_scroll) glfwMakeContextCurrent(window) init() basic_gl_setup() class Temp(object): """Temp class to make objects""" def __init__(self): pass foo = Temp() foo.bar = 34 foo.bur = 4 foo.mytext = [203,12] foo.myswitch = 10 foo.select = 'Tiger' foo.record = False foo.calibrate = False foo.stream = True foo.test = False d = {} d['one'] = 1 def print_hello(): foo.select = 'Cougar' gui.scale += .1 print 'hello' # m.configuration = sidebar.configuration def printer(val): print 'setting to :',val print "pyglui version: %s" %(ui.__version__) gui = ui.UI() gui.scale = 1.0 sidebar = ui.Scrolling_Menu("MySideBar",pos=(-300,0),size=(0,0),header_pos='left') sm = ui.Growing_Menu("SubMenu",pos=(0,0),size=(0,100)) sm.append(ui.Slider("bar",foo)) sm.append(ui.Text_Input('mytext',foo,setter=printer)) ssm = ui.Growing_Menu("SubSubMenu",pos=(0,0),size=(0,100)) ssm.append(ui.Slider("bar",foo)) ssm.append(ui.Text_Input('mytext',foo,setter=printer)) sm.append(ssm) sidebar.append(sm) sm.append(ui.Selector('select',foo,selection=['Tiger','Lion','Cougar','Hyena']) ) sm.append(ui.Button("Say Hi!",print_hello)) gui.append(sidebar) m = ui.Scrolling_Menu("MyMenu",pos=(250,30),size=(300,500),header_pos='top') m.append(ui.Info_Text("This is my multiline info text. I wonder if multilines break as designed... How does it look? Info Text with long label text to test multiline break handling." )) m.append(ui.Selector('select',foo,selection=['Tiger','Lion','Cougar','Hyena'],setter=printer) ) m.append(ui.Slider("bur",foo,step=50,min=1,max=1005, label="Slider label with long label text to test overflow handling")) m.append(ui.Button("Say Hi!",print_hello)) m.append(ui.Switch("myswitch",foo,on_val=1000,off_val=10,label="Switch Me")) sm = ui.Growing_Menu("SubMenu",pos=(0,0),size=(0,100)) sm.append(ui.Slider("bar",foo)) sm.append(ui.Text_Input('mytext',foo)) m.append(sm) m.append(ui.Button("Say Hi!",print_hello)) rightbar = ui.Stretching_Menu('Right Bar',(0,100),(150,-100)) rightbar.append(ui.Thumb("record",foo,label="Record") ) rightbar.append(ui.Thumb("calibrate",foo,label="Calibrate") ) rightbar.append(ui.Thumb("stream",foo,label="Stream") ) rightbar.append(ui.Thumb("test",foo,label="Test") ) gui.append(rightbar) gui.append(m) import os import psutil pid = os.getpid() ps = psutil.Process(pid) ts = time.time() from pyglui import graph print graph.__version__ cpu_g = graph.Line_Graph() cpu_g.pos = (50,100) cpu_g.update_fn = ps.get_cpu_percent cpu_g.update_rate = 5 cpu_g.label = 'CPU %0.1f' fps_g = graph.Line_Graph() fps_g.pos = (50,100) fps_g.update_rate = 5 fps_g.label = "%0.0f FPS" fps_g.color[:] = .1,.1,.8,.9 st_graph = graph.Averaged_Value() st_graph.pos = (200,200) st_graph.update_rate = 5 st_graph.label = "Slider Value: %0.0f" st_graph.color[:] = 1.,0.,.6,.9 on_resize(window,*glfwGetWindowSize(window)) while not quit: dt,ts = time.time()-ts,time.time() clear_gl_screen() cpu_g.update() cpu_g.draw() fps_g.add(1./dt) fps_g.draw() st_graph.add(foo.bur) st_graph.draw() gui.update() glfwSwapBuffers(window) glfwPollEvents() glfwDestroyWindow(window) glfwTerminate() logger.debug("Process done")