Skip to content
Snippets Groups Projects
Commit e0d69db0 authored by Danilo Piparo's avatar Danilo Piparo
Browse files

Detect drawn canvases in the list of canvases, move comment stripper

parent 469ece46
No related branches found
No related tags found
No related merge requests found
import re
from IPython.core.inputtransformer import InputTransformer from IPython.core.inputtransformer import InputTransformer
from IPython import get_ipython from IPython import get_ipython
...@@ -9,22 +7,7 @@ import cppcompleter ...@@ -9,22 +7,7 @@ import cppcompleter
from IPython.core import display from IPython.core import display
def commentRemover( text ):
def blotOutNonNewlines( strIn ) : # Return a string containing only the newline chars contained in strIn
return "" + ("\n" * strIn.count('\n'))
def replacer( match ) :
s = match.group(0)
if s.startswith('/'): # Matched string is //...EOL or /*...*/ ==> Blot out all non-newline chars
return blotOutNonNewlines(s)
else: # Matched string is '...' or "..." ==> Keep unchanged
return s
pattern = re.compile(\
r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"',
re.DOTALL | re.MULTILINE)
return re.sub(pattern, replacer, text)
class CppTransformer(InputTransformer): class CppTransformer(InputTransformer):
...@@ -52,9 +35,7 @@ class CppTransformer(InputTransformer): ...@@ -52,9 +35,7 @@ class CppTransformer(InputTransformer):
utils.declareCppCode(self.cell) utils.declareCppCode(self.cell)
self.mustDeclare = False self.mustDeclare = False
else: else:
cell = self.cell utils.processCppCode(self.cell)
code = commentRemover(self.cell)
utils.processCppCode(code)
self.cell = "" self.cell = ""
if self.mustSwitchToPython: if self.mustSwitchToPython:
ip = get_ipython() ip = get_ipython()
......
...@@ -5,6 +5,7 @@ import time ...@@ -5,6 +5,7 @@ import time
import tempfile import tempfile
import itertools import itertools
import ctypes import ctypes
import re
from contextlib import contextmanager from contextlib import contextmanager
from IPython import get_ipython from IPython import get_ipython
from IPython.display import HTML from IPython.display import HTML
...@@ -101,6 +102,23 @@ def _setIgnoreLevel(level): ...@@ -101,6 +102,23 @@ def _setIgnoreLevel(level):
yield yield
ROOT.gErrorIgnoreLevel = originalLevel ROOT.gErrorIgnoreLevel = originalLevel
def commentRemover( text ):
def blotOutNonNewlines( strIn ) : # Return a string containing only the newline chars contained in strIn
return "" + ("\n" * strIn.count('\n'))
def replacer( match ) :
s = match.group(0)
if s.startswith('/'): # Matched string is //...EOL or /*...*/ ==> Blot out all non-newline chars
return blotOutNonNewlines(s)
else: # Matched string is '...' or "..." ==> Keep unchanged
return s
pattern = re.compile(\
r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"',
re.DOTALL | re.MULTILINE)
return re.sub(pattern, replacer, text)
class StreamCapture(object): class StreamCapture(object):
def __init__(self, stream, ip=get_ipython()): def __init__(self, stream, ip=get_ipython()):
streamsFileNo={sys.stderr:2,sys.stdout:1} streamsFileNo={sys.stderr:2,sys.stdout:1}
...@@ -271,10 +289,30 @@ class CanvasCapture(object): ...@@ -271,10 +289,30 @@ class CanvasCapture(object):
self.shell.events.unregister('pre_execute', self._pre_execute) self.shell.events.unregister('pre_execute', self._pre_execute)
self.shell.events.unregister('post_execute', self._post_execute) self.shell.events.unregister('post_execute', self._post_execute)
class CaptureDrawnCanvases(object):
'''
Capture the canvas which is drawn to display it.
'''
def __init__(self, ip=get_ipython()):
self.shell = ip
def _pre_execute(self):
pass
def _post_execute(self):
for can in ROOT.gROOT.GetListOfCanvases():
if can.IsDrawn():
can.Draw()
can.ResetDrawn()
def register(self):
self.shell.events.register('pre_execute', self._pre_execute)
self.shell.events.register('post_execute', self._post_execute)
captures = [StreamCapture(sys.stderr), captures = [StreamCapture(sys.stderr),
StreamCapture(sys.stdout)] StreamCapture(sys.stdout),
#CanvasCapture()] CaptureDrawnCanvases()]
def toCpp(): def toCpp():
''' '''
...@@ -392,9 +430,11 @@ def setStyle(): ...@@ -392,9 +430,11 @@ def setStyle():
# Here functions are defined to process C++ code # Here functions are defined to process C++ code
def processCppCodeImpl(cell): def processCppCodeImpl(cell):
cell = commentRemover(cell)
ROOT.gInterpreter.ProcessLine(cell) ROOT.gInterpreter.ProcessLine(cell)
def declareCppCodeImpl(cell): def declareCppCodeImpl(cell):
cell = commentRemover(cell)
ROOT.gInterpreter.Declare(cell) ROOT.gInterpreter.Declare(cell)
def processCppCode(cell): def processCppCode(cell):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment