Page 1 of 1

wxPython pdb.set_trace() after event fires

Posted: Wed Feb 10, 2016 7:46 pm
by guzzi_jones
It appears that my program outputs the results of pdb to a window rather than to the command line to allow my input commands such as "n" for next or "s " for sub.

Code: Select all

import wx
import pdb
class myPopupMenu(wx.Menu):
    def __init__(self,parent):
        super(myPopupMenu,self).__init__()
        pdb.set_trace()
        self.parent=parent
        mmi = wx.MenuItem(self,wx.NewId(),'Minimize')
        self.AppendItem(mmi)
        self.Bind(wx.EVT_MENU,self.OnMinimize,mmi)

        cmi = wx.MenuItem(self,wx.NewId(),'Close')
        self.AppendItem(cmi)
        self.Bind(wx.EVT_MENU,self.OnClose,cmi)

    def OnMinimize(self,e):
        self.parent.Iconize()
    def OnClose(self,e):
        self.parent.Close()

class Example(wx.Frame):
    def __init__(self,parent,title):
        wx.Frame.__init__(self,parent,title=title)
        self.Bind(wx.EVT_RIGHT_DOWN,self.OnRightDown)
        self.SetSize((250,200))
        self.Centre()
        self.Show(True)
    def OnRightDown(self,e):
        self.PopupMenu(myPopupMenu(self),e.GetPosition())

def main():
    ex = wx.App(redirect=True)
    Example(None,"Context Example")
    ex.MainLoop()

if __name__ == '__main__':
    main()

 
Does anyone know a way to change it to output to the console rather than to a new gui window?

Re: wxPython pdb.set_trace() after event fires

Posted: Thu Feb 11, 2016 1:41 pm
by guzzi_jones
It appears that winpdb is the answer here.
http://winpdb.org/tutorial/WinpdbTutorial.html

here is the divisible.py for future reference:

Code: Select all

import sys

def is_divisible(a, b):
    """Determines if integer a is divisible by integer b."""
    
    remainder = a % b
    # if there's no remainder, then a is divisible by b
    if not remainder:
        return True
    else:
        return False

def find_divisors(integer):
    """Find all divisors of an integer and return them as a list."""

    divisors = []
    # we know that an integer divides itself
    divisors.append(integer)
    # we also know that the biggest divisor other than the integer itself
    # must be at most half the value of the integer (think about it)
    divisor = integer / 2

    while divisor >= 0:
        if is_divisible(integer, divisor):
            divisors.append(divisor)
        divisor =- 1

    return divisors

if __name__ == '__main__':
    # do some checking of the user's input
    try:
        if len(sys.argv) == 2:
            # the following statement will raise a ValueError for
            # non-integer arguments
            test_integer = int(sys.argv[1])
            # check to make sure the integer was positive
            if test_integer <= 0:
                raise ValueError("integer must be positive")
        elif len(sys.argv) == 1:
            # print the usage if there are no arguments and exit
            print __doc__
            sys.exit(0)
        else:
            # alert the user they did not provide the correct number of
            # arguments
            raise ValueError("too many arguments")
    # catch the errors raised if sys.argv[1] is not a positive integer
    except ValueError, e:
        # alert the user to provide a valid argument
        print "Error: please provide one positive integer as an argument."
        sys.exit(2)

    divisors = find_divisors(test_integer)
    # print the results
    print "The divisors of %d are:" % test_integer
    for divisor in divisors:
        print divisor