當前位置: 首頁>>代碼示例>>Python>>正文


Python Vehicle.setLayout方法代碼示例

本文整理匯總了Python中vehicle.Vehicle.setLayout方法的典型用法代碼示例。如果您正苦於以下問題:Python Vehicle.setLayout方法的具體用法?Python Vehicle.setLayout怎麽用?Python Vehicle.setLayout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在vehicle.Vehicle的用法示例。


在下文中一共展示了Vehicle.setLayout方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: World

# 需要導入模塊: from vehicle import Vehicle [as 別名]
# 或者: from vehicle.Vehicle import setLayout [as 別名]
class World(DirectObject):
    instance = None

    def __init__(self):
        render.setAntialias(AntialiasAttrib.MAuto)

        # Enable physics - perhaps this should go someplace else, but it must
        # be done before the Vehicle is initialized.
        base.enableParticles()
        aei = AngularEulerIntegrator()
        base.physicsMgr.attachAngularIntegrator(aei)

        SelectionEngine.getDefault().enable()
        SelectionManager.getDefault().enable()
        
        # Make the environment and the vehicle model.
        makeEnvironment()
        self.vehicle = Vehicle(render)

        MissionElement.loadElementConfig('mission_elements.plist')

        #layoutName = AppPreferences.get('last_layout', 'defaultLayout.plist')
        if len(sys.argv) == 2:
            layoutName = sys.argv[1]
            print "Using command line argument %s for layout" %layoutName
        else:
            print "Using default layout file"
            print "Use ./sim2.py [layout file] to use a different layout"
            print "Or press Ctrl+O to open a new layout in the simulator"
            layoutName = 'defaultLayout.plist'

        self.layout = MissionLayout.loadLayout(layoutName)
        render.attachNewNode(self.layout)

        self.vehicle.setLayout(self.layout) #Link the layout 

        # Set up render buffer viewer, to aide debugging.
        self.accept("v", base.bufferViewer.toggleEnable)
        self.accept("V", base.bufferViewer.toggleEnable)
        base.bufferViewer.setPosition("llcorner")
        
        # Set up file saver
        self.accept('s', self._saveLayout)
        self.accept('o', self._openLayout)
        self.accept('f', self._setFreq)
        root = Tk()
        root.withdraw()
        self.modButtons = ModifierButtons()
        self.modButtons.addButton(KeyboardButton.control())
        self.accept('control', self.modButtons.buttonDown,
                [KeyboardButton.control()])
        self.accept('control-up', self.modButtons.buttonUp,
                [KeyboardButton.control()])
        # Add GUI Controls
        '''
        buttonReady = makeGeom('button_ready.png')
        b = DirectButton(geom = (buttonReady,
                                 makeGeom('button_click.png'),
                                 makeGeom('button_rollover.png'),
                                 buttonReady),
                          relief = None)
        b.reparentTo(pixel2d)
        b.hide()
        b.setPos(base.win.getXSize()/2, 0, -base.win.getYSize()/2)
        b.setScale(1, 1, 1)
        b.bind(DirectGuiGlobals.ACCEPT, eventHandler, ['accept'])
        b.bind(DirectGuiGlobals.ACCEPTFAILED, eventHandler, ['accept failed'])
        b.bind(DirectGuiGlobals.ADJUST, eventHandler, ['adjust'])
        b.bind(DirectGuiGlobals.B1CLICK, eventHandler, ['b1click'])
        b.bind(DirectGuiGlobals.B1PRESS, eventHandler, ['b1press'])
        b.bind(DirectGuiGlobals.B1RELEASE, eventHandler, ['b1release'])
        b.bind(DirectGuiGlobals.B2CLICK, eventHandler, ['b2click'])
        b.bind(DirectGuiGlobals.B2PRESS, eventHandler, ['b2press'])
        b.bind(DirectGuiGlobals.B2RELEASE, eventHandler, ['b2release'])
        b.bind(DirectGuiGlobals.B3CLICK, eventHandler, ['b3click'])
        b.bind(DirectGuiGlobals.B3PRESS, eventHandler, ['b3press'])
        b.bind(DirectGuiGlobals.B3RELEASE, eventHandler, ['b3release'])
        b.bind(DirectGuiGlobals.ENTER, eventHandler, ['enter'])
        b.bind(DirectGuiGlobals.EXIT, eventHandler, ['exit'])
        b.bind(DirectGuiGlobals.WITHIN, eventHandler, ['within'])
        b.bind(DirectGuiGlobals.WITHOUT, eventHandler, ['without'])
        b.bind(DirectGuiGlobals.CURSORMOVE, eventHandler, ['cursormove'])
        # b['frameSize'] = (3, 3, 3, 3)
        '''

    @classmethod
    def getInstance(cls):
        if cls.instance == None:
            cls.instance = World()
        return cls.instance

    def _saveLayout(self):
        if self.modButtons.isDown(KeyboardButton.control()):
            self.modButtons.buttonUp(KeyboardButton.control())
            self.modButtons.buttonUp(KeyboardButton.asciiKey('s'))
            filename = asksaveasfilename(filetypes=[('plist files', '*.plist')])
            if filename:
                self.layout.save(filename)
                AppPreferences.set('last_layout', filename)

#.........這裏部分代碼省略.........
開發者ID:athityakumar,項目名稱:software,代碼行數:103,代碼來源:sim2.py


注:本文中的vehicle.Vehicle.setLayout方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。