Show More
@@ -1,49 +1,49 | |||||
1 | import sys |
|
1 | import sys | |
2 | import os |
|
2 | import os | |
3 | from IPython.external.qt_for_kernel import QtCore, QtGui |
|
3 | from IPython.external.qt_for_kernel import QtCore, QtGui | |
4 |
|
4 | |||
5 | # If we create a QApplication, keep a reference to it so that it doesn't get |
|
5 | # If we create a QApplication, keep a reference to it so that it doesn't get | |
6 | # garbage collected. |
|
6 | # garbage collected. | |
7 | _appref = None |
|
7 | _appref = None | |
8 | _already_warned = False |
|
8 | _already_warned = False | |
9 |
|
9 | |||
10 | def inputhook(context): |
|
10 | def inputhook(context): | |
11 | global _appref |
|
11 | global _appref | |
12 | app = QtCore.QCoreApplication.instance() |
|
12 | app = QtCore.QCoreApplication.instance() | |
13 | if not app: |
|
13 | if not app: | |
14 | if sys.platform == 'linux': |
|
14 | if sys.platform == 'linux': | |
15 | if not os.environ.get('DISPLAY') \ |
|
15 | if not os.environ.get('DISPLAY') \ | |
16 | and not os.environ.get('WAYLAND_DISPLAY'): |
|
16 | and not os.environ.get('WAYLAND_DISPLAY'): | |
17 | import warnings |
|
17 | import warnings | |
18 | global _already_warned |
|
18 | global _already_warned | |
19 | if not _already_warned: |
|
19 | if not _already_warned: | |
20 | _already_warned = True |
|
20 | _already_warned = True | |
21 | warnings.warn( |
|
21 | warnings.warn( | |
22 | 'The DISPLAY or WAYLAND_DISPLAY enviroment variable is ' |
|
22 | 'The DISPLAY or WAYLAND_DISPLAY environment variable is ' | |
23 | 'not set or empty and Qt5 requires this enviroment ' |
|
23 | 'not set or empty and Qt5 requires this environment ' | |
24 | 'variable. Deactivate Qt5 code.' |
|
24 | 'variable. Deactivate Qt5 code.' | |
25 | ) |
|
25 | ) | |
26 | return |
|
26 | return | |
27 | _appref = app = QtGui.QApplication([" "]) |
|
27 | _appref = app = QtGui.QApplication([" "]) | |
28 | event_loop = QtCore.QEventLoop(app) |
|
28 | event_loop = QtCore.QEventLoop(app) | |
29 |
|
29 | |||
30 | if sys.platform == 'win32': |
|
30 | if sys.platform == 'win32': | |
31 | # The QSocketNotifier method doesn't appear to work on Windows. |
|
31 | # The QSocketNotifier method doesn't appear to work on Windows. | |
32 | # Use polling instead. |
|
32 | # Use polling instead. | |
33 | timer = QtCore.QTimer() |
|
33 | timer = QtCore.QTimer() | |
34 | timer.timeout.connect(event_loop.quit) |
|
34 | timer.timeout.connect(event_loop.quit) | |
35 | while not context.input_is_ready(): |
|
35 | while not context.input_is_ready(): | |
36 | timer.start(50) # 50 ms |
|
36 | timer.start(50) # 50 ms | |
37 | event_loop.exec_() |
|
37 | event_loop.exec_() | |
38 | timer.stop() |
|
38 | timer.stop() | |
39 | else: |
|
39 | else: | |
40 | # On POSIX platforms, we can use a file descriptor to quit the event |
|
40 | # On POSIX platforms, we can use a file descriptor to quit the event | |
41 | # loop when there is input ready to read. |
|
41 | # loop when there is input ready to read. | |
42 | notifier = QtCore.QSocketNotifier(context.fileno(), |
|
42 | notifier = QtCore.QSocketNotifier(context.fileno(), | |
43 | QtCore.QSocketNotifier.Read) |
|
43 | QtCore.QSocketNotifier.Read) | |
44 | # connect the callback we care about before we turn it on |
|
44 | # connect the callback we care about before we turn it on | |
45 | notifier.activated.connect(event_loop.exit) |
|
45 | notifier.activated.connect(event_loop.exit) | |
46 | notifier.setEnabled(True) |
|
46 | notifier.setEnabled(True) | |
47 | # only start the event loop we are not already flipped |
|
47 | # only start the event loop we are not already flipped | |
48 | if not context.input_is_ready(): |
|
48 | if not context.input_is_ready(): | |
49 | event_loop.exec_() |
|
49 | event_loop.exec_() |
@@ -1,46 +1,46 | |||||
1 | """Some simple tests for the plugin while running scripts. |
|
1 | """Some simple tests for the plugin while running scripts. | |
2 | """ |
|
2 | """ | |
3 | # Module imports |
|
3 | # Module imports | |
4 | # Std lib |
|
4 | # Std lib | |
5 | import inspect |
|
5 | import inspect | |
6 |
|
6 | |||
7 | # Our own |
|
7 | # Our own | |
8 |
|
8 | |||
9 | #----------------------------------------------------------------------------- |
|
9 | #----------------------------------------------------------------------------- | |
10 | # Testing functions |
|
10 | # Testing functions | |
11 |
|
11 | |||
12 | def test_trivial(): |
|
12 | def test_trivial(): | |
13 | """A trivial passing test.""" |
|
13 | """A trivial passing test.""" | |
14 | pass |
|
14 | pass | |
15 |
|
15 | |||
16 | def doctest_run(): |
|
16 | def doctest_run(): | |
17 | """Test running a trivial script. |
|
17 | """Test running a trivial script. | |
18 |
|
18 | |||
19 | In [13]: run simplevars.py |
|
19 | In [13]: run simplevars.py | |
20 | x is: 1 |
|
20 | x is: 1 | |
21 | """ |
|
21 | """ | |
22 |
|
22 | |||
23 | def doctest_runvars(): |
|
23 | def doctest_runvars(): | |
24 |
"""Test that variables defined in scripts get loaded correc |
|
24 | """Test that variables defined in scripts get loaded correctly via %run. | |
25 |
|
25 | |||
26 | In [13]: run simplevars.py |
|
26 | In [13]: run simplevars.py | |
27 | x is: 1 |
|
27 | x is: 1 | |
28 |
|
28 | |||
29 | In [14]: x |
|
29 | In [14]: x | |
30 | Out[14]: 1 |
|
30 | Out[14]: 1 | |
31 | """ |
|
31 | """ | |
32 |
|
32 | |||
33 | def doctest_ivars(): |
|
33 | def doctest_ivars(): | |
34 | """Test that variables defined interactively are picked up. |
|
34 | """Test that variables defined interactively are picked up. | |
35 | In [5]: zz=1 |
|
35 | In [5]: zz=1 | |
36 |
|
36 | |||
37 | In [6]: zz |
|
37 | In [6]: zz | |
38 | Out[6]: 1 |
|
38 | Out[6]: 1 | |
39 | """ |
|
39 | """ | |
40 |
|
40 | |||
41 | def doctest_refs(): |
|
41 | def doctest_refs(): | |
42 | """DocTest reference holding issues when running scripts. |
|
42 | """DocTest reference holding issues when running scripts. | |
43 |
|
43 | |||
44 | In [32]: run show_refs.py |
|
44 | In [32]: run show_refs.py | |
45 | c referrers: [<... 'dict'>] |
|
45 | c referrers: [<... 'dict'>] | |
46 | """ |
|
46 | """ |
General Comments 0
You need to be logged in to leave comments.
Login now