@ -77,9 +77,6 @@ class _TTkTextEditViewLineNumber(TTkAbstractScrollView):
else :
return self . size ( )
def viewDisplayedSize ( self ) - > ( int , int ) :
return self . size ( )
def paintEvent ( self , canvas ) :
if not self . _textWrap : return
_ , oy = self . getViewOffsets ( )
@ -104,7 +101,62 @@ class _TTkTextEditViewLineNumber(TTkAbstractScrollView):
canvas . drawChar ( pos = ( w - 1 , y ) , char = ' ▌ ' , color = separatorColor )
class TTkTextEditView ( TTkAbstractScrollView ) :
''' TTkTextEditView '''
'''
: py : class : ` TTkTextEditView `
: :
╔ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ╗
║ 0 ▌ " Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor ╥ ║
║ < ▌ incididunt ut labore et dolore magna aliqua . ║ ║
║ 1 ▌ ║ ║
║ 2 ▌ Ut enim ad minim veniam , quis nostrud exercitation ullamco laboris nisi ut aliqu ║ ║
║ < ▌ ip ex ea commodo consequat . Duis aute irure dolor in reprehenderit in voluptate ║ ║
║ < ▌ velit esse cillum dolore eu fugiat nulla pariatur . ║ ║
║ 3 ▌ ║ ║
║ 4 ▌ Excepteur sint occaecat cupidatat non proident , sunt in culpa qui officia deseru ║ ║
║ < ▌ nt mollit anim id est laborum . " ╨ ║
╚ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ╝
Demo : ` textedit . py < https : / / github . com / ceccopierangiolieugenio / pyTermTk / blob / main / demo / showcase / textedit . py > ` _
( ` Try Online < https : / / ceccopierangiolieugenio . github . io / pyTermTk / sandbox / sandbox . html ? fileUri = https : / / raw . githubusercontent . com / ceccopierangiolieugenio / pyTermTk / main / demo / showcase / textedit . py > ` __ )
` ttkdesigner Tutorial < https : / / github . com / ceccopierangiolieugenio / pyTermTk / blob / main / tutorial / ttkDesigner / textEdit > ` _
'''
currentColorChanged : pyTTkSignal
'''
This signal is emitted if the current character color has changed ,
for example caused by a change of the cursor position .
: param color : the new color
: type color : : py : class : ` TTkColor `
'''
undoAvailable : pyTTkSignal
'''
This signal is emitted whenever undo operations become available ( available is true )
or unavailable ( available is false ) .
: param available : the availability of undo
: type available : bool
'''
redoAvailable : pyTTkSignal
'''
This signal is emitted whenever redo operations become available ( available is true )
or unavailable ( available is false ) .
: param available : the availability of redo
: type available : bool
'''
textChanged : pyTTkSignal
'''
This signal is emitted whenever the document ' s content changes;
for example , when text is inserted or deleted , or when formatting is applied .
'''
classStyle = {
' default ' : { ' color ' : TTkColor . fg ( " #dddddd " ) + TTkColor . bg ( " #222222 " ) ,
@ -135,24 +187,38 @@ class TTkTextEditView(TTkAbstractScrollView):
' undoAvailable ' , ' redoAvailable ' ,
' textChanged '
)
'''
in order to support the line wrap , I need to divide the full data text in ;
_textDocument = the entire text divided in lines , easy to add / remove / append lines
_textWrap . _lines = an array of tuples for each displayed line with a pointer to a
specific line and its slice to be shown at this coordinate ;
[ ( line , ( posFrom , posTo ) ) , . . . ]
This is required to support the wrap feature
'''
# in order to support the line wrap, I need to divide the full data text in ;
# _textDocument = the entire text divided in lines, easy to add/remove/append lines
# _textWrap._lines = an array of tuples for each displayed line with a pointer to a
# specific line and its slice to be shown at this coordinate;
# [ (line, (posFrom, posTo)), ... ]
# This is required to support the wrap feature
def __init__ ( self , * ,
readOnly : bool = False ,
multiLine : bool = True ,
document : TTkTextDocument = None ,
* * kwargs ) - > None :
super ( ) . __init__ ( * * kwargs )
'''
: param lineNumber : Show the line number on the left , defaults to * * False * *
: type lineNumber : bool , optional
: param readOnly : In a read - only text edit the user can only navigate through the text and select text ; modifying the text is not possible , defaults to * * True * *
: type readOnly : bool , optional
: param multiLine : In a multiline text edit the user can split the text in multiple lines , defaults to * * True * *
: type multiLine : bool , optional
: param document : If required an external Document can be used in this text editor , this option is useful if multiple editors share the same document as in the ` demo < https : / / ceccopierangiolieugenio . github . io / pyTermTk / sandbox / sandbox . html ? fileUri = https : / / raw . githubusercontent . com / ceccopierangiolieugenio / pyTermTk / main / demo / showcase / textedit . py > ` __ , defaults to a new Document
: type document : : py : class : ` TTkTextDocument ` , optional
'''
self . currentColorChanged = pyTTkSignal ( TTkColor )
self . undoAvailable = pyTTkSignal ( bool )
self . redoAvailable = pyTTkSignal ( bool )
self . textChanged = pyTTkSignal ( )
self . _readOnly = readOnly
self . _multiLine = multiLine
self . _multiCursor = True
@ -165,6 +231,9 @@ class TTkTextEditView(TTkAbstractScrollView):
self . _textCursor = None
self . _textWrap = None
self . _clipboard = TTkClipboard ( )
super ( ) . __init__ ( * * kwargs )
self . setFocusPolicy ( TTkK . ClickFocus + TTkK . TabFocus )
self . setDocument ( document if document else TTkTextDocument ( ) )
self . disableWidgetCursor ( self . _readOnly )
@ -366,9 +435,6 @@ class TTkTextEditView(TTkAbstractScrollView):
elif self . lineWrapMode ( ) == TTkK . FixedWidth :
return self . wrapWidth ( ) , self . _textWrap . size ( )
def viewDisplayedSize ( self ) - > ( int , int ) :
return self . size ( )
def _pushCursor ( self ) :
ox , oy = self . getViewOffsets ( )
@ -625,181 +691,20 @@ class TTkTextEditView(TTkAbstractScrollView):
canvas . drawVLine ( pos = ( self . _textWrap . _wrapWidth , 0 ) , size = h , color = lineColor )
class TTkTextEdit ( TTkAbstractScrollArea ) :
''' TTkTextEdit
: :
╔ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ╗
║ 0 ▌ " Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor ╥ ║
║ < ▌ incididunt ut labore et dolore magna aliqua . ║ ║
║ 1 ▌ ║ ║
║ 2 ▌ Ut enim ad minim veniam , quis nostrud exercitation ullamco laboris nisi ut aliqu ║ ║
║ < ▌ ip ex ea commodo consequat . Duis aute irure dolor in reprehenderit in voluptate ║ ║
║ < ▌ velit esse cillum dolore eu fugiat nulla pariatur . ║ ║
║ 3 ▌ ║ ║
║ 4 ▌ Excepteur sint occaecat cupidatat non proident , sunt in culpa qui officia deseru ║ ║
║ < ▌ nt mollit anim id est laborum . " ╨ ║
╚ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ╝
Demo : ` textedit . py < https : / / github . com / ceccopierangiolieugenio / pyTermTk / blob / main / demo / showcase / textedit . py > ` _
( ` Try Online < https : / / ceccopierangiolieugenio . github . io / pyTermTk / sandbox / sandbox . html ? fileUri = https : / / raw . githubusercontent . com / ceccopierangiolieugenio / pyTermTk / main / demo / showcase / textedit . py > ` __ )
` ttkdesigner Tutorial < https : / / github . com / ceccopierangiolieugenio / pyTermTk / blob / main / tutorial / ttkDesigner / textEdit > ` _
: param lineNumber : Show the line number on the left , defaults to * * False * *
: type lineNumber : bool , optional
: param readOnly : In a read - only text edit the user can only navigate through the text and select text ; modifying the text is not possible , defaults to * * True * *
: type readOnly : bool , optional
: param multiLine : In a multiline text edit the user can split the text in multiple lines , defaults to * * True * *
: type multiLine : bool , optional
: param document : If required an external Document can be used in this text editor , this option is useful if multiple editors share the same document as in the ` demo < https : / / ceccopierangiolieugenio . github . io / pyTermTk / sandbox / sandbox . html ? fileUri = https : / / raw . githubusercontent . com / ceccopierangiolieugenio / pyTermTk / main / demo / showcase / textedit . py > ` __ , defaults to a new Document
: type document : : py : class : ` TTkTextDocument ` , optional
__doc__ = '''
: py : class : ` TTkTextEdit ` is a container widget which place : py : class : ` TTkTextEditView ` in a scrolling area with on - demand scroll bars .
. . py : method : : toAnsi ( )
. . py : method : : clear ( )
This method is forwarded to : meth : ` TTkTextEditView . clear `
. . py : method : : setText ( text )
This method is forwarded to : meth : ` TTkTextEditView . setText `
. . py : method : : append ( text )
This method is forwarded to : meth : ` TTkTextEditView . append `
. . py : method : : isReadOnly ( )
This method is forwarded to : meth : ` TTkTextEditView . isReadOnly `
. . py : method : : setReadOnly ( ro )
This method is forwarded to : meth : ` TTkTextEditView . setReadOnly `
. . py : method : : document ( )
This method is forwarded to : meth : ` TTkTextEditView . document `
. . py : method : : wrapWidth ( )
This method is forwarded to : meth : ` TTkTextEditView . wrapWidth `
. . py : method : : setWrapWidth ( width )
This method is forwarded to : meth : ` TTkTextEditView . setWrapWidth `
. . py : method : : multiLine ( )
This method is forwarded to : meth : ` TTkTextEditView . multiLine `
. . py : method : : lineWrapMode ( )
This method is forwarded to : meth : ` TTkTextEditView . lineWrapMode `
. . py : method : : setLineWrapMode ( mode )
This method is forwarded to : meth : ` TTkTextEditView . setLineWrapMode `
. . py : method : : wordWrapMode ( )
This method is forwarded to : meth : ` TTkTextEditView . wordWrapMode `
. . py : method : : setWordWrapMode ( mode )
This method is forwarded to : meth : ` TTkTextEditView . setWordWrapMode `
. . py : method : : textCursor ( )
This method is forwarded to : meth : ` TTkTextEditView . textCursor `
. . py : method : : setColor ( color )
This method is forwarded to : meth : ` TTkTextEditView . setColor `
. . py : method : : cut ( )
This method is forwarded to : meth : ` TTkTextEditView . cut `
. . py : method : : copy ( )
This method is forwarded to : meth : ` TTkTextEditView . copy `
. . py : method : : paste ( )
This method is forwarded to : meth : ` TTkTextEditView . paste `
. . py : method : : undo ( )
This method is forwarded to : meth : ` TTkTextEditView . undo `
. . py : method : : redo ( )
This method is forwarded to : meth : ` TTkTextEditView . redo `
. . py : method : : isUndoAvailable ( )
This method is forwarded to : meth : ` TTkTextEditView . isUndoAvailable `
. . py : method : : isRedoAvailable ( )
This method is forwarded to : meth : ` TTkTextEditView . isRedoAvailable `
. . py : method : : toAnsi ( )
This method is forwarded to : meth : ` TTkTextEditView . toAnsi `
. . py : method : : toRawText ( )
This method is forwarded to : meth : ` TTkTextEditView . toRawText `
. . py : method : : toPlainText ( )
This method is forwarded to : meth : ` TTkTextEditView . toPlainText `
'''
currentColorChanged : pyTTkSignal
'''
This signal is emitted if the current character color has changed ,
for example caused by a change of the cursor position .
: param color : the new color
: type color : : py : class : ` TTkColor `
'''
undoAvailable : pyTTkSignal
'''
This signal is emitted whenever undo operations become available ( available is true )
or unavailable ( available is false ) .
: param available : the availability of undo
: type available : bool
'''
redoAvailable : pyTTkSignal
'''
This signal is emitted whenever redo operations become available ( available is true )
or unavailable ( available is false ) .
: param available : the availability of redo
: type available : bool
'''
textChanged : pyTTkSignal
'''
This signal is emitted whenever the document ' s content changes;
for example , when text is inserted or deleted , or when formatting is applied .
'''
''' + TTkTextEditView.__doc__
__slots__ = (
' _textEditView ' ,
' _lineNumberView ' , ' _lineNumber ' ,
[ ' _textEditView ' ,
' _lineNumberView ' , ' _lineNumber ' ] +
( _forwardedSignals := [ # Forwarded Signals From TTkTexteditView
# Signals
' focusChanged ' , ' currentColorChanged ' ,
' undoAvailable ' , ' redoAvailable ' ,
' textChanged ' ] ) +
( _forwardedMethods := [ # Forwarded Methods From TTkTexteditView
# Forwarded Methods
' clear ' , ' setText ' , ' append ' , ' isReadOnly ' , ' setReadOnly ' , ' document ' ,
' wrapWidth ' , ' setWrapWidth ' ,
@ -811,11 +716,10 @@ class TTkTextEdit(TTkAbstractScrollArea):
' undo ' , ' redo ' , ' isUndoAvailable ' , ' isRedoAvailable ' ,
# Export Methods,
' toAnsi ' , ' toRawText ' , ' toPlainText ' , # 'toHtml', 'toMarkdown',
# Signals
' focusChanged ' , ' currentColorChanged ' ,
' undoAvailable ' , ' redoAvailable ' ,
' textChanged '
] )
)
_forwardWidget = TTkTextEditView
def __init__ ( self , * ,
# TTkWidget init
parent : TTkWidget = None ,
@ -831,6 +735,14 @@ class TTkTextEdit(TTkAbstractScrollArea):
lineNumber : bool = False ,
lineNumberStarting : int = 0 ,
* * kwargs ) - > None :
'''
: param textEditView : a custom TextEdit View to be used instead of the default one .
: type textEditView : : py : class : ` TTkTextEditView ` , optional
: param lineNumber : show the line number on the left side , defaults to False
: type lineNumber : bool , optional
: param lineNumberStarting : set the starting number of the left line number column , defaults to 0
: type lineNumberStarting : int , optional
'''
super ( ) . __init__ ( parent = parent , visible = visible , * * kwargs )
self . _textEditView = textEditView if textEditView else TTkTextEditView ( readOnly = readOnly , multiLine = multiLine , document = document )
# self.setFocusPolicy(self._textEditView.focusPolicy())
@ -844,44 +756,11 @@ class TTkTextEdit(TTkAbstractScrollArea):
textEditLayout . addWidget ( self . _lineNumberView , 0 , 0 )
self . setViewport ( textEditLayout )
self . clear = self . _textEditView . clear
self . setText = self . _textEditView . setText
self . append = self . _textEditView . append
self . document = self . _textEditView . document
self . isReadOnly = self . _textEditView . isReadOnly
self . setReadOnly = self . _textEditView . setReadOnly
self . textCursor = self . _textEditView . textCursor
self . setFocus = self . _textEditView . setFocus
self . multiLine = self . _textEditView . multiLine
self . setColor = self . _textEditView . setColor
self . cut = self . _textEditView . cut
self . copy = self . _textEditView . copy
self . paste = self . _textEditView . paste
self . undo = self . _textEditView . undo
self . redo = self . _textEditView . redo
self . isUndoAvailable = self . _textEditView . isUndoAvailable
self . isRedoAvailable = self . _textEditView . isRedoAvailable
# Forward export methods
self . toAnsi = self . _textEditView . toAnsi
self . toRawText = self . _textEditView . toRawText
self . toPlainText = self . _textEditView . toPlainText
# self.toHtml = self._textEditView.toHtml
# self.toMarkdown = self._textEditView.toMarkdown
# Forward Wrap Methods
self . wrapWidth = self . _textEditView . wrapWidth
self . setWrapWidth = self . _textEditView . setWrapWidth
self . lineWrapMode = self . _textEditView . lineWrapMode
self . setLineWrapMode = self . _textEditView . setLineWrapMode
self . wordWrapMode = self . _textEditView . wordWrapMode
self . setWordWrapMode = self . _textEditView . setWordWrapMode
# Forward Signals
self . focusChanged = self . _textEditView . focusChanged
self . currentColorChanged = self . _textEditView . currentColorChanged
self . undoAvailable = self . _textEditView . undoAvailable
self . redoAvailable = self . _textEditView . redoAvailable
self . textChanged = self . _textEditView . textChanged
for _attr in self . _forwardedSignals + self . _forwardedMethods :
setattr ( self , _attr , getattr ( self . _textEditView , _attr ) )
def textEditView ( self ) :
''' textEditView '''
return self . _textEditView
def getLineNumber ( self ) :
@ -894,10 +773,12 @@ class TTkTextEdit(TTkAbstractScrollArea):
self . _lineNumberView . setVisible ( ln )
def lineNumberStarting ( self ) :
''' lineNumberStarting '''
return self . _lineNumberView . _startingNumber
@pyTTkSlot ( int )
def setLineNumberStarting ( self , starting ) :
''' setLineNumberStarting '''
self . _lineNumberView . _startingNumber = starting
self . _lineNumberView . _wrapChanged ( )