Esempio n. 1
0
 def __init__(self, parent, port=None):
     ToolPane.__init__(self, parent, port)
     self.term = shell(self)
     sizer = wx.BoxSizer(wx.VERTICAL)
     sizer.Add(self.term, 1, wx.EXPAND|wx.ALL, 1)
     self.SetSizer(sizer)
     self.Fit()
     sizer.SetSizeHints(self)
     self.Show(True)
Esempio n. 2
0
 def __init__(self, parent, port=None):
     ToolPane.__init__(self, parent, port)
     self.term = shell(self)
     sizer = wx.BoxSizer(wx.VERTICAL)
     sizer.Add(self.term, 1, wx.EXPAND|wx.ALL, 1)
     self.SetSizer(sizer)
     self.Fit()
     sizer.SetSizeHints(self)
     self.Show(True)
Esempio n. 3
0
    def __init__(self, project, path):
        logging.info(":: Initializing Editor")
        logging.info(":: Reading settings")
        self.options = ProjectSettings(project, path)
        self.width = 1024
        self.height = 768

        logging.info(":: Starting windowing system")
        self.pyglet_window = pyglet.window.Window(self.width, self.height, resizable=True)
        self.pyglet_window.set_caption("Green Editor")
        self.pyglet_window.set_visible(True)
        
        # Set up event handlers
        self.keyboard = key.KeyStateHandler()
        #self.pyglet_window.push_handlers(self.keyboard)
        self.pyglet_window.push_handlers(self.on_key_press)
        self.pyglet_window.push_handlers(self.on_mouse_drag)
        self.pyglet_window.push_handlers(self.on_mouse_motion)
        self.pyglet_window.push_handlers(self.on_mouse_press)
        self.pyglet_window.push_handlers(self.on_resize)
        self.pyglet_window.push_handlers(self.on_draw)

        # Internal 'windows'
        self.tools_pane = ToolPane(150, self.height)
        self.mapeditor_pane = MapEditor(self.options, self.width, self.height, 150)
        self.tileset_window = TSetWindow()
        
        self.should_render = True
        self.input_timeout = 0
        #self.active_window = "MapEditor"
        self.active_window = "TileSet_Window"
        
        pyglet.clock.schedule(self.update)
        pyglet.app.run()
Esempio n. 4
0
    def __init__(self, project, path):
        logging.info(":: Initializing Editor")
        logging.info(":: Reading settings")
        self.options = ProjectSettings(project, path)
        self.width = 1024
        self.height = 768

        logging.info(":: Starting windowing system")
        self.pyglet_window = pyglet.window.Window(self.width,
                                                  self.height,
                                                  resizable=True)
        self.pyglet_window.set_caption("Green Editor")
        self.pyglet_window.set_visible(True)

        # Set up event handlers
        self.keyboard = key.KeyStateHandler()
        #self.pyglet_window.push_handlers(self.keyboard)
        self.pyglet_window.push_handlers(self.on_key_press)
        self.pyglet_window.push_handlers(self.on_mouse_drag)
        self.pyglet_window.push_handlers(self.on_mouse_motion)
        self.pyglet_window.push_handlers(self.on_mouse_press)
        self.pyglet_window.push_handlers(self.on_resize)
        self.pyglet_window.push_handlers(self.on_draw)

        # Internal 'windows'
        self.tools_pane = ToolPane(150, self.height)
        self.mapeditor_pane = MapEditor(self.options, self.width, self.height,
                                        150)
        self.tileset_window = TSetWindow()

        self.should_render = True
        self.input_timeout = 0
        #self.active_window = "MapEditor"
        self.active_window = "TileSet_Window"

        pyglet.clock.schedule(self.update)
        pyglet.app.run()
Esempio n. 5
0
    def __init__(self, parent, port=None):
        ToolPane.__init__(self, parent, port)
        self.curpose = "" 
        self.saveReq = False
        self.live = self.parent.live.IsChecked()

        sizer = wx.GridBagSizer(10,10)

        # pose editor, goes in a box:
        temp = wx.StaticBox(self, -1, 'edit pose')
        temp.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD))
        editBox = wx.StaticBoxSizer(temp,orient=wx.VERTICAL) 
        poseEditSizer = wx.GridBagSizer(5,5)
        # build servo editors
        self.servos = list() # the editors in the window
        for i in range(self.parent.project.count):
            temp = wx.Panel(self,-1)
            hbox = wx.BoxSizer(wx.HORIZONTAL)
            if (i+1)<10: 
                temp.enable = wx.CheckBox(temp, i, "ID 0"+str(i+1))
            else:
                temp.enable = wx.CheckBox(temp, i, "ID "+str(i+1))
            temp.enable.SetValue(True)
            temp.position = wx.Slider(temp, i, 512, 0, self.parent.project.resolution[i]-1, wx.DefaultPosition, (200, -1), wx.SL_HORIZONTAL | wx.SL_LABELS)
            hbox.Add(temp.enable)
            hbox.Add(temp.position)
            temp.SetSizer(hbox)
            # multiple columns now:
            if i < self.parent.columns:
                poseEditSizer.Add(temp, (0, i), wx.GBSpan(1,1), wx.TOP,10)
            else:
                poseEditSizer.Add(temp, (i/self.parent.columns, i%self.parent.columns))
            temp.Disable()  # servo editors start out disabled, enabled only when a pose is selected
            self.servos.append(temp)
        # grid it
        editBox.Add(poseEditSizer)
        sizer.Add(editBox, (0,0), wx.GBSpan(1,1), wx.EXPAND)

        # list of poses
        self.posebox = wx.ListBox(self, self.ID_POSE_BOX, choices=self.parent.project.poses.keys())
        sizer.Add(self.posebox, (0,1), wx.GBSpan(1,1), wx.EXPAND) 
        # and add/remove
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(wx.Button(self, self.BT_POSE_ADD, 'add'))
        hbox.Add(wx.Button(self, self.BT_POSE_REM, 'remove'))   
        hbox.Add(wx.Button(self, self.BT_POSE_RENAME, 'rename')) 
        sizer.Add(hbox,(1,1),wx.GBSpan(1,1),wx.ALIGN_CENTER)  

        # toolbar
        toolbar = wx.Panel(self, -1)
        toolbarsizer = wx.BoxSizer(wx.HORIZONTAL)        
        #  delta-T for interpolation
        self.deltaTButton = wx.Button(toolbar, self.BT_DELTA_T, 'delta-T')   
        self.deltaTButton.Disable()     
        toolbarsizer.Add(self.deltaTButton,1)
        self.deltaT = 500
        if port != None and port.hasInterpolation == True:        
            self.deltaTButton.Enable()
        toolbarsizer.Add(wx.Button(toolbar, self.BT_RELAX, 'relax'),1)
        toolbarsizer.Add(wx.Button(toolbar, self.BT_CAPTURE, 'capture'),1)         
        toolbarsizer.Add(wx.Button(toolbar, self.BT_SET, 'set'),1)                
        toolbar.SetSizer(toolbarsizer)
        sizer.Add(toolbar, (1,0), wx.GBSpan(1,1), wx.ALIGN_CENTER)

        self.Bind(wx.EVT_SLIDER, self.updatePose)
        self.Bind(wx.EVT_CHECKBOX, self.relaxServo)
        wx.EVT_BUTTON(self, self.BT_RELAX, self.parent.doRelax)    
        wx.EVT_BUTTON(self, self.BT_CAPTURE, self.capturePose) 
        wx.EVT_BUTTON(self, self.BT_SET, self.setPose)   
        wx.EVT_BUTTON(self, self.BT_POSE_ADD, self.addPose)   
        wx.EVT_BUTTON(self, self.BT_POSE_REM, self.remPose)   
        wx.EVT_BUTTON(self, self.BT_POSE_RENAME, self.renamePose)
        wx.EVT_BUTTON(self, self.BT_DELTA_T, self.doDeltaT)   
        wx.EVT_LISTBOX(self, self.ID_POSE_BOX, self.doPose)

        # key accelerators
        aTable = wx.AcceleratorTable([(wx.ACCEL_CTRL,  ord('S'), self.BT_CAPTURE),  # capture Servos
                                      (wx.ACCEL_CTRL, ord('R'), self.BT_RELAX),     # Relax
                                      (wx.ACCEL_CTRL, ord('A'), self.BT_POSE_ADV),  # Advance
                                     ])
        self.SetAcceleratorTable(aTable)
        self.Bind(wx.EVT_MENU,self.capturePose,id=self.BT_CAPTURE)
        self.Bind(wx.EVT_MENU,self.parent.doRelax,id=self.BT_RELAX)
        self.Bind(wx.EVT_MENU,self.advancePose,id=self.BT_POSE_ADV)

        self.SetSizerAndFit(sizer)
Esempio n. 6
0
class Editor:

    def __init__(self, project, path):
        logging.info(":: Initializing Editor")
        logging.info(":: Reading settings")
        self.options = ProjectSettings(project, path)
        self.width = 1024
        self.height = 768

        logging.info(":: Starting windowing system")
        self.pyglet_window = pyglet.window.Window(self.width, self.height, resizable=True)
        self.pyglet_window.set_caption("Green Editor")
        self.pyglet_window.set_visible(True)
        
        # Set up event handlers
        self.keyboard = key.KeyStateHandler()
        #self.pyglet_window.push_handlers(self.keyboard)
        self.pyglet_window.push_handlers(self.on_key_press)
        self.pyglet_window.push_handlers(self.on_mouse_drag)
        self.pyglet_window.push_handlers(self.on_mouse_motion)
        self.pyglet_window.push_handlers(self.on_mouse_press)
        self.pyglet_window.push_handlers(self.on_resize)
        self.pyglet_window.push_handlers(self.on_draw)

        # Internal 'windows'
        self.tools_pane = ToolPane(150, self.height)
        self.mapeditor_pane = MapEditor(self.options, self.width, self.height, 150)
        self.tileset_window = TSetWindow()
        
        self.should_render = True
        self.input_timeout = 0
        #self.active_window = "MapEditor"
        self.active_window = "TileSet_Window"
        
        pyglet.clock.schedule(self.update)
        pyglet.app.run()

    def update(self, dt):
        pass

    def on_draw(self):
        glClear(GL_COLOR_BUFFER_BIT)
        self.mapeditor_pane.draw()
        self.tools_pane.draw()
        self.tileset_window.draw()

    def on_key_press(self, symbol, modifiers):
        if symbol == key.Q:
            quit(1)
        elif symbol == key.S:
            self.mapeditor_pane.save("test.yaml")
        elif symbol == key.L:
            self.mapeditor_pane.load("test.yaml")
        elif symbol == key.MINUS:
            self.tile_size = self.tile_size - 1
        elif symbol == key.PLUS:
            self.tile_size = self.tile_size + 1
        elif symbol == key.R:
            self.mapeditor_pane.toggle_grid()
        elif symbol == key.RIGHT:
            self.mapeditor_pane.horiz_scroll(-1)
        elif symbol == key.UP:
            self.mapeditor_pane.vert_scroll(-1)
        elif symbol == key.LEFT:
            self.mapeditor_pane.horiz_scroll(1)
        elif symbol == key.DOWN:
            self.mapeditor_pane.vert_scroll(1)
        
    def on_mouse_drag(self, x, y, dx, dy, button, modifiers):
        print "on_mouse_drag:"
        print "  x: %s" % x
        print "  y: %s" % y
        print "  button: %s" % button
        
        if button & mouse.LEFT:
            if self.active_window == "TileSet_Window":
                self.tileset_window.on_mouse_drag(x, y, dx, dy, button, modifiers)

    def on_mouse_motion(self, x, y, dx, dy):
        print "on_mouse_motion:"
        print "  x: %s" % x
        print "  y: %s" % y

    def on_mouse_press(self, x, y, button, modifiers):
        print "on_mouse_press"
        print "  x: %s" % x
        print "  y: %s" % y
        print "  button: %s" % button
        if self.active_window == "MapEditor":
            self.mapeditor_pane.on_mouse_press(x, y, button, modifiers)
        elif self.active_window == "TileSet_Window":
            self.tileset_window.on_mouse_press(x, y, button, modifiers)

    def on_mouse_release(self, x, y, button, modifiers):
        print "on_mouse_release"
        print "  x: %s" % x
        print "  y: %s" % y
        print "  button: %s" % button

    def on_resize(self, w, h):
        logging.info("Resizing: %sx%s" % (w, h))
        self.width = w
        self.height = h
        self.mapeditor_pane.resize(self.width, self.height)
        self.tools_pane.resize(150, self.height)
Esempio n. 7
0
    def __init__(self, parent, port=None):
        ToolPane.__init__(self, parent, port)
        # default data
        self.signs = "+"*18
        self.curpose = ""
        self.ikChoice = ""
        self.optChoice = ""

        self.sizer = wx.GridBagSizer(10,10)

        # IK styles/Config
        temp = wx.StaticBox(self, -1, 'IK Config')
        temp.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD))
        configBox = wx.StaticBoxSizer(temp,orient=wx.VERTICAL)
        configSizer = wx.GridBagSizer(5,5)
        configSizer.Add(wx.StaticText(self, -1, "IK Type:"),(0,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL|wx.TOP,10)
        self.ikType = wx.ComboBox(self, self.ID_IKTYPE, choices=iKmodels.keys())
        configSizer.Add(self.ikType,(0,1),wx.GBSpan(1,1),wx.TOP,10)

        # IK Option (typical # of legs or # of DOF)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        self.optLabel = wx.StaticText(self, -1, "# of Legs:")
        configSizer.Add(self.optLabel,(1,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        self.ikOpt = wx.ComboBox(self, self.ID_IKOPT, choices=["4","6"])
        configSizer.Add(self.ikOpt,(1,1))
        configBox.Add(configSizer)
        self.sizer.Add(configBox, (0,1), wx.GBSpan(1,1), wx.EXPAND)

        # Actions buttons
        temp = wx.StaticBox(self, -1, 'Actions')
        temp.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD))
        actionBox = wx.StaticBoxSizer(temp,orient=wx.VERTICAL)
        actionSizer = wx.GridBagSizer(5,5)

        actionSizer.Add(wx.StaticText(self, -1, "Capture Limits:"), (0,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        actionSizer.Add(wx.StaticText(self, -1, "Capture Neutral:"), (1,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        actionSizer.Add(wx.StaticText(self, -1, "Set/Test Signs:"), (2,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)

        actionSizer.Add(wx.Button(self, self.BT_LIMITS, 'Capture'),(0,1))
        actionSizer.Add(wx.Button(self, self.BT_NEUTRAL, 'Capture'),(1,1))
        self.signButton = wx.Button(self, self.BT_SIGN, 'Go')
        actionSizer.Add(self.signButton,(2,1))

        actionBox.Add(actionSizer)
        self.sizer.Add(actionBox, (1,1), wx.GBSpan(1,1), wx.EXPAND)

        # NUKE Label
        nukeIt = wx.StaticText(self, -1, "NUKE: Get Your IK On")
        nukeIt.SetFont(wx.Font(15, wx.DEFAULT, wx.NORMAL, wx.BOLD, wx.ITALIC))
        self.sizer.Add(nukeIt, (2,0), wx.GBSpan(1,2), wx.ALIGN_CENTER_VERTICAL)

        # Buttons
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        gaitBut = wx.Button(self,-1,'Gait Builder')
        gaitBut.Disable()
        hbox.Add(gaitBut)
        viewBut = wx.Button(self,-1, 'Viewer/Tuner')
        viewBut.Disable()
        hbox.Add(viewBut)
        hbox.Add(wx.Button(self, self.BT_DRIVE, 'Test Drive'))
        hbox.Add(wx.Button(self,self.BT_EXPORT, 'Export'))
        self.sizer.Add(hbox, (2,2), wx.GBSpan(1,1), wx.ALIGN_CENTER)

        # Load Data (if possible)
        self.loadData()
        self.SetSizer(self.sizer)
        self.SetAutoLayout(1)
        self.sizer.Fit(self)

        # event handling
        wx.EVT_BUTTON(self, self.BT_LIMITS, self.doLimits)
        wx.EVT_BUTTON(self, self.BT_NEUTRAL, self.doNeutral)
        wx.EVT_BUTTON(self, self.BT_SIGN, self.doSignTest)
        wx.EVT_BUTTON(self, self.BT_DRIVE, self.doWalkTest)
        wx.EVT_BUTTON(self, self.BT_EXPORT, self.doExport)

        wx.EVT_COMBOBOX(self, self.ID_IKTYPE, self.doIKType)
        wx.EVT_COMBOBOX(self, self.ID_IKOPT, self.doIkOpt)
        wx.EVT_SPINCTRL(self, self.ID_ANY, self.save)
Esempio n. 8
0
    def __init__(self, parent, port=None):
        ToolPane.__init__(self, parent, port)
        # default data
        self.signs = "+" * 18
        self.curpose = ""
        self.ikChoice = ""
        self.optChoice = ""

        self.sizer = wx.GridBagSizer(10, 10)

        # IK styles/Config
        temp = wx.StaticBox(self, -1, 'IK Config')
        temp.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD))
        configBox = wx.StaticBoxSizer(temp, orient=wx.VERTICAL)
        configSizer = wx.GridBagSizer(5, 5)
        configSizer.Add(wx.StaticText(self, -1, "IK Type:"), (0, 0),
                        wx.GBSpan(1, 1), wx.ALIGN_CENTER_VERTICAL | wx.TOP, 10)
        self.ikType = wx.ComboBox(self,
                                  self.ID_IKTYPE,
                                  choices=iKmodels.keys())
        configSizer.Add(self.ikType, (0, 1), wx.GBSpan(1, 1), wx.TOP, 10)

        # IK Option (typical # of legs or # of DOF)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        self.optLabel = wx.StaticText(self, -1, "# of Legs:")
        configSizer.Add(self.optLabel, (1, 0), wx.GBSpan(1, 1),
                        wx.ALIGN_CENTER_VERTICAL)
        self.ikOpt = wx.ComboBox(self, self.ID_IKOPT, choices=["4", "6"])
        configSizer.Add(self.ikOpt, (1, 1))
        configBox.Add(configSizer)
        self.sizer.Add(configBox, (0, 1), wx.GBSpan(1, 1), wx.EXPAND)

        # Actions buttons
        temp = wx.StaticBox(self, -1, 'Actions')
        temp.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD))
        actionBox = wx.StaticBoxSizer(temp, orient=wx.VERTICAL)
        actionSizer = wx.GridBagSizer(5, 5)

        actionSizer.Add(wx.StaticText(self, -1, "Capture Limits:"), (0, 0),
                        wx.GBSpan(1, 1), wx.ALIGN_CENTER_VERTICAL)
        actionSizer.Add(wx.StaticText(self, -1, "Capture Neutral:"), (1, 0),
                        wx.GBSpan(1, 1), wx.ALIGN_CENTER_VERTICAL)
        actionSizer.Add(wx.StaticText(self, -1, "Set/Test Signs:"), (2, 0),
                        wx.GBSpan(1, 1), wx.ALIGN_CENTER_VERTICAL)

        actionSizer.Add(wx.Button(self, self.BT_LIMITS, 'Capture'), (0, 1))
        actionSizer.Add(wx.Button(self, self.BT_NEUTRAL, 'Capture'), (1, 1))
        self.signButton = wx.Button(self, self.BT_SIGN, 'Go')
        actionSizer.Add(self.signButton, (2, 1))

        actionBox.Add(actionSizer)
        self.sizer.Add(actionBox, (1, 1), wx.GBSpan(1, 1), wx.EXPAND)

        # NUKE Label
        nukeIt = wx.StaticText(self, -1, "NUKE: Get Your IK On")
        nukeIt.SetFont(wx.Font(15, wx.DEFAULT, wx.NORMAL, wx.BOLD, wx.ITALIC))
        self.sizer.Add(nukeIt, (2, 0), wx.GBSpan(1, 2),
                       wx.ALIGN_CENTER_VERTICAL)

        # Buttons
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        gaitBut = wx.Button(self, -1, 'Gait Builder')
        gaitBut.Disable()
        hbox.Add(gaitBut)
        viewBut = wx.Button(self, -1, 'Viewer/Tuner')
        viewBut.Disable()
        hbox.Add(viewBut)
        hbox.Add(wx.Button(self, self.BT_DRIVE, 'Test Drive'))
        hbox.Add(wx.Button(self, self.BT_EXPORT, 'Export'))
        self.sizer.Add(hbox, (2, 2), wx.GBSpan(1, 1), wx.ALIGN_CENTER)

        # Load Data (if possible)
        self.loadData()
        self.SetSizer(self.sizer)
        self.SetAutoLayout(1)
        self.sizer.Fit(self)

        # event handling
        wx.EVT_BUTTON(self, self.BT_LIMITS, self.doLimits)
        wx.EVT_BUTTON(self, self.BT_NEUTRAL, self.doNeutral)
        wx.EVT_BUTTON(self, self.BT_SIGN, self.doSignTest)
        wx.EVT_BUTTON(self, self.BT_DRIVE, self.doWalkTest)
        wx.EVT_BUTTON(self, self.BT_EXPORT, self.doExport)

        wx.EVT_COMBOBOX(self, self.ID_IKTYPE, self.doIKType)
        wx.EVT_COMBOBOX(self, self.ID_IKOPT, self.doIkOpt)
        wx.EVT_SPINCTRL(self, self.ID_ANY, self.save)
Esempio n. 9
0
    def __init__(self, parent, port=None):
        ToolPane.__init__(self, parent, port)
        self.curpose = ""
        self.saveReq = False
        self.live = self.parent.live.IsChecked()

        sizer = wx.GridBagSizer(10, 10)

        # pose editor, goes in a box:
        temp = wx.StaticBox(self, -1, 'edit pose')
        temp.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD))
        editBox = wx.StaticBoxSizer(temp, orient=wx.VERTICAL)
        poseEditSizer = wx.GridBagSizer(5, 5)
        # build servo editors
        self.servos = list()  # the editors in the window
        for i in range(self.parent.project.count):
            temp = wx.Panel(self, -1)
            hbox = wx.BoxSizer(wx.HORIZONTAL)
            if (i + 1) < 10:
                temp.enable = wx.CheckBox(temp, i, "ID 0" + str(i + 1))
            else:
                temp.enable = wx.CheckBox(temp, i, "ID " + str(i + 1))
            temp.enable.SetValue(True)
            temp.position = wx.Slider(temp, i, 512, 0,
                                      self.parent.project.resolution[i] - 1,
                                      wx.DefaultPosition, (200, -1),
                                      wx.SL_HORIZONTAL | wx.SL_LABELS)
            hbox.Add(temp.enable)
            hbox.Add(temp.position)
            temp.SetSizer(hbox)
            # multiple columns now:
            if i < self.parent.columns:
                poseEditSizer.Add(temp, (0, i), wx.GBSpan(1, 1), wx.TOP, 10)
            else:
                poseEditSizer.Add(
                    temp, (i / self.parent.columns, i % self.parent.columns))
            temp.Disable(
            )  # servo editors start out disabled, enabled only when a pose is selected
            self.servos.append(temp)
        # grid it
        editBox.Add(poseEditSizer)
        sizer.Add(editBox, (0, 0), wx.GBSpan(1, 1), wx.EXPAND)

        # list of poses
        self.posebox = wx.ListBox(self,
                                  self.ID_POSE_BOX,
                                  choices=self.parent.project.poses.keys())
        sizer.Add(self.posebox, (0, 1), wx.GBSpan(1, 1), wx.EXPAND)
        # and add/remove
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(wx.Button(self, self.BT_POSE_ADD, 'add'))
        hbox.Add(wx.Button(self, self.BT_POSE_REM, 'remove'))
        hbox.Add(wx.Button(self, self.BT_POSE_RENAME, 'rename'))
        sizer.Add(hbox, (1, 1), wx.GBSpan(1, 1), wx.ALIGN_CENTER)

        # toolbar
        toolbar = wx.Panel(self, -1)
        toolbarsizer = wx.BoxSizer(wx.HORIZONTAL)
        #  delta-T for interpolation
        self.deltaTButton = wx.Button(toolbar, self.BT_DELTA_T, 'delta-T')
        self.deltaTButton.Disable()
        toolbarsizer.Add(self.deltaTButton, 1)
        self.deltaT = 500
        if port != None and port.hasInterpolation == True:
            self.deltaTButton.Enable()
        toolbarsizer.Add(wx.Button(toolbar, self.BT_RELAX, 'relax'), 1)
        toolbarsizer.Add(wx.Button(toolbar, self.BT_CAPTURE, 'capture'), 1)
        toolbarsizer.Add(wx.Button(toolbar, self.BT_SET, 'set'), 1)
        toolbar.SetSizer(toolbarsizer)
        sizer.Add(toolbar, (1, 0), wx.GBSpan(1, 1), wx.ALIGN_CENTER)

        self.Bind(wx.EVT_SLIDER, self.updatePose)
        self.Bind(wx.EVT_CHECKBOX, self.relaxServo)
        wx.EVT_BUTTON(self, self.BT_RELAX, self.parent.doRelax)
        wx.EVT_BUTTON(self, self.BT_CAPTURE, self.capturePose)
        wx.EVT_BUTTON(self, self.BT_SET, self.setPose)
        wx.EVT_BUTTON(self, self.BT_POSE_ADD, self.addPose)
        wx.EVT_BUTTON(self, self.BT_POSE_REM, self.remPose)
        wx.EVT_BUTTON(self, self.BT_POSE_RENAME, self.renamePose)
        wx.EVT_BUTTON(self, self.BT_DELTA_T, self.doDeltaT)
        wx.EVT_LISTBOX(self, self.ID_POSE_BOX, self.doPose)

        # key accelerators
        aTable = wx.AcceleratorTable([
            (wx.ACCEL_CTRL, ord('S'), self.BT_CAPTURE),  # capture Servos
            (wx.ACCEL_CTRL, ord('R'), self.BT_RELAX),  # Relax
            (wx.ACCEL_CTRL, ord('A'), self.BT_POSE_ADV),  # Advance
        ])
        self.SetAcceleratorTable(aTable)
        self.Bind(wx.EVT_MENU, self.capturePose, id=self.BT_CAPTURE)
        self.Bind(wx.EVT_MENU, self.parent.doRelax, id=self.BT_RELAX)
        self.Bind(wx.EVT_MENU, self.advancePose, id=self.BT_POSE_ADV)

        self.SetSizerAndFit(sizer)
Esempio n. 10
0
    def __init__(self, parent, port=None):
        ToolPane.__init__(self, parent, port)
        # default data
        self.signs = "+"*18
        self.curpose = "" 
        self.ikChoice = ""
        self.legChoice = ""
        
        sizer = wx.GridBagSizer(10,10)
        
        # Body Dimensions 
        temp = wx.StaticBox(self, -1, 'Body Dimensions')
        temp.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD))
        bodyBox = wx.StaticBoxSizer(temp,orient=wx.VERTICAL) 
        bodySizer = wx.GridBagSizer(5,5)
    
        bodySizer.Add(wx.StaticText(self, -1, "Leg"), (0,0), wx.GBSpan(1,1), wx.EXPAND | wx.TOP, 10)
        bodySizer.Add(wx.StaticText(self, -1, "Coxa(mm):"), (1,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        bodySizer.Add(wx.StaticText(self, -1, "Femur(mm):"), (2,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        bodySizer.Add(wx.StaticText(self, -1, "Tibia(mm):"), (3,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        bodySizer.Add(wx.StaticText(self, -1, "Offsets"), (4,0), wx.GBSpan(1,1), wx.EXPAND | wx.TOP, 10)
        bodySizer.Add(wx.StaticText(self, -1, "X(mm):"), (5,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        bodySizer.Add(wx.StaticText(self, -1, "Y(mm):"), (6,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        bodySizer.Add(wx.StaticText(self, -1, "Mid-Y(mm):"), (7,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        bodySizer.Add(wx.StaticText(self, -1, "COG Offset"), (8,0), wx.GBSpan(1,1), wx.EXPAND | wx.TOP, 10)
        bodySizer.Add(wx.StaticText(self, -1, "X(mm):"), (9,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        bodySizer.Add(wx.StaticText(self, -1, "Y(mm):"), (10,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        
        # VARS = coxaLen, femurLen, tibiaLen, xBody, yBody, midyBody, xCOG, yCOG
        self.vars = list()
        self.vars.append(wx.SpinCtrl(self, self.ID_ANY, '50', min=1, max=5000))
        bodySizer.Add(self.vars[0], (1,1))
        self.vars.append(wx.SpinCtrl(self, self.ID_ANY, '50', min=1, max=5000))
        bodySizer.Add(self.vars[1], (2,1))
        self.vars.append(wx.SpinCtrl(self, self.ID_ANY, '50', min=1, max=5000))
        bodySizer.Add(self.vars[2], (3,1))
        self.picture = wx.StaticBitmap(self, bitmap=wx.Bitmap("tools/images/leg.jpg"))
        bodySizer.Add(self.picture, (1,2), wx.GBSpan(3,1))

        self.vars.append(wx.SpinCtrl(self, self.ID_ANY, '50', min=1, max=5000))
        bodySizer.Add(self.vars[3], (5,1))
        self.vars.append(wx.SpinCtrl(self, self.ID_ANY, '50', min=1, max=5000))
        bodySizer.Add(self.vars[4], (6,1))
        self.vars.append(wx.SpinCtrl(self, self.ID_ANY, '50', min=1, max=5000))
        bodySizer.Add(self.vars[5], (7,1)) 
        self.picture1 = wx.StaticBitmap(self, bitmap=wx.Bitmap("tools/images/body.jpg"))
        bodySizer.Add(self.picture1, (5,2), wx.GBSpan(3,1))      

        self.vars.append(wx.SpinCtrl(self, self.ID_ANY, '0', min=-200, max=200))
        bodySizer.Add(self.vars[6], (9,1))
        self.vars.append(wx.SpinCtrl(self, self.ID_ANY, '0', min=-200, max=200))
        bodySizer.Add(self.vars[7], (10,1))

        bodyBox.Add(bodySizer)
        sizer.Add(bodyBox, (0,0), wx.GBSpan(2,1), wx.EXPAND)

        # IK styles/Config
        temp = wx.StaticBox(self, -1, 'IK Config')
        temp.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD))
        configBox = wx.StaticBoxSizer(temp,orient=wx.VERTICAL) 
        configSizer = wx.GridBagSizer(5,5)
        configSizer.Add(wx.StaticText(self, -1, "IK Type:"),(0,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL|wx.TOP,10)
        self.ikType = wx.ComboBox(self, self.ID_IKTYPE, choices=iKmodels.keys())
        configSizer.Add(self.ikType,(0,1),wx.GBSpan(1,1),wx.TOP,10)   
        
        # Number of Legs
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        configSizer.Add(wx.StaticText(self, -1, "# of Legs:"),(1,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        self.legCount = wx.ComboBox(self, self.ID_LEGCOUNT, choices=["4","6"])
        configSizer.Add(self.legCount,(1,1))     
        #configSizer.Add(wx.Button(self, -1, 'Advanced View'), (2,1), wx.GBSpan(1,1), wx.ALIGN_RIGHT)
        configBox.Add(configSizer)
        sizer.Add(configBox, (0,1), wx.GBSpan(1,1), wx.EXPAND)

        # Actions buttons
        temp = wx.StaticBox(self, -1, 'Actions')
        temp.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD))
        actionBox = wx.StaticBoxSizer(temp,orient=wx.VERTICAL) 
        actionSizer = wx.GridBagSizer(5,5)

        actionSizer.Add(wx.StaticText(self, -1, "Capture Limits:"), (0,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        actionSizer.Add(wx.StaticText(self, -1, "Capture Neutral:"), (1,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        actionSizer.Add(wx.StaticText(self, -1, "Set/Test Signs:"), (2,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        #actionSizer.Add(wx.StaticText(self, -1, "Test Drive:"), (3,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
                
        actionSizer.Add(wx.Button(self, self.BT_LIMITS, 'Capture'),(0,1))
        actionSizer.Add(wx.Button(self, self.BT_NEUTRAL, 'Capture'),(1,1))
        self.signButton = wx.Button(self, self.BT_SIGN, 'Go')        
        actionSizer.Add(self.signButton,(2,1))
        #driveButton = wx.Button(self, self.BT_DRIVE, 'Drive')
        #driveButton.Disable()
        #actionSizer.Add(driveButton,(3,1))
        
        actionBox.Add(actionSizer)
        sizer.Add(actionBox, (1,1), wx.GBSpan(1,1), wx.EXPAND)    
        
        # Servo ID Selections
        temp = wx.StaticBox(self, -1, 'Servo Assignments')
        temp.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD))
        servoBox = wx.StaticBoxSizer(temp,orient=wx.VERTICAL) 
        servoSizer = wx.GridBagSizer(5,5)
    
        servoSizer.Add(wx.StaticText(self, -1, "LF Coxa:"), (0,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL| wx.TOP, 10)
        servoSizer.Add(wx.StaticText(self, -1, "LF Femur:"), (1,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        servoSizer.Add(wx.StaticText(self, -1, "LF Tibia:"), (2,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        servoSizer.Add(wx.StaticText(self, -1, "RF Coxa:"), (0,2), wx.GBSpan(1,1), wx.ALIGN_CENTER_VERTICAL| wx.TOP, 10)
        servoSizer.Add(wx.StaticText(self, -1, "RF Femur:"), (1,2), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        servoSizer.Add(wx.StaticText(self, -1, "RF Tibia:"), (2,2), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)

        servoSizer.Add(wx.StaticText(self, -1, "LM Coxa:"), (4,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        servoSizer.Add(wx.StaticText(self, -1, "LM Femur:"), (5,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        servoSizer.Add(wx.StaticText(self, -1, "LM Tibia:"), (6,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        servoSizer.Add(wx.StaticText(self, -1, "RM Coxa:"), (4,2), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        servoSizer.Add(wx.StaticText(self, -1, "RM Femur:"), (5,2), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        servoSizer.Add(wx.StaticText(self, -1, "RM Tibia:"), (6,2), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        
        servoSizer.Add(wx.StaticText(self, -1, "LR Coxa:"), (8,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        servoSizer.Add(wx.StaticText(self, -1, "LR Femur:"), (9,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        servoSizer.Add(wx.StaticText(self, -1, "LR Tibia:"), (10,0), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        servoSizer.Add(wx.StaticText(self, -1, "RR Coxa:"), (8,2), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        servoSizer.Add(wx.StaticText(self, -1, "RR Femur:"), (9,2), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        servoSizer.Add(wx.StaticText(self, -1, "RR Tibia:"), (10,2), wx.GBSpan(1,1),wx.ALIGN_CENTER_VERTICAL)
        
        # SERVOS = Coxa, Femur, Tibia (LF, RF, LM, RM, LR, RR)
        self.servos = list()
        self.servos.append(wx.SpinCtrl(self, self.ID_ANY, '2', min=1, max=self.parent.project.count))    # LF
        servoSizer.Add(self.servos[0], (0,1), wx.GBSpan(1,1), wx.EXPAND | wx.TOP, 10)
        self.servos.append(wx.SpinCtrl(self, self.ID_ANY, '4', min=1, max=self.parent.project.count))
        servoSizer.Add(self.servos[1], (1,1))
        self.servos.append(wx.SpinCtrl(self, self.ID_ANY, '6', min=1, max=self.parent.project.count))
        servoSizer.Add(self.servos[2], (2,1))

        self.servos.append(wx.SpinCtrl(self, self.ID_ANY, '1', min=1, max=self.parent.project.count))    # RF
        servoSizer.Add(self.servos[3], (0,3), wx.GBSpan(1,1), wx.EXPAND | wx.TOP, 10)
        self.servos.append(wx.SpinCtrl(self, self.ID_ANY, '3', min=1, max=self.parent.project.count))
        servoSizer.Add(self.servos[4], (1,3))
        self.servos.append(wx.SpinCtrl(self, self.ID_ANY, '5', min=1, max=self.parent.project.count))
        servoSizer.Add(self.servos[5], (2,3))

        self.servos.append(wx.SpinCtrl(self, self.ID_ANY, '14', min=1, max=self.parent.project.count))  # LM
        servoSizer.Add(self.servos[6], (4,1))
        self.servos.append(wx.SpinCtrl(self, self.ID_ANY, '16', min=1, max=self.parent.project.count))
        servoSizer.Add(self.servos[7], (5,1))
        self.servos.append(wx.SpinCtrl(self, self.ID_ANY, '18', min=1, max=self.parent.project.count))
        servoSizer.Add(self.servos[8], (6,1))

        self.servos.append(wx.SpinCtrl(self, self.ID_ANY, '13', min=1, max=self.parent.project.count))  # RM
        servoSizer.Add(self.servos[9], (4,3))
        self.servos.append(wx.SpinCtrl(self, self.ID_ANY, '15', min=1, max=self.parent.project.count))
        servoSizer.Add(self.servos[10], (5,3))
        self.servos.append(wx.SpinCtrl(self, self.ID_ANY, '17', min=1, max=self.parent.project.count))
        servoSizer.Add(self.servos[11], (6,3))

        self.servos.append(wx.SpinCtrl(self, self.ID_ANY, '8', min=1, max=self.parent.project.count))   # LR
        servoSizer.Add(self.servos[12], (8,1))
        self.servos.append(wx.SpinCtrl(self, self.ID_ANY, '10', min=1, max=self.parent.project.count))
        servoSizer.Add(self.servos[13], (9,1))
        self.servos.append(wx.SpinCtrl(self, self.ID_ANY, '12', min=1, max=self.parent.project.count))
        servoSizer.Add(self.servos[14], (10,1))        

        self.servos.append(wx.SpinCtrl(self, self.ID_ANY, '7', min=1, max=self.parent.project.count))   # RR
        servoSizer.Add(self.servos[15], (8,3))
        self.servos.append(wx.SpinCtrl(self, self.ID_ANY, '9', min=1, max=self.parent.project.count))
        servoSizer.Add(self.servos[16], (9,3))
        self.servos.append(wx.SpinCtrl(self, self.ID_ANY, '11', min=1, max=self.parent.project.count))
        servoSizer.Add(self.servos[17], (10,3))

        servoBox.Add(servoSizer)
        sizer.Add(servoBox, (0,2), wx.GBSpan(2,1), wx.EXPAND)

        # NUKE Label
        nukeIt = wx.StaticText(self, -1, "NUKE: Kinematics Made Easy")
        nukeIt.SetFont(wx.Font(15, wx.DEFAULT, wx.NORMAL, wx.BOLD, wx.ITALIC))
        sizer.Add(nukeIt, (2,0), wx.GBSpan(1,2), wx.ALIGN_CENTER_VERTICAL)        

        # Buttons
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        gaitBut = wx.Button(self,-1,'Gait Builder')
        gaitBut.Disable()        
        hbox.Add(gaitBut)
        viewBut = wx.Button(self,-1, 'Viewer/Tuner')
        viewBut.Disable()
        hbox.Add(viewBut)
        hbox.Add(wx.Button(self, self.BT_DRIVE, 'Test Drive'))
        hbox.Add(wx.Button(self,self.BT_EXPORT, 'Export'))
        sizer.Add(hbox, (2,2), wx.GBSpan(1,1), wx.ALIGN_CENTER) 

        self.SetSizer(sizer)
        self.SetAutoLayout(1)
        sizer.Fit(self)

        # Load Data (if possible)
        self.loadData()

        # event handling
        wx.EVT_BUTTON(self, self.BT_LIMITS, self.doLimits)                
        wx.EVT_BUTTON(self, self.BT_NEUTRAL, self.doNeutral)
        wx.EVT_BUTTON(self, self.BT_SIGN, self.doSignTest) 
        wx.EVT_BUTTON(self, self.BT_DRIVE, self.doWalkTest) 
        wx.EVT_BUTTON(self, self.BT_EXPORT, self.doExport) 

        wx.EVT_COMBOBOX(self, self.ID_IKTYPE, self.doIKType)
        wx.EVT_COMBOBOX(self, self.ID_LEGCOUNT, self.doLegCount) 
        wx.EVT_SPINCTRL(self, self.ID_ANY, self.save)         
Esempio n. 11
0
    def __init__(self, parent, port=None):
        ToolPane.__init__(self, parent, port) 
        self.curseq = ""
        self.curtran = -1

        sizer = wx.GridBagSizer(10,10)
    
        # sequence editor, goes in a box:
        temp = wx.StaticBox(self, -1, 'edit sequence')
        temp.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD))
        editBox = wx.StaticBoxSizer(temp,orient=wx.VERTICAL)
        seqEditSizer = wx.GridBagSizer(5,5)
        
        # transitions list
        temp = wx.StaticText(self, -1, "transitions:")
        temp.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD))
        seqEditSizer.Add(temp, (0,0), wx.GBSpan(1,1), wx.TOP,10)
        self.tranbox = wx.ListBox(self, self.ID_TRAN_BOX)
        seqEditSizer.Add(self.tranbox, (1,0), wx.GBSpan(5,1), wx.EXPAND|wx.ALL) 
        # and add/remove
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(wx.Button(self, self.BT_TRAN_ADD, 'new'))
        hbox.Add(wx.Button(self, self.BT_TRAN_REM, 'delete'))     
        seqEditSizer.Add(hbox,(6,0),wx.GBSpan(1,1),wx.ALIGN_CENTER)
        
        # pose name & delta-T
        seqEditSizer.Add(wx.StaticText(self, -1, "pose:"), (1,1))
        self.tranPose = wx.ComboBox(self, self.ID_TRAN_POSE, choices=self.parent.project.poses.keys())
        seqEditSizer.Add(self.tranPose, (1,2))
        seqEditSizer.Add(wx.StaticText(self, -1, "delta-T:"), (2,1))
        self.tranTime = wx.SpinCtrl(self, self.ID_TRAN_TIME, '1000', min=1, max=5000)
        seqEditSizer.Add(self.tranTime, (2,2))
        # buttons to move transition up/down
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(wx.Button(self, self.BT_MOVE_UP, 'move up'))
        hbox.Add(wx.Button(self, self.BT_MOVE_DN, 'move down'))     
        seqEditSizer.Add(hbox,(4,1),wx.GBSpan(1,2),wx.ALIGN_CENTER|wx.BOTTOM,10)
        # grid it
        editBox.Add(seqEditSizer)
        sizer.Add(editBox, (0,0), wx.GBSpan(1,1), wx.EXPAND)

        # list of sequences
        self.seqbox = wx.ListBox(self, self.ID_SEQ_BOX, choices=self.parent.project.sequences.keys())
        sizer.Add(self.seqbox, (0,1), wx.GBSpan(1,1), wx.EXPAND) 
        # and add/remove
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(wx.Button(self, self.BT_SEQ_ADD, 'add'))
        hbox.Add(wx.Button(self, self.BT_SEQ_REM, 'remove'))     
        sizer.Add(hbox,(1,1),wx.GBSpan(1,1),wx.ALIGN_CENTER)

        # toolbar
        toolbar = wx.Panel(self, -1)
        toolbarsizer = wx.BoxSizer(wx.HORIZONTAL)
        toolbarsizer.Add(wx.Button(toolbar, self.BT_RELAX, 'relax'),1)
        toolbarsizer.Add(wx.Button(toolbar, self.BT_RUN, 'run'),1)   
        toolbarsizer.Add(wx.Button(toolbar, self.BT_LOOP, 'loop'),1)        
        toolbarsizer.Add(wx.Button(toolbar, self.BT_HALT, 'halt'),1)
        toolbar.SetSizer(toolbarsizer)
        sizer.Add(toolbar, (1,0), wx.GBSpan(1,1), wx.ALIGN_CENTER)

        self.SetSizerAndFit(sizer)

        wx.EVT_BUTTON(self, self.BT_RELAX, self.parent.doRelax)    
        wx.EVT_BUTTON(self, self.BT_RUN, self.runSeq)     
        wx.EVT_BUTTON(self, self.BT_LOOP, self.runSeq)   
        wx.EVT_BUTTON(self, self.BT_HALT, self.haltSeq) 
        wx.EVT_BUTTON(self, self.BT_SEQ_ADD, self.addSeq)
        wx.EVT_BUTTON(self, self.BT_SEQ_REM, self.remSeq)   
        wx.EVT_LISTBOX(self, self.ID_SEQ_BOX, self.doSeq)
        wx.EVT_BUTTON(self, self.BT_MOVE_UP, self.moveUp)
        wx.EVT_BUTTON(self, self.BT_MOVE_DN, self.moveDn)
        wx.EVT_BUTTON(self, self.BT_TRAN_ADD, self.addTran)
        wx.EVT_BUTTON(self, self.BT_TRAN_REM, self.remTran)   
        wx.EVT_LISTBOX(self, self.ID_TRAN_BOX, self.doTran)
        
        wx.EVT_COMBOBOX(self, self.ID_TRAN_POSE, self.updateTran)
        wx.EVT_SPINCTRL(self, self.ID_TRAN_TIME, self.updateTran)
Esempio n. 12
0
class Editor:
    def __init__(self, project, path):
        logging.info(":: Initializing Editor")
        logging.info(":: Reading settings")
        self.options = ProjectSettings(project, path)
        self.width = 1024
        self.height = 768

        logging.info(":: Starting windowing system")
        self.pyglet_window = pyglet.window.Window(self.width,
                                                  self.height,
                                                  resizable=True)
        self.pyglet_window.set_caption("Green Editor")
        self.pyglet_window.set_visible(True)

        # Set up event handlers
        self.keyboard = key.KeyStateHandler()
        #self.pyglet_window.push_handlers(self.keyboard)
        self.pyglet_window.push_handlers(self.on_key_press)
        self.pyglet_window.push_handlers(self.on_mouse_drag)
        self.pyglet_window.push_handlers(self.on_mouse_motion)
        self.pyglet_window.push_handlers(self.on_mouse_press)
        self.pyglet_window.push_handlers(self.on_resize)
        self.pyglet_window.push_handlers(self.on_draw)

        # Internal 'windows'
        self.tools_pane = ToolPane(150, self.height)
        self.mapeditor_pane = MapEditor(self.options, self.width, self.height,
                                        150)
        self.tileset_window = TSetWindow()

        self.should_render = True
        self.input_timeout = 0
        #self.active_window = "MapEditor"
        self.active_window = "TileSet_Window"

        pyglet.clock.schedule(self.update)
        pyglet.app.run()

    def update(self, dt):
        pass

    def on_draw(self):
        glClear(GL_COLOR_BUFFER_BIT)
        self.mapeditor_pane.draw()
        self.tools_pane.draw()
        self.tileset_window.draw()

    def on_key_press(self, symbol, modifiers):
        if symbol == key.Q:
            quit(1)
        elif symbol == key.S:
            self.mapeditor_pane.save("test.yaml")
        elif symbol == key.L:
            self.mapeditor_pane.load("test.yaml")
        elif symbol == key.MINUS:
            self.tile_size = self.tile_size - 1
        elif symbol == key.PLUS:
            self.tile_size = self.tile_size + 1
        elif symbol == key.R:
            self.mapeditor_pane.toggle_grid()
        elif symbol == key.RIGHT:
            self.mapeditor_pane.horiz_scroll(-1)
        elif symbol == key.UP:
            self.mapeditor_pane.vert_scroll(-1)
        elif symbol == key.LEFT:
            self.mapeditor_pane.horiz_scroll(1)
        elif symbol == key.DOWN:
            self.mapeditor_pane.vert_scroll(1)

    def on_mouse_drag(self, x, y, dx, dy, button, modifiers):
        print "on_mouse_drag:"
        print "  x: %s" % x
        print "  y: %s" % y
        print "  button: %s" % button

        if button & mouse.LEFT:
            if self.active_window == "TileSet_Window":
                self.tileset_window.on_mouse_drag(x, y, dx, dy, button,
                                                  modifiers)

    def on_mouse_motion(self, x, y, dx, dy):
        print "on_mouse_motion:"
        print "  x: %s" % x
        print "  y: %s" % y

    def on_mouse_press(self, x, y, button, modifiers):
        print "on_mouse_press"
        print "  x: %s" % x
        print "  y: %s" % y
        print "  button: %s" % button
        if self.active_window == "MapEditor":
            self.mapeditor_pane.on_mouse_press(x, y, button, modifiers)
        elif self.active_window == "TileSet_Window":
            self.tileset_window.on_mouse_press(x, y, button, modifiers)

    def on_mouse_release(self, x, y, button, modifiers):
        print "on_mouse_release"
        print "  x: %s" % x
        print "  y: %s" % y
        print "  button: %s" % button

    def on_resize(self, w, h):
        logging.info("Resizing: %sx%s" % (w, h))
        self.width = w
        self.height = h
        self.mapeditor_pane.resize(self.width, self.height)
        self.tools_pane.resize(150, self.height)