def test_selection_listener_disconnected():
    """ Check that selection listeners get correctly disconnected """
    from pyface.api import GUI
    from pyface.qt.QtGui import QApplication, QItemSelectionModel
    from pyface.ui.qt4.util.event_loop_helper import EventLoopHelper
    from pyface.ui.qt4.util.testing import event_loop

    obj = ListStrEditorWithSelectedIndex(values=['value1', 'value2'])

    with store_exceptions_on_all_threads():
        qt_app = QApplication.instance()
        if qt_app is None:
            qt_app = QApplication([])
        helper = EventLoopHelper(gui=GUI(), qt_app=qt_app)

        # open the UI and run until the dialog is closed
        ui = obj.edit_traits(view=single_select_item_view)
        with helper.delete_widget(ui.control):
            press_ok_button(ui)

        # now run again and change the selection
        ui = obj.edit_traits(view=single_select_item_view)
        with event_loop():
            editor = ui.get_editors('values')[0]

            list_view = editor.list_view
            mi = editor.model.index(1)
            list_view.selectionModel().select(
                mi, QItemSelectionModel.ClearAndSelect)

    obj.selected = 'value2'
def test_selection_listener_disconnected():
    """ Check that selection listeners get correctly disconnected """
    from pyface.api import GUI
    from pyface.qt.QtGui import QApplication, QItemSelectionModel
    from pyface.ui.qt4.util.event_loop_helper import EventLoopHelper
    from pyface.ui.qt4.util.testing import event_loop

    obj = ListStrEditorWithSelectedIndex(values=['value1', 'value2'])

    with store_exceptions_on_all_threads():
        qt_app = QApplication.instance()
        if qt_app is None:
            qt_app = QApplication([])
        helper = EventLoopHelper(gui=GUI(), qt_app=qt_app)

        # open the UI and run until the dialog is closed
        ui = obj.edit_traits(view=single_select_item_view)
        with helper.delete_widget(ui.control):
            press_ok_button(ui)

        # now run again and change the selection
        ui = obj.edit_traits(view=single_select_item_view)
        with event_loop():
            editor = ui.get_editors('values')[0]

            list_view = editor.list_view
            mi = editor.model.index(1)
            list_view.selectionModel().select(mi, QItemSelectionModel.ClearAndSelect)

    obj.selected = 'value2'
Ejemplo n.º 3
0
    def setUp(self):
        qt_app = QApplication.instance()
        if qt_app is None:
            qt_app = QApplication([])
        self.qt_app = qt_app
        self.gui = GUI()
        self.event_loop_helper = EventLoopHelper(qt_app=self.qt_app,
                                                 gui=self.gui)
        try:
            import traitsui.api
        except ImportError:
            self.traitsui_raise_patch = None
        else:
            self.traitsui_raise_patch = mock.patch(
                "traitsui.qt4.ui_base._StickyDialog.raise_")
            self.traitsui_raise_patch.start()

        def new_activate(self):
            self.control.activateWindow()

        self.pyface_raise_patch = mock.patch(
            "pyface.ui.qt4.window.Window.activate",
            new_callable=lambda: new_activate,
        )
        self.pyface_raise_patch.start()
Ejemplo n.º 4
0
    def test_selection_listener_disconnected(self):
        """Check that selection listeners get correctly disconnected"""
        from pyface.qt.QtGui import QApplication, QItemSelectionModel
        from pyface.ui.qt4.util.testing import event_loop

        obj = ListStrEditorWithSelectedIndex(values=["value1", "value2"])

        with reraise_exceptions():
            qt_app = QApplication.instance()
            if qt_app is None:
                qt_app = QApplication([])

            # open the UI and run until the dialog is closed
            with create_ui(obj, dict(view=single_select_item_view)) as ui:
                pass

            # now run again and change the selection
            with create_ui(
                obj, dict(view=single_select_item_view)
            ) as ui, event_loop():
                editor = ui.get_editors("values")[0]

                list_view = editor.list_view
                mi = editor.model.index(1)
                list_view.selectionModel().select(
                    mi, QItemSelectionModel.SelectionFlag.ClearAndSelect
                )

        obj.selected = "value2"
Ejemplo n.º 5
0
    def setUp(self):
        qt_app = QApplication.instance()
        if qt_app is None:
            qt_app = QApplication([])
        self.qt_app = qt_app
        self.gui = GUI()
        self.event_loop_helper = EventLoopHelper(
            qt_app=self.qt_app,
            gui=self.gui
        )
        try:
            import traitsui.api
        except ImportError:
            self.traitsui_raise_patch = None
        else:
            self.traitsui_raise_patch = mock.patch(
                'traitsui.qt4.ui_base._StickyDialog.raise_')
            self.traitsui_raise_patch.start()

        def new_activate(self):
            self.control.activateWindow()

        self.pyface_raise_patch = mock.patch(
            'pyface.ui.qt4.window.Window.activate',
            new_callable=lambda: new_activate)
        self.pyface_raise_patch.start()
Ejemplo n.º 6
0
def start():
    # app = QApplication(sys.argv)
    # Don't create a new QApplication, it would unhook the Events
    # set by Traits on the existing QApplication. Simply use the
    # '.instance()' method to retrieve the existing one.
    app = QApplication.instance()
    window = MainWindow()
    sys.exit(app.exec_())
Ejemplo n.º 7
0
    def init(self):
        """
        Prepare the event loop for use.
        """
        qt_app = QApplication.instance()
        if qt_app is None:
            qt_app = QApplication([])
        self.qt_app = qt_app

        self._attribute_setter = AttributeSetter()
        self._attribute_setter.setattr.connect(
            self._attribute_setter._on_setattr, Qt.QueuedConnection)
Ejemplo n.º 8
0
    def setUp(self):
        from pyface.qt.QtGui import QApplication
        from pyface.ui.qt4.util.event_loop_helper import EventLoopHelper

        qt_app = QApplication.instance()
        if qt_app is None:
            qt_app = QApplication([])
        self.qt_app = qt_app

        if NativeScrollBar is None:
            raise unittest.SkipTest("Qt4 NativeScrollbar not available.")
        self.gui = GUI()
        self.event_loop_helper = EventLoopHelper(gui=self.gui, qt_app=qt_app)
        self.container = Container(position=[0, 0], bounds=[600, 600])
        self.window = Window(None, size=(600, 600), component=self.container)
Ejemplo n.º 9
0
    def setUp(self):
        from pyface.qt.QtGui import QApplication
        from pyface.ui.qt4.util.event_loop_helper import EventLoopHelper

        qt_app = QApplication.instance()
        if qt_app is None:
            qt_app = QApplication([])
        self.qt_app = qt_app

        if NativeScrollBar is None:
            raise unittest.SkipTest("Qt4 NativeScrollbar not available.")
        self.gui = GUI()
        self.event_loop_helper = EventLoopHelper(gui=self.gui, qt_app=qt_app)
        self.container = Container(position=[0, 0], bounds=[600, 600])
        self.window = Window(None, size=(600, 600), component=self.container)
Ejemplo n.º 10
0
    def setUp(self):
        qt_app = QApplication.instance()
        if qt_app is None:
            qt_app = QApplication([])
        self.qt_app = qt_app
        self.gui = GUI()
        self.event_loop_helper = EventLoopHelper(qt_app=self.qt_app,
                                                 gui=self.gui)
        self.traitsui_raise_patch = mock.patch(
            'traitsui.qt4.ui_base._StickyDialog.raise_')
        self.traitsui_raise_patch.start()

        def new_activate(self):
            self.control.activateWindow()

        self.pyface_raise_patch = mock.patch(
            'pyface.ui.qt4.window.Window.activate',
            new_callable=lambda: new_activate)
        self.pyface_raise_patch.start()
Ejemplo n.º 11
0
#
# Classes
#


class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()

        self.mayavi_widget = MayaviQWidget()

        # Layouting

        main_layout = QGridLayout()
        main_layout.addWidget(self.mayavi_widget, 1, 1)

        self.setCentralWidget(QWidget())
        self.centralWidget().setLayout(main_layout)


if __name__ == "__main__":
    # Don't create a new QApplication, it would unhook the Events
    # set by Traits on the existing QApplication. Simply use the
    # '.instance()' method to retrieve the existing one.
    app = QApplication.instance()
    main_window = MainWindow()
    main_window.show()

    # Start the main event loop.
    sys.exit(app.exec_())