[wxPython-users] Recent file list
Saketh Bhamidipati
saketh.bhamidipati at gmail.com
Thu Jul 27 15:44:39 PDT 2006
On 7/27/06, Josiah Carlson <jcarlson at uci.edu> wrote:
>
>
> "Saketh Bhamidipati" <saketh.bhamidipati at gmail.com> wrote:
> > I checked manually if file loading from the recent file list works. It
> > works. I checked the ID's of everything, and there are no longer any
> > conflicts.
> >
> > This means that the afflicted code is my self.Bind statement for the
> menu
> > range.
> >
> > self.Bind(wx.EVT_MENU_RANGE, self.OnFileHistory, id=3Dwx.ID_FILE1, id2=
=3D
> > wx.ID_FILE9)
> >
> > I am unable to test if this statement executed successfully on
> application
> > start. Are there any examples of wx.FileHistory that I can look at? I am
> > stumped by this problem.
>
> You can download the PyPE source, available at
> http://sf.net/projects/pype . The relevant sections are
> MainWindow.__init__, where states "Adds opened file history to the File
> menu", though not everything in that section is necessarily about the
> menu history, and MainWindow.OnFileHistory. This functionality has
> worked in PyPE unchanged for more than 2 years.
>
> In regards to static IDs, though many demos in the past have used static
> IDs, it is a poor choice, as one never knows when one needs to insert a
> new ID. It is much easier to use -1 or wx.ID_ANY if you don't care
> about IDs, and NAME =3D wx.NewId() when you care about named ids. Further,
> static assignments of the form NAME =3D 1929 when using wxPython are
> foolish, as wxPython has its own set of internal ids, that may collide
> with arbitrarily chosen ID numbers, which can cause any one of a number
> of problems. Mixing wx.NewId() and static assignments are also foolish,
> because you can introduce your own ID collisions.
>
>
> - Josiah
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help at lists.wxwidgets.org
>
> I've figured out the problem, but I can't find a solution.
I used the following code to get the ID's of the menu items:
...
filerecentmenu =3D wx.Menu()
filemenu.AppendMenu(wx.NewId(), "&Recent Files", filerecentmenu)
self.hist.UseMenu(filerecentmenu)
self.hist.AddFilesToMenu()
...
for item in filerecentmenu.GetMenuItems():
print item.GetId()
For some reason, wx.ID_FILE1 is not the ID of the first item in the recent
files menu. There are two items in the recent files menu, and their ID's are
102 and 103. wx.ID_FILE1 and wx.ID_FILE2, on the other hand, are 5050 and
5051, respectively. This would explain why the EVT_MENU_RANGE is not binding
to the correct items.
The good news is that if I explicitly use 102 and 103 as id and id2 for the
EVT_MENU_RANGE, everything works as expected - the recent files open . But I
just did it for testing purposes.
Is there any way I can get the recent file MenuItems to have wx.ID_FILE1 and
wx.ID_FILE2 as their IDs. without explicitly defining the IDs? Now that I
have identified the exact nature of the problem, finding a solution should
be easier.
-Saketh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/200607=
27/0a6f8cf9/attachment.htm
More information about the wxpython-users
mailing list