Hi all,
I'd like to ask about the possibility to combine some text styles in a
TextCtrl widget.
I'd like to set some rather basic styles (e.g. bold, italic,
underlined text in black, blue, red ...) and also the combinations of
these simple properties.
I tried wx.TextAttr.Merge( ), but it doesn't seem to work as needed,
probably because of the way the styles are defined
b = wx.TextAttr("BLACK", wx.NullColour, wx.Font(-1,
wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.BOLD))
i = wx.TextAttr("BLACK", wx.NullColour, wx.Font(-1,
wx.FONTFAMILY_DEFAULT, wx.ITALIC, wx.NORMAL))
...
wx.TextAttr.Merge(base, overlay) on b and i effectively results in
the overlay style, as all its properties replace the base.
Is it somehow possible to define only the relevant property of the
overlay, so that the others would remain as in the base style?
(e.g. can I only add italic to a bold base text to obtain bold italic?)
It seems wx.TextAttr.Combine( ) works the same in this respect, what
is actually its usage as oposed to Merge?
Or is there some other way to achieve this combined styling in a
TextCtrl? (I can't use e.g. richtext.RichTextCtrl for other reasons).
One approach might be to maintain the list of all the style
combinations needed, but is it the only possible way,or am I missing
something?
Hi all,
I'd like to ask about the possibility to combine some text styles in a
TextCtrl widget.
I'd like to set some rather basic styles (e.g. bold, italic,
underlined text in black, blue, red ...) and also the combinations of
these simple properties.
I tried wx.TextAttr.Merge( ), but it doesn't seem to work as needed,
probably because of the way the styles are defined
b = wx.TextAttr("BLACK", wx.NullColour, wx.Font(-1,
wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.BOLD))
i = wx.TextAttr("BLACK", wx.NullColour, wx.Font(-1,
wx.FONTFAMILY_DEFAULT, wx.ITALIC, wx.NORMAL))
...
wx.TextAttr.Merge(base, overlay) on b and i effectively results in
the overlay style, as all its properties replace the base.
Is it somehow possible to define only the relevant property of the
overlay, so that the others would remain as in the base style?
(e.g. can I only add italic to a bold base text to obtain bold italic?)
It seems wx.TextAttr.Combine( ) works the same in this respect, what
is actually its usage as oposed to Merge?
It returns a new attr object in which any attributes not set in attr are set from attrDef, and then any still not set are fetched from the textctrl. Merge is supposed to work the same way except it doesn't fall back to the textctrl, and the order of the other two args is reversed.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
Thanks for the answer Robin!
I guess, the real problem I now have with this code is actualy with
using the wx.Font() as a part of wx.TextAttr (as I'd like to combine
mostly font properties - bold, italic, underlined - possibly also
colour via TextAttr).
It seems, that for wx.Font() the basic attributes are explicitely required:
__init__(self, pointSize, family, style, weight, underline=False,
face=EmptyString, encoding=FONTENCODING_DEFAULT)
Is it in this case somehow possible to set only some of the font
parameters of the overlay style, while retaining the others from the
base style with Merge() ?
Thanks again,
Vlasta
···
2009/3/23 Robin Dunn <robin@alldunn.com>:
Vlastimil Brom wrote:
Hi all,
I'd like to ask about the possibility to combine some text styles in a
TextCtrl widget.
I'd like to set some rather basic styles (e.g. bold, italic,
underlined text in black, blue, red ...) and also the combinations of
these simple properties.
I tried wx.TextAttr.Merge( ), but it doesn't seem to work as needed,
probably because of the way the styles are defined
b = wx.TextAttr("BLACK", wx.NullColour, wx.Font(-1,
wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.BOLD))
i = wx.TextAttr("BLACK", wx.NullColour, wx.Font(-1,
wx.FONTFAMILY_DEFAULT, wx.ITALIC, wx.NORMAL))
...
wx.TextAttr.Merge(base, overlay) on b and i effectively results in
the overlay style, as all its properties replace the base.
Is it somehow possible to define only the relevant property of the
overlay, so that the others would remain as in the base style?
(e.g. can I only add italic to a bold base text to obtain bold italic?)
It seems wx.TextAttr.Combine( ) works the same in this respect, what
is actually its usage as oposed to Merge?
It returns a new attr object in which any attributes not set in attr are set
from attrDef, and then any still not set are fetched from the textctrl.
Merge is supposed to work the same way except it doesn't fall back to the
textctrl, and the order of the other two args is reversed.
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
I guess, the real problem I now have with this code is actualy with
using the wx.Font() as a part of wx.TextAttr (as I'd like to combine
mostly font properties - bold, italic, underlined - possibly also
colour via TextAttr).
It seems, that for wx.Font() the basic attributes are explicitely required:
__init__(self, pointSize, family, style, weight, underline=False,
face=EmptyString, encoding=FONTENCODING_DEFAULT)
Is it in this case somehow possible to set only some of the font
parameters of the overlay style, while retaining the others from the
base style with Merge() ?
No, wx.TextAttr only looks at colors, font and alignment. It doesn't look at the attributes of the font at all as far as I know.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
Ok, thanks for the confirmation Robin,
I'll try to maintain all of the font+style combinations, or maybe
implement some simplified merging of font attributes before the
resulting Font is constructed.
I really appreciate your prompt answer;
regards,
Vlasta
···
2009/3/23 Robin Dunn <robin@alldunn.com>:
Vlastimil Brom wrote:
I guess, the real problem I now have with this code is actualy with
using the wx.Font() as a part of wx.TextAttr (as I'd like to combine
mostly font properties - bold, italic, underlined - possibly also
colour via TextAttr).
It seems, that for wx.Font() the basic attributes are explicitely
required:
__init__(self, pointSize, family, style, weight, underline=False,
face=EmptyString, encoding=FONTENCODING_DEFAULT)
Is it in this case somehow possible to set only some of the font
parameters of the overlay style, while retaining the others from the
base style with Merge() ?
No, wx.TextAttr only looks at colors, font and alignment. It doesn't look
at the attributes of the font at all as far as I know.
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!