4

I want a wx.TextCtrl to take the entire remaining width of a panel. It is placed with a wx.StaticText and a wx.Button in a horizontal wx.BoxSizer in a vertical wx.BoxSizer in a wx.lib.scrolledpanel.ScrolledPanel (which is self below):

# create TextCtrl
self.fileNameInput = wx.TextCtrl (self, style=wx.TE_PROCESS_ENTER)
# create horizontal sizer with 3 items
self.fileNameSizer = wx.BoxSizer (wx.HORIZONTAL)
self.fileNameSizer.Add (wx.StaticText (self, -1, 'none'), flag=(wx.ALIGN_CENTER_VERTICAL))
self.fileNameSizer.Add (self.fileNameInput, proportion=1, flag=(wx.EXPAND | wx.ALIGN_CENTER_VERTICAL))
self.fileNameSizer.Add (wx.Button (self, label='Button'), flag=(wx.ALIGN_CENTER_VERTICAL))
# create vertical sizer
self.SetSizer (wx.BoxSizer (wx.VERTICAL))
self.GetSizer ().Add (self.fileNameSizer)

Neither proportion nor wx.EXPAND help to make the TextCtrl larger, presumably because the sizer looks at the TextCtrls own width. But I did not find any style or flag for the `'TextCtrl' to make it variable-width..?

Thanks for ideas!

EDIT: Replaced "..." by something working

virtualnobi
  • 1,140
  • 2
  • 11
  • 35
  • 2
    You'll get more answers if you make it easier for people. This would be much easier to answer if you posted a self-contained minimal example that would actually run. I think I know what's wrong, but I don't want to post an answer until I check it, and I'm not going to spend all time replacing "..."s, etc. – tom10 Dec 06 '13 at 05:27
  • @tom10: thanks for being so thorough, but I wanted to keep uninteresting stuff outside and assumed I would be able to figure out the details if I get a hint from someone who thinks he knows what's wrong... :-| Anyway, I replaced the ...s – virtualnobi Dec 06 '13 at 08:58
  • 2
    It would be very helpful if you create self-contained minimal runnable example which demonstrates the problem. Similar to my answer. – Fenikso Dec 06 '13 at 09:19

1 Answers1

4

I think that what is wrong is this line:

self.GetSizer().Add(self.fileNameSizer)

There should be some of proportion=1 and/or flag=wx.EXPAND to make the nested sizer match its master size.

Something like this:

import wx

class MainWindow(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)

        self.panel = wx.Panel(self)

        self.label = wx.StaticText(self.panel, label="Label")
        self.text = wx.TextCtrl(self.panel)
        self.button = wx.Button(self.panel, label="Test")

        self.button1 = wx.Button(self.panel, label="ABOVE")
        self.button2 = wx.Button(self.panel, label="BELLOW")

        self.horizontal = wx.BoxSizer()
        self.horizontal.Add(self.label, flag=wx.CENTER)
        self.horizontal.Add(self.text, proportion=1, flag=wx.CENTER)
        self.horizontal.Add(self.button, flag=wx.CENTER)

        self.vertical = wx.BoxSizer(wx.VERTICAL)
        self.vertical.Add(self.button1, flag=wx.EXPAND)
        self.vertical.Add(self.horizontal, proportion=1, flag=wx.EXPAND)
        self.vertical.Add(self.button2, flag=wx.EXPAND)

        self.panel.SetSizerAndFit(self.vertical)  
        self.Show()


app = wx.App(False)
win = MainWindow(None)
app.MainLoop()

BTW: Please stop adding space before ( in method calls. Also I would recommend object oriented approach so you do not loose access to your GUI objects.

Fenikso
  • 9,251
  • 5
  • 44
  • 72
  • Thanks a lot - I was looking at the wrong sizer... silly me. And yes, I do already follow your OO advice, but why should I keep function and `(` together (apart from style, I mean)? – virtualnobi Dec 09 '13 at 15:49
  • 2
    Just for the style. It is a common convention. There are a few styles used, but this is so weird that it becomes hard to read. – Fenikso Dec 09 '13 at 15:50
  • Well, I'll try. :-) Thanks for the background! – virtualnobi Dec 09 '13 at 16:11