Ejemplo n.º 1
0
 def initGui(self):
     if self.guiInitialized:
         return
     self.guiInitialized = True
     from views.preferences import Preferences
     self.prefs = Preferences()
     argv = sys.argv
     qApp.setWindowIcon(QIcon('ui/mainwindow/images/cadnano2-app-icon.png'))
     self.undoGroup = QUndoGroup()
     self.documentControllers = set()  # Open documents
     self.activeDocument = None
     self.v = {}  # Newly created VirtualHelix register here by idnum.
     self.ph = {}
     self.phg = None
     self.d = self.newDocument(isFirstNewDoc=True)
     if "-i" in 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"
         print ("\tv\tmaps the numbers of recently created " +
               "VirtualHelixes to the VHs themselves")
         print "\tph\tmaps virtual helix numbers to pathhelix"
         print "\tphg()\tthe last initialized PathHelixGroup"
         print "\tpySide()\ttrue iff the app is using PySide"
         print "\tquit()\tquit (for when the menu fails)"
         interact('', local={'a': self,
                             'd': lambda: self.d,
                             'v': self.v,
                             'ph': self.ph,
                             'phg': lambda: self.phg,
                             'pySide': self.usesPySide})
Ejemplo n.º 2
0
 def __init__(self, argv):
     self.argv = argv
     if QCoreApplication.instance() == None:
         self.qApp = QApplication(argv)
         assert(QCoreApplication.instance() != None)
         self.qApp.setOrganizationDomain("cadnano.org")
     else:
         self.qApp = qApp
     super(CadnanoQt, self).__init__()
     from views.preferences import Preferences
     self.prefs = Preferences()
     self.qApp.setWindowIcon(QIcon('ui/mainwindow/images/cadnano2-app-icon.png'))
     self.documentControllers = set()  # Open documents
     self.activeDocument = None
     self.vh = {}  # Newly created VirtualHelix register here by idnum.
     self.vhi = {}
     self.partItem = None
     self.sharedApp = self
Ejemplo n.º 3
0
 def __init__(self, argv):
     self.argv = argv
     if QCoreApplication.instance() == None:
         self.qApp = QApplication(argv)
         assert(QCoreApplication.instance() != None)
         self.qApp.setOrganizationDomain("cadnano.org")
     else:
         self.qApp = qApp
     super(CadnanoQt, self).__init__()
     from views.preferences import Preferences
     self.prefs = Preferences()
     self.qApp.setWindowIcon(QIcon('ui/mainwindow/images/cadnano2-app-icon.png'))
     self.documentControllers = set()  # Open documents
     self.activeDocument = None
     self.vh = {}  # Newly created VirtualHelix register here by idnum.
     self.vhi = {}
     self.partItem = None
     self.sharedApp = self
Ejemplo n.º 4
0
class CadnanoQt(QObject):
    dontAskAndJustDiscardUnsavedChanges = False
    shouldPerformBoilerplateStartupScript = False
    documentWasCreatedSignal = pyqtSignal(object)  # doc
    documentWindowWasCreatedSignal = pyqtSignal(object, object)  # doc, window

    def __init__(self, argv):
        self.argv = argv
        if QCoreApplication.instance() == None:
            self.qApp = QApplication(argv)
            assert (QCoreApplication.instance() != None)
            self.qApp.setOrganizationDomain("cadnano.org")
        else:
            self.qApp = qApp
        super(CadnanoQt, self).__init__()
        from views.preferences import Preferences
        self.prefs = Preferences()
        self.qApp.setWindowIcon(
            QIcon('ui/mainwindow/images/cadnano2-app-icon.png'))
        self.documentControllers = set()  # Open documents
        self.activeDocument = None
        self.vh = {}  # Newly created VirtualHelix register here by idnum.
        self.vhi = {}
        self.partItem = None
        self.sharedApp = self

    def ignoreEnv(self):
        return os.environ.get('CADNANO_IGNORE_ENV_VARS_EXCEPT_FOR_ME', False)

    def finishInit(self):
        self.d = self.newDocument(isFirstNewDoc=True)
        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,\
                                })
        # else:
        #     self.exec_()

    def isInMaya(self):
        return QCoreApplication.instance().applicationName().contains(
            "Maya", Qt.CaseInsensitive)

    def isGui(self):
        return True

    def exec_(self):
        if hasattr(self, 'qApp'):
            self.mainEventLoop = QEventLoop()
            self.mainEventLoop.exec_()
            #self.qApp.exec_()

    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()

    def prefsClicked(self):
        self.prefs.showDialog()
Ejemplo n.º 5
0
class CADnano(QObject):
    sharedApp = None  # This class is a singleton.
    usesPySide = usesPySide     # This is bad that this can work
    dontAskAndJustDiscardUnsavedChanges = False
    shouldPerformBoilerplateStartupScript = False
    PySide_loaded = PySide_loaded

    def __init__(self):
        argv = saved_argv
        if QCoreApplication.instance() == None:
            self.qApp = QApplication(argv)
            assert(QCoreApplication.instance() != None)
            self.qApp.setOrganizationDomain("cadnano.org")
        super(CADnano, self).__init__()
        assert(not CADnano.sharedApp)
        CADnano.sharedApp = self
        self.guiInitialized = False

    def initGui(self):
        if self.guiInitialized:
            return
        self.guiInitialized = True
        from views.preferences import Preferences
        self.prefs = Preferences()
        argv = sys.argv
        qApp.setWindowIcon(QIcon('ui/mainwindow/images/cadnano2-app-icon.png'))
        self.undoGroup = QUndoGroup()
        self.documentControllers = set()  # Open documents
        self.activeDocument = None
        self.v = {}  # Newly created VirtualHelix register here by idnum.
        self.ph = {}
        self.phg = None
        self.d = self.newDocument(isFirstNewDoc=True)
        if "-i" in 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"
            print ("\tv\tmaps the numbers of recently created " +
                  "VirtualHelixes to the VHs themselves")
            print "\tph\tmaps virtual helix numbers to pathhelix"
            print "\tphg()\tthe last initialized PathHelixGroup"
            print "\tpySide()\ttrue iff the app is using PySide"
            print "\tquit()\tquit (for when the menu fails)"
            interact('', local={'a': self,
                                'd': lambda: self.d,
                                'v': self.v,
                                'ph': self.ph,
                                'phg': lambda: self.phg,
                                'pySide': self.usesPySide})

    def isInMaya(self):
        return QCoreApplication.instance().applicationName().contains(
                                                    "Maya", Qt.CaseInsensitive)

    def deleteAllMayaNodes(self):
        if not self.isInMaya():
            return
        import maya.cmds as cmds
        nodes = cmds.ls("DNAShapeTransform*", "DNAStrandShader*")
        for n in nodes:
            cmds.delete(n)
        for doc in self.documentControllers:
            if hasattr(doc, 'solidHelixGrp'):
                doc.solidHelixGrp.clearInternalDataStructures()

    def exec_(self):
        if hasattr(self, 'qApp'):
            self.qApp.exec_()

    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()

    def prefsClicked(self):
        self.prefs.showDialog()
Ejemplo n.º 6
0
class CadnanoQt(QObject):
    dontAskAndJustDiscardUnsavedChanges = False
    shouldPerformBoilerplateStartupScript = False
    documentWasCreatedSignal = pyqtSignal(object)  # doc
    documentWindowWasCreatedSignal = pyqtSignal(object, object)  # doc, window

    def __init__(self, argv):
        self.argv = argv
        if QCoreApplication.instance() == None:
            self.qApp = QApplication(argv)
            assert(QCoreApplication.instance() != None)
            self.qApp.setOrganizationDomain("cadnano.org")
        else:
            self.qApp = qApp
        super(CadnanoQt, self).__init__()
        from views.preferences import Preferences
        self.prefs = Preferences()
        self.qApp.setWindowIcon(QIcon('ui/mainwindow/images/cadnano2-app-icon.png'))
        self.documentControllers = set()  # Open documents
        self.activeDocument = None
        self.vh = {}  # Newly created VirtualHelix register here by idnum.
        self.vhi = {}
        self.partItem = None
        self.sharedApp = self
	
    
    def ignoreEnv(self):
        return os.environ.get('CADNANO_IGNORE_ENV_VARS_EXCEPT_FOR_ME', False)

    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,\
                                })
        # else:
        #     self.exec_()

    def isInMaya(self):
        return QCoreApplication.instance().applicationName().contains(
                                                    "Maya", Qt.CaseInsensitive)
    def isGui(self):
        return True
    
    def exec_(self):
        if hasattr(self, 'qApp'):
            self.mainEventLoop = QEventLoop()
            self.mainEventLoop.exec_()
            #self.qApp.exec_()

    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()

    def prefsClicked(self):
        self.prefs.showDialog()
Ejemplo n.º 7
0
class CadnanoQt(QObject):
    """
    This is the application base object, aka sharedApp or cadnano.app().
    This is NOT a QApplication, but the parent of self.qApp = QApplication.
    Additional prominent child objects of a CadnanoQt objects (self):
        self.documentControllers :  set of document controllers (will currently holds just one documentcontroller)

    """
    dontAskAndJustDiscardUnsavedChanges = False
    shouldPerformBoilerplateStartupScript = False
    documentWasCreatedSignal = pyqtSignal(object)  # doc
    documentWindowWasCreatedSignal = pyqtSignal(object, object)  # doc, window

    def __init__(self, argv):
        self.argv = argv
        if QCoreApplication.instance() == None:
            self.qApp = QApplication(argv)
            assert(QCoreApplication.instance() != None)
            self.qApp.setOrganizationDomain("cadnano.org")
        else:
            self.qApp = qApp
        super(CadnanoQt, self).__init__()
        from views.preferences import Preferences
        self.prefs = Preferences()
        self.qApp.setWindowIcon(QIcon('ui/mainwindow/images/cadnano2-app-icon.png'))
        self.documentControllers = set()  # Open documents
        self.activeDocument = None
        self.vh = {}  # Newly created VirtualHelix register here by idnum.
        self.vhi = {}
        self.partItem = None
        self.sharedApp = self

    def ignoreEnv(self):
        return os.environ.get('CADNANO_IGNORE_ENV_VARS_EXCEPT_FOR_ME', False)

    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..."

        # else:
        #     self.exec_()  # exec_() is invoked conditionally in main.py depending on command line arguments.

    def isInMaya(self):
        return QCoreApplication.instance().applicationName().contains(
                                                    "Maya", Qt.CaseInsensitive)
    def isGui(self):
        return True

    def exec_(self):
        """
        Starts main application loop. Invoked by the main.py bootstrapping script.
        # Notice: CadnanoQt is NOT a QtApplication, it is a QtObject. self.qApp is the application.
        """
        if hasattr(self, 'qApp'):
            #self.mainEventLoop = QEventLoop()
            #self.mainEventLoop.exec_() # Why this?
            self.qApp.exec_()           # This works better than the above mainEventLoop.exec_(), at least on linux.

    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()

    def prefsClicked(self):
        self.prefs.showDialog()