Skip to content

Commit be164d2

Browse files
author
stephanie
committed
merge in changes from use_api:
2 parents 9258008 + b1afe95 commit be164d2

31 files changed

+1603
-892
lines changed

odmtools/controller/NewFlagValuesController.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
import wx
22
from odmtools.view.NewFlagValuesView import NewFlagValuesView
3+
import odmtools.controller.olvAddPoint
34

45

56
class NewFlagValuesController(NewFlagValuesView):
67
def __init__(self, parent, series_service, qualifier_choice, record_service):
78

89
NewFlagValuesView.__init__(self, parent)
10+
self.parent = parent
911
self.series_service = series_service
1012
self.qualifer_choice = qualifier_choice
1113
self.record_service = record_service
1214
self.__new_annotation = "New Annontation"
1315

14-
annotations = self.series_service.get_all_annotations()
15-
self.append_items_to_annotation(annotations)
16-
self.annotation_combo.SetSelection(0)
16+
if self.qualifer_choice:
17+
annotations = self.series_service.get_all_annotations()
18+
self.append_items_to_annotation(annotations)
19+
1720
self.annotation_combo.Append(self.__new_annotation)
21+
self.annotation_combo.SetSelection(0)
1822

1923
self.cancel_button.Bind(wx.EVT_BUTTON, self.on_cancel)
2024
self.Bind(wx.EVT_CLOSE, self.on_cancel)
@@ -32,7 +36,9 @@ def append_items_to_annotation(self, annotations):
3236
def on_cancel(self, event):
3337
self.MakeModal(False)
3438
self.Destroy()
35-
event.Skip()
39+
40+
if event:
41+
event.Skip()
3642

3743
def on_ok(self, event):
3844
selection = self.annotation_combo.GetValue()
@@ -46,6 +52,9 @@ def on_ok(self, event):
4652
annotation = self.series_service.get_annotation_by_code(code)
4753
self.record_service.flag(annotation.AnnotationID)
4854

55+
if isinstance(self.parent, odmtools.controller.olvAddPoint.OLVAddPoint):
56+
self.parent.refresh_annotations()
57+
4958
self.on_cancel(event)
5059

5160
if __name__ == '__main__':

odmtools/controller/WizardActionController.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import wx
22
from odmtools.view.WizardActionView import WizardActionView
33
from wx.wizard import WizardPageSimple
4+
from odm2api.ODM2.models import Affiliations
45

56

7+
# Should we rename this to Affiliations instead of actions? Action is created else where
68
class WizardActionController(WizardPageSimple):
79
def __init__(self, parent, affiliations):
810
WizardPageSimple.__init__(self, parent)
@@ -16,6 +18,34 @@ def __init__(self, parent, affiliations):
1618
if self.affiliations is None:
1719
return
1820
# Populate table with the affiliations
21+
self.populate_affiliations_table()
22+
23+
def populate_affiliations_table(self):
24+
"""
25+
self.affiliations must be a list affiliations
26+
:return:
27+
"""
28+
if not isinstance(self.affiliations, list):
29+
return
30+
if not len(self.affiliations) and not isinstance(self.affiliations[0], Affiliations):
31+
return
32+
33+
data = []
34+
for affiliation in self.affiliations:
35+
data.append([
36+
affiliation.PersonObj.PersonFirstName + " " + affiliation.PersonObj.PersonLastName,
37+
affiliation.OrganizationObj.OrganizationName
38+
])
39+
40+
columns = ["Person", "Organization"]
41+
self.action_view.affiliations_table.set_columns(columns)
42+
self.action_view.affiliations_table.set_table_content(data)
43+
44+
def get_affiliation(self):
45+
index = self.action_view.affiliations_table.GetFirstSelected()
46+
return self.affiliations[index]
47+
48+
1949

2050

2151
if __name__ == '__main__':

odmtools/controller/WizardMethodController.py

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55

66

77
class WizardMethodController(WizardPageSimple):
8-
def __init__(self, parent, series_service):
8+
def __init__(self, parent, series_service, current_method=None):
99
WizardPageSimple.__init__(self, parent)
1010

1111
main_sizer = wx.BoxSizer(wx.VERTICAL)
12+
1213
self.method_view = WizardMethodView(self)
1314
main_sizer.Add(self.method_view, 1, wx.EXPAND | wx.RIGHT, -16) # Sufficient to hide the scroll bar
1415
self.SetSizer(main_sizer)
@@ -17,24 +18,40 @@ def __init__(self, parent, series_service):
1718
table_columns = ["ID", "Descriptions", "Link", "Code", "Type"]
1819
self.cv_types = []
1920
self.method_view.existing_method_table.set_columns(table_columns)
21+
2022
self.on_auto_radio(None)
2123

24+
self.all_methods = []
25+
self.current_method_in_series = current_method # Not the same as the selected method in the table
26+
self.__populate_table()
27+
self.select_current_method()
28+
self.method_view.method_type_combo.AppendItems(self.cv_types)
29+
self.on_existing_method_radio(None)
30+
2231
self.method_view.auto_method_radio.Bind(wx.EVT_RADIOBUTTON, self.on_auto_radio)
2332
self.method_view.existing_method_radio.Bind(wx.EVT_RADIOBUTTON, self.on_existing_method_radio)
2433
self.method_view.create_method_radio.Bind(wx.EVT_RADIOBUTTON, self.on_create_method_radio)
2534

26-
self.__fetch_data()
27-
self.method_view.method_type_combo.AppendItems(self.cv_types)
35+
def select_current_method(self):
36+
if self.current_method_in_series is None:
37+
return
38+
39+
if self.current_method_in_series not in self.all_methods:
40+
return # the current method is not in the table
41+
42+
index = self.all_methods.index(self.current_method_in_series)
43+
self.method_view.existing_method_table.Select(index)
2844

2945
def on_auto_radio(self, event):
30-
self.method_view.existing_method_table.Enable(False)
31-
self.__set_create_method_section_(False)
46+
self.method_view.existing_method_table.Disable()
47+
self.enable_create_method_section(False)
3248

3349
def on_existing_method_radio(self, event):
3450
self.method_view.existing_method_table.Enable()
35-
self.__set_create_method_section_(False)
51+
self.enable_create_method_section(False)
52+
self.method_view.existing_method_table.SetFocus()
3653

37-
def __set_create_method_section_(self, active):
54+
def enable_create_method_section(self, active):
3855
if not isinstance(active, bool):
3956
raise Exception("active must be type bool")
4057

@@ -47,12 +64,12 @@ def __set_create_method_section_(self, active):
4764

4865
def on_create_method_radio(self, event):
4966
self.method_view.existing_method_table.Disable()
50-
self.__set_create_method_section_(True)
67+
self.enable_create_method_section(True)
5168

52-
def __fetch_data(self):
53-
methods = self.series_service.get_all_methods()
69+
def __populate_table(self):
70+
self.all_methods = self.series_service.get_all_methods()
5471
data = []
55-
for meth in methods:
72+
for meth in self.all_methods:
5673
data.append([
5774
meth.MethodID, meth.MethodDescription,
5875
meth.MethodLink, meth.MethodCode,
@@ -64,7 +81,7 @@ def __fetch_data(self):
6481

6582
self.method_view.existing_method_table.set_table_content(data=data)
6683

67-
def getMethod(self):
84+
def get_method(self):
6885
if self.method_view.auto_method_radio.GetValue():
6986
return self.__auto_generate_a_method()
7087

@@ -87,14 +104,7 @@ def __auto_generate_a_method(self):
87104

88105
def __select_existing_method(self):
89106
index = self.method_view.existing_method_table.GetFirstSelected()
90-
desc = self.method_view.existing_method_table.GetItem(index, 1).GetText()
91-
link = self.method_view.existing_method_table.GetItem(index, 2).GetText()
92-
code = self.method_view.existing_method_table.GetItem(index, 3).GetText()
93-
94-
method = self.series_service.get_method_by_code(method_code=code)
95-
method.MethodLink = link
96-
method.MethodDescription = desc
97-
return method
107+
return self.all_methods[index]
98108

99109
def __create_new_method(self):
100110
code = self.method_view.method_code_text_ctrl.GetValue()

odmtools/controller/WizardProcessLevelController.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
class WizardProcessLevelController(WizardPageSimple):
8-
def __init__(self, parent, service_manager):
8+
def __init__(self, parent, service_manager, current_processing_level=None):
99
WizardPageSimple.__init__(self, parent)
1010

1111
self.service_manager = service_manager
@@ -14,20 +14,37 @@ def __init__(self, parent, service_manager):
1414
main_sizer.Add(self.processing_level_view, 1, wx.EXPAND | wx.RIGHT, -16)
1515
self.SetSizer(main_sizer)
1616

17+
self.all_processing_level = []
1718
table_columns = ["Code", "Definition", "Explanation", "ID"]
1819
self.processing_level_view.existing_process_table.set_columns(table_columns)
20+
self.current_processing_level = current_processing_level
1921
self.__fetch_data()
22+
self.select_current_processing_level()
2023

2124
self.processing_level_view.create_process_level_radio.Bind(wx.EVT_RADIOBUTTON, self.on_create_radio)
2225
self.processing_level_view.existing_process_radio.Bind(wx.EVT_RADIOBUTTON, self.on_existing_radio)
2326

27+
def select_current_processing_level(self):
28+
if self.current_processing_level is None:
29+
return
30+
31+
index = -1
32+
for i in range(len(self.all_processing_level)):
33+
if self.all_processing_level[i].ProcessingLevelID == self.current_processing_level.ProcessingLevelID:
34+
index = i
35+
break
36+
37+
if index >= 0:
38+
self.processing_level_view.existing_process_table.Select(index)
39+
2440
def on_create_radio(self, event):
2541
self.processing_level_view.existing_process_table.Enable(False)
2642
self.__set_create_proces_section(True)
2743

2844
def on_existing_radio(self, event):
2945
self.processing_level_view.existing_process_table.Enable(True)
3046
self.__set_create_proces_section(False)
47+
self.processing_level_view.existing_process_table.SetFocus()
3148

3249
def __set_create_proces_section(self, active):
3350
if not isinstance(active, bool):
@@ -39,10 +56,10 @@ def __set_create_proces_section(self, active):
3956

4057
def __fetch_data(self):
4158
series_service = self.service_manager.get_series_service()
42-
processes = series_service.get_all_processing_levels()
59+
self.all_processing_level = series_service.get_all_processing_levels()
4360

4461
data = []
45-
for proc in processes:
62+
for proc in self.all_processing_level:
4663
data.append([
4764
proc.ProcessingLevelCode,
4865
proc.Definition,
@@ -54,18 +71,16 @@ def __fetch_data(self):
5471

5572
def get_processing_level(self):
5673
if self.processing_level_view.create_process_level_radio.GetValue():
57-
return self.__select_existing_processing_level()
74+
return self.__create_processing_level()
5875

5976
if self.processing_level_view.existing_process_radio.GetValue():
6077
return self.__select_existing_processing_level()
6178

6279
return None
6380

6481
def __select_existing_processing_level(self):
65-
selected_row = self.processing_level_view.existing_process_table.get_selected_row()
66-
code = selected_row[0]
67-
proc_level = self.service_manager.get_series_service().get_processing_level_by_code(codes=code)
68-
return proc_level
82+
index = self.processing_level_view.existing_process_table.GetFirstSelected()
83+
return self.all_processing_level[index]
6984

7085
def __create_processing_level(self):
7186
code = self.processing_level_view.level_code_text_ctrl.GetValue()

odmtools/controller/WizardVariableController.py

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ def __init__(self, parent, service_manager, current_variable):
1010

1111
self.service_manager = service_manager
1212
self.current_variable = current_variable
13+
self.all_variables = []
14+
1315
main_sizer = wx.BoxSizer(wx.VERTICAL)
1416
self.variable_view = WizardVariableView(self)
1517
main_sizer.Add(self.variable_view, 1, wx.EXPAND | wx.RIGHT, -16)
@@ -20,23 +22,48 @@ def __init__(self, parent, service_manager, current_variable):
2022
self.on_current_radio(None)
2123

2224
self.__fetch_data()
25+
self.select_current_variable()
26+
2327
self.variable_view.current_variable_radio.Bind(wx.EVT_RADIOBUTTON, self.on_current_radio)
2428
self.variable_view.existing_variable_radio.Bind(wx.EVT_RADIOBUTTON, self.on_existing_radio)
2529
self.variable_view.create_variable_radio.Bind(wx.EVT_RADIOBUTTON, self.on_create_radio)
2630

31+
def select_current_variable(self):
32+
if self.current_variable is None:
33+
return
34+
35+
index = -1
36+
for i in range(len(self.all_variables)):
37+
if self.all_variables[i].VariableID == self.current_variable.VariableID:
38+
index = i
39+
break
40+
41+
if index >= 0:
42+
self.variable_view.variable_table.Select(index)
43+
2744
def on_current_radio(self, event):
2845
self.variable_view.variable_table.Enable(False)
29-
self.__set_create_variable_section(False)
46+
self.__enable_create_variable_section(False)
47+
48+
if event:
49+
event.Skip()
3050

3151
def on_create_radio(self, event):
3252
self.variable_view.variable_table.Enable(False)
33-
self.__set_create_variable_section(True)
53+
self.__enable_create_variable_section(True)
54+
55+
if event:
56+
event.Skip()
3457

3558
def on_existing_radio(self, event):
3659
self.variable_view.variable_table.Enable(True)
37-
self.__set_create_variable_section(False)
60+
self.__enable_create_variable_section(False)
61+
self.variable_view.variable_table.SetFocus()
62+
63+
if event:
64+
event.Skip()
3865

39-
def __set_create_variable_section(self, active):
66+
def __enable_create_variable_section(self, active):
4067
if not isinstance(active, bool):
4168
raise Exception("active must be type bool")
4269

@@ -61,9 +88,9 @@ def __fetch_data(self):
6188

6289
def __populate_variable_table(self):
6390
series_serivce = self.service_manager.get_series_service()
64-
variables = series_serivce.get_all_variables()
91+
self.all_variables = series_serivce.get_all_variables()
6592
data = []
66-
for var in variables:
93+
for var in self.all_variables:
6794
data.append([var.VariableCode,
6895
var.VariableNameCV,
6996
var.SpeciationCV,
@@ -74,27 +101,28 @@ def __populate_variable_table(self):
74101
self.variable_view.variable_table.set_table_content(data=data)
75102

76103
def get_variable(self):
77-
v = Variable()
78104
if self.variable_view.current_variable_radio.GetValue():
79-
v = self.current_variable
80-
elif self.variable_view.existing_variable_radio.GetValue():
81-
row = self.variable_view.variable_table.get_selected_row()
82-
code = row[0]
83-
v = self.service_manager.get_series_service().get_variable_by_code(code)
105+
return self.current_variable
84106

85-
elif self.variable_view.create_variable_radio.GetValue():
86-
return self.get_new_variable()
107+
if self.variable_view.existing_variable_radio.GetValue():
108+
return self.__select_existing_variable()
87109

88-
return v
110+
if self.variable_view.create_variable_radio.GetValue():
111+
return self.__create_new_variable()
112+
113+
return None
114+
115+
def __select_existing_variable(self):
116+
index = self.variable_view.variable_table.GetFirstSelected()
117+
return self.all_variables[index]
89118

90-
def get_new_variable(self):
119+
def __create_new_variable(self):
91120
v = Variable()
92121
v.code = self.variable_view.variable_code_text_ctrl.GetValue() if self.variable_view.variable_code_text_ctrl.GetValue() <> "" else None
93122
v.name = self.variable_view.variable_name_combo.GetValue() if self.variable_view.variable_name_combo.GetValue() <> "" else None
94123
v.speciation = self.variable_view.speciation_combo.GetValue() if self.variable_view.speciation_combo.GetValue() <> "" else None
95124
v.variable_unit = self.service_manager.get_series_service()
96125
v.no_data_value = self.variable_view.no_data_value_text_ctrl.GetValue() if self.variable_view.no_data_value_text_ctrl.GetValue() <> "" else None
97-
# Need unit name, time support but neither of them are in the form...
98126

99127
return v
100128

0 commit comments

Comments
 (0)