lpcmanager

Parents 0366569f233d
Children 9334ed6090df
#2569 removed python files search hack, to be re-implemented on beremiz side as a general CTN search capability
  • +0 -168
    LPCManager.py
  • --- a/LPCManager.py Tue Feb 06 13:56:30 2018 +0100
    +++ b/LPCManager.py Tue Feb 06 14:50:52 2018 +0100
    @@ -325,87 +325,6 @@
    ("runtime_%s.py" % location_str, file(runtimefile_path, "rb")))
    PythonFileCTNMixin.CTNGenerate_C = CTNGenerate_C
    -def ResetSearchResults(self):
    - self.Highlights = []
    - self.SearchParams = None
    - self.SearchResults = None
    - self.VariableSearchResults = []
    - self.CurrentFindHighlight = None
    - self.index = 0
    -CodeEditor.ResetSearchResults = ResetSearchResults
    -
    -from graphics.GraphicCommons import ERROR_HIGHLIGHT, SEARCH_RESULT_HIGHLIGHT, REFRESH_HIGHLIGHT_PERIOD
    -[STC_CODE_ERROR, STC_CODE_SEARCH_RESULT,
    - STC_CODE_SECTION] = range(15, 18)
    -
    -HIGHLIGHT_TYPES = {
    - ERROR_HIGHLIGHT: STC_CODE_ERROR,
    - SEARCH_RESULT_HIGHLIGHT: STC_CODE_SEARCH_RESULT,
    -}
    -def FindVariable(self, direction, search_params, variables):
    - first = False
    - if self.SearchParams != search_params:
    - first = True
    - self.SearchParams = search_params
    - if len(self.VariableSearchResults) > 0:
    - (r, c) = self.VariableSearchResults[self.index]
    - variables.VariablesGrid.SetCellBackgroundColour(r, c, SEARCH_RESULT_HIGHLIGHT[1])
    - grid = variables.VariablesGrid
    - cols = grid.GetNumberCols()
    - rows = grid.GetNumberRows()
    - self.VariableSearchResults = []
    - for row in range(rows):
    - for col in range(cols):
    - value = variables.VariablesGrid.GetCellValue(row, col)
    - search_value = search_params['find_pattern']
    - if search_params['case_sensitive'] == False:
    - search_value = search_value.lower()
    - value = value.lower()
    - if search_value in value:
    - self.VariableSearchResults.append((row, col))
    - self.index = 0
    - if len(self.VariableSearchResults) > 0:
    - (r, c) = self.VariableSearchResults[self.index]
    - variables.VariablesGrid.SetCellBackgroundColour(r, c, SEARCH_RESULT_HIGHLIGHT[1])
    - if not first:
    - self.index += direction
    - self.index = self.index % len(self.VariableSearchResults)
    - (r, c) = self.VariableSearchResults[self.index]
    - variables.VariablesGrid.SetCellBackgroundColour(r, c, SEARCH_RESULT_HIGHLIGHT[0])
    - variables.VariablesGrid.MakeCellVisible(r, c)
    - variables.VariablesGrid.ForceRefresh()
    -CodeEditor.FindVariable = FindVariable
    -
    -def SearchInPyfile(self, criteria):
    - result = []
    - from xml.dom import minidom
    - dir_list = next(os.walk(self.ProjectPath))[1]
    - for dir in dir_list:
    - if dir not in ["build", "CanOpen@CanOpen", "project_files"]:
    - path = os.path.join(self.ProjectPath, dir, 'pyfile.xml')
    - variablelist = []
    - if os.path.exists(path):
    - pyfile = minidom.parse(path)
    - variablelist = pyfile.getElementsByTagName('variable')
    - for s in variablelist:
    - if criteria["find_pattern"] in s.attributes['name'].value:
    - result.append(dir)
    - return result
    -PLCControler.SearchInPyfile = SearchInPyfile
    -
    -def OnSearchInProjectMenu(self, event):
    - dialog = SearchInProjectDialog(self)
    - if dialog.ShowModal() == wx.ID_OK:
    - criteria = dialog.GetCriteria()
    - if len(criteria) > 0:
    - result = self.Controler.SearchInProject(criteria)
    - pyresult = self.Controler.SearchInPyfile(criteria)
    - self.ClearSearchResults()
    - self.SearchResultPanel.SetSearchResults(criteria, result, pyresult)
    - self.SearchResultPanel.AddPyFileResults(pyresult)
    - self.SelectTab(self.SearchResultPanel)
    -IDEFrame.OnSearchInProjectMenu = OnSearchInProjectMenu
    -
    def GenerateProjectTreeBranch(self, root, infos, item_alone=False):
    to_delete = []
    item_name = infos["name"]
    @@ -447,93 +366,6 @@
    self.ProjectTree.Delete(item)
    IDEFrame.GenerateProjectTreeBranch = GenerateProjectTreeBranch
    -defaultSearchResultPanelInit = SearchResultPanel.__init__
    -def SearchResultPanelInit(self, parent, window):
    - defaultSearchResultPanelInit(self, parent, window)
    - self.TreeImageDict["py_file"] = self.TreeImageList.Add(GetBitmap("py_file"))
    - self.TreeImageDict["wx_glade"] = self.TreeImageList.Add(GetBitmap("wx_glade"))
    -SearchResultPanel.__init__ = SearchResultPanelInit
    -
    -def SetSearchResults(self, criteria, search_results, py_results):
    - self.Criteria = criteria
    - self.SearchResults = {}
    - self.ElementsOrder = []
    - self.PySearchResults = py_results
    -
    - for infos, start, end, text in search_results:
    - if infos[0] not in self.ElementsOrder:
    - self.ElementsOrder.append(infos[0])
    -
    - results = self.SearchResults.setdefault(infos[0], [])
    - results.append((infos, start, end, text))
    -
    - self.RefreshView()
    -SearchResultPanel.SetSearchResults = SetSearchResults
    -
    -def AddPyFileResults(self, search_results):
    - distinct_list = list(set(search_results))
    - for result in distinct_list:
    - name = result.split('@')
    - matches = search_results.count(result)
    - if name[1] == "py_ext":
    - root = self.SearchResultsTree.GetRootItem()
    - self.SearchResultsTree.AppendItem(root, name[0], image=self.TreeImageDict["py_file"])
    - else:
    - root = self.SearchResultsTree.GetRootItem()
    - self.SearchResultsTree.AppendItem(root, name[0], image=self.TreeImageDict["wx_glade"])
    - if matches > 1:
    - text = _("(%d matches)") % search_results.count(result)
    - start_idx, end_idx = 0, len(text)
    - style = wx.TextAttr(wx.Colour(0, 127, 174))
    - text_ctrl_style = wx.BORDER_NONE | wx.TE_READONLY | wx.TE_RICH2
    - if wx.Platform != '__WXMSW__' or len(text.splitlines()) > 1:
    - text_ctrl_style |= wx.TE_MULTILINE
    - text_ctrl = wx.TextCtrl(id=-1, parent=self.SearchResultsTree, pos=wx.Point(0, 0),
    - value=text, style=text_ctrl_style)
    - width, height = text_ctrl.GetTextExtent(text)
    - text_ctrl.SetClientSize(wx.Size(width + 1, height))
    - text_ctrl.SetBackgroundColour(self.SearchResultsTree.GetBackgroundColour())
    - child = self.SearchResultsTree.GetLastChild(root)
    - text_ctrl.SetInsertionPoint(0)
    - text_ctrl.SetStyle(start_idx, end_idx, style)
    - self.SearchResultsTree.SetItemWindow(child, text_ctrl)
    -SearchResultPanel.AddPyFileResults = AddPyFileResults
    -
    -
    -def ResetSearchResults(self):
    - self.Criteria = None
    - self.ElementsOrder = []
    - self.SearchResults = {}
    - self.PySearchResults = []
    - self.RefreshView()
    -SearchResultPanel.ResetSearchResults = ResetSearchResults
    -
    -
    -def GetPythonTextCtrlDClickFunction(self, item):
    - for type in self.ParentWindow.CTR.Children.values():
    - for name in type:
    - if name.BaseParams.attrib['Name'] == item:
    - name._OpenView()
    - selected = self.ParentWindow.TabsOpened.GetSelection()
    - if selected != -1:
    - window = self.ParentWindow.TabsOpened.GetPage(selected)
    - window.CodeEditor.FindVariable(1, {'find_pattern': self.Criteria['find_pattern'],
    - 'regular_expression': self.Criteria['regular_expression'],
    - 'pattern': self.Criteria['pattern'],
    - 'case_sensitive': self.Criteria['case_sensitive'],
    - 'filter': self.Criteria['filter']}, window.VariablesPanel)
    - for (r, c) in window.CodeEditor.VariableSearchResults:
    - window.VariablesPanel.VariablesGrid.SetCellBackgroundColour(r, c,
    - SEARCH_RESULT_HIGHLIGHT[0])
    -SearchResultPanel.GetPythonTextCtrlDClickFunction = GetPythonTextCtrlDClickFunction
    -
    -
    -def OnSearchResultsTreeItemActivated(self, event):
    - self.ShowSearchResults(event.GetItem())
    - if event.GetItem()._data is None:
    - self.GetPythonTextCtrlDClickFunction(event.GetItem()._text)
    - event.Skip()
    -SearchResultPanel.OnSearchResultsTreeItemActivated = OnSearchResultsTreeItemActivated
    defaultProjectPropertiesPanelInit = ProjectPropertiesPanel.__init__
    def OurProjectPropertiesPanelInit(self, parent, controller=None, window=None, enable_required=True):