[pygtksourceview/gtksourcecompletion] Added bindings for GtkSourceCompletion
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: svn-commits-list gnome org
- Subject: [pygtksourceview/gtksourcecompletion] Added bindings for GtkSourceCompletion
- Date: Sat, 18 Apr 2009 07:37:59 -0400 (EDT)
commit 414c93b6faa2f08274a54c1d10392c47bd32d91e
Author: Jesse van den Kieboom <jesse icecrew nl>
Date: Sat Apr 18 13:37:06 2009 +0200
Added bindings for GtkSourceCompletion
Binding should work correctly and all methods should be bound. A simple test provider was added to the test
---
gtksourceview2.defs | 345 +++++++++++++++++++++++++++++++++++++++++++++++
gtksourceview2.override | 212 ++++++++++++++++++++++++++++-
test/test-widget.py | 28 ++++
3 files changed, 582 insertions(+), 3 deletions(-)
diff --git a/gtksourceview2.defs b/gtksourceview2.defs
index 0a6c07d..e63d5e5 100644
--- a/gtksourceview2.defs
+++ b/gtksourceview2.defs
@@ -63,6 +63,38 @@
(gtype-id "GTK_TYPE_SOURCE_VIEW")
)
+(define-object Completion
+ (in-module "GtkSourceView")
+ (parent "GObject")
+ (c-name "GtkSourceCompletion")
+ (gtype-id "GTK_TYPE_SOURCE_COMPLETION")
+)
+
+(define-object CompletionInfo
+ (in-module "GtkSourceView")
+ (parent "GtkWindow")
+ (c-name "GtkSourceCompletionInfo")
+ (gtype-id "GTK_TYPE_SOURCE_COMPLETION_INFO")
+)
+
+(define-object CompletionItem
+ (in-module "GtkSourceView")
+ (parent "GObject")
+ (c-name "GtkSourceCompletionItem")
+ (gtype-id "GTK_TYPE_SOURCE_COMPLETION_ITEM")
+)
+
+(define-interface CompletionProposal
+ (in-module "GtkSourceView")
+ (c-name "GtkSourceCompletionProposal")
+ (gtype-id "GTK_TYPE_SOURCE_COMPLETION_PROPOSAL")
+)
+
+(define-interface CompletionProvider
+ (in-module "GtkSourceView")
+ (c-name "GtkSourceCompletionProvider")
+ (gtype-id "GTK_TYPE_SOURCE_COMPLETION_PROVIDER")
+)
;; Enumerations and flags ...
@@ -812,6 +844,22 @@
)
)
+(define-method get_completion
+ (of-object "GtkSourceView")
+ (c-name "gtk_source_view_get_completion")
+ (return-type "GtkSourceCompletion*")
+)
+
+(define-method show_completion
+ (of-object "GtkSourceView")
+ (c-name "gtk_source_view_show_completion")
+ (return-type "none")
+ (parameters
+ '("GList*" "providers")
+ )
+)
+
+
;; From gtksourcemark.h
@@ -1163,6 +1211,237 @@
)
)
+;; From gtksourcecompletion.h
+
+(define-function gtk_source_completion_get_type
+ (c-name "gtk_source_completion_get_type")
+ (return-type "GType")
+)
+
+(define-method add_provider
+ (of-object "GtkSourceCompletion")
+ (c-name "gtk_source_completion_add_provider")
+ (return-type "gboolean")
+ (parameters
+ '("GtkSourceCompletionProvider*" "provider")
+ )
+)
+
+(define-method remove_provider
+ (of-object "GtkSourceCompletion")
+ (c-name "gtk_source_completion_remove_provider")
+ (return-type "gboolean")
+ (parameters
+ '("GtkSourceCompletionProvider*" "provider")
+ )
+)
+
+(define-method popup
+ (of-object "GtkSourceCompletion")
+ (c-name "gtk_source_completion_popup")
+ (return-type "gboolean")
+ (parameters
+ '("GList*" "providers")
+ '("const-gchar*" "criteria")
+ )
+)
+
+(define-method finish
+ (of-object "GtkSourceCompletion")
+ (c-name "gtk_source_completion_finish")
+ (return-type "none")
+)
+
+(define-method get_info_window
+ (of-object "GtkSourceCompletion")
+ (c-name "gtk_source_completion_get_info_window")
+ (return-type "GtkSourceCompletionInfo*")
+)
+
+
+
+;; From gtksourcecompletioninfo.h
+
+(define-function gtk_source_completion_info_get_type
+ (c-name "gtk_source_completion_info_get_type")
+ (return-type "GType")
+)
+
+(define-function gtk_source_completion_info_new
+ (c-name "gtk_source_completion_info_new")
+ (is-constructor-of "GtkSourceCompletionInfo")
+ (return-type "GtkSourceCompletionInfo*")
+)
+
+(define-method move_to_iter
+ (of-object "GtkSourceCompletionInfo")
+ (c-name "gtk_source_completion_info_move_to_iter")
+ (return-type "none")
+ (parameters
+ '("GtkTextView*" "view")
+ '("GtkTextIter*" "iter")
+ )
+)
+
+(define-method set_sizing
+ (of-object "GtkSourceCompletionInfo")
+ (c-name "gtk_source_completion_info_set_sizing")
+ (return-type "none")
+ (parameters
+ '("gint" "width")
+ '("gint" "height")
+ '("gboolean" "shrink_width")
+ '("gboolean" "shrink_height")
+ )
+)
+
+(define-method set_widget
+ (of-object "GtkSourceCompletionInfo")
+ (c-name "gtk_source_completion_info_set_widget")
+ (return-type "none")
+ (parameters
+ '("GtkWidget*" "widget")
+ )
+)
+
+(define-method get_widget
+ (of-object "GtkSourceCompletionInfo")
+ (c-name "gtk_source_completion_info_get_widget")
+ (return-type "GtkWidget*")
+)
+
+
+
+;; From gtksourcecompletionitem.h
+
+(define-function gtk_source_completion_item_get_type
+ (c-name "gtk_source_completion_item_get_type")
+ (return-type "GType")
+)
+
+(define-function gtk_source_completion_item_new
+ (c-name "gtk_source_completion_item_new")
+ (is-constructor-of "GtkSourceCompletionItem")
+ (return-type "GtkSourceCompletionItem*")
+ (properties
+ '("label" (argname "label"))
+ '("icon" (argname "icon") (optional))
+ '("info" (argname "info") (optional))
+ )
+)
+
+(define-function gtk_source_completion_item_new_from_stock
+ (c-name "gtk_source_completion_item_new_from_stock")
+ (return-type "GtkSourceCompletionItem*")
+ (parameters
+ '("const-gchar*" "label")
+ '("const-gchar*" "stock")
+ '("const-gchar*" "info")
+ )
+)
+
+;; From gtksourcecompletionproposal.h
+
+(define-function gtk_source_completion_proposal_get_type
+ (c-name "gtk_source_completion_proposal_get_type")
+ (return-type "GType")
+)
+
+(define-method get_label
+ (of-object "GtkSourceCompletionProposal")
+ (c-name "gtk_source_completion_proposal_get_label")
+ (return-type "const-gchar*")
+)
+
+(define-method get_icon
+ (of-object "GtkSourceCompletionProposal")
+ (c-name "gtk_source_completion_proposal_get_icon")
+ (return-type "GdkPixbuf*")
+)
+
+(define-method get_info
+ (of-object "GtkSourceCompletionProposal")
+ (c-name "gtk_source_completion_proposal_get_info")
+ (return-type "const-gchar*")
+)
+
+(define-method activate
+ (of-object "GtkSourceCompletionProposal")
+ (c-name "gtk_source_completion_proposal_activate")
+ (return-type "gboolean")
+ (parameters
+ '("GtkSourceBuffer*" "buffer")
+ )
+)
+
+
+
+;; From gtksourcecompletionprovider.h
+
+(define-function gtk_source_completion_provider_get_type
+ (c-name "gtk_source_completion_provider_get_type")
+ (return-type "GType")
+)
+
+(define-method get_name
+ (of-object "GtkSourceCompletionProvider")
+ (c-name "gtk_source_completion_provider_get_name")
+ (return-type "const-gchar*")
+)
+
+(define-method get_icon
+ (of-object "GtkSourceCompletionProvider")
+ (c-name "gtk_source_completion_provider_get_icon")
+ (return-type "GdkPixbuf*")
+)
+
+(define-method get_proposals
+ (of-object "GtkSourceCompletionProvider")
+ (c-name "gtk_source_completion_provider_get_proposals")
+ (return-type "GList*")
+)
+
+(define-method filter_proposal
+ (of-object "GtkSourceCompletionProvider")
+ (c-name "gtk_source_completion_provider_filter_proposal")
+ (return-type "gboolean")
+ (parameters
+ '("GtkSourceCompletionProposal*" "proposal")
+ '("const-gchar*" "criteria")
+ )
+)
+
+(define-method get_automatic
+ (of-object "GtkSourceCompletionProvider")
+ (c-name "gtk_source_completion_provider_get_automatic")
+ (return-type "gboolean")
+)
+
+(define-method get_interactive
+ (of-object "GtkSourceCompletionProvider")
+ (c-name "gtk_source_completion_provider_get_interactive")
+ (return-type "gboolean")
+)
+
+(define-method get_info_widget
+ (of-object "GtkSourceCompletionProvider")
+ (c-name "gtk_source_completion_provider_get_info_widget")
+ (return-type "GtkWidget*")
+ (parameters
+ '("GtkSourceCompletionProposal*" "proposal")
+ )
+)
+
+(define-method update_info
+ (of-object "GtkSourceCompletionProvider")
+ (c-name "gtk_source_completion_provider_update_info")
+ (return-type "none")
+ (parameters
+ '("GtkSourceCompletionProposal*" "proposal")
+ '("GtkSourceCompletionInfo*" "info")
+ )
+)
+
;; virtuals
@@ -1174,3 +1453,69 @@
(of-object "GtkSourceView")
(return-type "none")
)
+
+(define-virtual get_label
+ (of-object "GtkSourceCompletionProposal")
+ (return-type "const-gchar*")
+)
+
+(define-virtual get_icon
+ (of-object "GtkSourceCompletionProposal")
+ (return-type "GdkPixbuf*")
+)
+
+(define-virtual get_info
+ (of-object "GtkSourceCompletionProposal")
+ (return-type "const-gchar*")
+)
+
+(define-virtual get_name
+ (of-object "GtkSourceCompletionProvider")
+ (return-type "const-gchar*")
+)
+
+(define-virtual get_icon
+ (of-object "GtkSourceCompletionProvider")
+ (return-type "GdkPixbuf*")
+)
+
+(define-virtual get_proposals
+ (of-object "GtkSourceCompletionProvider")
+ (return-type "GList*")
+)
+
+(define-virtual filter_proposal
+ (of-object "GtkSourceCompletionProvider")
+ (return-type "gboolean")
+ (parameters
+ '("GtkSourceCompletionProposal*" "proposal")
+ '("const-gchar*" "criteria")
+ )
+)
+
+(define-virtual get_automatic
+ (of-object "GtkSourceCompletionProvider")
+ (return-type "gboolean")
+)
+
+(define-virtual get_interactive
+ (of-object "GtkSourceCompletionProvider")
+ (return-type "gboolean")
+)
+
+(define-virtual get_info_widget
+ (of-object "GtkSourceCompletionProvider")
+ (return-type "GtkWidget*")
+ (parameters
+ '("GtkSourceCompletionProposal*" "proposal")
+ )
+)
+
+(define-virtual update_info
+ (of-object "GtkSourceCompletionProvider")
+ (return-type "none")
+ (parameters
+ '("GtkSourceCompletionProposal*" "proposal")
+ '("GtkSourceCompletionInfo*" "info")
+ )
+)
diff --git a/gtksourceview2.override b/gtksourceview2.override
index 6ab928e..a75d326 100644
--- a/gtksourceview2.override
+++ b/gtksourceview2.override
@@ -14,6 +14,10 @@ headers
#include <gtksourceview/gtksourceiter.h>
#include <gtksourceview/gtksourcebuffer.h>
#include <gtksourceview/gtksourceprintcompositor.h>
+#include <gtksourceview/gtksourcecompletion.h>
+#include <gtksourceview/gtksourcecompletionitem.h>
+#include <gtksourceview/gtksourcecompletionprovider.h>
+#include <gtksourceview/gtksourcecompletioninfo.h>
static PyObject *
gslist_to_pylist_objs (const GSList *source)
@@ -30,6 +34,20 @@ gslist_to_pylist_objs (const GSList *source)
}
static PyObject *
+glist_to_pylist_objs (const GList *source)
+{
+ const GList *iter;
+ PyObject *dest = PyList_New (0);
+ for (iter = source; iter != NULL; iter = iter->next)
+ {
+ PyObject *item = pygobject_new ((GObject *)iter->data);
+ PyList_Append (dest, item);
+ Py_DECREF (item);
+ }
+ return dest;
+}
+
+static PyObject *
strv_to_pylist (char **strv)
{
gsize len, i;
@@ -106,10 +124,12 @@ import gtk.TextView as PyGtkTextView_Type
import gtk.TextBuffer as PyGtkTextBuffer_Type
import gtk.TextMark as PyGtkTextMark_Type
import gtk.PrintContext as PyGtkPrintContext_Type
-
+import gtk.Widget as PyGtkWidget_Type
+import gtk.Window as PyGtkWindow_Type
%%
ignore-glob
*_get_type
+gtk_source_completion_item_new_from_stock
%%
override gtk_source_language_get_globs noargs
static PyObject *
@@ -260,7 +280,7 @@ static PyObject *
_wrap_gtk_source_language_tp_new(PyTypeObject *type)
{
PyErr_SetString(PyExc_TypeError,
- "cannot create instance of type `GtkSourceLanguage'");
+ "cannot create instance of type `GtkSourceLanguage'");
return NULL;
}
@@ -270,7 +290,7 @@ static PyObject *
_wrap_gtk_source_style_scheme_tp_new(PyTypeObject *type)
{
PyErr_SetString(PyExc_TypeError,
- "cannot create instance of type `GtkSourceStyleScheme'");
+ "cannot create instance of type `GtkSourceStyleScheme'");
return NULL;
}
@@ -466,3 +486,189 @@ _wrap_gtk_source_view_get_mark_category_background(PyGObject *self,
return(Py_None);
}
}
+
+%%
+override gtk_source_view_show_completion kwargs
+
+static GList *
+pylist_to_glist_gobjs (PyObject *object, GType gtype)
+{
+ PyObject *item;
+ GObject *obj;
+ GList *ret = NULL;
+ int num;
+ int i;
+
+ if (object == Py_None) {
+ return ret;
+ }
+
+ num = PySequence_Size (object);
+
+ for (i = 0; i < num; ++i) {
+ item = PySequence_GetItem (object, i);
+
+ if (PyObject_TypeCheck(item, &PyGObject_Type)) {
+ obj = pygobject_get (item);
+
+ if (g_type_is_a (G_TYPE_FROM_INSTANCE (obj), gtype)) {
+ ret = g_list_prepend (ret, g_object_ref (obj));
+ }
+ }
+ }
+
+ return g_list_reverse (ret);
+}
+
+static PyObject *
+_wrap_gtk_source_view_show_completion (PyGObject *self,
+ PyObject *args,
+ PyObject *kwargs)
+{
+ static char *kwlist[] = { "providers", NULL };
+ PyObject *providers;
+ GList *items;
+
+ if (!PyArg_ParseTupleAndKeywords(args,
+ kwargs,
+ "|O:GtkSourceView.show_completion",
+ kwlist, &providers));
+
+ if (providers != Py_None && !PySequence_Check(providers)) {
+ PyErr_SetString(PyExc_TypeError, "providers must be a list");
+ return NULL;
+ }
+
+ items = pylist_to_glist_gobjs (providers, GTK_TYPE_SOURCE_COMPLETION_PROVIDER);
+ gtk_source_view_show_completion (GTK_SOURCE_VIEW(self), items);
+
+ g_list_foreach (items, (GFunc)g_object_unref, NULL);
+ g_list_free (items);
+
+ return NULL;
+}
+
+%%
+override gtk_source_completion_popup kwargs
+static PyObject *
+_wrap_gtk_source_completion_popup(PyGObject *self,
+ PyObject *args,
+ PyObject *kwargs)
+{
+ static char *kwlist[] = { "providers", "criteria", NULL };
+ PyObject *providers;
+ const char *criteria;
+ GList *items;
+
+ if (!PyArg_ParseTupleAndKeywords(args,
+ kwargs,
+ "|Oz:GtkSourceCompletion.popup",
+ kwlist, &providers, &criteria));
+
+ if (providers != Py_None && !PySequence_Check(providers)) {
+ PyErr_SetString(PyExc_TypeError, "providers must be a list");
+ return NULL;
+ }
+
+ items = pylist_to_glist_gobjs (providers, GTK_TYPE_SOURCE_COMPLETION_PROVIDER);
+ gtk_source_completion_popup (GTK_SOURCE_COMPLETION(self), items, criteria);
+
+ g_list_foreach (items, (GFunc)g_object_unref, NULL);
+ g_list_free (items);
+
+ return NULL;
+}
+
+%%
+override GtkSourceCompletionProvider__do_get_proposals kwargs
+static PyObject *
+_wrap_GtkSourceCompletionProvider__do_get_proposals(PyObject *cls,
+ PyObject *args,
+ PyObject *kwargs)
+{
+ GtkSourceCompletionProviderIface *iface;
+ static char *kwlist[] = { "self", NULL };
+ PyGObject *self;
+ GList *ret;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O!:GtkSourceCompletionProvider.get_proposals", kwlist, &PyGtkSourceCompletionProvider_Type, &self))
+ return NULL;
+ iface = g_type_interface_peek(g_type_class_peek(pyg_type_from_object(cls)), GTK_TYPE_SOURCE_COMPLETION_PROVIDER);
+ if (iface->get_proposals)
+ ret = iface->get_proposals(GTK_SOURCE_COMPLETION_PROVIDER(self->obj));
+ else {
+ PyErr_SetString(PyExc_NotImplementedError, "interface method GtkSourceCompletionProvider.get_proposals not implemented");
+ return NULL;
+ }
+
+ return glist_to_pylist_objs (ret);
+}
+
+%%
+override gtk_source_completion_provider_get_proposals kwargs
+static PyObject *
+_wrap_gtk_source_completion_provider_get_proposals(PyGObject *self,
+ PyObject *args,
+ PyObject *kwargs)
+{
+ GList *proposals;
+
+ proposals = gtk_source_completion_provider_get_proposals (GTK_SOURCE_COMPLETION_PROVIDER (self));
+
+ return glist_to_pylist_objs (proposals);
+}
+%%
+override GtkSourceCompletionProvider__proxy_do_get_proposals
+static GList *
+_wrap_GtkSourceCompletionProvider__proxy_do_get_proposals(GtkSourceCompletionProvider *self)
+{
+ PyGILState_STATE __py_state;
+ PyObject *py_self;
+ GList *retval;
+ PyObject *py_retval;
+ PyObject *py_method;
+
+ __py_state = pyg_gil_state_ensure();
+ py_self = pygobject_new((GObject *) self);
+ if (!py_self) {
+ if (PyErr_Occurred())
+ PyErr_Print();
+ pyg_gil_state_release(__py_state);
+ return FALSE;
+ }
+
+
+ py_method = PyObject_GetAttrString(py_self, "do_get_proposals");
+ if (!py_method) {
+ if (PyErr_Occurred())
+ PyErr_Print();
+ Py_DECREF(py_self);
+ pyg_gil_state_release(__py_state);
+ return FALSE;
+ }
+ py_retval = PyObject_CallObject(py_method, NULL);
+ if (!py_retval) {
+ if (PyErr_Occurred())
+ PyErr_Print();
+ Py_XDECREF(py_retval);
+ Py_DECREF(py_method);
+ Py_DECREF(py_self);
+ pyg_gil_state_release(__py_state);
+ return NULL;
+ }
+
+ if (py_retval != Py_None && !PySequence_Check (py_retval)) {
+ PyErr_SetString(PyExc_TypeError, "proposals must be a list");
+ PyErr_Print();
+ retval = NULL;
+ } else {
+ retval = pylist_to_glist_gobjs (py_retval, GTK_TYPE_SOURCE_COMPLETION_PROPOSAL);
+ }
+
+ Py_XDECREF(py_retval);
+ Py_DECREF(py_method);
+ Py_DECREF(py_self);
+ pyg_gil_state_release(__py_state);
+
+ return retval;
+}
diff --git a/test/test-widget.py b/test/test-widget.py
index fe1688c..a55c610 100644
--- a/test/test-widget.py
+++ b/test/test-widget.py
@@ -28,6 +28,7 @@ import gtk
import gtksourceview2 as gtksourceview
import gio
import pango
+import gobject
######################################################################
@@ -298,6 +299,31 @@ buffer_ui_description = """
</ui>
"""
+class TestProvider(gobject.GObject, gtksourceview.CompletionProvider):
+ def __init__(self, name):
+ gobject.GObject.__init__(self)
+
+ self.name = name
+
+ def do_get_name(self):
+ return self.name
+
+ def do_get_proposals(self):
+ return [
+ gtksourceview.CompletionItem("Proposal 1", None, None),
+ gtksourceview.CompletionItem("Proposal 2", None, None),
+ gtksourceview.CompletionItem("Proposal 3", None, None),
+ ]
+
+gobject.type_register(TestProvider)
+
+######################################################################
+##### initialize completion
+def initialize_completion(view):
+ completion = view.get_completion()
+
+ completion.add_provider(TestProvider('Provider 1'))
+ completion.add_provider(TestProvider('Provider 2'))
######################################################################
##### create view window
@@ -314,6 +340,8 @@ def create_view_window(buffer, sourceview = None):
buffer.connect('changed', update_cursor_position, view)
view.connect('button-press-event', button_press_cb)
window.connect('delete-event', window_deleted_cb, view)
+
+ initialize_completion(view)
# action group and UI manager
action_group = gtk.ActionGroup('ViewActions')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]