I'm trying to add to the "recently used" files list from Python 3 on Ubuntu.
I am able to successfully read the recently used file list like this:
from gi.repository import Gtk
recent_mgr = Gtk.RecentManager.get_default()
for item in recent_mgr.get_items():
print(item.get_uri())
This prints out the same list of files I see when I look at "Recent" in Nautilus, or look at the "Recently Used" place in the file dialog of apps like GIMP.
However, when I tried adding an item like this (where /home/laurence/foo/bar.txt
is an existing text file)...
recent_mgr.add_item('file:///home/laurence/foo/bar.txt')
...the file does not show up in the Recent section of Nautilus or in file dialogs. It doesn't even show up in the results returned by get_items()
.
How can I add a file to GTK's recently used file list from Python?
add_item()
return? – Legationadd_item()
returnsTrue
. (Actually, is seems to always returnTrue
, even if the URI I pass to it is nonexistant or complete nonsense. The only exception is if I pass it a non-str
. Then it raisesTypeError
.) – Chesterchesterfieldadd_item()
returns true would suggest it is something else. Could it be picking up the wrong history file some how? If it returns true it suggests it succeeded in writing it somewhere. – Maundadd_item()
doesn't use GError while every other method of GtkRecentManager does. I'll ask that later; maybe one of the GTK+ developers can guess what's going on... – Legationg_content_type_guess
to block the flow of the program I think, see my answer below. – Confectioneryadd_full()
is written in a way that even though it is synchronous, it cannot fail unless the input parameters are wrong. I'm not sure if this is smart, but oh well :/ – Legationg_content_type_guess
worst guess is the first mimetype in the system's mimetype list. Not a very smart guess ! – Confectioneryapplication/octet-stream
? – Legation