]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/ide/activegrid/tool/MessageService.py 
   1  #----------------------------------------------------------------------------    2  # Name:         MessageService.py    3  # Purpose:      Message View Service for pydocview    9  # Copyright:    (c) 2004-2005 ActiveGrid, Inc.   10  # License:      wxWindows License   11  #----------------------------------------------------------------------------   17  class  MessageView ( Service
. ServiceView
):   18      """ Reusable Message View for any document.   19          When an item is selected, the document view is called back (with DoSelectCallback) to highlight and display the corresponding item in the document view.   22      #----------------------------------------------------------------------------   24      #----------------------------------------------------------------------------   26      def  _CreateControl ( self
,  parent
,  id ):   27          txtCtrl 
=  STCTextEditor
. TextCtrl ( parent
,  id )   28          txtCtrl
. SetMarginWidth ( 1 ,  0 )   # hide line numbers   29          txtCtrl
. SetReadOnly ( True )   31          if  wx
. Platform 
==  '__WXMSW__' :   35          txtCtrl
. SetFont ( wx
. Font ( 10 ,  wx
. DEFAULT
,  wx
. NORMAL
,  wx
. NORMAL
,  faceName 
=  font
))   36          txtCtrl
. SetFontColor ( wx
. BLACK
)   37          txtCtrl
. StyleClearAll ()   38          txtCtrl
. UpdateStyles ()   43  ##    def ProcessEvent(self, event):   44  ##        stcControl = self.GetControl()   45  ##        if not isinstance(stcControl, wx.stc.StyledTextCtrl):   46  ##            return wx.lib.docview.View.ProcessUpdateUIEvent(self, event)   48  ##        if id == wx.ID_CUT:   51  ##        elif id == wx.ID_COPY:   54  ##        elif id == wx.ID_PASTE:   57  ##        elif id == wx.ID_CLEAR:   60  ##        elif id == wx.ID_SELECTALL:   61  ##            stcControl.SetSelection(0, -1)   65  ##    def ProcessUpdateUIEvent(self, event):   66  ##        stcControl = self.GetControl()   67  ##        if not isinstance(stcControl, wx.stc.StyledTextCtrl):   68  ##            return wx.lib.docview.View.ProcessUpdateUIEvent(self, event)   70  ##        if id == wx.ID_CUT:   71  ##            event.Enable(stcControl.CanCut())   73  ##        elif id == wx.ID_COPY:   74  ##            event.Enable(stcControl.CanCopy())   76  ##        elif id == wx.ID_PASTE:   77  ##            event.Enable(stcControl.CanPaste())   79  ##        elif id == wx.ID_CLEAR:   80  ##            event.Enable(True)  # wxBug: should be stcControl.CanCut()) but disabling clear item means del key doesn't work in control as expected   82  ##        elif id == wx.ID_SELECTALL:   83  ##            event.Enable(stcControl.GetTextLength() > 0)   87      #----------------------------------------------------------------------------   88      # Service specific methods   89      #----------------------------------------------------------------------------   92          self
. GetControl (). SetReadOnly ( False )   93          self
. GetControl (). ClearAll ()   94          self
. GetControl (). SetReadOnly ( True )   97      def  AddLines ( self
,  text
):   98          self
. GetControl (). SetReadOnly ( False )   99          self
. GetControl (). AddText ( text
)  100          self
. GetControl (). SetReadOnly ( True )  104          return  self
. GetControl (). GetText ()  107      def  GetCurrentPos ( self
):  108          return  self
. GetControl (). GetCurrentPos ()  111      def  GetCurrLine ( self
):  112          return  self
. GetControl (). GetCurLine ()  115      #----------------------------------------------------------------------------  117      #----------------------------------------------------------------------------  119      def  SetCallback ( self
,  callback
):  120          """ Sets in the event table for a doubleclick to invoke the given callback.  121              Additional calls to this method overwrites the previous entry and only the last set callback will be invoked.  123          wx
. stc
. EVT_STC_DOUBLECLICK ( self
. GetControl (),  self
. GetControl (). GetId (),  callback
)  127  class  MessageService ( Service
. Service
):  130      #----------------------------------------------------------------------------  132      #----------------------------------------------------------------------------  133      SHOW_WINDOW 
=  wx
. NewId ()   # keep this line for each subclass, need unique ID for each Service  136      #----------------------------------------------------------------------------  138      #----------------------------------------------------------------------------  140      def  _CreateView ( self
):  141          return  MessageView ( self
)