Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bindings/pyroot/pythonizations/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ set(py_sources
ROOT/_pythonization/_rvec.py
ROOT/_pythonization/_stl_vector.py
ROOT/_pythonization/_tarray.py
ROOT/_pythonization/_tbrowser.py
ROOT/_pythonization/_tclass.py
ROOT/_pythonization/_tclonesarray.py
ROOT/_pythonization/_tcollection.py
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,66 @@
importlib.import_module(__name__ + "." + module_name)


def _wait_press_windows():
from ROOT import gSystem
import msvcrt
import time

Check failure on line 343 in bindings/pyroot/pythonizations/python/ROOT/_pythonization/__init__.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

bindings/pyroot/pythonizations/python/ROOT/_pythonization/__init__.py:341:4: I001 Import block is un-sorted or un-formatted

while not gSystem.ProcessEvents():
if msvcrt.kbhit():
k = msvcrt.getch()
if k[0] == 32:
break
else:
time.sleep(0.01)


def _wait_press_posix():
from ROOT import gSystem
import sys
import select
import tty
import termios
import time

Check failure on line 360 in bindings/pyroot/pythonizations/python/ROOT/_pythonization/__init__.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

bindings/pyroot/pythonizations/python/ROOT/_pythonization/__init__.py:355:4: I001 Import block is un-sorted or un-formatted

old_settings = termios.tcgetattr(sys.stdin)

tty.setcbreak(sys.stdin.fileno())

try:

while not gSystem.ProcessEvents():
c = ''
if select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []):
c = sys.stdin.read(1)
if (c == '\x20'):
break
time.sleep(0.01)

finally:
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)


def _run_root_event_loop():
from ROOT import gROOT
import os
import sys

Check failure on line 383 in bindings/pyroot/pythonizations/python/ROOT/_pythonization/__init__.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

bindings/pyroot/pythonizations/python/ROOT/_pythonization/__init__.py:381:4: I001 Import block is un-sorted or un-formatted

# no special handling in batch mode
if gROOT.IsBatch():
return

# no special handling in case of notebooks
if 'IPython' in sys.modules and sys.modules['IPython'].version_info[0] >= 5:
return

print("Press <space> key to continue")

if os.name == 'nt':
_wait_press_windows()
else:
_wait_press_posix()


# \endcond

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Author: Sergey Linev GSI 11/2025

################################################################################
# Copyright (C) 1995-2025, Rene Brun and Fons Rademakers. #
# All rights reserved. #
# #
# For the licensing terms see $ROOTSYS/LICENSE. #
# For the list of contributors see $ROOTSYS/README/CREDITS. #
################################################################################

r'''
\pythondoc TBrowser

Functionality of constructor and Draw() methods were extended to support interactive
work in the python scripts. If extra block parameter is True, script execution
will be suspended until <space> key pressed by user. Simple example:

\code{.py}
\endcode
import ROOT

# block until space is pressed
br = ROOT.TBrowser(block = True)

# continue work to load new files

# block here again until space is pressed
br.Draw(block = True)

# continues after <space> is pressed
\endpythondoc
'''

from . import pythonization, _run_root_event_loop

Check failure on line 34 in bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tbrowser.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tbrowser.py:34:1: I001 Import block is un-sorted or un-formatted


def _TBrowser_constructor(self, *args, block: bool = False):

self._original_constructor(*args)

if block:
_run_root_event_loop()


def _TBrowser_Draw(self, option: str = "", block: bool = False):
"""
Draw the browser.
Also blocks script execution and runs the ROOT graphics event loop until the <space> keyword is pressed,
but only if the following conditions are met:
* The `block` optional argument is set to `True`.
* ROOT graphics are enabled, i.e. `ROOT.gROOT.IsBatch() == False`.
* The script is running not in ipython notebooks.
"""

self._Draw(option)

# run loop if block flag is set
if block:
_run_root_event_loop()


@pythonization('TBrowser')
def pythonize_tbrowser(klass):
# Parameters:
# klass: class to be pythonized

klass._original_constructor = klass.__init__
klass.__init__ = _TBrowser_constructor

klass._Draw = klass.Draw
klass.Draw = _TBrowser_Draw

Original file line number Diff line number Diff line change
Expand Up @@ -32,67 +32,7 @@
\endpythondoc
'''

from . import pythonization

def wait_press_windows():
from ROOT import gSystem
import msvcrt
import time

while not gSystem.ProcessEvents():
if msvcrt.kbhit():
k = msvcrt.getch()
if k[0] == 32:
break
else:
time.sleep(0.01)


def wait_press_posix():
from ROOT import gSystem
import sys
import select
import tty
import termios
import time

old_settings = termios.tcgetattr(sys.stdin)

tty.setcbreak(sys.stdin.fileno())

try:

while not gSystem.ProcessEvents():
c = ''
if select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []):
c = sys.stdin.read(1)
if (c == '\x20'):
break
time.sleep(0.01)

finally:
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)

def run_root_event_loop():
from ROOT import gROOT
import os
import sys

# no special handling in batch mode
if gROOT.IsBatch():
return

# no special handling in case of notebooks
if 'IPython' in sys.modules and sys.modules['IPython'].version_info[0] >= 5:
return

print("Press <space> key to continue")

if os.name == 'nt':
wait_press_windows()
else:
wait_press_posix()

from . import pythonization, _run_root_event_loop

Check failure on line 35 in bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tcanvas.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tcanvas.py:35:1: I001 Import block is un-sorted or un-formatted

def _TCanvas_Update(self, block = False):
"""
Expand All @@ -108,7 +48,7 @@

# run loop if block flag is set
if block:
run_root_event_loop()
_run_root_event_loop()


def _TCanvas_Draw(self, option: str = "", block: bool = False):
Expand All @@ -126,7 +66,7 @@
# run loop if block flag is set
if block:
self._Update()
run_root_event_loop()
_run_root_event_loop()


@pythonization('TCanvas')
Expand Down
Loading