Re: Gio.DBusObjectManagerClient not updating

2018-03-06 Thread Hayden Lau
Sorry all, this is a repeat email that got caught up in the spam filtering 
system. I already had some responses earlier (after I joined the mailing list).

Thanks,
Hayden

On 2018-03-06, 1:36 PM, "python-hackers-list on behalf of Hayden Lau" 
 
wrote:

[This sender failed our fraud detection checks and may not be who they 
appear to be. Learn about spoofing at http://aka.ms/LearnAboutSpoofing]

Hello,

I understand this is a dev mailing list, but I’m not sure where to post 
this question otherwise.

I’m attempting to write an application that interacts with UDisks2 over 
DBus with PyGObject. However, I’m finding that after instantiating the proper 
Gio.DBusObjectManagerClient, I seem to be unable to get updates on the 
ObjectManager’s state. Am I missing something? The only example code that I 
could find that had similar functionality was in udiskie 
(https://github.com/coldfix/udiskie), but that application uses Gio.DBusProxy 
directly. Is that the recommended approach? My (non-working) proof of concept 
code pasted below. It prints the initial set of objects reported by the 
‘org.freedesktop.UDisks2’ object manager, but does not print changes (either 
via signal or polling) when disks are added or removed.

Thank you,
Hayden Lau


from time import sleep
import gi
gi.require_version('Gio', '2.0')
from gi.repository import Gio

udisks2 = Gio.DBusObjectManagerClient.new_for_bus_sync(
Gio.BusType.SYSTEM,
Gio.DBusObjectManagerClientFlags.NONE,
'org.freedesktop.UDisks2',
'/org/freedesktop/UDisks2',
None,
None,
None
)

def new_obj_handler(obj):
print('New Object: ', obj)

def new_iface_handler(obj):
print('New Interface: ', obj)

def get_paths(objmgr):
return [obj.get_object_path() for obj in objmgr.get_objects()]

udisks2.connect('interface-added', new_iface_handler)
udisks2.connect('object-added', new_obj_handler)

paths = []
while(True):
if paths != get_paths(udisks2):
paths = get_paths(udisks2)
print(paths)
sleep(1)



___
python-hackers-list mailing list
python-hackers-list@gnome.org
https://mail.gnome.org/mailman/listinfo/python-hackers-list


___
python-hackers-list mailing list
python-hackers-list@gnome.org
https://mail.gnome.org/mailman/listinfo/python-hackers-list


Gio.DBusObjectManagerClient not updating

2018-03-06 Thread Hayden Lau
Hello,

I understand this is a dev mailing list, but I’m not sure where to post this 
question otherwise.

I’m attempting to write an application that interacts with UDisks2 over DBus 
with PyGObject. However, I’m finding that after instantiating the proper 
Gio.DBusObjectManagerClient, I seem to be unable to get updates on the 
ObjectManager’s state. Am I missing something? The only example code that I 
could find that had similar functionality was in udiskie 
(https://github.com/coldfix/udiskie), but that application uses Gio.DBusProxy 
directly. Is that the recommended approach? My (non-working) proof of concept 
code pasted below. It prints the initial set of objects reported by the 
‘org.freedesktop.UDisks2’ object manager, but does not print changes (either 
via signal or polling) when disks are added or removed.

Thank you,
Hayden Lau


from time import sleep
import gi
gi.require_version('Gio', '2.0')
from gi.repository import Gio

udisks2 = Gio.DBusObjectManagerClient.new_for_bus_sync(
Gio.BusType.SYSTEM, 
Gio.DBusObjectManagerClientFlags.NONE,
'org.freedesktop.UDisks2',
'/org/freedesktop/UDisks2',
None,
None,
None
)

def new_obj_handler(obj):
print('New Object: ', obj)

def new_iface_handler(obj):
print('New Interface: ', obj)

def get_paths(objmgr):
return [obj.get_object_path() for obj in objmgr.get_objects()]

udisks2.connect('interface-added', new_iface_handler)
udisks2.connect('object-added', new_obj_handler)

paths = []
while(True):
if paths != get_paths(udisks2):
paths = get_paths(udisks2)
print(paths)
sleep(1)



___
python-hackers-list mailing list
python-hackers-list@gnome.org
https://mail.gnome.org/mailman/listinfo/python-hackers-list


Re: Gio.DBusObjectManagerClient not updating

2018-01-13 Thread Christian Stadelmann
Hi Hayden Lau,

do you have a GLib mainloop running? If no, maybe creating and starting
one may help.

See also: https://bugzilla.gnome.org/show_bug.cgi?id=759644

-- 
Regards
Chris


Am Samstag, den 13.01.2018, 16:19 + schrieb Hayden Lau:
> Hello,
> 
> I understand this is a dev mailing list, but I’m not sure where to
> post this question otherwise.
> 
> I’m attempting to write an application that interacts with UDisks2
> over  DBus with PyGObject. However, I’m finding that after
> instantiating the  proper Gio.DBusObjectManagerClient, I seem to be
> unable to get updates  on the ObjectManager’s state. Am I missing
> something? The only example  code that I could find that had similar
> functionality was in udiskie (https://github.com/coldfix/udiskie),  b
> ut that application uses Gio.DBusProxy directly. Is that
> the  recommended approach? My (non-working) proof of concept code
> pasted  below. It prints the initial set of objects reported by
> the  ‘org.freedesktop.UDisks2’ object manager, but does not print
> changes  (either via signal or polling) when disks are added or
> removed.
> 
> I am using the version of PyGObject that comes packaged with Ubuntu
> 16.04 LTS, 3.20.0, along with the versions of DBus and Glib, etc that
> also come with the OS. (https://packages.ubuntu.com/xenial/python3-gi
> )
> 
> Thank you,
> Hayden Lau
> 
> 
> from time import sleep
> import gi
> gi.require_version('Gio', '2.0')
> from gi.repository import Gio
> 
> udisks2 = Gio.DBusObjectManagerClient.new_for_bus_sync(
> Gio.BusType.SYSTEM, 
> Gio.DBusObjectManagerClientFlags.NONE,
> 'org.freedesktop.UDisks2',
> '/org/freedesktop/UDisks2',
> None,
> None,
> None
> )
> 
> def new_obj_handler(obj):
> print('New Object: ', obj)
> 
> def new_iface_handler(obj):
> print('New Interface: ', obj)
> 
> def get_paths(objmgr):
> return [obj.get_object_path() for obj in objmgr.get_objects()]
> 
> udisks2.connect('interface-added', new_iface_handler)
> udisks2.connect('object-added', new_obj_handler)
> 
> paths = []
> while(True):
> if paths != get_paths(udisks2):
> paths = get_paths(udisks2)
> print(paths)
> sleep(1)
> ___
> python-hackers-list mailing list
> python-hackers-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/python-hackers-list

signature.asc
Description: This is a digitally signed message part
___
python-hackers-list mailing list
python-hackers-list@gnome.org
https://mail.gnome.org/mailman/listinfo/python-hackers-list


Re: Gio.DBusObjectManagerClient not updating

2018-01-13 Thread infirit
Op 01/13/2018 om 05:19 PM schreef Hayden Lau:
> I understand this is a dev mailing list, but I’m not sure where to post this 
> question otherwise.

You can try the Gtk user mailinglist but I have not had much answers in
there regarding Gio's DBus classes.

> I’m attempting to write an application that interacts with UDisks2 over  DBus 
> with PyGObject. However, I’m finding that after instantiating the  proper 
> Gio.DBusObjectManagerClient, I seem to be unable to get updates  on the 
> ObjectManager’s state. Am I missing something? The only example  code that I 
> could find that had similar functionality was in udiskie 
> (https://github.com/coldfix/udiskie),  but that application uses 
> Gio.DBusProxy directly. Is that the  recommended approach? My (non-working) 
> proof of concept code pasted  below. It prints the initial set of objects 
> reported by the  ‘org.freedesktop.UDisks2’ object manager, but does not print 
> changes  (either via signal or polling) when disks are added or removed.

The object manager is there as the name suggest to manage dbus objects.
From it you can easily create proxies for all the objects it manages. If
you like some other examples of how to use Gio's dbus classes have a
look at
https://github.com/blueman-project/blueman/tree/master/blueman/bluez.

Now for the actual problem. Gio dbus implementation require a eventloop
to update. If you do not intend to use any Gtk widgets you can use
GLib.MainLoop if you do then call Gtk.main at the end of your module

> 
> from time import sleep
> import gi
> gi.require_version('Gio', '2.0')
> from gi.repository import Gio
from gi.repository import GLib
>
> udisks2 = Gio.DBusObjectManagerClient.new_for_bus_sync(
>     Gio.BusType.SYSTEM, 
>     Gio.DBusObjectManagerClientFlags.NONE,
>     'org.freedesktop.UDisks2',
>     '/org/freedesktop/UDisks2',
>     None,
>     None,
>     None
> )
>
> def new_obj_handler(obj):
>     print('New Object: ', obj)
>
> def new_iface_handler(obj):
>     print('New Interface: ', obj)
>
> def get_paths(objmgr):
>     return [obj.get_object_path() for obj in objmgr.get_objects()]
>
> udisks2.connect('interface-added', new_iface_handler)
> udisks2.connect('object-added', new_obj_handler)
loop = GLib.MainLoop()
loop.run()

> paths = []
> while(True):
>     if paths != get_paths(udisks2):
>     paths = get_paths(udisks2)
>     print(paths)
>     sleep(1)

Above is not going to work when you use an eventloop. You will need to
schedule a function to be run, for example with GLib.timeout_add_seconds
[1].

~infirit

[1]
https://developer.gnome.org/glib/stable/glib-The-Main-Event-Loop.html#g-timeout-add-seconds

___
python-hackers-list mailing list
python-hackers-list@gnome.org
https://mail.gnome.org/mailman/listinfo/python-hackers-list


Gio.DBusObjectManagerClient not updating

2018-01-13 Thread Hayden Lau
Hello,

I understand this is a dev mailing list, but I’m not sure where to post this 
question otherwise.

I’m attempting to write an application that interacts with UDisks2 over  DBus 
with PyGObject. However, I’m finding that after instantiating the  proper 
Gio.DBusObjectManagerClient, I seem to be unable to get updates  on the 
ObjectManager’s state. Am I missing something? The only example  code that I 
could find that had similar functionality was in udiskie 
(https://github.com/coldfix/udiskie),  but that application uses Gio.DBusProxy 
directly. Is that the  recommended approach? My (non-working) proof of concept 
code pasted  below. It prints the initial set of objects reported by the  
‘org.freedesktop.UDisks2’ object manager, but does not print changes  (either 
via signal or polling) when disks are added or removed.

I am using the version of PyGObject that comes packaged with Ubuntu 16.04 LTS, 
3.20.0, along with the versions of DBus and Glib, etc that also come with the 
OS. (https://packages.ubuntu.com/xenial/python3-gi)

Thank you,
Hayden Lau


from time import sleep
import gi
gi.require_version('Gio', '2.0')
from gi.repository import Gio

udisks2 = Gio.DBusObjectManagerClient.new_for_bus_sync(
    Gio.BusType.SYSTEM, 
    Gio.DBusObjectManagerClientFlags.NONE,
    'org.freedesktop.UDisks2',
    '/org/freedesktop/UDisks2',
    None,
    None,
    None
)

def new_obj_handler(obj):
    print('New Object: ', obj)

def new_iface_handler(obj):
    print('New Interface: ', obj)

def get_paths(objmgr):
    return [obj.get_object_path() for obj in objmgr.get_objects()]

udisks2.connect('interface-added', new_iface_handler)
udisks2.connect('object-added', new_obj_handler)

paths = []
while(True):
    if paths != get_paths(udisks2):
    paths = get_paths(udisks2)
    print(paths)
    sleep(1)
___
python-hackers-list mailing list
python-hackers-list@gnome.org
https://mail.gnome.org/mailman/listinfo/python-hackers-list