I've got a dialog which includes a couple of TextCtrls as fields, one read-only, the other where the user enters a string. (Code extract below.)
My problem is that the text-entry field is sometimes too narrow, and as the user enters text it doesn't scroll. I don't care about scrolling so much (though that should be controllable, shouldn't it, without adding a horizontal scrollbar to a one-line-high field?). I just want to make the field wide enough for any likely string (I can predict pretty well in this case). But I don't want it to extend all the way to both edges of the dialog, which looks stupid.
I can't figure out the magic combination for making it *bigger* but not *too big*. (Fooling around with the dialog's self.GetSizeTuple and so on doesn't seem very promising. I tried a second, horizontal sizer around (each) TextCtrl, but maybe I didn't get the right combination of flags for its style for my purpose?
My dialog's __init__ contains these lines, plus others clearly irrelevant to the problem:
wx.Dialog.__init__(self, None, id, style=wx.DEFAULT_DIALOG_STYLE |
wx.RESIZE_BORDER)
self.textline1 = wx.StaticText( . . .
self.wordAsKnown = wx.TextCtrl(self, -1, "") # my read-only field
self.wordAsKnown.AppendText(wordSyls)
self.wordAsKnown.SetEditable(0)
self.textline4 = wx.StaticText( . . .
self.wordCorrected = wx.TextCtrl(self, -1, "") # my editable field
self.OKbutton = wx.Button(self, wx.ID_OK, " OK ")
self.OKbutton.SetDefault()
self.CancelButton = wx.Button(self, wx.ID_CANCEL, " Cancel ")
mainsizer = wx.BoxSizer(wx.VERTICAL)
mainsizer.Add((20, 20), 0)
mainsizer.Add(self.textline1, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 3)
# . . . (more static stuff)
mainsizer.Add((20,20),0)
mainsizer.Add(self.wordAsKnown, 0, wx.ALIGN_CENTER_HORIZONTAL, 3)
# . . . (more spacers and static stuff)
mainsizer.Add(self.wordCorrected, 0, wx.ALIGN_CENTER_HORIZONTAL, 3)
mainsizer.Add((20,20),0)
buttonsizer = wx.BoxSizer(wx.HORIZONTAL)
buttonsizer.Add((30,30),0)
buttonsizer.Add(self.OKbutton, 0, wx.ALIGN_LEFT)
buttonsizer.Add((20,30),0)
buttonsizer.Add(self.CancelButton, 0, wx.ALIGN_RIGHT)
mainsizer.Add(buttonsizer, 0, wx.ALIGN_CENTER); mainsizer.AddSpacer((20,20),0)
self.Bind(wx.EVT_BUTTON, self.OnOK, self.OKbutton)
self.SetSizer(mainsizer); self.SetAutoLayout(True)
mainsizer.Fit(self)
Everybody thinks Sizers are a headache (and everybody's right) -- but really, the headache is just figuring out and keeping straight *what the style flags apply to* -- what's inside it, what it's inside. I think maybe that's where I'm going wrong, but now I'm too confused to know.
Thanks for any light on the subject.
Charles Hartman
Professor of English, Poet in Residence
http://cherry.conncoll.edu/cohar
http://villex.blogspot.com