27 |
27 |
28 #------------------------------------------------------------------------------- |
28 #------------------------------------------------------------------------------- |
29 # Helpers |
29 # Helpers |
30 #------------------------------------------------------------------------------- |
30 #------------------------------------------------------------------------------- |
31 |
31 |
32 def GetDirChoiceOptions(): |
32 def GetDirFilterChoiceOptions(): |
33 _ = lambda x : x |
33 _ = lambda x : x |
34 return [(_("All"), [LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY]), |
34 return [(_("All"), [LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY]), |
35 (_("Input"), [LOCATION_VAR_INPUT]), |
35 (_("Input"), [LOCATION_VAR_INPUT]), |
36 (_("Output"), [LOCATION_VAR_OUTPUT]), |
36 (_("Output"), [LOCATION_VAR_OUTPUT]), |
37 (_("Memory"), [LOCATION_VAR_MEMORY])] |
37 (_("Memory"), [LOCATION_VAR_MEMORY])] |
38 DIRCHOICE_OPTIONS_FILTER = dict([(_(option), filter) for option, filter in GetDirChoiceOptions()]) |
38 DIRFILTERCHOICE_OPTIONS = dict([(_(option), filter) for option, filter in GetDirFilterChoiceOptions()]) |
|
39 |
|
40 def GetTypeFilterChoiceOptions(): |
|
41 _ = lambda x : x |
|
42 return [_("All"), |
|
43 _("Type and derivated"), |
|
44 _("Type strict")] |
39 |
45 |
40 # turn LOCATIONDATATYPES inside-out |
46 # turn LOCATIONDATATYPES inside-out |
41 LOCATION_SIZES = {} |
47 LOCATION_SIZES = {} |
42 for size, types in LOCATIONDATATYPES.iteritems(): |
48 for size, types in LOCATIONDATATYPES.iteritems(): |
43 for type in types: |
49 for type in types: |
47 # Browse Locations Dialog |
53 # Browse Locations Dialog |
48 #------------------------------------------------------------------------------- |
54 #------------------------------------------------------------------------------- |
49 |
55 |
50 class BrowseLocationsDialog(wx.Dialog): |
56 class BrowseLocationsDialog(wx.Dialog): |
51 |
57 |
52 def __init__(self, parent, var_type, locations): |
58 def __init__(self, parent, var_type, controller): |
53 wx.Dialog.__init__(self, parent, |
59 wx.Dialog.__init__(self, parent, |
54 size=wx.Size(600, 400), title=_('Browse Locations')) |
60 size=wx.Size(600, 400), title=_('Browse Locations'), |
|
61 style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER) |
55 |
62 |
56 main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10) |
63 main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10) |
57 main_sizer.AddGrowableCol(0) |
64 main_sizer.AddGrowableCol(0) |
58 main_sizer.AddGrowableRow(1) |
65 main_sizer.AddGrowableRow(1) |
59 |
66 |
66 self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnLocationsTreeItemActivated, |
73 self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnLocationsTreeItemActivated, |
67 self.LocationsTree) |
74 self.LocationsTree) |
68 main_sizer.AddWindow(self.LocationsTree, border=20, |
75 main_sizer.AddWindow(self.LocationsTree, border=20, |
69 flag=wx.LEFT|wx.RIGHT|wx.GROW) |
76 flag=wx.LEFT|wx.RIGHT|wx.GROW) |
70 |
77 |
71 button_gridsizer = wx.FlexGridSizer(cols=3, hgap=5, rows=1, vgap=0) |
78 button_gridsizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0) |
72 button_gridsizer.AddGrowableCol(2) |
79 button_gridsizer.AddGrowableCol(1) |
|
80 button_gridsizer.AddGrowableCol(3) |
73 button_gridsizer.AddGrowableRow(0) |
81 button_gridsizer.AddGrowableRow(0) |
74 main_sizer.AddSizer(button_gridsizer, border=20, |
82 main_sizer.AddSizer(button_gridsizer, border=20, |
75 flag=wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.GROW) |
83 flag=wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.GROW) |
76 |
84 |
77 direction_label = wx.StaticText(self, label=_('Direction:')) |
85 direction_label = wx.StaticText(self, label=_('Direction:')) |
78 button_gridsizer.AddWindow(direction_label, |
86 button_gridsizer.AddWindow(direction_label, |
79 flag=wx.ALIGN_CENTER_VERTICAL) |
87 flag=wx.ALIGN_CENTER_VERTICAL) |
80 |
88 |
81 self.DirChoice = wx.ComboBox(self, style=wx.CB_READONLY) |
89 self.DirFilterChoice = wx.ComboBox(self, size=wx.Size(0, -1), style=wx.CB_READONLY) |
82 self.Bind(wx.EVT_COMBOBOX, self.OnDirChoice, self.DirChoice) |
90 self.Bind(wx.EVT_COMBOBOX, self.OnFilterChoice, self.DirFilterChoice) |
83 button_gridsizer.AddWindow(self.DirChoice, |
91 button_gridsizer.AddWindow(self.DirFilterChoice, |
|
92 flag=wx.GROW|wx.ALIGN_CENTER_VERTICAL) |
|
93 |
|
94 filter_label = wx.StaticText(self, label=_('Type:')) |
|
95 button_gridsizer.AddWindow(filter_label, |
84 flag=wx.ALIGN_CENTER_VERTICAL) |
96 flag=wx.ALIGN_CENTER_VERTICAL) |
|
97 |
|
98 self.TypeFilterChoice = wx.ComboBox(self, size=wx.Size(0, -1), style=wx.CB_READONLY) |
|
99 self.Bind(wx.EVT_COMBOBOX, self.OnFilterChoice, self.TypeFilterChoice) |
|
100 button_gridsizer.AddWindow(self.TypeFilterChoice, |
|
101 flag=wx.GROW|wx.ALIGN_CENTER_VERTICAL) |
85 |
102 |
86 button_sizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) |
103 button_sizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) |
87 self.Bind(wx.EVT_BUTTON, self.OnOK, button_sizer.GetAffirmativeButton()) |
104 self.Bind(wx.EVT_BUTTON, self.OnOK, button_sizer.GetAffirmativeButton()) |
88 button_gridsizer.AddWindow(button_sizer, flag=wx.ALIGN_RIGHT) |
105 button_gridsizer.AddSizer(button_sizer, flag=wx.ALIGN_RIGHT) |
89 |
106 |
90 self.SetSizer(main_sizer) |
107 self.SetSizer(main_sizer) |
91 |
108 |
|
109 self.Controller = controller |
92 self.VarType = var_type |
110 self.VarType = var_type |
93 self.Locations = locations |
111 self.BaseVarType = self.Controller.GetBaseType(self.VarType) |
|
112 self.VarTypeSize = LOCATION_SIZES[self.BaseVarType] |
|
113 self.Locations = self.Controller.GetVariableLocationTree() |
94 |
114 |
95 # Define Tree item icon list |
115 # Define Tree item icon list |
96 self.TreeImageList = wx.ImageList(16, 16) |
116 self.TreeImageList = wx.ImageList(16, 16) |
97 self.TreeImageDict = {} |
117 self.TreeImageDict = {} |
98 |
118 |
108 |
128 |
109 # Assign icon list to TreeCtrls |
129 # Assign icon list to TreeCtrls |
110 self.LocationsTree.SetImageList(self.TreeImageList) |
130 self.LocationsTree.SetImageList(self.TreeImageList) |
111 |
131 |
112 # Set a options for the choice |
132 # Set a options for the choice |
113 for option, filter in GetDirChoiceOptions(): |
133 for option, filter in GetDirFilterChoiceOptions(): |
114 self.DirChoice.Append(_(option)) |
134 self.DirFilterChoice.Append(_(option)) |
115 self.DirChoice.SetStringSelection(_("All")) |
135 self.DirFilterChoice.SetStringSelection(_("All")) |
116 self.RefreshFilter() |
136 for option in GetTypeFilterChoiceOptions(): |
|
137 self.TypeFilterChoice.Append(_(option)) |
|
138 self.TypeFilterChoice.SetStringSelection(_("All")) |
|
139 self.RefreshFilters() |
117 |
140 |
118 self.RefreshLocationsTree() |
141 self.RefreshLocationsTree() |
119 |
142 |
120 def RefreshFilter(self): |
143 def RefreshFilters(self): |
121 self.Filter = DIRCHOICE_OPTIONS_FILTER[self.DirChoice.GetStringSelection()] |
144 self.DirFilter = DIRFILTERCHOICE_OPTIONS[self.DirFilterChoice.GetStringSelection()] |
|
145 self.TypeFilter = self.TypeFilterChoice.GetSelection() |
122 |
146 |
123 def RefreshLocationsTree(self): |
147 def RefreshLocationsTree(self): |
124 root = self.LocationsTree.GetRootItem() |
148 root = self.LocationsTree.GetRootItem() |
125 if not root.IsOk(): |
149 if not root.IsOk(): |
126 root = self.LocationsTree.AddRoot("") |
150 root = self.LocationsTree.AddRoot("") |
127 self.GenerateLocationsTreeBranch(root, self.Locations) |
151 self.GenerateLocationsTreeBranch(root, self.Locations) |
|
152 |
|
153 def FilterType(self, location_type, location_size): |
|
154 if self.TypeFilter == 0: |
|
155 return True |
|
156 |
|
157 if location_size != self.VarTypeSize: |
|
158 return False |
|
159 |
|
160 if self.TypeFilter == 1: |
|
161 return self.Controller.IsOfType(location_type, self.BaseVarType) |
|
162 elif self.TypeFilter == 2: |
|
163 return location_type == self.VarType |
|
164 |
|
165 return True |
128 |
166 |
129 def GenerateLocationsTreeBranch(self, root, locations): |
167 def GenerateLocationsTreeBranch(self, root, locations): |
130 to_delete = [] |
168 to_delete = [] |
131 item, root_cookie = self.LocationsTree.GetFirstChild(root) |
169 item, root_cookie = self.LocationsTree.GetFirstChild(root) |
132 for loc_infos in locations: |
170 for loc_infos in locations: |
133 infos = loc_infos.copy() |
171 infos = loc_infos.copy() |
134 if infos["type"] in [LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP] or\ |
172 if infos["type"] in [LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP] or\ |
135 infos["type"] in self.Filter and (infos["IEC_type"] == self.VarType or |
173 infos["type"] in self.DirFilter and self.FilterType(infos["IEC_type"], infos["size"]): |
136 infos["IEC_type"] is None and LOCATION_SIZES[self.VarType] == infos["size"]): |
|
137 children = [child for child in infos.pop("children")] |
174 children = [child for child in infos.pop("children")] |
138 if not item.IsOk(): |
175 if not item.IsOk(): |
139 item = self.LocationsTree.AppendItem(root, infos["name"]) |
176 item = self.LocationsTree.AppendItem(root, infos["name"]) |
140 if wx.Platform != '__WXMSW__': |
177 if wx.Platform != '__WXMSW__': |
141 item, root_cookie = self.LocationsTree.GetNextChild(root, root_cookie) |
178 item, root_cookie = self.LocationsTree.GetNextChild(root, root_cookie) |
155 infos = self.LocationsTree.GetPyData(event.GetItem()) |
192 infos = self.LocationsTree.GetPyData(event.GetItem()) |
156 if infos["type"] not in [LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP]: |
193 if infos["type"] not in [LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP]: |
157 wx.CallAfter(self.EndModal, wx.ID_OK) |
194 wx.CallAfter(self.EndModal, wx.ID_OK) |
158 event.Skip() |
195 event.Skip() |
159 |
196 |
160 def OnDirChoice(self, event): |
197 def OnFilterChoice(self, event): |
161 self.RefreshFilter() |
198 self.RefreshFilters() |
162 self.RefreshLocationsTree() |
199 self.RefreshLocationsTree() |
163 |
200 |
164 def GetValues(self): |
201 def GetValues(self): |
165 selected = self.LocationsTree.GetSelection() |
202 selected = self.LocationsTree.GetSelection() |
166 return self.LocationsTree.GetPyData(selected) |
203 return self.LocationsTree.GetPyData(selected) |
167 |
204 |
168 def OnOK(self, event): |
205 def OnOK(self, event): |