LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-29-2005, 06:55 PM   #1
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
wxPython: control handling its own events?


Hi,

Using wxPython I'm deriving a class from the wxTreeCtrl class, to make it list sub-directory trees. I'd like to make it read the directories to display all by itself, so I don't need to clutter up the code of the wxFrame class with all kinds of control-specific things.

I started out with a wxTreeCtrl-example that comes with wxPython, and stripped it. Than I moved the code for displaying some items in the tree to my class derived from wxTreeCtrl, which was easy.

Now I'd like to have my custom tree-control also do things when some (of its own) events occur. And I can't seem to find out how to that. Is it possible? If so, will it still be possible for a wxPanel (the parent) to get the same event? Instead of the "EVT_"-construct, is there some way to overload a function that will get called when the event occurs? If so, where could I find information about which functions to overload?

Below my code so far (largely taken from the wxTreeCtrl example from the wxPython package).
Code:
#!/usr/bin/env python

from wxPython.wx import *
import string

class SubdirTreeCtrl(wxTreeCtrl):
    def __init__(self, parent, id, pos, size):
        wxTreeCtrl.__init__(self, parent, id, pos, size, wxTR_HAS_BUTTONS | wxTR_HIDE_ROOT)
        self.root = self.AddRoot("Subdirectories")

        # Add items
        for x in range(15):
            child = self.AppendItem(self.root, "Dir %d" % x)
            self.SortChildren(self.root)
            for y in range(5):
                last = self.AppendItem(child, "File %d-%s" % (x, chr(ord("a")+y)))

        self.Expand(self.root)

class MainPanel(wxPanel):
    def __init__(self, parent):
        wxPanel.__init__(self, parent, -1)

        tID = wxNewId()
        self.tree = SubdirTreeCtrl(self, tID, wxDefaultPosition, (200, 200))
 
        # I'd like to move lines like the one below to the SubDirTreeCtrl class
        EVT_TREE_ITEM_EXPANDED  (self, tID, self.OnItemExpanded)

    def OnItemExpanded(self, event):
        item = event.GetItem()
        print "OnItemExpanded: %s\n" % self.tree.GetItemText(item)

app = wxPySimpleApp()
frame = wxFrame(None, -1, "Directories")
MainPanel(frame)
frame.Show(true)
app.MainLoop()

Last edited by Hko; 07-29-2005 at 07:00 PM.
 
Old 07-30-2005, 06:58 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Original Poster
Rep: Reputation: 111Reputation: 111
* b u m p *
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Control amount of time a user may be logged in. (Parental Control) darrensnospam Mandriva 13 02-18-2006 05:01 PM
wxPython xlord Programming 0 05-23-2004 04:12 PM
Can't launch redhat-network-control after updating gnome-control-center fedetxf Red Hat 0 12-12-2003 07:12 AM
wxPython. vexer Slackware 5 09-22-2003 03:11 PM
wxPython Filsta Linux - Software 0 08-20-2002 03:29 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration