Re: [pygtk] multiselect with ListStore and TreeView

2003-02-12 Thread Emmanuele Bassi
* John Hunter <[EMAIL PROTECTED]>:

> Unfortunately, I can't see how with either of these I can create a
> multiselect text list, with the ability to select and deselect text by
> clicking on it. 

Ever tried this:

selection = treeview.get_selection()
selection.set_mode(gtk.SELECTION_MULTIPLE)

?

This works as you expect "out-of-the-box" (well, except deselection by
a mouse click: you will have to create a callback to handle that).

Kind regards,
 Emmanuele.

-- 
Emmanuele Bassi (Zefram)  [ http://digilander.iol.it/ebassi/ ]
GnuPG Key fingerprint = 4DD0 C90D 4070 F071 5738  08BD 8ECC DB8F A432 0FF4
___
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] multiselect with ListStore and TreeView

2003-02-12 Thread John Hunter
> "John" == John Hunter <[EMAIL PROTECTED]> writes:

John> Where is the magic pixie dust that I am missing?

OK, I knew I was making this too hard.  It just took a few hours of
poring over the documentation and examples to figure *the right way*
to do it.  Here is a demo script which does the multiselection using
ListStore and TreeView for the next hapless soul who passes this way

import gobject
import gtk

COLUMN_TEXT=0

# initialize the ListStore.  Fom more complicated lists, see pygtk src example
# pygtk-demo/demos/list_store.py
mydata = ['John', 'Miriam', 'Rahel', 'Ava', 'Baerbel']
model = gtk.ListStore(gobject.TYPE_STRING)
for item in mydata:
iter = model.append()
model.set(iter, COLUMN_TEXT, item)

# set up the treeview to do multiple selection
treeview = gtk.TreeView(model)
treeview.set_rules_hint(gtk.TRUE)
column = gtk.TreeViewColumn('Name', gtk.CellRendererText(),
text=COLUMN_TEXT)
treeview.append_column(column)
treeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE)

# when you click ok, call this function for each selected item
def foreach(model, path, iter, selected):
selected.append(model.get_value(iter, COLUMN_TEXT))

def ok_clicked(event):
selected = []
treeview.get_selection().selected_foreach(foreach, selected)
print 'And the winners are...', selected
gtk.main_quit()

# the rest is just window boilerplate
win = gtk.Window()
win.connect('destroy', lambda win: gtk.main_quit())
win.set_title('GtkListStore demo')
win.set_border_width(8)
vbox = gtk.VBox(gtk.FALSE, 8)
win.add(vbox)

label = gtk.Label('Select your firends and family')
vbox.pack_start(label, gtk.FALSE, gtk.FALSE)

sw = gtk.ScrolledWindow()
sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
sw.set_policy(gtk.POLICY_NEVER,
  gtk.POLICY_AUTOMATIC)
vbox.pack_start(sw)
sw.add(treeview)
win.set_default_size(280, 250)

button = gtk.Button('OK')
button.show()
button.connect("clicked", ok_clicked )
vbox.pack_end(button,gtk.FALSE)

win.show_all()
gtk.main()

___
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] multiselect with ListStore and TreeView

2003-02-12 Thread John Hunter
> "David" == David M Cook <[EMAIL PROTECTED]> writes:

David> Well for CRToggle you have "toggled" and for CRText you
David> have "edited", and that's it AFAIK.  See the C API docs for
David> the the signatures of the callbacks.

Thanks for the info.

Unfortunately, I can't see how with either of these I can create a
multiselect text list, with the ability to select and deselect text by
clicking on it.  In the example below, I can select text, but cannot
deselect it, because if I click on already selected text, it is not
"changed" and hence my handler is not called.  "edited" doesn't work
for me because I don't want to edit the text.  "toggled" doesn't work
because I don't want users to have to check every single item -- the
list will be long with natural ranges so I want them to be able to
select a range with click item_1, shift click item_n.

Below I use treeview.get_selection().connect("changed", changed),
which has the deselection problem.  Can I connect the
gtk.TreeSelection to something besides 'changed' that will be called
whenever a row is clicked.  I adventurously tried 'clicked' and
'activated', but both are unknown signal names.

Where is the magic pixie dust that I am missing?

import gobject
import gtk

COLUMN_BOOL=0
COLUMN_TEXT=1

data = ['John', 'Miriam', 'Rahel', 'Ava', 'Baerbel']
def create_model():
store = gtk.ListStore(gobject.TYPE_BOOLEAN, gobject.TYPE_STRING)
for item in data:
iter = store.append()

store.set(iter,
  COLUMN_BOOL, gtk.FALSE,
  COLUMN_TEXT, item)
return store

def changed(w, *args):
#print w.get_selected(), w, type(w)
model, iter =  w.get_selected()
on = model.get_value(iter, COLUMN_BOOL)
on = not on
model.set(iter, COLUMN_BOOL, on)
print model.get_value(iter, COLUMN_TEXT), \
  model.get_value(iter, COLUMN_BOOL)

win = gtk.Window()

win.connect('destroy', lambda win: gtk.main_quit())
win.set_title('GtkListStore de2mo')
win.set_border_width(8)
vbox = gtk.VBox(gtk.FALSE, 8)
win.add(vbox)

label = gtk.Label('This is the list')
vbox.pack_start(label, gtk.FALSE, gtk.FALSE)

sw = gtk.ScrolledWindow()
sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
sw.set_policy(gtk.POLICY_NEVER,
  gtk.POLICY_AUTOMATIC)
vbox.pack_start(sw)

model = create_model()
treeview = gtk.TreeView(model)
treeview.set_rules_hint(gtk.TRUE)
sw.add(treeview)


model = treeview.get_model()

renderer = gtk.CellRendererToggle()
column = gtk.TreeViewColumn('ON', renderer, active=COLUMN_BOOL)
column.set_visible(gtk.FALSE)

renderer = gtk.CellRendererText()
column = gtk.TreeViewColumn('Name', renderer,
text=COLUMN_TEXT)
treeview.append_column(column)
treeview.get_selection().connect("changed", changed)
#renderer.connect("edited", changed)

win.set_default_size(280, 250)

win.show_all()
gtk.main()

___
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] Kiwi for GTK2?

2003-02-12 Thread Christian Reis
On Wed, Feb 12, 2003 at 04:03:51PM +0100, Åsmund Skjæveland wrote:
> Will there be a release of Kiwi for GTK2/PyGTK 1.99?

Yes, there will, as soon as my MSc thesis is delivered and I have some
time to clear bugs off the backburner. Some of the heavy lifting has
been done already by Johan, but I need to think a lot about CList and
how to port it.

There's a couple of hard problems to solve with CList, but the basic
framework should be a 5-minute hack to get working. Unfortunately, my
MSc is about 1 year late and the final delivery date is 10 days. I don't
have much time :-(

I'll be keeping the mailing list updated about my progress.

Take care,
--
Christian Reis, Senior Engineer, Async Open Source, Brazil.
http://async.com.br/~kiko/ | [+55 16] 261 2331 | NMFL
___
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] Kiwi for GTK2?

2003-02-12 Thread Åsmund Skjæveland
Will there be a release of Kiwi for GTK2/PyGTK 1.99?

-- 
Åsmund Skjæveland 
(OpenPGP keyid 54B975CE)



msg05454/pgp0.pgp
Description: PGP signature


[pygtk] Setting Window Properties

2003-02-12 Thread Martin Grimme
Hello,

I have a question about setting the properties of a GdkWindow
with PyGTK 1.9.x.

Since PyGTK does not yet support 'skip_taskbar', I want to
set the property manually.
How can I set this property?

window.property_change("_NET_WM_STATE, "ATOM", 32,
  gtk.gdk.PROP_MODE_APPEND, "_NET_WM_STATE_SKIP_TASKBAR")

does not work because PyGTK complains about the data not
being a sequence of integers...
How do I get the required integers from the string?


Bye, Martin Grimme -- http://www.pycage.de

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