[glade/gladegjs] Added GJS plugin for JavaScript objects support
- From: Juan Pablo Ugarte <jpu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glade/gladegjs] Added GJS plugin for JavaScript objects support
- Date: Tue, 13 Sep 2016 13:00:53 +0000 (UTC)
commit 1d5feadcc0204e0106115f8eff851aee3938523c
Author: Juan Pablo Ugarte <juanpablougarte gmail com>
Date: Sun Jul 31 21:08:52 2016 -0300
Added GJS plugin for JavaScript objects support
configure.ac | 18 +++++++
plugins/Makefile.am | 4 ++
plugins/gjs/Makefile.am | 30 +++++++++++
plugins/gjs/glade-gjs.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 183 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 021622c..72c752b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -207,6 +207,22 @@ fi
AM_CONDITIONAL(BUILD_PYTHON, test x"$have_python" = "xyes")
+dnl ================================================================
+dnl GJS for optional JavaScript support
+dnl ================================================================
+GJS_REQUIRED=1.45.3
+
+AC_ARG_ENABLE(gjs,
+ AS_HELP_STRING([--disable-gjs], [disable gjs catalog]),
+ check_gjs=$enableval, check_gjs=yes)
+
+if test x"$check_gjs" = x"yes"; then
+ PKG_CHECK_MODULES([GJS],[gtk+-3.0 gjs-1.0 >= $GJS_REQUIRED],[have_gjs=yes],[have_gjs=no])
+else
+ have_gjs=no
+fi
+AM_CONDITIONAL(BUILD_GJS, test x"$have_gjs" = "xyes")
+
# ==================================================================
# Glade User Manual (requires yelp-tools)
# ==================================================================
@@ -341,6 +357,7 @@ plugins/gtk+/icons/Makefile
plugins/gtk+/icons/16x16/Makefile
plugins/gtk+/icons/22x22/Makefile
plugins/python/Makefile
+plugins/gjs/Makefile
plugins/gladeui/Makefile
po/Makefile.in
doc/Makefile
@@ -362,6 +379,7 @@ Configuration:
Debug Enabled: ${enable_debug}
GTK+ UNIX Print Widgets: ${have_unix_print}
PYTHON Widgets support: ${have_python}
+ GJS Widgets support: ${have_gjs}
Gladeui Catalog: ${enable_gladeui}
Introspection Data: ${found_introspection}
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 7366796..9420d64 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -6,6 +6,10 @@ if BUILD_PYTHON
SUBDIRS += python
endif
+if BUILD_GJS
+SUBDIRS += gjs
+endif
+
if BUILD_GLADEUI
SUBDIRS += gladeui
endif
diff --git a/plugins/gjs/Makefile.am b/plugins/gjs/Makefile.am
new file mode 100644
index 0000000..86ad9a5
--- /dev/null
+++ b/plugins/gjs/Makefile.am
@@ -0,0 +1,30 @@
+## Process this file with automake to produce Makefile.in
+
+libgladeui = $(top_builddir)/gladeui/libgladeui-2.la
+
+
+# libgladegjs
+
+gladegjs_LTLIBRARIES = libgladegjs.la
+gladegjsdir = $(pkglibdir)/modules
+
+libgladegjs_la_CPPFLAGS = \
+ -DG_LOG_DOMAIN=\"GladeUI-GJS\" \
+ -I$(top_srcdir) \
+ -I$(top_builddir) \
+ $(GJS_INCLUDES)
+
+libgladegjs_la_CFLAGS = \
+ $(AM_CFLAGS) \
+ $(PLUGINS_WARN_CFLAGS) \
+ $(GJS_CFLAGS)
+
+libgladegjs_la_SOURCES = glade-gjs.c
+
+libgladegjs_la_LDFLAGS = -module -avoid-version $(AM_LDFLAGS) $(GJS_LDFLAGS)
+libgladegjs_la_LIBADD = $(libgladeui) $(GJS_LIBS)
+
+if PLATFORM_WIN32
+libgladegjs_la_LDFLAGS += -no-undefined
+endif
+
diff --git a/plugins/gjs/glade-gjs.c b/plugins/gjs/glade-gjs.c
new file mode 100644
index 0000000..a67633a
--- /dev/null
+++ b/plugins/gjs/glade-gjs.c
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2016 Juan Pablo Ugarte.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Authors:
+ * Juan Pablo Ugarte <juanpablougarte gmail com>
+ */
+
+#ifndef STANDALONE_DEBUG
+#include <config.h>
+#endif
+
+#include <gjs/gjs.h>
+#include <gladeui/glade.h>
+
+static gboolean
+glade_gjs_setup ()
+{
+ GjsContext *context;
+ const gchar *path;
+ const GList *l;
+ GArray *paths;
+
+ paths = g_array_new (TRUE, FALSE, sizeof (gchar *));
+
+ /* GLADE_ENV_MODULE_PATH has priority */
+ if ((path = g_getenv (GLADE_ENV_MODULE_PATH)))
+ g_array_append_val (paths, path);
+
+ /* Append modules directory */
+ if ((path = glade_app_get_modules_dir ()))
+ g_array_append_val (paths, path);
+
+ /* Append extra paths (declared in the Preferences) */
+ for (l = glade_catalog_get_extra_paths (); l; l = g_list_next (l))
+ g_array_append_val (paths, l->data);
+
+ /* Create new JS context and set it as default if needed */
+ context = gjs_context_new_with_search_path ((gchar **) paths->data);
+ if (gjs_context_get_current() != context)
+ gjs_context_make_current (context);
+
+g_object_ref_sink (context);
+
+ g_array_free (paths, TRUE);
+
+ return FALSE;
+}
+
+void
+glade_gjs_init (const gchar *name)
+{
+ gchar *import_sentence, *cname;
+ static gsize init = 0;
+ int exit_status = 0;
+ GError *error = NULL;
+
+ if (g_once_init_enter (&init))
+ {
+ if (glade_gjs_setup ())
+ return;
+
+ g_once_init_leave (&init, TRUE);
+ }
+
+ cname = g_strdup (name);
+ if (cname[0])
+ cname[0] = g_ascii_toupper (cname[0]);
+
+ /* Yeah, we use the catalog name as the library */
+ import_sentence = g_strdup_printf ("const %s = imports.%s;", cname, name);
+
+ /* Importing the module will create all the GTypes so that glade can use them at runtime */
+ gjs_context_eval (gjs_context_get_current (),
+ import_sentence, -1, NULL,
+ &exit_status,
+ &error);
+
+ if (error)
+ {
+ g_warning ("GJS module '%s' import failed: '%s' %s", name, import_sentence, error->message);
+ g_error_free (error);
+ }
+
+ g_free (import_sentence);
+}
+
+#ifdef STANDALONE_DEBUG
+
+/* gcc -DSTANDALONE_DEBUG=1 glade-gjs.c -o glade-gjs -O0 -g `pkg-config gladeui-2.0 gobject-2.0 gjs-1.0
--libs --cflags` */
+int
+main (int argc, char **argv)
+{
+ GtkWidget *win, *box, *label;
+
+ gtk_init (&argc, &argv);
+ glade_init ();
+
+ win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+
+ glade_gjs_init ("gjsplugin");
+
+ box = g_object_new (g_type_from_name("Gjs_MyBox"), NULL);
+
+ label = gtk_label_new ("This is a regular GtkLabel inside a MyBox GJS object");
+
+ gtk_container_add (GTK_CONTAINER (box), label);
+ gtk_container_add (GTK_CONTAINER (win), box);
+
+ gtk_widget_show_all (GTK_WIDGET (win));
+
+ gtk_main ();
+
+ return 0;
+}
+
+#endif
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]