I've created a right-click menu for a ListBox. The right-click menu
allows the user to Save/Restore the
items in the ListBox to/from disk. The popup menu works fine and the
event handler is called.
When I look at the event object, there are two methods which imply
they will return the selected item:
event.GetSelection() and event.GetString() return 0 and ""
respectively, not the selected item.
event.GetEventObject() does not have any methods which look like they
should return the selected item.
So I've started looking through the wx API under Menu and Event
related topics, but I'm obviously in the wrong place.
I could probably store the selected item in a class variable during
the EVT_LISTBOX event, then just reference the class variable in the
EVT_CONTEXT_MENU event handler, but I would like to better-understand
the event structure of the popup menu event.
The event should be a menu event, not a listbox event, so you'd need
to use the ListBox's GetCurrentSelection() method, or some variation
thereof, to find the data you want.
Josh
···
On Sun, Jan 3, 2010 at 3:52 PM, cappy2112 <cappy2112@gmail.com> wrote:
I've created a right-click menu for a ListBox. The right-click menu
allows the user to Save/Restore the
items in the ListBox to/from disk. The popup menu works fine and the
event handler is called.
When I look at the event object, there are two methods which imply
they will return the selected item:
event.GetSelection() and event.GetString() return 0 and ""
respectively, not the selected item.
event.GetEventObject() does not have any methods which look like they
should return the selected item.
So I've started looking through the wx API under Menu and Event
related topics, but I'm obviously in the wrong place.
I could probably store the selected item in a class variable during
the EVT_LISTBOX event, then just reference the class variable in the
EVT_CONTEXT_MENU event handler, but I would like to better-understand
the event structure of the popup menu event.
When I use the ListBox GetCurrentSelection(), GetLabel() and
GetLabelText() none of them return the selected item, while
in the context of the menu event. I have the style for the ListBox set
to LB_SINGLE, FWIW.
···
On Jan 3, 4:39 pm, Josh English <joshua.r.engl...@gmail.com> wrote:
The event should be a menu event, not a listbox event, so you'd need
to use the ListBox's GetCurrentSelection() method, or some variation
thereof, to find the data you want.
On Jan 3, 4:39 pm, Josh English<joshua.r.engl...@gmail.com> wrote:
The event should be a menu event, not a listbox event, so you'd need
to use the ListBox's GetCurrentSelection() method, or some variation
thereof, to find the data you want.
Thanks Josh...
When I use the ListBox GetCurrentSelection(), GetLabel() and
GetLabelText() none of them return the selected item, while
in the context of the menu event. I have the style for the ListBox set
to LB_SINGLE, FWIW.
I've been thinking about this and thought I'd give it a try. It is
possible to bind wx.EVT_CONTEXT_MENU to a list box. I can't get it to
help.
I can get the position of the event in the ListBox, but the
ListBox.HitTest() method isn't available in MSW (according to my
docs), so the position is useless on my system.
Short of binding the regular EVT_LISTBOX to create the context menu, I
can't find a way to make the context menu work.
Windows XP (64-bit), Python 2.5.4, wxPython 2.8.10.1 with AGW from SVN.
I was hoping that someone might have an example of code that creates widgets dynamically. I've attached a JPEG that shows the widget I'm trying to recreate. It's busy, but really all I need help with is the group in the center.
The dynamic widget is the scroll window in the center. In our program we open a text file where each line of text is used to create a line in the scrolled window. This line contains a check box, and two spin controls. If we open a different text file, then the current set of compound widgets is destroyed and a new set is used to populate the scrolled window.
Well, maybe don't think of the scrolled window as the "unit" so much; it is
just display space. The "unit" is each "line" in this. So what you might
do is make a class that is a panel, and each panel = one line. That panel
can be its own class, and in the class you would have everything you need.
The class will take as its arguments the data necessary to fill in the fields
(the metabolite names and any default starting values).
One you have this template for a "line", you can do something like:
(where self = your scrolledpanel display area, and assume somewhere
int his .py file or imported you have a PanelLine class that creates the
line you want and knows what to do with initial values data)
for line_of_text in myTextFile:
line = PanelLine(self, -1. initial_values_needed)
self.myBoxSizer.AddWindow(line, 0, border=0, flag=0)
self.Layout()
This might also be done with a wxGrid, wxList, ObjectListView, or
UltimateListCtrl or some other such widget.
Che
···
On Wed, Jan 6, 2010 at 11:27 AM, Brian J. Soher <bsoher@briansoher.com> wrote:
Hi,
Windows XP (64-bit), Python 2.5.4, wxPython 2.8.10.1 with AGW from SVN.
I was hoping that someone might have an example of code that creates widgets
dynamically. I've attached a JPEG that shows the widget I'm trying to
recreate. It's busy, but really all I need help with is the group in the
center.
The dynamic widget is the scroll window in the center. In our program we
open a text file where each line of text is used to create a line in the
scrolled window. This line contains a check box, and two spin controls. If
we open a different text file, then the current set of compound widgets is
destroyed and a new set is used to populate the scrolled window.
Try it. I see that there is an implementation for it so it may be that the docs are wrong and it will work fine.
···
On 1/5/10 8:46 PM, Josh English wrote:
I've been thinking about this and thought I'd give it a try. It is
possible to bind wx.EVT_CONTEXT_MENU to a list box. I can't get it to
help.
I can get the position of the event in the ListBox, but the
ListBox.HitTest() method isn't available in MSW (according to my
docs), so the position is useless on my system.
I was hoping that someone might have an example of code that creates widgets dynamically. I've attached a JPEG that shows the widget I'm trying to recreate. It's busy, but really all I need help with is the group in the center.
there really isn't that much to it -- Python being a dynamic language, it's pretty much the same, static or dynamic.
I'd create a compound widget class:
class ChemWidget(wx.Panel):
def __init__(self, parent, chem_name)
...
create your checkbox, labels, etc here (laid out with sizers)
Now when you read the file, in a custom ScrolledPanel:
sizer = wx.BoxSizer(wx.VERTICAL)
chem_widgets =
# you could also use a dict here, if you want to be able to find
# particular ones more easily.
for chem in chem_list:
cm = ChemWidget(self, chem)
chem_widgets.append(cm)
sizer.Add(cm, 0, wx.CENTER_HORIZONTAL)
I hope that gives you the idea.
-Chris
···
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception