-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdynamic_wizard.py
119 lines (94 loc) · 4.58 KB
/
dynamic_wizard.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
################################################################################
#
# George Dietz
# CEBM@Brown
#
# My policy for the wizards is that they should know nothing about the various
# selections that are made on the pages (store nothing internally)
# rather the selections are stored in the pages themselves and are retrieved
# with accessor functions through the wizard
#
################################################################################
from PyQt4 import QtCore, QtGui
from PyQt4.Qt import *
from ome_globals import *
#import python_to_R
from common_wizard_pages.choose_effect_size_page import ChooseEffectSizePage
from common_wizard_pages.data_location_page import DataLocationPage
from common_wizard_pages.refine_studies_page import RefineStudiesPage
from common_wizard_pages.methods_and_parameters_page import MethodsAndParametersPage
from common_wizard_pages.summary_page import SummaryPage
#from common_wizard_pages.failsafe_page import FailsafeWizardPage
#from common_wizard_pages.funnel_page import FunnelPage
(Page_ChooseEffectSize, Page_DataLocation, Page_RefineStudies,
Page_MethodsAndParameters, Page_Summary, Page_Failsafe,
Page_FunnelParameters) = range(7)
# map page keys (from R) to wizard page ids
pageid = {
'DATALOCATION': Page_DataLocation,
'REFINESTUDIES': Page_RefineStudies,
'SUMMARY': Page_Summary
}
class DynamicWizard(QtGui.QWizard):
def __init__(self, model, wizard_parameters, parent=None):
super(DynamicWizard, self).__init__(parent)
self.model = model
self.wizard_parameters = wizard_parameters
self.setWindowTitle(self.wizard_parameters['WIZARD.WINDOW.TITLE'])
self.setWizardStyle(QWizard.ClassicStyle)
self._create_wizard_pages()
QObject.connect(self, SIGNAL("currentIdChanged(int)"), self._change_size)
def _change_size(self, pageid):
print("changing size")
self.adjustSize()
def _create_wizard_pages(self):
'''
Initialize wizard pages specified by wizard parameters
'''
print "wizard parameters: %s" % str(self.wizard_parameters)
for page_key, page_parameters in self.wizard_parameters['WIZARD.PAGES'].items():
page_arguments = {}
print "page key: %s, page parameters: %s" % (page_key, str(page_parameters))
if page_key == 'DATALOCATION':
if 'SHOW.RAW.DATA' in page_parameters:
page_arguments['show_raw_data'] = page_parameters['SHOW.RAW.DATA']
print "Page arguments: %s" % str(page_arguments)
self.data_location_page = DataLocationPage(model=self.model, **page_arguments)
self.setPage(Page_DataLocation, self.data_location_page)
elif page_key == 'REFINESTUDIES':
self.refine_studies_page = RefineStudiesPage(model=self.model)
self.setPage(Page_RefineStudies, self.refine_studies_page)
elif page_key == 'SUMMARY':
self.summary_page = SummaryPage()
self.setPage(Page_Summary, self.summary_page)
def nextId(self):
page_id = self.currentId()
return self.next_id_helper(page_id)
def next_id_helper(self, page_id):
pages = self.wizard_parameters['WIZARD.PAGES'].keys() # pages in order
pageids = [pageid[pagekey] for pagekey in pages]
currentpageindex = pageids.index(page_id)
if currentpageindex == len(pageids) - 1:
# End wizard if on last page
return -1
# go to next page
return pageids[currentpageindex+1]
#### Getters
# Data location
def get_data_location(self):
return self.data_location_page.get_data_locations()
# Refine Studies page
def get_included_studies_in_proper_order(self):
all_studies = self.model.get_studies_in_current_order()
included_studies = self.refine_studies_page.get_included_studies()
included_studies_in_order = [study for study in all_studies if study in included_studies]
return included_studies_in_order
# Summary Page
def get_summary(self):
''' Make a summary string to show the user at the end of the wizard summarizing most of the user selections '''
return wizard_summary(wizard=self, next_id_helper=self.next_id_helper,
summary_page_id=Page_Summary,
analysis_label="Failsafe Analysis")
def save_selections(self): # returns a bool
# Should the selections be saved?
return self.summary_page.save_selections()