Пример #1
0
    def __init__(self):
        binPath = LoadPath()
        binAuto = int(binPath == '')
        if os.name == 'nt': binAuto = 0

        self.buttonFunc = {}

        self.bBinPathAuto = ButtonWrapper('Auto', 3, 'toggle', initial=binAuto)
        self.bBinPathManual = ButtonWrapper('Manual',
                                            4,
                                            'toggle',
                                            initial=int(not binAuto))

        def fBinToggle(evt):
            if evt is 4:
                self.bBinPathAuto.val = (self.bBinPathAuto.val + 1) % 2
            else:
                self.bBinPathManual.val = (self.bBinPathManual.val + 1) % 2

        self.buttonFunc[3] = self.buttonFunc[4] = fBinToggle

        self.bBinPath = ButtonWrapper(
            'PandaBinPath:',
            0,
            'string',
            'The path that contains panda tool binaries (e.g. pview)',
            binPath,
            length=300)
        self.bBinPathSel = ButtonWrapper('Select', 5, 'push')
        if os.name == 'nt' and not binPath:
            envpath = os.getenv('PATH')
            pathdirs = envpath.split(os.pathsep)
            candidates = filter(
                lambda x: x.lower().find('panda3d') != -1 and x.lower().find(
                    'bin') != -1, pathdirs)
            if candidates:
                self.bBinPath.val = candidates[0]

        self.bLaunch = ButtonWrapper('Launch Chicken', 6, 'push')

        def fLaunch(dummy):
            if self.error is False:
                print os.path.join(Blender.Get('scriptsdir'), EXPORTER_NAME)
                Blender.Run(
                    os.path.join(Blender.Get('scriptsdir'), EXPORTER_NAME))
            else:
                if self.error is True:
                    word = "corrected"
                elif self.error is None:
                    word = "validated"
                Draw.PupMenu(
                    'Launch Error%s|Cannot launch until configuration is %s' %
                    ('%t', word))

        self.buttonFunc[6] = fLaunch

        self.bCheck = ButtonWrapper('Check Configuration', 7, 'push')

        def fCheck(dummy):
            self.msg = []
            if self.bBinPathAuto.val:
                bin = ''
            else:
                bin = self.bBinPath.val
            self.error = CheckPath(bin, self.msg)
            if self.error is False:
                d = {}
                if self.bBinPathManual.val:
                    d['PandaBinPath'] = bin
                else:
                    d['PandaBinPath'] = ''
                Registry.SetKey('Chicken', d, True)
            else:
                Draw.PupMenu('Configuration Errors%t|' + '|'.join(self.msg))
                print self.msg

        self.buttonFunc[7] = fCheck

        self.pathMap = {5: self.bBinPath}

        def fPathSelector(id):
            def updatePath(fn):
                n = fn.rfind(os.sep)
                fn = fn[0:n]
                if os.path.isdir(fn):
                    self.pathMap[id].val = fn

            Window.FileSelector(updatePath, "Select Path",
                                self.pathMap[id].val)

        self.buttonFunc[5] = fPathSelector

        self.error = None
        self.msg = []

        Draw.Register(self.draw, self.event, self.button)