/
main.py
295 lines (236 loc) · 11.4 KB
/
main.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 28 22:15:51 2013
@author: clisle
"""
import os
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtDeclarative
global api
global newAlgorithmControlsDialogInstance
import dialogs
# add calls to manage files for Arbor
from QtArborFileManager import QtArborFileManager
# add calls to manage files for Arbor
from QtArborAlgorithmManager import QtArborAlgorithmManager
# global data structures to remember the projects, types, and instances
projectList = []
datatypelist = []
datasetList = []
class Form(QDialog):
# Define the main user interface
def __init__(self, parent=None):
super(Form, self).__init__(parent)
self.quitbutton = QPushButton("Quit")
self.title = QLabel("Arbor Project and File Manager")
self.title.setAlignment(Qt.AlignCenter)
#wf_manager = workflowManager.workflowManager()
self.horiz_splitter = QSplitter()
#put up a logo
pm = QPixmap("Arbor_128px.png")
self.arborLogo = QLabel()
self.arborLogo.setPixmap(pm);
# list window to show the projects currently stored
self.projectListWidget = QListWidget(self)
self.projectListWidget.setObjectName("projectListWidget")
# list window to show the type of data allowed in this project
self.datatypeListWidget = QListWidget(self)
self.datatypeListWidget.setObjectName("datatypeListWidget")
# list the instances of data in the database
self.datasetListWidget = QListWidget(self)
self.datasetListWidget.setObjectName("datasetListWidget")
# put the widgets together in the window but allow them to adjust
self.horiz_splitter.addWidget(self.arborLogo)
self.horiz_splitter.addWidget(self.projectListWidget)
self.horiz_splitter.addWidget(self.datatypeListWidget)
self.horiz_splitter.addWidget(self.datasetListWidget)
# add buttons
button_panel = QSplitter();
self.newProjectButton = QPushButton("New Project")
self.deleteProjectButton = QPushButton("Delete Selected\nProject")
self.deleteDatasetButton = QPushButton("Delete Selected\nDataset")
self.algorithmControlsButton = QPushButton("Run Algorithms on\nCurrent Project")
# add button tow 2
button_panel2 = QSplitter();
self.newTreeButton = QPushButton("Load Tree")
self.newTreeFromOpenTreeButton = QPushButton("Load from OTL")
self.newCharacterButton = QPushButton("Load Character\nMatrix")
self.newObservationsButton = QPushButton("Load Occurrences")
self.newSequencesButton = QPushButton("Load Sequences")
self.newWorkflowButton = QPushButton("Open Workflow\nDialog")
self.newWorkstepParametersButton = QPushButton("Adjust Workflow\n Parameters")
self.changeDatabaseButton = QPushButton("Change Database Info")
button_panel.addWidget(self.newProjectButton)
button_panel.addWidget(self.deleteProjectButton)
button_panel.addWidget(self.deleteDatasetButton)
button_panel.addWidget(self.algorithmControlsButton)
button_panel2.addWidget(self.newTreeButton)
button_panel2.addWidget(self.newTreeFromOpenTreeButton)
button_panel2.addWidget(self.newCharacterButton)
button_panel2.addWidget(self.newObservationsButton)
button_panel2.addWidget(self.newSequencesButton)
button_panel2.addWidget(self.newWorkflowButton)
button_panel2.addWidget(self.newWorkstepParametersButton)
button_panel2.addWidget(self.changeDatabaseButton)
# emit a single when a project is selected
#arbor_project_changed = pyqtSignal(string)
# Create layout and add widgets
layout = QVBoxLayout()
layout.addWidget(self.title)
layout.addWidget(self.horiz_splitter)
layout.addWidget(button_panel)
layout.addWidget(button_panel2)
layout.addWidget(self.quitbutton)
# Set dialog layout
self.setLayout(layout)
# Add button signal to greetings slot
#self.button.clicked.connect(self.greetings)
self.quitbutton.clicked.connect(self.quitprogram)
self.newProjectButton.clicked.connect(self.processNewProjectButton)
self.deleteProjectButton.clicked.connect(self.deleteSelectedProject)
self.deleteDatasetButton.clicked.connect(self.deleteSelectedDataset)
self.algorithmControlsButton.clicked.connect(self.processAlgorithmControlsButton)
self.newTreeButton.clicked.connect(self.processNewTreeButton)
self.newTreeFromOpenTreeButton.clicked.connect(self.processNewTreeFromOpenTreeButton)
self.newCharacterButton.clicked.connect(self.processNewCharacterButton)
self.newObservationsButton.clicked.connect(self.processNewObservationsButton)
self.newSequencesButton.clicked.connect(self.processNewSequencesButton)
self.newWorkflowButton.clicked.connect(self.processNewWorkflowButton)
self.newWorkstepParametersButton.clicked.connect(self.processNewWorkstepParametersButton)
self.changeDatabaseButton.clicked.connect(self.processDatabaseChangeButton)
# set callback so user clicking on a project displays project info
#self.projectListWidget.itemActivated.connect(self.clearTypesandDatasetLists)
self.projectListWidget.itemClicked.connect(self.selectProjectItem)
# show instances that match the selected datatype
self.datatypeListWidget.itemClicked.connect(self.selectDataTypeItem)
# Initialize the Geiger module under R
def greetings(self):
print ("Running Geiger Init...")
#geigerWrap.gw_InitGeiger()
print ("Finished Geiger Init...")
# Closeout any leftover processes and interfaces, then quit
def quitprogram(self):
print ("Safe Closeout...")
#geigerWrap.gw_ShutdownGeiger()
app.quit()
def processNewProjectButton(self):
dialogs.openNewProjectDialog()
self.updateProjectList()
def clearTypesandDatasetLists(self):
self.datasetListWidget.clear()
self.datatypeListWidget.clear()
# user selected a particular project, so display the types for this project
def selectProjectItem(self):
global newAlgorithmControlsDialogInstance
# test that there is actually something selected
if (self.projectListWidget.currentItem()):
# now display the types in this project
prname = str(self.projectListWidget.currentItem().text())
# TODO: do we need a test for a valid project here? (see selectDataTypeItem)
api.setCurrentProjectName(prname)
typeListForProject = api.getListOfTypesForProject(prname)
print "api returned types: ",typeListForProject
self.datatypeListWidget.clear()
self.datasetListWidget.clear()
for j in range(0,len(typeListForProject)):
self.datatypeListWidget.addItem(typeListForProject[j])
# tell the algorithm dialog what the current project is
dialogs.changeCurrentProject(prname);
# user clicked a datatype inside a project. we want to display all the
# instances of this datatype. If there is nothing selected, then don't fill the instance list
def selectDataTypeItem(self):
# test that there is actually something selected
if (self.datatypeListWidget.currentItem()):
typename = str(self.datatypeListWidget.currentItem().text())
# do nothing if no type is currently selected. The dataset list
# only needs to be updated if the user is currently observing some
# datasets
if len(typename)>0:
prname = api.getCurrentProjectName()
instancesForThisType = api.getListOfDatasetsByProjectAndType(prname,typename)
print "api returned types: ",instancesForThisType
self.datasetListWidget.clear()
for j in range(0,len(instancesForThisType)):
self.datasetListWidget.addItem(instancesForThisType[j])
# refresh the entire project list dialog with all the projects in the database
def updateProjectList(self):
global api
print "updateProjectList"
projectListFromMongo = api.getListOfProjectNames()
self.projectListWidget.clear()
self.datatypeListWidget.clear()
self.datasetListWidget.clear()
for i in range(0,len(projectListFromMongo)):
self.projectListWidget.addItem(projectListFromMongo[i])
# lookup the name from the list of projects and delete it. Use the
# index into the list widget to select the project to delete
def deleteSelectedProject(self):
global api
print "deleteProject"
currentName = str(self.projectListWidget.currentItem().text())
print "selected ",currentName," to delete"
projectListFromMongo = api.getListOfProjectNames()
if currentName in projectListFromMongo:
print "found name in project list"
api.deleteProjectNamed(currentName)
# this might be redundant because of the projectlistChanged signal
self.updateProjectList()
# delete a single dataset from a project
def deleteSelectedDataset(self):
global api
print "deleteDataset"
currentProjectName = str(self.projectListWidget.currentItem().text())
currentDatatypeName = str(self.datatypeListWidget.currentItem().text())
currentDatasetName = str(self.datasetListWidget.currentItem().text())
api.deleteDataset(currentProjectName,currentDatatypeName,currentDatasetName)
self.updateProjectList()
def processNewTreeButton(self):
dialogs.openNewTreeDialog()
def processNewTreeFromOpenTreeButton(self):
dialogs.openNewTreeOfLifeDialog()
def processNewCharacterButton(self):
dialogs.openNewCharacterDialog()
def processNewObservationsButton(self):
dialogs.openNewOccurrencesDialog()
def processNewSequencesButton(self):
dialogs.openNewSequenceDialog()
def processNewWorkflowButton(self):
dialogs.openNewWorkflowDialog()
def processNewWorkstepParametersButton(self):
dialogs.openWorkstepParametersDialog()
def processDatabaseChangeButton(self):
global api
dialogs.openDatabaseChangeDialog()
def refreshAfterDatabaseChange(self):
self.projectListWidget.clear()
self.clearTypesandDatasetLists()
self.updateProjectList()
def processAlgorithmControlsButton(self):
dialogs.openAlgorithmControlsDialog();
if __name__ == '__main__':
# Create the Qt Application
global app
app = QApplication(sys.argv)
# connect to database and initiaize the API
global api
api = QtArborFileManager()
api.initDatabaseConnection()
# initialize the installed algorithm API
global algorithms
algorithms = QtArborAlgorithmManager()
algorithms.setProjectManagerAPI(api)
algorithms.initAlgorithmLibrary()
# Create and show the form
form = Form()
# the window opens up really tiny without this, because QML size wasn't set
#form.setMinimumSize(800,600)
dialogs.initializeAllDialogs(api,algorithms)
api.projectListChangedSignal.connect(form.updateProjectList)
api.datasetListChangedSignal.connect(form.selectDataTypeItem)
api.datatypeListChangedSignal.connect(form.selectProjectItem)
form.updateProjectList()
form.show()
# Run the main Qt loop
app.exec_()