[nautilus-python/nautilus-3.0] Forgot to add the non-deleted changes to the previous commit. Included them here
- From: Adam Plumb <adamplumb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-python/nautilus-3.0] Forgot to add the non-deleted changes to the previous commit. Included them here
- Date: Tue, 8 Mar 2011 21:12:14 +0000 (UTC)
commit f3515ab30369c07fa0d89e132599295c6e69150c
Author: Adam Plumb <adamplumb gmail com>
Date: Tue Mar 8 16:12:06 2011 -0500
Forgot to add the non-deleted changes to the previous commit. Included them here
configure.in | 23 +-------
examples/background-image.py | 12 ++--
examples/block-size-column.py | 13 ++--
examples/location-widget-provider.py | 8 +-
examples/md5sum-property-page.py | 23 ++++----
examples/open-terminal.py | 19 +++---
examples/submenu.py | 34 +++++++----
examples/update-file-info-async.py | 12 +++-
src/Makefile.am | 24 --------
src/nautilus-python-object.c | 56 +----------------
src/nautilus-python.c | 107 +++++----------------------------
src/nautilus-python.h | 1 -
12 files changed, 93 insertions(+), 239 deletions(-)
---
diff --git a/configure.in b/configure.in
index f587e41..824a730 100644
--- a/configure.in
+++ b/configure.in
@@ -12,10 +12,8 @@ AC_CONFIG_MACRO_DIR([m4])
AC_SUBST(ACLOCAL_AMFLAGS, "-I m4 -I .")
-NAUTILUS_REQUIRED=2.22.0
-PYGTK_REQUIRED=2.8.0
+NAUTILUS_REQUIRED=2.91
PYGOBJECT_REQUIRED=2.16.0
-GNOME_PYTHON_REQUIRED=2.12.0
AC_PROG_CC
AC_DISABLE_STATIC
@@ -42,26 +40,9 @@ AM_CHECK_PYTHON_HEADERS(,[AC_MSG_ERROR(could not find Python headers)])
AM_CHECK_PYTHON_LIBS(,[AC_MSG_ERROR(could not find Python lib)])
-PKG_CHECK_MODULES(NAUTILUS_PYTHON, [pygtk-2.0 >= $PYGTK_REQUIRED
- pygobject-2.0 >= $PYGOBJECT_REQUIRED
- gnome-python-2.0 >= $GNOME_PYTHON_REQUIRED
+PKG_CHECK_MODULES(NAUTILUS_PYTHON, [pygobject-2.0 >= $PYGOBJECT_REQUIRED
libnautilus-extension >= $NAUTILUS_REQUIRED])
-AC_MSG_CHECKING(for pygtk defs)
-PYGTK_DEFSDIR=`$PKG_CONFIG --variable=defsdir pygtk-2.0`
-AC_SUBST(PYGTK_DEFSDIR)
-AC_MSG_RESULT($PYGTK_DEFSDIR)
-
-AC_MSG_CHECKING(for pygtk codegen)
-PYGTK_CODEGEN="$PYTHON `$PKG_CONFIG --variable=codegendir pygtk-2.0`/codegen.py"
-AC_SUBST(PYGTK_CODEGEN)
-AC_MSG_RESULT($PYGTK_CODEGEN)
-
-AC_MSG_CHECKING(for pygobject defs)
-PYGOBJECT_DEFSDIR=`$PKG_CONFIG --variable=defsdir pygobject-2.0`
-AC_SUBST(PYGOBJECT_DEFSDIR)
-AC_MSG_RESULT($PYGOBJECT_DEFSDIR)
-
PYGOBJECT_DATADIR=`$PKG_CONFIG --variable=datadir pygobject-2.0`
AC_SUBST(PYGOBJECT_DATADIR)
diff --git a/examples/background-image.py b/examples/background-image.py
index 5736776..9411f24 100644
--- a/examples/background-image.py
+++ b/examples/background-image.py
@@ -1,12 +1,14 @@
import urllib
import gconf
-import nautilus
+
+import gobject
+from gi.repository import Nautilus
SUPPORTED_FORMATS = 'image/jpeg', 'image/png'
BACKGROUND_KEY = '/desktop/gnome/background/picture_filename'
-class BackgroundImageExtension(nautilus.MenuProvider):
+class BackgroundImageExtension(gobject.GObject, Nautilus.MenuProvider):
def __init__(self):
self.gconf = gconf.client_get_default()
@@ -33,8 +35,8 @@ class BackgroundImageExtension(nautilus.MenuProvider):
if file.get_uri_scheme() != 'file':
return
- item = nautilus.MenuItem('Nautilus::set_background_image',
- 'Use as background image',
- 'Set the current image as a background image')
+ item = Nautilus.MenuItem(name='Nautilus::set_background_image',
+ label='Use as background image',
+ tip='Set the current image as a background image')
item.connect('activate', self.menu_activate_cb, file)
return item,
diff --git a/examples/block-size-column.py b/examples/block-size-column.py
index 3c8b719..a197539 100644
--- a/examples/block-size-column.py
+++ b/examples/block-size-column.py
@@ -1,17 +1,18 @@
import os
import urllib
-import nautilus
+import gobject
+from gi.repository import Nautilus
-class ColumnExtension(nautilus.ColumnProvider, nautilus.InfoProvider):
+class ColumnExtension(gobject.GObject, Nautilus.ColumnProvider, Nautilus.InfoProvider):
def __init__(self):
pass
def get_columns(self):
- return nautilus.Column("NautilusPython::block_size_column",
- "block_size",
- "Block size",
- "Get the block size"),
+ return Nautilus.Column(name="NautilusPython::block_size_column",
+ attribute="block_size",
+ label="Block size",
+ description="Get the block size"),
def update_file_info(self, file):
if file.get_uri_scheme() != 'file':
diff --git a/examples/location-widget-provider.py b/examples/location-widget-provider.py
index d10cb1d..4153eaf 100644
--- a/examples/location-widget-provider.py
+++ b/examples/location-widget-provider.py
@@ -1,12 +1,12 @@
-import nautilus
-import gtk
+import gobject
+from gi.repository import Nautilus, Gtk
-class LocationProviderExample(nautilus.LocationWidgetProvider):
+class LocationProviderExample(gobject.GObject, Nautilus.LocationWidgetProvider):
def __init__(self):
pass
def get_widget(self, uri, window):
- entry = gtk.Entry()
+ entry = Gtk.Entry()
entry.set_text(uri)
entry.show()
return entry
diff --git a/examples/md5sum-property-page.py b/examples/md5sum-property-page.py
index 271c18a..017c3d9 100644
--- a/examples/md5sum-property-page.py
+++ b/examples/md5sum-property-page.py
@@ -1,10 +1,10 @@
import hashlib
import urllib
-import gtk
-import nautilus
+import gobject
+from gi.repository import Nautilus, Gtk
-class MD5SumPropertyPage(nautilus.PropertyPageProvider):
+class MD5SumPropertyPage(gobject.GObject, Nautilus.PropertyPageProvider):
def __init__(self):
pass
@@ -21,22 +21,23 @@ class MD5SumPropertyPage(nautilus.PropertyPageProvider):
filename = urllib.unquote(file.get_uri()[7:])
- self.property_label = gtk.Label('MD5Sum')
+ self.property_label = Gtk.Label('MD5Sum')
self.property_label.show()
- self.hbox = gtk.HBox(0, False)
+ self.hbox = Gtk.HBox(homogeneous=False, spacing=0)
self.hbox.show()
- label = gtk.Label('MD5Sum:')
+ label = Gtk.Label('MD5Sum:')
label.show()
- self.hbox.pack_start(label)
+ self.hbox.pack_start(label, False, False, 0)
- self.value_label = gtk.Label()
- self.hbox.pack_start(self.value_label)
+ self.value_label = Gtk.Label()
+ self.hbox.pack_start(self.value_label, False, False, 0)
md5sum = hashlib.md5(filename).hexdigest()
self.value_label.set_text(md5sum)
self.value_label.show()
- return nautilus.PropertyPage("NautilusPython::md5_sum",
- self.property_label, self.hbox),
+ return Nautilus.PropertyPage(name="NautilusPython::md5_sum",
+ label=self.property_label,
+ page=self.hbox),
diff --git a/examples/open-terminal.py b/examples/open-terminal.py
index 8890a69..cc38670 100644
--- a/examples/open-terminal.py
+++ b/examples/open-terminal.py
@@ -2,13 +2,14 @@
import os
import urllib
-import gtk
-import nautilus
import gconf
+import gobject
+from gi.repository import Nautilus
+
TERMINAL_KEY = '/desktop/gnome/applications/terminal/exec'
-class OpenTerminalExtension(nautilus.MenuProvider):
+class OpenTerminalExtension(gobject.GObject, Nautilus.MenuProvider):
def __init__(self):
self.client = gconf.client_get_default()
@@ -33,15 +34,15 @@ class OpenTerminalExtension(nautilus.MenuProvider):
if not file.is_directory() or file.get_uri_scheme() != 'file':
return
- item = nautilus.MenuItem('NautilusPython::openterminal_file_item',
- 'Open Terminal' ,
- 'Open Terminal In %s' % file.get_name())
+ item = Nautilus.MenuItem(name='NautilusPython::openterminal_file_item',
+ label='Open Terminal' ,
+ tip='Open Terminal In %s' % file.get_name())
item.connect('activate', self.menu_activate_cb, file)
return item,
def get_background_items(self, window, file):
- item = nautilus.MenuItem('NautilusPython::openterminal_item',
- 'Open Terminal Here',
- 'Open Terminal In This Directory')
+ item = Nautilus.MenuItem(name='NautilusPython::openterminal_item',
+ label='Open Terminal Here',
+ tip='Open Terminal In This Directory')
item.connect('activate', self.menu_background_activate_cb, file)
return item,
diff --git a/examples/submenu.py b/examples/submenu.py
index 9a98ebf..5be7cfa 100644
--- a/examples/submenu.py
+++ b/examples/submenu.py
@@ -1,28 +1,38 @@
-import nautilus
+import gobject
+from gi.repository import Nautilus
-class ExampleMenuProvider(nautilus.MenuProvider):
-
- # Nautilus crashes if a plugin doesn't implement the __init__ method.
- # See Bug #374958
+class ExampleMenuProvider(gobject.GObject, Nautilus.MenuProvider):
def __init__(self):
pass
def get_file_items(self, window, files):
- top_menuitem = nautilus.MenuItem('ExampleMenuProvider::Foo', 'Foo', '')
+ top_menuitem = Nautilus.MenuItem(name='ExampleMenuProvider::Foo',
+ label='Foo',
+ tip='',
+ icon='')
- submenu = nautilus.Menu()
+ submenu = Nautilus.Menu()
top_menuitem.set_submenu(submenu)
- sub_menuitem = nautilus.MenuItem('ExampleMenuProvider::Bar', 'Bar', '')
+ sub_menuitem = Nautilus.MenuItem(name='ExampleMenuProvider::Bar',
+ label='Bar',
+ tip='',
+ icon='')
submenu.append_item(sub_menuitem)
return top_menuitem,
def get_background_items(self, window, file):
- submenu = nautilus.Menu()
- submenu.append_item(nautilus.MenuItem('ExampleMenuProvider::Bar', 'Bar', ''))
-
- menuitem = nautilus.MenuItem('ExampleMenuProvider::Foo', 'Foo', '')
+ submenu = Nautilus.Menu()
+ submenu.append_item(Nautilus.MenuItem(name='ExampleMenuProvider::Bar2',
+ label='Bar2',
+ tip='',
+ icon=''))
+
+ menuitem = Nautilus.MenuItem(name='ExampleMenuProvider::Foo2',
+ label='Foo2',
+ tip='',
+ icon='')
menuitem.set_submenu(submenu)
return menuitem,
diff --git a/examples/update-file-info-async.py b/examples/update-file-info-async.py
index 1d14d4f..fa02702 100644
--- a/examples/update-file-info-async.py
+++ b/examples/update-file-info-async.py
@@ -1,15 +1,19 @@
-import nautilus
import gobject
+from gi.repository import Nautilus
-class UpdateFileInfoAsync(nautilus.InfoProvider):
+class UpdateFileInfoAsync(gobject.GObject, Nautilus.InfoProvider):
def __init__(self):
pass
def update_file_info_full(self, provider, handle, closure, file):
print "update_file_info_full"
+ print handle
gobject.timeout_add_seconds(3, self.update_cb, provider, handle, closure)
- return nautilus.OPERATION_IN_PROGRESS
+ return Nautilus.OperationResult.IN_PROGRESS
def update_cb(self, provider, handle, closure):
print "update_cb"
- self.update_complete_invoke(provider, handle, closure, result=nautilus.OPERATION_FAILED)
+ Nautilus.info_provider_update_complete_invoke(self.hello, provider, handle, Nautilus.OperationResult.FAILED)
+
+ def hello(self):
+ print "HELLO"
diff --git a/src/Makefile.am b/src/Makefile.am
index 0b93d81..9e8299a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -22,27 +22,3 @@ libnautilus_python_la_SOURCES = \
libnautilus_python_la_LDFLAGS = -module -avoid-version
libnautilus_python_la_LIBADD = $(NAUTILUS_PYTHON_LIBS) $(PYTHON_LIBS)
-
-pyexec_LTLIBRARIES = nautilus.la
-pyexecdir = $(NAUTILUS_LIBDIR)/nautilus-python
-
-nautilus_la_LDFLAGS = -module -avoid-version -export-symbols-regex initnautilus
-nautilus_la_LIBADD = $(NAUTILUS_PYTHON_LIBS)
-nautilus_la_SOURCES = nautilusmodule.c
-nodist_nautilus_la_SOURCES = nautilus.c
-nautilus.c: nautilus.defs nautilus.override
-CLEANFILES = nautilus.c
-EXTRA_DIST = nautilus.override nautilus.defs
-
-.defs.c:
- (cd $(srcdir)\
- && $(PYGTK_CODEGEN) \
- --register $(PYGTK_DEFSDIR)/pango-types.defs \
- --register $(PYGTK_DEFSDIR)/gdk-types.defs \
- --register $(PYGTK_DEFSDIR)/gtk-types.defs \
- --register $(PYGOBJECT_DEFSDIR)/gio-types.defs \
- --register $(PYGOBJECT_DEFSDIR)/unix-types.defs \
- --override $*.override \
- --prefix py$* $*.defs) > gen-$*.c \
- && cp gen-$*.c $*.c \
- && rm -f gen-$*.c
diff --git a/src/nautilus-python-object.c b/src/nautilus-python-object.c
index 6de25bc..168e301 100644
--- a/src/nautilus-python-object.c
+++ b/src/nautilus-python-object.c
@@ -149,7 +149,7 @@ nautilus_python_object_get_property_pages (NautilusPropertyPageProvider *provide
"(N)", py_files);
HANDLE_RETVAL(py_ret);
- HANDLE_LIST(py_ret, NautilusPropertyPage, "nautilus.PropertyPage");
+ HANDLE_LIST(py_ret, NautilusPropertyPage, "Nautilus.PropertyPage");
beach:
Py_XDECREF(py_ret);
@@ -252,7 +252,7 @@ nautilus_python_object_get_file_items (NautilusMenuProvider *provider,
HANDLE_RETVAL(py_ret);
- HANDLE_LIST(py_ret, NautilusMenuItem, "nautilus.MenuItem");
+ HANDLE_LIST(py_ret, NautilusMenuItem, "Nautilus.MenuItem");
beach:
free_pygobject_data_list(files);
@@ -299,7 +299,7 @@ nautilus_python_object_get_background_items (NautilusMenuProvider *provider,
HANDLE_RETVAL(py_ret);
- HANDLE_LIST(py_ret, NautilusMenuItem, "nautilus.MenuItem");
+ HANDLE_LIST(py_ret, NautilusMenuItem, "Nautilus.MenuItem");
beach:
free_pygobject_data(file, NULL);
@@ -309,58 +309,10 @@ nautilus_python_object_get_background_items (NautilusMenuProvider *provider,
}
#undef METHOD_NAME
-#define METHOD_NAME "get_toolbar_items"
-static GList *
-nautilus_python_object_get_toolbar_items (NautilusMenuProvider *provider,
- GtkWidget *window,
- NautilusFileInfo *file)
-{
- NautilusPythonObject *object = (NautilusPythonObject*)provider;
- GList *ret = NULL;
- PyObject *py_ret = NULL;
- PyGILState_STATE state = pyg_gil_state_ensure();
-
- debug_enter();
-
- CHECK_OBJECT(object);
-
- if (PyObject_HasAttrString(object->instance, "get_toolbar_items_full"))
- {
- py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX "get_toolbar_items_full",
- "(NNN)",
- pygobject_new((GObject *)provider),
- pygobject_new((GObject *)window),
- pygobject_new((GObject *)file));
- }
- else if (PyObject_HasAttrString(object->instance, "get_toolbar_items"))
- {
- py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME,
- "(NN)",
- pygobject_new((GObject *)window),
- pygobject_new((GObject *)file));
- }
- else
- {
- goto beach;
- }
-
- HANDLE_RETVAL(py_ret);
-
- HANDLE_LIST(py_ret, NautilusMenuItem, "nautilus.MenuItem");
-
- beach:
- free_pygobject_data(file, NULL);
- Py_XDECREF(py_ret);
- pyg_gil_state_release(state);
- return ret;
-}
-#undef METHOD_NAME
-
static void
nautilus_python_object_menu_provider_iface_init (NautilusMenuProviderIface *iface)
{
iface->get_background_items = nautilus_python_object_get_background_items;
- iface->get_toolbar_items = nautilus_python_object_get_toolbar_items;
iface->get_file_items = nautilus_python_object_get_file_items;
}
@@ -383,7 +335,7 @@ nautilus_python_object_get_columns (NautilusColumnProvider *provider)
HANDLE_RETVAL(py_ret);
- HANDLE_LIST(py_ret, NautilusColumn, "nautilus.Column");
+ HANDLE_LIST(py_ret, NautilusColumn, "Nautilus.Column");
beach:
Py_XDECREF(py_ret);
diff --git a/src/nautilus-python.c b/src/nautilus-python.c
index 27df331..0908477 100644
--- a/src/nautilus-python.c
+++ b/src/nautilus-python.c
@@ -70,47 +70,22 @@ np_init_pygobject(void)
return TRUE;
}
-static inline gboolean
-np_init_pygtk(void)
+static inline gboolean
+np_init_pygi(void)
{
- PyObject *pygtk = PyImport_ImportModule("gtk._gtk");
- if (pygtk != NULL)
- {
-#ifdef Py_CAPSULE_H
- void *capsule = PyCapsule_Import("gtk._gtk._PyGtk_API", 0);
- if (capsule)
- {
- _PyGtk_API = (struct _PyGtk_FunctionStruct*)capsule;
- }
-#endif
- if (!_PyGtk_API)
- {
- PyObject *module_dict = PyModule_GetDict(pygtk);
- PyObject *cobject = PyDict_GetItemString(module_dict, "_PyGtk_API");
- if (PyCObject_Check(cobject))
- {
- _PyGtk_API = (struct _PyGtk_FunctionStruct*)
- PyCObject_AsVoidPtr(cobject);
- }
- else
- {
- PyErr_SetString(PyExc_RuntimeError,
- "could not find _PyGtk_API object");
- PyErr_Print();
- return FALSE;
- }
- }
- }
- else
- {
+ PyObject *gi;
+
+ gi = PyImport_ImportModule ("gi");
+ if (gi == NULL)
+ {
PyErr_Print();
- g_warning("could not import gtk._gtk");
+ g_warning("could not import gi");
return FALSE;
- }
+ }
+
return TRUE;
}
-
static void
nautilus_python_load_file(GTypeModule *type_module,
const gchar *filename)
@@ -209,8 +184,7 @@ nautilus_python_load_dir (GTypeModule *module,
static gboolean
nautilus_python_init_python (void)
{
- PyObject *pygtk, *mdict, *require;
- PyObject *sys_path, *tmp, *nautilus, *gtk, *pygtk_version, *pygtk_required_version;
+ PyObject *sys_path, *nautilus;
GModule *libpython;
char *argv[] = { "nautilus", NULL };
@@ -246,23 +220,6 @@ nautilus_python_init_python (void)
return FALSE;
}
- /* pygtk.require("2.0") */
- debug("pygtk.require(\"2.0\")");
- pygtk = PyImport_ImportModule("pygtk");
- if (!pygtk)
- {
- PyErr_Print();
- return FALSE;
- }
- mdict = PyModule_GetDict(pygtk);
- require = PyDict_GetItemString(mdict, "require");
- PyObject_CallObject(require, Py_BuildValue("(S)", PyString_FromString("2.0")));
- if (PyErr_Occurred())
- {
- PyErr_Print();
- return FALSE;
- }
-
/* import gobject */
debug("init_pygobject");
if (!np_init_pygobject())
@@ -271,59 +228,29 @@ nautilus_python_init_python (void)
return FALSE;
}
- /* import gtk */
- debug("init_pygtk");
- if (!np_init_pygtk())
+ /* import gi */
+ debug("init_pygi");
+ if (!np_init_pygi())
{
- g_warning("pygtk initialization failed");
+ g_warning("pygi initialization failed");
return FALSE;
}
- /* gobject.threads_init() */
- debug("pyg_enable_threads");
- setenv("PYGTK_USE_GIL_STATE_API", "", 0);
- pyg_enable_threads();
-
- /* gtk.pygtk_version < (2, 4, 0) */
- gtk = PyImport_ImportModule("gtk");
- mdict = PyModule_GetDict(gtk);
- pygtk_version = PyDict_GetItemString(mdict, "pygtk_version");
- pygtk_required_version = Py_BuildValue("(iii)", 2, 4, 0);
- if (PyObject_Compare(pygtk_version, pygtk_required_version) == -1)
- {
- g_warning("PyGTK %s required, but %s found.",
- PyString_AsString(PyObject_Repr(pygtk_required_version)),
- PyString_AsString(PyObject_Repr(pygtk_version)));
- Py_DECREF(pygtk_required_version);
- return FALSE;
- }
- Py_DECREF(pygtk_required_version);
-
- /* sys.path.insert(., ...) */
- debug("sys.path.insert(0, ...)");
- sys_path = PySys_GetObject("path");
- PyList_Insert(sys_path, 0,
- (tmp = PyString_FromString(NAUTILUS_LIBDIR "/nautilus-python")));
- Py_DECREF(tmp);
-
/* import nautilus */
g_setenv("INSIDE_NAUTILUS_PYTHON", "", FALSE);
debug("import nautilus");
- nautilus = PyImport_ImportModule("nautilus");
+ nautilus = PyImport_ImportModule("gi.repository.Nautilus");
if (!nautilus)
{
PyErr_Print();
return FALSE;
}
- /* Extract types and interfaces from nautilus */
- mdict = PyModule_GetDict(nautilus);
-
_PyGtkWidget_Type = pygobject_lookup_class(GTK_TYPE_WIDGET);
g_assert(_PyGtkWidget_Type != NULL);
#define IMPORT(x, y) \
- _PyNautilus##x##_Type = (PyTypeObject *)PyDict_GetItemString(mdict, y); \
+ _PyNautilus##x##_Type = (PyTypeObject *)PyObject_GetAttrString(nautilus, y); \
if (_PyNautilus##x##_Type == NULL) { \
PyErr_Print(); \
return FALSE; \
diff --git a/src/nautilus-python.h b/src/nautilus-python.h
index a9319c3..4745d22 100644
--- a/src/nautilus-python.h
+++ b/src/nautilus-python.h
@@ -45,7 +45,6 @@ extern NautilusPythonDebug nautilus_python_debug;
#define debug_enter_args(x, y) { if (nautilus_python_debug & NAUTILUS_PYTHON_DEBUG_MISC) \
g_printf("%s: entered " x "\n", __FUNCTION__, y); }
-
PyTypeObject *_PyGtkWidget_Type;
#define PyGtkWidget_Type (*_PyGtkWidget_Type)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]