Commits

windwiny committed 71a7517

add show program log dialog

  • Participants
  • Parent commits 9076cda

Comments (0)

Files changed (2)

         if not hasattr(self, '_rsyncdoc'):
             sp = subprocess.Popen('rsync --help -v', stdout=subprocess.PIPE)
             self._rsyncdoc = sp.stdout.read().decode(G.str_encode)
-            self._dlg = wx.Dialog(self, title=u"rsync --help", size=wx.Size(600,480),
+            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')
 import sys
 import os
 import subprocess
+import time
 import sqlite3
 import locale
 import wx
+import wx.stc
 
 class G:
     str_encode = locale.getdefaultlocale()[1]
     return mygrsync(parent)
 
 [wxID_MYGRSYNC, wxID_MYGRSYNCBTNCOMPARE, wxID_MYGRSYNCBTNEXIT, 
- wxID_MYGRSYNCBTNGETDIRS, wxID_MYGRSYNCBTNRSYNC, wxID_MYGRSYNCBTNSWITCH, 
- wxID_MYGRSYNCCHK_TOPWINDOW, wxID_MYGRSYNCPANEL1, wxID_MYGRSYNCSTATICTEXT1, 
- wxID_MYGRSYNCSTATICTEXT2, wxID_MYGRSYNCTXTDST, wxID_MYGRSYNCTXTSRC, 
-] = [wx.NewId() for _init_ctrls in range(12)]
+ wxID_MYGRSYNCBTNGETDIRS, wxID_MYGRSYNCBTNRSYNC, wxID_MYGRSYNCBTNSHOWLOG, 
+ wxID_MYGRSYNCBTNSWITCH, wxID_MYGRSYNCCHK_TOPWINDOW, wxID_MYGRSYNCPANEL1, 
+ wxID_MYGRSYNCSTATICTEXT1, wxID_MYGRSYNCSTATICTEXT2, wxID_MYGRSYNCTXTDST, 
+ wxID_MYGRSYNCTXTSRC, 
+] = [wx.NewId() for _init_ctrls in range(13)]
 
 class mygrsync(wx.Frame):
     def _init_ctrls(self, prnt):
 
         self.staticText1 = wx.StaticText(id=wxID_MYGRSYNCSTATICTEXT1,
               label=u'SRC', name='staticText1', parent=self.panel1,
-              pos=wx.Point(16, 8), size=wx.Size(21, 14), style=0)
+              pos=wx.Point(8, 8), size=wx.Size(21, 14), style=0)
 
         self.staticText2 = wx.StaticText(id=wxID_MYGRSYNCSTATICTEXT2,
               label=u'DST', name=u'staticText2', parent=self.panel1,
-              pos=wx.Point(16, 32), size=wx.Size(23, 14), style=0)
+              pos=wx.Point(8, 32), size=wx.Size(23, 14), style=0)
 
         self.txtSRC = wx.TextCtrl(id=wxID_MYGRSYNCTXTSRC, name=u'txtSRC',
-              parent=self.panel1, pos=wx.Point(40, 8), size=wx.Size(256, 22),
+              parent=self.panel1, pos=wx.Point(32, 8), size=wx.Size(256, 22),
               style=0, value=u'')
         self.txtSRC.Bind(wx.EVT_TEXT, self.OnTxt_x, id=wxID_MYGRSYNCTXTSRC)
 
         self.txtDST = wx.TextCtrl(id=wxID_MYGRSYNCTXTDST, name=u'txtDST',
-              parent=self.panel1, pos=wx.Point(40, 32), size=wx.Size(256, 22),
+              parent=self.panel1, pos=wx.Point(32, 32), size=wx.Size(256, 22),
               style=0, value=u'')
         self.txtDST.Bind(wx.EVT_TEXT, self.OnTxt_x, id=wxID_MYGRSYNCTXTDST)
 
         self.btnSwitch = wx.Button(id=wxID_MYGRSYNCBTNSWITCH, label=u']',
-              name=u'btnSwitch', parent=self.panel1, pos=wx.Point(296, 8),
+              name=u'btnSwitch', parent=self.panel1, pos=wx.Point(288, 8),
               size=wx.Size(24, 48), style=0)
         self.btnSwitch.Bind(wx.EVT_BUTTON, self.OnBtnSwitchButton,
               id=wxID_MYGRSYNCBTNSWITCH)
 
         self.btnCompare = wx.Button(id=wxID_MYGRSYNCBTNCOMPARE,
               label=u'GUI diff', name=u'btnCompare', parent=self.panel1,
-              pos=wx.Point(160, 64), size=wx.Size(56, 40), style=0)
+              pos=wx.Point(96, 64), size=wx.Size(56, 40), style=0)
         self.btnCompare.Enable(False)
         self.btnCompare.Bind(wx.EVT_BUTTON, self.OnBtnCompareButton,
               id=wxID_MYGRSYNCBTNCOMPARE)
 
         self.btnGetDirs = wx.Button(id=wxID_MYGRSYNCBTNGETDIRS,
               label=u'Look Copyed ', name=u'btnGetDirs', parent=self.panel1,
-              pos=wx.Point(64, 64), size=wx.Size(96, 40), style=0)
+              pos=wx.Point(8, 64), size=wx.Size(88, 40), style=0)
         self.btnGetDirs.Bind(wx.EVT_BUTTON, self.OnBtnGetDirsButton,
               id=wxID_MYGRSYNCBTNGETDIRS)
 
         self.btnRsync = wx.Button(id=wxID_MYGRSYNCBTNRSYNC, label=u'Rsync',
-              name=u'btnRsync', parent=self.panel1, pos=wx.Point(216, 64),
+              name=u'btnRsync', parent=self.panel1, pos=wx.Point(152, 64),
               size=wx.Size(56, 40), style=0)
         self.btnRsync.Bind(wx.EVT_BUTTON, self.OnBtnRsyncButton,
               id=wxID_MYGRSYNCBTNRSYNC)
 
         self.btnExit = wx.Button(id=wxID_MYGRSYNCBTNEXIT, label=u'EXIT',
-              name=u'btnExit', parent=self.panel1, pos=wx.Point(280, 64),
+              name=u'btnExit', parent=self.panel1, pos=wx.Point(216, 64),
               size=wx.Size(40, 40), style=0)
+        self.btnExit.SetForegroundColour(wx.Colour(255, 0, 0))
         self.btnExit.Bind(wx.EVT_BUTTON, self.OnBtnExitButton,
               id=wxID_MYGRSYNCBTNEXIT)
 
         self.chk_topwindow = wx.CheckBox(id=wxID_MYGRSYNCCHK_TOPWINDOW,
               label=u'Top', name=u'chk_topwindow', parent=self.panel1,
-              pos=wx.Point(8, 72), size=wx.Size(48, 24), style=0)
+              pos=wx.Point(272, 56), size=wx.Size(48, 24), style=0)
         self.chk_topwindow.SetValue(False)
         self.chk_topwindow.Bind(wx.EVT_CHECKBOX, self.OnChk_topwindowCheckbox,
               id=wxID_MYGRSYNCCHK_TOPWINDOW)
 
+        self.btnShowLog = wx.Button(id=wxID_MYGRSYNCBTNSHOWLOG, label=u'>>',
+              name=u'btnShowLog', parent=self.panel1, pos=wx.Point(272, 80),
+              size=wx.Size(48, 24), style=0)
+        self.btnShowLog.Bind(wx.EVT_BUTTON, self.OnBtnShowLogButton,
+              id=wxID_MYGRSYNCBTNSHOWLOG)
+
     def __init__(self, parent):
         self._init_ctrls(parent)
-        di = os.path.dirname(os.path.abspath(__file__))
-        if os.path.isfile(di):
-            di = os.path.dirname(di)
-        if os.path.isdir(di):
-            os.chdir(di)
+        self.initctls()
+        self.init1()
 
+    def initctls(self):
         ff = wx.Font(9, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Courier New')
         self.txtSRC.SetFont(ff)
         self.txtDST.SetFont(ff)
         self.btnCompare.Disable()
         self.btnRsync.Disable()
+        self.panel1.Bind(wx.EVT_MOTION, self.OnPanelMotion)
+        self.settopwindow()
+        self.initlogwin(ff)
+
+    def initlogwin(self, ff):
+        self._logdlg = wx.Dialog(self, title=u"mygrsync log", size=wx.Size(440,640),
+                              style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
+        self._logstc = wx.stc.StyledTextCtrl(self._logdlg)
+        self._logstc.StyleSetFont(wx.stc.STC_STYLE_DEFAULT, ff)
+        self._logstc.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER)
+        self._logstc.SetMarginWidth(1, 38)
+        self._logstc.SetSize(self._logdlg.GetClientSize())
+        self._logstc.AppendText('%s\n%s\n\n' % (
+            time.strftime('  %Y-%m-%d %H:%M:%S\n'), os.getcwdu()))
+        self._logstc.EmptyUndoBuffer()
+        self._stdout, self._stderr = sys.stdout, sys.stderr
+        sys.stdout, sys.stderr = self, self
+
+    def write(self, txt):
+        if type(txt) == type(u''):
+            pass
+        elif type(txt) == type(''):
+            txt = txt.decode(G.str_encode, 'replace')
+        else:
+            txt = str(txt).decode(G.str_encode, 'replace')
+        self._logstc.AppendText(txt)
+        self._logstc.GotoLine(self._logstc.GetLineCount())
+
+    def init1(self):
+        di = os.path.dirname(os.path.abspath(__file__))
+        if os.path.isfile(di):
+            di = os.path.dirname(di)
+        if os.path.isdir(di):
+            os.chdir(di)
         G.initfromfile()
         if '-v' in sys.argv:
             G.showall()
-        self.panel1.Bind(wx.EVT_MOTION, self.OnPanelMotion)
-        self.settopwindow()
 
     def OnBtnSwitchButton(self, event):
         t1 = self.txtSRC.GetValue()
             self.Move((mouse.x-self.delta.x,\
                        mouse.y-self.delta.y))
 
+    def OnBtnShowLogButton(self, event):
+        event.Skip()
+        self._logdlg.Show()
+