Exemple #1
0
    def test_reset_with_destroy_qt(self):
        # Characterization test:
        # UI.reset(destroy=True) destroys all ui children of the top control

        from pyface import qt

        foo = FooDialog()
        with create_ui(foo) as ui:

            # decorate children's `deleteLater` function to check that it is
            # called on `reset`. check only with the editor parts (only widgets
            # are scheduled.
            # See traitsui.qt4.toolkit.GUIToolkit.destroy_children)
            for c in ui.control.children():
                c.deleteLater = count_calls(c.deleteLater)

            ui.reset(destroy=True)

            # the top control is still there
            self.assertIsNotNone(ui.control)

            # but its children are scheduled for removal
            for c in ui.control.children():
                if isinstance(c, qt.QtGui.QWidget):
                    self.assertEqual(c.deleteLater._n_calls, 1)
    def test_destroy_after_ok_wx(self):
        # Behavior: after pressing 'OK' in a dialog, the method UI.finish is
        # called and the view control and its children are destroyed

        import wx

        foo = FooDialog()
        with create_ui(foo) as ui:

            # keep reference to the control to check that it was destroyed
            control = ui.control

            # decorate control's `Destroy` function to check that it is called
            control.Destroy = count_calls(control.Destroy)

            # press the OK button and close the dialog
            okbutton = ui.control.FindWindowByName("button", ui.control)
            self.assertEqual(okbutton.Label, 'OK')

            click_event = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED,
                                          okbutton.GetId())
            okbutton.ProcessEvent(click_event)

            self.assertIsNone(ui.control)
            self.assertEqual(control.Destroy._n_calls, 1)
Exemple #3
0
    def test_destroy_after_ok_wx(self):
        # Behavior: after pressing 'OK' in a dialog, the method UI.finish is
        # called and the view control and its children are destroyed

        foo = FooDialog()
        tester = UITester()
        with tester.create_ui(foo) as ui:
            # keep reference to the control to check that it was destroyed
            control = ui.control

            # decorate control's `Destroy` function to check that it is called
            control.Destroy = count_calls(control.Destroy)

            # press the OK button and close the dialog
            ok_button = tester.find_by_id(ui, "OK")
            self.assertEqual(ok_button.inspect(DisplayedText()), "OK")
            self.assertTrue(ok_button.inspect(IsEnabled()))
            ok_button.perform(MouseClick())

            self.assertIsNone(ui.control)
            self.assertEqual(control.Destroy._n_calls, 1)
    def test_destroy_after_ok_qt(self):
        # Behavior: after pressing 'OK' in a dialog, the method UI.finish is
        # called and the view control and its children are destroyed

        from pyface import qt

        foo = FooDialog()
        with create_ui(foo) as ui:

            # keep reference to the control to check that it was deleted
            control = ui.control

            # decorate control's `deleteLater` function to check that it is
            # called
            control.deleteLater = count_calls(control.deleteLater)

            # press the OK button and close the dialog
            okb = control.findChild(qt.QtGui.QPushButton)
            okb.click()

            self.assertIsNone(ui.control)
            self.assertEqual(control.deleteLater._n_calls, 1)