Skip to content

Commit

Permalink
Merge pull request #40 from enthought/fix/qt-slots-with-argument
Browse files Browse the repository at this point in the history
BUG: Work around emitting events with arguments
  • Loading branch information
Pietro Berkes committed Feb 15, 2016
2 parents 36adfb5 + c839814 commit 315b23d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 16 deletions.
9 changes: 7 additions & 2 deletions qt_binder/binder.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,13 @@ def set(self, object, name, value):
d[name] = value
return
args = self._process_args(value)
# Use the QMetaMethod to invoke the signal for PyQt4 compatibility.
self.meta_method.invoke(qobj, *args)
if len(args) == 0:
# Use the QMetaMethod to invoke the signal for PyQt4 compatibility.
self.meta_method.invoke(qobj)
else:
# In both PyQt4 and PySide, QMetaMethod.invoke() does not
# automatically convert the arguments, so emit it directly.
getattr(qobj, name).emit(*args)


class Rename(object):
Expand Down
54 changes: 40 additions & 14 deletions qt_binder/tests/test_raw_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,26 @@

import unittest

from pyface.ui.qt4.util.gui_test_assistant import GuiTestAssistant
from traits.api import pop_exception_handler, push_exception_handler

from ..qt import QtCore, QtGui
from ..raw_widgets import BasicGridLayout, GroupBox, HBoxLayout, Label, \
Object, VBoxLayout, Widget, binder_registry
LineEdit, Object, VBoxLayout, Widget, binder_registry


class TestBoxLayout(unittest.TestCase):
class _BaseTestWithGui(GuiTestAssistant):

def setUp(self):
# Start up a QApplication if needed.
self.app = QtGui.QApplication.instance()
if self.app is None:
self.app = QtGui.QApplication([])
GuiTestAssistant.setUp(self)
push_exception_handler(reraise_exceptions=True)

def tearDown(self):
pop_exception_handler()
GuiTestAssistant.tearDown(self)


class TestBoxLayout(_BaseTestWithGui, unittest.TestCase):

def test_configure_nested_layout(self):
# Regression test for a bug that prevented layouts from being nested.
Expand Down Expand Up @@ -66,20 +74,38 @@ def test_lookup_grid_layout(self):
BasicGridLayout)


class TestGroupBox(unittest.TestCase):
class TestGroupBox(_BaseTestWithGui, unittest.TestCase):

def test_group_box_can_be_childless(self):
box = GroupBox()
box.construct()
box.configure()
self.assertIsInstance(box.qobj, QtGui.QGroupBox)
try:
box.configure()
self.assertIsInstance(box.qobj, QtGui.QGroupBox)
finally:
box.dispose()

def test_groupbox_alignment_works(self):
# PySide has a bug. Ensure that we work around it.
box = GroupBox()
box.construct()
box.configure()
# Test getting.
box.alignment
# Test setting.
box.alignment = QtCore.Qt.AlignLeft
try:
box.configure()
# Test getting.
box.alignment
# Test setting.
box.alignment = QtCore.Qt.AlignLeft
finally:
box.dispose()


class TestQLineEdit(_BaseTestWithGui, unittest.TestCase):

def test_slots_with_arguments_work(self):
le = LineEdit()
le.construct()
try:
le.configure()
le.textEdited = u'text'
finally:
le.dispose()

0 comments on commit 315b23d

Please sign in to comment.