私はさまざまなログデータを含むTextCtrlを持っていますが、ユーザーが検索する文字列を検索できるEditTextフィールドもあります。検索ボタンをクリックすると、ログに記録されます。ブラウザで標準の検索/ハイライト/メモ帳などPython TextCtrl検索とハイライト機能
私はすでに動作しており、成功した利用者の言葉を強調したコードは、しかし私は実装したいと行方不明のビットがいくつかあります:
- は、
同じ単語を検索し、次の単語をハイライト表示するなどの機能があります。EDIT:これは以下のコードで[次を検索]ボタンを追加することで解決しました。このカウントは、次のハイライトをログの終わりまでではなく1ワードに制限します。 - はそれを同じ単語、または新しい単語
スタートすること、新しい単語が検索され、現在のワードをアンハイライト位置0(データの先頭)新しい単語をEDITを検索する場合に: DEFdef findTxt(self,e): global wordPos newstring = self.logTxt.GetValue() for i in range(self.progressBox.GetNumberOfLines()): line = self.progressBox.GetLineText(i) if newstring in line: startPos = self.progressBox.GetValue().find(newstring) endPos = startPos + len(newstring) wordPos = endPos self.progressBox.Bind(wx.EVT_SET_FOCUS, self.highlightText(startPos, endPos)) startPos = 0 self.findNextBtn.Enable() def findNext(self,e): global wordPos newstring = self.logTxt.GetValue() count = 0 for i in range(self.progressBox.GetNumberOfLines()): if count == 0: line = self.progressBox.GetValue() if newstring in line: startPos = self.progressBox.GetValue().find(newstring, wordPos) endPos = startPos + len(newstring) wordPos = endPos self.progressBox.Bind(wx.EVT_SET_FOCUS, self.highlightText(startPos, endPos)) count = 1 def highlightText(self, pos, size): self.progressBox.SetStyle(pos, size, wx.TextAttr("black", "turquoise")) self.progressBox.SetInsertionPoint(pos)
すべての基準が満たされた