-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathfrmCreateVariable.py
More file actions
116 lines (89 loc) · 4.9 KB
/
Copy pathfrmCreateVariable.py
File metadata and controls
116 lines (89 loc) · 4.9 KB
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
"""Subclass of clsCreateVariable, which is generated by wxFormBuilder."""
import wx
from odmtools.view.clsCreateVariable import clsCreateVariable
from odmtools.odmdata import Variable
# Implementing clsCreateVariable
class frmCreateVariable(clsCreateVariable):
# Handlers for clsCreateVariable events.
def __init__(self, parent, service_man, old_var=None):
self.parent = parent
self.service_man = service_man
cv_service = self.service_man.get_cv_service()
self.series_service = self.service_man.get_series_service()
clsCreateVariable.__init__(self, parent)
self.variable= None
self.__init_boxes(old_var, cv_service)
def __init_boxes(self, old_var, cv_service):
# if old_var:
# name_list = [old_var.name]
# time_unit = [x.term for x in cv_service.get_units()]#[old_var.time_unit.name]
# var_unit = [old_var.variable_unit.name]
# sample_list = [old_var.sample_medium]
# spec_list = [old_var.speciation]
#else:
name_list = [x.term for x in cv_service.get_variable_name_cvs()]
var_unit=[x.name for x in cv_service.get_units_names()]
time_unit=[x.name for x in cv_service.get_units()]
gen_list = [x.term for x in cv_service.get_general_category_cvs()]
sample_list =[x.term for x in cv_service.get_sample_medium_cvs()]
spec_list =[x.term for x in cv_service.get_speciation_cvs()]
val_type =[x.term for x in cv_service.get_value_type_cvs()]
data_type =[x.term for x in cv_service.get_data_type_cvs()]
self.cbVarName.AppendItems(name_list)
self.cbVarUnits.AppendItems(var_unit)
self.cbTSUnits.AppendItems(time_unit)
self.cbSampleMedium.AppendItems(sample_list)
self.cbSpeciation.AppendItems(spec_list)
self.cbValueType.AppendItems(val_type)
self.cbDataType.AppendItems(data_type)
self.cbGenCat.AppendItems(gen_list)
if old_var:
self.cbVarName.SetValue(old_var.name)
self.cbVarUnits.SetValue(old_var.variable_unit.name)
self.cbTSUnits.SetValue(old_var.time_unit.name)
self.cbSampleMedium.SetValue(old_var.sample_medium)
self.cbSpeciation.SetValue(old_var.speciation)
self.cbValueType.SetValue(old_var.value_type)
self.cbDataType.SetValue(old_var.data_type)
self.txtNoDV.SetValue(str(old_var.no_data_value))
self.cbGenCat.SetValue(str(old_var.general_category))
self.txtTSValue.SetValue(str(old_var.time_support))
def getVariable(self):
return self.variable
def all_fields_full(self):
return (self.cbVarName.GetValue() is not None) and \
(self.txtVarCode.GetValue() != '') and \
(self.cbVarUnits.GetValue() is not None)and \
(self.cbTSUnits.GetValue() is not None) and \
(self.cbSampleMedium.GetValue() is not None) and \
(self.cbSpeciation.GetValue() is not None) and \
(self.cbValueType.GetValue() is not None) and \
(self.cbDataType.GetValue() is not None) and \
(self.txtNoDV.GetValue() != '') and \
(self.cbGenCat.GetValue() is not None) and \
(self.txtTSValue.GetValue() != '')
def OnBtnCreateButton(self, event):
self.variable = self.createVariable()
if self.all_fields_full():
self.EndModal(wx.ID_OK)
else:
wx.MessageDialog(None, "Variable was not created, A Value is missing", " ", wx.OK).ShowModal()
def createVariable(self):
v = Variable()
v.code = self.txtVarCode.GetValue() if self.txtVarCode.GetValue() != u'' else None
v.name = self.cbVarName.GetValue() if self.cbVarName.GetValue() != u'' else None
v.speciation = self.cbSpeciation.GetValue() if self.cbSpeciation.GetValue() != u'' else None
v.variable_unit = self.series_service.get_unit_by_name( self.cbVarUnits.GetValue())
v.variable_unit_id = v.variable_unit.id
v.sample_medium = self.cbSampleMedium.GetValue() if self.cbSampleMedium.GetValue() != u'' else None
v.value_type = self.cbValueType.GetValue() if self.cbValueType.GetValue() != u'' else None
v.is_regular = self.cbIsRegular.GetValue() if self.cbIsRegular.GetValue() != u'' else None
v.time_support = self.txtTSValue.GetValue() if self.txtTSValue.GetValue() != u'' else None
v.time_unit = self.series_service.get_unit_by_name(self.cbTSUnits.GetValue())
v.time_unit_id = v.time_unit.id
v.data_type = self.cbDataType.GetValue() if self.cbDataType.GetValue() != u'' else None
v.general_category = self.cbGenCat.GetValue() if self.cbGenCat.GetValue() != u'' else None
v.no_data_value = self.txtNoDV.GetValue() if self.txtNoDV.GetValue() != u'' else None
return v
def OnBtnCancelButton(self, event):
self.EndModal(wx.ID_CANCEL)