Commit 875e246f authored by Johan Dahlin's avatar Johan Dahlin Committed by Johan Dahlin

Bug 552534 – nautilus-python should support writing location widget

2008-09-16  Johan Dahlin  <jdahlin@async.com.br>

    Bug 552534 – nautilus-python should support writing location widget providers

    * src/nautilus-python-object.c (nautilus_python_object_get_widget),
    (nautilus_python_object_location_widget_provider_iface_init),
    (nautilus_python_object_get_type):
    * src/nautilus-python.c (nautilus_python_load_file),
    (nautilus_python_init_python):
    * src/nautilus-python.h:
    * src/nautilus.defs:
    * src/nautilus.override:

    Patch by Tim Cole


svn path=/trunk/; revision=58
parent 52e183ea
2008-09-16 Johan Dahlin <jdahlin@async.com.br>
Bug 552534 – nautilus-python should support writing location widget providers
* src/nautilus-python-object.c (nautilus_python_object_get_widget),
(nautilus_python_object_location_widget_provider_iface_init),
(nautilus_python_object_get_type):
* src/nautilus-python.c (nautilus_python_load_file),
(nautilus_python_init_python):
* src/nautilus-python.h:
* src/nautilus.defs:
* src/nautilus.override:
Patch by Tim Cole
2008-06-09 German Poo-Caaman~o <gpoo@gnome.org>
* config.h.in
......
......@@ -33,6 +33,7 @@
#include <libnautilus-extension/nautilus-file-info.h>
#include <libnautilus-extension/nautilus-info-provider.h>
#include <libnautilus-extension/nautilus-column-provider.h>
#include <libnautilus-extension/nautilus-location-widget-provider.h>
#include <libnautilus-extension/nautilus-menu-item.h>
#include <libnautilus-extension/nautilus-menu-provider.h>
#include <libnautilus-extension/nautilus-property-page-provider.h>
......@@ -131,6 +132,51 @@ nautilus_python_object_property_page_provider_iface_init (NautilusPropertyPagePr
iface->get_pages = nautilus_python_object_get_property_pages;
}
#define METHOD_NAME "get_widget"
static GtkWidget *
nautilus_python_object_get_widget (NautilusLocationWidgetProvider *provider,
const char *uri,
GtkWidget *window)
{
NautilusPythonObject *object = (NautilusPythonObject*)provider;
GtkWidget *ret = NULL;
PyObject *py_ret = NULL;
PyGObject *py_ret_gobj;
PyObject *py_uri = NULL;
PyGILState_STATE state = pyg_gil_state_ensure();
debug_enter();
CHECK_METHOD_NAME(object->instance);
py_uri = PyString_FromString(uri);
py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME,
"(NN)", py_uri,
pygobject_new((GObject *)window));
HANDLE_RETVAL(py_ret);
py_ret_gobj = (PyGObject *)py_ret;
if (!pygobject_check(py_ret_gobj, &PyGtkWidget_Type)) {
PyErr_SetString(PyExc_TypeError,
METHOD_NAME "should return a gtk.Widget");
goto beach;
}
ret = (GtkWidget *)g_object_ref(py_ret_gobj->obj);
beach:
Py_XDECREF(py_ret);
pyg_gil_state_release(state);
return ret;
}
#undef METHOD_NAME
static void
nautilus_python_object_location_widget_provider_iface_init (NautilusLocationWidgetProviderIface *iface)
{
iface->get_widget = nautilus_python_object_get_widget;
}
#define METHOD_NAME "get_file_items"
static GList *
nautilus_python_object_get_file_items (NautilusMenuProvider *provider,
......@@ -364,6 +410,12 @@ nautilus_python_object_get_type (GTypeModule *module,
NULL
};
static const GInterfaceInfo location_widget_provider_iface_info = {
(GInterfaceInitFunc) nautilus_python_object_location_widget_provider_iface_init,
NULL,
NULL
};
static const GInterfaceInfo menu_provider_iface_info = {
(GInterfaceInitFunc) nautilus_python_object_menu_provider_iface_init,
NULL,
......@@ -406,6 +458,12 @@ nautilus_python_object_get_type (GTypeModule *module,
NAUTILUS_TYPE_PROPERTY_PAGE_PROVIDER,
&property_page_provider_iface_info);
}
if (PyObject_IsSubclass(type, (PyObject*)&PyNautilusLocationWidgetProvider_Type)) {
g_type_module_add_interface (module, gtype,
NAUTILUS_TYPE_LOCATION_WIDGET_PROVIDER,
&location_widget_provider_iface_info);
}
if (PyObject_IsSubclass(type, (PyObject*)&PyNautilusMenuProvider_Type)) {
g_type_module_add_interface (module, gtype,
......
......@@ -139,6 +139,7 @@ nautilus_python_load_file(GTypeModule *type_module, const gchar *filename)
if (PyObject_IsSubclass(value, (PyObject*)&PyNautilusColumnProvider_Type) ||
PyObject_IsSubclass(value, (PyObject*)&PyNautilusInfoProvider_Type) ||
PyObject_IsSubclass(value, (PyObject*)&PyNautilusLocationWidgetProvider_Type) ||
PyObject_IsSubclass(value, (PyObject*)&PyNautilusMenuProvider_Type) ||
PyObject_IsSubclass(value, (PyObject*)&PyNautilusPropertyPageProvider_Type)) {
......@@ -293,6 +294,9 @@ nautilus_python_init_python (void)
/* 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); \
if (_PyNautilus##x##_Type == NULL) { \
......@@ -303,6 +307,7 @@ nautilus_python_init_python (void)
IMPORT(Column, "Column");
IMPORT(ColumnProvider, "ColumnProvider");
IMPORT(InfoProvider, "InfoProvider");
IMPORT(LocationWidgetProvider, "LocationWidgetProvider");
IMPORT(Menu, "Menu");
IMPORT(MenuItem, "MenuItem");
IMPORT(MenuProvider, "MenuProvider");
......
......@@ -46,6 +46,9 @@ extern NautilusPythonDebug nautilus_python_debug;
g_printf("%s: entered " x "\n", __FUNCTION__, y); }
PyTypeObject *_PyGtkWidget_Type;
#define PyGtkWidget_Type (*_PyGtkWidget_Type)
PyTypeObject *_PyNautilusColumn_Type;
#define PyNautilusColumn_Type (*_PyNautilusColumn_Type)
......@@ -55,6 +58,9 @@ PyTypeObject *_PyNautilusColumnProvider_Type;
PyTypeObject *_PyNautilusInfoProvider_Type;
#define PyNautilusInfoProvider_Type (*_PyNautilusInfoProvider_Type)
PyTypeObject *_PyNautilusLocationWidgetProvider_Type;
#define PyNautilusLocationWidgetProvider_Type (*_PyNautilusLocationWidgetProvider_Type)
PyTypeObject *_PyNautilusMenu_Type;
#define PyNautilusMenu_Type (*_PyNautilusMenu_Type)
......
......@@ -25,6 +25,12 @@
(gtype-id "NAUTILUS_TYPE_INFO_PROVIDER")
)
(define-interface LocationWidgetProvider
(in-module "Nautilus")
(c-name "NautilusLocationWidgetProvider")
(gtype-id "NAUTILUS_TYPE_LOCATION_WIDGET_PROVIDER")
)
(define-object Menu
(in-module "Nautilus")
(parent "GObject")
......
......@@ -28,6 +28,7 @@ headers
#include <libnautilus-extension/nautilus-file-info.h>
#include <libnautilus-extension/nautilus-info-provider.h>
#include <libnautilus-extension/nautilus-column-provider.h>
#include <libnautilus-extension/nautilus-location-widget-provider.h>
#include <libnautilus-extension/nautilus-menu-provider.h>
#include <libnautilus-extension/nautilus-property-page-provider.h>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment