wx.richtext.SymbolPickerDialog¶
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)
Class Hierarchy¶
Methods Summary¶
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 |
Properties Summary¶
See |
|
See |
|
See |
Class API¶
- class wx.richtext.SymbolPickerDialog(Dialog)¶
Possible constructors:
SymbolPickerDialog() -> None SymbolPickerDialog(symbol, initialFont, normalTextFont, parent, id=ID_ANY, title=_("Symbols"), pos=DefaultPosition, size=DefaultSize, style=DEFAULT_DIALOG_STYLE|RESIZE_BORDER|CLOSE_BOX) -> None
SymbolPickerDialog presents the user with a choice of fonts and a grid of available characters.
Methods¶
- __init__(self, *args, **kw)¶
-
__init__ (self)
Default constructor.
- Return type:
None
__init__ (self, symbol, initialFont, normalTextFont, parent, id=ID_ANY, title=_(“Symbols”), pos=DefaultPosition, size=DefaultSize, style=DEFAULT_DIALOG_STYLE|RESIZE_BORDER|CLOSE_BOX)
Constructor.
- Parameters:
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.
- Return type:
None
- 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.
- static GetClassDefaultAttributes(variant=WINDOW_VARIANT_NORMAL)¶
- Parameters:
variant (WindowVariant)
- Return type:
VisualAttributes
- GetFontName(self)¶
Returns the font name (the font reflected in the font list).
- Return type:
str
- GetFromUnicode(self)¶
Returns
True
if the dialog is showing the full range of Unicode characters.- Return type:
bool
- GetNormalTextFontName(self)¶
Gets the font name used for displaying symbols in the absence of a selected font.
- Return type:
str
- GetSymbol(self)¶
Gets the current or initial symbol as a string.
- Return type:
str
- GetSymbolChar(self)¶
Gets the selected symbol character as an integer.
- Return type:
int
- HasSelection(self)¶
Returns
True
if a symbol is selected.- Return type:
bool
- SetFontName(self, value)¶
Sets the initial/selected font name.
- Parameters:
value (string)
- Return type:
None
- SetFromUnicode(self, value)¶
Sets the internal flag indicating that the full Unicode range should be displayed.
- Parameters:
value (bool)
- Return type:
None
- SetNormalTextFontName(self, value)¶
Sets the name of the font to be used in the absence of a selected font.
- Parameters:
value (string)
- Return type:
None
- SetSymbol(self, value)¶
Sets the symbol as a one or zero character string.
- Parameters:
value (string)
- Return type:
None
- SetUnicodeMode(self, unicodeMode)¶
Sets Unicode display mode.
- Parameters:
unicodeMode (bool)
- Return type:
None
- UseNormalFont(self)¶
Returns
True
if the has specified normal text - that is, there is no selected font.- Return type:
bool
Properties¶
- FontName¶
See
GetFontName
andSetFontName
- FromUnicode¶
See
GetFromUnicode
andSetFromUnicode
- NormalTextFontName¶
- SymbolChar¶
See
GetSymbolChar