-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Support interactive TBrowser in python #20550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+138
−63
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8905714
Introduce pythonization of TBrowser::Draw
linev 67f4243
Move `run_root_event_loop` function to __init__.py script
linev 88f5a74
Add block parameter to TBrowser constructor pythonization
linev a2d4536
Prefix run_root_event_loop function name with _
linev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tbrowser.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
|
|
||
| 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 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.