]>
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 #----------------------------------------------------------------------------
19 #----------------------------------------------------------------------------
22 messageService
= wx
. GetApp (). GetService ( MessageService
)
23 view
= messageService
. GetView ()
28 def ShowMessages ( messages
, clear
= False ):
29 if (( messages
!= None ) and ( len ( messages
) > 0 )):
30 messageService
= wx
. GetApp (). GetService ( MessageService
)
31 messageService
. ShowWindow ( True )
32 view
= messageService
. GetView ()
36 for message
in messages
:
37 view
. AddLines ( message
)
41 #----------------------------------------------------------------------------
43 #----------------------------------------------------------------------------
46 class MessageView ( Service
. ServiceView
):
47 """ Reusable Message View for any document.
48 When an item is selected, the document view is called back (with DoSelectCallback) to highlight and display the corresponding item in the document view.
51 #----------------------------------------------------------------------------
53 #----------------------------------------------------------------------------
55 def _CreateControl ( self
, parent
, id ):
56 txtCtrl
= STCTextEditor
. TextCtrl ( parent
, id )
57 txtCtrl
. SetMarginWidth ( 1 , 0 ) # hide line numbers
58 txtCtrl
. SetReadOnly ( True )
60 if wx
. Platform
== '__WXMSW__' :
64 txtCtrl
. SetFont ( wx
. Font ( 10 , wx
. DEFAULT
, wx
. NORMAL
, wx
. NORMAL
, faceName
= font
))
65 txtCtrl
. SetFontColor ( wx
. BLACK
)
66 txtCtrl
. StyleClearAll ()
67 txtCtrl
. UpdateStyles ()
68 wx
. EVT_SET_FOCUS ( txtCtrl
, self
. OnFocus
)
72 def GetDocument ( self
):
75 def OnFocus ( self
, event
):
76 wx
. GetApp (). GetDocumentManager (). ActivateView ( self
)
79 def ProcessEvent ( self
, event
):
80 stcControl
= self
. GetControl ()
81 if not isinstance ( stcControl
, wx
. stc
. StyledTextCtrl
):
82 return wx
. lib
. docview
. View
. ProcessEvent ( self
, event
)
87 elif id == wx
. ID_CLEAR
:
90 elif id == wx
. ID_SELECTALL
:
91 stcControl
. SetSelection ( 0 , - 1 )
95 def ProcessUpdateUIEvent ( self
, event
):
96 stcControl
= self
. GetControl ()
97 if not isinstance ( stcControl
, wx
. stc
. StyledTextCtrl
):
98 return wx
. lib
. docview
. View
. ProcessUpdateUIEvent ( self
, event
)
100 if id == wx
. ID_CUT
or id == wx
. ID_PASTE
:
101 # I don't think cut or paste makes sense from a message/log window.
104 elif id == wx
. ID_COPY
:
105 hasSelection
= ( stcControl
. GetSelectionStart () != stcControl
. GetSelectionEnd ())
106 event
. Enable ( hasSelection
)
108 elif id == wx
. ID_CLEAR
:
109 event
. Enable ( True ) # wxBug: should be stcControl.CanCut()) but disabling clear item means del key doesn't work in control as expected
111 elif id == wx
. ID_SELECTALL
:
112 event
. Enable ( stcControl
. GetTextLength () > 0 )
116 #----------------------------------------------------------------------------
117 # Service specific methods
118 #----------------------------------------------------------------------------
120 def ClearLines ( self
):
121 self
. GetControl (). SetReadOnly ( False )
122 self
. GetControl (). ClearAll ()
123 self
. GetControl (). SetReadOnly ( True )
126 def AddLines ( self
, text
):
127 self
. GetControl (). SetReadOnly ( False )
128 self
. GetControl (). AddText ( text
)
129 self
. GetControl (). SetReadOnly ( True )
133 return self
. GetControl (). GetText ()
136 def GetCurrentPos ( self
):
137 return self
. GetControl (). GetCurrentPos ()
140 def GetCurrLine ( self
):
141 return self
. GetControl (). GetCurLine ()
144 #----------------------------------------------------------------------------
146 #----------------------------------------------------------------------------
148 def SetCallback ( self
, callback
):
149 """ Sets in the event table for a doubleclick to invoke the given callback.
150 Additional calls to this method overwrites the previous entry and only the last set callback will be invoked.
152 wx
. stc
. EVT_STC_DOUBLECLICK ( self
. GetControl (), self
. GetControl (). GetId (), callback
)
156 class MessageService ( Service
. Service
):
159 #----------------------------------------------------------------------------
161 #----------------------------------------------------------------------------
162 SHOW_WINDOW
= wx
. NewId () # keep this line for each subclass, need unique ID for each Service
165 #----------------------------------------------------------------------------
167 #----------------------------------------------------------------------------
169 def _CreateView ( self
):
170 return MessageView ( self
)