27 from functools import reduce |
27 from functools import reduce |
28 |
28 |
29 import wx |
29 import wx |
30 import wx.lib.buttons |
30 import wx.lib.buttons |
31 import wx.lib.agw.customtreectrl as CT |
31 import wx.lib.agw.customtreectrl as CT |
|
32 from pprint import pprint |
32 |
33 |
33 from PLCControler import * |
34 from PLCControler import * |
34 from util.BitmapLibrary import GetBitmap |
35 from util.BitmapLibrary import GetBitmap |
35 from plcopen.types_enums import GetElementType |
36 from plcopen.types_enums import GetElementType |
36 |
37 |
128 ("CONFIGURATION", ITEM_CONFIGURATION), |
129 ("CONFIGURATION", ITEM_CONFIGURATION), |
129 ("RESOURCE", ITEM_RESOURCE), |
130 ("RESOURCE", ITEM_RESOURCE), |
130 ("DATATYPE", ITEM_DATATYPE), |
131 ("DATATYPE", ITEM_DATATYPE), |
131 ("ACTION", "action_block"), |
132 ("ACTION", "action_block"), |
132 ("IL", "IL"), |
133 ("IL", "IL"), |
133 ("ST", "ST")]: |
134 ("ST", "ST"), |
|
135 ("FILE", ITEM_CONFNODE), |
|
136 ]: |
134 self.TreeImageDict[itemtype] = self.TreeImageList.Add(GetBitmap(imgname)) |
137 self.TreeImageDict[itemtype] = self.TreeImageList.Add(GetBitmap(imgname)) |
135 |
138 |
136 for itemtype in ["function", "functionBlock", "program", |
139 for itemtype in ["function", "functionBlock", "program", |
137 "comment", "block", "io_variable", |
140 "comment", "block", "io_variable", |
138 "connector", "contact", "coil", |
141 "connector", "contact", "coil", |
200 "text": None, |
203 "text": None, |
201 "matches": len(results)} |
204 "matches": len(results)} |
202 |
205 |
203 children = element_infos.setdefault("children", []) |
206 children = element_infos.setdefault("children", []) |
204 for infos, start, end, text in results: |
207 for infos, start, end, text in results: |
205 if infos[1] == "name" or element_type == ITEM_DATATYPE: |
208 if len(words) == 1: # CTN match |
|
209 child_name = {"body":str(start[0])+":", |
|
210 "variable":_("Variable:")}[infos[1]] |
|
211 child_type = {"body":ITEM_CONFNODE, |
|
212 "variable":"var_inout"}[infos[1]] |
|
213 elif infos[1] == "name" or element_type == ITEM_DATATYPE: |
206 child_name = GenerateName(infos[1:]) |
214 child_name = GenerateName(infos[1:]) |
207 child_type = element_type |
215 child_type = element_type |
208 else: |
216 else: |
209 if element_type == ITEM_RESOURCE: |
217 if element_type == ITEM_RESOURCE: |
210 child_type = element_type |
218 child_type = element_type |
230 "matches": 1, |
238 "matches": 1, |
231 "children": [], |
239 "children": [], |
232 } |
240 } |
233 children.append(child_infos) |
241 children.append(child_infos) |
234 |
242 |
|
243 # not Project node |
235 if len(words) > 2: |
244 if len(words) > 2: |
236 for _element_infos in search_results_tree_children: |
245 for _element_infos in search_results_tree_children: |
237 if _element_infos["name"] == words[1]: |
246 if _element_infos["name"] == words[1]: |
238 _element_infos["matches"] += len(children) |
247 _element_infos["matches"] += len(children) |
239 _element_infos["children"].append(element_infos) |
248 _element_infos["children"].append(element_infos) |
240 break |
249 break |
241 if element_type == ITEM_RESOURCE: |
250 if element_type == ITEM_RESOURCE: |
242 search_results_tree_children.append(element_infos) |
251 search_results_tree_children.append(element_infos) |
243 else: |
252 else: # Project node or CTN |
244 search_results_tree_children.append(element_infos) |
253 search_results_tree_children.append(element_infos) |
245 |
254 |
246 if matches_number < 2: |
255 if matches_number < 2: |
247 header_format = _("'{a1}' - {a2} match in project") |
256 header_format = _("'{a1}' - {a2} match in project") |
248 else: |
257 else: |
285 self.SearchResultsTree.SetItemImage(root, self.TreeImageDict[self.ParentWindow.Controler.GetPouType(infos["name"])]) |
294 self.SearchResultsTree.SetItemImage(root, self.TreeImageDict[self.ParentWindow.Controler.GetPouType(infos["name"])]) |
286 else: |
295 else: |
287 self.SearchResultsTree.SetItemImage(root, self.TreeImageDict[infos["type"]]) |
296 self.SearchResultsTree.SetItemImage(root, self.TreeImageDict[infos["type"]]) |
288 |
297 |
289 text = None |
298 text = None |
|
299 print("XXXXXXXXXXXXXX") |
|
300 pprint(infos) |
290 if infos["text"] is not None: |
301 if infos["text"] is not None: |
291 text = infos["text"] |
302 text = infos["text"] |
292 start, end = infos["data"][1:3] |
303 start, end = infos["data"][1:3] |
293 text_lines = infos["text"].splitlines() |
304 text_lines = infos["text"].splitlines() |
294 start_idx = start[1] |
305 start_idx = start[1] |
300 style = wx.TextAttr(wx.Colour(0, 127, 174)) |
311 style = wx.TextAttr(wx.Colour(0, 127, 174)) |
301 |
312 |
302 if text is not None: |
313 if text is not None: |
303 text_ctrl_style = wx.BORDER_NONE | wx.TE_READONLY | wx.TE_RICH2 |
314 text_ctrl_style = wx.BORDER_NONE | wx.TE_READONLY | wx.TE_RICH2 |
304 if wx.Platform != '__WXMSW__' or len(text.splitlines()) > 1: |
315 if wx.Platform != '__WXMSW__' or len(text.splitlines()) > 1: |
305 text_ctrl_style |= wx.TE_MULTILINE |
316 text_ctrl_style |= wx.TE_MULTILINE | wx.TE_NO_VSCROLL |
306 text_ctrl = wx.TextCtrl(id=-1, parent=self.SearchResultsTree, pos=wx.Point(0, 0), |
317 text_ctrl = wx.TextCtrl(id=-1, parent=self.SearchResultsTree, pos=wx.Point(0, 0), |
307 value=text, style=text_ctrl_style) |
318 value=text, style=text_ctrl_style) |
308 width, height = text_ctrl.GetTextExtent(text) |
319 width, height = text_ctrl.GetTextExtent(text) |
309 text_ctrl.SetClientSize(wx.Size(width + 1, height)) |
320 text_ctrl.SetClientSize(wx.Size(width + 1, height)) |
310 text_ctrl.SetBackgroundColour(self.SearchResultsTree.GetBackgroundColour()) |
321 text_ctrl.SetBackgroundColour(self.SearchResultsTree.GetBackgroundColour()) |