GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Oct 23, 2014 3:06 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: pygtk scrolledwindow minimum size
PostPosted: Wed Mar 05, 2014 5:12 am 
Offline
Familiar Face

Joined: Wed Nov 07, 2012 2:34 am
Posts: 5
I don't have much pygtk experience, but I have read as much documentation as I could to figure this out before posting. I apologize if it's easy to do, and I know there are a lot of similar posts, but I just can't get it figured out.

I have a treeview inside a scrolledwindow. The treeview can contain several rows. By default, it sizes itself so that it's only one row high. As the user adds more rows, the scroll bar can be used to see them, but this is really ugly and inconvenient. By default, I'd like at least 5 rows visible, even if there aren't that many items in the list.

How do I set a minimum size so that at least 5 rows are always shown? Do I use a gtk.Adjustment? If so, how? Do I need to set the minimum size of the treeview or the scrolledwindow?

This looks exactly like the problem I have, but making these changes didn't work for me at all:
http://stackoverflow.com/questions/4579 ... lledwindow

Can someone please point me in the right direction?
Thanks!


Top
 Profile  
 
 Post subject: Re: pygtk scrolledwindow minimum size
PostPosted: Thu Mar 06, 2014 9:21 pm 
Offline
Familiar Face

Joined: Tue Oct 08, 2013 5:16 am
Posts: 20
In the Stackoverflow article you mentioned, the "True"/"False" values refer to packing, I think. You can also set a "width request" and "height request". I'm using Glade, so I usually don't look up the commands. Also, I'm using Python, not sure if I could help if you're using C or something else.


Top
 Profile  
 
 Post subject: Re: pygtk scrolledwindow minimum size
PostPosted: Fri Mar 07, 2014 12:16 am 
Offline
Familiar Face

Joined: Wed Nov 07, 2012 2:34 am
Posts: 5
Quote:
In the Stackoverflow article you mentioned, the "True"/"False" values refer to packing, I think.

I think you're right... changing those didn't make any difference to me, but that's the closest thing I've been able to find.
Quote:
You can also set a "width request" and "height request". I'm using Glade, so I usually don't look up the commands. Also, I'm using Python, not sure if I could help if you're using C or something else.

I am not using Glade (I know it'd be easier, but I'm trying to learn pygtk, so I don't want to take the easy way just yet), and I am using Python, so if you have any tips, please let me know. I tried googling with the terms "height request," but I keep getting the same things. If I remember, I'll try to extract a meaningful chunk of code tonight.

Thanks!


Top
 Profile  
 
 Post subject: Re: pygtk scrolledwindow minimum size
PostPosted: Fri Mar 07, 2014 3:22 am 
Offline
Familiar Face

Joined: Wed Nov 07, 2012 2:34 am
Posts: 5
Here's the code for the liststore, listview, scrolledwindow, and page.
Code:
self.stListLS   = gtk.ListStore(str)
self.stListView = gtk.TreeView(self.stListLS)
...
self.stListScroll = gtk.ScrolledWindow(None, None)
self.stListScroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
self.stListScroll.add(self.stListView)
...
self.page.pack_start(self.stListScroll, False, False, 0)


The stackoverflow link added a gtk.adjustment to the scrolled window and changed the pack_start arguments to True. I tried the same thing, and it made no difference.

Ideas? Thanks!


Top
 Profile  
 
 Post subject: Re: pygtk scrolledwindow minimum size
PostPosted: Fri Mar 07, 2014 4:45 am 
Offline
Familiar Face

Joined: Tue Oct 08, 2013 5:16 am
Posts: 20
So I think you are setting Expand/Fill for the wrong widget. You need to set it for the scrolledwindow. I'm not sure about hard coding this stuff, but you might try something like this.

Code:
self.stListLS   = gtk.ListStore(str)
self.stListView = gtk.TreeView(self.stListLS)
...
self.stListScroll = gtk.ScrolledWindow(None, None)
self.stListScroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
#self.stListScroll.add(self.stListView)
...
# Here you are actually setting Expand/Fill for the page "self.page"
self.page.pack_start(self.stListScroll, True, True, 0)
# This might work, you are setting Expand/Fill for the scrolledwindow
self.stListScroll.pack_start(self.stListView, True, True, 0)
# If that doesn't work, try the size_request method (again, not sure)
self.stListScroll.size_request(width_var, height_var)


Top
 Profile  
 
 Post subject: [solved] pygtk scrolledwindow minimum size
PostPosted: Fri Mar 07, 2014 4:45 am 
Offline
Familiar Face

Joined: Wed Nov 07, 2012 2:34 am
Posts: 5
OK, got it... arrived at this conclusion WHILE taupist was writing a reply, and that's pretty close to the solution.

I got a little confused, I had used the gtk.Window method set_default_size(), so when I realized that the scrolledwindow class doesn't inherit that, I wasn't sure what to search for. The trick was that scrolledwindows inherit from gtk.Widget, and gtk.Widget provides the set_size_request() method:
https://developer.gnome.org/pygtk/stable/class-gtkwidget.html#method-gtkwidget--set-size-request

That does what I want. Thanks everyone!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group