# HG changeset patch # User Edouard Tisserant # Date 1553169866 -3600 # Node ID 9812b332f3509a405a4501a7aaba5ea4c29ffbfe # Parent c80b0d864475c290275616159318f2a1f56a269f WIP adding searching capabilities in python files. was done : - change stub search results to trigger highlighting un variable panel - trying to highlight in CTN code file editors -> problem with EditorPanel not having self.VariableEditor set... - added highlight capability to CTN's CodeFileEditor's VariablePanel diff -r c80b0d864475 -r 9812b332f350 CodeFileTreeNode.py --- a/CodeFileTreeNode.py Wed Mar 20 11:34:41 2019 +0100 +++ b/CodeFileTreeNode.py Thu Mar 21 13:04:26 2019 +0100 @@ -212,7 +212,7 @@ def CTNSearch(self, criteria): # TODO really search - return [((self.CTNFullName(),"variable",0), (0,2),(0,4),"a_cow"), + return [((self.CTNFullName(),"var_inout",1,"name"), (0,2),(0,4),"a_cow"), ((self.CTNFullName(),"body"), (1,12),(1,15),"Bitch I'm a cow !")] # ------------------------------------------------------------------------------- diff -r c80b0d864475 -r 9812b332f350 IDEFrame.py --- a/IDEFrame.py Wed Mar 20 11:34:41 2019 +0100 +++ b/IDEFrame.py Thu Mar 21 13:04:26 2019 +0100 @@ -2561,7 +2561,7 @@ # ------------------------------------------------------------------------------- def ShowHighlight(self, infos, start, end, highlight_type): - print(infos) + print("ZZZZZZZZZZZZZ", infos, start, end, highlight_type) self.SelectProjectTreeItem(infos[0]) if infos[1] == "name": self.Highlights[infos[0]] = highlight_type diff -r c80b0d864475 -r 9812b332f350 controls/SearchResultPanel.py --- a/controls/SearchResultPanel.py Wed Mar 20 11:34:41 2019 +0100 +++ b/controls/SearchResultPanel.py Thu Mar 21 13:04:26 2019 +0100 @@ -207,9 +207,9 @@ for infos, start, end, text in results: if len(words) == 1: # CTN match child_name = {"body":str(start[0])+":", - "variable":_("Variable:")}[infos[1]] + "var_inout":_("Variable:")}[infos[1]] child_type = {"body":ITEM_CONFNODE, - "variable":"var_inout"}[infos[1]] + "var_inout":"var_inout"}[infos[1]] elif infos[1] == "name" or element_type == ITEM_DATATYPE: child_name = GenerateName(infos[1:]) child_type = element_type diff -r c80b0d864475 -r 9812b332f350 editors/CodeFileEditor.py --- a/editors/CodeFileEditor.py Wed Mar 20 11:34:41 2019 +0100 +++ b/editors/CodeFileEditor.py Thu Mar 21 13:04:26 2019 +0100 @@ -644,6 +644,7 @@ """ for row in range(self.GetNumberRows()): + row_highlights = self.Highlights.get(row, {}) for col in range(self.GetNumberCols()): editor = None renderer = None @@ -656,7 +657,9 @@ grid.SetCellEditor(row, col, editor) grid.SetCellRenderer(row, col, renderer) - grid.SetCellBackgroundColour(row, col, wx.WHITE) + highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1] + grid.SetCellBackgroundColour(row, col, highlight_colours[0]) + grid.SetCellTextColour(row, col, highlight_colours[1]) self.ResizeRow(grid, row) @@ -859,6 +862,20 @@ return event.Skip() + def AddVariableHighlight(self, infos, highlight_type): + self.Table.AddHighlight(infos, highlight_type) + cell_visible = infos[0] + colnames = [colname.lower() for colname in self.Table.colnames] + self.VariablesGrid.MakeCellVisible(cell_visible, colnames.index(infos[1])) + self.Table.ResetView(self.VariablesGrid) + + def RemoveVariableHighlight(self, infos, highlight_type): + self.Table.RemoveHighlight(infos, highlight_type) + self.Table.ResetView(self.VariablesGrid) + + def ClearHighlights(self, highlight_type=None): + self.Table.ClearHighlights(highlight_type) + self.Table.ResetView(self.VariablesGrid) # ------------------------------------------------------------------------------- # CodeFileEditor Main Frame Class @@ -914,3 +931,21 @@ def Find(self, direction, search_params): self.CodeEditor.Find(direction, search_params) + + def AddHighlight(self, infos, start, end, highlight_type): + if self.VariablesPanel is not None and infos[0] == "var_inout": + self.VariablesPanel.AddVariableHighlight(infos[1:], highlight_type) + else: + self.CodeEditor.AddHighlight(infos, start, end, highlight_type) + + def RemoveHighlight(self, infos, start, end, highlight_type): + if self.VariablesPanel is not None and infos[0] == "var_inout": + self.VariablesPanel.RemoveVariableHighlight(infos[1:], highlight_type) + else: + self.CodeEditor.RemoveHighlight(infos, start, end, highlight_type) + + def ClearHighlights(self, highlight_type=None): + if self.VariablesPanel is not None: + self.VariablesPanel.ClearHighlights(highlight_type) + else: + self.CodeEditor.ClearHighlights(highlight_type)