Ejemplo n.º 1
0
 def newDocument(self, isFirstNewDoc=False, fp=None):
     """
     Creates a new document, ensuring that a document controller is also instantiated if required.
     If isFirstNewDoc is True, a new documentController is always instantiated.
     A new documentController will create a new document during __init__().
     This method is called by finishInit() to ensure a document is created on application init.
     """
     from controllers.documentcontroller import DocumentController
     defaultFile = fp or os.environ.get('CADNANO_DEFAULT_DOCUMENT', None)
     if defaultFile and isFirstNewDoc:
         defaultFile = path.expanduser(defaultFile)
         defaultFile = path.expandvars(defaultFile)
         dc = DocumentController()
         doc = dc.document()
         from model.io.decoder import decode
         decode(doc, file(defaultFile).read())
         print "Loaded default document: %s" % doc
     else:
         dc = next(iter(self.documentControllers), None)
         # cadnano currently only supports ONE documentcontroller per app instance, controlling exactly ONE document.
         if dc:                  # if a documentcontroller already exists
             dc.newDocument()    # currently, this just empties the existing document object.
         else: # first dc
             # A DocumentController creates a new doc during init and adds itself to app.documentControllers:
             dc = DocumentController()
     return dc.document()
Ejemplo n.º 2
0
 def newDocument(self, isFirstNewDoc=False):
     from controllers.documentcontroller import DocumentController
     defaultFile = environ.get('CADNANO_DEFAULT_DOCUMENT', None)
     if defaultFile and isFirstNewDoc:
         defaultFile = path.expanduser(defaultFile)
         defaultFile = path.expandvars(defaultFile)
         from model.decoder import decode
         doc = decode(file(defaultFile).read())
         print "Loaded default document: %s" % doc
         dc = DocumentController(doc, defaultFile)
     else:
         docCtrlrCount = len(self.documentControllers)
         if docCtrlrCount == 0:  # first dc
             # dc adds itself to app.documentControllers
             dc = DocumentController()
         elif docCtrlrCount == 1:  # dc already exists
             dc = list(self.documentControllers)[0]
             dc.newDocument()  # tell it to make a new doucment
     return dc.document()
Ejemplo n.º 3
0
 def newDocument(self, isFirstNewDoc=False):
     from controllers.documentcontroller import DocumentController
     defaultFile = os.environ.get('CADNANO_DEFAULT_DOCUMENT', None)
     if defaultFile and isFirstNewDoc:
         defaultFile = path.expanduser(defaultFile)
         defaultFile = path.expandvars(defaultFile)
         dc = DocumentController()
         doc = dc.document()
         from model.io.decoder import decode
         decode(doc, file(defaultFile).read())
         print "Loaded default document: %s" % doc
     else:
         docCtrlrCount = len(self.documentControllers)
         if docCtrlrCount == 0:  # first dc
             # dc adds itself to app.documentControllers
             dc = DocumentController()
         elif docCtrlrCount == 1:  # dc already exists
             dc = list(self.documentControllers)[0]
             dc.newDocument()  # tell it to make a new doucment
     return dc.document()