[wxPython] New wxPython/Python user and possible bug

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[wxPython] New wxPython/Python user and possible bug

Cavanaugh, Craig
Hello all,

I've just begun learning python and wxPython.  I've been working on a
personal finance program that I want to work on Linux and Windows.

I've been working on it during lunch breaks at work on an NT system, and I
am progressing well, but after trying to work on it at home, I ran into a
BIG problem

I'm getting a core dump when I call  self.tree.Expand(self.root).  It works
fine under Windows but it dies using wxGTK.  I'm using the the 2.1.11
release on both  systems (Win NT & Redhat 6.1 using the RPM. Also, I'm using
the latest gtk 1.2.6 )

The trick to the problem is that I create 2 instances of the wxAccountSheet
and then add them to a wxNotebook.  The core occurs when I create the second
instance.

BTW, I plan to release the program under GPL as soon as I have basic
functionality completed.  It's basicaly going to be a Quicken Clone.

TIA
Craig
------------------------------------- start of code
-----------------------------------------------
from wxPython.wx import *
from wxCreateAccount import *
import engine

class wxAccountSheet(wxPanel):
    def __init__(self, parent, engine, accounts):
        wxPanel.__init__(self, parent, -1)
        print "start of wxAccountSheet::__init__"

        self.__accounts = accounts        
        self.engine = engine
        self.tmpAccount = None
        self.tID = NewId()
        self.root = None

        self.tree = wxTreeCtrl(self, self.tID, wxDefaultPosition,
wxDefaultSize, wxTR_HAS_BUTTONS)

        i = 0        
        count = len(self.__accounts)        

        while i < count:
            treeData = wxTreeItemData(self.__accounts[i])
            self.root = self.tree.AddRoot(self.__accounts[i].getName(), data
= treeData)
            if self.__accounts[i].getNumChildren() > 0:
                self.addChildren(self.__accounts[i].getChildren(),
self.root)
            i = i + 1        
        print "after data parse"

        self.tree.Expand(self.root)  # <====== it dies here
        print "after tree expansion"
       
        EVT_TREE_ITEM_EXPANDED  (self, self.tID, self.OnItemExpanded)
        EVT_TREE_ITEM_COLLAPSED (self, self.tID, self.OnItemCollapsed)
        EVT_TREE_SEL_CHANGED    (self, self.tID, self.OnSelChanged)

        EVT_LEFT_DCLICK(self.tree, self.OnLeftDClick)
        EVT_RIGHT_DOWN(self.tree, self.OnRightClick)
        print "before menu creation"

        # build the PopupMenu
        self.popMenu = wxMenu()
       
        self.newID = wxNewId()
        self.popMenu.Append(self.newID, "New", "Create an Account")
        EVT_MENU(self, self.newID, self.OnMenuNew)
       
        self.editID = wxNewId()
        self.popMenu.Append(self.editID, "Edit", "Edit an Account")
        EVT_MENU(self, self.editID, self.OnMenuEdit)
       
        self.delID = wxNewId()
        self.popMenu.Append(self.delID, "Delete", "Delete an Account")
        EVT_MENU(self, self.delID, self.OnMenuDelete)
        print "after menu creation"

    def addChildren(self, accounts, root):
        "Recursive function to walk through the tree"
       
        i = 0
        count = len(accounts)

        while i < count:
            treeData = wxTreeItemData(accounts[i])
            twig = self.tree.AppendItem(root, accounts[i].getName(), data =
treeData)
            if accounts[i].getNumChildren() > 0:
                self.addChildren(accounts[i].getChildren(), twig)
            i = i + 1                
        return        

    def OnRightClick(self, event):
        pt = event.GetPosition();
        item = self.tree.HitTest(pt)  
        self.tmpAccount = self.tree.GetPyData(item)     # need to save the
parent account
     
        self.tree.SelectItem(item)
        self.PopupMenu(self.popMenu, pt)                # display the popup
menu
        self.tmpAccount = None                          # clear the temporay
reference to the account
----------------------------- end of code
--------------------------------------------------------------------------

_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] New wxPython/Python user and possible bug

Robin Dunn
>
>         while i < count:
>             treeData = wxTreeItemData(self.__accounts[i])
>             self.root = self.tree.AddRoot(self.__accounts[i].getName(),
data

> = treeData)
>             if self.__accounts[i].getNumChildren() > 0:
>                 self.addChildren(self.__accounts[i].getChildren(),
> self.root)
>             i = i + 1
>         print "after data parse"
>
>         self.tree.Expand(self.root)  # <====== it dies here
>         print "after tree expansion"
>


It took me a while to see the problem.  It wasn't until I was actually
executing the program that I realized what's going on and then had to smack
my head on the desk yelling "Duh!"

The generic tree control (used for wxGTK) only allows a single root.
Apparently for your second tree the value of count is > 1.

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users