#31 Use `wx.FileHistory`

closed
nobody
None
5
2010-08-28
2010-08-26
No

`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.

Discussion

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)

    #drscript
    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()
    d.Destroy()
    if answer == wx.ID_OK:
    ->DrFrame.OpenOrSwitchToFile(d.GetStringSelection())

    (-> 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):
    recentfiles.append(DrFrame.recentfiles.GetHistoryFile(i))

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

     
1 2 > >> (Page 1 of 2)