1 """EditWindow class."""
3 __author__
= "Patrick K. O'Brien <pobrien@orbtech.com>"
5 __revision__
= "$Revision$"[11:-2]
16 from version
import VERSION
24 if wx
.Platform
== '__WXMSW__':
25 FACES
= { 'times' : 'Times New Roman',
26 'mono' : 'Courier New',
27 'helv' : 'Lucida Console',
28 'lucida' : 'Lucida Console',
29 'other' : 'Comic Sans MS',
35 FACES
= { 'times' : 'Times',
38 'other' : 'new century schoolbook',
45 class EditWindow(stc
.StyledTextCtrl
):
46 """EditWindow based on StyledTextCtrl."""
48 revision
= __revision__
50 def __init__(self
, parent
, id=-1, pos
=wx
.DefaultPosition
,
51 size
=wx
.DefaultSize
, style
=wx
.CLIP_CHILDREN | wx
.SUNKEN_BORDER
):
52 """Create EditWindow instance."""
53 stc
.StyledTextCtrl
.__init
__(self
, parent
, id, pos
, size
, style
)
55 stc
.EVT_STC_UPDATEUI(self
, id, self
.OnUpdateUI
)
56 dispatcher
.connect(receiver
=self
._fontsizer
, signal
='FontIncrease')
57 dispatcher
.connect(receiver
=self
._fontsizer
, signal
='FontDecrease')
58 dispatcher
.connect(receiver
=self
._fontsizer
, signal
='FontDefault')
60 def _fontsizer(self
, signal
):
61 """Receiver for Font* signals."""
63 if signal
== 'FontIncrease':
65 elif signal
== 'FontDecrease':
67 elif signal
== 'FontDefault':
72 """Configure shell based on user preferences."""
73 self
.SetMarginType(1, stc
.STC_MARGIN_NUMBER
)
74 self
.SetMarginWidth(1, 40)
76 self
.SetLexer(stc
.STC_LEX_PYTHON
)
77 self
.SetKeyWords(0, ' '.join(keyword
.kwlist
))
80 self
.SetViewWhiteSpace(False)
82 self
.SetUseTabs(False)
83 # Do we want to automatically pop up command completion options?
84 self
.autoComplete
= True
85 self
.autoCompleteIncludeMagic
= True
86 self
.autoCompleteIncludeSingle
= True
87 self
.autoCompleteIncludeDouble
= True
88 self
.autoCompleteCaseInsensitive
= True
89 self
.AutoCompSetIgnoreCase(self
.autoCompleteCaseInsensitive
)
90 self
.AutoCompSetAutoHide(False)
91 self
.AutoCompStops(' .,;:([)]}\'"\\<>%^&+-=*/|`')
92 # Do we want to automatically pop up command argument help?
93 self
.autoCallTip
= True
94 self
.CallTipSetBackground(wx
.Colour(255, 255, 232))
95 self
.SetWrapMode(False)
97 self
.SetEndAtLastLine(False)
98 except AttributeError:
101 def setStyles(self
, faces
):
102 """Configure font size, typeface and color for lexer."""
105 self
.StyleSetSpec(stc
.STC_STYLE_DEFAULT
,
106 "face:%(mono)s,size:%(size)d,back:%(backcol)s" % \
112 self
.StyleSetSpec(stc
.STC_STYLE_LINENUMBER
,
113 "back:#C0C0C0,face:%(mono)s,size:%(lnsize)d" % faces
)
114 self
.StyleSetSpec(stc
.STC_STYLE_CONTROLCHAR
,
115 "face:%(mono)s" % faces
)
116 self
.StyleSetSpec(stc
.STC_STYLE_BRACELIGHT
,
117 "fore:#0000FF,back:#FFFF88")
118 self
.StyleSetSpec(stc
.STC_STYLE_BRACEBAD
,
119 "fore:#FF0000,back:#FFFF88")
122 self
.StyleSetSpec(stc
.STC_P_DEFAULT
,
123 "face:%(mono)s" % faces
)
124 self
.StyleSetSpec(stc
.STC_P_COMMENTLINE
,
125 "fore:#007F00,face:%(mono)s" % faces
)
126 self
.StyleSetSpec(stc
.STC_P_NUMBER
,
128 self
.StyleSetSpec(stc
.STC_P_STRING
,
129 "fore:#7F007F,face:%(mono)s" % faces
)
130 self
.StyleSetSpec(stc
.STC_P_CHARACTER
,
131 "fore:#7F007F,face:%(mono)s" % faces
)
132 self
.StyleSetSpec(stc
.STC_P_WORD
,
134 self
.StyleSetSpec(stc
.STC_P_TRIPLE
,
136 self
.StyleSetSpec(stc
.STC_P_TRIPLEDOUBLE
,
137 "fore:#000033,back:#FFFFE8")
138 self
.StyleSetSpec(stc
.STC_P_CLASSNAME
,
140 self
.StyleSetSpec(stc
.STC_P_DEFNAME
,
142 self
.StyleSetSpec(stc
.STC_P_OPERATOR
,
144 self
.StyleSetSpec(stc
.STC_P_IDENTIFIER
,
146 self
.StyleSetSpec(stc
.STC_P_COMMENTBLOCK
,
148 self
.StyleSetSpec(stc
.STC_P_STRINGEOL
,
149 "fore:#000000,face:%(mono)s,back:#E0C0E0,eolfilled" % faces
)
151 def OnUpdateUI(self
, event
):
152 """Check for matching braces."""
153 # If the auto-complete window is up let it do its thing.
154 if self
.AutoCompActive() or self
.CallTipActive():
159 caretPos
= self
.GetCurrentPos()
161 charBefore
= self
.GetCharAt(caretPos
- 1)
162 styleBefore
= self
.GetStyleAt(caretPos
- 1)
165 if charBefore
and chr(charBefore
) in '[]{}()' \
166 and styleBefore
== stc
.STC_P_OPERATOR
:
167 braceAtCaret
= caretPos
- 1
171 charAfter
= self
.GetCharAt(caretPos
)
172 styleAfter
= self
.GetStyleAt(caretPos
)
173 if charAfter
and chr(charAfter
) in '[]{}()' \
174 and styleAfter
== stc
.STC_P_OPERATOR
:
175 braceAtCaret
= caretPos
177 if braceAtCaret
>= 0:
178 braceOpposite
= self
.BraceMatch(braceAtCaret
)
180 if braceAtCaret
!= -1 and braceOpposite
== -1:
181 self
.BraceBadLight(braceAtCaret
)
183 self
.BraceHighlight(braceAtCaret
, braceOpposite
)
186 """Return True if text is selected and can be copied."""
187 return self
.GetSelectionStart() != self
.GetSelectionEnd()
190 """Return True if text is selected and can be cut."""
191 return self
.CanCopy() and self
.CanEdit()
194 """Return True if editing should succeed."""
195 return not self
.GetReadOnly()
198 """Return True if pasting should succeed."""
199 return stc
.StyledTextCtrl
.CanPaste(self
) and self
.CanEdit()