wx.richtext.SymbolPickerDialog presents the user with a choice of fonts and a grid of available characters.
This modal dialog provides the application with a selected symbol and optional font selection.
Although this dialog is contained in the rich text library, the dialog is generic and can be used in other contexts.
To use the dialog, pass a default symbol specified as a string, an initial font name, and a current font name. The difference between the initial font and current font is that the initial font determines what the font control will be set to when the dialog shows - an empty string will show the selection normal text. The current font, on the other hand, is used by the dialog to determine what font to display the characters in, even when no initial font is selected. This allows the user (and application) to distinguish between inserting a symbol in the current font, and inserting it with a specified font.
When the dialog is dismissed, the application can get the selected symbol with wx.richtext.SymbolPickerDialog.GetSymbol
and test whether a font was specified with wx.richtext.SymbolPickerDialog.UseNormalFont
,fetching the specified font with wx.richtext.SymbolPickerDialog.GetFontName
.
Here’s a realistic example, inserting the supplied symbol into a rich text control in either the current font or specified font.
ctrl = self.FindWindow(ID_RICHTEXT_CTRL)
attr = wx.TextAttr()
attr.SetFlags(wx.TEXT_ATTR_FONT)
ctrl.GetStyle(ctrl.GetInsertionPoint(), attr)
currentFontName = ''
if (attr.HasFont() and attr.GetFont().IsOk()):
currentFontName = attr.GetFont().GetFaceName()
# Don't set the initial font in the dialog (so the user is choosing
# 'normal text', i.e. the current font) but do tell the dialog
# what 'normal text' is.
dlg = wx.richtext.SymbolPickerDialog("*", '', currentFontName, self)
if dlg.ShowModal() == wx.ID_OK:
if dlg.HasSelection():
insertionPoint = ctrl.GetInsertionPoint()
ctrl.WriteText(dlg.GetSymbol())
if not dlg.UseNormalFont():
font = attr.GetFont()
font.SetFaceName(dlg.GetFontName())
attr.SetFont(font)
ctrl.SetStyle(insertionPoint, insertionPoint+1, attr)
Default constructor. |
|
Creation: see the constructor for details about the parameters. |
|
Returns the font name (the font reflected in the font list). |
|
Returns |
|
Gets the font name used for displaying symbols in the absence of a selected font. |
|
Gets the current or initial symbol as a string. |
|
Gets the selected symbol character as an integer. |
|
Returns |
|
Sets the initial/selected font name. |
|
Sets the internal flag indicating that the full Unicode range should be displayed. |
|
Sets the name of the font to be used in the absence of a selected font. |
|
Sets the symbol as a one or zero character string. |
|
Sets Unicode display mode. |
|
Returns |
See |
|
See |
|
See |
wx.richtext.
SymbolPickerDialog
(Dialog)¶Possible constructors:
SymbolPickerDialog()
SymbolPickerDialog(symbol, initialFont, normalTextFont, parent,
id=ID_ANY, title=_("Symbols"), pos=DefaultPosition, size=DefaultSize,
style=DEFAULT_DIALOG_STYLE|RESIZE_BORDER|CLOSE_BOX)
SymbolPickerDialog presents the user with a choice of fonts and a grid of available characters.
__init__
(self, *args, **kw)¶__init__ (self)
Default constructor.
__init__ (self, symbol, initialFont, normalTextFont, parent, id=ID_ANY, title=_(“Symbols”), pos=DefaultPosition, size=DefaultSize, style=DEFAULT_DIALOG_STYLE|RESIZE_BORDER|CLOSE_BOX)
Constructor.
symbol (string) – The initial symbol to show. Specify a single character in a string, or an empty string.
initialFont (string) – The initial font to be displayed in the font list. If empty, the item normal text will be selected.
normalTextFont (string) – The font the dialog will use to display the symbols if the initial font is empty.
parent (wx.Window) – The dialog’s parent.
id (wx.WindowID) – The dialog’s identifier.
title (string) – The dialog’s caption.
pos (wx.Point) – The dialog’s position.
size (wx.Size) – The dialog’s size.
style (long) – The dialog’s window style.
Create
(self, symbol, initialFont, normalTextFont, parent, id=ID_ANY, caption=GetTranslation("Symbols"), pos=DefaultPosition, size=Size(400, 300), style=DEFAULT_DIALOG_STYLE|RESIZE_BORDER|CLOSE_BOX)¶Creation: see the constructor for details about the parameters.
GetClassDefaultAttributes
(variant=WINDOW_VARIANT_NORMAL)¶variant (WindowVariant) –
VisualAttributes
GetFontName
(self)¶Returns the font name (the font reflected in the font list).
string
GetFromUnicode
(self)¶Returns True
if the dialog is showing the full range of Unicode characters.
bool
GetNormalTextFontName
(self)¶Gets the font name used for displaying symbols in the absence of a selected font.
string
GetSymbol
(self)¶Gets the current or initial symbol as a string.
string
GetSymbolChar
(self)¶Gets the selected symbol character as an integer.
int
HasSelection
(self)¶Returns True
if a symbol is selected.
bool
SetFontName
(self, value)¶Sets the initial/selected font name.
value (string) –
SetFromUnicode
(self, value)¶Sets the internal flag indicating that the full Unicode range should be displayed.
value (bool) –
SetNormalTextFontName
(self, value)¶Sets the name of the font to be used in the absence of a selected font.
value (string) –
SetSymbol
(self, value)¶Sets the symbol as a one or zero character string.
value (string) –
SetUnicodeMode
(self, unicodeMode)¶Sets Unicode display mode.
unicodeMode (bool) –
UseNormalFont
(self)¶Returns True
if the has specified normal text - that is, there is no selected font.
bool
FontName
¶See GetFontName
and SetFontName
FromUnicode
¶See GetFromUnicode
and SetFromUnicode
NormalTextFontName
¶SymbolChar
¶See GetSymbolChar