Skip to content

Commit 67f4243

Browse files
committed
Move run_root_event_loop function to __init__.py script
Let use it for pythonization of TCanvas and TBrowser
1 parent 8905714 commit 67f4243

File tree

3 files changed

+62
-122
lines changed

3 files changed

+62
-122
lines changed

bindings/pyroot/pythonizations/python/ROOT/_pythonization/__init__.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,4 +337,64 @@ def _register_pythonizations():
337337
importlib.import_module(__name__ + "." + module_name)
338338

339339

340+
def _wait_press_windows():
341+
from ROOT import gSystem
342+
import msvcrt
343+
import time
344+
345+
while not gSystem.ProcessEvents():
346+
if msvcrt.kbhit():
347+
k = msvcrt.getch()
348+
if k[0] == 32:
349+
break
350+
else:
351+
time.sleep(0.01)
352+
353+
354+
def _wait_press_posix():
355+
from ROOT import gSystem
356+
import sys
357+
import select
358+
import tty
359+
import termios
360+
import time
361+
362+
old_settings = termios.tcgetattr(sys.stdin)
363+
364+
tty.setcbreak(sys.stdin.fileno())
365+
366+
try:
367+
368+
while not gSystem.ProcessEvents():
369+
c = ''
370+
if select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []):
371+
c = sys.stdin.read(1)
372+
if (c == '\x20'):
373+
break
374+
time.sleep(0.01)
375+
376+
finally:
377+
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
378+
340379
# \endcond
380+
381+
def run_root_event_loop():
382+
from ROOT import gROOT
383+
import os
384+
import sys
385+
386+
# no special handling in batch mode
387+
if gROOT.IsBatch():
388+
return
389+
390+
# no special handling in case of notebooks
391+
if 'IPython' in sys.modules and sys.modules['IPython'].version_info[0] >= 5:
392+
return
393+
394+
print("Press <space> key to continue")
395+
396+
if os.name == 'nt':
397+
_wait_press_windows()
398+
else:
399+
_wait_press_posix()
400+

bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tbrowser.py

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -28,67 +28,7 @@
2828
\endpythondoc
2929
'''
3030

31-
from . import pythonization
32-
33-
def wait_press_windows():
34-
from ROOT import gSystem
35-
import msvcrt
36-
import time
37-
38-
while not gSystem.ProcessEvents():
39-
if msvcrt.kbhit():
40-
k = msvcrt.getch()
41-
if k[0] == 32:
42-
break
43-
else:
44-
time.sleep(0.01)
45-
46-
47-
def wait_press_posix():
48-
from ROOT import gSystem
49-
import sys
50-
import select
51-
import tty
52-
import termios
53-
import time
54-
55-
old_settings = termios.tcgetattr(sys.stdin)
56-
57-
tty.setcbreak(sys.stdin.fileno())
58-
59-
try:
60-
61-
while not gSystem.ProcessEvents():
62-
c = ''
63-
if select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []):
64-
c = sys.stdin.read(1)
65-
if (c == '\x20'):
66-
break
67-
time.sleep(0.01)
68-
69-
finally:
70-
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
71-
72-
def run_root_event_loop():
73-
from ROOT import gROOT
74-
import os
75-
import sys
76-
77-
# no special handling in batch mode
78-
if gROOT.IsBatch():
79-
return
80-
81-
# no special handling in case of notebooks
82-
if 'IPython' in sys.modules and sys.modules['IPython'].version_info[0] >= 5:
83-
return
84-
85-
print("Press <space> key to continue")
86-
87-
if os.name == 'nt':
88-
wait_press_windows()
89-
else:
90-
wait_press_posix()
91-
31+
from . import pythonization, run_root_event_loop
9232

9333

9434
def _TBrowser_Draw(self, option: str = "", block: bool = False):

bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tcanvas.py

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -32,67 +32,7 @@
3232
\endpythondoc
3333
'''
3434

35-
from . import pythonization
36-
37-
def wait_press_windows():
38-
from ROOT import gSystem
39-
import msvcrt
40-
import time
41-
42-
while not gSystem.ProcessEvents():
43-
if msvcrt.kbhit():
44-
k = msvcrt.getch()
45-
if k[0] == 32:
46-
break
47-
else:
48-
time.sleep(0.01)
49-
50-
51-
def wait_press_posix():
52-
from ROOT import gSystem
53-
import sys
54-
import select
55-
import tty
56-
import termios
57-
import time
58-
59-
old_settings = termios.tcgetattr(sys.stdin)
60-
61-
tty.setcbreak(sys.stdin.fileno())
62-
63-
try:
64-
65-
while not gSystem.ProcessEvents():
66-
c = ''
67-
if select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []):
68-
c = sys.stdin.read(1)
69-
if (c == '\x20'):
70-
break
71-
time.sleep(0.01)
72-
73-
finally:
74-
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
75-
76-
def run_root_event_loop():
77-
from ROOT import gROOT
78-
import os
79-
import sys
80-
81-
# no special handling in batch mode
82-
if gROOT.IsBatch():
83-
return
84-
85-
# no special handling in case of notebooks
86-
if 'IPython' in sys.modules and sys.modules['IPython'].version_info[0] >= 5:
87-
return
88-
89-
print("Press <space> key to continue")
90-
91-
if os.name == 'nt':
92-
wait_press_windows()
93-
else:
94-
wait_press_posix()
95-
35+
from . import pythonization, run_root_event_loop
9636

9737
def _TCanvas_Update(self, block = False):
9838
"""

0 commit comments

Comments
 (0)