Recent file list

I’m trying to implement a recent file list in my application, but I’m having some trouble. I’m not sure how recent file lists are conventionally implemented, so my method may be different.

First of all, I have a class RecentFileManager which takes care of manipulating the recent files file.

class RecentFileManager:
def init(self, filename):
self.file = file(filename, “r”)

def writeFile(self, filepath):
    """ Writes a filepath to the recent file list.

    The filepath should include the filename. """
    self.file.write(filepath)

def getRecentFiles(self):
    return self.file.readlines()

My first question is not wxPython-related, but I’m unable to find the answer anywhere. What file descriptor am I supposed to use for read-write access? I know it’s not “r”.

Anyway, using that RecentFileManager I dynamically generate a menu.

    filerecentmenu = wx.Menu()
    filemenu.AppendMenu(109, "&Recent Files", filerecentmenu)
    # Recent file loop

    for item in self.recent.getRecentFiles():
        recentitem = filerecentmenu.Append(wx.NewId(), item.rstrip(), "")
        self.Bind(wx.EVT_MENU, self.OnOpenRecent, recentitem)

The menu looks like it is generated properly, but there are a few problems. First, it binds every item in the Recent Files menu to a different action that’s completely unrelated to opening files (e.g. exiting, saving, etc.). Is this because I’m using wx.NewId(), and the application is binding to the wrong methods? I want it to bind to OnOpenRecent.

Second, I want each item in the Recent Files menu, when clicked, to open that file. I have everything set up, but I can’t figure out how to make OnOpenRecent recognize the menu item that is sending the event, and open the correct file in that manner. If I have three items in the Recent Files menu, I have no way of clicking on one of them and having the application recognize which one I clicked.

To recap:

  1. What’s the correct file descriptor for read-write access?
  2. How can I bind the dynamically generated menu items to a single method?
  3. How can I make this method recognize which menu item is sending the event?
    If there’s an easier way to go about implementing recent file lists, I would like to hear about it.

Thank you for the assistance.

-Saketh

Saketh Bhamidipati wrote:

I’m trying to implement a recent file list in my
application, but I’m having some trouble. I’m not sure how recent file
lists are conventionally implemented, so my method may be different.

First of all, I have a class RecentFileManager which takes care of
manipulating the recent files file.

> if there's an easier way to go about implementing recent > file lists, I would like to hear about it. > > > > Thank you for the assistance. > > > > -Saketh

Take a look at wx.FileHistory in the wxPython/wxWidgets docs i.e. wxPython2.6
Docs and Demos\docs\wx.chm

···

Regards,

David Hughes

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 = wx.Menu()
    filemenu.AppendMenu(109, "&Recent Files", filerecentmenu)
    self.hist.UseMenu(filerecentmenu)
    self.hist.AddFilesToMenu()

That’s the only problem I have left.

-Saketh

···

On 7/25/06, David Hughes dfh@forestfield.co.uk wrote:

I’m trying to implement a recent file list in my
application, but I’m having some trouble. I’m not sure how recent file
lists are conventionally implemented, so my method may be different.

First of all, I have a class RecentFileManager which takes care of
manipulating the recent files file.

Saketh Bhamidipati wrote:

if there’s an easier way to go about implementing recent
file lists, I would like to hear about it.

Thank you for the assistance.

-Saketh

Take a look at wx.FileHistory in the wxPython/wxWidgets docs i.e. wxPython2.6
Docs and Demos\docs\wx.chm

Regards,

David Hughes

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 = e.GetId() - wx.ID_FILE1
        path = self.hist.GetHistoryFile(fileNum)
        self.OpenFile(path)

- Josiah

···

"Saketh Bhamidipati" <saketh.bhamidipati@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 = wx.Menu()
        filemenu.AppendMenu(109, "&Recent Files", filerecentmenu)
        self.hist.UseMenu(filerecentmenu)
        self.hist.AddFilesToMenu()

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.FileHistory instance, self.hist:
filerecentmenu = 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=wx.ID_FILE1
, id2=wx.ID_FILE9)

This is the method:

def OnFileHistory(self, e):
    fileNum = e.GetId() - wx.ID_FILE1
    path = self.hist.GetHistoryFile(fileNum)
       
    self.OpenFile

(path)

The problem is that OnFileHistory never gets called (I checked this), which is a bad thing. I tried to use some guy’s example code at [

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/409012](http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/409012) to see if I implemented my wx.FileHistory correctly, and the only difference that I see is that he set the wx.FileHistory’s menu to the main filemenu, whereas I use a submenu. Am I forgetting to do something with the wx.FileHistory instance?

-Saketh

···

On 7/25/06, Saketh Bhamidipati saketh.bhamidipati@gmail.com wrote:

On 7/25/06, Josiah Carlson < > jcarlson@uci.edu> wrote:

“Saketh Bhamidipati” <saketh.bhamidipati@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 = 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 = e.GetId() - wx.ID_FILE1
    path = self.hist.GetHistoryFile(fileNum)
    self.OpenFile(path)
  • Josiah

Saketh Bhamidipati wrote:

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.FileHistory instance, self.hist:
        filerecentmenu = 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=wx.ID_FILE1 , id2=wx.ID_FILE9)

Is self the frame that the menubar is attached to?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Have you tried "id1=" rather than "id="?

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 = 1000

Instead I either pass a -1 as an ID (equivalent to wx.ID_ANY), or
explicitly generate a new id via:

    ITEM = wx.NewId()

You had mentioned static ids before, which may continue to be a problem.

- Josiah

···

"Saketh Bhamidipati" <saketh.bhamidipati@gmail.com> wrote:

On 7/25/06, Saketh Bhamidipati <saketh.bhamidipati@gmail.com> wrote:
> On 7/25/06, Josiah Carlson <jcarlson@uci.edu> wrote:
> > "Saketh Bhamidipati" <saketh.bhamidipati@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 = 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 = e.GetId() - wx.ID_FILE1
> > path = 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 = 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=wx.ID_FILE1 , id2=
wx.ID_FILE9)

“Saketh Bhamidipati” <

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 = 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 = e.GetId() - wx.ID_FILE1
    path = 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 = 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=wx.ID_FILE1
, id2=
wx.ID_FILE9)

Have you tried “id1=” rather than “id=”?

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 = 1000

Instead I either pass a -1 as an ID (equivalent to wx.ID_ANY
), or
explicitly generate a new id via:

ITEM = 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

···

On 7/26/06, Josiah Carlson jcarlson@uci.edu wrote:

“Saketh Bhamidipati” saketh.bhamidipati@gmail.com wrote:

On 7/25/06, Saketh Bhamidipati <saketh.bhamidipati@gmail.com > > wrote:

On 7/25/06, Josiah Carlson jcarlson@uci.edu wrote:
saketh.bhamidipati@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=wx.ID_FILE1, id2=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 = wx.NewId() when you care about named ids. Further,
static assignments of the form NAME = 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

···

"Saketh Bhamidipati" <saketh.bhamidipati@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=wx.ID_FILE1, id2=
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.

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 = 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

···

On 7/27/06, Josiah Carlson jcarlson@uci.edu wrote:

“Saketh Bhamidipati” saketh.bhamidipati@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=wx.ID_FILE1, id2=
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 = wx.NewId() when you care about named ids. Further,
static assignments of the form NAME = 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@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@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 = wx.Menu()
        filemenu.AppendMenu(wx.NewId(), "&Recent Files", filerecentmenu)
        self.hist.UseMenu(filerecentmenu)
        self.hist.AddFilesToMenu()
        ...
        for item in filerecentmenu.GetMenuItems():
            print item.GetId()

[snip]

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.

The trick is that you let the history object handle all menu item
creation, etc. Assuming you have a list of files in your history,
called history...

    for h in history:
        self.hist.AddFileToHistory(h)

Though be aware that the last file added to the history will be the one
on top, so you may need to reverse the list prior to iterating through
it.

- Josiah

···

"Saketh Bhamidipati" <saketh.bhamidipati@gmail.com> wrote:

I thought of that after writing this code:

    for item in filerecentmenu.GetMenuItems

():
wx.ID_FILE1 = item.GetId()
break
wx.ID_FILE9
= wx.ID_FILE1 + 8

I don’t know if it will hold, but if the code breaks then I will come begging for help again. So far, so good, though.

···

On 7/27/06, Josiah Carlson jcarlson@uci.edu wrote:

“Saketh Bhamidipati” saketh.bhamidipati@gmail.com wrote:

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 = wx.Menu()
    filemenu.AppendMenu(wx.NewId(), "&Recent Files", filerecentmenu)
    self.hist.UseMenu(filerecentmenu)
    self.hist.AddFilesToMenu()
    ...
    for item in filerecentmenu.GetMenuItems():
        print item.GetId()

[snip]

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.

The trick is that you let the history object handle all menu item

creation, etc. Assuming you have a list of files in your history,
called history…

for h in history:
    self.hist.AddFileToHistory(h)

Though be aware that the last file added to the history will be the one

on top, so you may need to reverse the list prior to iterating through
it.

  • Josiah

This make perfect sense to me, but there are situations where it is very convenient to have a continuous sequence of IDs, eg radio buttons. NewId does not guarantee this; here's the proof:

def test():
     last = wx.NewId()
     for x in range(60000):
         new = wx.NewId()
         if last != new - 1:
             print 'non-sequential at',last,new
         last = new

(It gives "non-sequential at 4998 6000".) Hitting 5K is quite feasible in a long-running program that uses NewId dynamically in constructing dialogs. One solution to this is to hunt for the sequence:

def GetIdSequence(n):
     while 1:
         start = wx.NewId()
         for x in range(n-1):
             stop = wx.NewId()
         if stop - start == n - 1:
             return start

Does anyone have any other suggestions?

Phil Mayes

···

At 10:59 PM 7/26/2006, Josiah wrote:

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 = wx.NewId() when you care about named ids. Further,
static assignments of the form NAME = 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.

The history handler already has an API for dealing with history items.
I don't understand why you aren't willing to use it, especially
considering that it leads to shorter code, and you don't need to change
built-in IDs (that may break if you don't generate those 9 ids one right
after the other, which is more code to write and maintain).

But hey, if you want to write more code, that is fragile, change
built-in ids, and ignore a previously-existing API, then that is your
business. But I'm not going to give you any more advice that you seem
to be unwilling to follow.

- Josiah

···

"Saketh Bhamidipati" <saketh.bhamidipati@gmail.com> wrote:

On 7/27/06, Josiah Carlson <jcarlson@uci.edu> wrote:
> The trick is that you let the history object handle all menu item
> creation, etc. Assuming you have a list of files in your history,
> called history...
>
> for h in history:
> self.hist.AddFileToHistory(h)
>
> Though be aware that the last file added to the history will be the one
> on top, so you may need to reverse the list prior to iterating through
> it.
>
> - Josiah
>
I thought of that after writing this code:

        for item in filerecentmenu.GetMenuItems():
            wx.ID_FILE1 = item.GetId()
            break
        wx.ID_FILE9 = wx.ID_FILE1 + 8

I don't know if it will hold, but if the code breaks then I will come
begging for help again. So far, so good, though.

That is very interesting. According to CVS:
http://cvs.wxwidgets.org/viewcvs.cgi/wxWidgets/src/common/utilscmn.cpp?rev=1.165&content-type=text/vnd.viewcvs-markup

The implementation of wxNewId is:

long wxNewId()
{
    // skip the part of IDs space that contains hard-coded values:
    if (wxCurrentId == wxID_LOWEST)
        wxCurrentId = wxID_HIGHEST + 1;

    return wxCurrentId++;
}

And should only ever return consecutively larger values until it hits
the statically assigned range. According to wxPython...

wxID_LOWEST == 4999 and wxID_HIGHEST == 5999, which corroborates your
statement. However, once past that initial break, you should get
un-interrupted ids until you wrap around in about 4 billion ids.

If I were to make a suggestion to wxWidgets, it would be to start
initially at wxID_HIGHEST + 1, remove the if statement, and call it good.
Or heck, you can pre-generate ids until you get to 6000, or even override
wx.NewId() to do such on its first call.

- Josiah

···

Phil Mayes <phil@philmayes.com> wrote:

At 10:59 PM 7/26/2006, Josiah wrote:
>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 = wx.NewId() when you care about named ids. Further,
>static assignments of the form NAME = 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.

This make perfect sense to me, but there are situations where it is very
convenient to have a continuous sequence of IDs, eg radio buttons. NewId
does not guarantee this; here's the proof:

def test():
     last = wx.NewId()
     for x in range(60000):
         new = wx.NewId()
         if last != new - 1:
             print 'non-sequential at',last,new
         last = new

(It gives "non-sequential at 4998 6000".) Hitting 5K is quite feasible in
a long-running program that uses NewId dynamically in constructing
dialogs. One solution to this is to hunt for the sequence:

def GetIdSequence(n):
     while 1:
         start = wx.NewId()
         for x in range(n-1):
             stop = wx.NewId()
         if stop - start == n - 1:
             return start

Does anyone have any other suggestions?