]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/samples/ide/activegrid/tool/MessageService.py
removed code inside USE_SIZABLE_CALENDAR, we should allow making the main calendar...
[wxWidgets.git] / wxPython / samples / ide / activegrid / tool / MessageService.py
index 288d40d5c96d45c4d33393ca5842124083511f6d..4765a40ead3e317f372be83c6ffebde05351f749 100644 (file)
@@ -14,6 +14,35 @@ import wx
 import Service
 import STCTextEditor
 
+#----------------------------------------------------------------------------
+# Utility
+#----------------------------------------------------------------------------
+
+def ClearMessages():
+    messageService = wx.GetApp().GetService(MessageService)
+    view = messageService.GetView()
+    if view:
+        view.ClearLines()
+
+
+def ShowMessages(messages, clear=False):
+    if ((messages != None) and (len(messages) > 0)):
+        messageService = wx.GetApp().GetService(MessageService)
+        messageService.ShowWindow(True)
+        view = messageService.GetView()
+        if view:
+            if (clear):
+                view.ClearLines()
+            for message in messages:
+                view.AddLines(message)
+                view.AddLines("\n")
+
+
+#----------------------------------------------------------------------------
+# Classes
+#----------------------------------------------------------------------------
+
+
 class MessageView(Service.ServiceView):
     """ Reusable Message View for any document.
         When an item is selected, the document view is called back (with DoSelectCallback) to highlight and display the corresponding item in the document view.
@@ -36,52 +65,52 @@ class MessageView(Service.ServiceView):
         txtCtrl.SetFontColor(wx.BLACK)
         txtCtrl.StyleClearAll()
         txtCtrl.UpdateStyles()
+        wx.EVT_SET_FOCUS(txtCtrl, self.OnFocus)
 
         return txtCtrl
 
-
-##    def ProcessEvent(self, event):
-##        stcControl = self.GetControl()
-##        if not isinstance(stcControl, wx.stc.StyledTextCtrl):
-##            return wx.lib.docview.View.ProcessUpdateUIEvent(self, event)
-##        id = event.GetId()
-##        if id == wx.ID_CUT:
-##            stcControl.Cut()
-##            return True
-##        elif id == wx.ID_COPY:
-##            stcControl.Copy()
-##            return True
-##        elif id == wx.ID_PASTE:
-##            stcControl.Paste()
-##            return True
-##        elif id == wx.ID_CLEAR:
-##            stcControl.Clear()
-##            return True
-##        elif id == wx.ID_SELECTALL:
-##            stcControl.SetSelection(0, -1)
-##            return True
-##
-##
-##    def ProcessUpdateUIEvent(self, event):
-##        stcControl = self.GetControl()
-##        if not isinstance(stcControl, wx.stc.StyledTextCtrl):
-##            return wx.lib.docview.View.ProcessUpdateUIEvent(self, event)
-##        id = event.GetId()
-##        if id == wx.ID_CUT:
-##            event.Enable(stcControl.CanCut())
-##            return True
-##        elif id == wx.ID_COPY:
-##            event.Enable(stcControl.CanCopy())
-##            return True
-##        elif id == wx.ID_PASTE:
-##            event.Enable(stcControl.CanPaste())
-##            return True
-##        elif id == wx.ID_CLEAR:
-##            event.Enable(True)  # wxBug: should be stcControl.CanCut()) but disabling clear item means del key doesn't work in control as expected
-##            return True
-##        elif id == wx.ID_SELECTALL:
-##            event.Enable(stcControl.GetTextLength() > 0)
-##            return True
+    def GetDocument(self):
+        return None
+
+    def OnFocus(self, event):
+        wx.GetApp().GetDocumentManager().ActivateView(self)
+        event.Skip()
+
+    def ProcessEvent(self, event):
+        stcControl = self.GetControl()
+        if not isinstance(stcControl, wx.stc.StyledTextCtrl):
+            return wx.lib.docview.View.ProcessEvent(self, event)
+        id = event.GetId()
+        if id == wx.ID_COPY:
+            stcControl.Copy()
+            return True
+        elif id == wx.ID_CLEAR:
+            stcControl.Clear()
+            return True
+        elif id == wx.ID_SELECTALL:
+            stcControl.SetSelection(0, -1)
+            return True
+
+
+    def ProcessUpdateUIEvent(self, event):
+        stcControl = self.GetControl()
+        if not isinstance(stcControl, wx.stc.StyledTextCtrl):
+            return wx.lib.docview.View.ProcessUpdateUIEvent(self, event)
+        id = event.GetId()
+        if id == wx.ID_CUT or id == wx.ID_PASTE:
+            # I don't think cut or paste makes sense from a message/log window.
+            event.Enable(False)
+            return True
+        elif id == wx.ID_COPY:
+            hasSelection = (stcControl.GetSelectionStart() != stcControl.GetSelectionEnd()) 
+            event.Enable(hasSelection)
+            return True
+        elif id == wx.ID_CLEAR:
+            event.Enable(True)  # wxBug: should be stcControl.CanCut()) but disabling clear item means del key doesn't work in control as expected
+            return True
+        elif id == wx.ID_SELECTALL:
+            event.Enable(stcControl.GetTextLength() > 0)
+            return True
 
         
     #----------------------------------------------------------------------------
@@ -95,6 +124,7 @@ class MessageView(Service.ServiceView):
 
 
     def AddLines(self, text):
+        self.GetControl().SetCurrentPos(self.GetControl().GetTextLength())
         self.GetControl().SetReadOnly(False)
         self.GetControl().AddText(text)
         self.GetControl().SetReadOnly(True)
@@ -139,5 +169,3 @@ class MessageService(Service.Service):
 
     def _CreateView(self):
         return MessageView(self)
-        
-