Setting the size of a TextCtrl

I am using XRCed to generate a simple UI.

By default, the TextCtrl has a few characters width in the UI. How do I
increase the *visible* working length of the control? Changing "size" in
XRCed is increasing the totalscrollable length, while I want to change
the visible length. What is this dimension called, and how does one
change it after the control has already been instantiated? There is no
SetSize()

- Sandip

···

--
Sandip Bhattacharya * Puroga Technologies * sandip@puroga.com
Work: http://www.puroga.com * Home/Blog: http://www.sandipb.net/blog

PGP/GPG Signature: 51A4 6C57 4BC6 8C82 6A65 AE78 B1A1 2280 A129 0FF3

the visible length. What is this dimension called, and how does one
change it after the control has already been instantiated? There is no
SetSize()

Hi Sandip,

Do you know that you don't want to use sizers?

Typically, you would set the wxExpand flag so that it expands to fit
the controls around it. Try loading the attached xrc file with XRCed.
I've also put that in the top cell of a vertical box sizer, and put a
growing spacer (with option 1) below it so the text control doesn't
get too tall.

-Jim

wideTextControl.xrc (490 Bytes)

James Carroll wrote:

the visible length. What is this dimension called, and how does one
change it after the control has already been instantiated? There is no
SetSize()

Hi Sandip,

Do you know that you don't want to use sizers?

Typically, you would set the wxExpand flag so that it expands to fit
the controls around it. Try loading the attached xrc file with XRCed.
I've also put that in the top cell of a vertical box sizer, and put a
growing spacer (with option 1) below it so the text control doesn't
get too tall.

Hi Jim!

Yes that work for your example. I didnt know about the wxExpand.
However, take a look at the following exercise that I am doing. I am
using a GridSizer to make the columns look more consistent. However the
textctrl isnt expanding, even with the wxExpand flag. What am i doing wrong?

- Sandip

The code I am using is:

from wxPython.wx import *
from wxPython.xrc import *

class MyApp(wxApp):
    def OnInit(self):
        self.res = wxXmlResource("fahandcel.xrc")
        self.frame = self.res.LoadFrame(None,"frame_main")
        self.panel = XRCCTRL(self.frame,"panel_main")
        self.ecel = XRCCTRL(self.panel,"e_cel")
        self.efah = XRCCTRL(self.panel,"e_fah")

        EVT_TEXT_ENTER(self.frame, XRCID("e_cel"), self.EnterVal)
        EVT_TEXT_ENTER(self.frame, XRCID("e_fah"), self.EnterVal)

        self.mb = self.res.LoadMenuBar("menu_main")
        EVT_MENU(self.frame, XRCID("menu_quit"), self.ShutDown)

        self.frame.SetMenuBar(self.mb)
        self.frame.Show(True)
        return True

    def EnterVal(self,event):
        tofah = False
        if event.GetEventObject() == self.ecel:
            tofah = True

        try:
            reading = float(event.GetEventObject().GetValue())
            if tofah:
                self.efah.SetValue(str(reading * 9/5.0+32))
            else:
                self.ecel.SetValue(str((reading-32) * 5/9.0))
        except ValueError:
            event.GetEventObject().SetValue("Invalid entry")
            event.GetEventObject().SetSelection(-1,-1)

    def ShutDown(self,event):
        self.frame.Destroy()

MyApp().MainLoop()

fahandcel.xrc (1.41 KB)

···

--
Sandip Bhattacharya * Puroga Technologies * sandip@puroga.com
Work: http://www.puroga.com * Home/Blog: http://www.sandipb.net/blog

PGP/GPG Signature: 51A4 6C57 4BC6 8C82 6A65 AE78 B1A1 2280 A129 0FF3

First, in XRCed, click on the grid sizer and in the field called
'growable cols' have it read [1] so it knows that the second column
can grow.

Next, set the 'option' to 1 for both text controls.

I think of 'option' as a proportion setting. You tell it which cell
of the sizer to expand by how much. If you have two cells in a sizer,
and set the option in one to 2 and the other to 3, then the first will
always take 2/5ths of the size. Here, setting the static text to 0
and the text to 1 means that the static text won't expand, but the
text control will do all the expanding.

With these two changes, your text controls might just start growing
with the size of your frame. For some reason XRCed is freezing on me
(in windows XP with python 2.4 and wxPython 2.6.1) when I try to make
these changes... but hopefully you'll have better luck.)

-Jim

···

On 7/14/05, Sandip Bhattacharya <sandip@lug-delhi.org> wrote:

James Carroll wrote:
>>the visible length. What is this dimension called, and how does one
>>change it after the control has already been instantiated? There is no
>>SetSize()
>
>
> Hi Sandip,
>
> Do you know that you don't want to use sizers?
>
> Typically, you would set the wxExpand flag so that it expands to fit
> the controls around it. Try loading the attached xrc file with XRCed.
> I've also put that in the top cell of a vertical box sizer, and put a
> growing spacer (with option 1) below it so the text control doesn't
> get too tall.

Hi Jim!

Yes that work for your example. I didnt know about the wxExpand.
However, take a look at the following exercise that I am doing. I am
using a GridSizer to make the columns look more consistent. However the
textctrl isnt expanding, even with the wxExpand flag. What am i doing wrong?

- Sandip

The code I am using is:

from wxPython.wx import *
from wxPython.xrc import *

class MyApp(wxApp):
    def OnInit(self):
        self.res = wxXmlResource("fahandcel.xrc")
        self.frame = self.res.LoadFrame(None,"frame_main")
        self.panel = XRCCTRL(self.frame,"panel_main")
        self.ecel = XRCCTRL(self.panel,"e_cel")
        self.efah = XRCCTRL(self.panel,"e_fah")

        EVT_TEXT_ENTER(self.frame, XRCID("e_cel"), self.EnterVal)
        EVT_TEXT_ENTER(self.frame, XRCID("e_fah"), self.EnterVal)

        self.mb = self.res.LoadMenuBar("menu_main")
        EVT_MENU(self.frame, XRCID("menu_quit"), self.ShutDown)

        self.frame.SetMenuBar(self.mb)
        self.frame.Show(True)
        return True

    def EnterVal(self,event):
        tofah = False
        if event.GetEventObject() == self.ecel:
            tofah = True

        try:
            reading = float(event.GetEventObject().GetValue())
            if tofah:
                self.efah.SetValue(str(reading * 9/5.0+32))
            else:
                self.ecel.SetValue(str((reading-32) * 5/9.0))
        except ValueError:
            event.GetEventObject().SetValue("Invalid entry")
            event.GetEventObject().SetSelection(-1,-1)

    def ShutDown(self,event):
        self.frame.Destroy()

MyApp().MainLoop()

--
Sandip Bhattacharya * Puroga Technologies * sandip@puroga.com
Work: http://www.puroga.com * Home/Blog: http://www.sandipb.net/blog

PGP/GPG Signature: 51A4 6C57 4BC6 8C82 6A65 AE78 B1A1 2280 A129 0FF3

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

James Carroll wrote:

First, in XRCed, click on the grid sizer and in the field called
'growable cols' have it read [1] so it knows that the second column
can grow.

Next, set the 'option' to 1 for both text controls.

I think of 'option' as a proportion setting. You tell it which cell
of the sizer to expand by how much. If you have two cells in a sizer,
and set the option in one to 2 and the other to 3, then the first will
always take 2/5ths of the size. Here, setting the static text to 0
and the text to 1 means that the static text won't expand, but the
text control will do all the expanding.

With these two changes, your text controls might just start growing
with the size of your frame. For some reason XRCed is freezing on me
(in windows XP with python 2.4 and wxPython 2.6.1) when I try to make
these changes... but hopefully you'll have better luck.)

Cool! Yes, the text controls have started growing. Two things further
that I would like to ask:
1. Why doesnt the hgap of wxFlexGridSizer make any difference to the
distance between the control and the border? Is hgap only between
elements of the sizer?
2. Isnt there any way to fix the length of the textcontrol to a specific
number of characters? And tell teh frame that grow only as much as the
textctrl needs, but dont allow yourself to be resized further?

- Sandip

···

--
Sandip Bhattacharya * Puroga Technologies * sandip@puroga.com
Work: http://www.puroga.com * Home/Blog: http://www.sandipb.net/blog

PGP/GPG Signature: 51A4 6C57 4BC6 8C82 6A65 AE78 B1A1 2280 A129 0FF3

Hi Sandip,

Cool! Yes, the text controls have started growing. Two things further
that I would like to ask:
1. Why doesnt the hgap of wxFlexGridSizer make any difference to the
distance between the control and the border? Is hgap only between
elements of the sizer?

1. Yes, the gap is just between elements... There is a separate
border option. When you set the border, you also have to set some
additional flags: wxAll , wxLeft, wxRight, wxTop, wxBottom ( all is
really the other four or-ed together.) The border will just be on the
sides specified.

2. Isnt there any way to fix the length of the textcontrol to a specific
number of characters? And tell teh frame that grow only as much as the
textctrl needs, but dont allow yourself to be resized further?

I did a test where I created a panel in XRCed, and added a horizontal
box sizer to that. In the box sizer, I added a static text and a text
control, and I set the size of the text control to 400, -1 (400
pixels wide, default height). When I preview this it looks right.
One way to keep the frame from resizing is to specifiy it has a
STATIC_BORDER in the frame's style. There is probably a way of doing
this that still looks like a frame... (the static border removes the
title bar.) I'm not sure how. You could handle the resize events in
your code and choose to ignore them if you want. This would take a
completely empty OnSize handler (don't call event skip, and don't pass
it to the function's parent.)

-Jim

James Carroll wrote:

STATIC_BORDER in the frame's style. There is probably a way of doing
this that still looks like a frame... (the static border removes the
title bar.) I'm not sure how. You could handle the resize events in
your code and choose to ignore them if you want. This would take a
completely empty OnSize handler (don't call event skip, and don't pass
it to the function's parent.)

FWIW, from the wxWidgets help file: "The default frame style is for normal, resizeable frames. To create a frame which can not be resized by user, you may use the following combination of styles: wxDEFAULT_FRAME_STYLE & ~ (wxRESIZE_BORDER | wxRESIZE_BOX | wxMAXIMIZE_BOX)".

Don Dwiggins
Advanced Publishing Technology

Don Dwiggins wrote:

FWIW, from the wxWidgets help file: "The default frame style is for
normal, resizeable frames. To create a frame which can not be resized by
user, you may use the following combination of styles:
wxDEFAULT_FRAME_STYLE & ~ (wxRESIZE_BORDER | wxRESIZE_BOX |
wxMAXIMIZE_BOX)".

I had read that. The problem is that XRCED doesnt allow such
combinations during UI creation, and one has to do it from code. My
attempts in doing it using frame.SetStyle(frame.GetStyle) havent been
working.

I have shifted to wxglade from XRCed, and this problem has been solved.

Thanks

···

--
Sandip Bhattacharya * Puroga Technologies * sandip@puroga.com
Work: http://www.puroga.com * Home/Blog: http://www.sandipb.net/blog

PGP/GPG Signature: 51A4 6C57 4BC6 8C82 6A65 AE78 B1A1 2280 A129 0FF3