Example #1
0
def run_standalone():
    import subprocess
    
    ourPath=([p for p in sys.path if os.path.exists(p+'/newprojectwizard_win.py')]+[''])[0]
    os.system(ourPath+'/newprojectwizard.py')

    try:file=open(ourPath+'/projectconf.tmp','r')
    except: return
    projectFile=file.readline()[:-1]
    projectKind=file.readline()[:-1]
    projectName=file.readline()[:-1]
    projectSourceLang=file.readline()[:-1]
    projectTargetlang=file.readline()[:-1]
    file.close()
    os.remove(ourPath+'/projectconf.tmp')

    Project.init(projectFile, projectKind, projectName, projectSourceLang, projectTargetlang)
    Lokalize.openProject(projectFile)
Example #2
0
class ProjectAssistant(QWizard):
    def __init__(self):
        QWizard.__init__(self)
        for p in pages:
            exec "self.addPage( %s(self) )" % p

        #for page in [self.page(pageId) for pageId in self.pageIds()]:
        for page in [self.page(pages.index(pageId)) for pageId in pages]:
            self.connect(page,SIGNAL("nextRequested()"),self,SLOT("next()"))
            
        self.connect(self,SIGNAL("finished(int)"),self,SLOT("deleteLater()"))
        self.connect(self,SIGNAL("accepted()"),self.handleAccept)

    def handleAccept(self):
        fs=lambda name:self.field(name).toString()
        fi=lambda name:self.field(name).toInt()[0]
        fb=lambda name:self.field(name).toBool()

        kinds=['odf','kde']
        projectKind=kinds[self.page(0).group.checkedId()]
        langs=allLanguagesList

        doInit=True
        projectfilename='index.lokalize'
        #if projectKind=='odf' and fb('odf-template-source-files'):
            #projectfilename=QFileInfo(fs('odf-template-files')).baseName()+'.lokalize'

        if projectKind=='odf':
            loc=QDir(fs('location'))
            loc.mkdir(fs('name'))
            projectFilePath=loc.absoluteFilePath(fs('name')+'/'+projectfilename)
            targetlang=langs[fi('target-lang')]
            name=fs('name').toLower()
        elif projectKind=='kde':
            name='kde'
            loc=QDir(fs('kde-existing-location'))
            targetlang=loc.dirName()
            print 'project lang: %s' % targetlang
            print 'project loc: %s' % fs('kde-existing-location')

            l=loc.entryList(QStringList('*.lokalize'), QDir.Filter(QDir.Files))
            if len(l):
                doInit=False
                projectfilename=l[0]
            projectFilePath=loc.absoluteFilePath(projectfilename)

        if projectKind=='odf':
            files=[fs('odf-template-files')]
            for f in files:
                info=QFileInfo(f)
                xlf=QDir.toNativeSeparators(info.absolutePath()+'/'+info.baseName()+'.xlf')
                #this makes Lokalize crash on close
                #try: odf2xliff.main(tt_args(unicode(f), unicode(xlf)))
                #except:
                if True:
                    print 'odf2xliff via subprocess.call', unicode(f),  unicode(xlf)
                    try:
                        retcode = subprocess.call(['odf2xliff', unicode(f),  unicode(xlf)])
                        print >>sys.stderr
                    except OSError, e:
                        print >>sys.stderr, "Execution failed:", e


        self.projectName=name+'-'+targetlang
        self.projectSourceLang=langs[fi('source-lang')]
        self.projectTargetLang=targetlang
        self.projectKind=projectKind
        self.projectFilePath=projectFilePath

        self.projectShouldBeInitialized=doInit
        if doInit and not standalone:
            Lokalize.openProject(projectFilePath)
            Project.init(projectFilePath, projectKind, self.projectName, self.projectSourceLang, targetlang)
            Lokalize.openProject(projectFilePath)