1
2 __doc__ = """GNUmed StyledTextCtrl subclass for SOAP editing.
3
4 based on: 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)"""
5
6 __author__ = "K. Hilbert <Karsten.Hilbert@gmx.net>"
7 __license__ = "GPL v2 or later (details at http://www.gnu.org)"
8
9 import logging
10 import sys
11
12
13 import wx
14 import wx.stc
15
16
17 if __name__ == '__main__':
18 sys.path.insert(0, '../../')
19 from Gnumed.business import gmSoapDefs
20 from Gnumed.wxpython import gmKeywordExpansionWidgets
21 from Gnumed.wxpython.gmTextCtrl import cUnicodeInsertion_TextCtrlMixin
22
23
24 _log = logging.getLogger('gm.stc')
25
26
28
29 - def __init__(self, *args, **kwargs):
30 if not isinstance(self, wx.stc.StyledTextCtrl):
31 raise TypeError('[%s]: can only be applied to wx.stc.StyledTextCtrl, not [%s]' % (cWxTextCtrlCompatibility_StcMixin, self.__class__.__name__))
32
33
34
35
37 _log.debug('%s.GetValue() - %s', cWxTextCtrlCompatibility_StcMixin, self.__class__.__name__)
38 return self.GetText()
39
40
41 - def SetValue(self, value):
42 _log.debug('%s.SetValue() - %s', cWxTextCtrlCompatibility_StcMixin, self.__class__.__name__)
43 return self.SetText(value)
44
45
46 - def WriteText(self, value):
47 return self.InsertText(self.CurrentPos, value)
48
49
52
53 LastPosition = property(GetLastPosition, lambda x:x)
54
55
58
59
60 - def GetLineText(self, line_no):
61 return self.GetLine(line_no)
62
63
65 return self.CurrentPos
66
67 - def SetInsertionPoint(self, position):
68 self.CurrentPos = position
69
70 InsertionPoint = property(GetInsertionPoint, SetInsertionPoint)
71
72
73 - def ShowPosition(self, position):
74
75 self.CurrentPos = position
76 self.EnsureCaretVisible()
77
78
79 - def IsMultiLine(self):
81
82
83 - def PositionToXY(self, position):
84 try:
85
86
87 return super(wx.TextAreaBase, self).PositionToXY(position)
88 except AttributeError:
89
90
91 return (True, self.GetColumn(position), self.LineFromPosition(position))
92
93
94 - def Replace(self, start, end, replacement):
95 self.SetSelection(start, end)
96 self.ReplaceSelection(replacement)
97 wx.CallAfter(self.SetSelection, 0, 0)
98
99
100 -class cSoapSTC(cUnicodeInsertion_TextCtrlMixin, gmKeywordExpansionWidgets.cKeywordExpansion_TextCtrlMixin, cWxTextCtrlCompatibility_StcMixin, wx.stc.StyledTextCtrl):
101
102 _MARKER_ADM = 0
103 _MARKER_S = 1
104 _MARKER_O = 2
105 _MARKER_A = 3
106 _MARKER_P = 4
107 _MARKER_U = 5
108 _MARKER_LINE_BG_LIGHT_GREY = 31
109
110 _DEFINED_MARKERS_MASK = (
111 _MARKER_ADM
112 |
113 _MARKER_S
114 |
115 _MARKER_O
116 |
117 _MARKER_A
118 |
119 _MARKER_P
120 |
121 _MARKER_U
122 |
123 _MARKER_LINE_BG_LIGHT_GREY
124 )
125
126 _DEFINED_MARKER_NUMS = [
127 _MARKER_ADM,
128 _MARKER_S,
129 _MARKER_O,
130 _MARKER_A,
131 _MARKER_P,
132 _MARKER_U,
133 _MARKER_LINE_BG_LIGHT_GREY
134 ]
135 _SOAP_MARKER_NUMS = [
136 _MARKER_ADM,
137 _MARKER_S,
138 _MARKER_O,
139 _MARKER_A,
140 _MARKER_P,
141 _MARKER_U
142 ]
143 _SOAP2MARKER = {
144 None: _MARKER_ADM,
145 ' ': _MARKER_ADM,
146 '.': _MARKER_ADM,
147 's': _MARKER_S,
148 'o': _MARKER_O,
149 'a': _MARKER_A,
150 'p': _MARKER_P,
151 'u': _MARKER_U,
152 'S': _MARKER_S,
153 'O': _MARKER_O,
154 'A': _MARKER_A,
155 'P': _MARKER_P,
156 'U': _MARKER_U
157 }
158 _MARKER2SOAP = {
159 _MARKER_ADM: None,
160 _MARKER_S: 's',
161 _MARKER_O: 'o',
162 _MARKER_A: 'a',
163 _MARKER_P: 'p',
164 _MARKER_U: 'u'
165 }
166 _SOAPMARKER2BACKGROUND = {
167 _MARKER_ADM: False,
168 _MARKER_S: True,
169 _MARKER_O: False,
170 _MARKER_A: True,
171 _MARKER_P: False,
172 _MARKER_U: True
173 }
174
176
177
178 if args[2] == '':
179 l_args = list(args)
180 l_args[2] = wx.DefaultPosition
181 args = tuple(l_args)
182 wx.stc.StyledTextCtrl.__init__(self, *args, **kwargs)
183 cWxTextCtrlCompatibility_StcMixin.__init__(self)
184 gmKeywordExpansionWidgets.cKeywordExpansion_TextCtrlMixin.__init__(self)
185 cUnicodeInsertion_TextCtrlMixin.__init__(self)
186
187
188 self.SetWrapMode(wx.stc.STC_WRAP_NONE)
189
190 self.SetEdgeColumn(80)
191 self.SetEdgeColour('grey')
192
193 self.SetEdgeMode(wx.stc.STC_EDGE_BACKGROUND)
194
195
196 self.SetEOLMode(wx.stc.STC_EOL_LF)
197
198 self.SetViewEOL(0)
199
200
201
202 self.SetViewWhiteSpace(wx.stc.STC_WS_INVISIBLE)
203
204
205
206
207
208 self.SetCaretLineBackground('khaki')
209 self.SetCaretLineVisible(1)
210
211
212
213 self.SetMarginLeft(0)
214
215 self.SetMarginType(0, wx.stc.STC_MARGIN_SYMBOL)
216 self.SetMarginWidth(0, 16)
217 self.SetMarginMask(0, cSoapSTC._DEFINED_MARKERS_MASK)
218
219 self.SetMarginType(1, wx.stc.STC_MARGIN_SYMBOL)
220 self.SetMarginMask(1, 0)
221 self.SetMarginWidth(1, 0)
222 self.SetMarginType(2, wx.stc.STC_MARGIN_SYMBOL)
223 self.SetMarginMask(2, 0)
224 self.SetMarginWidth(2, 0)
225
226
227
228 self.MarkerDefine(cSoapSTC._MARKER_ADM, wx.stc.STC_MARK_CHARACTER + ord('.'), 'blue', 'white')
229 self.MarkerDefine(cSoapSTC._MARKER_S, wx.stc.STC_MARK_CHARACTER + ord(gmSoapDefs.soap_cat2l10n['s']), 'blue', 'grey96')
230 self.MarkerDefine(cSoapSTC._MARKER_O, wx.stc.STC_MARK_CHARACTER + ord(gmSoapDefs.soap_cat2l10n['o']), 'blue', 'white')
231 self.MarkerDefine(cSoapSTC._MARKER_A, wx.stc.STC_MARK_CHARACTER + ord(gmSoapDefs.soap_cat2l10n['a']), 'blue', 'grey96')
232 self.MarkerDefine(cSoapSTC._MARKER_P, wx.stc.STC_MARK_CHARACTER + ord(gmSoapDefs.soap_cat2l10n['p']), 'blue', 'white')
233 self.MarkerDefine(cSoapSTC._MARKER_U, wx.stc.STC_MARK_CHARACTER + ord(gmSoapDefs.soap_cat2l10n['u']), 'blue', 'grey96')
234 self.MarkerDefine(cSoapSTC._MARKER_LINE_BG_LIGHT_GREY, wx.stc.STC_MARK_BACKGROUND, 'grey96', 'grey96')
235
236
237
238 self.__changing_SOAP_cat = False
239 self.__markers_of_prev_line = None
240 self.__ensure_has_all_soap_types = False
241
242
243 self.UsePopUp(0)
244 self.__build_context_menu()
245
246
247 self.SetText_from_SOAP()
248
249 self.__register_events()
250
251
252 self.enable_keyword_expansions()
253
254
255
256
257 - def SetText(self, *args, **kwargs):
258 _log.debug('%s.SetText()', self.__class__.__name__)
259 wx.stc.StyledTextCtrl.SetText(self, *args, **kwargs)
260
261 - def AddText(self, *args, **kwargs):
262 _log.debug('%s.AddText()', self.__class__.__name__)
263 wx.stc.StyledTextCtrl.AddText(self, *args, **kwargs)
264
265 - def AddStyledText(self, *args, **kwargs):
266 _log.debug('%s.AddStyledText()', self.__class__.__name__)
267 wx.stc.StyledTextCtrl.AddStyledText(self, *args, **kwargs)
268
269 - def InsertText(self, *args, **kwargs):
270 _log.debug('%s.InsertText()', self.__class__.__name__)
271 wx.stc.StyledTextCtrl.InsertText(self, *args, **kwargs)
272
273
275 sel_start, sel_end = self.GetSelection()
276 start_line = self.LineFromPosition(sel_start)
277 end_line = start_line + text.count('\n')
278 start_line_soap_cat = self.MarkerGet(start_line)
279
280 wx.stc.StyledTextCtrl.ReplaceSelection(self, text)
281 if start_line != end_line:
282 for target_line in range(start_line, end_line):
283 self.MarkerDelete(target_line, -1)
284 self.__set_markers_of_line(target_line, start_line_soap_cat)
285
286
288 _log.debug('%s.ReplaceTarget()', self.__class__.__name__)
289 wx.stc.StyledTextCtrl.ReplaceTarget(self, *args, **kwargs)
290
292 _log.debug('%s.ReplaceTargetRE()', self.__class__.__name__)
293 wx.stc.StyledTextCtrl.ReplaceTargetRE(self, *args, **kwargs)
294
295
296
297
298 - def SetText_from_SOAP(self, soap=None, sort_order=None):
299
300 if soap is None:
301
302 soap = {}
303 if sort_order is None:
304 sort_order = ['s', 'o', 'a', 'p', None, 'u']
305
306
307 for cat in 'soap':
308 try:
309 soap[cat]
310 except KeyError:
311 soap[cat] = ['']
312 try:
313 soap['u']
314 except KeyError:
315 soap['u'] = []
316 try:
317 soap[None]
318 except KeyError:
319 soap[None] = []
320 if '.' in soap:
321 soap[None].extend(soap['.'])
322 del soap['.']
323 if ' ' in soap:
324 soap[None].extend(soap[' '])
325 del soap[' ']
326
327
328 for cat in 'soapu':
329 if cat not in sort_order:
330 sort_order.append(cat)
331 if None not in sort_order:
332 sort_order.append(None)
333
334
335 soap_lines = []
336 line_categories = []
337 for cat in sort_order:
338 lines = soap[cat]
339 if len(lines) == 0:
340 continue
341 for line in lines:
342 soap_lines.append(line.strip())
343 line_categories.append(cat)
344
345 _log.debug('%s.SetText_from_SOAP(): 1 controlled use of .SetText() follows', self.__class__.__name__)
346 self.SetText('\n'.join(soap_lines))
347
348 for idx in range(len(line_categories)):
349
350 self.set_soap_cat_of_line(idx, line_categories[idx])
351
352
353 - def GetText_as_SOAP(self):
354 lines = self.GetText().split('\n')
355 soap = {}
356 for line_idx in range(len(lines)):
357 cat = self.get_soap_cat_of_line(line_idx)
358 try:
359 soap[cat]
360 except KeyError:
361 soap[cat] = []
362 soap[cat].append(lines[line_idx])
363 return soap
364
365 soap = property(GetText_as_SOAP, lambda x:x)
366
367
369 soap = self.GetText_as_SOAP()
370 for cat in soap:
371 if ''.join([ l.strip() for l in soap[cat] ]) != '':
372 return False
373 return True
374
375 empty = property(_get_empty, lambda x:x)
376
377
380
381
388
389
390
391
393 line_text = self.GetLine(line)
394 line_start = self.PositionFromLine(line)
395 line_end = self.GetLineEndPosition(line)
396 self.SetTargetStart(line_start)
397 self.SetTargetEnd(line_end)
398 self.ReplaceTarget(line_text.rstrip())
399
400
402 return self.PointFromPosition(self.CurrentPos)
403
404
407
408
409
410
412
413
414 self.__popup_menu = wx.Menu(title = _('SOAP Editor Actions:'))
415
416
417 item = self.__popup_menu.Append(-1, _('&Sort lines'), _('Sort lines by SOAP category'))
418 self.Bind(wx.EVT_MENU, self.__on_sort_by_soap, item)
419
420
421 item = self.__popup_menu.Append(-1, _('e&Xpand keyword'), _('Expand keyword / macro'))
422 self.Bind(wx.EVT_MENU, self.__on_expand_keyword, item)
423
424
425 item = self.__popup_menu.Append(-1, _('Insert &Unicode'), _('Insert a unicode character'))
426 self.Bind(wx.EVT_MENU, self.__on_insert_unicode, item)
427
428 self.__popup_menu.AppendSeparator()
429
430
431
432
433
434 menu_line = wx.Menu()
435
436 item = menu_line.Append(-1, _('as &Subjective'), _('Set line to category "Subjective"'))
437 self.Bind(wx.EVT_MENU, self.__on_make_line_Soap, item)
438 item = menu_line.Append(-1, _('as &Objective'), _('Set line to category "Objective"'))
439 self.Bind(wx.EVT_MENU, self.__on_make_line_sOap, item)
440 item = menu_line.Append(-1, _('as &Assessment'), _('Set line to category "Assessment"'))
441 self.Bind(wx.EVT_MENU, self.__on_make_line_soAp, item)
442 item = menu_line.Append(-1, _('as &Plan'), _('Set line to category "Plan"'))
443 self.Bind(wx.EVT_MENU, self.__on_make_line_soaP, item)
444 item = menu_line.Append(-1, _('as &Unspecified'), _('Set line to category "unspecified"'))
445 self.Bind(wx.EVT_MENU, self.__on_make_line_soapU, item)
446 item = menu_line.Append(-1, _('as ad&Ministrative'), _('Set line to category "administrative"'))
447 self.Bind(wx.EVT_MENU, self.__on_make_line_soapADM, item)
448 menu_line.AppendSeparator()
449 item = menu_line.Append(-1, _('\u2192 &Clipboard'), _('Copy line to clipboard'))
450 self.Bind(wx.EVT_MENU, self.__on_line2clipboard, item)
451 item = menu_line.Append(-1, _('\u2192 +Clipboard+'), _('Add line to clipboard'))
452 self.Bind(wx.EVT_MENU, self.__on_add_line2clipboard, item)
453
454
455
456 menu_all = wx.Menu()
457
458 item = menu_all.Append(-1, _('\u2192 &Clipboard'), _('Copy content to clipboard'))
459 self.Bind(wx.EVT_MENU, self.__on_content2clipboard, item)
460 item = menu_all.Append(-1, _('\u2192 +Clipboard+'), _('Add content to clipboard'))
461 self.Bind(wx.EVT_MENU, self.__on_add_content2clipboard, item)
462
463
464
465
466
467
468
469
470 self.__menu_selection = wx.Menu()
471
472 item = self.__menu_selection.Append(-1, _('\u2192 &Clipboard'), _('Copy selection to clipboard'))
473 self.Bind(wx.EVT_MENU, self.__on_region2clipboard, item)
474 item = self.__menu_selection.Append(-1, _('\u2192 +Clipboard+'), _('Add selection to clipboard'))
475 self.Bind(wx.EVT_MENU, self.__on_add_region2clipboard, item)
476
477 self.__popup_menu.Append(wx.NewId(), _('&Line ...'), menu_line)
478 self.__popup_menu.Append(wx.NewId(), _('&Text ...'), menu_all)
479 self.__popup_menu.Append(wx.NewId(), _('&Region ...'), self.__menu_selection)
480
481
483 sel_start, sel_end = self.GetSelection()
484 sel_menu_id = self.__popup_menu.FindItem(_('&Region ...'))
485 if sel_start == sel_end:
486 self.__popup_menu.Enable(sel_menu_id, False)
487 else:
488 self.__popup_menu.Enable(sel_menu_id, True)
489
490 self.PopupMenu(self.__popup_menu, position)
491
492
494 if wx.TheClipboard.IsOpened():
495 _log.debug('clipboard already open')
496 return ''
497 if not wx.TheClipboard.Open():
498 _log.debug('cannot open clipboard')
499 return ''
500 data_obj = wx.TextDataObject()
501 got_it = wx.TheClipboard.GetData(data_obj)
502 if not got_it:
503 return ''
504 return data_obj.Text
505
506
507
508
511
512
515
516
518 txt = self.GetText().strip()
519 if txt == '':
520 return
521 self.CopyText(len(txt), txt)
522
523
525 txt = self.GetText().strip()
526 if txt == '':
527 return
528 txt = self.__get_clipboard_text() + '\n' + txt
529 self.CopyText(len(txt), txt)
530
531
534
535
537 region = self.GetTextRange(self.SelectionStart, self.SelectionEnd)
538 if region.strip() == '':
539 return
540 txt = self.__get_clipboard_text() + '\n' + region
541 self.CopyText(len(txt), txt)
542
543
545 txt = self.GetLine(self.CurrentLine).strip()
546 if txt == '':
547 return
548 self.CopyText(len(txt), txt)
549
550
552 txt = self.GetLine(self.CurrentLine).strip()
553 if txt == '':
554 return
555 txt = self.__get_clipboard_text() + '\n' + txt
556 self.CopyText(len(txt), txt)
557
558
562
563
567
568
572
573
577
578
582
583
587
588
591
592
593
594
596 self.MarkerDelete(target, -1)
597 self.__set_markers_of_line(target, self.MarkerGet(source))
598
599
604
605
607 markers = self.MarkerGet(line)
608 for marker_num in cSoapSTC._SOAP_MARKER_NUMS:
609 if markers & (1 << marker_num):
610 return marker_num
611
612 return -1
613
614
622
623
624
656
657
663
664
666 self.__ensure_has_all_soap_types = False
667 self.sort_by_SOAP()
668
669
671 line_count = 0
672 line_w_marker = -1
673 while True:
674 line_w_marker = self.MarkerNext(line_w_marker + 1, (1 << marker))
675 if line_w_marker == -1:
676 break
677 line_count += 1
678 return line_count
679
680
684
685
686
687
689
690 if evt.HasModifiers():
691
692 evt.Skip()
693 return False
694
695 sel_start, sel_end = self.GetSelection()
696 if sel_start != sel_end:
697 evt.Skip()
698 sel_start_line = self.LineFromPosition(sel_start)
699 sel_end_line = self.LineFromPosition(sel_end)
700
701 if sel_start_line == sel_end_line:
702 return
703 sel_start_soap_marker = self.get_soap_marker_of_line(sel_start_line)
704 sel_end_soap_marker = self.get_soap_marker_of_line(sel_end_line)
705 if sel_start_soap_marker == sel_end_soap_marker:
706
707 return
708 self.__ensure_has_all_soap_types = True
709 return
710
711 curr_line = self.CurrentLine
712 if (curr_line + 1) == self.LineCount:
713
714
715
716
717 evt.Skip()
718 return False
719
720
721 caret_pos = self.GetColumn(self.CurrentPos)
722 max_pos = self.LineLength(curr_line) - 1
723 if caret_pos < max_pos:
724
725
726
727 evt.Skip()
728 return False
729
730 soap_marker_current_line = self.get_soap_marker_of_line(curr_line)
731 soap_marker_next_line = self.get_soap_marker_of_line(curr_line + 1)
732 if soap_marker_current_line == soap_marker_next_line:
733
734
735
736
737 evt.Skip()
738 return False
739
740
741
742
743
744
745
746
747 return True
748
749
751
752 if evt.HasModifiers():
753
754 evt.Skip()
755 return False
756
757 sel_start, sel_end = self.GetSelection()
758 if sel_start != sel_end:
759 evt.Skip()
760 sel_start_line = self.LineFromPosition(sel_start)
761 sel_end_line = self.LineFromPosition(sel_end)
762
763 if sel_start_line == sel_end_line:
764 return
765 sel_start_soap_marker = self.get_soap_marker_of_line(sel_start_line)
766 sel_end_soap_marker = self.get_soap_marker_of_line(sel_end_line)
767 if sel_start_soap_marker == sel_end_soap_marker:
768
769 return
770 self.__ensure_has_all_soap_types = True
771 return
772
773 curr_line = self.LineFromPosition(self.CurrentPos)
774 if curr_line == 0:
775
776 evt.Skip()
777 return False
778
779 if self.GetColumn(self.CurrentPos) > 0:
780
781 evt.Skip()
782 return False
783
784 soap_marker_current_line = self.get_soap_marker_of_line(curr_line)
785 soap_marker_next_line = self.get_soap_marker_of_line(curr_line - 1)
786 if soap_marker_current_line == soap_marker_next_line:
787
788
789
790
791 evt.Skip()
792 return False
793
794
795
796
797
798
799
800
801 return True
802
803
805
806 evt.Skip()
807 if evt.HasModifiers():
808
809 self.__markers_of_prev_line = None
810 return
811 self.__markers_of_prev_line = self.MarkerGet(self.CurrentLine)
812
813
829
830
832 if wx.MAJOR_VERSION > 2:
833 evt.Skip()
834 return
835
836
837 self.__show_context_menu(self.caret_coords_on_screen())
838
839
841 menu_position = evt.GetPosition()
842 if menu_position == wx.DefaultPosition:
843 caret_pos_in_stc = self.PointFromPosition(self.CurrentPos)
844 caret_pos_on_screen = self.ClientToScreen(caret_pos_in_stc)
845 menu_position = caret_pos_on_screen
846 self.__show_context_menu(menu_position)
847
848
849
850
852
853 self.Bind(wx.EVT_KEY_DOWN, self._on_key_down)
854
855 self.Bind(wx.EVT_CONTEXT_MENU, self._on_context_menu_activated)
856
857
858 self.Bind(wx.stc.EVT_STC_CHARADDED, self._on_stc_char_added)
859 self.Bind(wx.stc.EVT_STC_CHANGE, self._on_stc_change)
860
861
862
863
864
865
866
867
868
871
872
874
875
876 if self.__changing_SOAP_cat:
877 self.__handle_soap_category_key_down(chr(evt.GetUniChar()).lower(), self.CurrentLine)
878
879 return
880
881 key = evt.KeyCode
882
883
884 if key == wx.WXK_RETURN:
885 self.__handle_return_key_down(evt)
886 return
887
888
889 if key == wx.WXK_BACK:
890 self.__handle_backspace_key(evt)
891 return
892
893
894 if key == wx.WXK_DELETE:
895 self.__handle_delete_key(evt)
896 return
897
898
899 if key == wx.WXK_MENU:
900 self.__handle_menu_key_down(evt)
901 return
902
903
904 if key == ord('T'):
905 if evt.HasModifiers():
906 if evt.CmdDown():
907 self.__changing_SOAP_cat = True
908 return
909
910 evt.Skip()
911
912
914 evt.Skip()
915 key = evt.GetKey()
916 if key == 10:
917
918
919
920
921
922
923
924
925
926
927
928 if self.__markers_of_prev_line is None:
929 return
930 self.__set_markers_of_line(self.CurrentLine - 1, self.__markers_of_prev_line)
931 self.__set_markers_of_line(self.CurrentLine, self.__markers_of_prev_line)
932 self.__markers_of_prev_line = None
933 return
934
935
939
940
941
942
943
944
945
947
948
949 wx.TheClipboard.Flush()
950 evt.Skip()
951
952
954
955
956
957 if debug and evt.GetPosition() < 250:
958 evt.SetDragAllowMove(False)
959 evt.SetDragText("DRAGGED TEXT")
960
961
962
964
965
966
967
968
969 if debug and evt.GetPosition() < 250:
970 evt.SetDragResult(wx.DragNone)
971
972
974
975
976
977
978
979 if debug and evt.GetPosition() < 500:
980 evt.SetDragText("DROPPED TEXT")
981
982
983
984
985
986
987
988
990
991
992
993
994
995
996
997
998
999
1000 pass
1001
1002
1004 st = ""
1005 table = [(stc.STC_MOD_INSERTTEXT, "InsertText"),
1006 (stc.STC_MOD_DELETETEXT, "DeleteText"),
1007 (stc.STC_MOD_CHANGESTYLE, "ChangeStyle"),
1008 (stc.STC_MOD_CHANGEFOLD, "ChangeFold"),
1009 (stc.STC_PERFORMED_USER, "UserFlag"),
1010 (stc.STC_PERFORMED_UNDO, "Undo"),
1011 (stc.STC_PERFORMED_REDO, "Redo"),
1012 (stc.STC_LASTSTEPINUNDOREDO, "Last-Undo/Redo"),
1013 (stc.STC_MOD_CHANGEMARKER, "ChangeMarker"),
1014 (stc.STC_MOD_BEFOREINSERT, "B4-Insert"),
1015 (stc.STC_MOD_BEFOREDELETE, "B4-Delete")
1016 ]
1017
1018 for flag,text in table:
1019 if flag & modType:
1020 st = st + text + " "
1021
1022 if not st:
1023 st = 'UNKNOWN'
1024
1025 return st
1026
1027
1028
1029
1030 if wx.Platform == '__WXMSW__':
1031 face1 = 'Arial'
1032 face2 = 'Times New Roman'
1033 face3 = 'Courier New'
1034 pb = 12
1035 else:
1036 face1 = 'Helvetica'
1037 face2 = 'Times'
1038 face3 = 'Courier'
1039 pb = 14
1040
1041
1042 _USE_PANEL = 1
1043
1045 if not _USE_PANEL:
1046 ed = p = cSoapSTC(nb, -1)
1047
1048 else:
1049 p = wx.Panel(nb, -1, style=wx.NO_FULL_REPAINT_ON_RESIZE)
1050 ed = cSoapSTC(p, -1, log)
1051 s = wx.BoxSizer(wx.HORIZONTAL)
1052 s.Add(ed, 1, wx.EXPAND)
1053 p.SetSizer(s)
1054 p.SetAutoLayout(True)
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070 ed.SetText(demoText)
1071
1072 if wx.USE_UNICODE:
1073 import codecs
1074 decode = codecs.lookup("utf-8")[1]
1075
1076 ed.GotoPos(ed.GetLength())
1077 ed.AddText("\n\nwx.StyledTextCtrl can also do Unicode:\n")
1078 uniline = ed.GetCurrentLine()
1079 unitext, l = decode('\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd - '
1080 '\xd0\xbb\xd1\x83\xd1\x87\xd1\x88\xd0\xb8\xd0\xb9 '
1081 '\xd1\x8f\xd0\xb7\xd1\x8b\xd0\xba \xd0\xbf\xd1\x80\xd0\xbe\xd0\xb3\xd1\x80\xd0\xb0\xd0\xbc\xd0\xbc\xd0\xb8\xd1\x80\xd0\xbe\xd0\xb2\xd0\xb0\xd0\xbd\xd0\xb8\xd1\x8f!\n\n')
1082 ed.AddText('\tRussian: ')
1083 ed.AddText(unitext)
1084 ed.GotoPos(0)
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095 ed.EmptyUndoBuffer()
1096
1097
1098 ed.StyleSetSpec(stc.STC_STYLE_DEFAULT, "size:%d,face:%s" % (pb, face3))
1099 ed.StyleClearAll()
1100 ed.StyleSetSpec(1, "size:%d,bold,face:%s,fore:#0000FF" % (pb, face1))
1101 ed.StyleSetSpec(2, "face:%s,italic,fore:#FF0000,size:%d" % (face2, pb))
1102 ed.StyleSetSpec(3, "face:%s,bold,size:%d" % (face2, pb))
1103 ed.StyleSetSpec(4, "face:%s,size:%d" % (face1, pb-1))
1104
1105
1106
1107 ed.StartStyling(98, 0xff)
1108 ed.SetStyling(6, 1)
1109
1110 ed.StartStyling(190, 0xff)
1111 ed.SetStyling(20, 2)
1112
1113 ed.StartStyling(310, 0xff)
1114 ed.SetStyling(4, 3)
1115 ed.SetStyling(2, 0)
1116 ed.SetStyling(10, 4)
1117
1118
1119
1120 ed.SetMarginType(0, stc.STC_MARGIN_NUMBER)
1121 ed.SetMarginWidth(0, 22)
1122 ed.StyleSetSpec(stc.STC_STYLE_LINENUMBER, "size:%d,face:%s" % (pb-2, face1))
1123
1124
1125 ed.SetMarginType(1, stc.STC_MARGIN_SYMBOL)
1126 ed.MarkerDefine(0, stc.STC_MARK_ROUNDRECT, "#CCFF00", "RED")
1127 ed.MarkerDefine(1, stc.STC_MARK_CIRCLE, "FOREST GREEN", "SIENNA")
1128 ed.MarkerDefine(2, stc.STC_MARK_SHORTARROW, "blue", "blue")
1129 ed.MarkerDefine(3, stc.STC_MARK_ARROW, "#00FF00", "#00FF00")
1130
1131
1132 ed.MarkerAdd(17, 0)
1133 ed.MarkerAdd(18, 1)
1134 ed.MarkerAdd(19, 2)
1135 ed.MarkerAdd(20, 3)
1136 ed.MarkerAdd(20, 0)
1137
1138
1139
1140 ed.IndicatorSetStyle(0, stc.STC_INDIC_SQUIGGLE)
1141 ed.IndicatorSetForeground(0, wx.RED)
1142 ed.IndicatorSetStyle(1, stc.STC_INDIC_DIAGONAL)
1143 ed.IndicatorSetForeground(1, wx.BLUE)
1144 ed.IndicatorSetStyle(2, stc.STC_INDIC_STRIKE)
1145 ed.IndicatorSetForeground(2, wx.RED)
1146
1147 ed.StartStyling(836, stc.STC_INDICS_MASK)
1148 ed.SetStyling(10, stc.STC_INDIC0_MASK)
1149 ed.SetStyling(8, stc.STC_INDIC1_MASK)
1150 ed.SetStyling(10, stc.STC_INDIC2_MASK | stc.STC_INDIC1_MASK)
1151
1152
1153
1154 if debug:
1155 print("GetTextLength(): ", ed.GetTextLength(), len(ed.GetText()))
1156 print("GetText(): ", repr(ed.GetText()))
1157 print()
1158 print("GetStyledText(98, 104): ", repr(ed.GetStyledText(98, 104)), len(ed.GetStyledText(98, 104)))
1159 print()
1160 print("GetCurLine(): ", repr(ed.GetCurLine()))
1161 ed.GotoPos(5)
1162 print("GetCurLine(): ", repr(ed.GetCurLine()))
1163 print()
1164 print("GetLine(1): ", repr(ed.GetLine(1)))
1165 print()
1166 ed.SetSelection(25, 35)
1167 print("GetSelectedText(): ", repr(ed.GetSelectedText()))
1168 print("GetTextRange(25, 35): ", repr(ed.GetTextRange(25, 35)))
1169 print("FindText(0, max, 'indicators'): ", end=' ')
1170 print(ed.FindText(0, ed.GetTextLength(), "indicators"))
1171 if wx.USE_UNICODE:
1172 end = ed.GetLength()
1173 start = ed.PositionFromLine(uniline)
1174 print("GetTextRange(%d, %d): " % (start, end), end=' ')
1175 print(repr(ed.GetTextRange(start, end)))
1176
1177
1178 wx.CallAfter(ed.GotoPos, 0)
1179 return p
1180
1181
1182
1183 overview = """\
1184 <html><body>
1185 Once again, no docs yet. <b>Sorry.</b> But <a href="data/stc.h.html">this</a>
1186 and <a href="http://www.scintilla.org/ScintillaDoc.html">this</a> should
1187 be helpful.
1188 </body><html>
1189 """
1190
1191
1192
1193
1194 if __name__ == '__main__':
1195
1196 if len(sys.argv) < 2:
1197 sys.exit()
1198
1199 if sys.argv[1] != 'test':
1200 sys.exit()
1201
1202 import wx.lib.colourdb
1203
1204 from Gnumed.pycommon import gmI18N
1205 gmI18N.activate_locale()
1206 gmI18N.install_domain(domain = 'gnumed')
1207
1208
1210 app = wx.PyWidgetTester(size = (600, 600))
1211 wx.lib.colourdb.updateColourDB()
1212
1213 app.SetWidget(cSoapSTC, -1, (100,50))
1214 app.MainLoop()
1215 return True
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225 test_stc()
1226