forked from douglaslab/cadnano2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcadnanoqt.py
executable file
·141 lines (123 loc) · 5.29 KB
/
cadnanoqt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
"""
cadnanoqt
Created by Jonathan deWerd on 2012-01-11.
"""
import util, sys, os
import cadnano
from code import interact
util.qtWrapImport('QtWidgets', globals(), ['qApp', 'QApplication', 'QUndoGroup'])
util.qtWrapImport('QtGui', globals(), ['QIcon'])
util.qtWrapImport('QtCore', globals(), ['QObject', 'QCoreApplication', 'Qt',
'QEventLoop', 'pyqtSignal'])
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 "Maya" in QCoreApplication.instance().applicationName()
def isGui(self):
return True
def destroyApp(self):
""" Destroy the QApplication.
Do not set `self.qApp = None` in this method.
Do it external to the CadnanoQt class
"""
global decodeFile
global Document
global DocumentController
# print("documentWasCreatedSignal", self.documentWasCreatedSignal)
# if self.documentControllers:
# self.documentWasCreatedSignal.disconnect(self.wirePrefsSlot)
decodeFile = None
Document = None
DocumentController = None
self.documentControllers.clear()
self.qApp.quit()
# end def
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()