Please help me to with a layout

Hi,

I’m trying to setup a layout, but I am lost. I have been trying to solve it for 3 days. Please see the layout and widget tree in the images, the panels are not displayed properly when I run the script. What is wrong with the parenting and nesting here?

Hi,

...

Hi,

I'm trying to setup a layout, but I am lost. I have been trying to solve it for 3 days. Please see the layout and widget tree in the images, the panels are not displayed properly when I run the script. What is wrong with the parenting and nesting here?

A few more hints of what you would like to see might help to be able to help you:).

What do you mean by "not displayed properly"? Not in the correct order, some widgets/panels not showing where you want them to show or not completely shown ...............................................?

It might also be useful to have a small runnable app (http://wiki.wxpython.org/MakingSampleApps) , so one can run it and see what is happening.

Werner

···

On 20/12/2013 17:31, steve wrote:

I want to achieve the layout given in the colored picture. Some widgets are not shown, some of them are not in correct order, some are not reponsive to mouse clicks, ans I see white blanks areas on the GUI window.

···

On Friday, December 20, 2013 7:17:27 PM UTC+2, werner wrote:

Hi,

On 20/12/2013 17:31, steve wrote:

Hi,

I’m trying to setup a layout, but I am lost. I have been trying to
solve it for 3 days. Please see the layout and widget tree in the
images, the panels are not displayed properly when I run the script.
What is wrong with the parenting and nesting here?

A few more hints of what you would like to see might help to be able to
help you:).

What do you mean by “not displayed properly”? Not in the correct order,
some widgets/panels not showing where you want them to show or not
completely shown …?

It might also be useful to have a small runnable app
(http://wiki.wxpython.org/MakingSampleApps) , so one can run it and see
what is happening.

Werner

If your main panel is called self.main_panel, try doing

main_panel.Layout()

If that doesn’t solve all your problems (which it probably won’t, but might take care of some), you have to post a small runnable sample, as Werner said; otherwise, without seeing your code you are asking us to be clairvoyants. But generally, these problems sometimes seem to be that you have “mis-parented” objects, so go through and check that each widget has been given the correct parent.

···

On Fri, Dec 20, 2013 at 12:23 PM, steve oslocourse@gmail.com wrote:

I want to achieve the layout given in the colored picture. Some widgets are not shown, some of them are not in correct order, some are not reponsive to mouse clicks, ans I see white blanks areas on the GUI window.

On Friday, December 20, 2013 7:17:27 PM UTC+2, werner wrote:

Hi,

On 20/12/2013 17:31, steve wrote:

Hi,

I’m trying to setup a layout, but I am lost. I have been trying to
solve it for 3 days. Please see the layout and widget tree in the
images, the panels are not displayed properly when I run the script.
What is wrong with the parenting and nesting here?

A few more hints of what you would like to see might help to be able to
help you:).

What do you mean by “not displayed properly”? Not in the correct order,
some widgets/panels not showing where you want them to show or not
completely shown …?

It might also be useful to have a small runnable app
(http://wiki.wxpython.org/MakingSampleApps) , so one can run it and see
what is happening.

Werner

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

C M wrote:

If your main panel is called self.main_panel, try doing

main_panel.Layout()

If that doesn't solve all your problems (which it probably won't, but
might take care of some), you have to post a small runnable sample, as
Werner said; otherwise, without seeing your code you are asking us to be
clairvoyants. But generally, these problems sometimes seem to be that
you have "mis-parented" objects, so go through and check that each
widget has been given the correct parent.

Also, a good technique is to start with just the inner components and get their layout working correctly independent of the rest, and then add them to the next outer component and get that working correctly, etc. If you make each of those components separate classes and responsible for their own layout, then the whole thing comes together much easier than trying to do it all at once.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org

OK, I attached a runnable example script

test4.py (4.44 KB)

···

On Saturday, December 21, 2013 1:00:31 AM UTC+2, Robin Dunn wrote:

C M wrote:

If your main panel is called self.main_panel, try doing

main_panel.Layout()

If that doesn’t solve all your problems (which it probably won’t, but

might take care of some), you have to post a small runnable sample, as

Werner said; otherwise, without seeing your code you are asking us to be

clairvoyants. But generally, these problems sometimes seem to be that

you have “mis-parented” objects, so go through and check that each

widget has been given the correct parent.

Also, a good technique is to start with just the inner components and
get their layout working correctly independent of the rest, and then add
them to the next outer component and get that working correctly, etc.
If you make each of those components separate classes and responsible
for their own layout, then the whole thing comes together much easier
than trying to do it all at once.


Robin Dunn

Software Craftsman

http://wxPython.org

Hi Steve,

OK, I attached a runnable example script

I loaded and run your script and things show, are they correct or not I have no idea as I don't know what you like to see.

One thing I noticed is that you call 'sys.exit' in your close handlers - why? One it doesn't work as you don't import sys, but more importantly why force and exit when doing nothing will do the correct and clean closing of your program. I am running on Windows 7 with Python 2.7 and the wxPython 3.0 preview, what OS are you running and why did you need sys.exit? Didn't e.g. an event.Skip() or like in my case just nothing work for you?

If you explain in more detail what doesn't work for you I will try and see if I can help you fixing it.

Werner

···

On 21/12/2013 01:55, steve wrote:

Hello Werner,

I want to see this:
1- On each notebook page, I want a grid area, and a chart area. These two should be placed one on top of the other, the gird area should be on top of chart area. I used 2 panels (1 for grid area, 1 for chart area) and a vertical box sizer for that
2- Grid area should consist of 4 sub-grids:

  • 2 of the sub-grids should be on top, they are the headers for the other (bottom) 2 sub-grid areas. I used 1 panel and 1 box sizer for each top sub-grids. Then 1 parent panel using a horizontal box sizer to place them side by side on top.
  • The bottom 2 sub grids, they contain the data values, again I used a panel 1 panel and 1 box sizer for each top sub-grids. Then 1 parent panel using horizontal box sizer to place them side by side on bottom.
    3- Now we have 2 panels each containing 2 grids. These 2 panels should be placed vertically. Thus, I used 1 parent panel and a vertical box sizer, then added those 2 panels to this parent panel, now they should be one on top of the other.
    4- The parent panel containing 4 grid areas, and the chart panel should be placed vertically, thus I used a panel child to the notebook page. Then a vertical box sizer, placing 4-gridded panel and chart panel one on top of other.

Please see the image attached to this post above

···

On Saturday, December 21, 2013 7:48:42 PM UTC+2, werner wrote:

Hi Steve,

On 21/12/2013 01:55, steve wrote:

OK, I attached a runnable example script

I loaded and run your script and things show, are they correct or not I
have no idea as I don’t know what you like to see.

One thing I noticed is that you call ‘sys.exit’ in your close handlers -
why? One it doesn’t work as you don’t import sys, but more importantly
why force and exit when doing nothing will do the correct and clean
closing of your program. I am running on Windows 7 with Python 2.7 and
the wxPython 3.0 preview, what OS are you running and why did you need
sys.exit? Didn’t e.g. an event.Skip() or like in my case just nothing
work for you?

If you explain in more detail what doesn’t work for you I will try and
see if I can help you fixing it.

Werner

steve wrote:

OK, I attached a runnable example script

It looks like another case of parenting problems to me, at least mostly. If you use the WIT (http://wiki.wxpython.org/Widget_Inspection_Tool) you can see that there are a bunch of Grids and GridObjects all on one panel. Selecting each and clicking Highlight will show that they are all stacked on top of each other in the bottom section of the notebook page. If I turn on viewing of the sizers then that gets even more confusing.

Snap006.png

···

On Saturday, December 21, 2013 1:00:31 AM UTC+2, Robin Dunn wrote:

    Also, a good technique is to start with just the inner components and
    get their layout working correctly independent of the rest, and then
    add
    them to the next outer component and get that working correctly, etc.
    If you make each of those components separate classes and responsible
    for their own layout, then the whole thing comes together much easier
    than trying to do it all at once.

--
Robin Dunn
Software Craftsman
http://wxPython.org

I think the parenting is correct. I couldn’t find out what is wrong. Each object has its own parent and sizer.

···

On Saturday, December 21, 2013 11:07:20 PM UTC+2, Robin Dunn wrote:

steve wrote:

OK, I attached a runnable example script

It looks like another case of parenting problems to me, at least mostly.
If you use the WIT (http://wiki.wxpython.org/Widget_Inspection_Tool)
you can see that there are a bunch of Grids and GridObjects all on one
panel. Selecting each and clicking Highlight will show that they are
all stacked on top of each other in the bottom section of the notebook
page. If I turn on viewing of the sizers then that gets even more
confusing.

On Saturday, December 21, 2013 1:00:31 AM UTC+2, Robin Dunn wrote:

Also, a good technique is to start with just the inner components and
get their layout working correctly independent of the rest, and then
add
them to the next outer component and get that working correctly, etc.
If you make each of those components separate classes and responsible
for their own layout, then the whole thing comes together much easier
than trying to do it all at once.


Robin Dunn

Software Craftsman

http://wxPython.org

steve wrote:

I think the parenting is correct. I couldn't find out what is wrong.
Each object has its own parent and sizer.

Take a closer look at this:

class GridObject(wx.Panel):

     def __init__(self, parent, row, cols):

         wx.Panel.__init__(self, parent)
         self.grid = gridlib.Grid(parent, -1)
         self.grid.CreateGrid(row, cols)

         sizer = wx.BoxSizer(wx.VERTICAL)
         sizer.Add(self.grid, 1, wx.EXPAND)
         self.SetSizer(sizer)

···

     > On Saturday, December 21, 2013 1:00:31 AM UTC+2, Robin Dunn wrote:
     >
     > Also, a good technique is to start with just the inner components
    and
     > get their layout working correctly independent of the rest, and then
     > add
     > them to the next outer component and get that working correctly,
    etc.
     > If you make each of those components separate classes and
    responsible
     > for their own layout, then the whole thing comes together much
    easier
     > than trying to do it all at once.

There is a good reason why I keep requoting this block of text.

--
Robin Dunn
Software Craftsman
http://wxPython.org

Thank you, that helped.
Another thing, when I add two panels to a horizontal box sizer, the panel I add first appears on the right in the layout. Shouldn’t it appear on the left, because I added it first?
such as:

     sizer = wx.BoxSizer(wx.HORIZONTAL)

     sizer.Add(left_panel, 1, wx.EXPAND)

     sizer.Add(right_panel, 1, wx.EXPAND)
     self.SetSizer(sizer)

Above, I expect left_panel to appear on left, bu it appears on the right. How is the order of panels decided here?

best regards

···

On Sunday, December 22, 2013 2:26:58 AM UTC+2, Robin Dunn wrote:

steve wrote:

I think the parenting is correct. I couldn’t find out what is wrong.

Each object has its own parent and sizer.

Take a closer look at this:

class GridObject(wx.Panel):

 def __init__(self, parent, row, cols):



     wx.Panel.__init__(self, parent)

     self.grid = gridlib.Grid(parent, -1)

     self.grid.CreateGrid(row, cols)



     sizer = wx.BoxSizer(wx.VERTICAL)

     sizer.Add(self.grid, 1, wx.EXPAND)

     self.SetSizer(sizer)
 > On Saturday, December 21, 2013 1:00:31 AM UTC+2, Robin Dunn wrote:
 >
 > Also, a good technique is to start with just the inner components
and
 > get their layout working correctly independent of the rest, and then
 > add
 > them to the next outer component and get that working correctly,
etc.
 > If you make each of those components separate classes and
responsible
 > for their own layout, then the whole thing comes together much
easier
 > than trying to do it all at once.

There is a good reason why I keep requoting this block of text.


Robin Dunn

Software Craftsman

http://wxPython.org

steve wrote:

Thank you, that helped.
Another thing, when I add two panels to a horizontal box sizer, the
panel I add first appears on the right in the layout. Shouldn't it
appear on the left, because I added it first?
such as:

sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(left_panel, 1, wx.EXPAND)
sizer.Add(right_panel, 1, wx.EXPAND)
self.SetSizer(sizer)

Above, I expect left_panel to appear on left, bu it appears on the
right. How is the order of panels decided here?

Your expectation is correct.

Is self the parent of left_panel and right_panel?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org

Yes, it is.

···

On Saturday, December 28, 2013 3:30:08 AM UTC+2, Robin Dunn wrote:

steve wrote:

Thank you, that helped.

Another thing, when I add two panels to a horizontal box sizer, the

panel I add first appears on the right in the layout. Shouldn’t it

appear on the left, because I added it first?

such as:

sizer = wx.BoxSizer(wx.HORIZONTAL)

sizer.Add(left_panel, 1, wx.EXPAND)

sizer.Add(right_panel, 1, wx.EXPAND)

self.SetSizer(sizer)

Above, I expect left_panel to appear on left, bu it appears on the

right. How is the order of panels decided here?

Your expectation is correct.

Is self the parent of left_panel and right_panel?


Robin Dunn

Software Craftsman

http://wxPython.org

I fixed some things and tried again, now left_panel appears, but right_panel is nowhere.

···

On Saturday, December 28, 2013 6:27:49 AM UTC+2, steve wrote:

Yes, it is.

On Saturday, December 28, 2013 3:30:08 AM UTC+2, Robin Dunn wrote:

steve wrote:

Thank you, that helped.

Another thing, when I add two panels to a horizontal box sizer, the

panel I add first appears on the right in the layout. Shouldn’t it

appear on the left, because I added it first?

such as:

sizer = wx.BoxSizer(wx.HORIZONTAL)

sizer.Add(left_panel, 1, wx.EXPAND)

sizer.Add(right_panel, 1, wx.EXPAND)

self.SetSizer(sizer)

Above, I expect left_panel to appear on left, bu it appears on the

right. How is the order of panels decided here?

Your expectation is correct.

Is self the parent of left_panel and right_panel?


Robin Dunn

Software Craftsman

http://wxPython.org

Here is the code I use:

···

parent_panel = wx.Panel(self)

        left_panel = grid_maker.GridArea(parent_panel) *#create a panel that contains a wx.grid object*
        binder = cxt_functions.AddGridFunctions(self, left_panel)  *#bind some context menu functions to this grid*
        binder.BindGridMenu()
        left_panel.grid.ShowScrollbars(wx.SHOW_SB_DEFAULT,wx.SHOW_SB_NEVER)
       
        right_panel = grid_maker.GridArea(parent_panel) *#create a panel that contains a wx.grid objec*t
        right_panel.grid.SetMinSize((110,50))           
       
        parent_panel_sizer = wx.BoxSizer(wx.HORIZONTAL)
        parent_panel_sizer.Add(left_panel, 1, wx.EXPAND)
        parent_panel_sizer.Add(right_panel, 1, wx.EXPAND)           
        parent_panel.SetSizer(parent_panel_sizer)     

On Saturday, December 28, 2013 6:38:39 AM UTC+2, steve wrote:

I fixed some things and tried again, now left_panel appears, but right_panel is nowhere.

On Saturday, December 28, 2013 6:27:49 AM UTC+2, steve wrote:

Yes, it is.

On Saturday, December 28, 2013 3:30:08 AM UTC+2, Robin Dunn wrote:

steve wrote:

Thank you, that helped.

Another thing, when I add two panels to a horizontal box sizer, the

panel I add first appears on the right in the layout. Shouldn’t it

appear on the left, because I added it first?

such as:

sizer = wx.BoxSizer(wx.HORIZONTAL)

sizer.Add(left_panel, 1, wx.EXPAND)

sizer.Add(right_panel, 1, wx.EXPAND)

self.SetSizer(sizer)

Above, I expect left_panel to appear on left, bu it appears on the

right. How is the order of panels decided here?

Your expectation is correct.

Is self the parent of left_panel and right_panel?


Robin Dunn

Software Craftsman

http://wxPython.org

I am not sure what you have fixed so far. Perhaps this can help…

for_steve.py (11 KB)

DevPlayer, thank you very much for taking your time, this has explained a lot of things to me.
However, when I try to add 3 panels to a horizontal sizer, the last panel does not show up:

    innersizer = wx.BoxSizer(wx.HORIZONTAL)
    innersizer.Add(self.crewHeaderPanel, 1, szflags)
    innersizer.Add(self.calendarHeaderPanel, 1, szflags)
    innersizer.Add(self.vacationHeaderPanel, 1, szflags)   ----------------> this panel does not show up in the GUI

    self.SetSizer(innersizer)
···

On Friday, January 3, 2014 6:02:28 AM UTC+2, DevPlayer wrote:

I am not sure what you have fixed so far. Perhaps this can help…

  1. Did the module I gave you work fine without modification? It worked find here.

  2. Can you put JUST your new panel into a wx.Frame() without error?

  3. Send only the exact line you are instantating the self.vacationheaderPanel and it’s init method.

  4. I usually put at least one widget as a child into a panel. Sometimes a plain empty panel needs something in it to size property (due to a syntax error somewhere I interject unintentionally. A wx.TextCtrl() with wx.TE_MULTILINE is a good test widget.

  5. make sure your VacationHeaderPanel(object) class def starts with “class” and not “def”

for_steve2.bmp (1.33 MB)

Hello,

  1. Yes it worked fine without modification, thanks
  2. Yes I can

I found out that the last panel is there, but it isn’t displayed because the other panels are consuming all the space of the parent panel.
The problem is:
“310 CALENDAR HEADER PANEL”‘s width should be equal to "310 ROSTER PANEL"s width. i.e “310 CALENDAR HEADER PANEL”’ is actually the header of “310 ROSTER PANEL”. They are both wx.grid objects. You know there is “freeze panes” feature of MS EXCEL, I’m trying to achieve the same feature in wx.grid, using separate grid objects placed in separate panels.

I fixed it the following way:

width_1 = 310_CALENDAR _HEADER_PANEL_sizer.GetWidth()
310_ROSTER_PANEL_sizer.SetWidth((width_1, 1))

Is it the proper way? How would you do it?

Best Regards

···

On Wednesday, January 8, 2014 4:23:17 AM UTC+2, DevPlayer wrote:

  1. Did the module I gave you work fine without modification? It worked find here.
  2. Can you put JUST your new panel into a wx.Frame() without error?
  1. Send only the exact line you are instantating the self.vacationheaderPanel and it’s init method.
  1. I usually put at least one widget as a child into a panel. Sometimes a plain empty panel needs something in it to size property (due to a syntax error somewhere I interject unintentionally. A wx.TextCtrl() with wx.TE_MULTILINE is a good test widget.
  1. make sure your VacationHeaderPanel(object) class def starts with “class” and not “def”