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