Exemplo n.º 1
0
    def finishInit(self):
        self.d = self.newDocument(isFirstNewDoc=True)
        os.environ['CADNANO_DISCARD_UNSAVED'] = 'True' ## added by Nick
        if os.environ.get('CADNANO_DISCARD_UNSAVED', False) and not self.ignoreEnv():
            self.sharedApp.dontAskAndJustDiscardUnsavedChanges = True
        if os.environ.get('CADNANO_DEFAULT_DOCUMENT', False) and not self.ignoreEnv():
            self.sharedApp.shouldPerformBoilerplateStartupScript = True
        cadnano.loadAllPlugins()

        if "-i" in self.argv:
            print "Welcome to cadnano's debug mode!"

            # All api shortcut functions have been factored out to the utils module.
            # (So the functions are easier to access if running cadnano as part of a larger script!)
            ns = cadnano_api.get_api(self)

            if readline:
                print "Enabling line-completion for standard code.interact mode...\n"
                # This is required, even when invoked via ipython, to get completion for a, d, etc.
                readline.set_completer(rlcompleter.Completer(ns).complete) # Makes it work :)
                readline.parse_and_bind("tab: complete") # Not strictly required when invoked via ipython.
            else:
                print "No readline/completer available..."
            print ns['cadnanohelp']
            code.interact("", local=ns)
            print "Interactive mode with code.interact complete..."
Exemplo n.º 2
0
    def finishInit(self):
        self.d = self.newDocument(isFirstNewDoc=True)
        os.environ['CADNANO_DISCARD_UNSAVED'] = 'True'  ## added by Nick
        if os.environ.get('CADNANO_DISCARD_UNSAVED',
                          False) and not self.ignoreEnv():
            self.sharedApp.dontAskAndJustDiscardUnsavedChanges = True
        if os.environ.get('CADNANO_DEFAULT_DOCUMENT',
                          False) and not self.ignoreEnv():
            self.sharedApp.shouldPerformBoilerplateStartupScript = True
        cadnano.loadAllPlugins()
        if "-i" in self.argv:
            print "Welcome to cadnano's debug mode!"
            print "Some handy locals:"
            print "\ta\tcadnano.app() (the shared cadnano application object)"
            print "\td()\tthe last created Document"

            def d():
                return self.d

            print "\tw()\tshortcut for d().controller().window()"

            def w():
                return self.d.controller().window()

            print "\tp()\tshortcut for d().selectedPart()"

            def p():
                return self.d.selectedPart()

            print "\tpi()\tthe PartItem displaying p()"

            def pi():
                return w().pathroot.partItemForPart(p())

            print "\tvh(i)\tshortcut for p().virtualHelix(i)"

            def vh(vhref):
                return p().virtualHelix(vhref)

            print "\tvhi(i)\tvirtualHelixItem displaying vh(i)"

            def vhi(vhref):
                partitem = pi()
                vHelix = vh(vhref)
                return partitem.vhItemForVH(vHelix)

            print "\tquit()\tquit (for when the menu fails)"
            print "\tgraphicsItm.findChild()  see help(pi().findChild)"
            interact('', local={'a':self, 'd':d, 'w':w,\
                                'p':p, 'pi':pi, 'vh':vh, 'vhi':vhi,\
                                })
Exemplo n.º 3
0
    def finishInit(self):
        self.d = self.newDocument(isFirstNewDoc=True)
        os.environ['CADNANO_DISCARD_UNSAVED'] = 'True' ## added by Nick 
        if os.environ.get('CADNANO_DISCARD_UNSAVED', False) and not self.ignoreEnv():
            self.sharedApp.dontAskAndJustDiscardUnsavedChanges = True
        if os.environ.get('CADNANO_DEFAULT_DOCUMENT', False) and not self.ignoreEnv():
            self.sharedApp.shouldPerformBoilerplateStartupScript = True
        cadnano.loadAllPlugins()
        if "-i" in self.argv:
            print "Welcome to cadnano's debug mode!"
            print "Some handy locals:"
            print "\ta\tcadnano.app() (the shared cadnano application object)"
            print "\td()\tthe last created Document"
            def d():
                return self.d

            print "\tw()\tshortcut for d().controller().window()"
            def w():
                return self.d.controller().window()

            print "\tp()\tshortcut for d().selectedPart()"
            def p():
                return self.d.selectedPart()

            print "\tpi()\tthe PartItem displaying p()"
            def pi():
                return w().pathroot.partItemForPart(p())

            print "\tvh(i)\tshortcut for p().virtualHelix(i)"
            def vh(vhref):
                return p().virtualHelix(vhref)

            print "\tvhi(i)\tvirtualHelixItem displaying vh(i)"
            def vhi(vhref):
                partitem = pi()
                vHelix = vh(vhref)
                return partitem.vhItemForVH(vHelix)
                
            print "\tquit()\tquit (for when the menu fails)"
            print "\tgraphicsItm.findChild()  see help(pi().findChild)"
            interact('', local={'a':self, 'd':d, 'w':w,\
                                'p':p, 'pi':pi, 'vh':vh, 'vhi':vhi,\
                                })
Exemplo n.º 4
0
    def addPluginAtPath(self, fname):
        self.fileopendialog.close()
        fname = str(fname[0])
        print "Attempting to open plugin %s" % fname
        try:
            zf = zipfile.ZipFile(fname, 'r')
        except Exception as e:
            self.failWithMsg("Plugin file seems corrupt: %s." % e)
            return
        tdir = tempfile.mkdtemp()
        try:
            for f in zf.namelist():
                if f.endswith('/'):
                    os.makedirs(os.path.join(tdir, f))
            for f in zf.namelist():
                if not f.endswith('/'):
                    zf.extract(f, tdir)
        except Exception as e:
            self.failWithMsg("Extraction of plugin archive failed: %s." % e)
            return
        filesInZip = [(f, os.path.join(tdir, f)) for f in os.listdir(tdir)]
        try:
            self.confirmDestructiveIfNecessary(filesInZip)
            self.removePluginsToBeOverwritten(filesInZip)
            self.movePluginsIntoPluginsFolder(filesInZip)
        except OSError:
            print "Couldn't copy files into plugin directory, attempting\
                   again after boosting privileges."

            if platform.system() == 'Darwin':
                self.darwinAuthedMvPluginsIntoPluginsFolder(filesInZip)
            elif platform.system() == 'Linux':
                self.linuxAuthedMvPluginsIntoPluginsFolder(filesInZip)
            else:
                print "Can't boost privelages on platform %s" % platform.system(
                )
        loadedAPlugin = cadnano.loadAllPlugins()
        if not loadedAPlugin:
            print "Unable to load anythng from plugin %s" % fname
        self.readPreferences()
        shutil.rmtree(tdir)
Exemplo n.º 5
0
 def addPluginAtPath(self, fname):
     self.fileopendialog.close()
     fname = str(fname[0])
     print "Attempting to open plugin %s"%fname
     try:
         zf = zipfile.ZipFile(fname, 'r')
     except Exception as e:
         self.failWithMsg("Plugin file seems corrupt: %s."%e)
         return
     tdir = tempfile.mkdtemp()
     try:
         for f in zf.namelist():
             if f.endswith('/'):
                 os.makedirs(os.path.join(tdir,f))
         for f in zf.namelist():
             if not f.endswith('/'):
                 zf.extract(f, tdir)
     except Exception as e:
         self.failWithMsg("Extraction of plugin archive failed: %s."%e)
         return
     filesInZip = [(f, os.path.join(tdir, f)) for f in os.listdir(tdir)]
     try:
         self.confirmDestructiveIfNecessary(filesInZip)
         self.removePluginsToBeOverwritten(filesInZip)
         self.movePluginsIntoPluginsFolder(filesInZip)
     except OSError:
         print "Couldn't copy files into plugin directory, attempting\
                again after boosting privileges."
         if platform.system() == 'Darwin':
             self.darwinAuthedMvPluginsIntoPluginsFolder(filesInZip)
         elif platform.system() == 'Linux':
             self.linuxAuthedMvPluginsIntoPluginsFolder(filesInZip)
         else:
             print "Can't boost privelages on platform %s"%platform.system()
     loadedAPlugin = cadnano.loadAllPlugins()
     if not loadedAPlugin:
         print "Unable to load anythng from plugin %s"%fname
     self.readPreferences()
     shutil.rmtree(tdir)