[wxPython] Change font and dimensions for a control at runtime

hi wxPeople...

once more i (Da german kid) have a question. First -Thx- to all
who helped me out at the past. all of it works (nearly). now i want to
change the font and the dimensions for all controls at
runtime if the user choose a new font...
But all controls (a lof of them) already initalized and owned
the "old" font which was actual at programstart. All items was
prepared with the following function...

#point, fonttype, fontfont owned values loaded from the database
def setfont( item ):
    # SetFont
    item.SetFont( wxFont( point, wxSWISS, wxNORMAL, fonttype, FALSE,
fontfont ) )

    # Now get the new Size for the font and set the size
    # Its not the point of my interest, but it also the function...
    # I know its not the fine art to identify the control, but it works...
    itemsize=item.GetBestSize()
    checkstring=(str(item)[:16])
    if checkstring== "<C wxTextCtrl in":
        if item.GetSize().GetHeight()<30:

item.SetSize(wxSize(item.GetSize().GetWidth(),itemsize.GetHeight()))
        else:
            pass
    elif checkstring== "<C wxButton inst":
        item.SetSize(itemsize)
    elif checkstring== "<C wxButton inst":
        item.SetSize(itemsize)
    elif checkstring== "<C wxCheckBox in":
        if item.GetSize().GetWidth() < itemsize.GetWidth():
            item.SetSize(itemsize)
        else:
            if item.GetSize().GetHeight() < itemsize.GetHeight():

item.SetSize(wxSize(item.GetSize().GetWidth(),itemsize.GetHeight()))
            else:
                pass
    elif checkstring== "<C wxRadioBox in":
        item.SetSize(itemsize)
    elif checkstring== "<C wxRadioButton":
        item.SetSize(wxSize(itemsize.GetWidth(),item.GetSize().GetHeight()))
    elif checkstring== "<C wxStaticText ":
        try:
            if item.ReturnStaticWidth(): # Speziell
für My_wxStaticText()

item.SetSize(wxSize(item.GetSize().GetWidth(),itemsize.GetHeight()))
            else:
                item.SetSize(itemsize)
        except:
            item.SetSize(itemsize)
    else:
        print(str(item)[:16])
    return item

All Controls (resp. all dialogs and forms) are in one file. They loaded
from there
in the mainframe. i know that i have to ""refresh"" all controls, so that
they automaticly
call setfont(item) and get the new font and size. After that the sizers
have to
layout new..
or could i import the file with the controls new, so that all controls be
new loaded, with the
new preferences?

hm, whatever. i also know (!) that my writin - english is so bad that
nobody understood my
problem. i check the list every hour. Now i m searching further for a
solution...

thx, reen

Rene Freund

···

--------------------------
rene@meder.de

I am still relatively new to wxPython and wxWindows, so do not take my note
very seriously...

I used StyledTextCtrl (Scintilla) for a little while as my output widget (no
data editing, just
output data from other processes), and noticed several draw-backs about it:
1) no native word wrapping (I coded simple static word wrapping upon data
insertion)
2) was unable to get it work fast under Linux (GTK+) - it worked fine on
same machine in
  Win2k

So I went looking for other possibilities to achieve what I needed:
I looked at GTK+ and Win32 API and noticed that GTK+'s Text widget and Win32
RichText
widget support rich text. I added couple methods to wxGTK and will do same
for wxMSW today.
And I patched the wxPython wrapper slightly for it to use those methods.

What I added for TextCtrl:
  bool SetActiveFont( const wxFont &font )
  bool SetActiveForegroundColour( const wxColour &colour )
  bool SetActiveBackgroundColour( const wxColour &colour )

These methods change private variables which are used in WriteText and
AppendText methods
for new text addition.

What I changed for TextCtrl:
  WriteText
  AppendText
Changed these to use those internal variables managed by above functions for
new text added
to widget.

I was curious - has anyone else played with this topic? On the FAQ of
wxWindows site
I read that this has not been implemented in wxWindows - if it so, and noone
has worked
on this - I can add couple more methods for wxGTK and wxMSW to do styling of
already
existing text, and this could be added to standart distribution? If noone
likes my proposal,
I will just use it myself then... Btw, to keep this portable (not sure if
this can be done
for wxMotif or wxMac - these methods can be implemented on those to do just
nothing...:slight_smile:

jEECHA

I used StyledTextCtrl (Scintilla) for a little while as my output widget

(no

data editing, just
output data from other processes), and noticed several draw-backs about

it:

1) no native word wrapping (I coded simple static word wrapping upon data
insertion)

There have been lots of discussions about this on the scintilla list. IIRC,
the bottom line is that it is real hard to implement it without imacting
performance of the rest scintilla.

2) was unable to get it work fast under Linux (GTK+) - it worked fine on
same machine in
Win2k

This has been fixed in CVS and will be in the next release. (Soon)

So I went looking for other possibilities to achieve what I needed:
I looked at GTK+ and Win32 API and noticed that GTK+'s Text widget and

Win32

RichText
widget support rich text. I added couple methods to wxGTK and will do same
for wxMSW today.
And I patched the wxPython wrapper slightly for it to use those methods.

...

and this could be added to standart distribution?

Sounds good, I think it is something that others would like. If you can
make a diff against the CVS version of the files and then submit it as a
patch at the Sourceforge page then that would be the best.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!

Btw, wxPython build instructions suggest SWIG 1.1-883 to be used,
but 1.1-883 version ./configure does not know how to find Python 2.0 or 2.1
includes and libraries...

jEECHA

Before I start messing up the CVS version, I will try to summarize changes I
proposed ...
Btw, do wxWindows development folks read this too? Or should I post this
message
on their list too, or maybe wxPython folks are very same folks who do
wxWindows :slight_smile: ?

I am willing to make:

···

======================
wxWindows API changes:
-----------------------
  class TextCtrl
  public
    /* in fact - do we need Get* methods for these? */
    /* not quite sure anyone will ever use those... */
    /* sets/gets font to be used for new data addition */
    bool SetActiveFont( const wxFont &font );
    wxFont GetActiveFont();
    /* sets/gets foreground colour to be used for new data addition */
    bool SetActiveForegroundColour( const wxColour &colour);
    wxColour GetActiveForegroundColour();
    /* sets/gets background colour to be used for new data addition */
    bool SetActiveBackgroundColour( const wxColour &colour);
    wxColour GetActiveBackgroundColour();

    /* styles range using active font/foreground colour/background colour */
    bool SetStyling(long start, long end);

  private
    /* stores active font */
    wxFont m_activeFont;
    /* stores active foreground color */
    wxColour m_activeForegroundColour;
    /* stores active background color */
    wxColour m_activeBackgroundColour;

Methods AppendText and WriteText wil be changed to use these variables.
Existing methods
SetForegroundColour, SetBackgroundColour and SetFont will be left same.
If underlaying toolkit does not support rich text in it's control (older
GTK+, maybe OS/2, Mac, Motif),
new methods are implemented to do nothing.

wxPython API changes:
----------------------
  Changes are made to wrap above specified methods into Python (just a matter
of adding
    couple lines to controls.i :slight_smile:

I can do wxGTK and wxPython changes myself, and probably wxMSW changes once
I get MS Visual Studio too,
which will happen tomorrow.
Basically I already have a working prototype for GTK+ except for SetStyling
method, which will
require some more documentation studying from me, but I already know how to
do that on MSW from my
previous experiences with it's Rich Text control...

If proposed changes is OK, let me know and I will do them.

jEECHA

Before I start messing up the CVS version, I will try to summarize changes

I

proposed ...
Btw, do wxWindows development folks read this too? Or should I post this
message
on their list too,

If you want to discuss it first you should send it to the wx-dev list. That
is where you can reach all the core developers. I think the only ones on
this list are myself, and recently Vaclav as well.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!

I made the changes for wxGTK and wxPython we were talking about,
except for SetStyling(), since I did not find a nice way to do
that in GTK except for removing selected range and readding it to
control, which is quite dirty...

I already made cvs diffs for the changed files but then I started
to ponder - since these SetActive* methods do not more than just
change some private variables, perhaps these functions should be
implemented in TextCtrlBase class, not TextCtrl itself. If I get
the structure of sources correctly TextCtrlBase is used for all
wrappers (GTK+, MSW, Mac etc), so it might be the right place to
add SetActive methods to - it will not require these methods to
be added for each interface.

Those private variables will be used in WriteText and AppendText
methods, which are defined for each individual wrapper, so if
particular wrapper is not changed - they all will still be API
compatible.

Another problem - I cannot get MS VS right now, but I can write
the code for wxMSW, and maybe someone else can compile and test it?

jEECHA

I made the changes for wxGTK and wxPython we were talking about,
except for SetStyling(), since I did not find a nice way to do
that in GTK except for removing selected range and readding it to
control, which is quite dirty...

If that's the only way then it would be better to do it dirty than not at
all. But perhaps if you ask on the wx-dev list somebody may be able to
help.

I already made cvs diffs for the changed files but then I started
to ponder - since these SetActive* methods do not more than just
change some private variables, perhaps these functions should be
implemented in TextCtrlBase class, not TextCtrl itself. If I get
the structure of sources correctly TextCtrlBase is used for all
wrappers (GTK+, MSW, Mac etc), so it might be the right place to
add SetActive methods to - it will not require these methods to
be added for each interface.

Sounds good to me. That's what the base class is there for.

Another problem - I cannot get MS VS right now, but I can write
the code for wxMSW, and maybe someone else can compile and test it?

You can build wxWindows (but not wxPython yet) with the free mingw32 with
and also with the free Borland compiler. You can build and test with that
before submitting the patch if you like. Otherwise go ahead and submit the
patch with a note about it being untested on MSW and ask on wx-dev for
somebody to take a look at it.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!