PyFrame Guide to wxPython

Copyright and License information Home

__ A B C D E F G H I L M P R S T U V W

wxStyledTextCtrl - Utility / Miscellaneous

  • GetBufferedDraw

  • GetCodePage

  • GetControlCharSymbol

  • GetCurrentLine

  • GetCursor

  • GetFirstVisibleLine

  • GetLastKeydownProcessed

  • GetLength

  • GetLineCount

  • GetModify

  • GetMouseDownCaptures

  • GetMouseDwellTime

  • GetStatus

  • GetSTCFocus

  • GetTextLength

  • LineLength

  • LinesOnScreen

  • SendMsg

  • SetBufferedDraw

  • SetCodePage

  • SetControlCharSymbol

  • SetCursor

  • SetLastKeydownProcessed

  • SetMouseDownCaptures

  • SetMouseDwellTime

  • SetStatus

  • SetSTCFocus

  • SetWordChars

  • TextHeight

  • TextWidth

  • UsePopUp

  • WordEndPosition

  • WordStartPosition

Summary:

This section features a hodge-podge of utility and miscellaneous functions.

----

GetBufferedDraw()

Returns an integer that's 1 if buffered drawing is active or 0 if it is not. See SetBufferedDraw.

top

----

GetCodePage()

Returns an integer with the code page. See SetCodePage.

top

----

GetControlCharSymbol()

Returns an integer with the ASCII code for a symbol used to show control characters in the display. See SetControlCharSymbol.

top

----

GetCurrentLine()

This method executes LineFromPosition(GetCurrentPos()). Hence, it returns an integer with the current line based on the current position. It isn't shown in the Scintilla documentation.

top

----

GetCursor()

Returns an integer with the current cursor type, or -1 (wxSTC_CURSORNORMAL) if you have not changed the cursor type. See SetCursor.

top

----

GetFirstVisibleLine()

This returns an integer with the line number of the first visible line in the Scintilla view. The first line in the document is numbered 0.

top

----

GetLastKeydownProcessed

Returns an integer with the value of the 'lastKeyDownConsumed' flag. See SetLastKeydownProcessed.

top

----

GetLength()

Returns an integer with the length of the Document in characters. Identical in function to GetTextLength.

top

----

GetLineCount()

This returns an integer with the number of lines in the document. An empty document contains 1 line. A document holding only an end of line sequence has 2 lines.

top

----

GetModify()

Is the document different from when it was last saved? Use this method to find out. It works by determining if the savepoint (SetSavePoint) is the same as the current undo position (see Undo for more information). In other words, if you use SetSavePoint to tell the STC when you've saved the Document, then GetModify() tells you whether or not there have been any changes that have not been undone by the user. Be sure to examine the docs for SetSavePoint to see how events can be emitted by the STC as the undo point moves away from and back to the save point.

top

----

GetMouseDownCaptures()

Returns an integer that's 1 if the STC captures the mouse or 0 if it doesn't. Also see SetMouseDownCaptures.

top

----

GetMouseDwellTime()

Returns an integer that indicates how long (in milliseconds) the mouse must sit still over the STC in order to generate a EVT_STC_DWELLSTART event. Also see SetMouseDwellTime.

top

----

GetStatus()

Returns an internal STC error number. But this feature actually is not used by the STC, so it's not very useful at this time. See also SetStatus.

top

----

GetSTCFocus()

Returns an integer with the value of the internal focus flag. Also see SetSTCFocus.

top

----

GetTextLength()

Returns an integer with the length of the Document in characters. Identical in function to GetLength.

top

----

LineLength(line)

This returns the an integer with the length of the line specified by the integer parameter line, including any line end characters. If line is negative or beyond the last line in the document, the result is 0. If you want the length of the line not including any end of line characters use GetLineEndPosition(line) - PositionFromLine(line).

top

----

LinesOnScreen()

This returns an integer with the number of complete lines visible on the screen. With a constant line height, this is the vertical space available divided by the line separation. Unless you arrange to size your window to an integral number of lines, there may be a partial line visible at the bottom of the view.

top

----

SendMsg(msg,wp,lp)

For those who like to get close to the metal, you can send any message to the STC with SendMsg. You'd better check thru stc.h and other sources, as well as understand the messaging paradigm to understand how to use this. The return value is a long integer, but may be 0.

The msg parameter is the message code, the wp (word param) and lp (long param/pointer) parameter are the inputs that the message may require, and you can omit them if not needed (they'll internally be set to zero).

top

----

SetBufferedDraw(buffered)

Sets the STC's buffered drawing mode on (the default) or off based on the value of the integer parameter buffered. If buffered = 0 then the mode is off; if it is 1 then the mode is on. Returns None.

Buffered drawing mode causes all graphics drawing for a line to be done into a bitmap buffer which is blitted to the screen to help avoid visible flickering.

top

----

SetCodePage(codePage)

The code page is set to the value of the integer parameter codePage. Returns None.

From the Scintilla documentation: Scintilla has some very simple Japanese DBCS (and probably Chinese and Korean) support. Use this message with codepage set to the code page number to set Scintilla to use code page information to ensure double byte characters are treated as one character rather than two. This also stops the caret from moving between the two bytes in a double byte character. Call with codepage set to zero to disable DBCS support. The default is SetCodePage(0).

Code page wxSTC_CP_UTF8 (65001) sets Scintilla into Unicode mode with the document treated as a sequence of characters expressed in UTF-8. The text is converted to the platform's normal Unicode encoding before being drawn by the OS and can thus display Hebrew, Arabic, Cyrillic, and Han characters. Languages which can use two characters stacked vertically in one horizontal space such as Thai will mostly work but there are some issues where the characters are drawn separately leading to visual glitches. Bidirectional text is not supported. For GTK+, the locale should be set to a Unicode locale with a call similar to setlocale(LC_CTYPE, "en_US.UTF-8"). Fonts with an "iso10646" registry should be used in a font set. Font sets are a comma separated list of partial font specifications where each partial font specification can be in the form of foundry-fontface-charsetregistry-encoding *OR* fontface-charsetregistry-encoding *OR* foundry-fontface *OR* fontface. An example is "misc-fixed-iso10646-1,*".

{Setting code page to a non-zero value that is not wxSTC_CP_UTF8 causes...?}

top

----

SetControlCharSymbol(symbol)

Sets the symbol that's to be used to indicate control characters to the value of the integer parameter symbol. Returns None.

From the Scintilla documentation: By default, Scintilla diplays control characters (characters with codes less than 32) as their ASCII mnemonics: "NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL", "BS", "HT", "LF", "VT", "FF", "CR", "SO", "SI", "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB", "CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US" in a rounded rectangle. These mnemonics come from the early days of signalling, though some are still used (LF = Line Feed, BS = Back Space, CR = Carrige Return, for example).

You can choose to replace these mnemonics by a nominated symbol with an ASCII code in the range 32 to 255. If you set a symbol value less than 32, all control characters are displayed as mnemonics. The symbol you set is rendered in the the font of the style set for the character. You can read back the current symbol with GetControlCharSymbol . The default symbol value is 0.

top

----

SetCursor(cursorType)

You usually don't need to mess around with the cursor appearance as the STC does most of this for you. You may occasionally wish to set the 'wait' cursor if you're doing some operation that takes a long time in response to something that happens when the user selects some option.

In that case, use this method with a cursorType of wxSTC_CURSORWAIT. Restore the normal cursor with a cursorType of wxSTC_CURSORNORMAL.

SetCursor returns None.

top

----

SetLastKeydownProcessed(val)

Sets the STC's internal 'lastKeyDownConsumed' to the value of the integer parameter val. This flag indicates whether or not the STC has actually used up the last key input from the keyboard; the source code mentions that you can use this feature (perhaps along with GetLastKeydownProcessed) to prevent the EVT_CHAR handler from adding the character. This author is not sure how or why you'd want to do so. Also note that this is a wxWindows/wxPython port feature and isn't present in the Scintilla component itself.

top

----

SetMouseDownCaptures(captures)

Sets the STC's 'capture mouse' flag to the value of the integer parameter captures. When 1, the STC will capture the mouse when its button is pressed down when the mouse pointer is over the STC window. This is the default. You may wish to turn off this action, if so, use captures = 0.

Returns None. See also GetMouseDownCaptures.

top

----

SetMouseDwellTime(periodMilliseconds)

The integer parameter periodMilliseconds) sets how long (in milliseconds) the mouse must sit still over the STC in order to generate a EVT_STC_DWELLSTART event.

Returns None. See also GetMouseDwellTime.

top

----

SetStatus(statusCode)

Sets the STC's internal error status to the value of the integer parameter status. Only use with a value of zero in order to reset an error status indication. This feature is unused in the STC at this time, also see GetStatus. Returns None.

top

----

SetSTCFocus(focus)

Set or reset the STC's internal focus flag based on the value of the integer parameter focus. Use 0 or 1 to reset or set the flag. Returns None.

From the Scintilla documentation: On GTK+, focus handling is more complicated than on Windows, so Scintilla can be told with this message to grab the focus. The internal focus flag can be set with SetSTCFocus. This is used by clients which have complex focus requirements such as having their own window which gets the real focus but with the need to indicate that Scintilla has the logical focus.

top

----

SetWordChars(characters)

From the Scintilla documentation: Scintilla has several functions that operate on words which are defined to be contiguous sequences of characters from a particular set of characters. This method is used to define which characters are members of that set. If the string object characters is '' (an empty string) then the default set (see below), is used.

For example, if you don't allow '_' in your set of characters use:

SetWordChars("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789").

If you want to use the default set, you must use SetWordChars(''). Note that an empty string is passed as the characters parameter.

It's important to realize that SetWordChars operates on a Document-by-Document basis. That is, when a new Document is created (whether it's the one created when you instantiate a STC or one you create with CreateDocument) a default list (as shown below) is created. If you modify the list with SetWordChars on one Document this does not affect the list used with other Documents.

Returns None.

The default list of chars that count as part of words, as set by creating a Document or using SetWordChars('') is:

_
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789

In addition, all character values greater or equal to 0x80 are added to this set of word characters when the default set is created. This isn't mentioned in the Scintilla docs. See Document::SetWordChars in Document.cxx for more information.

top

----

TextHeight(line)

Returns the height of the line specified by the integer parameter line, in pixels. Note that all lines have the same height (at least in the STC's current incarnation).

top

----

TextWidth(style,text)

Returns an integer that represents the width, in pixels, of a string object text when presented using the style number specified by the integer parameter style. One use for this would be to see how wide to set a margin for line numbers.

top

----

UsePopUp(allowPopUp)

If you click the right mouse button over a STC window, a simple editing menu pops up. You can disable this with UsePopUp(0) or re-enable it with UsePopUp(1). Returns None.

top

----

WordEndPosition(pos, onlyWordCharacters)

WordStartPosition(pos, onlyWordCharacters)

These two methods return integers representing the end or start position of words using the same definition of words used by the STC. See SetWordChars if you want to change the default list of characters that count as words. The integer parameter pos is the position of the document to begin searching - backwards towards the start of a word when using WordStartPosition or forwards towards the end of a word when using WordEndPosition.

The integer parameter onlyWordCharacters is set to 1 to stop searching at the first non-word character in the search direction. If onlyWordCharacters is 0, the first character in the search direction sets the type of the search as word or non-word and the search stops at the first non-matching character. Searches are also terminated by the start or end of the document.

The Scintilla documentation shows this example:

If "w" represents word characters and "." represents non-word characters and "|" represents the position and true or false is the state of onlyWordCharacters:

Initial state

end, true

end, false

start, true

start, false

..ww..|..ww..

..ww..|..ww..

..ww....|ww..

..ww..|..ww..

..ww|....ww..

....ww|ww....

....wwww|....

....wwww|....

....|wwww....

....|wwww....

..ww|....ww..

..ww|....ww..

..ww....|ww..

..|ww....ww..

..|ww....ww..

..ww....|ww..

..ww....ww|..

..ww....ww|..

..ww....|ww..

..ww|....ww..

top

----