Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
174 views
in Technique[技术] by (71.8m points)

wxwidgets - how to stop growing width of window when child sizers width increased in wx.Dialog in wxpython

I am very new to wxpython and wxwidgets.I have the code for wx.Dialog like below.

def __init__(self, parent, Name, Platform):
    wx.Dialog.__init__(self, parent, -1, 'Launch Dialog', size=(-1,-1), pos=(-1,-1))
     ###some code 
    self.createSizers()
    self.Fit() 

def createSizers()
    self.mainSizer = wx.BoxSizer(wx.VERTICAL)
    SelectionSizer = wx.StaticBoxSizer(self.staticBoxTestSelection, wx.VERTICAL)
    self.horzDetailsSizer = wx.BoxSizer(wx.HORIZONTAL) 
    self.DetailsSizer = wx.BoxSizer(wx.VERTICAL)
    ### add func here

    self.ListingSizer = wx.BoxSizer(wx.VERTICAL)
    ### add func here

     # Horizontal Splitter
    self.horzDetailsSizer.Add(self.ListingSizer, 3, wx.EXPAND)
    self.horzDetailsSizer.AddSpacer(5)
    self.horzDetailsSizer.Add(self.DetailsSizer, 2, wx.EXPAND)

    # Add subsizers to main
    SelectionSizer.Add(self.horzDetailsSizer, 1, wx.EXPAND | wx.ALL, 5)

    self.mainSizer.Add(SelectionSizer, 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 5)

     ### Initialize mainSize
    self.SetSizer(self.mainSizer)

Here the problem is when the statictextctrl sizers or listctrl sizers of self.DetailsSizer increase width of whole window size and also subsizers width is increasing on right side of window.

I wish to fix the dialog box size and the subsizers should adjust within the window size.That is if one subsizer width is increased, adjacent subsizer should adjust with the space..

Is there any way to do that? Please help me to get rid of this issue.

EDIT:

This is not about user resizing the dialog window..it is about the width of dialog box dynamically growing horizontally.

For ex. in my dialog box I have 2 box sizers named as listing and details adjacent to each other in the window of default size(-1,-1).

In details box I am displaying 'name' dynamically which is related to selected option from listing sizer..So the length of 'name' will change every time..If the length is more and the string is a single word the width of details sizer is increased horizontally so that listing sizer increased.So main sizer of window increased like below.

I do not want this growing and again coming to normal window.The window size should always fix and in case of 'name' length increased in details sizer ,the listing sizer should shrink and adjust with the detail sizer.

Normal Dialog box:

enter image description here

Dynamically width increased:

enter image description here

Desired output to be:

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Maybe you need to add a sizer without proportion. Look at this code

# Horizontal Splitter
self.horzDetailsSizer.Add(self.ListingSizer, 3, wx.EXPAND) # This Line need to be changed
self.horzDetailsSizer.AddSpacer(5)
self.horzDetailsSizer.Add(self.DetailsSizer, 2, wx.EXPAND)

When you put the proportion 0, the children will not grow on x axis, only in y axis (Because the wx.EXPAND is used). Try to change like code bellow

self.horzDetailsSizer.Add(self.ListingSizer, 0, wx.EXPAND)

This blog (http://www.blog.pythonlibrary.org/2013/11/06/wxpython-101-using-frame-styles) have an explanation to wx Flags. To make a Dialog without resize try to put:

class TestDialog(wx.Dialog):
    def __init__(self,parent)
        dialogStyle = wx.DEFAULT_DIALOG_STYLE& ~ (wx.RESIZE_BORDER | wx.RESIZE_BOX | wx.MAXIMIZE_BOX)
        wx.Dialog.__init__(self, parent, -1, style=dialogStyle)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...