TextViewer.py
changeset 64 dd6f693e46a1
parent 58 39cd981ff242
child 68 66308e07402c
--- a/TextViewer.py	Tue Aug 07 17:37:38 2007 +0200
+++ b/TextViewer.py	Tue Aug 07 17:38:48 2007 +0200
@@ -22,9 +22,8 @@
 #License along with this library; if not, write to the Free Software
 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-from wxPython.wx import *
-from wxPython.stc import * 
 import wx
+import wx.stc
 from types import *
 
 import re
@@ -41,11 +40,11 @@
     LETTERS.append(chr(ord('a') + i))
     LETTERS.append(chr(ord('A') + i))
 
-[wxSTC_PLC_WORD, wxSTC_PLC_COMMENT, wxSTC_PLC_NUMBER, wxSTC_PLC_VARIABLE, 
- wxSTC_PLC_FUNCTION, wxSTC_PLC_JUMP] = range(6)
+[STC_PLC_WORD, STC_PLC_COMMENT, STC_PLC_NUMBER, STC_PLC_VARIABLE, 
+ STC_PLC_FUNCTION, STC_PLC_JUMP] = range(6)
 [SPACE, WORD, NUMBER, COMMENT] = range(4)
 
-[wxID_TEXTVIEWER,
+[ID_TEXTVIEWER,
 ] = [wx.NewId() for _init_ctrls in range(1)]
 
 if wx.Platform == '__WXMSW__':
@@ -90,39 +89,39 @@
     else:
         return None
 
-class TextViewer(wxStyledTextCtrl):
+class TextViewer(wx.stc.StyledTextCtrl):
     
     def __init__(self, parent, window, controler):
-        wxStyledTextCtrl.__init__(self, parent, wxID_TEXTVIEWER, style=0)
-        
-        self.CmdKeyAssign(ord('+'), wxSTC_SCMOD_CTRL, wxSTC_CMD_ZOOMIN)
-        self.CmdKeyAssign(ord('-'), wxSTC_SCMOD_CTRL, wxSTC_CMD_ZOOMOUT)
+        wx.stc.StyledTextCtrl.__init__(self, parent, ID_TEXTVIEWER, style=0)
+        
+        self.CmdKeyAssign(ord('+'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMIN)
+        self.CmdKeyAssign(ord('-'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMOUT)
         
         self.SetViewWhiteSpace(False)
         
-        self.SetLexer(wxSTC_LEX_CONTAINER)
+        self.SetLexer(wx.stc.STC_LEX_CONTAINER)
         
         # Global default styles for all languages
-        self.StyleSetSpec(wxSTC_STYLE_DEFAULT, "face:%(mono)s,size:%(size)d" % faces)
+        self.StyleSetSpec(wx.stc.STC_STYLE_DEFAULT, "face:%(mono)s,size:%(size)d" % faces)
         self.StyleClearAll()  # Reset all to be like the default
         
-        self.StyleSetSpec(wxSTC_STYLE_LINENUMBER,  "back:#C0C0C0,size:%(size)d" % faces)
+        self.StyleSetSpec(wx.stc.STC_STYLE_LINENUMBER,  "back:#C0C0C0,size:%(size)d" % faces)
         self.SetSelBackground(1, "#E0E0E0")
         
         # Highlighting styles
-        self.StyleSetSpec(wxSTC_PLC_WORD, "fore:#00007F,bold,size:%(size)d" % faces)
-        self.StyleSetSpec(wxSTC_PLC_VARIABLE, "fore:#7F0000,size:%(size)d" % faces)
-        self.StyleSetSpec(wxSTC_PLC_FUNCTION, "fore:#7F7F00,size:%(size)d" % faces)
-        self.StyleSetSpec(wxSTC_PLC_COMMENT, "fore:#7F7F7F,size:%(size)d" % faces)
-        self.StyleSetSpec(wxSTC_PLC_NUMBER, "fore:#007F7F,size:%(size)d" % faces)
-        self.StyleSetSpec(wxSTC_PLC_JUMP, "fore:#007F00,size:%(size)d" % faces)
+        self.StyleSetSpec(STC_PLC_WORD, "fore:#00007F,bold,size:%(size)d" % faces)
+        self.StyleSetSpec(STC_PLC_VARIABLE, "fore:#7F0000,size:%(size)d" % faces)
+        self.StyleSetSpec(STC_PLC_FUNCTION, "fore:#7F7F00,size:%(size)d" % faces)
+        self.StyleSetSpec(STC_PLC_COMMENT, "fore:#7F7F7F,size:%(size)d" % faces)
+        self.StyleSetSpec(STC_PLC_NUMBER, "fore:#007F7F,size:%(size)d" % faces)
+        self.StyleSetSpec(STC_PLC_JUMP, "fore:#007F00,size:%(size)d" % faces)
         
         # Indicators styles
-        self.IndicatorSetStyle(0, wxSTC_INDIC_SQUIGGLE)
-        self.IndicatorSetForeground(0, wxRED)
+        self.IndicatorSetStyle(0, wx.stc.STC_INDIC_SQUIGGLE)
+        self.IndicatorSetForeground(0, wx.RED)
         
         # Line numbers in the margin
-        self.SetMarginType(1, wxSTC_MARGIN_NUMBER)
+        self.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER)
         self.SetMarginWidth(1, 50)
         
         # Indentation size
@@ -141,26 +140,26 @@
         self.Parent = window
         self.Controler = controler
 
-        self.SetModEventMask(wxSTC_MOD_BEFOREINSERT|wxSTC_MOD_BEFOREDELETE)
-
-        EVT_KEY_DOWN(self, self.OnKeyDown)
-        EVT_STC_STYLENEEDED(self, wxID_TEXTVIEWER, self.OnStyleNeeded)
-        EVT_STC_DO_DROP(self, wxID_TEXTVIEWER, self.OnDoDrop)
-        EVT_KILL_FOCUS(self, self.OnKillFocus)
-        EVT_STC_MODIFIED(self, wxID_TEXTVIEWER, self.OnModification)
+        self.SetModEventMask(wx.stc.STC_MOD_BEFOREINSERT|wx.stc.STC_MOD_BEFOREDELETE)
+
+        self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
+        self.Bind(wx.stc.EVT_STC_STYLENEEDED, self.OnStyleNeeded, id=ID_TEXTVIEWER)
+        self.Bind(wx.stc.EVT_STC_DO_DROP, self.OnDoDrop, id=ID_TEXTVIEWER)
+        self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
+        self.Bind(wx.stc.EVT_STC_MODIFIED, self.OnModification, id=ID_TEXTVIEWER)
     
     def OnModification(self, event):
         if not self.DisableEvents:
             mod_type = event.GetModificationType()
-            if not (mod_type&wxSTC_PERFORMED_UNDO or mod_type&wxSTC_PERFORMED_REDO):
-                if mod_type&wxSTC_MOD_BEFOREINSERT:
+            if not (mod_type&wx.stc.STC_PERFORMED_UNDO or mod_type&wx.stc.STC_PERFORMED_REDO):
+                if mod_type&wx.stc.STC_MOD_BEFOREINSERT:
                     if self.CurrentAction == None:
                         self.StartBuffering()
                     elif self.CurrentAction[0] != "Add" or self.CurrentAction[1] != event.GetPosition() - 1:
                         self.Controler.EndBuffering()
                         self.StartBuffering()
                     self.CurrentAction = ("Add", event.GetPosition())
-                elif mod_type&wxSTC_MOD_BEFOREDELETE:
+                elif mod_type&wx.stc.STC_MOD_BEFOREDELETE:
                     if self.CurrentAction == None:
                         self.StartBuffering()
                     elif self.CurrentAction[0] != "Delete" or self.CurrentAction[1] != event.GetPosition() + 1:
@@ -256,23 +255,23 @@
             line += char
             if char == NEWLINE:
                 if state == COMMENT:
-                    self.SetStyling(i - start_pos + 1, wxSTC_PLC_COMMENT)
+                    self.SetStyling(i - start_pos + 1, STC_PLC_COMMENT)
                 elif state == NUMBER:
-                    self.SetStyling(i - start_pos, wxSTC_PLC_NUMBER)
+                    self.SetStyling(i - start_pos, STC_PLC_NUMBER)
                 elif state == WORD:
                     if word in self.Keywords:
-                        self.SetStyling(i - start_pos, wxSTC_PLC_WORD)
+                        self.SetStyling(i - start_pos, STC_PLC_WORD)
                     elif word in self.Variables:
-                        self.SetStyling(i - start_pos, wxSTC_PLC_VARIABLE)
+                        self.SetStyling(i - start_pos, STC_PLC_VARIABLE)
                     elif word in self.Functions:
-                        self.SetStyling(i - start_pos, wxSTC_PLC_FUNCTION)
+                        self.SetStyling(i - start_pos, STC_PLC_FUNCTION)
                     elif word in self.Jumps:
-                        self.SetStyling(i - start_pos, wxSTC_PLC_JUMP)
+                        self.SetStyling(i - start_pos, STC_PLC_JUMP)
                     else:
                         self.SetStyling(i - start_pos, 31)
                         if self.GetCurrentPos() < start_pos or self.GetCurrentPos() > i:
-                            self.StartStyling(start_pos, wxSTC_INDICS_MASK)
-                            self.SetStyling(i - start_pos, wxSTC_INDIC0_MASK)
+                            self.StartStyling(start_pos, wx.stc.STC_INDICS_MASK)
+                            self.SetStyling(i - start_pos, wx.stc.STC_INDIC0_MASK)
                             self.StartStyling(i, 0xff)    
                 else:
                     self.SetStyling(i - start_pos, 31)
@@ -285,7 +284,7 @@
                 state = COMMENT
             elif state == COMMENT:
                 if line.endswith("*)"):
-                    self.SetStyling(i - start_pos + 2, wxSTC_PLC_COMMENT)
+                    self.SetStyling(i - start_pos + 2, STC_PLC_COMMENT)
                     start_pos = i + 1
                     state = SPACE
             elif char in LETTERS:
@@ -309,40 +308,40 @@
             else:
                 if state == WORD:
                     if word in self.Keywords:
-                        self.SetStyling(i - start_pos, wxSTC_PLC_WORD)
+                        self.SetStyling(i - start_pos, STC_PLC_WORD)
                     elif word in self.Variables:
-                        self.SetStyling(i - start_pos, wxSTC_PLC_VARIABLE)
+                        self.SetStyling(i - start_pos, STC_PLC_VARIABLE)
                     elif word in self.Functions:
-                        self.SetStyling(i - start_pos, wxSTC_PLC_FUNCTION)
+                        self.SetStyling(i - start_pos, STC_PLC_FUNCTION)
                     elif word in self.Jumps:
-                        self.SetStyling(i - start_pos, wxSTC_PLC_JUMP)
+                        self.SetStyling(i - start_pos, STC_PLC_JUMP)
                     else:
                         self.SetStyling(i - start_pos, 31)
                         if self.GetCurrentPos() < start_pos or self.GetCurrentPos() > i:
-                            self.StartStyling(start_pos, wxSTC_INDICS_MASK)
-                            self.SetStyling(i - start_pos, wxSTC_INDIC0_MASK)
+                            self.StartStyling(start_pos, wx.stc.STC_INDICS_MASK)
+                            self.SetStyling(i - start_pos, wx.stc.STC_INDIC0_MASK)
                             self.StartStyling(i, 0xff)
                     word = ""
                     start_pos = i
                     state = SPACE
                 elif state == NUMBER:
-                    self.SetStyling(i - start_pos, wxSTC_PLC_NUMBER)
+                    self.SetStyling(i - start_pos, STC_PLC_NUMBER)
                     start_pos = i
                     state = SPACE
             i += 1
         if state == COMMENT:
-            self.SetStyling(i - start_pos + 2, wxSTC_PLC_COMMENT)
+            self.SetStyling(i - start_pos + 2, STC_PLC_COMMENT)
         elif state == NUMBER:
-            self.SetStyling(i - start_pos, wxSTC_PLC_NUMBER)
+            self.SetStyling(i - start_pos, STC_PLC_NUMBER)
         elif state == WORD:
             if word in self.Keywords:
-                self.SetStyling(i - start_pos, wxSTC_PLC_WORD)
+                self.SetStyling(i - start_pos, STC_PLC_WORD)
             elif word in self.Variables:
-                self.SetStyling(i - start_pos, wxSTC_PLC_VARIABLE)
+                self.SetStyling(i - start_pos, STC_PLC_VARIABLE)
             elif word in self.Functions:
-                self.SetStyling(i - start_pos, wxSTC_PLC_FUNCTION)
+                self.SetStyling(i - start_pos, STC_PLC_FUNCTION)
             elif word in self.Jumps:
-                self.SetStyling(i - start_pos, wxSTC_PLC_JUMP)
+                self.SetStyling(i - start_pos, STC_PLC_JUMP)
             else:
                 self.SetStyling(i - start_pos, 31)
         else:
@@ -351,15 +350,15 @@
     
     def Cut(self):
         self.ResetBuffer()
-        self.CmdKeyExecute(wxSTC_CMD_CUT)
+        self.CmdKeyExecute(wx.stc.STC_CMD_CUT)
         self.RefreshBuffer()
     
     def Copy(self):
-        self.CmdKeyExecute(wxSTC_CMD_COPY)
+        self.CmdKeyExecute(wx.stc.STC_CMD_COPY)
     
     def Paste(self):
         self.ResetBuffer()
-        self.CmdKeyExecute(wxSTC_CMD_PASTE)
+        self.CmdKeyExecute(wx.stc.STC_CMD_PASTE)
         self.RefreshBuffer()
     
     def RefreshModel(self):
@@ -373,7 +372,7 @@
         key = event.KeyCode()
 
         # Code completion
-        if key == WXK_SPACE and event.ControlDown():
+        if key == wx.WXK_SPACE and event.ControlDown():
             
             line = self.GetCurrentLine()
             if line == 0:
@@ -406,7 +405,7 @@
                 self.AutoCompShow(len(words[-1]), " ".join(kw))
         else:
             self.TextChanged = False
-            wxCallAfter(self.RefreshModel)
+            wx.CallAfter(self.RefreshModel)
             event.Skip()
 
     def OnKillFocus(self, event):