Skip to content

Commit e6b76d7

Browse files
author
Jurica Bradaric
committed
python3 port
1 parent 42c3cee commit e6b76d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+985
-832
lines changed

Makefile.am

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ EXTRA_DIST += $(ATK_DEFS) $(ATK_OVERRIDES)
7070
atk.c: $(ATK_DEFS) $(ATK_OVERRIDES)
7171
atk_la_CFLAGS = $(ATK_CFLAGS)
7272
atk_la_LIBADD = $(ATK_LIBS)
73-
atk_la_LDFLAGS = $(common_ldflags) -export-symbols-regex initatk
73+
atk_la_LDFLAGS = $(common_ldflags) -export-symbols-regex PyInit_atk
7474
atk_la_SOURCES = atkmodule.c
7575
nodist_atk_la_SOURCES = atk.c
7676
if BUILD_ATK
@@ -85,7 +85,7 @@ EXTRA_DIST += $(PANGO_DEFS) pango.override
8585
pango.c: $(PANGO_DEFS) pango.override
8686
pango_la_CFLAGS = $(PANGO_CFLAGS)
8787
pango_la_LIBADD = $(PANGO_LIBS)
88-
pango_la_LDFLAGS = $(common_ldflags) -export-symbols-regex initpango
88+
pango_la_LDFLAGS = $(common_ldflags) -export-symbols-regex PyInit_pango
8989
pango_la_SOURCES = pangomodule.c
9090
nodist_pango_la_SOURCES = pango.c
9191
if BUILD_PANGO
@@ -99,7 +99,7 @@ CLEANFILES += pangocairo.c
9999
EXTRA_DIST += $(PANGOCAIRO_DEFS) pangocairo.override
100100
pangocairo.c: $(PANGOCAIRO_DEFS) pangocairo.override
101101
pangocairo_la_CFLAGS = $(PYCAIRO_CFLAGS) $(PANGOCAIRO_CFLAGS)
102-
pangocairo_la_LDFLAGS = $(common_ldflags) -export-symbols-regex initpangocairo
102+
pangocairo_la_LDFLAGS = $(common_ldflags) -export-symbols-regex PyInit_pangocairo
103103
pangocairo_la_LIBADD = $(PANGOCAIRO_LIBS)
104104
pangocairo_la_SOURCES = pangocairomodule.c
105105
nodist_pangocairo_la_SOURCES = pangocairo.c

atk-types.defs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
(parent "AtkObject")
2727
(c-name "AtkNoOpObject")
2828
(gtype-id "ATK_TYPE_NO_OP_OBJECT")
29+
(heaptype #t)
2930
)
3031

3132
(define-object ObjectFactory

atk.override

+3-3
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ _wrap_atk_editable_text_insert_text(PyGObject *self, PyObject *args,
217217

218218
atk_editable_text_insert_text(ATK_EDITABLE_TEXT(self->obj),
219219
string, length, &position);
220-
return PyInt_FromLong(position);
220+
return PyLong_FromLong(position);
221221
}
222222
%%
223223
override atk_image_get_image_size noargs
@@ -357,7 +357,7 @@ _wrap_atk_table_get_selected_columns(PyGObject *self)
357357
ret = atk_table_get_selected_columns(ATK_TABLE(self->obj), &selected);
358358
py_selected = PyTuple_New(ret);
359359
for (i = 0; i < ret; i++) {
360-
PyTuple_SetItem(py_selected, i, PyInt_FromLong(selected[i]));
360+
PyTuple_SetItem(py_selected, i, PyLong_FromLong(selected[i]));
361361
}
362362

363363
g_free(selected);
@@ -374,7 +374,7 @@ _wrap_atk_table_get_selected_rows(PyGObject *self)
374374
ret = atk_table_get_selected_rows(ATK_TABLE(self->obj), &selected);
375375
py_selected = PyTuple_New(ret);
376376
for (i = 0; i < ret; i++) {
377-
PyTuple_SetItem(py_selected, i, PyInt_FromLong(selected[i]));
377+
PyTuple_SetItem(py_selected, i, PyLong_FromLong(selected[i]));
378378
}
379379

380380
g_free(selected);

atkmodule.c

+14-4
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,26 @@ void _pyatk_register_boxed_types(void);
3333

3434
extern PyMethodDef pyatk_functions[];
3535

36-
DL_EXPORT(void)
37-
initatk(void)
36+
static struct PyModuleDef atkmodule_def = {
37+
PyModuleDef_HEAD_INIT,
38+
"atk",
39+
NULL,
40+
-1,
41+
pyatk_functions
42+
};
43+
44+
PyMODINIT_FUNC
45+
PyInit_atk(void)
3846
{
3947
PyObject *m, *d;
4048

41-
init_pygobject ();
49+
if (!pygobject_init(-1, -1, -1))
50+
return NULL;
4251

43-
m = Py_InitModule ("atk", pyatk_functions);
52+
m = PyModule_Create(&atkmodule_def);
4453
d = PyModule_GetDict (m);
4554
_pyatk_register_boxed_types();
4655
pyatk_register_classes (d);
4756
pyatk_add_constants(m, "ATK_");
57+
return m;
4858
}

atkrectangle.override

+9-9
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ _wrap_atk_rectangle_getitem(PyGBoxed *self, Py_ssize_t pos)
105105
}
106106
rect = pyg_boxed_get(self, AtkRectangle);
107107
switch (pos) {
108-
case 0: return PyInt_FromLong(rect->x);
109-
case 1: return PyInt_FromLong(rect->y);
110-
case 2: return PyInt_FromLong(rect->width);
111-
case 3: return PyInt_FromLong(rect->height);
108+
case 0: return PyLong_FromLong(rect->x);
109+
case 1: return PyLong_FromLong(rect->y);
110+
case 2: return PyLong_FromLong(rect->width);
111+
case 3: return PyLong_FromLong(rect->height);
112112
default:
113113
g_assert_not_reached();
114114
return NULL;
@@ -126,7 +126,7 @@ _wrap_atk_rectangle_setitem(PyGBoxed *self, Py_ssize_t pos, PyObject *value)
126126
return -1;
127127
}
128128
rect = pyg_boxed_get(self, AtkRectangle);
129-
val = PyInt_AsLong(value);
129+
val = PyLong_AsLong(value);
130130
if (PyErr_Occurred())
131131
return -1;
132132
switch(pos) {
@@ -158,7 +158,7 @@ _wrap_atk_rectangle__set_x(PyGBoxed *self, PyObject *value, void *closure)
158158
{
159159
gint val;
160160

161-
val = PyInt_AsLong(value);
161+
val = PyLong_AsLong(value);
162162
if (PyErr_Occurred())
163163
return -1;
164164
pyg_boxed_get(self, AtkRectangle)->x = val;
@@ -171,7 +171,7 @@ _wrap_atk_rectangle__set_y(PyGBoxed *self, PyObject *value, void *closure)
171171
{
172172
gint val;
173173

174-
val = PyInt_AsLong(value);
174+
val = PyLong_AsLong(value);
175175
if (PyErr_Occurred())
176176
return -1;
177177
pyg_boxed_get(self, AtkRectangle)->y = val;
@@ -184,7 +184,7 @@ _wrap_atk_rectangle__set_width(PyGBoxed *self, PyObject *value, void *closure)
184184
{
185185
gint val;
186186

187-
val = PyInt_AsLong(value);
187+
val = PyLong_AsLong(value);
188188
if (PyErr_Occurred())
189189
return -1;
190190
pyg_boxed_get(self, AtkRectangle)->width = val;
@@ -197,7 +197,7 @@ _wrap_atk_rectangle__set_height(PyGBoxed *self, PyObject *value, void *closure)
197197
{
198198
gint val;
199199

200-
val = PyInt_AsLong(value);
200+
val = PyLong_AsLong(value);
201201
if (PyErr_Occurred())
202202
return -1;
203203
pyg_boxed_get(self, AtkRectangle)->height = val;

configure.ac

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ m4_define(pygobject_required_version, 2.21.3)
2020
AC_INIT(pygtk, pygtk_version,
2121
[http://bugzilla.gnome.org/enter_bug.cgi?product=pygtk])
2222
AC_SUBST(ACLOCAL_AMFLAGS, "-I m4 -I .")
23+
AC_CONFIG_MACRO_DIR([m4])
2324

2425
AC_DEFINE(PYGTK_MAJOR_VERSION, pygtk_major_version, [PyGtk major version])
2526
AC_SUBST(PYGTK_MAJOR_VERSION, pygtk_major_version)
@@ -80,7 +81,7 @@ AM_PATH_PYTHON(2.3.5)
8081
AM_CHECK_PYTHON_HEADERS(,[AC_MSG_ERROR(could not find Python headers)])
8182

8283
AC_MSG_CHECKING([for PySignal_SetWakeupFd in Python.h])
83-
py_prefix=`$PYTHON -c "import sys; print sys.prefix"`
84+
py_prefix=`$PYTHON -c "import sys; print(sys.prefix)"`
8485
old_CPPFLAGS=$CPPFLAGS
8586
CPPFLAGS="-Wall -Werror $PYTHON_INCLUDES"
8687
AC_TRY_COMPILE([#include <Python.h>],
@@ -453,7 +454,7 @@ AC_ARG_ENABLE(numpy,
453454

454455
if test "x$enable_numpy" != xno; then
455456
save_CPPFLAGS="$CPPFLAGS"
456-
numpy_INCLUDES=`$PYTHON -c "import numpy; print numpy.get_include()" 2> /dev/null`
457+
numpy_INCLUDES=`$PYTHON -c "import numpy; print(numpy.get_include())" 2> /dev/null`
457458
if test "x$numpy_INCLUDES" = "x"; then
458459
AC_MSG_WARN([Could not find a valid numpy installation, disabling.])
459460
enable_numpy=no

examples/glade/autoconnect.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def __init__(self):
1313
xml.signal_autoconnect(self)
1414

1515
def on_button1_clicked(self, button):
16-
print 'foo!'
16+
print('foo!')
1717

1818
test = SimpleTest()
1919
gtk.main()

examples/gobject/editable-interface.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(self, text):
1111
self.set_text(text)
1212

1313
def do_do_delete_text(self, start_pos, end_pos):
14-
print "do_do_delete_text", start_pos, end_pos
14+
print("do_do_delete_text", start_pos, end_pos)
1515
gtk.Entry.do_do_delete_text(self, start_pos, end_pos)
1616

1717
gobject.type_register(EditableLabel)

examples/gobject/properties.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,32 @@ def __init__(self):
1414
self.__gobject_init__()
1515
self.foo = 'bar'
1616
def do_set_property(self, pspec, value):
17-
print ' do_set_property called for %s=%r' % (pspec.name, value)
17+
print(' do_set_property called for %s=%r' % (pspec.name, value))
1818
if pspec.name == 'foo':
1919
self.foo = value
2020
else:
21-
raise AttributeError, 'unknown property %s' % pspec.name
21+
raise AttributeError('unknown property %s' % pspec.name)
2222
def do_get_property(self, pspec):
23-
print ' do_get_property called for %s' % pspec.name
23+
print(' do_get_property called for %s' % pspec.name)
2424
if pspec.name == 'foo':
2525
return self.foo
2626
elif pspec.name == 'boolprop':
2727
return 1
2828
else:
29-
raise AttributeError, 'unknown property %s' % pspec.name
29+
raise AttributeError('unknown property %s' % pspec.name)
3030
gobject.type_register(MyObject)
3131

32-
print "MyObject properties: ", gobject.list_properties(MyObject)
32+
print("MyObject properties: ", gobject.list_properties(MyObject))
3333
obj = MyObject()
3434

3535
val = obj.get_property('foo')
36-
print "obj.get_property('foo') == ", val
36+
print("obj.get_property('foo') == ", val)
3737

3838
obj.set_property('foo', 'spam')
39-
print "obj.set_property('foo', 'spam')"
39+
print("obj.set_property('foo', 'spam')")
4040

4141
val = obj.get_property('foo')
42-
print "obj.get_property('foo') == ", val
42+
print("obj.get_property('foo') == ", val)
4343

4444
val = obj.get_property('boolprop')
45-
print "obj.get_property('boolprop') == ", val
45+
print("obj.get_property('boolprop') == ", val)

examples/gobject/signal.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ class C(gobject.GObject):
1010
def __init__(self):
1111
self.__gobject_init__() # default constructor using our new GType
1212
def do_my_signal(self, arg):
13-
print "C: class closure for `my_signal' called with argument", arg
13+
print("C: class closure for `my_signal' called with argument", arg)
1414

1515
class D(C):
1616
def do_my_signal(self, arg):
17-
print "D: class closure for `my_signal' called. Chaining up to C"
17+
print("D: class closure for `my_signal' called. Chaining up to C")
1818
C.do_my_signal(self, arg)
1919

2020
def my_signal_handler(object, arg, *extra):
21-
print "handler for `my_signal' called with argument", arg, \
22-
"and extra args", extra
21+
print("handler for `my_signal' called with argument", arg, \
22+
"and extra args", extra)
2323

2424
inst = C()
2525
inst2 = D()

examples/gtk/bin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ def do_forall(self, internal, callback, data):
2929
label = gtk.Label()
3030
c = Bin()
3131
c.add(label)
32-
print c.get_children()
32+
print(c.get_children())
3333
c.remove(label)

examples/gtk/customtreemodel.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(self, *values):
2222

2323
# This is only needed to make the model gc-safe, since
2424
# leak_references is False.
25-
self.__iters = range(0, len(values))
25+
self.__iters = list(range(0, len(values)))
2626

2727
def on_get_n_columns(self):
2828
return 0

examples/gtk/filechooser.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
response = dialog.run()
3131
if response == gtk.RESPONSE_OK:
32-
print dialog.get_filename(), 'selected'
32+
print(dialog.get_filename(), 'selected')
3333
elif response == gtk.RESPONSE_CANCEL:
34-
print 'Closed, no files selected'
34+
print('Closed, no files selected')
3535
dialog.destroy()

examples/gtk/widget.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from gtk import gdk
99

1010
if gtk.pygtk_version < (2, 8):
11-
print "PyGtk 2.8 or later required for this example"
11+
print("PyGtk 2.8 or later required for this example")
1212
raise SystemExit
1313

1414
try:

examples/ide/browse.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def expand_row_cb(self, treeview, riter, path):
6262
return True
6363
citer = model.iter_children(riter)
6464
model.remove(citer)
65-
keylist = dict.keys()
65+
keylist = list(dict.keys())
6666
keylist.sort()
6767
for key in keylist:
6868
obj = dict[key]

examples/ide/gtkcons.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def remQuotStr(s):
6464

6565
def bracketsBalanced(s):
6666
'''Returns true iff the brackets in s are balanced'''
67-
s = filter(lambda x: x in '()[]{}', s)
67+
s = [x for x in s if x in '()[]{}']
6868
stack = []
6969
brackets = {'(':')', '[':']', '{':'}'}
7070
while len(s) != 0:
@@ -106,8 +106,8 @@ def writelines(self, l):
106106
self.__b.insert_with_tags(iter, s, self.__font)
107107
self.__w.scroll_to_mark(self.__ins, 0.0)
108108
self.__w.queue_draw()
109-
def seek(self, a): raise IOError, (29, 'Illegal seek')
110-
def tell(self): raise IOError, (29, 'Illegal seek')
109+
def seek(self, a): raise IOError(29, 'Illegal seek')
110+
def tell(self): raise IOError(29, 'Illegal seek')
111111
truncate = tell
112112

113113
class Console(gtk.VBox):
@@ -288,9 +288,9 @@ def run(self, cmd):
288288
try:
289289
r = eval(cmd, self.namespace, self.namespace)
290290
if r is not None:
291-
print `r`
291+
print(repr(r))
292292
except SyntaxError:
293-
exec cmd in self.namespace
293+
exec(cmd, self.namespace)
294294
except:
295295
if hasattr(sys, 'last_type') and \
296296
sys.last_type == SystemExit:

0 commit comments

Comments
 (0)