Re: How does one add an item to the “recently used” file list (from Python)?
- From: Laurence Gonsalves <laurence xenomachina com>
- To: infirit <infirit gmail com>
- Cc: gtk-list gnome org
- Subject: Re: How does one add an item to the “recently used” file list (from Python)?
- Date: Sat, 8 Oct 2016 14:52:23 -0700
On Fri, Oct 7, 2016 at 3:13 PM, infirit <infirit gmail com> wrote:
That is how you do it, however you _require_ a main-loop running for
this to work. Working example below.
...
from gi.repository import Gtk, GLib
def on_timeout(manager):
res = manager.add_item('file:///home/user/example.txt')
print(res)
recent_manager = Gtk.RecentManager.get_default()
GLib.timeout_add(5000, on_timeout, recent_manager)
Gtk.main()
Thanks! Is it necessary to use timeout_add? I noticed that I can call
add_item before starting the main loop, and it seems to work once the
main loop is started. I'm not sure if that's relying on undocumented
behavior, however.
I also want to quit the process right after adding the items. This
seems to work:
recent_mgr = Gtk.RecentManager.get_default()
for file in args.files:
uri = GLib.filename_to_uri(os.path.abspath(file))
recent_mgr.add_item(uri)
GLib.idle_add(Gtk.main_quit)
Gtk.main()
But again, I'm not sure if this relies on undocumented behavior. (For
example, I noticed that I need the idle_add to be after the add_item
calls, or else the add_item calls never really "execute". I guess this
makes sense if add_item is also effectively adding an idle handler,
but I don't know if this behavior is documented or if it just works
"by accident".)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]