#31 Use `wx.FileHistory`


`wx` comes with a class to handle an MRU list that can be attached to a menu for things like file histories. I sublassed it to get a more Python sequence like behaviour (len(), read only index access, iterable) and moved the code to save and load the list into that class. This eliminated a little bit code repetition. Downside: Changing the number of recent files in the preferences needs a restart to become effective.


1 2 > >> (Page 1 of 2)
  • thank you for all your improvements and patches. I will take a look into them in the next days. Important things are, that they do not change the interface, because many plugins rely on this interfaces.

  • I have a script, which access also to the recent files. I will take a look, if I can adapt this. I like it very much, because it uses the drSingleChoice (with the ability to shrink the choice, while you are typing)

    import wx
    from drSingleChoiceDialog import drSingleChoiceDialog
    DrFrame.myrecentfiles = DrFrame.recentfiles[:]
    d = drSingleChoiceDialog(DrFrame, "Select from recent Files", DrFrame.myrecentfiles)
    d.SetSize((500, 200))
    answer = d.ShowModal()
    if answer == wx.ID_OK:

    (-> is a tab character)

  • You make the assumption that `DrFrame.recentfiles` is a list by using ``[:]`` to copy it. If you just assume that it is a sequence or iterable by changing that line to: ``DrFrame.myrecentfiles = list(DrFrame.recentfiles)`` it should work with my patch just fine.

    BTW: Is it really a good idea to attach new attributes to `DrFrame`? That object already has too many attributes and every new bears the risk of a name collision. Especially in this case you don't even seem to use the fact that the copy of the recent file names is persistent.

  • Yes, the DrFrame Variable is unnecessary. I also saw this, but here, one cannot change the posting afterwards again, a "local" variable is preferable of course. It isn't needed aftwards anyway. The drSingleChoice Dialog sorts the list inline, so I copied it before. Maybe a change from sort to sorted would be better, so the list is not changed, and the copy list is unnecesary then.

  • I've checked in the copy list in drSingleChoiceDialog.py this, so now:
    from drSingleChoiceDialog import drSingleChoiceDialog
    d = drSingleChoiceDialog(DrFrame, "Select from recent Files", DrFrame.recentfiles)
    (default it sorts the list) works

  • this patch was quite difficult to apply. Now my drscript is not working anymore (as I awaited; so I must look, how reanimate it again)

  • That was quite easy:
    creating the list anew:

    cnt = DrFrame.recentfiles.GetCount()

    recentfiles = list()
    for i in range(cnt):

    • status: open --> closed
  • added patches, thanks

1 2 > >> (Page 1 of 2)