On Sat, 22 Feb 2003, Anthony Tekatch wrote:
> 
> On Sat, 22 Feb 2003 18:59:14 -0600, Lars Clausen <[EMAIL PROTECTED]>
> wrote:
>> I'm trying to print out the selected area of a TreeView, but can't seem
>> to get the contents out.  I can't use gtk_tree_path_to_string, as pygtk
>> has no treepath object, only a singleton tuple(!?).  I can't use
>> treemodel.get_iter_from_string, as that function doesn't seem to exist.
>> Same goes for treemodel.get().  What's the easiest way to get the
>> contents of a row given a model, a path and an iter?
> 
> 
> You can use the TreeView.get_selection().get_selected() which returns the
> selected,iter
> 
> then you can use the get_value(iter,0) to get the value of the selected
> item.

Thanks!  The get_value() answered half of my question.  Now I can get the
contents of a cell.

The other half is complicated by the fact that I use SELECTION_MULTIPLE,
during which I cannot use get_selected.  I can iterate over the selection,
but I've found no easy way to check if there is a selection at all.  Right
now I'm resorting to the following hack:

any_output = False

def output_line(model, path, iter, file):
    ...output stuff...
    any_output = True
    return False

def output_to_file(file,treeview):
    any_output = False
    selection = treeview.get_selection()
    selection.selected_foreach(output_line, file)
    if (not(any_output)):
        model = treeview.get_model()
        model.foreach(output_line, file)

Not pretty, but it gets the job done.

-Lars

-- 
Lars Clausen (http://shasta.cs.uiuc.edu/~lrclause)| Hårdgrim of Numenor
"I do not agree with a word that you say, but I   |----------------------------
will defend to the death your right to say it."   | Where are we going, and
    --Evelyn Beatrice Hall paraphrasing Voltaire  | what's with the handbasket?
_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to