2 :author: Dr. Gunnar Schwant
3 :contact: g.schwant@gmx.de
7 import os
, throbimages
, time
8 from wxPython
.wx
import *
9 from wxPython
.stc
import *
10 from docutilsadapter
import get_rest_bibl_fields
11 from docutilsadapter
import get_rest_directives
12 from dialogs
import customMsgBox
13 from shutil
import copyfile
15 if wxPlatform
== '__WXMSW__':
16 faces
= { 'times': 'Times New Roman',
17 'mono' : 'Courier New',
19 'other': 'Comic Sans MS',
24 faces
= { 'times': 'Times',
27 'other': 'new century schoolbook',
32 #---------------------------------------------------------------------------
34 class CustomStyledTextCtrl(wxStyledTextCtrl
):
35 def __init__(self
, parent
, ID
, log
):
36 wxStyledTextCtrl
.__init
__(self
, parent
, ID
)
39 self
.CmdKeyAssign(ord('L'), wxSTC_SCMOD_CTRL
, wxSTC_CMD_ZOOMIN
)
40 self
.CmdKeyAssign(ord('K'), wxSTC_SCMOD_CTRL
, wxSTC_CMD_ZOOMOUT
)
41 self
.SetEdgeMode(wxSTC_EDGE_LINE
)
42 self
.SetEdgeColour(wxColour(175,255,255))
43 self
.SetEdgeColumn(75)
46 self
.SetEOLMode(wxSTC_EOL_LF
)
50 EVT_STC_MODIFIED(self
, ID
, self
.OnModified
)
51 EVT_CHAR(self
, self
.OnChar
)
53 # lists for autocompletion:
54 self
.bibliographic_fields
= get_rest_bibl_fields()
55 self
.directives
= get_rest_directives()
62 self
.StyleSetSpec(wxSTC_STYLE_DEFAULT
, 'face:%(mono)s,size:%(size)d' % faces
)
63 self
.StyleSetSpec(1, 'face:%(mono)s,bold,fore:#0000FF,size:%(size)d' % faces
)
64 self
.StyleSetSpec(2, 'face:%(mono)s,italic,fore:#FF0000,size:%(size)d' % faces
)
65 self
.StyleSetSpec(3, 'face:%(mono)s,bold,size:%(size)d' % faces
)
66 self
.StyleSetSpec(4, 'face:%(mono)s,size:%(size)d' % faces
)
67 self
.StyleSetSpec(wxSTC_STYLE_CONTROLCHAR
, 'face:%(other)s' % faces
)
69 # line numbers in the margin
70 self
.StyleSetSpec(wxSTC_STYLE_LINENUMBER
,
71 'back:#C0C0C0,face:%(helv)s,size:%(size2)d' % faces
)
72 self
.SetMarginType(0, wxSTC_MARGIN_NUMBER
)
73 self
.SetMarginWidth(0, 3*faces
['size']-2)
76 self
.SetMarginType(1, wxSTC_MARGIN_SYMBOL
)
77 self
.MarkerDefine(0, wxSTC_MARK_CIRCLE
, 'RED', '#FFFF00')
78 self
.MarkerDefine(1, wxSTC_MARK_CIRCLE
, '#FFFF00', 'RED')
80 def OnChar(self
, event
):
82 currpos
= self
.GetCurrentPos()
83 currcol
= self
.GetColumn(currpos
)
84 if currcol
== 0 and key
== ord(':'):
86 self
.AutoCompShow(0, self
.bibliographic_fields
)
87 elif currcol
== 2 and key
== ord(' '):
88 if self
.GetCharAt(currpos
- 1) == self
.GetCharAt(currpos
- 2) == ord('.'):
90 self
.AutoCompShow(0, self
.directives
)
96 def OnModified(self
, evt
):
99 def set_lexer(self
, ext
):
100 lexer
= self
.GetLexer()
101 if ext
== '.html' or ext
== '.htm':
102 if lexer
!= wxSTC_LEX_HTML
:
103 self
.SetLexer(wxSTC_LEX_HTML
)
105 if lexer
!= wxSTC_LEX_NULL
:
106 self
.SetLexer(wxSTC_LEX_NULL
)
108 def LoadFile(self
, filename
):
112 f
= open(filename
, 'rt')
115 ext
= os
.path
.splitext(filename
)[1]
118 self
.EmptyUndoBuffer()
122 customMsgBox(self
, '%s:\n%s\n%s' % sys
.exc_info(), 'error')
126 def SaveFile(self
, filename
, backup
=0):
132 copyfile(filename
, '%s.bak' % filename
)
133 f
= open(filename
, 'w')
134 f
.write(self
.GetText())
139 customMsgBox(self
, 'Error when saving "%s".\n\n%s:\n%s\n%s' \
140 % (filename
, sys
.exc_info()[0], sys
.exc_info()[1],
151 #---------------------------------------------------------------------------
153 class CustomStatusBar(wxStatusBar
):
154 def __init__(self
, parent
):
155 wxStatusBar
.__init
__(self
, parent
, -1)
156 self
.SetFieldsCount(2)
157 self
.SetStatusWidths([-1,150])
159 self
.SetStatusText('Ready', 0)
162 self
.timer
= wxPyTimer(self
.Notify
)
163 self
.timer
.Start(1000)
168 t
= time
.localtime(time
.time())
169 st
= time
.strftime(" %d-%b-%Y %H:%M:%S", t
)
170 self
.SetStatusText(st
, 1)
172 #---------------------------------------------------------------------------
174 class CustomTreeCtrl(wxTreeCtrl
):
176 def OnCompareItems(self
, item1
, item2
):
177 t1
= self
.GetItemText(item1
)
178 t2
= self
.GetItemText(item2
)
179 #self.log.WriteText('compare: ' + t1 + ' <> ' + t2 + '\n')
180 if t1
< t2
: return -1
181 if t1
== t2
: return 0