def create_interface(self): self.app = ui.Widget() self.app.setGeometry(App.screen_x, App.screen_y, App.width, App.height) # -------------------------------------------------------------------- # # Sliders x = App.width-220 y = 40 h = 15 inc = 40 sliders = [ [ 0, "X-Axis, " , self.update_shift_x , Algorithm.shift_x ] , [ 0, "Y-Axis, " , self.update_shift_y , Algorithm.shift_y ] , [ 1, "scaling x, " , self.update_scaling_x , Algorithm.scaling_x ] , [ 1, "scaling y, " , self.update_scaling_y , Algorithm.scaling_y ] , [ 2, None, None, None] , [ 0, "Globals, " , self.update_n_globals , Algorithm.n_globals ] , [ 0, "Locals, " , self.update_n_locals , Algorithm.n_locals ] , [ 1, "max tangent length, " , self.update_m_length , Algorithm.m_length ] , [ 1, "max error, " , self.update_m_error , Algorithm.m_error ] ] for (slider_type, title, update_fn, alg_var) in sliders: if slider_type == 0: ui.slider( self.app, title , alg_var , ui.Geo(x=x, y=y, w=200, h=h) , update_fn ) elif slider_type == 1: ui.p_slider( self.app, title , alg_var[2] , ui.Geo(x=x, y=y, w=200, h=h) , update_fn ) else: # add a gap y += inc * 0.5 y += inc # -- # -------------------------------------------------------------------- # # Buttons y += inc * 0.5 x = App.width - 120 inc = 30 ui.button( self.app, "Globals", ui.Geo(x=x, y=y, w=100, h=20) , self.update_globals ); y += inc ui.button( self.app, "Interp, Use N", ui.Geo(x=x, y=y, w=100, h=20) , self.update_interp_using_n ); y += inc ui.button( self.app, "Interp, Iterative", ui.Geo(x=x, y=y, w=100, h=20) , self.update_interp_iterative ); y += inc ui.button( self.app, "Export", ui.Geo(x=x, y=y, w=100, h=20) , self.export_json ); y += inc # -- # -------------------------------------------------------------------- # # Toggles def create_display_toggle(change, name): def fn(value): change[name] = value self.app.update() return fn # Display x = App.width - 120 y = App.height - 200 inc = 20 self.display_toggles = App.display for key in App.display_order: ui.button( self.app, key, ui.Geo(x = x, y = y, w = 100, h = 20) , create_display_toggle(self.display_toggles, key) , checkable = True, checked = self.display_toggles[key]) y += inc # Curves x = 20 y = 20 inc = 20 self.curves = {} self.dimensions = {} for layer in Motion.layers: for name in layer: self.curves[name] = False ui.label(self.app, name, ui.Geo(x = x, y = y)) x += 100 self.dimensions[name] = {"rx":False, "ry":False, "rz":False} ui.button( self.app, "x", ui.Geo(x = x, y = y, w = 20, h = 20) , create_display_toggle(self.dimensions[name], "rx") , checkable = True, checked = False); x+=inc ui.button( self.app, "y", ui.Geo(x = x, y = y, w = 20, h = 20) , create_display_toggle(self.dimensions[name], "ry") , checkable = True, checked = False); x+=inc ui.button( self.app, "z", ui.Geo(x = x, y = y, w = 20, h = 20) , create_display_toggle(self.dimensions[name], "rz") , checkable = True, checked = False); x+=inc y += inc x = 20 y += inc # -- # -------------------------------------------------------------------- # # Complete self.app.setWindowTitle(App.title) self.app.show() self.app.setMouseTracking(True) # Drawing function def paintFn(e): def do_drawing(parent, active): # Get sizing, and adjust for slider offset ox = self.shift_x oy = self.shift_y sx = self.scaling_x sy = self.scaling_y # Display, setup drawing = ui.Drawing() drawer = ui.Drawer(drawing, ox, oy, sx, sy) drawing.begin(parent) drawing.setRenderHint(ui.Antialiasing, True) # Display, draw if active[0]: self.draw_zeroline(drawer) if active[1]: self.draw_mocap(drawer) if active[2]: self.draw_keyframes_global(drawer) if active[3]: self.draw_keyframes_local(drawer) if active[4]: self.draw_interpolation(drawer) # Display, cleanup drawing.end() # Drawing for display output do_drawing(self.app, [1, 1, 1, 1, 1]) # Drawing for image output if self.display_toggles["save_as_made"]: image = ui.Image(App.width, App.height, ui.ImageFormat) do_drawing(image, [0, 1, 1, 1, 1]) image.save("../logs/%d.png" % ( self.n_globals ) ) self.app.paintEvent = paintFn
def controls(self): self.wcontrols = ui.Widget() self.wcontrols.resize(300, App.height) self.wcontrols.move(App.width,0) self.wcontrols.setWindowTitle('Curves') self.filename = ui.TextIn(self.wcontrols) self.filename.move(20, 20) self.filename.setPlaceholderText("output") # -------------------------------------------------------------------- # # Sliders x = 20 y = 80 h = 15 inc = 40 sliders = [ [ 0, "X-Axis, " , self.update_shift_x , Algorithm.shift_x ] , [ 0, "Y-Axis, " , self.update_shift_y , Algorithm.shift_y ] , [ 1, "scaling x, " , self.update_scaling_x , Algorithm.scaling_x ] , [ 1, "scaling y, " , self.update_scaling_y , Algorithm.scaling_y ] , [ 0, "Globals, " , self.update_globals , Algorithm.n_globals ] , [ 1, "threshold alpha, " , self.update_alpha , Algorithm.alpha ] , [ 1, "threshold beta y, " , self.update_beta , Algorithm.beta ] ] for (slider_type, title, update_fn, alg_var) in sliders: if slider_type == 0: ui.slider( self.wcontrols, title , alg_var , ui.Geo(x=x, y=y, w=200, h=h) , update_fn ) elif slider_type == 1: ui.p_slider( self.wcontrols, title , alg_var[2] , ui.Geo(x=x, y=y, w=200, h=h) , update_fn ) else: y += inc * 0.5 y += inc # # -------------------------------------------------------------------- # # Toggles x = 20 inc = 20 y += 40 for key in App.display_order: ui.button( self.wcontrols, key, ui.Geo(x = x, y = y, w = 100, h = 20) , self.create_display_toggle(self.display_toggles, key) , checkable = True, checked = self.display_toggles[key]) y += inc # # -------------------------------------------------------------------- # self.wcontrols.show()