LinuxQuestions.org
Review your favorite Linux distribution.
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 08-07-2006, 08:57 PM   #1
Chrax
Member
 
Registered: Apr 2004
Distribution: Dapper
Posts: 167

Rep: Reputation: 31
PyGTK TreeView segmentation fault on expand_all()


I have recently begun a project using PyGTK, and part of my planned interface has a gtk.TreeView showing a portion of the filesystem. Now, rather than load the entire FS structure into the tree right from the beginning, I made a lazy tree by adding blank children to rows representing directories, and connected a call to fill in the data when a row with blank children was expanded.

Now, this works all fine and well, in general. I can browse my entire filesystem this way. But I noticed that hitting '*' (which I believe is a call to expand_all(), though the documentation does not say this explicitly) on a row representing any empty directory causes a segmentation fault.

This problem can be alleviated by not removing the blank child after attempting to add directory contents, but I would like to avoid this approach.

My suspicion is that expand_all() assumes that there are children present, and when I remove the blank row (after attempting to add any subdirectories and files), it does not check to make sure there are still children.

So I suppose I have a couple questions. First, can anybody confirm my suspicions? Secondly, is this a PyGTK bug, or am I doing something that simply should never be done? Finally, do you see any way to fix this problem?

Code:
def onExpand(self, view, iter, path):
        """Add directory contents on first expansion of its entry"""
        sorted = view.get_model() # TreeModelSort
        iter = sorted.convert_iter_to_child_iter(None,iter)
        store = sorted.get_model() # TreeStore
        child = store.iter_children(iter)
        cpath = store.get(iter,1)[0][1:] # Hidden column with fs path info
        if store.get_value(child, 0) is None:
                sorted.addDir(cpath,iter)
                store.remove(child)
If any other code is necessary, I can provide my entire program. However, I think I've isolated the problem to that last line (execution continues beyond it, so it's not exactly the line itself), and want to hear any recommendations for how to still remove that blank child without causing expand_all() to fall on its face.

Thanks in advance,
Chris
 
Old 08-08-2006, 05:18 AM   #2
Chrax
Member
 
Registered: Apr 2004
Distribution: Dapper
Posts: 167

Original Poster
Rep: Reputation: 31
In case anybody follows after, I solved this problem by connecting that function to both signals "test-expand-row" and "row-expanded". The former gets rid of the segfault problem by being run before expand_all() gets going too far, and the latter makes sure the blank children don't show.

A little bit hackish, but the upshot is that instead of expanding only one level on '*' and crashing with empty directories, we now expand two levels at a time and empty directories present no problems.
 
  


Reply

Tags
pygtk, segfault


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika Suse/Novell 2 12-02-2005 09:34 AM
Segmentation fault tejas15_10 Programming 9 06-20-2005 09:12 AM
Segmentation fault bondoroyot Linux - Newbie 1 06-14-2005 07:53 PM
Segmentation fault tejas15_10 Linux - Newbie 1 06-14-2005 04:44 AM
segmentation fault libriana Linux - Newbie 2 06-10-2005 05:52 PM


All times are GMT -5. The time now is 07:08 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration