Web lists-archives.com

Re: How does one add an item to the “recently used” file list (from Python)?




On Sat, Oct 8, 2016 at 3:33 PM, infirit <infirit@xxxxxxxxx> wrote:
> Op 10/08/2016 om 11:52 PM schreef Laurence Gonsalves:
>> 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.
>
> There is no undocumented behaviour, many parts of Gtk and GLib require a
> mainloop to function properly, GtkRecentManager is one of them and
> sending/receiving signals is another.

Sorry if I wasn't clear. I wasn't talking about starting the mainloop.
I was talking about calling add_item *before* starting the mainloop
rather than scheduling the add_item calls from an event handler. Doing
this seems to work, but I'm not sure if it's guaranteed to work or if
it's relying on undocumented behavior.

> You could do that but it relies, imo, on implicit behaviour that if no
> higher tasks are running it should quit. My approach would be that you
> explicitly call Gtk.main_quit when you are done processing the files.
....
> def on_timeout(manager, files):
>     for path in files:
>         f = Gio.File.new_for_path(path)
>         exists = f.query_exists()
>         if exists:
>             res = manager.add_item(f.get_uri())
>             print(res)
>     Gtk.main_quit()

I tried this and it didn't work. It looks like main_quit terminates
the main loop immediately, before the add_item requests even have a
chance to do their job.

> My timeout was five seconds, but it could be one milliseconds so it has
> no noticeable delay when you run it.

Is there any advantage to using a timeout over idle_add? If a timeout
must be used, why not use a zero timeout?

> [1] https://lazka.github.io/pgi-docs/#Gio-2.0/interfaces/File.html

Thanks for that. I'll update my code to use it.
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
https://mail.gnome.org/mailman/listinfo/gtk-list