wx.richtext.RichTextObject¶
This is the base for drawable rich text objects.
Class Hierarchy¶
Known Subclasses¶
wx.richtext.RichTextCompositeObject, wx.richtext.RichTextImage, wx.richtext.RichTextPlainText
Methods Summary¶
Constructor, taking an optional parent pointer. |
|
Returns |
|
Adjusts the attributes for virtual attribute provision, collapsed borders, etc. |
|
Returns the rectangle which the child has available to it given restrictions specified in the child attribute, e.g. |
|
Calculates the range of the object. |
|
Returns |
|
Returns |
|
Returns |
|
Clones the object. |
|
Convert units in pixels to tenths of a millimetre. |
|
Converts units in tenths of a millimetre to device units. |
|
Copies the object. |
|
Deletes the given range. |
|
Reference-counting allows us to use the same object in multiple lists (not yet used). |
|
Do a split from pos, returning an object containing the second part, and setting the first part in ‘this’. |
|
Draw the item, within the given range. |
|
Draws a border. |
|
Draws the borders and background for the given rectangle and attributes. |
|
Edits the object’s properties via a GUI. |
|
Finds the absolute position and row height for the given character position. |
|
Returns the absolute object position, by traversing up the child/parent hierarchy. |
|
Returns the object’s attributes. |
|
Calculates the available content space in the given rectangle, given the margins, border and padding specified in the object’s attributes. |
|
Returns the best size, i.e. the ideal starting size for this object irrespective of available space. |
|
Returns the bottom margin of the object, in pixels. |
|
Returns the various rectangles of the box model in pixels. |
|
Returns the containing buffer. |
|
Gets the cached object size as calculated by Layout. |
|
Returns the top-level container of this object. |
|
Returns the stored descent value. |
|
Returns the floating direction. |
|
Returns the left margin of the object, in pixels. |
|
Gets the maximum object size as calculated by Layout. |
|
Gets the minimum object size as calculated by Layout. |
|
Returns the identifying name for this object from the properties, using the “name” key. |
|
Gets the ‘natural’ size for an object. |
|
Returns the object’s own range (valid if top-level). |
|
Returns the object’s own range only if a top-level object. |
|
Returns a pointer to the parent object. |
|
Returns the top-level container of this object. |
|
Returns the object position in pixels. |
|
Returns the object’s properties. |
|
Returns the label to be used for the properties context menu item. |
|
Returns the object’s range. |
|
Returns the object size for the given range. |
|
Returns the rectangle enclosing the object. |
|
Returns the right margin of the object, in pixels. |
|
Returns a selection object specifying the selections between start and end character positions. |
|
Returns any text in this object for the given range. |
|
Returns the top margin of the object, in pixels. |
|
Returns the total margin for the object in pixels, taking into account margin, padding and border size. |
|
Returns the |
|
Returns |
|
Hit-testing: returns a flag indicating hit test details, plus information about position. |
|
Imports this object from |
|
Invalidates the object at the given range. |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Lay the item out at the specified position with the given size constraint. |
|
Lays out the object first with a given amount of space, and then if no width was specified in attr, lays out the object again using the minimum size. |
|
Returns |
|
Moves the object recursively, by adding the offset from old to new. |
|
Reference-counting allows us to use the same object in multiple lists (not yet used). |
|
Sets the object’s attributes. |
|
Sets the cached object size as calculated by Layout. |
|
Sets the stored descent value. |
|
Set the margin around the object, in pixels. |
|
Sets the maximum object size as calculated by Layout. |
|
Sets the minimum object size as calculated by Layout. |
|
Sets the identifying name for this object as a property using the “name” key. |
|
Set the object’s own range, for a top-level object with its own position space. |
|
Sets the pointer to the parent object. |
|
Sets the object position in pixels. |
|
Sets the object’s properties. |
|
Sets the object’s range within its container. |
|
Call to show or hide this object. |
|
Returns the final object in the split objects if this object was split due to differences between sub-object virtual attributes. |
|
Returns |
Properties Summary¶
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
Class API¶
- class wx.richtext.RichTextObject(Object)¶
Possible constructors:
RichTextObject(parent=None) -> None
This is the base for drawable rich text objects.
Methods¶
- __init__(self, parent=None)¶
Constructor, taking an optional parent pointer.
- Parameters:
parent (wx.richtext.RichTextObject)
- Return type:
None
- AcceptsFocus(self)¶
Returns
True
if objects of this class can accept the focus, i.e. a call to SetFocusObject is possible.For example, containers supporting text, such as a text box object, can accept the focus, but a table can’t (set the focus to individual cells instead).
- Return type:
bool
- AdjustAttributes(self, attr, context)¶
Adjusts the attributes for virtual attribute provision, collapsed borders, etc.
- Parameters:
attr (wx.richtext.RichTextAttr)
context (wx.richtext.RichTextDrawingContext)
- Return type:
bool
- static AdjustAvailableSpace(dc, buffer, parentAttr, childAttr, availableParentSpace, availableContainerSpace)¶
Returns the rectangle which the child has available to it given restrictions specified in the child attribute, e.g.
50% width of the parent, 400 pixels, x position 20% of the parent, etc. availableContainerSpace might be a parent that the cell has to compute its width relative to. E.g. a cell that’s 50% of its parent.
- Parameters:
dc (wx.DC)
buffer (wx.richtext.RichTextBuffer)
parentAttr (wx.richtext.RichTextAttr)
childAttr (wx.richtext.RichTextAttr)
availableParentSpace (wx.Rect)
availableContainerSpace (wx.Rect)
- Return type:
- CalculateRange(self, start)¶
Calculates the range of the object.
By default, guess that the object is 1 unit long.
- Parameters:
start (long)
- Return type:
int
- CanEditProperties(self)¶
Returns
True
if we can edit the object’s properties via a GUI.- Return type:
bool
- CanMerge(self, object, context)¶
Returns
True
if this object can merge itself with the given one.- Parameters:
object (wx.richtext.RichTextObject)
context (wx.richtext.RichTextDrawingContext)
- Return type:
bool
- CanSplit(self, context)¶
Returns
True
if this object can potentially be split, by virtue of having different virtual attributes for individual sub-objects.- Parameters:
context (wx.richtext.RichTextDrawingContext)
- Return type:
bool
- Clone(self)¶
Clones the object.
- Return type:
- ConvertPixelsToTenthsMM(self, *args, **kw)¶
Convert units in pixels to tenths of a millimetre.
ConvertPixelsToTenthsMM (self, dc, pixels)
- Parameters:
dc (wx.DC)
pixels (int)
- Return type:
int
ConvertPixelsToTenthsMM (ppi, pixels, scale=1.0)
- Parameters:
ppi (int)
pixels (int)
scale (float)
- Return type:
int
- ConvertTenthsMMToPixels(self, *args, **kw)¶
Converts units in tenths of a millimetre to device units.
ConvertTenthsMMToPixels (self, dc, units)
- Parameters:
dc (wx.DC)
units (int)
- Return type:
int
ConvertTenthsMMToPixels (ppi, units, scale=1.0)
- Parameters:
ppi (int)
units (int)
scale (float)
- Return type:
int
- Copy(self, obj)¶
Copies the object.
- Parameters:
- Return type:
None
- DeleteRange(self, range)¶
Deletes the given range.
- Parameters:
range (wx.richtext.RichTextRange)
- Return type:
bool
- Dereference(self)¶
Reference-counting allows us to use the same object in multiple lists (not yet used).
- Return type:
None
- DoSplit(self, pos)¶
Do a split from pos, returning an object containing the second part, and setting the first part in ‘this’.
- Parameters:
pos (long)
- Return type:
- Draw(self, dc, context, range, selection, rect, descent, style)¶
Draw the item, within the given range.
Some objects may ignore the range (for example paragraphs) while others must obey it (lines, to implement wrapping)
- Parameters:
dc (wx.DC)
context (wx.richtext.RichTextDrawingContext)
range (wx.richtext.RichTextRange)
selection (wx.richtext.RichTextSelection)
rect (wx.Rect)
descent (int)
style (int)
- Return type:
bool
- static DrawBorder(dc, buffer, attr, borders, rect, flags=0)¶
Draws a border.
- Parameters:
dc (wx.DC)
buffer (wx.richtext.RichTextBuffer)
attr (wx.richtext.RichTextAttr)
borders (wx.richtext.TextAttrBorders)
rect (wx.Rect)
flags (int)
- Return type:
bool
- static DrawBoxAttributes(dc, buffer, attr, boxRect, flags=0, obj=None)¶
Draws the borders and background for the given rectangle and attributes.
boxRect is taken to be the outer margin box, not the box around the content.
- Parameters:
dc (wx.DC)
buffer (wx.richtext.RichTextBuffer)
attr (wx.richtext.RichTextAttr)
boxRect (wx.Rect)
flags (int)
- Return type:
bool
- EditProperties(self, parent, buffer)¶
Edits the object’s properties via a GUI.
- Parameters:
parent (wx.Window)
buffer (wx.richtext.RichTextBuffer)
- Return type:
bool
- FindPosition(self, dc, context, index, forceLineStart)¶
Finds the absolute position and row height for the given character position.
- Parameters:
dc (wx.DC)
context (wx.richtext.RichTextDrawingContext)
index (long)
forceLineStart (bool)
- Return type:
le[bool, wx.Point, int]
- GetAbsolutePosition(self)¶
Returns the absolute object position, by traversing up the child/parent hierarchy.
TODO
: may not be needed, if all object positions are in fact relative to the top of the coordinate space.- Return type:
Point
- GetAttributes(self)¶
Returns the object’s attributes.
- Return type:
- GetAvailableContentArea(self, dc, context, outerRect)¶
Calculates the available content space in the given rectangle, given the margins, border and padding specified in the object’s attributes.
- Parameters:
dc (wx.DC)
context (wx.richtext.RichTextDrawingContext)
outerRect (wx.Rect)
- Return type:
- GetBestSize(self)¶
Returns the best size, i.e. the ideal starting size for this object irrespective of available space.
For a short text string, it will be the size that exactly encloses the text. For a longer string, it might use the parent width for example.
- Return type:
Size
- GetBottomMargin(self)¶
Returns the bottom margin of the object, in pixels.
- Return type:
int
- static GetBoxRects(dc, buffer, attr)¶
Returns the various rectangles of the box model in pixels.
You can either specify contentRect (inner) or marginRect (outer), and the other must be the default rectangle (no width or height). Note that the outline doesn’t affect the position of the rectangle, it’s drawn in whatever space is available.
- Parameters:
dc (wx.DC)
buffer (wx.richtext.RichTextBuffer)
attr (wx.richtext.RichTextAttr)
- Return type:
le[bool, wx.Rect, wx.Rect, wx.Rect, wx.Rect, wx.Rect]
- GetBuffer(self)¶
Returns the containing buffer.
- Return type:
- GetCachedSize(self)¶
Gets the cached object size as calculated by Layout.
- Return type:
Size
- GetContainer(self)¶
Returns the top-level container of this object.
May return itself if it’s a container; use GetParentContainer to return a different container.
- Return type:
- GetDescent(self)¶
Returns the stored descent value.
- Return type:
int
- GetFloatDirection(self)¶
Returns the floating direction.
- Return type:
int
- GetLeftMargin(self)¶
Returns the left margin of the object, in pixels.
- Return type:
int
- GetMaxSize(self)¶
Gets the maximum object size as calculated by Layout.
This allows us to fit an object to its contents or allocate extra space if required.
- Return type:
Size
- GetMinSize(self)¶
Gets the minimum object size as calculated by Layout.
This allows us to constrain an object to its absolute minimum size if necessary.
- Return type:
Size
- GetName(self)¶
Returns the identifying name for this object from the properties, using the “name” key.
- Return type:
str
- GetNaturalSize(self)¶
Gets the ‘natural’ size for an object.
For an image, it would be the image size.
- Return type:
- GetOwnRange(self)¶
Returns the object’s own range (valid if top-level).
- Return type:
- GetOwnRangeIfTopLevel(self)¶
Returns the object’s own range only if a top-level object.
- Return type:
- GetParent(self)¶
Returns a pointer to the parent object.
- Return type:
- GetParentContainer(self)¶
Returns the top-level container of this object.
Returns a different container than itself, unless there’s no parent, in which case it will return
None
.- Return type:
- GetPosition(self)¶
Returns the object position in pixels.
- Return type:
Point
- GetProperties(self)¶
Returns the object’s properties.
- Return type:
- GetPropertiesMenuLabel(self)¶
Returns the label to be used for the properties context menu item.
- Return type:
str
- GetRange(self)¶
Returns the object’s range.
- Return type:
- GetRangeSize(self, range, size, descent, dc, context, flags, position=Point(0, 0), parentSize=DefaultSize, partialExtents=None)¶
Returns the object size for the given range.
Returns
False
if the range is invalid for this object.- Parameters:
range (wx.richtext.RichTextRange)
size (wx.Size)
descent (int)
dc (wx.DC)
context (wx.richtext.RichTextDrawingContext)
flags (int)
position (wx.Point)
parentSize (wx.Size)
partialExtents (list of integers)
- Return type:
bool
- GetRightMargin(self)¶
Returns the right margin of the object, in pixels.
- Return type:
int
- GetSelection(self, start, end)¶
Returns a selection object specifying the selections between start and end character positions.
For example, a table would deduce what cells (of range length 1) are selected when dragging across the table.
- Parameters:
start (long)
end (long)
- Return type:
- GetTextForRange(self, range)¶
Returns any text in this object for the given range.
- Parameters:
range (wx.richtext.RichTextRange)
- Return type:
str
- GetTopMargin(self)¶
Returns the top margin of the object, in pixels.
- Return type:
int
- static GetTotalMargin(dc, buffer, attr)¶
Returns the total margin for the object in pixels, taking into account margin, padding and border size.
- Parameters:
dc (wx.DC)
buffer (wx.richtext.RichTextBuffer)
attr (wx.richtext.RichTextAttr)
- Return type:
Tuple[bool, int, int, int, int]
- GetXMLNodeName(self)¶
Returns the
XML
node name of this object.This must be overridden for XmlNode-base
XML
export to work.- Return type:
str
- HandlesChildSelections(self)¶
Returns
True
if this object can handle the selections of its children, fOr example a table.Required for composite selection handling to work.
- Return type:
bool
- HitTest(self, dc, context, pt, flags=0)¶
Hit-testing: returns a flag indicating hit test details, plus information about position.
contextObj is returned to specify what object position is relevant to, since otherwise there’s an ambiguity. @ obj might not be a child of contextObj, since we may be referring to the container itself if we have no hit on a child - for example if we click outside an object.
The function puts the position in textPosition if one is found. pt is in logical units (a zero y position is at the beginning of the buffer).
- Parameters:
dc (wx.DC)
context (wx.richtext.RichTextDrawingContext)
pt (wx.Point)
flags (int)
- Return type:
Tuple[int, int, RichTextObject, RichTextObject]
- Returns:
One of the wx.richtext.RichTextHitTestFlags values.
- ImportFromXML(self, buffer, node, handler, recurse)¶
Imports this object from
XML
.- Parameters:
buffer (wx.richtext.RichTextBuffer)
node (wx.xml.XmlNode)
handler (wx.richtext.RichTextXMLHandler)
recurse (bool)
- Return type:
bool
- Invalidate(self, invalidRange=RICHTEXT_ALL)¶
Invalidates the object at the given range.
With no argument, invalidates the whole object.
- Parameters:
invalidRange (wx.richtext.RichTextRange)
- Return type:
None
- IsAtomic(self)¶
Returns
True
if no user editing can be done inside the object.This returns
True
for simple objects,False
for most composite objects, butTrue
for fields, which if composite, should not be user-edited.- Return type:
bool
- IsComposite(self)¶
Returns
True
if this object is composite.- Return type:
bool
- IsEmpty(self)¶
Returns
True
if the object is empty.- Return type:
bool
- IsFloatable(self)¶
Returns
True
if this class of object is floatable.- Return type:
bool
- IsFloating(self)¶
Returns
True
if this object is currently floating.- Return type:
bool
- IsShown(self)¶
Returns
True
if the object will be shown,False
otherwise.- Return type:
bool
- IsTopLevel(self)¶
Returns
True
if this object is top-level, i.e. contains its own paragraphs, such as a text box.- Return type:
bool
- Layout(self, dc, context, rect, parentRect, style)¶
Lay the item out at the specified position with the given size constraint.
Layout must set the cached size. rect is the available space for the object, and parentRect is the container that is used to determine a relative size or position (for example if a text box must be 50% of the parent text box).
- Parameters:
dc (wx.DC)
context (wx.richtext.RichTextDrawingContext)
rect (wx.Rect)
parentRect (wx.Rect)
style (int)
- Return type:
bool
- LayoutToBestSize(self, dc, context, buffer, parentAttr, attr, availableParentSpace, availableContainerSpace, style)¶
Lays out the object first with a given amount of space, and then if no width was specified in attr, lays out the object again using the minimum size.
availableParentSpace is the maximum space for the object, whereas availableContainerSpace is the container with which relative positions and sizes should be computed. For example, a text box whose space has already been constrained in a previous layout pass to availableParentSpace, but should have a width of 50% of availableContainerSpace. (If these two rects were the same, a 2nd pass could see the object getting too small.)
- Parameters:
dc (wx.DC)
context (wx.richtext.RichTextDrawingContext)
buffer (wx.richtext.RichTextBuffer)
parentAttr (wx.richtext.RichTextAttr)
attr (wx.richtext.RichTextAttr)
availableParentSpace (wx.Rect)
availableContainerSpace (wx.Rect)
style (int)
- Return type:
bool
- Merge(self, object, context)¶
Returns
True
if this object merged itself with the given one.The calling code will then delete the given object.
- Parameters:
object (wx.richtext.RichTextObject)
context (wx.richtext.RichTextDrawingContext)
- Return type:
bool
- Move(self, pt)¶
Moves the object recursively, by adding the offset from old to new.
- Parameters:
pt (wx.Point)
- Return type:
None
- Reference(self)¶
Reference-counting allows us to use the same object in multiple lists (not yet used).
- Return type:
None
- SetAttributes(self, attr)¶
Sets the object’s attributes.
- Parameters:
attr (wx.richtext.RichTextAttr)
- Return type:
None
- SetCachedSize(self, sz)¶
Sets the cached object size as calculated by Layout.
- Parameters:
sz (wx.Size)
- Return type:
None
- SetDescent(self, descent)¶
Sets the stored descent value.
- Parameters:
descent (int)
- Return type:
None
- SetMargins(self, *args, **kw)¶
Set the margin around the object, in pixels.
SetMargins (self, margin)
- Parameters:
margin (int)
- Return type:
None
SetMargins (self, leftMargin, rightMargin, topMargin, bottomMargin)
- Parameters:
leftMargin (int)
rightMargin (int)
topMargin (int)
bottomMargin (int)
- Return type:
None
- SetMaxSize(self, sz)¶
Sets the maximum object size as calculated by Layout.
This allows us to fit an object to its contents or allocate extra space if required.
- Parameters:
sz (wx.Size)
- Return type:
None
- SetMinSize(self, sz)¶
Sets the minimum object size as calculated by Layout.
This allows us to constrain an object to its absolute minimum size if necessary.
- Parameters:
sz (wx.Size)
- Return type:
None
- SetName(self, name)¶
Sets the identifying name for this object as a property using the “name” key.
- Parameters:
name (string)
- Return type:
None
- SetOwnRange(self, range)¶
Set the object’s own range, for a top-level object with its own position space.
- Parameters:
range (wx.richtext.RichTextRange)
- Return type:
None
- SetParent(self, parent)¶
Sets the pointer to the parent object.
- Parameters:
parent (wx.richtext.RichTextObject)
- Return type:
None
- SetPosition(self, pos)¶
Sets the object position in pixels.
- Parameters:
pos (wx.Point)
- Return type:
None
- SetProperties(self, props)¶
Sets the object’s properties.
- Parameters:
props (wx.richtext.RichTextProperties)
- Return type:
None
- SetRange(self, range)¶
Sets the object’s range within its container.
- Parameters:
range (wx.richtext.RichTextRange)
- Return type:
None
- Show(self, show)¶
Call to show or hide this object.
This function does not cause the content to be laid out or redrawn.
- Parameters:
show (bool)
- Return type:
None
- Split(self, context)¶
Returns the final object in the split objects if this object was split due to differences between sub-object virtual attributes.
Returns itself if it was not split.
- Parameters:
context (wx.richtext.RichTextDrawingContext)
- Return type:
- UsesParagraphAttributes(self)¶
Returns
True
if this object takes note of paragraph attributes (text and image objects don’t).- Return type:
bool
Properties¶
- AbsolutePosition¶
- Attributes¶
See
GetAttributes
andSetAttributes
- BestSize¶
See
GetBestSize
- BottomMargin¶
See
GetBottomMargin
- CachedSize¶
See
GetCachedSize
andSetCachedSize
- Container¶
See
GetContainer
- Descent¶
See
GetDescent
andSetDescent
- FloatDirection¶
- LeftMargin¶
See
GetLeftMargin
- MaxSize¶
See
GetMaxSize
andSetMaxSize
- MinSize¶
See
GetMinSize
andSetMinSize
- NaturalSize¶
See
GetNaturalSize
- OwnRange¶
See
GetOwnRange
andSetOwnRange
- OwnRangeIfTopLevel¶
- ParentContainer¶
- Position¶
See
GetPosition
andSetPosition
- Properties¶
See
GetProperties
andSetProperties
- PropertiesMenuLabel¶
- RightMargin¶
See
GetRightMargin
- TopMargin¶
See
GetTopMargin
- XMLNodeName¶
See
GetXMLNodeName