Re: [pygtk] How to add a keyboard shortcut to a widget?

2007-04-15 Thread David M. Cook
On Sat, Apr 14, 2007 at 11:49:47PM -0300, Gabriel Falcão wrote:
 I want to connect a keyboard keys combo ato emit a signal in some widget.
 Using glade its easy, mas i cant use glade.
 How i add this feature directly from code?
 
 im using pygtk2.8

See

http://www.async.com.br/faq/pygtk/index.py?req=showfile=faq23.034.htp

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] How to add a keyboard shortcut to a widget?

2007-04-15 Thread David M. Cook
On Sun, Apr 15, 2007 at 06:12:15AM -0300, Gabriel Falcão wrote:

self.desktop = gtk.gdk.get_default_root_window()
self.deskEvent = gtk.gdk.Event(gtk.gdk.BUTTON_PRESS)
gtk.binding_entry_add_signal(self.deskEvent, gtk.keysyms.F12,
 gtk.keysyms.Control_L, 'button-press-event')

I've only gotten it to work by subclassing a gtk widget as in the FAQ
example.  Can you subclass egg.TrayIcon?

Dave Cook  
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Best pattern for keyboard accelerators in dialog

2007-01-28 Thread David M. Cook
On Fri, Jan 26, 2007 at 08:49:51AM +, Richard Taylor wrote:

 I would like to provide keyboard accelerators that move the focus to the 
 appropriate Widget. I want to underline a letter in each label and link 
 Alt-letter to switch to the Edit widget alongside the Label. I would like 
 these accelerators to work regardless of which widget has the focus.

Easiest is

label.set_use_underline(True)
label.set_mnemonic_widget(widget)

but that's global. I don't know of a way to make that only
work in a sub-widget.

http://pygtk.org/docs/pygtk/class-gtklabel.html#method-gtklabel--set-mnemonic-widget

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] handling events

2006-10-22 Thread David M. Cook
On Sun, Oct 22, 2006 at 09:57:47AM +0200, Pascal DUCHATELLE wrote:

  I could add a status bar to each notebook page but this is no elegent way...

I'd put the status bar handling code in its own module.  Then import that
module wherever it's needed.

If you want to reduce coupling in your code, you could adapt one of the
publish/subscribe examples from the Python Cookbook.

Dave Cook


___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] PyGTK .app bundle for MacOS X?

2006-10-18 Thread David M. Cook
On Wed, Oct 18, 2006 at 11:39:51PM +0200, Wolfgang Keller wrote:

 I'm looking for a way that allows a clueless Python scripting dilettant like 
 me to build a double-clickable .app bundle of a PyGTK application for MacOS 
 X.
 
 Any ideas? Such as e.g. a pre-made empty .app bundle that includes already 
 the Python interpreter and a compiled PyGTK module?

I don't know of such an app bundle.  You could compile all the packages
yourself.  I've done it before, but it's very tedious as you often have to
backtrack to get dependencies and fuss over the config settings.

Instead, I would suggest darwinports: http://darwinports.opendarwin.org/ 
Or fink: http://fink.sf.net
They've done all this work for you.

I prefer darwinports (though I'd much rather have an RPM based system than
either of those).  You do have to use *their* copy of python (unless
there's a way to get around that.)  Both of them also have a tendency to
overdo dependencies IMO.

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] PyGTK .app bundle for MacOS X?

2006-10-18 Thread David M. Cook
On Wed, Oct 18, 2006 at 09:29:27PM -0700, David M. Cook wrote:

  Both of them also have a tendency to
 overdo dependencies IMO.

I should take that back about dependencies.  Darwinports does a pretty
straightforward job with this:

david-cooks-computer:~ davidcook$ sudo port install py-gtk2
---  Installing pkgconfig 0.21_0
---  Installing glib2 2.12.4_0
---  Installing atk 1.12.2_0
---  Installing zlib 1.2.3_0
---  Installing libpng 1.2.10_2+darwin_8
---  Installing freetype 2.1.10_1
---  Installing fontconfig 2.3.2_2+macosx
---  Installing render 0.9_0
---  Installing xrender 0.9.0_0+darwin_8
---  Installing Xft2 2.1.7_0
---  Installing cairo 1.2.4_1
---  Installing pango 1.14.3_0
---  Installing jpeg 6b_1
---  Installing tiff 3.8.2_0+darwin_8
---  Installing gtk2 2.10.3_0
---  Installing libxml2 2.6.23_0
---  Installing libglade2 2.6.0_1
---  Installing python24 2.4.3_1+darwin_8
---  Installing py-numeric 24.2_0+darwin_8+macosx
---  Installing py-cairo 1.2.2_0
---  Installing py-gobject 2.12.1_0
---  Installing py-gtk2 2.10.1_0

Apart from the iffy inclusion of numeric, there don't seem to be any
unneeded dependencies (your session might look a little different as I've
already installed stuff like tetex, which brings in a lot of dependencies).
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Wait until a thread is ended

2006-09-28 Thread David M. Cook
On Thu, Sep 28, 2006 at 09:16:20PM +0200, Adolfo González Blázquez wrote:

 I would like to know if someone can point me a solution to make a
 function run as a separate thread, and wait until it is ended, without
 blocking the gui.

 In my application, i'm getting a long file listing using glob(), and i
 want this function to run as a thread, so the user can stop it using a
 button in the gui (right now, the gui freezes till glob is ended), and
 then run another function to fill the treeview (this now works without
 blocking the gui, using generators). .

Use a callback to handle the result and call it from your thread with
gtk.idle_add().

Dave Cook

___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] event handling

2006-09-03 Thread David M. Cook
On Sun, Sep 03, 2006 at 08:37:13AM +0200, Pascal DUCHATELLE wrote:
  dic = {on_mainWindow_destroy : gtk.main_quit,
 on_hello_key_press_event : self.hellorecompile}
  followed by this:
  self.wTree.signal_autoconnect(dic)
  Is there a way to use the second solution but also pass 
  an argument like in the first one ?

You can use a tuple in your dic.  See

http://www.async.com.br/faq/pygtk/index.py?req=showfile=faq22.004.htp

Also, you can use a closure:

foo = 5
baz = 6
def my_handler(*args):
print foo
print baz

dic = {some_handle : my_handler}

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] The row-changed in gtk.TreeModel Signal

2006-08-07 Thread David M. Cook
On Mon, Aug 07, 2006 at 09:10:26AM -0700, Shehnaaz Kagdi wrote:

 2) Whenever this happens -
 self.liststore.append([john,smith,
 blabla,bla]) 
 I would like the treeview to display the latest
 data/row in the liststore

You shouldn't need to call row_changed after an append.  Is your treeview
not getting updated after an append?.  In your case, you would only need to
do that only if, say, you kept a reference to the the list, e.g. 

l = [john, ...]

and changed it via the reference behind the ListStore's back, e.g.

l[0] = bob

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] button queue

2006-07-31 Thread David M. Cook
On Mon, Jul 31, 2006 at 07:11:56AM -0700, Mr Jason Cupp wrote:

 I am pretty new to pygtk.  I wrote a program where there are several
buttons that are connected to a method that plays different wav files using
pymedia.  My problem is that if I keep pressing buttons while a wav is being
played, it queues the events and just keeps playing audio files for the
events that were racked up.  I want a button to only work when an audio file
is not being played.
===

You should make the button insensitive in your click callback, and then
make it sensitive again when the program is ready.  If the button action is
also a menu item, you can use the action API.  See sections 16.1 and 16.7 of
the tutorial.

Dave Cook


___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Implementing command history with a gtk.Entry

2006-07-25 Thread David M. Cook
On Mon, Jul 24, 2006 at 10:47:44AM -0700, N. French wrote:

 My problem is:  how do I catch the up/down arrow keypresses?  I was

I know of two ways to catch the up/down arrows:

- connect to the key-press event
- Create your own Entry subclass with up/down arrow keybindings

See the FAQ for the latter, which is the more elegant solution if you are
not using glade.  Unfortunately, I don't think gtk lets you add keybindings
to an existing instance (i.e. from a glade widget tree), which seems like a
bug to me.

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Bug in TreeView.scroll_to_cell()

2006-07-13 Thread David M. Cook
On Thu, Jul 13, 2006 at 03:21:02PM +0200, Alessandro Pellizzari wrote:

 It works pretty good until circa row 900, showing the cell at the top of
 the treeview, then it begins going wrong, showing cell 930 (or similar)
 at the top and not scrolling down, even for cell, e.g., 1200, which goes
 out of the visible area.

Try doing the scroll_to_cell in an idle_add callback.

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Setting gtk.TreeViewColumn width

2006-07-12 Thread David M. Cook
On Tue, Jul 11, 2006 at 01:26:35PM -0600, Adam Olsen wrote:

 I guess I should have specified that I looked there.  I can only see a way
 to set a max width, a min width, and a fixed width.  I'd just like to set
 the width, but allow the user to be able to resize it as well.

Yeah, you're right, that is confusing.  Here's what I use:

tvc.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
tvc.set_resizable(True)
tvc.set_fixed_width(self.width)

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Setting gtk.TreeViewColumn width

2006-07-11 Thread David M. Cook
On Tue, Jul 11, 2006 at 11:00:50AM -0600, Adam Olsen wrote:
 Is there a way to set gtk.TreeViewColumn widths programmatically?

Yes.  Take a look at the API reference at pygtk.org.

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Need help with Tree/List view

2006-06-10 Thread David M. Cook
On Fri, Jun 09, 2006 at 03:31:49PM -0400, Hussein Vastani wrote:

 Now my question is. How do I indicate to the user which cell in the row is 
 editable. If he/she has selected a particular row, then there is no clear 

This seems to be a problem with a lot of themes that use a really thin, hard
to see focus indicator.  The only way I know how to fix it is to modify the
style to give a thicker more visible focus indicator.  Take a look at the
gtkrc for the LargePrint theme.  You can change this just for the TreeView
widgets in your app.

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] how to install pyGTK

2006-05-30 Thread David M. Cook
On Tue, May 30, 2006 at 09:14:13AM -0700, arya jain wrote:

 am not able to install the graphic tool kit pyGTK from the site

You need to install the following:

Gtk+/Win32 Development Environment:

  http://gladewin32.sourceforge.net/modules/news/
  
pycairo and pygtk:

  http://www.mapr.ucl.ac.be/~gustin/win32_ports/

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] gtk.TreeModelRowIter.next

2006-05-17 Thread David M. Cook
On Tue, May 16, 2006 at 10:54:40PM -0700, Brian wrote:
 It says:
 
 When there are no more rows left the StopIteration exception is raised.
 
 But I can't find out any more about the StopIteration.  ie. where is it
 defined, where do you import it from.  I can't find it in any of the
 gtk.Constants, treeview, treemodel, etc..

It's already loaded into __builtins__, so you don't have to import anything.

dir(__builtins__)

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] New Gtk/PyGtk Book

2006-04-28 Thread David M. Cook
On Tue, Apr 25, 2006 at 11:47:26AM -0700, [EMAIL PROTECTED] wrote:
 I'd definitely love to see a Python/Glade book.  Is there a better way of 
 quickly developing linux apps?

Add in Kiwi and let Gazpacho mature some more, and I'd say no, but I've
never really given PyQt or wxPython much of a chance.  I also really like
the Netbeans/Jython combination for non-native apps.

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] PyGTK on Mac OS X

2006-04-07 Thread David M. Cook
On Thu, Apr 06, 2006 at 04:13:13PM -0400, Pierre Thibault wrote:
 PyGTK is mostly used by Linux users, is it the case?

I think it works fairly well on win32 as well.  On OS X an X Windows System
(X11) server is required as gtk2 has not been ported.  This is included on
the OS X install disc, and it's easy to install and run, but it's not
something I'd expect the average Mac user to be particularly comfortable
with.

Wxpython supposedly has native look and feel on the Mac, but the one
wxpython app I run on my Mac, Audacity, doesn't look altogether quite right
to my eyes.

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] PyGTK on Mac OS X

2006-04-06 Thread David M. Cook
On Wed, Apr 05, 2006 at 05:26:27PM -0400, Pierre Thibault wrote:

*** Could not run GLIB test program, checking why...

Try setting PKG_CONFIG_PATH, e.g.

env 
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig:/usr/X11R6/lib/pkgconfig
 ./configure

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


[pygtk] gtk.binding_entry_add with existing object

2006-03-25 Thread David M. Cook
I want to do something like what's described in 

http://www.async.com.br/faq/pygtk/index.py?req=showfile=faq23.034.htp

except I want to do it for existing entry objects loaded from a glade file.
Is this possible?

TIA,
Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] how to get selected rows at the time user selects a row ('cursor-changed' does not do it)

2006-02-06 Thread David M. Cook
On Mon, Feb 06, 2006 at 10:04:51PM +0200, Nikos Kouremenos wrote:

 thanks Dave. your recipe (hehe Cook :-*) works. /me wonders if PyGTK
 REF says it, else needs to be added in a FAQ

It's in the FAQ:

http://www.async.com.br/faq/pygtk/index.py?req=showfile=faq13.011.htp

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Adding columns to a TreeView/TreeStore?

2006-02-05 Thread David M. Cook
On Wed, Feb 01, 2006 at 03:26:11AM +1100, John Pye wrote:

 The issue appears to be that there is no way of adding columns to a
 *TreeStore* -- so I must copy the data from the existing TreeStore to a
 new one with an extra column, then re-set the model for the TreeView to
 the new TreeStore.

 Is there a better way? I imagine this could be slow in some cases where
 there is a lot of data.

Make your TreeStore have just one column of objects and use a cell data
function for each treeview column.  Then you can dynamically add attributes
for the new columns.  See

http://pygtk.org/pygtk2tutorial/sec-CellRenderers.html#sec-CellDataFunction

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Getting selected rows.

2005-10-06 Thread David M. Cook
On Thu, Oct 06, 2005 at 03:15:21PM +0200, Robert Bigaignon wrote:

 PS : I use PyGTK 1.99, so unfortunately get_selected_rows() is not
 available.

The trick with that old version was to visit each selected row with
TreeSelection.selected_foreach() and save it in a list.  But you really
should upgrade.

Dave Cook

___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] New version of the PyGTK Reference Manual

2005-09-21 Thread David M. Cook
On Tue, Sep 20, 2005 at 10:35:03AM -0700, John Finlay wrote:

 gobject.spawn_async() functions, 

The docs say

  Eventually you must call g_spawn_close_pid() on the child_pid, in order to
  free resources which may be associated with the child process.

Looks like something left over from the C docs?

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Undo and Redo

2005-09-04 Thread David M. Cook
On Sun, Sep 04, 2005 at 09:51:11AM +0200, N. Volbers wrote:

 Look at Documentation and then at the Developer's Guide.  This is a
 very nice introduction to an undo mechanism that basically works like
 this:  If you call an undoable function, then it must return an
 undo-tuple which contains the name of a function f and the appropriate
 arguments x,y,..., so that f(x,y,...) will undo the last action.  This
 will also enable you to offer a redo mechanism for free!

This seems more Pythonic to me than the Java-ish Action base class method.
If you wanted to get fancy, you could use a decorator, so you just decorate
the methods you want un/redoable.

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] what is equal to a list box?

2005-09-01 Thread David M. Cook
On Thu, Sep 01, 2005 at 01:15:42PM -0500, nephish wrote:

 is always down. like what i think a list box is, but cant seem to find that.
 you know, just a box with a list of items that can be selected in it.

You want a TreeView with a ListStore.  See the tutorial.

Dave Cook

___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] progress bar question

2005-08-21 Thread David M. Cook
On Sun, Aug 21, 2005 at 11:20:21PM +0200, dimitri pater wrote:

 def progress_timeout(pbobj):
 new_val = pbobj.pbar.get_fraction() + 0.01
 if new_val  1.0:
 new_val = 0.0
 pbobj.pbar.set_fraction(new_val)

You need to execute a main loop iteration here.

while gtk.events_pending():
gtk.main_iteration()

BTW, you should use spaces instead of tabs for indentation (at least I
assume that's why your indentation is getting lost).

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Documentation recommendations

2005-08-12 Thread David M. Cook
On Thu, Aug 11, 2005 at 05:33:06PM -0400, Andrew Conkling wrote:

 chintzy.  The only other option of which I can think is some HTML
 pages, but I don't know how I'd use them in my program (other than
 launching a browser).  

Well, that might not be so bad.  Take a look at the webbrowser module in the
standard lib.  It tries to be somewhat cross-platform, i.e. using KDE or
Gnome to launch the browser, or the default the user has set in OS X or
windows.

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Documentation recommendations

2005-08-12 Thread David M. Cook
On Fri, Aug 12, 2005 at 07:15:01AM -0400, Andrew Conkling wrote:

 OK, Dave, I'll check it out; thanks.  What would it do in, say, Xfce?

If the default doesn't work, you can fall back on the Netscape('firefox') or
Netscape('mozilla') browser objects, e.g.

# untested code!
import webbrowser
# webbrowser doesn't know firefox yet, but you can use the 
# Netscape('firefox') browser object.
browsersToTry = [webbrowser, webbrowser.Netscape('firefox'), ...]
for browser in browsersToTry:
try:
   browser.open(...)
except webbrowser.Error:
   continue
break
else: # should be executed if we fall thru to the end
popupErrorDialog('Can't find a browser.')

Note that the user can configure the default browser if neccessary with the
BROWSER environment variable.

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Installing pygtk on OS X

2005-08-12 Thread David M. Cook
On Fri, Aug 12, 2005 at 02:23:13PM -0400, Jared Dziedzic wrote:

 I'm having a lot of issues installing pygtk on OS X (10.3). I was wondering 
 how everyone else installed it. Fink ends up messing up python by installing 
 two versions (regular python for Mac, then python on X11). 

Don't install Fink's Python or pygtk.  Just install gtk2 and
then use the setup script in the pygtk source.

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] pyGTK Chapter in new book

2005-08-07 Thread David M. Cook
On Sat, Aug 06, 2005 at 09:22:00PM -0400, Dave Aitel wrote:

 http://www.amazon.com/exec/obidos/tg/detail/-/0764596543/
 
Good job.

If you search inside the book for pygtk, you can read a few pages of that
section.

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] sorting in treeView

2005-08-06 Thread David M. Cook
On Sat, Aug 06, 2005 at 04:29:24PM +, Vinay Reddy wrote:

 In case of a tie while sorting on a particular column other columns
 are considered at all. I want the sorting function to sort based on
 the other columns in case of a tie (in the main column).

Use a sort function.  See the tutorial:

http://pygtk.org/pygtk2tutorial/sec-TreeModelInterface.html#sec-SortingTreeModelRows

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Updating the app

2005-07-06 Thread David M. Cook
On Wed, Jul 06, 2005 at 09:23:44AM -0300, Jose de Paula Eufrasio Junior wrote:

 I'm making a pygtk app and got several fields wich values are inserted
 (like textviews, spinbuttons) and these values can be changed with
 values from other widgets on the app.
 I'm not very friendly to the idea of a 'refresh' button, and like to
 know from you guys what's the best manner to do it...

You probably want to use the Observer pattern.  A simplified Pythonic
version would be something like

def addCallback(self, cb):
self._callbacks.append(cb)
...
def notify(self, *args, **kw):
for cb in self._callbacks:
cb(self, *args, **kw)

You can find a lot fancier variants (e.g. publish/subscribe) of this on the
web.

You can also create your own gobject signals or watch for changes in gobject
properties.

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] need advises on treeview use for memory puprose

2005-07-05 Thread David M. Cook
On Tue, Jul 05, 2005 at 04:10:25PM +0200, [EMAIL PROTECTED] wrote:

 I'm using lot of treeviews.


 Is it better in memory purpose to:
 1. use the gtk.treestore as data storage. (have an entry in the model 
 for each simple type str ... or use a more complex object ?).

It's a lot more flexible and easier to manage to append objects (I use
dictionaries) to the store and then use a data_func to display the data.

Also, If you have large amounts of data, consider implementing the UI with
ListStoress instead of TreeStores.  GTK's TreeStore is just not very
efficient for large datasets.

 2. have an independent data storage. (when a row is selected, we search 
 the name of the selectedComponent, find it in the dataStorage and modify 
 the dataStorage).

Depends on how much data you have and how much the user is expected to
display at any one time.  You would probably want to implement some kind of
lazy loading for a large dataset if they user will only be accessing a small
part of it at any one time.

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] gtk.TreeStore with variable column count ?

2005-06-01 Thread David M. Cook
On Wed, Jun 01, 2005 at 08:54:52AM +, Adrian Immler wrote:

 how can i create a gtk.TreeStore with a variable count of the columns ?
 how can i add/remove columns from a TreeStore ?

I don't think it's possible to add/remove columns from an existing store.  

Instead I would suggest using objects (which could just be dictionaries) in
your TreeStore together with a TreeView data func.  This gives you lots of
flexibility.  Alternatively, you could get a TreeModelFilter from your
model. See the tutorial for more info.

Dave Cook



___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Detect that all windows are closed

2005-05-29 Thread David M. Cook
On Sun, May 29, 2005 at 09:11:34PM +0200, Calle Erlandsson wrote:

 But this create a new problem: When I've closed all the windows the app
 is still running because I haven't run the gtk.main_quit().
 How do I solve this problem?

The function

gtk.window_list_toplevels()

may be helpful here.  Just check after destroying a window for how many are
left.

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Adding large amounts of data to a ListStore

2005-05-26 Thread David M. Cook
On Thu, May 26, 2005 at 03:49:23AM -0400, Jody Steele wrote:

 Currenty I am using the append() function to insert data into my  
 ListStore, and that is all fine and dandy except when the dataset is  
 fairly large (7520 entries in one test).
 
 It ended up taking about 500 seconds to insert all of the data into the  
 list.

It sounds like something is really wrong. I can load over 13000 items into
my ListStore in a few seconds on an AMD64, and about 10 seconds on a 1.5GHz
G4. And this is appending python objects (dictionaries), using a data_func
to render them, and with column autosizing turned on.

Could you give us a few more details about what kind of objects you are
loading into your ListStore and how you are loading them?  Are you doing
anything in between appends?  For example, printing debug info can really
slow things down, so try running your script with python foo  /dev/null.

Dave Cook

___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Adding large amounts of data to a ListStore

2005-05-26 Thread David M. Cook
On Thu, May 26, 2005 at 04:50:35AM -0400, Jody Steele wrote:

 self.list.set_sort_func(0, self.__Sort,(column0.get_sort_order,0))
 self.list.set_sort_func(1, self.__Sort,(column1.get_sort_order,1))
 self.list.set_sort_func(2, self.__Sort,(column2.get_sort_order,2))

I'm guessing these sort funcs are eating up the time. I would keep track of
the total time spent in these sort funcs by incrementing some global
variables.  Or use the profiler.

Dave Cook

___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Inheriting window with widgets

2005-05-18 Thread David M. Cook
On Tue, May 17, 2005 at 06:22:46PM -0400, Samantha wrote:

 2. If #1 is not available, here is what I am trying to do. I have a main
 window with a tree on the left  side of a window. The tree is in a
 table. When the user clicks on a tree widget(?), something happens on
 the right side. I have been able to send a window as an argument to the
 function that does things on the right side of the window, but the
 widgets embedded in the window (being sent as an argument) doesn't
 appear to get inherited. I learned that I cannot have more than one type
 of gtkWidget in a gtkWindow, so I am not sure how I can go about
 accomplishing what I am trying to do. 

This is usually called master/detail.  The tree is your master and the the
right side is the detail.  I'd do this with a paned window, with a notebook
on the right hand side that has Show Tabs set to No (programatically:
notebook.set_show_tabs(gtk.FALSE); I'd leave the tabs visible while
testing).  Each page of the notebook will contain the different widgets you
want to show, so you just have to switch pages in response to the tree
selection to show the correct widget.

Dave Cook



___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Signal emitted when a row in TreeView is selected?

2005-05-15 Thread David M. Cook
On Sun, May 15, 2005 at 04:23:37PM +0100, Magnus Therning wrote:
 I can't seem to find what signal will be emitted when a row in a
 TreeView (with ListStore) is selected. I've tried the following signals:

You connect to the TreeView's selected object's changed signal, then in
your call back you check for what actually is selected.  Assuming multiple
selection mode:

treeview.get_selection().connect(changed, self.on_selection_changed, ...)
...
def on_selection_changed(selection, ...):
model, paths = selection.get_selected_rows()
if paths:
  ...
  
I'm sure this is in the FAQ somewhere.

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] ANNOUNCE: Gazpacho 0.5.3

2005-04-12 Thread David M. Cook
On Mon, Apr 11, 2005 at 12:46:51PM -0300, Christian Robottom Reis wrote:

 This is Kiwi used to do, what Kiwi2 does, 

Kiwi2?  Where?

Dave Cook
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Is there an automated way to create IconSources/IconSets/IconFactories ?

2004-11-19 Thread David M. Cook
On Thu, Nov 18, 2004 at 11:12:48AM -0500, Chris Lambacher wrote:

 I am attempting to use UIManager to generate a ToolBar and a MenuBar.
 I want to add icons that are not stock icons, but UIManger requires
 that you use stock icons.  That means that an IconFactory needs to be
 created for the icons I wish to use.  IconSets need to be added to the
 IconFactory for each icon and IconSources have to be added to the
 IconSets.  I have my icons and I could just write a module to create
 the IconFactory (I want to share the icons between several related
 projects), but given that I can specify my menus and toolbars in XML I
 was wondering if there was a way to do the equivalent for IconFactory
 creation.  Styles obviously do something similar to this.  Can I
 create a partial style and just grab the IconFactory for that style
 and run the set_default method?

I do it the way you describe, and it's a very simple bit if code.  Using XML
seems like it would actually be more work.  (I'd probably use a dictionary,
now instead of a list of tuples.).

  import gtk
  
  '''Registers new icons with gtk.  Tries to use already existing icons
  if they are available, otherwise it loads them from files.'''

  ICON_INFO = [
  ('gnome-stock-mic', 'gnome-stock-mic.png'),
  ('gnome-stock-midi', 'stock_midi.png'),
  ('gnome-stock-attach',  'stock_attach.png'),
  ('classicollect-composer', 'composer.png'),
  ('classicollect-work', 'work.png'),
  ('classicollect-role', 'role.png'),
  ('classicollect-artist', 'artist.png'),
  ('classicollect-performance', 'performance.png')
  ]
  
  def register_iconsets(icon_info):
  iconfactory = gtk.IconFactory()
  stock_ids = gtk.stock_list_ids()
  for stock_id, file in icon_info:
  # only load image files when our stock_id is not present
  if stock_id not in stock_ids:
  pixbuf = gtk.gdk.pixbuf_new_from_file(file)
  iconset = gtk.IconSet(pixbuf)
  iconfactory.add(stock_id, iconset)
  iconfactory.add_default()

  register_iconsets(ICON_INFO)

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Packing widgets inside a Cell

2004-10-27 Thread David M. Cook
On Wed, Oct 27, 2004 at 06:56:19PM -0300, Fernando San Mart?n Woerner wrote:

 I need to pack a gtk.Expander inside a cell in a treeview, is this
 possible?, 

Not currently.  For any particular widget you want in a cell a CellRenderer
needs to be implemented.  gtk+ 2.4 has CellRenderers for text (which can be
editable), pixbufs, and toggle buttons, and 2.6 will have combobox and
progressbar renderers.

 do i use pack_start() method?

pack_start is for packing CellRenderer's into a TreeViewColumn.  

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] ctree look pygtk2.2/gtk2.4

2004-10-21 Thread David M. Cook
On Thu, Oct 21, 2004 at 10:17:44AM -0300, Christian Robottom Reis wrote:

 On Thu, Oct 21, 2004 at 02:12:19PM +0100, Stuart Hughes wrote:
  I did see those, but I wanted the style to have the little box with a 
  '+' in it for unexpanded nodes and '-' for expanded nodes.  Also I 
  wanted little lines connecting them.  
 
 Oh. I believe you can get that effect through styling/themeing; I guess

I don't think you can get the connecting lines that way, though.

Dave Cook

___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] initialize a combo list

2004-10-05 Thread David M. Cook
On Mon, Oct 04, 2004 at 06:22:30AM -0400, Thomas Mills Hinkle wrote:

 Will the refiltering really happen automatically if I just make the
 function call Entry.get_text() directly? (if so, when does this happen?
 If not, I still need to connect the refilter() call to some event)

Ah, I remember now that I had to call model.row_changed to get my filter to
refilter (each row has a visible attribute that can change).  In your case
you might want to connect to the changed signal on the entries and refilter
in your callback.

Dave Cook

___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] initialize a combo list

2004-10-05 Thread David M. Cook
On Tue, Oct 05, 2004 at 05:12:21PM -0400, Thomas Mills Hinkle wrote:

 Okay -- that's what I'd thought. So we return to the problem,
 unfortunately. In my case, connecting to the 'changed' signal is too
 expensive -- it makes response visibly sluggish while the user types.

Yeah, I was thinking that would be a problem.

 So, currently, I'll keep connecting to the focus-out signal on the Entry
 widgets... none of this explains why the ComboBoxEntry and ComboBox
 don't provide signals for the popup event... oh well.

The only other think I can think of is to force the rendering of the popup
to be dynamic by using a modify_func on the filter.  I would have thought
that using a visible_func would be enough for this, but apparently the state
of the model still has to change for it to refilter.

I would put in an RFE in bugzilla.

Dave Cook

___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] initialize a combo list

2004-10-04 Thread David M. Cook
On Mon, Oct 04, 2004 at 05:32:28AM -0400, Thomas Mills Hinkle wrote:

 I am using the ComboBoxEntry but I was still hoping for an answer to the
 above query -- how to connect to the combo-list popup event. In my case,
 I have a very large model which gets filtered based on other
 EntryWidgets in my GUI -- currently I do the filtering when the focus
 leaves the other widgets, but this isn't quite what I want because it
 creates a confusing pause for some users (depending on the speed of
 their system and size of the data their working with). It makes more
 sense for that pause to happen when they click the little arrow on the
 ComboBoxEntry and only then. Is there a way to connect to this event?

I would suggest using a TreeModelFilter with a custom visible func, e.g.

entries = [refs to your entries here]
filter = mymodel.filter_new()
filter.set_visible_func(visible_func, entries)
cbentry.set_model(filter)
...
def visible_func(model, iter, entries):
# test model values against entry values

This should track changes in the model and the entries without any manual
intervention.

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] initialize a combo list

2004-10-03 Thread David M. Cook
On Sun, Oct 03, 2004 at 02:43:58PM +0200, Matthias Teege wrote:

 I have a lot of combo widgets in a small application. The data for the
 combo-list-items come from a database. It is necessary to update the
 combo-lists when the user clicks on the combo item. So I try to
 connect to the button_press event on the combo-widget with
 combo.connect(button_press_event, button_press), but if i click the
 combo nothing happens.

You might consider using ComboBoxEntry instead.  Then you can use a model
for the popup list.  Then you just need to make sure the model tracks the
changes in the database.

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] pygtk + glade: code decomposition best practices?

2004-09-30 Thread David M. Cook
On Thu, Sep 30, 2004 at 01:18:04PM +0300, Ruslan wrote:

 I would like to ask people using pygtk + glade to share their approach
 on code decomposition. For example, there is GUI(made in glade) -
 Notebook with different pages containing a lot of widgets that needs to
 be connected with signals handlers. Having one main class that gets all
 widgets from glade file and contains all signal handlers seems not very
 good approach. Probably for each Notebook page should be created
 separate class to handle GUI signals from page widgets, maybe there is
 some kind of software pattern for handling such cases...
 Anyway if someone has any suggestions/ideas, you are welcome.

I put my XML object in a module, essentially making it globally available in
the application, so I can do

  from myxml import XML # XML is a gtk.glade.XML object
  ...
  foowidget = XML.get_widget('foo')
  XML.signal_connect('on_baz_clicked', self.bazmethod)

allowing me to access the widgets and handlers wherever I need them.

Dave Cook

___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] CList

2004-09-15 Thread David M. Cook
On Tue, Sep 14, 2004 at 02:37:40PM -0400, Jamey Cribbs wrote:

 Every few months, I grab the latest version of pygtk and attempt to 
 duplicate the CList functionality using TreeView, but to no avail.  I 
 have done a lot of reading, attempted to use 
 Liststore/TreeModelSort/TreeView combinations, read up on how to handle 
 large datasets, etc..  Not only does this seem WAY more complicated than 
 it needs to be, it also is slower than the CList.

How large are the datasets we're talking about here, just so we have a
reference?

 Basically, I use the CList as a multi-column listbox to show rows from a 
 database.  I know that this can easily be done using TreeView.  Where it 
 gets complicated is when you want to sort the TreeView or refresh the 
 data from the database and you want the current sort and selected record 
 to be shown.  In other words, when I refresh the view or when I return 
 to the view from editing a single record, I want it to be sorted the 
 same way it was, with the same selected record showing.

First, it's essential to keep clear the distinction between the view and the
model (ListStore in this case).  When you say refresh the view, do you
mean is that you're clearing the model and reloading the data into it?  You
shouldn't need to do this very often.  When you make changes to the model,
they should be automatically reflected in the view.  How are you writing the
data to the model? 

Also, it would help to see some code.

Dave Cook




 This is very complicated using TreeViews, especially because I have 
 resorted to using TreeModelSort in order to try and speed up the very 
 slow sort times when refreshing data in a view.
 
 Anyway, sorry to rant.  I really just want to know how long I can count 
 on CList being in pygtk2.  CList is a great widget and it handles all of 
 my needs just fine.
 
 Thanks.
 
 Jamey
 
 Confidentiality Notice: This email message, including any attachments, is 
 for the sole use of the intended recipient(s) and may contain confidential 
 and/or privileged information. If you are not the intended recipient(s), 
 you are hereby notified that any dissemination, unauthorized review, use, 
 disclosure or distribution of this email and any materials contained in any 
 attachments is prohibited. If you receive this message in error, or are not 
 the intended recipient(s), please immediately notify the sender by email 
 and destroy all copies of the original message, including attachments.
 ___
 pygtk mailing list   [EMAIL PROTECTED]
 http://www.daa.com.au/mailman/listinfo/pygtk
 Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Using ListStores for popup menus (ala ComboBoxEntries)

2004-09-15 Thread David M. Cook
On Wed, Sep 15, 2004 at 06:28:37AM -0400, Thomas Mills Hinkle wrote:

 Currently, I'm using popup menus in TreeViews as a hack since I can't
 pack a ComboBoxEntry into a TreeView. It would be convenient to use the
 same TreeModel for both these popup menus and ComboBoxEntries elsewhere
 inthe UI. Has anyone else implemented this?

For a list or a tree?  Should be pretty trivial for a list.

I've done this for 2 CBE's and a tree with 2 levels.  I catch the selection
event in the first CBE and then set the model for the second CBE to a
TreeModelFilter of the original model re-rooted to the selected row.

Apparently 2.6 will have direct support for tree handling with ComboBoxes so
you don't have to do it this hackish way.

http://www.gtk.org/plan/2.6/

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] IronPython

2004-09-12 Thread David M. Cook
On Fri, Sep 10, 2004 at 08:16:25AM -0400, Dave Aitel wrote:

 Has anyone looked at IronPython? I think you could write a pyGTK that
 used (wrapped) the GTK# libraries so all our great pyGTK programs could
 run on Mono.

http://usefulinc.com/edd/blog/contents/2004/08/24-monoadn-ex/read

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] PyGTK for Mac OS X?

2004-08-19 Thread David M. Cook
On Thu, Aug 19, 2004 at 11:31:35AM +0400, Mikhail Sobolev wrote:

 I looked around for PyGTK port for Mac OS X, and it looks like such a
 thing does not exist (at least, as an official release).  Is my
 impression correct?

Pygtk runs fine under Apple's X11 server

http://www.apple.com/macosx/features/x11/download/

The quickest way to get the gtk libraries under OS X is to install darwinports

http://darwinports.opendarwin.org/

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


[pygtk] Lazy tree implementation

2004-08-19 Thread David M. Cook
Thought I'd share my lazy tree implementation.  The idea is that child rows
in a tree are not filled in until the user clicks on the expander for that
row.  Until then, an single unset row is used as a placeholder for the the
child rows.

http://members.cox.net/davecook/pygtk/LazyTreeStore.py

To use it, you need to structure your tree data as nodes with getChildren()
and hasChild() methods.  An example is show for browsing a filesystem.

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Tutorial Question...

2004-08-08 Thread David M. Cook
On Sun, Aug 08, 2004 at 05:45:38AM -0400, dave wrote:

 Are we supposed to be talking about TreeStore's here instead of liststores?
 
 I'm currently doing a search on a TreeStore:
 for row in treestore:
  if row[0]==searchedthing:
 return row

Here's what I came up with when someone asked about this back on 7/7:

#untested back-of-the-envelope coding!
#Uses the gtk standard of returning False on match.
def search_func(model, col, key, iter, user_data):
value = model.get_value(iter, col)
return value!=key

def search(model, col, key, iter, search_func, user_data):
if search_func(model, col, key, iter, user_data):
for i in range(model.iter_n_children()):
 child = model.iter_nth_child(i)
 search(model, col, key, child, search_func, user_data)
else:
yield iter

it = model.get_iter_first()
mysearch = search(model, 0, 'foobar', it, search_func)
matches = list(mysearch)


Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] PyGTK2 Tutorial v.2.1

2004-07-07 Thread David M. Cook
On Tue, Jul 06, 2004 at 12:06:28PM -0700, John Finlay wrote:

 In addition to receiving comments about tutorial problems, errors and 
 enhancements, I'm interested in hearing from poeple who have used the 
 GenericTreeModel. Specifically, I'm interested in what applications 
 require a custom tree model instead of the standard ones, and what 
 issues they encountered developing and using a custom tree model. Same 
 for the GenericCellRenderer.

Attached is a GenericCellRenderer that I used in my Classicollect app
(ripped out of context and simplified a bit), but not shown is the important
part where you have to take care of sending all the
row-insert/changed/deleted etc. signals.  Note that it doesn't do the
subclassing quite correctly.  I could fix this up into a simple working
example if anyone is interested.

Essentially I implemented this tree (really a forest) the way we were taught
in school: each tree node has its cargo, a reference to the parent node, and
a list of child nodes.

I also keep an index for each node, which is its position its parent's child
list, for efficiently finding the path of a node.  Since get_path doesn't
seem to get called much (by treeviews anyway), this may not be necessary,
and it does add some extra bookkeeping if you remove or insert nodes.

I originally wrote this because I didn't know about
TreeViewColumn.set_cell_data_func, and, well, writing a GTM is kinda fun.
Then I went back to it when I found that cell_data_funcs wouldn't work with
interactive searches (there was no TreeView.set_search_func in pygtk at the
time; when I found out about that it was fixed by gjc within the day!) or
with the new ComboBoxes. Now with TreeModelFilter, I don't think I have any
need for a generic TreeModel, though I haven't had a chance to really test
it with a large data set.  And if this works:

http://bugzilla.gnome.org/show_bug.cgi?id=144509

you have yet another easy way to write a custom TreeStore.




import pygtk; pygtk.require('2.0')
import gtk

# Schematically, nodes look something like this:

class Node:

def __init__(self, parent=None, children=None, data=None,
 index=0, level=None):
self.parent = parent
if children is None: self.children = []
if data is None: self.data = {} # node cargo
self.index = index # index of child
self.level = level # provides info about each depth of the tree 


OUTFILE = sys.stdout

def print_debug(*args):
for arg in args:
print OUTFILE, arg,
print OUTFILE
OUTFILE.flush()


class PyListTreeModel(gtk.GenericTreeModel):

'''A TreeModel using Node objects as its base data structure.'''

def __init__(self, root, *column_types):
'''constructor for the model.  Make sure you call
PyTreeModel.__init__'''
gtk.GenericTreeModel.__init__(self)
self.set_property(leak_references, 0)
self.column_types = column_types
self.ncolumns = len(self.column_types)
self.root = root

def on_get_flags(self):
'''returns the GtkTreeModelFlags for this particular type of model'''
print_debug(on_get_flags)
return 0

def on_get_n_columns(self):
'''returns the number of columns in the model'''
print_debug(on_get_n_columns)
return self.ncolumns

def on_get_column_type(self, index):
'''returns the type of a column in the model'''
print_debug(on_get_column_type, index)
t = self.column_types[index]
return t

def on_get_path(self, node):
'''returns the tree path (a tuple of indices at the various
levels) for a particular node.'''
print_debug(on_get_path, node)
path = []
while node.parent:
path.append(node.index)
node = node.parent
path.reverse()
return tuple(path)

def on_get_iter(self, path):
'''returns the node corresponding to the given path'''
print_debug(on_get_iter:, path)
node = self.root
try:
for i in path:
node = node.children[i]
except IndexError:
node = None
return node

def on_get_value(self, node, i):
'''returns the value stored in a particular column for the node'''
print_debug(on_get_value:, node, i)
level = node.level
try:
value = node.data[level.keys[i]]
except KeyError:
value = level.control_cols[i]
return value

def on_iter_next(self, node):
'''returns the next node at this level of the tree'''
print_debug(on_iter_next, node)
siblings = node.parent.children
try:
next = siblings[node.index+1]
except IndexError:
next = None
return next

def on_iter_children(self, node):
'''returns the first child of this node'''
print_debug(on_iter_children, node)
  

Re: [pygtk] traversing a TreeView

2004-07-07 Thread David M. Cook
On Wed, Jul 07, 2004 at 01:13:28AM +, Christian Bird wrote:

 I've got a question about the best way to iterate over the items in a
 TreeView starting with an arbitrary item in the treeview.  I'm trying

#untested back-of-the-envelope coding!  
#Uses the gtk standard of returning False on match.

def search_func(model, col, key, iter, user_data):
value = model.get_value(iter, col)
return value!=key

def search(model, col, key, iter, search_func, user_data):
if search_func(model, col, key, iter, user_data):
for i in range(model.iter_n_children()):
 child = model.iter_nth_child(i)
 search(model, col, key, child, search_func, user_data)
else:
yeild iter


mysearch = search(model, 0, 'foobar', it, search_func)
matches = list(mysearch)


___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


[pygtk] Fun with TreeModelFilter

2004-07-03 Thread David M. Cook
This class solved a problem that has been bothering me for a long time: how
to do interactive searches when your store contains only objects.  The
TreeView wants to access a column of strings to do this.  Also, the new
ComboBoxEntry can use a TreeModel, but again it wants to access a column
directly to get its text.

This is where TMF comes in.  Not only can you filter a model, but it also
lets you synthesize completely new columns.  Jon Finlay's amazing tutorial
does a good job covering TMF:

http://tinyurl.com/2qjn9

The other solutions I came up with were writing a custom TreeModel (requires
keeping track of a lot), and keeping a redundant string column that is kept
synchronized with the object column using the Observer pattern.

And here's some code showing how TMF can be used in this case:

import gtk

class Node(object):

def __init__(self, name):
self.name = name

def __str__(self):
return self.name


def modify_func(model, iter, col):
child_iter = model.convert_iter_to_child_iter(iter)
child_model = model.get_model()
return child_model.get_value(child_iter, 0)

def print_nodes(model):
it = model.get_iter_first()
while it:
print model.get_value(it, 0), repr(model.get_value(it, 1))
it = model.iter_next(it)

store = gtk.ListStore(object)

# ModelFilter synthesizes a string column using the modify func.
# This string column can be used for interactive searches and ComboBoxes.
filtered = store.filter_new()
filtered.set_modify_func((str, object), modify_func)

# put objects in the store
nodes = map(Node, ['larry', 'bill', 'scott'])
for node in nodes:
it = store.append()
store.set_value(it, 0, node)
print_nodes(filtered)

# modify the objects
for node, name in zip(nodes, ['guido', 'linus', 'james']):
node.name = name
# does the ModelFilter track our changes?
print_nodes(filtered)
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Progress Cell Renderer

2004-06-25 Thread David M. Cook
On Fri, Jun 25, 2004 at 04:32:30PM +0200, Lorenzo Gil Sanchez wrote:

 I'm not sure what do you mean. There is a bug in GTK+ about having a
 CellRendererCombo: 
 
 http://bugzilla.gnome.org/show_bug.cgi?id=139347
 
 Wrapping it in pygtk after that would be pretty easy.
 
 If you mean if we have a bug about full support to subclass gobjects in
 pygtk I think there is no such a bug but I may be wrong.

There are various bug reports scattered around relating to this, but I think
this is the mother of them all:

http://bugzilla.gnome.org/show_bug.cgi?id=129843

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Progress Cell Renderer

2004-06-24 Thread David M. Cook
On Wed, Jun 23, 2004 at 11:39:21AM -0300, Gustavo Niemeyer wrote:

 I haven't found this anywhere, so I thought someone else might
 be interested as well. Here is a cell renderer which mimicks
 progress bars, based on current gtk+ code.

Has anybody done a cell renderer for combo boxes?

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] treeview typeahead

2004-06-11 Thread David M. Cook
On Wed, Jun 09, 2004 at 08:33:27PM +0200, Danny Milosavljevic wrote:

 Can this internal search box be called(shown) per code (i.e. on first
 keypress, on toolbutton) ?

I don't know, I can't find an API for it.  You might want to ask for the
feature in bugzilla.

Dave Cook
 
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Subclassing GtkWidget in PyGTK

2004-06-08 Thread David M. Cook
On Fri, Jun 04, 2004 at 01:35:37PM +0200, Johan Dahlin wrote:

 That demonstrates how to subclass a GtkWidget in PyGTK.

What about when constructors require arguments?  Is this still an issue?

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] MVC and TreeView

2004-06-05 Thread David M. Cook
On Fri, Jun 04, 2004 at 11:11:28PM +0100, Jonathon McKitrick wrote:
 
 Hi David,
 
 the tips you gave me were very helpful.  I have a working prototype now that
 has helped me understand the basics.  But what if I want to still have
 multiple columns?  I'm still not quite sure where those should be added or
 accounted for.

When you set the cell_data_func, you can pass in an index, and then in your
callback return different object attributes based on the index.

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] MVC and TreeView

2004-06-04 Thread David M. Cook
On Fri, Jun 04, 2004 at 06:20:04PM +0100, Jonathon McKitrick wrote:

 if I have a set of objects and show their properties in a TreeView, is it
 better to change the original objects then rebuild the ListStore, or extract the
 changes from the ListStore and modify the original objects?

Best to avoid redundancy altogether if you can by directly using your objects.

You can put the actual objects in the ListStore and then set the cell
contents using a callback as described in the FAQ.  

http://www.async.com.br/faq/pygtk/index.py?req=showfile=faq13.029.htp

This is the easiest way to do it, but you lose interactive searches (which
must be on a text column in the TreeModel.)

Or you can write a custom TreeModel that returns values from your objects.
This is more work since you have to write all the model methods and are
responsible for sending out the right signals when the model changes.

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Storing a TreeView

2004-04-03 Thread David M. Cook
On Sat, Apr 03, 2004 at 11:00:40AM +0200, Nemesis wrote:

 Hi all,
I'm writing a newsreader with python+pygtk. I'm using a TreeView
 in order to show the articles (in a threaded fashion). I'd like to
 store the model so I don't have to rebuild the threads every time I
 select the group.
 I've tried pickling the TreeModel, but it isn't picklable. How can
 I store this information?

Options I can think of:

1. Traverse the tree (TreeModel.foreach and TreeModel.get_value) 
   and save each node.  You can use the path as a key, and it's then
   easy to rebuild the TreeModel.
   
2. Save nodes in the tree as they are added.  It may help to subclass
   TreeStore.
   
3. Write you own TreeModel that can be persisted at once.

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Storing a TreeView

2004-04-03 Thread David M. Cook
On Sat, Apr 03, 2004 at 02:12:28PM +0200, Nemesis wrote:

 Hmm, I think that the n.1 is the most simple, but however you have to
 cicle the list and rebuild the tree, as far I can see.
 I'm not sure I understood n.2, 

The idea is to subclass TreeStore and override TreeStore.set/set_value (and
also TreeStore.remove if you are deleting nodes) so that you save data every
time set_value is called. 

But why persist the store, why not just keep it in memory and use
TreeView.set_model to change stores?  Do you really need to save the headers
in between sessions?

Dave Cook


___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] How to focos a TreeView's cell?

2004-03-13 Thread David M. Cook
On Sat, Mar 13, 2004 at 01:45:58AM -0600, Mauricio Téllez wrote:

 Hi, I have a ListStore with 3 column of type gobject.TYPE_STRING, the
 first and thirth columns are editable, but the second is not. I have an
 Add button that when I click it append a new row to the model, so I
 want that the first cell in the view's new row get selected and ready to
 insert text (as if I clicked the cell), and that when I finished with

Use TreeView.set_cursor() and TreeView.scroll_to_cell().  I've found that I
had to put the scroll_to_cell in an idle callback to make it work right
(this may be because of the old gtk in RH9).

view.set_cursor(newpath, viewcol, gtk.TRUE)
gtk.idle_add(scroll_to_cell, view, newpath, viewcol)

def scroll_to_cell(view, path, viewcol):
view.scroll_to_cell(path)

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] PyGtk usage question

2004-03-13 Thread David M. Cook
On Fri, Mar 12, 2004 at 02:00:21PM -0600, Alex Roitman wrote:

 pygtk is in Debian since very long ago. Debian has arguably one of the

And in Red Hat since they've used it for their installer and admin tools for
years (since 6.0 or thereabouts IIRC).

Dave Cook

___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Selection issues with TreeModelSort

2004-03-11 Thread David M. Cook
On Thu, Mar 11, 2004 at 04:43:33PM -0700, Don Allingham wrote:

 I have created a custom tree model, derived from GenericTreeModel. I use
 text strings as iters for the model. This is working well. When I get
 the current selection, I get the string that I was using as an iter.
 
model = MyModel()
tree.set_model(model)
selection = tree.get_selection()
 
return_is_string = selection.get_selected()

I don't see how that works, it sounds like a fortuitous bug.  In C, a
TreeIter is an opaque structure.  You should still have to do a get_value to
get an actual usable value.

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Tooltips inside a TreeView

2004-02-09 Thread David M. Cook
On Mon, Feb 09, 2004 at 11:39:37AM +, Graham Ashton wrote:

 I was wondering if it's possible to do row specific tooltips.

See http://bugzilla.gnome.org/show_bug.cgi?id=80980

Though this is per cell.  Don't know if per row is possible.

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] ComboCellEditor

2004-01-17 Thread David M. Cook
On Fri, Jan 16, 2004 at 03:52:09PM -0200, Christian Robottom Reis wrote:

 Aren't there bugs open on this subject? This has been discussed at
 length here, and IIRC there was some consensus that something needs to
 be fixed (in PyGTK, IIRC). As to whether you should rewrite the

Doesn't gtk 2.3 now have a combobox that implements CellEditable?

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] TreeView, Windows Look Feel

2004-01-05 Thread David M. Cook
On Fri, Jan 02, 2004 at 09:40:58AM +0800, Bert Marco Schuldes wrote:

 Icons and especially visible lines connecting 
 the nodes of the tree.

I think that's what this RFE is about:

http://bugzilla.gnome.org/show_bug.cgi?id=106406

But there seems to be some confusion there between grid lines as in a
spreadsheat and connecting lines between tree nodes.

I'm pretty sure the lines aren't possible.  Depending on the nodes in your
tree, using different pixmaps at each level on the tree may help users to
figure out where they are in the tree.  See the FAQ for some examples.

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Some gtk-noob TreeStore problems :]

2003-12-31 Thread David M. Cook
On Tue, Dec 30, 2003 at 10:14:19PM +0100, Daniel Kirkegaard Mouritsen wrote:
 Hey everybody,
 
 I'm having problems with the gtk.CellRendererToggle() renderer, I have a
 TreeStore with three column defined like this:
 
 tree_store = gtk.TreeStore(gobject.GObject, gobject.TYPE_STRING,
 gobject.TYPE_STRING)

You need a gobject.TYPE_BOOLEAN for the toggle buttons unless you are using
TreeViewColumn.set_cell_data_func().

 Ive connected the toggled signal to a function, but when i
 activate/deactivate the toggle it applies the changes to all the
 toggles.

What does your callback look like?

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] signal on title colum of GtkTreeView

2003-11-13 Thread David M. Cook
On Thu, Nov 13, 2003 at 12:12:34PM +0100, Harobed wrote:

 I would like to show popup window when I click on title column of
 TreeView.

The TreeViewColumn object has a clicked signal:

http://tinyurl.com/uuke (scroll to the bottom)

So that you know which column was clicked, you can either attach data to the
TreeViewColumn or pass user data in when you connect the signal (for example
a key or column number).  You'll usually do this when adding the columns to
the TreeView.

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


[pygtk] Avoiding extra space in rows without icons in treeview

2003-11-08 Thread David M. Cook
I have a treeview/treemodel with icons for the first column of each row,
using TreeViewColumn.pack_start (works great; thanks guys!).  However, I'd
like some rows to not have icons.  I tried putting None for the pixbuf in my
treemodel for those cases, which works, but it leaves quite a bit of space
where the icon would have been.  Is there a way around this, perhaps by
creating an empty pixbuf?

Thanks,
Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] How to remove a row from a GTK.ListStore?

2003-11-01 Thread David M. Cook
On Sat, Nov 01, 2003 at 12:52:56PM -0500, Hans Deragon wrote:

   Newbie here.  I tried to figure out how to remove a row from a 
 GTK.ListStore  on the web (documentation and mailing list archives), but I 
 could not figure it out.  The documentation is pretty poor.
 
   What I want to figure out is how can I get the iter required by 
 GTK.ListStore.remove()?  I have a GTK.TreeView with at GTK.ListStore as a 
 Model.  I want to remove the row that has been selected by the user.  How 
 do I proceed?  How do I obtain the iter that points to the currently 
 selected item? It must be easy, but I cannot find the function that would 
  return the iter.

TreeView contains a selection object that manages user selections.  You need
to get the selection object, then query it for the selected path with the
get_selected() method.  For single selection mode:

selection = treeview.get_selection()
result = selection.get_selected()
if result: #result could be None
   model, iter = result
model.remove(iter)

For multiple selection mode you need to use a little hack to get the
selected paths until get_selected_rows() is implemented (2.2 API):

rows = []
selection.selected_foreach(lambda model, path, iter: rows.append(path))

rows will then be a list of selected paths, and you can use
model.get_iter(path) to get the iters.  Note that this hack will work with
either selection mode, so I use it everywhere instead of get_selected().

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] hide certain rows in treeview

2003-10-13 Thread David M. Cook
On Thu, Oct 09, 2003 at 10:43:54AM -0700, Yang Zheng wrote:

 Is it possible to not show certain rows in a treeview that is attached
 to a treestore?  I know you can display only certain columns, but what
 if there are some rows in a treestore structure that I do not want to be
 displayed?  Can I set a flag and have it skipped?

There's no way to do this currently without copying to another treestore.
gtk 2.4 will have a FilteredTreeModel that does this.

http://www.gtk.org/plan/2.4/

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] nonstandard widgets in pygtk?

2003-10-13 Thread David M. Cook
On Tue, Oct 07, 2003 at 11:36:36AM -1000, Tim Newsham wrote:

 Hi,  I would like to compile some nonstandard gtk extensions 
 written in C into pygtk.  What is involved in this process?
 Is there any documentation that covers pygtk internals?  Are
 interfaces generated or defined manually?

This may be helpful:

http://www-106.ibm.com/developerworks/linux/library/l-wrap/

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] hide certain rows in treeview

2003-10-13 Thread David M. Cook
On Thu, Oct 09, 2003 at 11:10:09AM -0700, David M. Cook wrote:
 On Thu, Oct 09, 2003 at 10:43:54AM -0700, Yang Zheng wrote:
 
  Is it possible to not show certain rows in a treeview that is attached
  to a treestore?  I know you can display only certain columns, but what
  if there are some rows in a treestore structure that I do not want to be
  displayed?  Can I set a flag and have it skipped?
 
 There's no way to do this currently without copying to another treestore.
 gtk 2.4 will have a FilteredTreeModel that does this.

However, it occurs to me that it may be possible to implement your own
FilteredTreeModel as a custom TreeModel.

Dave Cook


___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Several TreeViews with Common Model

2003-09-29 Thread David M. Cook
On Mon, Sep 29, 2003 at 10:36:40AM +0700, mige wrote:

 I'm trying to use a treemodel [store]  in both views (showing as a tree 
 and a list), just like file explorer.
 The tree view is working fine.
 But, I need to show the direct childrens in the list view if I click the 
 node. Is there any way not to copy the model ? So, no need creating new 
 model. May be just passing the node as (sub) treemodel [as list-store] 
 for the list view ?

I don't know a way to do that currently without writing your own treemodels,
which is not hard. Then you can have instances of MyTreeStore and
MyListStore that reference the same underlying data structure.

Dave Cook

___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] 'About' strangeness.

2003-09-01 Thread David M. Cook
On Mon, Sep 01, 2003 at 12:40:11AM -0700, Colin Fox wrote:

 In addition to my previous message about the missing yellow star in the
 About menu, the Gnome About dialog itself is causing me some grief.
 
 If I show the about box, then dismiss it, then show it again, my program
 aborts immediately with a segfault. No traceback stack or anything. I've
 tried handling the 'response' and 'close' signals (hiding the dialog 
 returning gtk.TRUE), to no avail.

You also need to handle the delete_event signal and keep it from propagating
by returning gtk.TRUE.

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Help with passing parameteres to a callback routine(newbie)

2003-08-24 Thread David M. Cook
On Sat, Aug 23, 2003 at 02:16:43PM +0100, Peter Stokes wrote:

 I am a newbie to Python and Pygtk, so please bear with me if this is the
 millionth time you have been asked this.
 
 I have written my first program with Radio buttons and need to
 understand how do I pass AND use a a parameter by reference (list called
 Company), 

Since variables are always references in python, so are all function
parameters.  As long as you pass a mutable object like a list, dict, or
user-defined object, you should be able to change it in your callback; so
something else is going on here.  I'd put a print in the callback to see
whether the condition is ever met for the insert to happen.

Dave Cook

___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Embedding a widget in a CellRenderer

2003-08-22 Thread David M. Cook
On Fri, Aug 22, 2003 at 03:57:41AM +0200, Nicholas Wieland wrote:

 Ehm ... I've posted this request after having read 99% of the mailing list
 archives, now I've found the answer in the last 1% ...
 Sorry for that, and thanks to Lorenzo Gil Sanchez ...

Sounds like it should be a FAQ.  Do you have a link to the enlightening post?

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


[pygtk] pygtk article in September Linux Journal

2003-08-15 Thread David M. Cook
by Dave Aitel.  Good exposure for pygtk.  And it's on the web:

http://www.linuxjournal.com/article.php?sid=6586

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] bug in TreeView?

2003-07-30 Thread David M. Cook
On Wed, Jul 30, 2003 at 06:19:00PM +0200, Emanuele Olivetti wrote:

 if you select a node, click 'Choose parent' and select the same
 node in the parent list you get a core.
 
 Configuration: LinuxBox with gtk+-2.0.9 and pygtk-1.99.16

Seems to work OK with gtk+-2.2.1.  gtk+-2.0 had all sorts of treeview bugs.
Even gtk+-2.2.0 had some severe ones.

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] GtkTree documentation

2003-07-27 Thread David M. Cook
On Sun, Jul 27, 2003 at 03:05:47AM -0700, Colin Fox wrote:

 Is there any documentation or examples that show how to use the new
 GtkTree code in python? Especially with a libglade generated interface?
 
 A working tree example would be ideal. 

There's a tutorial here:

http://liw.iki.fi/liw/texts/gtktreeview-tutorial.html

Don't forget the examples that come with the pygtk distribution.  I whipped
up my own example of a multi-column treeview.  It demonstrates a few things:

* How make certain cells editable.  Here I use two control columns
  at the end of my row (store column 2  3) that control whether a cell
  is editable and visible.  How the renderer uses these columns is set with
  
column = gtk.TreeViewColumn(column_titles[i], cell, text=i,
editable=ncols+i, visible=ncols+i)

  which means that the renderer will get the text to render from column i
  and determine whether the cell is editable and visible using the 
  values in column ncols+i.  See the properties for the different
  renderers to see what other keywords you can use.
  
* A callback for the edited signal which actually sets the new text
  that you type in a cell.  I use set_data/get_data to retrieve the 
  actual store column that the renderer corresponds to (you could also
  pass it as user_data when connecting the callback).
  
* How to get a selection, this is in the on_delete_button_clicked callback.

Dave Cook  



try:
import pygtk; pygtk.require('2.0')
except:
# Hope for the best...
pass
import gobject
import gtk
from gtk import mainquit
import gtk.glade

GLADEFILE = 'simple_treestore.glade'
COLUMN_TITLES = ('Composer', 'Title')
COLUMN_TYPES = [gobject.TYPE_STRING]*2 + [gobject.TYPE_BOOLEAN]*2

treedata = [[0, 'Mahler, Gustav', 1, '', 2, 1, 3, 0],
[0, '', 1, 'Symphony No 1', 2, 0, 3, 1],
[0, '', 1, 'Symphony No 9', 2, 0, 3, 1],
[0, 'Prokofiev, Sergei', 1, '', 2, 1, 3, 0],
[0, '', 1, 'Alexander Nevsky', 2, 0, 3, 1],
[0, '', 1, 'Piano Concerto No 3', 2, 0, 3, 1],
[0, 'Bartok, Bela', 1, '', 2, 1, 3, 0],
[0, '', 1, 'Concerto for Orchestra', 2, 0, 3, 1],
[0, '', 1, 'String Quartet No 5', 2, 0, 3, 1]]


def on_delete_button_clicked(treeview):
selection = treeview.get_selection()
select_tuple = selection.get_selected()
if select_tuple:
store, iter = select_tuple
store.remove(iter)

def edited_callback(renderer, path_string, newtext, treeview):
colno = renderer.get_data('colno')
if colno!=None:
indices = path_string.split(':')
path = tuple( map(int, indices) )
store = treeview.get_model()
iter = store.get_iter(path)
store.set_value(iter, colno, newtext)

def add_columns(treeview, column_titles):
ncols = len(column_titles)
for i in range(ncols):
cell = gtk.CellRendererText()
column = gtk.TreeViewColumn(column_titles[i], cell, text=i,
editable=ncols+i, visible=ncols+i)
cell.set_data('colno', i)
cell.connect(edited, edited_callback, treeview)
treeview.append_column(column)

def init_store(store, rows):
for row in rows:
if row[-1]==0:
iter = store.append(None)
parent = iter
else:
iter = store.append(parent)
store.set(iter, *row)

def main():
xml = gtk.glade.XML(GLADEFILE)
treeview = xml.get_widget('treeview')
add_columns(treeview, COLUMN_TITLES)
xml.signal_autoconnect(globals())
store = gtk.TreeStore(*COLUMN_TYPES)
init_store(store, treedata)
treeview.set_model(store)
gtk.main()

if __name__=='__main__':
main()





?xml version=1.0 standalone=no? !--*- mode: xml -*--
!DOCTYPE glade-interface SYSTEM http://glade.gnome.org/glade-2.0.dtd;

glade-interface

widget class=GtkWindow id=window1
  property name=visibleTrue/property
  property name=title translatable=yeswindow1/property
  property name=typeGTK_WINDOW_TOPLEVEL/property
  property name=window_positionGTK_WIN_POS_NONE/property
  property name=modalFalse/property
  property name=default_width240/property
  property name=default_height240/property
  property name=resizableTrue/property
  property name=destroy_with_parentFalse/property
  signal name=delete_event handler=mainquit last_modification_time=Sun, 27 Jul 
2003 12:15:57 GMT/

  child
widget class=GtkVBox id=vbox1
  property name=visibleTrue/property
  property name=homogeneousFalse/property
  property name=spacing0/property

  child
widget class=GtkScrolledWindow id=scrolledwindow1
  property name=border_width3/property
  property name=visibleTrue/property
  property name=can_focusTrue/property
  property name=hscrollbar_policyGTK_POLICY_AUTOMATIC/property
  property name=vscrollbar_policyGTK_POLICY_AUTOMATIC/property
  

Re: [pygtk] GtkTree documentation

2003-07-27 Thread David M. Cook
On Sun, Jul 27, 2003 at 10:01:15AM -0600, Jim Ray wrote:
 In the attached example how would you ensure that the parent always is 
 bold?

You can use markup:

treedata = [[0, 'bMahler, Gustav/b', 1, '', 2, 1, 3, 0],
[0, '', 1, 'Symphony No 1', 2, 0, 3, 1],
[0, '', 1, 'Symphony No 9', 2, 0, 3, 1],
[0, 'bProkofiev, Sergei/b', 1, '', 2, 1, 3, 0],
[0, '',1, 'Alexander Nevsky', 2, 0, 3, 1],
[0, '', 1, 'Piano Concerto No 3', 2, 0, 3, 1],
[0, 'bBartok, Bela/b', 1, '', 2, 1, 3, 0],
[0, '', 1, 'Concerto for Orchestra', 2, 0, 3, 1],
[0, '', 1, 'String Quartet No 5', 2, 0, 3, 1]]
...
column = gtk.TreeViewColumn(column_titles[i], cell, markup=i,
editable=ncols+i, visible=ncols+i)

Or you can use the weight attribute:

import pango
...
treedata = [[0, 'Mahler, Gustav', 1, '', 2, 1, 3, 0, 4, pango.WEIGHT_BOLD],
[0, '', 1, 'Symphony No 1', 2, 0, 3, 1, 4, pango.WEIGHT_NORMAL],
[0, '', 1, 'Symphony No 9', 2, 0, 3, 1, 4, pango.WEIGHT_NORMAL],
[0, 'Prokofiev, Sergei', 1, '', 2, 1, 3, 0, 4, pango.WEIGHT_BOLD],
[0, '', 1, 'Alexander Nevsky', 2, 0, 3, 1, 4, pango.WEIGHT_NORMAL],
[0, '', 1, 'Piano Concerto No 3', 2, 0, 3, 1, 4, pango.WEIGHT_NORMAL],
[0, 'Bartok, Bela', 1, '', 2, 1, 3, 0, 4, pango.WEIGHT_BOLD],
[0, '', 1, 'Concerto for Orchestra', 2, 0, 3, 1, 4, pango.WEIGHT_NORMAL],
[0, '', 1, 'String Quartet No 5', 2, 0, 3, 1, 4, pango.WEIGHT_NORMAL]]
...
column = gtk.TreeViewColumn(column_titles[i], cell, text=i,
editable=ncols+i, visible=ncols+i,
weight=ncols+2)


Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Context Menu in CellRendererText

2003-07-24 Thread David M. Cook
On Wed, Jul 23, 2003 at 06:55:36AM -0700, David Mortensen wrote:

 My question is this:  is there a simple way I can keep the right click event 
 from triggering an edited signal?  Is there some other means for getting my 
 desired result (pop-up menu and updates on edits)?

You should be able to prevent the event from propogating by returning
gtk.TRUE from your button-press-event callback.

http://tinyurl.com/hvzy

untested code:

def on_button_press_event(self, widget, event):
if event.type==gtk.gdk.BUTTON_PRESS and event.button==3:
   # do stuff
   return gtk.TRUE

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Edit a cell in response to menu?

2003-07-09 Thread David M. Cook
On Wed, Jul 09, 2003 at 08:51:24PM +0100, Stephen Kennedy wrote:

 When a cell is set to be editable, how
 do I actually set it into the 'editing'
 state?

view.set_cursor(path, viewcol, gtk.TRUE)

 gtk_cell_renderer_start_editing takes
 a lot of lowlevel parameters and at this
 stage there is no gdkEvent to pass on.
 
 def on_rename_activate(self, menuitem):
 path = self._get_selected_paths()[0]
 iter = self.model.get_iter(path)
 self.model.set_value(iter, EDITABLE_COLUMN, 1)

  # get the TreeViewColumn, viewcol, that corresponds 
  # to this store column
  self.view.set_cursor(path, viewcol, gtk.TRUE)
  
Dave Cook

___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


[pygtk] Problem with stock icons on Mandrake 9.1 not showing up

2003-07-06 Thread David M. Cook
I've been testing an application (created with glade2 on RH 9) on various
distros and on Mandrake 9.1 I have a problem with stock icons in my toolbar
not showing up (such as gnome-stock-midi, gnome-stock-mic, and
gnome-stock-attach, and gnome-stock-text-bulleted-list).  I also get the
warning:

(glade-gnome-demo:15363): GLib-GObject-WARNING **: gobject.c:946: object
class GnomeProgram' has no property named default-icon'

I also tested by mocking up a gnome app with the glade2 in Mandrake and
adding toolbar buttons with those stock icons.  Same problem, despite that
fact that the icons are visible in glade.

I'm using the gnome libs that Mandrake 9.1 comes with, but gnome-python from
CVS.

Any ideas on this one?

Dave Cook




___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Problem with iter and Tree/list model

2003-06-20 Thread David M. Cook
On Tue, Jun 17, 2003 at 10:12:29PM +0200, Thomas Sonne Olesen wrote:

 What is the difference between:
   iter = self.append ()
 self.set (iter, 0, ref)
 and 
   iter = self.append ()
 self.set_value (iter, 0, ref)

set_value is for a single value, and set is for 1 or more values:

set(iter, 1, 'bob', 3, 'harry', 5, 20)

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Problem with iter and Tree/list model

2003-06-18 Thread David M. Cook
On Tue, Jun 17, 2003 at 10:12:29PM +0200, Thomas Sonne Olesen wrote:

 File /usr/local/bin/pyblink, line 104, in save
   r=self.get_value(iter,0)
   TypeError: iter must be a GtkTreeIter

Try putting a 

print `iter`

here (with backticks, or use repr()) to see whether the iter is None at this
point.

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] libglade questions

2003-06-06 Thread David M. Cook
On Fri, Jun 06, 2003 at 12:41:52PM +0300, Ionutz Borcoman wrote:

 Q: Do I need to parse the glade file in every class ? 

You could do this, or you could pass the XML object around, or you could get
the widgets you need in one place and pass them to where they are needed.  

  xml = gtk.glade.XML(GLADEFILE)
  foo_widget = xml.get_widget('foo')
  baz_object = Baz(foo_widget)
  xml.signal_autoconnect(baz_object)

 With what
 parameters ? How do I get a class for the app1, one for about2 and one
 for window1 ? 

Just use get_widget to get these widgets from the tree by name.  Gtk is not
a framework like Qt; you don't sublcass any framework classes.

 Q: What restrictions do I have to consider when setting the callback
 names in glade ? What is the scope of handler names defined in Glade ?

There is just one namespace, so you do have to be careful to use unique
names for things you want to be unique.

 Can I use the same handler name for different handler in different
 objects ? 

http://www.async.com.br/faq/pygtk/index.py?req=showfile=faq03.001.htp

 Is the  'delete' handler for clicked on button4 different from
 that defined for window1 or are they the same ? 

If you give then the same name, 'delete', the handlers are the same.  The
names aren't qualified in the glade file.

You *can* use the same name for the handler.  Howerver, whatever callback
you connect to the handler will get called when either signal is emitted.
If that's not what you intend, give the handlers unique names (if you give
your widgets unique names, this is the default behavior.) 

 Is the 'delete' handler
 for app1 different from that for 'delete' handler for window1 ?

Ditto.  But, again, by default these will be given different handler names:
'on_app1_delete_event' and 'on_window1_delete_event'.

 Q: Can I turn the notebook1 and notebook2 into custom classes ? How do I
 do that ? 

I think you mean objects rather than classes, right?  (Unless you do want
different behavior for each notebook).

You can't inherit from already existing widget objects, but you can use
aggretation or delegation:

class NotebookController(object):

  def __init__(self, notebook):
  self.notebook = notebook
  ...
  
  def foo(self, bar):
  self.notebook.foo(bar)

notebook1 = NotebookController(xml.get_widget('notebook1'))

 Can I use handlers defined in glade in my custom classes ?

Sure, see the FAQ entry above for one way to do it.

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] [Announce] msnp.py 0.3 released

2003-06-01 Thread David M. Cook
On Sun, Jun 01, 2003 at 11:54:25AM +1000, Malcolm Tredinnick wrote:

 We don't get a lot of off-topic stuff on this list, so others may not
 mind. But I keep missing the bit where this announcement relates to
 PyGTK. It's a protocol library, right? Not a GUI?

Maybe it's a subtle request for a pygtk frontent.

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Treeview with boolean checkboxes

2003-03-30 Thread David M. Cook
On Sat, Mar 29, 2003 at 11:33:49AM -0700, Jay Graves wrote:

 I have a project where I am using a treeview where one of the columns is
 a boolean (check box) field.  The behaviour I want is for only one check
 box to be checked at any time.  So if the user checks row 2 and then
 checks row 8, row 2 is automatically unchecked.  Is there a
 gtkTreeViewColumn setting that will set the functionality or is it
 something I will have to do manually?

What you want are radio buttons.  I haven't tried this, but from the docs,
it looks like you would use radio instead of active when adding a column:

cell = gtk.CellRendererToggle()
tvcolumn = gtk.TreeViewColumn('foo', cell, radio=RADIOCOLUMN)

However, it's not clear to me whether the radio buttons have to be grouped
or whether this does it for you.  See the FAQ:

http://www.async.com.br/faq/pygtk/index.py?req=all#9.1

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Should PyGtk be proposed for the Python 2.4 release?

2003-03-24 Thread David M. Cook
On Mon, Mar 24, 2003 at 02:52:32AM -0500, Eric S. Raymond wrote:

 The biggest weakness of PyGTK at this moment is woefully inadequate
 documentation.  The API documentation is simply not up to the standard of
 detail and clarity expected in a Python standard library.

Tkinter was part of the standard library *long* before there was adequate
documentation for it.  There is still not much in the standard library docs.
This is no excuse for the present situation with pygtk, but it does indictate
that standards for inclusion in the library have not always been that
stringent.

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Is there a guide how to program with pygtk?

2003-03-14 Thread David M. Cook
On Tue, Dec 21, 2004 at 10:29:17PM -0200, Michel wrote:
 Hi Guys!
 
 I want to program in pygtk but I didn't find a guide, I read the faq
 and some examples but I want a reference guide...

See FAQ item 1.7.

 Tell me if the pygtk is very unlike tkinter... 
 I used tkinter to make guis and
 I think it's easy to work, is the pygtk so easy?

pygtk is not as easy as tkinter, but it has a lot more features and is
faster.

The broad concepts (event driven programming) are still the same.  I don't
think there's anything you need to *unlearn*.

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Tutorial translations.

2003-02-25 Thread David M. Cook
On Mon, Feb 24, 2003 at 05:22:57PM -0800, John Finlay wrote:

 I converted most of these as well for the PyGTK tutorial at 
 http://www.moeraki.com/pygtktutorial/index.html

I was thinking of doing a TreeView/Model tutorial covering more ground than
the one that's already out there.  What kind of formats will you accept
submissions in?  

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Tutorial translations.

2003-02-25 Thread David M. Cook
On Tue, Feb 25, 2003 at 05:38:03PM -0300, Christian Reis wrote:

 Lars W. wrote a tutorial on it, 

Yes, I wanted to pick up where that one left off.  Also, this hasn't been
added to the pygtk tutorial.  People shouldn't be forced to hunt all over
for this stuff IMO, and there's that pygtk tutorial sitting there with
undocumented widgets that just happen to be the most interesting ones.

Alright, I admit it, I just like seeing my own words on the web.

 have you looked at the FAQ?

Um, I suppose I could add some more stuff to the FAQ... but I'm feeling too
lazy to come up with tortured questions for the answers.  You did mention
at one point a separate section for stuff like this.

Dave Cook

___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


  1   2   >