views:

32

answers:

1

Is there a way to allow a custom wx.Dialog to be resized in the horizontal direction only? I've tried using GetSize() and then setting the min and max height of the window using SetSizeHints(), but for some reason it always allows the window to be resized just a little, and it looks rather tacky. The only other alternative I have come up with is to hard-code the min and max height, but I don't think that would be such a good idea...

Relevant code:

class SomeDialog(wx.Dialog):

    def __init__(self, parent):                               
        wx.Dialog.__init__(self, parent, title="blah blah",
                           style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
        size = self.GetSize()
        self.SetSizeHints(minW=size.GetWidth(), minH=size.GetHeight(),
                          maxH=size.GetHeight())

os: Windows 7
python version: 2.5.4
wxPython version: 2.8.10

+1  A: 

If you don't want the height to change, why would it be a bad idea to set min and max height to the same value (the one you want to force)? You can of course get the system estimate of the "best value" with GetBetSize or related methods. Though I find the fact that setting the size hints doesn't have the same effect (as I think it should) peculiar... what platform are you using wxpython on, and what version of Python, wxpython, and the platform/OS itself...?

Alex Martelli
I'm not keen on hardcoding the values because I'm not sure that it will be the same on different computers, and it's a PITA to figure out the exact value of the height it is automatically rendered at every time I change something on the dialog. I've added the version details to the question :)
falcon
I've done the GetBestSize route I think. Something similar anyway; I let the layout stuff do its thing then get the current geometry and set min and max to the same value. It works well enough. Beware of the difference between client size and frame size; I don't remember the details there either but that may be tripping you up. Alternatively, can your top-level sizer just be horizontal and not flagged as EXPAND?
dash-tom-bang
@hawk, but you have to get the "best height" (which will take care of all system dependencies) anyway, even if just to set the size hints -- I'm definitely not talking about _hardcoding_ anything, just trying to set the min and max height to "best" (as you're trying to do above but via the size hints). Of course you have to call this simple "set fixed height" function again any time you change the dialog -- but so you would if the size hint setting worked!
Alex Martelli
@Alex Sorry, misunderstanding :) Okay, I tried GetBestSize() and it did the same thing as GetSize(), however GetClientSize(), as per dash-tom-bang's suggestion, worked somewhat better, but it can still be resized a little bit.
falcon
Ah! I got it! I was placing the code above before the call toself.SetSizerAndFit(...). GetBestSize() works now, thanks :)
falcon
@hawk, oh good, I was starting to worry that I'd have to start rooting again for my kaspersky disk so as to be able to put my new cheap win7 laptop on the net -- glad that I can keep delaying (there are more urgent post-move tasks;-) and especially that your problem has gone!
Alex Martelli