Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated the Python GTK widget to Python 3 and GTK 3. #221

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ gtk/zbarmarshal.h:
gtk/ZBar-1.0.typelib:
$(MAKE) -C $(srcdir)/gtk ZBar-1.0.typelib

if HAVE_PYGTK2
if HAVE_PYGTK
include $(srcdir)/pygtk/Makefile.am.inc
endif
endif
Expand Down
25 changes: 6 additions & 19 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,6 @@ AC_ARG_VAR([PYTHON_CONFIG], [full path to python-config program])
AC_ARG_VAR([PYTHON_CFLAGS], [compiler flags for building python extensions])
AC_ARG_VAR([PYTHON_LDFLAGS], [linker flags for building python extensions])

AC_ARG_VAR([PYGTK_H2DEF], [full path to PyGTK h2def.py module (python2 only)])
AC_ARG_VAR([PYGTK_CODEGEN], [full path to pygtk-codegen program (python2 only)])
AC_ARG_VAR([PYGTK_DEFS], [directory where PyGTK definitions may be found (python2 only)])

AS_IF([test -z "$PYTHON"],
[AS_IF([test "x$with_python" = "xauto"],
[AC_PATH_PROGS([PYTHON], [python3 python2 python], [:], [$PATH])],
Expand Down Expand Up @@ -613,24 +609,15 @@ Install the development package for python-$am_cv_python_version, or configure
CPPFLAGS="$CPPFLAGS_save"

dnl PyGTK
dnl disable pygtk when we're on Python 3
AS_IF([test "x$with_gtk" != "xno"],
[AS_IF([test "x$PYTHON_VERSION_MAJOR" = "x2"],
[PKG_CHECK_MODULES([PYGTK], [pygtk-2.0], [with_pygtk2="yes"], [with_pygtk2="no"])
AC_CHECK_PROGS([PYGTK_CODEGEN], [pygobject-codegen-2.0 pygtk-codegen-2.0 pygtk-codegen], [:])

AS_IF([test "x$PYGTK_H2DEF" = "x"],
[PYGTK_H2DEF=`$PKG_CONFIG pygtk-2.0 --variable=codegendir`/h2def.py
AS_IF([test -f "$PYGTK_H2DEF"], [], [PYGTK_H2DEF=":"])])
AS_IF([test "x$PYGTK_DEFS" = "x"],
[PYGTK_DEFS=`$PKG_CONFIG pygtk-2.0 --variable=defsdir`])
[AS_IF([test "x$PYTHON_VERSION_MAJOR" = "x3"],
[PKG_CHECK_MODULES([PYGOBJECT], [pygobject-3.0], [with_pygtk="yes"], [with_pygtk="no"])], [:])
])
])
], [with_python="no"])

AS_IF([test "x$PYTHON_VERSION_MAJOR" != "x2"], [with_pygtk2="no"])
AS_IF([test "x$PYTHON_VERSION_MAJOR" != "x3"], [with_pygtk="no"])
AM_CONDITIONAL([HAVE_PYTHON], [test "x$with_python" != "xno"])
AM_CONDITIONAL([HAVE_PYGTK2], [test "x$with_pygtk2" != "xno"])
AM_CONDITIONAL([HAVE_PYGTK], [test "x$with_pygtk" != "xno"])

dnl GObject Introspection (GIR)

Expand Down Expand Up @@ -910,8 +897,8 @@ AS_IF([test "x$have_GM" = "xyes"],
[echo " => ImageMagick is preferred, as GraphicsMagick doesn't support https"])
AS_IF([test "x$with_gtk" = "xno"],
[echo " => GTK support will *NOT* be built"])
AS_IF([test "x$with_pygtk2" != "xyes" && test "xPYTHON_VERSION_MAJOR" = "x2"],
[echo " => the Python 2 GTK widget wrapper will *NOT* be built"])
AS_IF([test "x$with_pygtk" != "xyes" && test "xPYTHON_VERSION_MAJOR" = "x3"],
[echo " => the Python GTK widget wrapper will *NOT* be built"])
AS_IF([test "x$with_qt" != "xyes"],
[echo " => the Qt widget will *NOT* be built"])
AS_IF([test "x$with_qt" = "xyes" && test "x$enable_static_qt" = "xyes" ],
Expand Down
31 changes: 31 additions & 0 deletions gtk/zbargtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ enum
PROP_VIDEO_DEVICE,
PROP_VIDEO_ENABLED,
PROP_VIDEO_OPENED,
PROP_VIDEO_WIDTH,
PROP_VIDEO_HEIGHT,
};

static guint zbar_gtk_signals[LAST_SIGNAL] = { 0 };
Expand Down Expand Up @@ -703,6 +705,11 @@ static void zbar_gtk_set_property(GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
ZBarGtk *self = ZBAR_GTK(object);
ZBarGtkPrivate *zbar;

if (!self->_private)
return;
zbar = ZBAR_GTK_PRIVATE(self->_private);

switch (prop_id) {
case PROP_VIDEO_DEVICE:
Expand All @@ -711,6 +718,14 @@ static void zbar_gtk_set_property(GObject *object, guint prop_id,
case PROP_VIDEO_ENABLED:
zbar_gtk_set_video_enabled(self, g_value_get_boolean(value));
break;
case PROP_VIDEO_WIDTH:
zbar_gtk_request_video_size(self, g_value_get_int(value),
zbar->video_height);
break;
case PROP_VIDEO_HEIGHT:
zbar_gtk_request_video_size(self, zbar->video_width,
g_value_get_int(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
}
Expand Down Expand Up @@ -739,6 +754,12 @@ static void zbar_gtk_get_property(GObject *object, guint prop_id, GValue *value,
case PROP_VIDEO_OPENED:
g_value_set_boolean(value, zbar->video_opened);
break;
case PROP_VIDEO_WIDTH:
g_value_set_int(value, zbar->video_width);
break;
case PROP_VIDEO_HEIGHT:
g_value_set_int(value, zbar->video_height);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
}
Expand Down Expand Up @@ -874,6 +895,16 @@ static void zbar_gtk_class_init(ZBarGtkClass *klass)
"current opened state of the video device", FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_property(object_class, PROP_VIDEO_OPENED, p);

p = g_param_spec_int("video-width", "Video width",
"controls the width of the video", 0, INT_MAX, DEFAULT_WIDTH,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
g_object_class_install_property(object_class, PROP_VIDEO_WIDTH, p);

p = g_param_spec_int("video-height", "Video height",
"controls the height of the video", 0, INT_MAX, DEFAULT_HEIGHT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
g_object_class_install_property(object_class, PROP_VIDEO_HEIGHT, p);
}

static void zbar_gtk_private_class_init(ZBarGtkPrivateClass *klass)
Expand Down
32 changes: 8 additions & 24 deletions pygtk/Makefile.am.inc
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
pyexec_LTLIBRARIES += pygtk/zbarpygtk.la
pygtk_zbarpygtk_la_CPPFLAGS = \
$(GTK_CFLAGS) $(PYTHON_CFLAGS) $(PYGTK_CFLAGS) $(AM_CPPFLAGS)
pygtk_zbarpygtk_la_LDFLAGS = -shared -module -avoid-version -export-dynamic \
-export-symbols-regex initzbarpygtk $(PYTHON_LDFLAGS)
pygtk_zbarpygtk_la_LIBADD = \
$(PYGTK_LIBS) gtk/libzbargtk.la $(AM_LIBADD)

pygtk_zbarpygtk_la_DEPENDENCIES = gtk/libzbargtk.la
dist_pygtk_zbarpygtk_la_SOURCES = pygtk/zbarpygtkmodule.c
nodist_pygtk_zbarpygtk_la_SOURCES = pygtk/zbarpygtk.c
BUILT_SOURCES += pygtk/zbarpygtk.c pygtk/zbarpygtk.defs
CLEANFILES += pygtk/zbarpygtk.c pygtk/zbarpygtk.defs
EXTRA_DIST += pygtk/zbarpygtk.override

# FIXME ugly hack to fixup new name... now non-standard?
pygtk/zbarpygtk.defs: include/zbar/zbargtk.h
$(PYTHON) $(PYGTK_H2DEF) $< | \
$(SED) -e 's/Z_TYPE_BAR_/ZBAR_TYPE_/' > $@

pygtk/%.c: pygtk/%.defs $(srcdir)/pygtk/zbarpygtk.override
$(PYGTK_CODEGEN) --prefix zbarpygtk \
--register $(PYGTK_DEFS)/gdk-types.defs \
--override $(srcdir)/pygtk/zbarpygtk.override $< > $@
pyexec_LTLIBRARIES += pygtk/zbargtk.la
pygtk_zbargtk_la_CPPFLAGS = \
$(GTK_CFLAGS) $(PYTHON_CFLAGS) $(PYGOBJECT_CFLAGS) $(AM_CPPFLAGS)
pygtk_zbargtk_la_LDFLAGS = \
-avoid-version -module $(PYTHON_LDFLAGS) $(PYGOBJECT_LDLAGS) $(AM_LDFLAGS)
pygtk_zbargtk_la_LIBADD = gtk/libzbargtk.la $(AM_LIBADD)
pygtk_zbargtk_la_DEPENDENCIES = gtk/libzbargtk.la
pygtk_zbargtk_la_SOURCES = pygtk/zbargtkmodule.c
42 changes: 25 additions & 17 deletions pygtk/zbarpygtkmodule.c → pygtk/zbargtkmodule.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*------------------------------------------------------------------------
* Copyright 2008-2009 (c) Jeff Brown <spadix@users.sourceforge.net>
* Copyright 2022 (c) Pier Angelo Vendrame <vogliadifarniente@gmail.com>
*
* This file is part of the ZBar Bar Code Reader.
*
Expand All @@ -21,26 +22,33 @@
* http://sourceforge.net/projects/zbar
*------------------------------------------------------------------------*/

/* avoid "multiple definition" darwin link errors
* for symbols defined in pygobject.h (bug #2052681)
*/
#define NO_IMPORT_PYGOBJECT
#include "Python.h"
#include "pygobject.h"
#include "zbar/zbargtk.h"

#include <pygobject.h>

void zbarpygtk_register_classes(PyObject *);
extern PyMethodDef zbarpygtk_functions[];

DL_EXPORT(void)
initzbarpygtk(void)
static PyObject *create_widget(PyObject *self, PyObject *args)
{
init_pygobject();
GtkWidget *widget = zbar_gtk_new();
if (!widget) {
return PyErr_NoMemory();
}
return pygobject_new(G_OBJECT(widget));
}

PyObject *mod = Py_InitModule("zbarpygtk", zbarpygtk_functions);
PyObject *dict = PyModule_GetDict(mod);
static PyMethodDef ZbargtkMethods[] = {
{ "create_widget", create_widget, METH_NOARGS, "Create a new barcode reader widget instance without any associated video device or image." },
{ NULL, NULL, 0, NULL }
};

zbarpygtk_register_classes(dict);
static struct PyModuleDef zbargtkmozule = {
PyModuleDef_HEAD_INIT, "zbargtk", "", -1, ZbargtkMethods
};

if (PyErr_Occurred())
Py_FatalError("unable to initialise module zbarpygtk");
PyMODINIT_FUNC PyInit_zbargtk(void)
{
PyObject *module = PyModule_Create(&zbargtkmozule);
if (!module)
return NULL;
pygobject_init(-1, -1, -1);
return module;
}
20 changes: 0 additions & 20 deletions pygtk/zbarpygtk.override

This file was deleted.

4 changes: 2 additions & 2 deletions test/Makefile.am.inc
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ check-convert: test/test_convert
echo "convert FAILED"; else echo "convert PASSED."; fi
@rm /tmp/base.I420.zimg 2>/dev/null

if HAVE_PYGTK2
check-pygtk: pygtk/zbarpygtk.la
if HAVE_PYGTK
check-pygtk: pygtk/zbargtk.la
PYTHONPATH=@abs_top_srcdir@/pygtk/.libs/ \
@PYTHON@ @abs_top_srcdir@/test/test_pygtk.py
else
Expand Down