[wxPython-users] Recent file list

Saketh Bhamidipati saketh.bhamidipati at gmail.com
Wed Jul 26 15:54:59 PDT 2006


On 7/26/06, Josiah Carlson <jcarlson at uci.edu> wrote:
>
>
> "Saketh Bhamidipati" <saketh.bhamidipati at gmail.com> wrote:
> > On 7/25/06, Saketh Bhamidipati <saketh.bhamidipati at gmail.com> wrote:
> > > On 7/25/06, Josiah Carlson <jcarlson at uci.edu> wrote:
> > > > "Saketh Bhamidipati" <saketh.bhamidipati at GMAIL.COM> wrote:
> > > > > Thanks very much! This is exactly what I needed.
> > > > >
> > > > > I'm still having problems with one thing, though - how can I make
> > > > > wx.FileHistory open the file when I click on the item in the
> Recent
> > > > Files
> > > > > menu? I have set the menu for wx.FileHistory to use to a certain
> menu.
> > > > The
> > > > > method I use to open files is called OpenFile(). How can I make
> each
> > > > item in
> > > > > the Recent Files menu bind to OpenFile itself? I've already
> inserted
> > > > the
> > > > > AddFileToHistory() calls in the right places, as well as saving
> and
> > > > loading
> > > > > the config file.
> > > > >
> > > > > Here's the important part of my code:
> > > > >
> > > > >         filerecentmenu =3D wx.Menu()
> > > > >         filemenu.AppendMenu(109, "&Recent Files", filerecentmenu)
> > > > >         self.hist.UseMenu(filerecentmenu)
> > > > >         self.hist.AddFilesToMenu ()
> > > >
> > > > You need to bind the menu event range, I think this should work...
> > > >
> > > >     wx.EVT_MENU_RANGE(self, wx.ID_FILE1, wx.ID_FILE9,
> self.OnFileHistory
> > > > )
> > > >
> > > > Then you have your event handler...
> > > >
> > > >     def OnFileHistory(self, e):
> > > >         fileNum =3D e.GetId() - wx.ID_FILE1
> > > >         path =3D self.hist.GetHistoryFile(fileNum)
> > > >         self.OpenFile(path)
> > > >
> > > > - Josiah
> > > >
> > I'm trying this, but it's not working. Although it's syntactically
> > correct, the application is not opening the files in the recent files
> menu.
> > I figured out why it was calling random methods before - I picked an
> already
> > used ID number. But now it does nothing. OnFileHistory never gets
> called.
> >
> > This is how I created the menu and associated it with the
> > wx.FileHistoryinstance,
> > self.hist:
> >         filerecentmenu =3D wx.Menu()
> >         filemenu.AppendMenu(199, "&Recent Files", filerecentmenu)
> >
> >         self.hist.UseMenu(filerecentmenu)
> >         self.hist.AddFilesToMenu()
> >
> > This is how I bound the method:
> > self.Bind(wx.EVT_MENU_RANGE, self.OnFileHistory, id=3Dwx.ID_FILE1 , id2=
=3D
> > wx.ID_FILE9)
>
> Have you tried "id1=3D" rather than "id=3D"?
>
> Other than that, I don't know.  I use this exact method in PyPE and it
> works fine (the particular section of code uses the old wxPython.wx
> imports, so may or may not work exactly the same). Note that I never
> create static ID assignments like the following:
>
>     ITEM =3D 1000
>
> Instead I either pass a -1 as an ID (equivalent to wx.ID_ANY), or
> explicitly generate a new id via:
>
>     ITEM =3D wx.NewId()
>
>
> You had mentioned static ids before, which may continue to be a problem.
>
> - Josiah
>
> Should I replace all explicit ID's with wx.NewId()?

Is self the frame that the menubar is attached to?


 Yes, it is. I think it is an ID problem, because I can't find anything else
wrong with my code. I will try replacing the explicit ID's with wx.NewId().

-Saketh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/200607=
26/84e2d6c6/attachment.htm


More information about the wxpython-users mailing list