[wxPython] wxPython demo crashes Python.exe, pythonw.exe

Hi

I just downloaded and installed wxPython 2.2.5. I'm running win98 with
ActivePython build 202.

When I try to run the demo (\python20\wxPython\demos\demo.py), whether
from python.exe, pythonw.exe, or pythonwin.exe, I get a fatal exception
from Windows--

PYTHONW caused an exception c06d007eH in module KERNEL32.DLL at
014f:bff9a3c0.

Upon further investigation, this happens any time I try to import
wxPython.wx, most specifically upon trying to import wxc.pyd ... also,
the exception id and the address are always the same.

Any ideas? Might this be an installation issue? I used binary
installers for both Python and wxPython, but you never know...

Thanks in advance...
Jeff Shannon

PYTHONW caused an exception c06d007eH in module KERNEL32.DLL at
014f:bff9a3c0.

A quick search of the archive turns up this:

http://lists.wxwindows.org/pipermail/wxpython-users/2001-January/004065.html

but I can't find the resolution although I remember that it was fixed...

Stephen, are you still reading this list and can you tell us what you did
when you had this problem?

IIRC, it was an issue of other DLLs on the system (or lack of one) so you
may want to get Dependency Walker from http://www.dependencywalker.com/ and
point it at wxc.pyd and see what it can tell you. You can also have it run
python.exe under its control and then type "import wxPython.wx" from the
interactive interpreter. It will give you log of all DLLs (or .pyd) that
are loaded, symbols imported, etc.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!

Robin Dunn wrote:

>
> PYTHONW caused an exception c06d007eH in module KERNEL32.DLL at
> 014f:bff9a3c0.
>

IIRC, it was an issue of other DLLs on the system (or lack of one) so you
may want to get Dependency Walker from http://www.dependencywalker.com/ and
point it at wxc.pyd and see what it can tell you. You can also have it run
python.exe under its control and then type "import wxPython.wx" from the
interactive interpreter. It will give you log of all DLLs (or .pyd) that
are loaded, symbols imported, etc.

Ah, yes, Dependency Walker tells me that I'm missing one "WS2_32.DLL", now I
just need to
figure out where to get a replacement for that. :slight_smile:

Thanks!
Jeff Shannon

Jeff Shannon wrote:

Ah, yes, Dependency Walker tells me that I'm missing one "WS2_32.DLL", now I
just need to
figure out where to get a replacement for that. :slight_smile:

Duh. Forgot that this was one of the few machines that has *not* been upgraded
to win98. Since I'm still running win95, I presumably need to install Winsock
2.0, which includes ws2_32.dll.....

Thanks again for pointing me in the right direction!
Jeff Shannon

Ah, yes, Dependency Walker tells me that I'm missing one "WS2_32.DLL",

now I

just need to
figure out where to get a replacement for that. :slight_smile:

As mentioned on the wxPython Download page you can get it for win95 at:

but I thought you said you had win98 and I thought win98 came with Winsock
2.0 already...

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!

Hi,

I am creating a menu dynamically, and I am always reusing the same id's
(0 to len(menu)).

It seems that further calls to EVT_MENU don't override previous calls
with the same id. I have modified the sample pyTree to demonstrate this.
First right click on the root item, correct functions get called. Then
right click on any other item, and the wrong function is called.

Am I missing something? Is it how it is supposed to work? I did find a
workaround, but it looks like a bug to me. I'm running on:

# Python 2.1 (#1, May 1 2001, 12:28:00)
# wxPython 2.2.5
# [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
# running Redhat 6.2 (2.2.14-5.0smp)

Gregory Popovitch

----- sample --------

from wxPython import wx
import string # Don't use it, but it's fun expanding :slight_smile:

···

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

def _getindent(line):
    """Returns the indentation level of the given line."""
    indent = 0
    for c in line:
        if c == ' ': indent = indent + 1
        elif c == '\t': indent = indent + 8
        else: break
    return indent

def _sourcefinder(func):
    try:
        f = open(func.co_filename,"r")
    except:
        return "(could not open file %s)" % (func.co_filename,)

    for i in range(func.co_firstlineno):
        line = f.readline()
    ind = _getindent(line)
    msg = ""
    while line:
        msg = msg + line
        line = f.readline()
        # the following should be <= ind, but then we get
        # confused by multiline docstrings. Using == works most of
        # the time... but not always!
        if _getindent(line) == ind: break
    return msg

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

class pyTree(wx.wxTreeCtrl):
    def __init__(self, parent, id, root):
        """
        Initialize function; because we insert branches into the tree
        as needed, we use the ITEM_EXPANDING event handler. The
        ITEM_COLLAPSED handler removes the stuff afterwards. The
        SEL_CHANGED handler attempts to display interesting
        information about the selected object.
        """
        wx.wxTreeCtrl.__init__(self, parent, id)
        self.root = self.AddRoot(str(root), -1, -1, wx.wxTreeItemData(root))
        if dir(root):
            self.SetItemHasChildren(self.root, wx.TRUE)
        wx.EVT_TREE_ITEM_EXPANDING(self, self.GetId(), self.OnItemExpanding)
        wx.EVT_TREE_ITEM_COLLAPSED(self, self.GetId(), self.OnItemCollapsed)
        wx.EVT_TREE_SEL_CHANGED(self, self.GetId(), self.OnSelChanged)
        wx.EVT_RIGHT_DOWN(self, self.OnRightClick) ### MODIF
        self.output = None
        
    #### MODIF ###
    def OnRightClick(self, event):
        pt = event.GetPosition();
        item, flags = self.HitTest(pt)
        if (flags | (wx.wxTREE_HITTEST_ONITEMLABEL |
wx.wxTREE_HITTEST_ONITEMINDENT)) != 0:
            if item == self.root:
                menuDef = [
                    ["Function One", self.One],
                    ["Function Two", self.Two],
                    ]
            else:
                menuDef = [
                    ["Function Two", self.Two],
                    ["Function One", self.One],
                    ]
            menu = wx.wxMenu()
            for i in range(len(menuDef)):
                print "appending: %d %s %s" % (i, menuDef[i][0],
str(menuDef[i][1]))
                menu.Append(i, menuDef[i][0])
                wx.EVT_MENU(self, i, menuDef[i][1])
            self.PopupMenu(menu, wx.wxPoint(event.GetX(), event.GetY()))
            menu.Destroy()
        event.Skip()

    def One(self, event):
        print "One"
        
    def Two(self, event):
        print "Two"
    #### END OF MODIF ###

    def SetOutput(self, output):
    self.output = output

    def OnItemExpanding(self,event):
        item = event.GetItem()
        obj = self.GetPyData( item )
        lst = dir(obj)
        for key in lst:
            new_obj = getattr(obj,key)
            new_item = self.AppendItem( item, key, -1, -1,
                                        wx.wxTreeItemData(new_obj) )
            if dir(new_obj):
                self.SetItemHasChildren(new_item, wx.TRUE)

    def OnItemCollapsed(self, event):
        item = event.GetItem()
        self.DeleteChildren(item)

    def OnSelChanged(self, event):
        if not self.output:
            return
        obj = self.GetPyData( event.GetItem() )
        msg = str(obj)
        if hasattr(obj, '__doc__'):
            msg = msg+"\n\nDocumentation string:\n\n%s" % ( getattr(obj,
'__doc__'),)
        # Is it a function?
        func = None
        if hasattr(obj, "func_code"): # normal function
            func = getattr(obj, "func_code")
        elif hasattr(obj, "im_func"): # unbound class method
            func = getattr(getattr(obj, "im_func"), "func_code")
        if func: # if we found one, let's try to print the source
            msg = msg+"\n\nFunction source:\n\n" + _sourcefinder(func)

        apply(self.output, (msg,))

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

overview = __doc__

def runTest(frame, nb, log):
    thisModule = __import__(__name__, globals())
    win = wx.wxFrame(frame, -1, "PyTreeItemData Test")
    split = wx.wxSplitterWindow(win, -1)
    tree = pyTree(split, -1, thisModule)
    text = wx.wxTextCtrl(split, -1, "", wx.wxDefaultPosition,
                         wx.wxDefaultSize, wx.wxTE_MULTILINE)
    split.SplitVertically(tree, text, 200)
    tree.SetOutput(text.SetValue)
    tree.SelectItem(tree.root)
    win.SetSize(wx.wxSize(800,500))
    frame.otherWin = win
    win.Show(1)

#----------------------------------------------------------------------
if __name__ == '__main__':

    class MyFrame(wx.wxFrame):
        """Very standard Frame class. Nothing special here!"""

        def __init__(self):
            """Make a splitter window; left a tree, right a textctrl.
Wow."""
            import __main__
            wx.wxFrame.__init__(self, wx.NULL, -1, "PyTreeItemData Test",
                                wx.wxDefaultPosition, wx.wxSize(800,500))
            split = wx.wxSplitterWindow(self, -1)
            tree = pyTree(split, -1, __main__)
            text = wx.wxTextCtrl(split, -1, "", wx.wxDefaultPosition,
                                 wx.wxDefaultSize, wx.wxTE_MULTILINE)
            split.SplitVertically(tree, text, 200)
            tree.SetOutput(text.SetValue)
            tree.SelectItem(tree.root)

    class MyApp(wx.wxApp):
        """This class is even less interesting than MyFrame."""

        def OnInit(self):
            """OnInit. Boring, boring, boring!"""
            frame = MyFrame()
            frame.Show(wx.TRUE)
            self.SetTopWindow(frame)
            return wx.TRUE

    app = MyApp(0)
    app.MainLoop()

I am creating a menu dynamically, and I am always reusing the same id's
(0 to len(menu)).

It seems that further calls to EVT_MENU don't override previous calls
with the same id.

That is correct. Additional EVT_** calls only add to the end of the dynamic
event table, they do not search for a match and replace it. (Probably
because of the wildcard issue it would be difficult to know what the
programmer really wanted to do.)

To remove an event handler binding you need to use wxEvtHandler.Disconnect,
which is defined like this:

        bool Disconnect(int id, int lastId = -1,
                        wxEventType eventType = wxEVT_NULL)

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!