Re: using gtk from nautilus plugin



Oops, looks like replied directly to Nils instead of the list, stupid me, here is my reply and sorry for the spamming.

Hi Nils,

gtk.MessageDialog is not working with your code because the fifth argument has to be either string or None, and the variable name is of type nautilus.FileInfo, which means you need to call alert(name.get_name()) not just alert(name). I think you could've obtained such debug info if you launched Nautilus from terminal.

Please refer to [1] for more info about nautilus.FileInfo.

Good luck in your extension :) ...

Bests,
Ahmad Sherif

[1] http://projects.gnome.org/nautilus-python/documentation/html/class-nautilus-python-file-info.html

On Sun, Aug 22, 2010 at 4:52 PM, Nils Andresen <andresen nils googlemail com> wrote:
Hi.
I have asked this question in some places, but never got an anwer..
I created an (python) extension like this:

import gtk
import nautilus
import os
def alert(message):
    """A function to debug"""
    dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL,
gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE, message)
    dialog.run()
    dialog.destroy()

class TestExtension(nautilus.MenuProvider):
    def __init__(self):
        pass

    def get_file_items(self, window, files):
        items = []
        """Called when the user selects a file in Nautilus."""
        item = nautilus.MenuItem("NautilusPython::test_item", "Test", "Test")
        item.connect("activate", self.menu_activate_cb, files)
        items.append(item)
        return items

    def menu_activate_cb(self, menu, files):
        """Called when the user selects the menu."""
        for name in files:
            alert(name)

however the gtk.MessageDialog never appears.
If I change the use from gtk to say easygui like this:

import easygui
import nautilus
import os

def alert(message):
   """A function to debug"""
   easygui.msgbox(message)

class TestExtension(nautilus.MenuProvider):
   def __init__(self):
       pass

   def get_file_items(self, window, files):
       items = []
       """Called when the user selects a file in Nautilus."""
       item = nautilus.MenuItem("NautilusPython::test_item", "Test", "Test")
       item.connect("activate", self.menu_activate_cb, files)
       items.append(item)
       return items

   def menu_activate_cb(self, menu, files):
       """Called when the user selects the menu."""
       for name in files:
           alert(name)

All is fine.

Can someone explain to me why the gtk.MessageDialog is not working in this code?

Yours,
Nils
--
nautilus-list mailing list
nautilus-list gnome org
http://mail.gnome.org/mailman/listinfo/nautilus-list



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