Error: '__main__.NautilusVFSFile' object is not iterable



Hi,

I am learning to write scripts for nautilus-python and, after reading the docs and some examples, I elaborated this small script:


#!/usr/bin/env python

from gi.repository import Nautilus, GObject, Gtk, GdkPixbuf
import urllib, os, subprocess, re
import locale, gettext

ROOT_ICON = "/usr/share/icons/elementary/stock/48/stock_person.svg"
TERMINAL_ICON = "/usr/share/pixmaps/gksu-root-terminal.png"
NAUTILUS_ICON = "/usr/share/icons/hicolor/scalable/apps/nautilus.svg"

class ColumnExtension(GObject.GObject, Nautilus.MenuProvider):
    def __init__(self):
        try:
            factory = Gtk.IconFactory()
           
            # Add Root icon
            pixbuf = GdkPixbuf.Pixbuf.new_from_file(ROOT_ICON)
            iconset = Gtk.IconSet.new_from_pixbuf(pixbuf)
            factory.add("Root", iconset)
           
            # Add Nautilus icon
            pixbuf = GdkPixbuf.Pixbuf.new_from_file(NAUTILUS_ICON)
            iconset = Gtk.IconSet.new_from_pixbuf(pixbuf)
            factory.add("Nautilus", iconset)

            # Add Root Terminal icon
            pixbuf = GdkPixbuf.Pixbuf.new_from_file(TERMINAL_ICON)
            iconset = Gtk.IconSet.new_from_pixbuf(pixbuf)
            factory.add("Terminal", iconset)
                       
            factory.add_default()
        except: pass

    def root_terminal(self, menu, selected):
        """Runs the Terminal on the given Directory"""
        bash_string = "gksu \"exo-open --launch TerminalEmulator --working-directory='" + selected + "'\" &"
        subprocess.call(bash_string, shell=True)

    def open_with_nautilus(self, menu, selected):
        """Open the selected Folder with Nautilus as Root User"""
        subprocess.call("gksu \"nautilus --no-desktop " + selected + "\" &", shell=True)

    def get_background_items(self, window, current_directory):
       
        menuitem = Nautilus.MenuItem(name='RootMenu::Root',
                                         label='Root',
                                         tip='',
                                         icon='Root')

        submenu = Nautilus.Menu()
        menuitem.set_submenu(submenu)

        sub_menuitem = Nautilus.MenuItem(name='RootMenu::RootTerminal',
                                         label='Root Terminal',
                                         tip='',
                                         icon='Terminal')
        submenu.append_item(sub_menuitem)
        sub_menuitem.connect('activate', self.root_terminal, re.escape(current_directory))

        sub_menuitem = Nautilus.MenuItem(name='RootMenu::OpenNautilus',
                                         label='Open as Root',
                                         tip='',
                                         icon='Nautilus')
        submenu.append_item(sub_menuitem)
        sub_menuitem.connect('activate', self.run_as_root, re.escape(current_directory))

        return menuitem,


Unfortunately, Nautilus does not like these lines and spits out an error:

Traceback (most recent call last):
  File "/home/vigil/.local/share/nautilus-python/extensions/root-menu.py", line 63, in get_background_items
    sub_menuitem.connect('activate', self.root_terminal, re.escape(current_directory))
  File "/usr/lib/python2.7/re.py", line 208, in escape
    s = list(pattern)
TypeError: '__main__.NautilusVFSFile' object is not iterable

I'm sure I'm missing something obvious, but I supposed that 'current_directory' in get_background_items was simply... the current directory. It turns out that it is a mysterious iterable object I wasn't aware of.

Being a total noob, I'd like to know what this error means.

Thank you


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