Re: Question about nautilus_menu_provider_emit_items_updated_signal



On 26 April 2010 19:19, Alexander Larsson <alexl redhat com> wrote:
>> What do I emit it from? The nautilus.MenuProvider doesn't provide any
>> "emit" method.
>
> Signal emission is a basic part of gobject, not a method on
> MenuProvider.

Sorry... I'm just not clear on the details here. If I subclass
gobject.GObject and use the "emit" method, then I get:

Emitting signal...
Traceback (most recent call last):
  File "/home/jason/.nautilus/python-extensions/MenuProvTest.py", line
32, in updated_callback
    self.emit('items_updated')
TypeError: <MenuProviderTest object at 0x7f1c4a452fa0 (GObject at
0x287b100)>: unknown signal name: items_updated

If I add the "items_updated" signal to my class' __gsignals__ dict,
then there's no exception, but nothing happens (I presume then that
I'm not firing the signal that the nautilus extension API defines, but
my own custom one now).

Here's the test I'm using:

----
import sys

import nautilus
import gobject

FAKE_MENU_ITEM = nautilus.MenuItem(
                            "Fake",
                            "Fake menu item",
                            "Fake menu item",
                            None)

class MenuProviderTest(gobject.GObject, nautilus.MenuProvider):

    # Probably not a good idea:
    __gsignals__ = {
        'items_updated' : (gobject.SIGNAL_RUN_LAST,
                           gobject.TYPE_NONE,
                           ())
    }

    def __init__(self):
        super(MenuProviderTest, self).__init__()

    def get_file_items(self, window, items):
        sys.stderr.write("In get_file_items\n")
        return [FAKE_MENU_ITEM]

    def get_background_items(self, window, folder):

        sys.stderr.write("In get_background_items\n")

        gobject.timeout_add_seconds(10, self.updated_callback)

        return [FAKE_MENU_ITEM]

    def updated_callback(self):
        sys.stderr.write("Emitting signal...\n")
        self.emit('items_updated')
        sys.stderr.write("Signal done...\n")
        return False

gobject.type_register(MenuProviderTest)
----

— Jason


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]