]> git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/ide/activegrid/tool/MessageService.py
Applied patch [ 1284335 ] doc update for wxString::operator[]
[wxWidgets.git] / wxPython / samples / ide / activegrid / tool / MessageService.py
1 #----------------------------------------------------------------------------
2 # Name: MessageService.py
3 # Purpose: Message View Service for pydocview
4 #
5 # Author: Morgan Hua
6 #
7 # Created: 9/2/04
8 # CVS-ID: $Id$
9 # Copyright: (c) 2004-2005 ActiveGrid, Inc.
10 # License: wxWindows License
11 #----------------------------------------------------------------------------
12
13 import wx
14 import Service
15 import STCTextEditor
16
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.
20 """
21
22 #----------------------------------------------------------------------------
23 # Overridden methods
24 #----------------------------------------------------------------------------
25
26 def _CreateControl(self, parent, id):
27 txtCtrl = STCTextEditor.TextCtrl(parent, id)
28 txtCtrl.SetMarginWidth(1, 0) # hide line numbers
29 txtCtrl.SetReadOnly(True)
30
31 if wx.Platform == '__WXMSW__':
32 font = "Courier New"
33 else:
34 font = "Courier"
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()
39
40 return txtCtrl
41
42
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)
47 ## id = event.GetId()
48 ## if id == wx.ID_CUT:
49 ## stcControl.Cut()
50 ## return True
51 ## elif id == wx.ID_COPY:
52 ## stcControl.Copy()
53 ## return True
54 ## elif id == wx.ID_PASTE:
55 ## stcControl.Paste()
56 ## return True
57 ## elif id == wx.ID_CLEAR:
58 ## stcControl.Clear()
59 ## return True
60 ## elif id == wx.ID_SELECTALL:
61 ## stcControl.SetSelection(0, -1)
62 ## return True
63 ##
64 ##
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)
69 ## id = event.GetId()
70 ## if id == wx.ID_CUT:
71 ## event.Enable(stcControl.CanCut())
72 ## return True
73 ## elif id == wx.ID_COPY:
74 ## event.Enable(stcControl.CanCopy())
75 ## return True
76 ## elif id == wx.ID_PASTE:
77 ## event.Enable(stcControl.CanPaste())
78 ## return True
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
81 ## return True
82 ## elif id == wx.ID_SELECTALL:
83 ## event.Enable(stcControl.GetTextLength() > 0)
84 ## return True
85
86
87 #----------------------------------------------------------------------------
88 # Service specific methods
89 #----------------------------------------------------------------------------
90
91 def ClearLines(self):
92 self.GetControl().SetReadOnly(False)
93 self.GetControl().ClearAll()
94 self.GetControl().SetReadOnly(True)
95
96
97 def AddLines(self, text):
98 self.GetControl().SetReadOnly(False)
99 self.GetControl().AddText(text)
100 self.GetControl().SetReadOnly(True)
101
102
103 def GetText(self):
104 return self.GetControl().GetText()
105
106
107 def GetCurrentPos(self):
108 return self.GetControl().GetCurrentPos()
109
110
111 def GetCurrLine(self):
112 return self.GetControl().GetCurLine()
113
114
115 #----------------------------------------------------------------------------
116 # Callback Methods
117 #----------------------------------------------------------------------------
118
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.
122 """
123 wx.stc.EVT_STC_DOUBLECLICK(self.GetControl(), self.GetControl().GetId(), callback)
124
125
126
127 class MessageService(Service.Service):
128
129
130 #----------------------------------------------------------------------------
131 # Constants
132 #----------------------------------------------------------------------------
133 SHOW_WINDOW = wx.NewId() # keep this line for each subclass, need unique ID for each Service
134
135
136 #----------------------------------------------------------------------------
137 # Overridden methods
138 #----------------------------------------------------------------------------
139
140 def _CreateView(self):
141 return MessageView(self)
142
143