Commits

windwiny committed 24732c7

add helpdlg findreplacedialog

  • Participants
  • Parent commits 3c35cfc

Comments (0)

Files changed (1)

 
     def OnBtnHelpButton(self, event):
         event.Skip()
-        if not hasattr(self, '_rsyncdoc'):
-            sp = subprocess.Popen('%s --help -v' % G._pg_RSYNC, shell=True,
-                                  stdout=subprocess.PIPE, stderr=subprocess.PIPE,
-                                  startupinfo=G.startupinfo)
-            self._rsyncdoc = sp.stdout.read().decode(G.str_encode)
-            print sp.stderr.read()
-            self._dlg = wx.Dialog(self, title=u"rsync --help", size=wx.Size(640,480),
-                                  style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
-            self._stc = wx.stc.StyledTextCtrl(self._dlg)
-            ff = wx.Font(9, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Courier New')
-            self._stc.StyleSetFont(wx.stc.STC_STYLE_DEFAULT, ff)
-            self._stc.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER)
-            self._stc.SetMarginWidth(1, 38)
-            self._stc.SetSize(self._dlg.GetClientSize())
-        if self._dlg.IsShown():
-            self._dlg.Hide()
+        if not hasattr(self, 'helpdlg'):
+            self.helpdlg = HelpDialog(self)
+        if self.helpdlg.IsShown():
+            self.helpdlg.Hide()
         else:
-            self._stc.SetText(self._rsyncdoc)
-            self._stc.EmptyUndoBuffer()
-            self._dlg.Show()
+            self.helpdlg.Show()
 
     def OnBtnsyncButton(self, event):
         if self.sp:
     def OnBtnCloseButton(self, event):
         event.Skip()
         self.Close()
+
+
+class HelpDialog(wx.Dialog):
+    def __init__(self, parent):
+        wx.Dialog.__init__(self, parent, title=u"rsync --help",
+                            size=wx.Size(640,480),
+                            style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
+        self.stc1 = wx.stc.StyledTextCtrl(self)
+        ff = wx.Font(9, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Courier New')
+        self.stc1.StyleSetFont(wx.stc.STC_STYLE_DEFAULT, ff)
+        self.stc1.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER)
+        self.stc1.SetMarginWidth(1, 38)
+        self.stc1.SetSize(self.GetClientSize())
+        self.initfinddlg()
+
+        sp = subprocess.Popen('%s --help -v' % G._pg_RSYNC, shell=True,
+                              stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+                              startupinfo=G.startupinfo)
+        rsyncdoc = sp.stdout.read().decode(G.str_encode)
+        print sp.stderr.read()
+        self.stc1.SetText(rsyncdoc)
+        self.stc1.EmptyUndoBuffer()
+
+    def initfinddlg(self):
+        self.stc1.Bind(wx.EVT_KEY_DOWN, self.OnShowFind)
+        self.Bind(wx.EVT_FIND, self.OnFind)
+        self.Bind(wx.EVT_FIND_NEXT, self.OnFind)
+        self.Bind(wx.EVT_FIND_REPLACE, self.OnFind)
+        self.Bind(wx.EVT_FIND_REPLACE_ALL, self.OnFind)
+        self.Bind(wx.EVT_FIND_CLOSE, self.OnFindClose)
+
+    def OnShowFind(self, evt):
+        if evt.GetUniChar() in [ord('F'), ord('f')] and evt.ControlDown():
+            print 'OnShowFind'
+        else:
+            evt.Skip()
+            return
+        if hasattr(self, 'finddlg'):
+            return
+        data = wx.FindReplaceData()
+        self.finddlg = wx.FindReplaceDialog(self, data, "Find")
+        self.finddlg.data = data  # save a reference to it...
+        self.finddlg.Show(True)
+
+    def Show(self, show=True):
+        super(HelpDialog, self).Show(show)
+        if show and hasattr(self, 'finddlg'):
+            self.finddlg.Show()
+
+    def Hide(self):
+        super(HelpDialog, self).Hide()
+        if hasattr(self, 'finddlg'):
+            self.finddlg.Hide()
+
+    def OnFind(self, evt=None):
+        print 'OnFind'
+        if not evt: return
+
+        flags = evt.GetFlags()
+        findTxt = evt.GetFindString()
+        stcflags = 0
+        if flags & 2: stcflags &= wx.stc.STC_FIND_WHOLEWORD
+        if flags & 4: stcflags &= wx.stc.STC_FIND_MATCHCASE
+        oldpos = self.stc1.GetCurrentPos()
+        b, e = self.stc1.GetSelectionStart(), self.stc1.GetSelectionEnd()
+        self.stc1.SearchAnchor()
+        if flags & 1:
+            ipos = self.stc1.SearchNext(stcflags, findTxt)    # bug?
+            if ipos == oldpos:
+                i = self.stc1.GetCurrentPos() + len(findTxt)
+                self.stc1.SetSelection(i, i)
+                self.stc1.SearchAnchor()
+                ipos = self.stc1.SearchNext(stcflags, findTxt)
+        else:
+            ipos = self.stc1.SearchPrev(stcflags, findTxt)
+            if ipos == oldpos:
+                i = self.stc1.GetCurrentPos() - len(findTxt)
+                self.stc1.SetSelection(i, i)
+                self.stc1.SearchAnchor()
+                ipos = self.stc1.SearchPrev(stcflags, findTxt)
+        if ipos != -1:
+            self.stc1.EnsureCaretVisible()
+            return
+        else:
+            self.stc1.SetSelectionStart(b)
+            self.stc1.SetSelectionEnd(e)
+            wx.MessageBox("Cann't find the:\n%s" % findTxt, 'msg', wx.OK, evt.GetDialog())
+        print 'OnFind end'
+
+    def OnFindClose(self, evt=None):
+        print ("FindReplaceDialog closing...\n")
+        if not evt: return
+        evt.GetDialog().Destroy()
+        del self.finddlg