Update of /cvsroot/pymerase/smw/smw/mathedit/medit
In directory sc8-pr-cvs1:/tmp/cvs-serv32238/smw/mathedit/medit
Added Files:
CmdList_CompoundCommand.py CmdList_Document.py
CmdList_Editor.py CmdList_InsertTextCommand.py
CmdList_RemoveTextCommand.py Command_Command.py
Derivation_Document.py Derivation_Editor.py
Derivation_Sidebar.py Edit_Document.py Edit_Editor.py
Formula_Document.py Formula_Editor.py Formula_Exceptions.py
Formula_FormatCommand.py Formula_FormatLineCommand.py
Formula_NameRuleCommand.py Highlight_Editor.py
Highlight_LangHighlighter.py Highlight_SyntaxHighlighter.py
MTextEdit.py Makefile Message.py Outline1_Document.py
Outline1_Editor.py Outline1_IndentCommand.py
Outline1_RemoveTextCommand.py Outline2_Editor.py
Outline2_Sidebar.py Preferences.py ProfileDefs.py
Profile_Document.py Profile_Editor.py Progress.py Resources.py
Text_Document.py Text_Editor.py Text_Symbols.py __init__.py
Log Message:
Imported version of SMW downloaded on 2003 Apr 14
--- NEW FILE: CmdList_CompoundCommand.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: CmdList_Document.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: CmdList_Editor.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: CmdList_InsertTextCommand.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: CmdList_RemoveTextCommand.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Command_Command.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Derivation_Document.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Derivation_Editor.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Derivation_Sidebar.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Edit_Document.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Edit_Editor.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Formula_Document.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Formula_Editor.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Formula_Exceptions.py ---
class LexicalException( Exception ):
pass
class SyntaxException( Exception ):
pass
class UnparseException( Exception ):
pass
--- NEW FILE: Formula_FormatCommand.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Formula_FormatLineCommand.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Formula_NameRuleCommand.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Highlight_Editor.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Highlight_LangHighlighter.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Highlight_SyntaxHighlighter.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: MTextEdit.py ---
import Preferences
# load preferences, also creates ~/.mathedit if necessary
Preferences.loadPreferences()
from Highlight_Editor import Highlight_Editor
from Outline2_Sidebar import Outline2_Sidebar
from Highlight_LangHighlighter import *
from qt import *
HighlightModes = { "python": Python_Highlighter,
"spython": SPython_Highlighter,
"c": C_Highlighter,
"c++": Cpp_Highlighter,
"java": Java_Highlighter }
# MTextEdit generally mimics the interface of QTextEdit, most methods are
# simple wrappers to calls in __editor and __editor.getDocument(). Until
# am interface is defined, methods will just be added as they are needed.
# Implementation of automatic delegation through __getattr__ was unsuccessful
# due to the fact that Qt methods are not listen in objects' __dict__.
# Note that signals from QTextEdit are forwarded as PYSIGNALs. The following
# signals are emitted:
# textChanged()
# selectionChanged()
# cursorPositionChanged( int para, int column )
# returnPressed()
# copyAvailable( bool )
# undoAvailable( bool )
# redoAvailable( bool )
class MTextEdit( QWidget ):
def __init__( self, medit=None, parent=None, name=None ):
QWidget.__init__( self, parent, name )
if medit:
doc = medit.__editor.getDocument()
else:
doc = None
self.__editor = Highlight_Editor(doc,self,name)
self.__sidebar = Outline2_Sidebar(self.__editor,self)
self.connect(self.__editor,SIGNAL('textChanged()'),
PYSIGNAL('textChanged'))
self.connect(self.__editor,SIGNAL('selectionChanged()'),
PYSIGNAL('selectionChanged'))
self.connect(self.__editor,SIGNAL('cursorPositionChanged( int, int )'),
PYSIGNAL('cursorPositionChanged'))
self.connect(self.__editor,SIGNAL('returnPressed()'),
PYSIGNAL('returnPressed'))
self.connect(self.__editor,SIGNAL('copyAvailable( bool )'),
PYSIGNAL('copyAvailable'))
self.__layout = QHBoxLayout(self)
self.__layout.addWidget(self.__sidebar)
self.__layout.addWidget(self.__editor)
self.__editor.setAutoParse(0)
def showSidebar( self, yes=1 ):
if yes:
self.__sidebar.show()
else:
self.__sidebar.hide()
def setSidebarWidth( self, width ):
self.__sidebar.setWidth(width)
def getSidebarWidth( self ):
return self.__sidebar.width()
def setIndentationWidth( self, w ):
self.__editor.setIndentationWidth(w)
def getIndentationWidth( self ):
return self.__editor.getIndentationWidth()
def getHighlightMode( self ):
mode = self.__editor.setHighlightMode(HighlightModes[mode])
for str in HighlightModes:
if mode==HighlightModes[str]:
return str
return ''
def setHighlightMode( self, mode ):
ms = unicode(mode)
for mstr in HighlightModes.keys():
if mstr.lower()==ms.lower():
self.__editor.setHighlightMode(HighlightModes[mstr])
return
self.__editor.setHighlightMode(None)
def setEdited( self, e ):
self.__editor.getDocument().setDirty(e)
def edited( self ):
return self.__editor.getDocument().isDirty()
### The following methods wrap methods in the delegatee (self.__editor)
def insertAt( self, text, para, index ):
self.__editor.getDocument().insertExternalText(para,index,text)
def setSelection( self, paraFrom, indexFrom, paraTo, indexTo, selNum=0 ):
l1 = self.__editor._dl2vl(paraFrom)
l2 = self.__editor._dl2vl(paraTo)
l1,c1,l2,c2 = self.__editor.docStrip2ViewStrip(paraFrom,indexFrom,
paraTo,indexTo)
self.__editor.setSelection(l1,c1,l2,c2,selNum)
def getSelection( self, selNum=0 ):
return self.__editor.getSelection(selNum)
def removeSelection( self, selNum=0 ):
self.__editor.removeSelection(selNum)
def removeSelectedText( self, selNum=0 ):
sel = self.__editor.getSelection(selNum)
if sel[0]==-1:
return
sel = apply(self.__editor.docStrip2ViewStrip,sel)
apply(self.__editor.getDocument().deleteStrip,sel)
def selectedText( self ):
sel = self.__editor.getSelection()
if sel[0]==-1:
return QString()
sel = apply(self.__editor.docStrip2ViewStrip,sel)
return apply(self.__editor.getDocument().getTextStrip,sel)
def hasSelectedText( self ):
return self.__editor.hasSelectedText()
def setCursorPosition( self, para, index ):
self.__editor.setCursorPosition(para,index)
def getCursorPosition( self ):
return self.__editor.getCursorPosition()
def paragraphs( self ):
return self.__editor.getDocument().lines()
def text( self, para=-1 ):
if para==-1:
return self.__editor.getDocument().getText()
else:
s = QString()
s.append('\t'*self.__editor.getDocument().getLineLevel(para))
s.append(self.__editor.getDocument().getLineText(para))
return s
def setText( self, txt ):
# This should work, but crashes on Windows. The error is possibly
# buried deep within the Editor class hierarchy.
#self.__editor.getDocument().setText(txt)
self.clear()
self.append(txt)
def paragraphLength( self, para ):
return (self.__editor.getDocument().getLineLevel(para) +
self.__editor.getDocument().getLineTextLen(para))
def setFont( self, f ):
self.__editor.setFont(f)
def append( self, text ):
dl = self.__editor.getDocument().lines()-1
dc = self.__editor.getDocument().getLineTextLen(dl)
self.__editor.getDocument().insertExternalText(dl,dc,text)
def setWordWrap( self, w ):
self.__editor.setWordWrap(w)
def wordWrap( self ):
return self.__editor.wordWrap()
def clear( self ):
self.__editor.getDocument().setText()
def undo( self ):
couldUndo = self.__editor.getDocument().canUndo()
couldRedo = self.__editor.getDocument().canRedo()
self.__editor.undo()
if couldUndo and not self.__editor.getDocument().canUndo():
self.emit(PYSIGNAL('undoAvailable'),(0,))
if not couldRedo and self.__editor.getDocument().canRedo():
self.emit(PYSIGNAL('redoAvailable'),(1,))
def redo( self ):
couldUndo = self.__editor.getDocument().canUndo()
couldRedo = self.__editor.getDocument().canRedo()
self.__editor.redo()
if not couldUndo and self.__editor.getDocument().canUndo():
self.emit(PYSIGNAL('undoAvailable'),(1,))
if couldRedo and not self.__editor.getDocument().canRedo():
self.emit(PYSIGNAL('redoAvailable'),(0,))
def cut( self ): self.__editor.cut()
def copy( self ): self.__editor.copy()
def paste( self ): self.__editor.paste()
def removeParagraph( self, para ):
raise ("Do not just remove paragraphs, it can be illegal under strict "
+"outlining! Read doc/Warning if you don't understand why")
def insertParagraph( self, text, para ):
if para==-1:
self.append("\n"+unicode(text))
else:
self.__editor.getDocument().insertExternalText(para,0,
unicode(text)+"\n")
def setReadOnly( self, yes=1 ):
self.__editor.setReadOnly(yes)
def readOnly( self ):
return self.__editor.readOnly()
--- NEW FILE: Makefile ---
clean:
rm -f *.pyc *.pyo
--- NEW FILE: Message.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Outline1_Document.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Outline1_Editor.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Outline1_IndentCommand.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Outline1_RemoveTextCommand.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Outline2_Editor.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Outline2_Sidebar.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Preferences.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: ProfileDefs.py ---
from Formula_Exceptions import *
from Derivation_Document import Derivation_MathRule
Rule = Derivation_MathRule
--- NEW FILE: Profile_Document.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Profile_Editor.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Progress.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Resources.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Text_Document.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Text_Editor.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Text_Symbols.py ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: __init__.py ---
|