I need to add / delete items from a wx.Sizer on the fly. Deleting
items is simple. However, I am having trouble with adding items.
The wx.Sizer class has an Insert method which takes an index as its
first parameter. I have stumbled through the docs and can not find a
way to get the index of a sizer item, which is what I need for the
Insert method.
Any ideas?
Thanks!
jw
I need to add / delete items from a wx.Sizer on the fly.
Deleting items is simple. However, I am having trouble with
adding items.
Can you use the Add method?
The wx.Sizer class has an Insert method which takes an index as
its first parameter. I have stumbled through the docs and can
not find a way to get the index of a sizer item, which is what
I need for the Insert method.
The index is an integer 0 to n-1 where n is the number of items in
the sizer. The first item you added is 0, the second is 1, and so
on. If you want to place the new item at a particular place in the
sizer, I believe you will need to keep track of (or calculate) this
index yourself.
Regards,
Donnal Walter
Arkansas Children's Hospital
···
--- Jaime Wyant <programmer.py@gmail.com> wrote:
> I need to add / delete items from a wx.Sizer on the fly.
> Deleting items is simple. However, I am having trouble with
> adding items.
Can you use the Add method?
No, the order of the items is important.
> The wx.Sizer class has an Insert method which takes an index as
> its first parameter. I have stumbled through the docs and can
> not find a way to get the index of a sizer item, which is what
> I need for the Insert method.
The index is an integer 0 to n-1 where n is the number of items in
the sizer. The first item you added is 0, the second is 1, and so
on. If you want to place the new item at a particular place in the
sizer, I believe you will need to keep track of (or calculate) this
index yourself.
That is what I had guessed. But I hoped it wasn't the case.
Thanks
jw
···
On 8/17/05, Donnal Walter <donnalcwalter@yahoo.com> wrote:
--- Jaime Wyant <programmer.py@gmail.com> wrote:
Jaime Wyant wrote:
I need to add / delete items from a wx.Sizer on the fly. Deleting
items is simple. However, I am having trouble with adding items.
The wx.Sizer class has an Insert method which takes an index as its
first parameter. I have stumbled through the docs and can not find a
way to get the index of a sizer item, which is what I need for the
Insert method.
Do you really want to delete and insert or would just Show() and
Show(, False) work?
GetItem() is a sort of "search" function to find the particular window you're trying to insert in front of.
I've lately become a fan of the GridBagSizer because of it's convenient method of referring to items by (row, col) coordinates.
Michael
Jaime Wyant wrote:
> I need to add / delete items from a wx.Sizer on the fly. Deleting
> items is simple. However, I am having trouble with adding items.
>
> The wx.Sizer class has an Insert method which takes an index as its
> first parameter. I have stumbled through the docs and can not find a
> way to get the index of a sizer item, which is what I need for the
> Insert method.
Do you really want to delete and insert or would just Show() and
Show(, False) work?
Yes I need to delete/insert. I have a simple gui where I'm trying to
represent a 1 to N relationship.
GetItem() is a sort of "search" function to find the particular window
you're trying to insert in front of.
I've lately become a fan of the GridBagSizer because of it's convenient
method of referring to items by (row, col) coordinates.
This sounds like a decent idea. It seems like the sizer should be
able to tell me the index position of an item. Oh well.
jw
···
On 8/17/05, Michael Hipp <Michael@hipp.com> wrote:
Michael
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
There is no native way of determining this. In Dabo, though, we frequently
need to get this value, too, so we added this method to our base mixin for
controls. Feel free to use it in your code.
def getPositionInSizer(self):
""" Returns the current position of this control in its containing
sizer. This is useful for when a control needs to be re-created in
place.
If the containing sizer is a box sizer, the integer position will
be returned. If it is a grid sizer, a row,col tuple will be returned.
If the object is not contained in a sizer, None will be returned.
"""
sz = self.GetContainingSizer()
if not sz:
return None
if isinstance(sz, wx.BoxSizer):
chil = sz.GetChildren()
for pos in range(len(chil)):
# Yeah, normally we'd just iterate over the children, but
# we want the position, so...
szitem = chil[pos]
if szitem.IsWindow():
if szitem.GetWindow() == self:
return pos
# If we reached here, something's wrong!
dabo.errorLog.write(_("Containing sizer did not match item %s")
% self.Name)
return None
elif isinstance(sz, wx.GridBagSizer):
# Return a row,col tuple
row, col = sz.GetItemPosition(self)
return (row, col)
else:
return None
···
On Wednesday 17 August 2005 10:15, Jaime Wyant wrote:
The wx.Sizer class has an Insert method which takes an index as its
first parameter. I have stumbled through the docs and can not find a
way to get the index of a sizer item, which is what I need for the
Insert method.
--
-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com
Thanks, that is nice. Is the sizer method GetChildren() documented
anywhere? I'd have come up with something similar had I known that
method existed.
jw
···
On 8/17/05, Ed Leafe <ed@leafe.com> wrote:
On Wednesday 17 August 2005 10:15, Jaime Wyant wrote:
> The wx.Sizer class has an Insert method which takes an index as its
> first parameter. I have stumbled through the docs and can not find a
> way to get the index of a sizer item, which is what I need for the
> Insert method.
There is no native way of determining this. In Dabo, though, we frequently
need to get this value, too, so we added this method to our base mixin for
controls. Feel free to use it in your code.
def getPositionInSizer(self):
""" Returns the current position of this control in its containing
sizer. This is useful for when a control needs to be re-created in
place.
If the containing sizer is a box sizer, the integer position will
be returned. If it is a grid sizer, a row,col tuple will be returned.
If the object is not contained in a sizer, None will be returned.
"""
sz = self.GetContainingSizer()
if not sz:
return None
if isinstance(sz, wx.BoxSizer):
chil = sz.GetChildren()
for pos in range(len(chil)):
# Yeah, normally we'd just iterate over the children, but
# we want the position, so...
szitem = chil[pos]
if szitem.IsWindow():
if szitem.GetWindow() == self:
return pos
# If we reached here, something's wrong!
dabo.errorLog.write(_("Containing sizer did not match item %s")
% self.Name)
return None
elif isinstance(sz, wx.GridBagSizer):
# Return a row,col tuple
row, col = sz.GetItemPosition(self)
return (row, col)
else:
return None
--
-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
You're right; I can't see it in the documentation (at least the stuff on the
wxWidgets site). But this has been there for at least a year and a half.
···
On Wednesday 17 August 2005 11:38, Jaime Wyant wrote:
Thanks, that is nice. Is the sizer method GetChildren() documented
anywhere? I'd have come up with something similar had I known that
method existed.
--
-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com
Ed Leafe wrote:
chil = sz.GetChildren()
for pos in range(len(chil)):
# Yeah, normally we'd just iterate over the children, but
# we want the position, so...
szitem = chil[pos]
A cosmetic improvement(?) to this is -
chil = sz.GetChildren()
for pos,szitem in enumerate(chil):
This was added to Python in 2.3, so if you need to support earlier versions,
stick to the old method.
Frank Millman
Frank Millman wrote:
Ed Leafe wrote:
chil = sz.GetChildren()
for pos in range(len(chil)):
# Yeah, normally we'd just iterate over the children, but
# we want the position, so...
szitem = chil[pos]
A cosmetic improvement(?) to this is -
chil = sz.GetChildren()
for pos,szitem in enumerate(chil):
Where is sizer.GetChildren() documented?
Thanks,
Michael
Michael Hipp wrote:
>
> A cosmetic improvement(?) to this is -
>
> chil = sz.GetChildren()
> for pos,szitem in enumerate(chil):
Where is sizer.GetChildren() documented?
Thanks,
Michael
This is copied from Werner's message of 18th August -
···
---------------------------------------------
Hi Ed,
Ed Leafe wrote:
On Wednesday 17 August 2005 11:38, Jaime Wyant wrote:
Thanks, that is nice. Is the sizer method GetChildren() documented
anywhere? I'd have come up with something similar had I known that
method existed.
You're right; I can't see it in the documentation (at least the stuff
on the wxWidgets site). But this has been there for at least a year and a
half.
It is there in the new API doc.
See you
Werner
---------------------------------------------
Frank
Frank Millman wrote:
This is copied from Werner's message of 18th August -
You're right; I can't see it in the documentation (at least the stuff on the wxWidgets site). But this has been there for at least a year and a
half.
It is there in the new API doc.
Thanks. I saw Werner's message too late to take back my email.
Question: I know the new API docs are on the wxPython.org site, but I don't see them anywhere in the "Docs Demos and Tools" package I installed. T'would be handy to have them locally on my hard drive, is there a simple way to download them or are they already there?
Thanks,
Michael
Hi Michael,
Michael Hipp wrote:
Frank Millman wrote:
This is copied from Werner's message of 18th August -
You're right; I can't see it in the documentation (at least the stuff on the wxWidgets site). But this has been there for at least a year and a
half.
It is there in the new API doc.
Thanks. I saw Werner's message too late to take back my email.
Question: I know the new API docs are on the wxPython.org site, but I don't see them anywhere in the "Docs Demos and Tools" package I installed. T'would be handy to have them locally on my hard drive, is there a simple way to download them or are they already there?
http://prdownloads.sourceforge.net/wxpython/wxPython-newdocs-2.6.1.0.tar.gz
Which you can get to from the Documentation section on this page:
http://www.wxpython.org/download.php#binaries
Thanks,
Michael
See you
Werner
···
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org