Skip to content

Commit 8b25923

Browse files
committed
Fixed addEventListener() not allowing built-in functions as listeners
1 parent 45793e4 commit 8b25923

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
v2.1.1
2+
======
3+
4+
* Fixed addEventListener() not allowing built-in functions as event listeners
5+
6+
17
v2.1.0
28
======
39

RELEASE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.1.0
1+
2.1.1

swingutils/events.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
from __future__ import unicode_literals
2-
from inspect import getargspec
3-
from types import MethodType
42

53
from java.util import EventListener
64

@@ -84,12 +82,6 @@ class so that autodetection will work)
8482
events (with :meth:`~EventListenerWrapper.unlisten`)
8583
8684
"""
87-
# Sanity check
88-
argspec = getargspec(listener)
89-
min_args = 2 if isinstance(listener, MethodType) else 1
90-
if len(argspec.args) < min_args and not argspec.varargs:
91-
raise TypeError('The target callable has too few parameters declared')
92-
9385
addMethodName = 'add%s' % eventInterface.__name__
9486
addMethod = getattr(target, addMethodName)
9587
removeMethodName = 'remove%s' % eventInterface.__name__

tests/test_events.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,17 @@ def selectionListener(event, **kwargs):
4949

5050
lst.setSelectionInterval(0, 0)
5151
assert holder[0] == {'test': 2}
52+
53+
54+
def testBuiltinListener():
55+
model = DefaultListModel()
56+
lst = JList(model)
57+
model.addElement(u'Test')
58+
events = []
59+
addEventListener(lst, ListSelectionListener, 'valueChanged',
60+
events.append)
61+
62+
lst.setSelectionInterval(0, 0)
63+
assert len(events) == 1
64+
assert events[0].firstIndex == 0
65+
assert events[0].lastIndex == 0

0 commit comments

Comments
 (0)