Exemplo n.º 1
0
def drawnow(draw_fig, show_once=False, confirm=False, *argv, **kwargs):
    """A function to refresh the current figure.

    Depends on matplotlib's interactive mode. Similar functionality to MATLAB's
    drawnow.

    Parameters
    ----------
    draw_fig : callable
               the function that draws the figure you want to update
    *argv    : any
               the list of parameters to pass ``draw_fig()``
    **kwargs : any
               the keywords to pass to ``draw_fig()``
    show_once, optional : bool, default == False. 
               If True, will call show() instead of draw(). 
    confirm, optional : bool, default == False
               If True, wait for user input after each iteration and present
               option to drop to python debugger (pdb).

    Limitations
    -----------
    - Occaisonally ignores Ctrl-C.
    - If two figures open and focus moved between figures, then other figure
      gets cleared.

    Usage Example
    -------------
      >>> def draw_fig_real():
      >>>     #figure() # don't call, otherwise opens new window
      >>>     imshow(z, interpolation='nearest')
      >>>     colorbar()
      >>>     #show()

      >>> N = 16
      >>> z = zeros((N,N))

      >>> ion()
      >>> figure()
      >>> for i in arange(N*N):
      >>>     z.flat[i] = 0
      >>>     drawnow(draw_fig_real)
    """

    # unpacking kw args (found online)
    kw = dict()
    kw.update(kwargs)

    # replace the current figure w/o opening new GUI
    clf()
    draw_fig(*argv, **kw)

    if show_once: show()
    else: draw()
    if confirm: 
        string = raw_input('Hit <Enter> to continue, "d<Enter>" for debugger: ')
        if string == 'd':
            print 'Type "exit" to continue program\n'
            pdb.runeval('u')
Exemplo n.º 2
0
def drawnow(draw_fig, show_once=False, confirm=False, *argv, **kwargs):
    """A function to refresh the current figure.
    Depends on matplotlib's interactive mode. Similar functionality to MATLAB's
    drawnow.
    Parameters
    ----------
    draw_fig : callable
               the function that draws the figure you want to update
    *argv    : any
               the list of parameters to pass ``draw_fig()``
    **kwargs : any
               the keywords to pass to ``draw_fig()``
    show_once, optional : bool, default == False.
               If True, will call show() instead of draw().
    confirm, optional : bool, default == False
               If True, wait for user input after each iteration and present
               option to drop to python debugger (pdb).
    Limitations
    -----------
    - Occaisonally ignores Ctrl-C especially while processing LaTeX.
    - Does not work in IPython's QtConsole. This depends on pylab's
      interactivity (implemented via ion()) working in QtConsole.
    - The initial processing of Latex labels (typically on the x/y axis and
      title) is slow. However, matplotlib caches the results so any subsequent
      animations are pretty fast.
    - If two figures open and focus moved between figures, then other figure
      gets cleared.
    Usage Example
    -------------
      >>> from pylab import * # import matplotlib before drawnow
      >>> from drawnow import drawnow, figure
      >>> def draw_fig_real():
      >>>     #figure() # don't call, otherwise opens new window
      >>>     imshow(z, interpolation='nearest')
      >>>     colorbar()
      >>>     #show()
      >>> N = 16
      >>> z = zeros((N,N))
      >>> figure()
      >>> for i in arange(N*N):
      >>>     z.flat[i] = 0
      >>>     drawnow(draw_fig_real)
    """
    # replace the current figure w/o opening new GUI
    plt.clf()
    draw_fig(*argv, **kwargs)

    if show_once: plt.show()
    else: plt.draw_all()

    plt.pause(1e-3) # allows time to draw

    if confirm:
        string = raw_input('Hit <Enter> to continue ("d" for debugger and "x" to exit): ')
        if string == 'x' or string=='exit':
            sys.exit()
        if string == 'd' or string=='debug':
            print('\nType "exit" to continue program execution\n')
            pdb.runeval('u')
Exemplo n.º 3
0
def execTemplate(code, data, pageFormat=None):
    # code is tuple (complied_code, source_code)
    if not pageFormat:
        pageFormat = CPageFormat(pageSize=CPageFormat.A4,
                                 orientation=CPageFormat.Portrait,
                                 leftMargin=5,
                                 topMargin=5,
                                 rightMargin=5,
                                 bottomMargin=5)
    try:
        infoContext = None
        for item in data.itervalues():
            if isinstance(item, CInfo):
                infoContext = item.context
                if infoContext:
                    break
        if not infoContext:
            infoContext = CInfoContext()

        stream = StringIO.StringIO()
        canvases = {}
        try:
            execContext = CTemplateContext(data, infoContext, stream,
                                           pageFormat)
            if QtGui.qApp.preferences.appPrefs.get('templateDebug', False):
                import pdb
                pdb.runeval(code[0], execContext, execContext.locals)
            sys.stdout = stream
            exec code[0] in execContext.locals, execContext
            canvases = execContext.getCanvases()
        finally:
            sys.stdout = sys.__stdout__
        return stream.getvalue(), canvases
    except ExTemplateContext, ex:
        QtGui.QMessageBox.critical(None, u'Печатная форма', ex.getRusMessage(),
                                   QtGui.QMessageBox.Ok, QtGui.QMessageBox.Ok)
        QtGui.qApp.logCurrentException()
        raise
Exemplo n.º 4
0
# Debugging pakage pdb

import pdb


def some_div(some_int):
    print("Start int", some_int)
    ret_int = 10 / some_int
    print("End some int", some_int)
    return ret_int


#different ways of calling debugger
pdb.run("some_div(2)")  #will not say what the function returns
print(pdb.runeval("some_div(2)"))  # will show what the function returns

print(pdb.runcall(
    some_div,
    2))  # will run same as runeval but should pass as function, parameter list
# pdb commands c

if __name__ == "__main__":
    try:
        some_div(0)
    except:
        import sys
        tb = sys.exc_info()[2]  #exception info

        pdb.post_mortem(tb)  # returns exception info in pdp prompt
Exemplo n.º 5
0
    print b.cor
    print b.get("cor")
    b.set("cor","branca")
    print b.cor


#---------------------------------------------------------------------------------------------

import pdb

def pyramid1(n):
    for i in range(1, n+1): 
        print((str(i)+" ")*i)

pdb.run("pyramid1(4)")
print pdb.runeval("2+3")

pdb.set_trace()
print "oioioi" 
#---------------------------------------------------------------------------------------------
import traceback
import sys

def produce_exception(recursion_level=2):
    sys.stdout.flush()
    if recursion_level:
        produce_exception(recursion_level-1)
    else:
        raise RuntimeError()

def call_function(f, recursion_level=2):
# s(tep) : execute exactly one line (smallest possible step forward)
# n(ext) : execute exactly one line in the current function
# unt(il) : continue executing until a higher line number is reached
# r(eturn) : continue executing until the current function returns
# c(ont(inue)) : continue executing until next break
# j(ump) lineno : lets you go back or forward to any line
# q(uit) : quit the debugger
#
# There are a few other commands that I don't use much (like setting
# conditional breakpoints etc.).

# Test out some of those commands
print bm.func3()
pdb.pm()

# The command 'pdb.set_trace()' sets an explicit breakpoint at some
# point in your code:
print bm.func2(4)

# You can also run a function under debugger control from the outset using:
pdb.run("bm.func3()")
# In effect, this puts a breakpoint before the function's first statement

# Two variants of 'run' are:
pdb.runeval("X")
# and
def func0(X):
    Z = 10 - Y
    return Z
pdb.runcall(func0, 3)
Exemplo n.º 7
0
import pdb
#pdb.run()
pdb.run("""
for i in range(0,10,3):
    i+=2
    print(i)
""")

#pdb.runeval()
pdb.runeval('(3+5)*2-6')


#pdb.runcall()
def sum(*args):
    s = 0
    for x in args:
        s += x
    return s


pdb.runcall(sum, 2, 4, 6, 8)

#pdb.set_trace()
pdb.set_trace()
for i in range(6):
    i *= i
    print(i)
Exemplo n.º 8
0
def drawnow(draw_fig, show_once=False, confirm=False, stop_on_close=False,
            *args, **kwargs):
    """A function to refresh the current figure.

    Depends on matplotlib's interactive mode. Similar functionality to MATLAB's
    drawnow.

    Parameters
    ----------
    draw_fig : callable
        The function that draws the figure you want to update
    show_once, optional : bool (default: False)
        If True, will call show() instead of draw().
    confirm, optional : bool, (default: False)
        If True, wait for user input after each iteration and present
        option to drop to python debugger (pdb).
    stop_on_close, optional : bool (default: False)
        When the figure is closed, stop the program execution.
    *args : list
        The list of parameters to pass ``draw_fig()``
    **kwargs : dict
        The keywords to pass to ``draw_fig()``

    Notes
    -----

    This function does not work with the inline plotting mode, which is
    common in Jupyter notebooks/lab, Spyder and the QTConsole. To
    disable this, run the following "magic" command:

        %matplotlib

    This will disable the Matplotlib inline mode and use the default plotting backend. For more detail, see `IPython's plotting documentation`_.

    Some limitations are the following:

    - Occaisonally ignores Ctrl-C especially while processing LaTeX.
    - The initial processing of Latex labels (typically on the x/y axis and
      title) is slow. However, matplotlib caches the results so any subsequent
      animations are pretty fast.
    - If two figures open and focus moved between figures, then other figure
      gets cleared.

    Usage Example
    -------------
      >>> from pylab import *  # import matplotlib before drawnow
      >>> from drawnow import drawnow, figure
      >>> def draw_fig_real():
      >>>     #figure() # don't call, otherwise opens new window
      >>>     imshow(z, interpolation='nearest')
      >>>     colorbar()
      >>>     #show()
      >>>
      >>> N = 16
      >>> z = zeros((N,N))
      >>>
      >>> figure()
      >>> for i in arange(N*N):
      >>>     z.flat[i] = 0
      >>>     drawnow(draw_fig_real)

    .. _IPython's plotting documentation: https://ipython.readthedocs.io/en/stable/interactive/plotting.html#id1

    """
    # replace the current figure w/o opening new GUI
    plt.clf()
    draw_fig(*args, **kwargs)

    if show_once:
        plt.show()
    else:
        plt.draw_all()

    plt.pause(1e-3)  # allows time to draw

    figures = plt.get_fignums()
    if stop_on_close and not figures:
        sys.exit()

    if confirm:
        string = raw_input('Hit <Enter> to continue, "d" for debugger and "x" '
                           'to exit: ')
        if string == 'x' or string == 'exit':
            sys.exit()
        if string == 'd' or string == 'debug':
            print('\nType "exit" to continue program execution\n')
            pdb.runeval('u')
Exemplo n.º 9
0
 def update_event(self, inp=-1):
     self.set_output_val(
         0, pdb.runeval(self.input(0), self.input(1), self.input(2)))
Exemplo n.º 10
0
# c(ont(inue)) : continue executing until next break
# j(ump) lineno : lets you go back or forward to any line
# q(uit) : quit the debugger
#
# There are a few other commands that I don't use much (like setting
# conditional breakpoints etc.).

# Test out some of those commands
print bm.func3()
pdb.pm()

# The command 'pdb.set_trace()' sets an explicit breakpoint at some
# point in your code:
print bm.func2(4)

# You can also run a function under debugger control from the outset using:
pdb.run("bm.func3()")
# In effect, this puts a breakpoint before the function's first statement

# Two variants of 'run' are:
pdb.runeval("X")


# and
def func0(X):
    Z = 10 - Y
    return Z


pdb.runcall(func0, 3)
Exemplo n.º 11
0
def test_runeval():
    # same as run but return the value
    pdb.runeval("test_debugger(0)")
Exemplo n.º 12
0
def drawnow(draw_fig, show_once=False, confirm=False, *argv, **kwargs):
    """A function to refresh the current figure.

    Depends on matplotlib's interactive mode. Similar functionality to MATLAB's
    drawnow.

    Parameters
    ----------
    draw_fig : callable
               the function that draws the figure you want to update
    *argv    : any
               the list of parameters to pass ``draw_fig()``
    **kwargs : any
               the keywords to pass to ``draw_fig()``
    show_once, optional : bool, default == False.
               If True, will call show() instead of draw().
    confirm, optional : bool, default == False
               If True, wait for user input after each iteration and present
               option to drop to python debugger (pdb).

    Limitations
    -----------
    - Occaisonally ignores Ctrl-C especially while processing LaTeX.
    - Does not work in IPython's QtConsole. This depends on pylab's
      interactivity (implemented via ion()) working in QtConsole.
    - The initial processing of Latex labels (typically on the x/y axis and
      title) is slow. However, matplotlib caches the results so any subsequent
      animations are pretty fast.
    - If two figures open and focus moved between figures, then other figure
      gets cleared.

    Usage Example
    -------------
      >>> from pylab import * # import matplotlib before drawnow
      >>> from drawnow import drawnow, figure
      >>> def draw_fig_real():
      >>>     #figure() # don't call, otherwise opens new window
      >>>     imshow(z, interpolation='nearest')
      >>>     colorbar()
      >>>     #show()

      >>> N = 16
      >>> z = zeros((N,N))

      >>> figure()
      >>> for i in arange(N*N):
      >>>     z.flat[i] = 0
      >>>     drawnow(draw_fig_real)
    """
    # replace the current figure w/o opening new GUI
    plt.clf()
    draw_fig(*argv, **kwargs)

    if show_once: plt.show()
    else: plt.draw_all()

    plt.pause(1e-3) # allows time to draw

    if confirm:
        string = raw_input('Hit <Enter> to continue ("d" for debugger and "x" to exit): ')
        if string == 'x' or string=='exit':
            sys.exit()
        if string == 'd' or string=='debug':
            print('\nType "exit" to continue program execution\n')
            pdb.runeval('u')
Exemplo n.º 13
0
def test_runeval():
    # same as run but return the value
    pdb.runeval("test_debugger(0)")
Exemplo n.º 14
0
# module for debugging - pdb
# command used with pdb - r (return), c (continue), h(help)

import pdb, sys


#print(dir(pdb))
def some_div(some_int):
    print("Start int", some_int)
    ret_int = 10 / some_int
    print("End some int", some_int)
    return ret_int


#print(pdb.run("some_div(0)")) # returns none object when c is pressed, doesn't return the actual o/p of the program
print(pdb.runeval("some_div(2)")
      )  # returns the actual value of the program when c is pressed
#pdb.runcall(some_div, 2) # the way of syntax differs from runeval()

# pdb.post_mortem() debugs the remaining program

if __name__ == '__main__':
    try:
        some_div(0)
    except:
        tb = sys.exc_info()[2]
        pdb.post_mortem(
            tb
        )  # takes the result of the exception as argument and debugs the dead program
        # after the exception