Re: [pygtk] Translating tool tip with non ascii characters.

2011-05-02 Thread Gerald Britton
On Mon, May 2, 2011 at 4:46 AM, Giuseppe Penone  wrote:
> it's full of glade files including non ascii characters out there (mainly
> the translators names filled in the about dialog) and it works, the encoding
> is utf-8.

Thanks!  Though I still need to know:

" Is a tooltip string, generated from glade file, is of (Python) type
string or unicode?"


>
> On Mon, May 2, 2011 at 2:46 AM, Gerald Britton 
> wrote:
>>
>>  I have a question:
>>
>>  Does anyone know if a tooltip string, generated from glade file, is of
>>  type string or unicode.
>>
>>  I think that the string must be unicode when calling gettext and the
>>  string contains non ascii
>>  characters.
>>
>>  At least it is so for tooltips generated in python code.
>>
>>
>> --
>> Gerald Britton
>> ___
>> pygtk mailing list   pygtk@daa.com.au
>> http://www.daa.com.au/mailman/listinfo/pygtk
>> Read the PyGTK FAQ: http://faq.pygtk.org/
>
>



-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


[pygtk] Translating tool tip with non ascii characters.

2011-05-01 Thread Gerald Britton
 I have a question:

 Does anyone know if a tooltip string, generated from glade file, is of
 type string or unicode.

 I think that the string must be unicode when calling gettext and the
 string contains non ascii
 characters.

 At least it is so for tooltips generated in python code.


-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


[pygtk] Fwd: [Gramps-devel] Translating tool tip with non ascii characters.

2011-04-27 Thread Gerald Britton
I have a question:

Does anyone know if a tooltip string, generated from glade file, is of
type string or unicode.

I think that the string must be unicode when calling gettext and the
string contains non ascii
characters.

At least it is so for tooltips generated in python code.

-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] PyGTK object escapes garbage collection

2010-12-24 Thread Gerald Britton
On Fri, Dec 24, 2010 at 5:28 AM, Hrvoje Niksic  wrote:
> The problem you describe sounds like it might be related to this infamous
> PyGTK bug:
>
> https://bugzilla.gnome.org/show_bug.cgi?id=546802
>
> In our tests the problems show up when a Python object that participates in
> a cycle is referenced only through a GTK widget.  When GC takes place,
> Python's cycle-breaker incorrectly concludes that the whole cycle is
> unreachable and runs tp_clear on all objects.  The objects are, of course,
> still reachable through PyGTK, and unfortunately now quite broken.
>
> A number of workarounds are available: simply access the widget's __dict__,
> which forces it to switch to a different reference-counting strategy.  Or
> store a reference to your object in a global variable or container.

To me, this is clearly a pygtk bug.  It should not be creating cycles
like this.  Also, it can create cycles without your participation.  If
you use builder, it can find callbacks using introspection.  I have
some modules that use introspection and have a few "connect" calls as
well.  To have to do all the introspection yourself in your own
modules is ridiculous.



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



-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] PyGTK object escapes garbage collection

2010-12-23 Thread Gerald Britton
I patched your code to use weakref like this:
...
import weakref
...
def __init__...
...
  button.connect("clicked", weakref.proxy(self.hello))
...

When I did that, there was nothing in the gc.get_referrers list at the
end.  If I understand this correctly, pygtk's reference to self.hello
was weak and didn't increment the ref counter, so when the page was
destroyed it was gc'd.

Would that work for you?

On Tue, Dec 21, 2010 at 12:16 PM, Pierre  wrote:
> Hello list,
>
> I run into a surprising behavior regarding garbage collection. In the
> following example, a Notebook page is removed from its parent widget and
> destroyed. However, the page is not garbage-collected unless the "tab"
> widget (a gtk.HBox) is first destroyed.
>
> Only the Page instance refers to the "tab" widget. Besides, "tab" is
> indirectly associated to the page: one of its child widget's signal is
> connected to a Page method. So we have something like this:
>
>  page --> tab --> button --> callback --> page --> tab --> etc.
>
> Once remove_page() returns, I would expect tab and page to be destroyed and
> collected, because both objects become unreachable (unreachable through
> Python variables and GTK calls). But the gc module shows that they are not
> collected.
>
> Is this the expected behavior ?  I'm using pygtk 2.17.0, gtk 2.20.1, and
> Python 2.6.6.
>
> Thank you for your time.
>
> Pierre
>
>
> # -- #
>
> import gc
> import gtk
> import gobject
>
> DESTROY_TAB = False
>
> class Page(gtk.VBox):
>
>    def __init__(self):
>        gtk.VBox.__init__(self)
>        self.pack_start(gtk.TextView(), True, True) # To fill the window
>        button = gtk.Button()
>        button.connect("clicked", self.hello)
>        title = gtk.Label("hello")
>        tab = gtk.HBox()
>        tab.pack_start(title, True, True)
>        tab.pack_end(button, False, False)
>        tab.show_all()
>
>        # Keeping a reference here is the culprit. Could it be a
>        # circular reference problem ?
>        # tab --> button --> hello --> page --> tab --> ...
>        self.tab = tab
>
>    def hello(self, widget):
>        print "hello"
>
> def add_page(notebook):
>    print "Adding a page to the Notebook."
>    page = Page()
>    page.show_all()
>    notebook.append_page(page, tab_label=page.tab)
>
> def remove_page(notebook):
>    print "Removing the page."
>    page = notebook.get_nth_page(0)
>    notebook.remove_page(0)
>    page.destroy()
>    # Destroying page.tab let the GC collect the page.
>    if DESTROY_TAB:
>        page.tab.destroy()
>
> def main():
>    notebook = gtk.Notebook()
>    w = gtk.Window()
>    w.add(notebook)
>    w.resize(400, 400)
>    w.show_all()
>    w.connect("destroy", gtk.main_quit)
>    gobject.idle_add(add_page, notebook)
>    gobject.timeout_add(1000, remove_page, notebook)
>    gobject.timeout_add(2000, gtk.main_quit)
>    gtk.main()
>
> def seek_page():
>    gc.collect()
>    oo = gc.get_objects()
>    for o in oo:
>        if hasattr(o, "__class__") and (o.__class__ is Page
>                                        or o.__class__ is gtk.HBox):
>            print
>            print o, "escaped garbage collection"
>            print 'Referrers are :'
>            for r in gc.get_referrers(o):
>                print '  *', repr(r)[:65], '...'
>
>
> main()
> seek_page()
>
>
> # Output:
> # --
> #
> # Adding a page to the Notebook.
> # Removing the page.
> #
> #  escaped garbage
> collection
> # Referrers are :
> #   * [(), {'__setattr__':  #   *  #   *  ...
> #
> #  escaped garbage
> collection
> # Referrers are :
> #   * [(), {'__setattr__':  #   *  ...
> #   * {'tab': } ...
> ___
> pygtk mailing list   pygtk@daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
>



-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] PyGTK object escapes garbage collection

2010-12-23 Thread Gerald Britton
I patched your code to use weakref like this:
...
import weakref
...
def __init__...
...
   button.connect("clicked", weakref.proxy(self.hello))
...

When I did that, there was nothing in the gc.get_referrers list at the
end.  If I understand this correctly, pygtk's reference to self.hello
was weak and didn't increment the ref counter, so when the page was
destroyed it was gc'd.

Would that work for you?




On Tue, Dec 21, 2010 at 12:16 PM, Pierre  wrote:
> Hello list,
>
> I run into a surprising behavior regarding garbage collection. In the
> following example, a Notebook page is removed from its parent widget and
> destroyed. However, the page is not garbage-collected unless the "tab"
> widget (a gtk.HBox) is first destroyed.
>
> Only the Page instance refers to the "tab" widget. Besides, "tab" is
> indirectly associated to the page: one of its child widget's signal is
> connected to a Page method. So we have something like this:
>
>  page --> tab --> button --> callback --> page --> tab --> etc.
>
> Once remove_page() returns, I would expect tab and page to be destroyed and
> collected, because both objects become unreachable (unreachable through
> Python variables and GTK calls). But the gc module shows that they are not
> collected.
>
> Is this the expected behavior ?  I'm using pygtk 2.17.0, gtk 2.20.1, and
> Python 2.6.6.
>
> Thank you for your time.
>
> Pierre
>
>
> # -- #
>
> import gc
> import gtk
> import gobject
>
> DESTROY_TAB = False
>
> class Page(gtk.VBox):
>
>    def __init__(self):
>        gtk.VBox.__init__(self)
>        self.pack_start(gtk.TextView(), True, True) # To fill the window
>        button = gtk.Button()
>        button.connect("clicked", self.hello)
>        title = gtk.Label("hello")
>        tab = gtk.HBox()
>        tab.pack_start(title, True, True)
>        tab.pack_end(button, False, False)
>        tab.show_all()
>
>        # Keeping a reference here is the culprit. Could it be a
>        # circular reference problem ?
>        # tab --> button --> hello --> page --> tab --> ...
>        self.tab = tab
>
>    def hello(self, widget):
>        print "hello"
>
> def add_page(notebook):
>    print "Adding a page to the Notebook."
>    page = Page()
>    page.show_all()
>    notebook.append_page(page, tab_label=page.tab)
>
> def remove_page(notebook):
>    print "Removing the page."
>    page = notebook.get_nth_page(0)
>    notebook.remove_page(0)
>    page.destroy()
>    # Destroying page.tab let the GC collect the page.
>    if DESTROY_TAB:
>        page.tab.destroy()
>
> def main():
>    notebook = gtk.Notebook()
>    w = gtk.Window()
>    w.add(notebook)
>    w.resize(400, 400)
>    w.show_all()
>    w.connect("destroy", gtk.main_quit)
>    gobject.idle_add(add_page, notebook)
>    gobject.timeout_add(1000, remove_page, notebook)
>    gobject.timeout_add(2000, gtk.main_quit)
>    gtk.main()
>
> def seek_page():
>    gc.collect()
>    oo = gc.get_objects()
>    for o in oo:
>        if hasattr(o, "__class__") and (o.__class__ is Page
>                                        or o.__class__ is gtk.HBox):
>            print
>            print o, "escaped garbage collection"
>            print 'Referrers are :'
>            for r in gc.get_referrers(o):
>                print '  *', repr(r)[:65], '...'
>
>
> main()
> seek_page()
>
>
> # Output:
> # --
> #
> # Adding a page to the Notebook.
> # Removing the page.
> #
> #  escaped garbage
> collection
> # Referrers are :
> #   * [(), {'__setattr__':  #   *  #   *  ...
> #
> #  escaped garbage
> collection
> # Referrers are :
> #   * [(), {'__setattr__':  #   *  ...
> #   * {'tab': } ...
> ___
> pygtk mailing list   pygtk@daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
>



-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] PyGTK object escapes garbage collection

2010-12-23 Thread Gerald Britton
We encountered this problem in our project (gramps-project.org).  It
took quite a bit of work to remove the refs to allow GC. Basically, we
added code to track the callbacks then, when the objects were deleted,
added code to explicitly remove them (delete them or set them to None)
to break the cyclical refs.  Also, we added code to delete (or set to
None) attributes that might possibly be involved in the cycle.

It was a lot of work but we eventually stopped the memory leaks.
Still, I believe that pygtk could be a LOT smarter in this regard.  I
think that what we had to do amounts to fixing a serious design issue
in pygtk.

On Tue, Dec 21, 2010 at 12:16 PM, Pierre  wrote:
> Hello list,
>
> I run into a surprising behavior regarding garbage collection. In the
> following example, a Notebook page is removed from its parent widget and
> destroyed. However, the page is not garbage-collected unless the "tab"
> widget (a gtk.HBox) is first destroyed.
>
> Only the Page instance refers to the "tab" widget. Besides, "tab" is
> indirectly associated to the page: one of its child widget's signal is
> connected to a Page method. So we have something like this:
>
>  page --> tab --> button --> callback --> page --> tab --> etc.
>
> Once remove_page() returns, I would expect tab and page to be destroyed and
> collected, because both objects become unreachable (unreachable through
> Python variables and GTK calls). But the gc module shows that they are not
> collected.
>
> Is this the expected behavior ?  I'm using pygtk 2.17.0, gtk 2.20.1, and
> Python 2.6.6.
>
> Thank you for your time.
>
> Pierre
>
>
> # -- #
>
> import gc
> import gtk
> import gobject
>
> DESTROY_TAB = False
>
> class Page(gtk.VBox):
>
>    def __init__(self):
>        gtk.VBox.__init__(self)
>        self.pack_start(gtk.TextView(), True, True) # To fill the window
>        button = gtk.Button()
>        button.connect("clicked", self.hello)
>        title = gtk.Label("hello")
>        tab = gtk.HBox()
>        tab.pack_start(title, True, True)
>        tab.pack_end(button, False, False)
>        tab.show_all()
>
>        # Keeping a reference here is the culprit. Could it be a
>        # circular reference problem ?
>        # tab --> button --> hello --> page --> tab --> ...
>        self.tab = tab
>
>    def hello(self, widget):
>        print "hello"
>
> def add_page(notebook):
>    print "Adding a page to the Notebook."
>    page = Page()
>    page.show_all()
>    notebook.append_page(page, tab_label=page.tab)
>
> def remove_page(notebook):
>    print "Removing the page."
>    page = notebook.get_nth_page(0)
>    notebook.remove_page(0)
>    page.destroy()
>    # Destroying page.tab let the GC collect the page.
>    if DESTROY_TAB:
>        page.tab.destroy()
>
> def main():
>    notebook = gtk.Notebook()
>    w = gtk.Window()
>    w.add(notebook)
>    w.resize(400, 400)
>    w.show_all()
>    w.connect("destroy", gtk.main_quit)
>    gobject.idle_add(add_page, notebook)
>    gobject.timeout_add(1000, remove_page, notebook)
>    gobject.timeout_add(2000, gtk.main_quit)
>    gtk.main()
>
> def seek_page():
>    gc.collect()
>    oo = gc.get_objects()
>    for o in oo:
>        if hasattr(o, "__class__") and (o.__class__ is Page
>                                        or o.__class__ is gtk.HBox):
>            print
>            print o, "escaped garbage collection"
>            print 'Referrers are :'
>            for r in gc.get_referrers(o):
>                print '  *', repr(r)[:65], '...'
>
>
> main()
> seek_page()
>
>
> # Output:
> # --
> #
> # Adding a page to the Notebook.
> # Removing the page.
> #
> #  escaped garbage
> collection
> # Referrers are :
> #   * [(), {'__setattr__':  #   *  #   *  ...
> #
> #  escaped garbage
> collection
> # Referrers are :
> #   * [(), {'__setattr__':  #   *  ...
> #   * {'tab': } ...
> ___
> pygtk mailing list   pygtk@daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
>



-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] Can't get tool tip to display

2010-12-17 Thread Gerald Britton
On Thu, Dec 16, 2010 at 5:20 PM, Dieter Verfaillie
 wrote:
> On 16/12/2010 23:04, Dieter Verfaillie wrote:
>> On 16/12/2010 22:06, Gerald Britton wrote:
>>> Hi Dieter,
>>>
>>> I just realized that your sample code displays a tooltip per row.
>>> What I would like to do is display the tip per column.  So, if I'm in
>>> column 3, I see "In column 3" or whatever, regardless of the row.  How
>>> should I modify your sample code to do that?
>>
>> Replace the on_query_tooltip() method in my previous example with the
>> snippet below. Note that the "columns" variable holds a gtk.TreeViewColumn
>> object.
>
> Or if you don't need that kind of flexibility you could add a column to
> your model and simply point treeview.set_tooltip_column() to it.
> See
> http://library.gnome.org/devel/pygtk/2.22/class-gtktreeview.html#method-gtktreeview--set-tooltip-column
> on how it works.
>

It looks like this is only for tooltips on entire rows:

"If you only plan to have simple (text-only) tooltips on full rows,"

So, it doesn't really meet my needs, since I want the tips to be by
columns, not rows.

> mvg,
> Dieter
>



-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] Can't get tool tip to display

2010-12-16 Thread Gerald Britton
Hi Dieter,

I just realized that your sample code displays a tooltip per row.
What I would like to do is display the tip per column.  So, if I'm in
column 3, I see "In column 3" or whatever, regardless of the row.  How
should I modify your sample code to do that?

On Fri, Dec 3, 2010 at 4:25 AM, Dieter Verfaillie
 wrote:
> Quoting "Gerald Britton" :
>>
>> Hi -- I have a treeview where I want tooltips to display upon
>> mouse-hover.  I need help to see what I'm missing in this section
>> since the tips are not popping up:  ("columns" is a simple list of
>> column names)
>>
>>        self.view = gtk.TreeView()
>>        self.model = gtk.ListStore(*[str] * (len(columns) + 1))
>>        for index, name in enumerate(columns):
>>            renderer = gtk.CellRendererText()
>>            if index > 0:
>>                renderer.set_property('editable', True)
>>                renderer.connect('edited', self.__cell_edited,
>>                                                (self.model, index + 1))
>>            column = gtk.TreeViewColumn(name, renderer, text=index + 1)
>>            foo = gtk.Tooltip()
>>            foo.text = name
>>            self.view.append_column(column)
>>            self.view.set_tooltip_cell(foo, None, column, None)
>>
>
> Here's a working example:
>
> 8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<
> import gtk
>
> class TestWindow(gtk.Window):
>    def __init__(self):
>        gtk.Window.__init__(self)
>
>        column_types = [str, str, str]
>        columns = ['index', 'something', 'whatever']
>
>        self.model = gtk.ListStore(*column_types)
>        self.view = gtk.TreeView(self.model)
>        self.view.set_headers_visible(True)
>        self.view.set_has_tooltip(True)
>        self.view.connect('query-tooltip', self.on_query_tooltip)
>
>        for index, name in enumerate(columns):
>            renderer = gtk.CellRendererText()
>
>            if index > 0:
>                renderer.set_property('editable', True)
>
>            column = gtk.TreeViewColumn(name, renderer, text=index)
>            self.view.append_column(column)
>
>        self.model.append(['0', 'test', 'dfjqkm'])
>        self.model.append(['1', 'test', 'arearzer'])
>
>        self.add(self.view)
>        self.show_all()
>
>    def on_query_tooltip(self, widget, x, y, keyboard_tip, tooltip):
>        if not widget.get_tooltip_context(x, y, keyboard_tip):
>            return False
>        else:
>            model, path, iter = widget.get_tooltip_context(x, y,
> keyboard_tip)
>
>            tooltip.set_markup('Value: %s' % model.get_value(iter, 2))
>            widget.set_tooltip_cell(tooltip, path, None, None)
>            return True
>
>
> def quit(widget, event):
>    gtk.main_quit()
>
>
> if __name__ == '__main__':
>    window = TestWindow()
>    window.connect('delete-event', quit)
>
>    gtk.main()
> 8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<
>
> 
> This message was sent using IMP, the Internet Messaging Program.
>



-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] Can't get tool tip to display

2010-12-05 Thread Gerald Britton
On Sun, Dec 5, 2010 at 2:52 AM, Alessandro Dentella  wrote:
> On Sat, Dec 04, 2010 at 11:05:14PM +0100, Dieter Verfaillie wrote:
>> Quoting "Gerald Britton" :
>> >Say, how would I patch this code to show tips when I mouse over the
>> >column headers?  It works great for the rows underneath.
>>
>> That's a good question... Has anybody done something like that?
>
> in sqlkit i substitute the header with a gtk.Label(), at that point you can
> do:
>
>   label.et_markup(...)
>   label.set_tooltip_text(...)

very cool, might just work for me, brings up another question.  With
set_tooltip_text you don't need a handler, correct?  Yet Dieters mod
of my code introduces a handler.  Is there a way to set the tooltip
text and not use a handler?  Just seems a little inconsistent, though
I suppose there's a good reason for that or that I'm totally off the
wall!

>
> and tooltips work as expected even thought it won't show the little arrow to
> sort the column.
>
> I had to substitute the header to be able to use markup in the label and to
> have a menu  dropdown, by  I wasn't able to have the dropdown on button press
> I just have it on button release.
>
>
> sandro
> *:-)
>
> --
> Sandro Dentella  *:-)
> http://www.reteisi.org             Soluzioni libere per le scuole
> http://sqlkit.argolinux.org        SQLkit home page - PyGTK/python/sqlalchemy
> ___
> pygtk mailing list   pygtk@daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
>



-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] Can't get tool tip to display

2010-12-02 Thread Gerald Britton
Reposting this query in case it has fallen off the radar

On Fri, Nov 26, 2010 at 3:04 PM, Gerald Britton
 wrote:
> Hi -- I have a treeview where I want tooltips to display upon
> mouse-hover.  I need help to see what I'm missing in this section
> since the tips are not popping up:  ("columns" is a simple list of
> column names)
>
>        self.view = gtk.TreeView()
>        self.model = gtk.ListStore(*[str] * (len(columns) + 1))
>        for index, name in enumerate(columns):
>            renderer = gtk.CellRendererText()
>            if index > 0:
>                renderer.set_property('editable', True)
>                renderer.connect('edited', self.__cell_edited,
>                                                (self.model, index + 1))
>            column = gtk.TreeViewColumn(name, renderer, text=index + 1)
>            foo = gtk.Tooltip()
>            foo.text = name
>            self.view.append_column(column)
>            self.view.set_tooltip_cell(foo, None, column, None)
>
> --
> Gerald Britton
>



-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


[pygtk] Can't get tool tip to display

2010-11-26 Thread Gerald Britton
Hi -- I have a treeview where I want tooltips to display upon
mouse-hover.  I need help to see what I'm missing in this section
since the tips are not popping up:  ("columns" is a simple list of
column names)

self.view = gtk.TreeView()
self.model = gtk.ListStore(*[str] * (len(columns) + 1))
for index, name in enumerate(columns):
renderer = gtk.CellRendererText()
if index > 0:
renderer.set_property('editable', True)
renderer.connect('edited', self.__cell_edited,
(self.model, index + 1))
column = gtk.TreeViewColumn(name, renderer, text=index + 1)
foo = gtk.Tooltip()
foo.text = name
self.view.append_column(column)
self.view.set_tooltip_cell(foo, None, column, None)

-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


[pygtk] Add tool tips to cells in a liststore.

2010-11-22 Thread Gerald Britton
Hi -- is it possible (and how would I?) add tool tips to cells in a
ltk.ListStore?  I want to have the tips display on mouseover events.

-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] Drag-and-drop between windows when running on MS Windows?

2010-07-18 Thread Gerald Britton
or wx

On Sat, Jul 17, 2010 at 4:26 AM, Saeed Rasooli  wrote:
> I personally love GTK and use PyGTK on linux, but sincerely if you want a
> better (and native) support for windows, I recomment PyQt!
> ___
> pygtk mailing list   pygtk@daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
>



-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] push huge array into liststore

2010-07-13 Thread Gerald Britton
2010/7/12 Gerald Britton :
> First off, why are you using an array?  Not that it's bad or anything,
> but how does it help you where a simple list would not?
>
> Second, what would be nice is if liststore.insert would take an
> interable.  Baring that you could simplify a little like this:
>
> keys = ['v1', 'v1', ..., 'vn']
> for d in data:
>    selt.liststore.insert(0, tuple(d[k] for k in keys))
>
> whether it is worth it or not depends on how many keys you have.

Here's another way, assuming that there
are not too many keys to be looked up:

append = self.liststore.append# lookup the method once
from operator import itemgetter
v1 = itemgetter('v1')   # special getter for 'v1'
v2 = itemgetter('v2')   # ...
v3 = itemgetter('v3')
...
for d in data:
   append((v1(d), v2(d), v3(d), ...))

Yet another approach:  If you can use OrderedDict (new in Python 2.7
and 3.1), you can do this:

append = self.liststore.append
for d in data:
  append(d.values())

>
> 2010/7/12 Pietro Battiston :
>> Il giorno lun, 12/07/2010 alle 17.48 +0200, Cornelius Kölbel ha scritto:
>>> Dear list,
>>>
>>> I got an array of dictionaries, that I want to add to a GTKListStore,
>>> that is displayed an a treeview.
>>>
>>> This is very slow. I already replaced the liststore.append by
>>> liststore.insert, which is much much faster.
>>> But still, filling the 10.000 values takes about 50 seconds.
>>>
>>> Is there any cool mapping function, to push the array to the liststore?
>>> I used a for loop to iterate over the array...
>>> I also tried while an to pop the array elements...
>>>
>>> It is something like this:
>>>
>>> data: array of dictionaries
>>>
>>> data = array( { 'v1' : 'something', 'v2': 'something else' } ,
>>>               { 'v1' : 'another',   'v2': 'something completely diff' }
>>>               )
>>>
>>>
>>> for d in data:
>>>    self.liststore.insert( 0, ( d.get("v1"), d.get("v2") ))
>>>
>>>
>>> ...is there a better way than doing a for loop?
>>> ...or a way to not have to interate over the 10.000 dicts?
>>>
>>> ...or is there a cool reading on performance tuning pyton?
>>
>>
>>
>> I really don't know, but... already read
>> http://faq.pygtk.org/index.py?req=show&file=faq13.043.htp
>> ?
>>
>> Pietro
>>
>> ___
>> pygtk mailing list   pygtk@daa.com.au
>> http://www.daa.com.au/mailman/listinfo/pygtk
>> Read the PyGTK FAQ: http://faq.pygtk.org/
>
>
>
> --
> Gerald Britton
>



-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] push huge array into liststore

2010-07-13 Thread Gerald Britton
On Mon, Jul 12, 2010 at 9:09 PM, Tim Evans  wrote:
> On 2010-07-13 3:48, Cornelius Kölbel wrote:
>> Dear list,
>>
>> I got an array of dictionaries, that I want to add to a GTKListStore,
>> that is displayed an a treeview.
>>
>> This is very slow. I already replaced the liststore.append by
>> liststore.insert, which is much much faster.
>> But still, filling the 10.000 values takes about 50 seconds.
>>
>> Is there any cool mapping function, to push the array to the liststore?
>> I used a for loop to iterate over the array...
>> I also tried while an to pop the array elements...
>>
>> It is something like this:
>>
>> data: array of dictionaries
>>
>> data = array( { 'v1' : 'something', 'v2': 'something else' } ,
>>                { 'v1' : 'another',   'v2': 'something completely diff' }
>>               )
>>
>>
>> for d in data:
>>     self.liststore.insert( 0, ( d.get("v1"), d.get("v2") ))
>>
>>
>> ...is there a better way than doing a for loop?
>> ...or a way to not have to interate over the 10.000 dicts?
>>
>> ...or is there a cool reading on performance tuning pyton?
>
> Some general ideas:
>  - Make sure the store isn't being viewed when you insert data, that
>    will slow it down.
>
>  - Do attribute lookups outside big loops:
>
>     append = self.liststore.append
>     get = d.get
>     for d in data:
>         append(0, (get('v1'), get('v2'), ...))

This sample won't work since you are using "d" before it is bound in
the for loop.  Also, the "append" method only takes one argument: the
row to be added to the store.  Here's another way, assuming that there
are not too many keys to be looked up:

append = self.liststore.append
from operator import itemgetter
v1 = itemgetter('v1')
v2 = itemgetter('v2')
v3 = itemgetter('v3')
...
for d in data:
append((v1(d), v2(d), v3(d), ...))

Yet another approach:  If you can use OrderedDict (new in Python 2.7
and 3.1), you can do this:

append = self.liststore.append
for d in data:
   append(d.values())




>
>  - Put the treeview into fixed height and width mode. Automatic sizing
>    is the enemy of treeview performance. This only works if all your
>    rows are the same height. The function calls you need are:
>      gtk.TreeViewColumn.set_sizing
>         with the gtk.TREE_VIEW_COLUMN_FIXED value
>      gtk.TreeViewColumn.set_fixed_width
>      gtk.TreeView.set_fixed_height_mode
>
>  - If your list is large enough it may be worth subclassing
>    gtk.TreeModel and overriding the required methods. It's complex, but
>    it can avoid referencing all your data at tree build time, instead
>    loading as the user scrolls.
>
>  - Write it in C. Always valid, even if as a last resort.
>
> --
> Tim Evans
> Applied Research Associates NZ
> http://www.aranz.com/
> ___
> pygtk mailing list   pygtk@daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
>



-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] push huge array into liststore

2010-07-12 Thread Gerald Britton
First off, why are you using an array?  Not that it's bad or anything,
but how does it help you where a simple list would not?

Second, what would be nice is if liststore.insert would take an
interable.  Baring that you could simplify a little like this:

keys = ['v1', 'v1', ..., 'vn']
for d in data:
selt.liststore.insert(0, tuple(d[k] for k in keys))

whether it is worth it or not depends on how many keys you have.

2010/7/12 Pietro Battiston :
> Il giorno lun, 12/07/2010 alle 17.48 +0200, Cornelius Kölbel ha scritto:
>> Dear list,
>>
>> I got an array of dictionaries, that I want to add to a GTKListStore,
>> that is displayed an a treeview.
>>
>> This is very slow. I already replaced the liststore.append by
>> liststore.insert, which is much much faster.
>> But still, filling the 10.000 values takes about 50 seconds.
>>
>> Is there any cool mapping function, to push the array to the liststore?
>> I used a for loop to iterate over the array...
>> I also tried while an to pop the array elements...
>>
>> It is something like this:
>>
>> data: array of dictionaries
>>
>> data = array( { 'v1' : 'something', 'v2': 'something else' } ,
>>               { 'v1' : 'another',   'v2': 'something completely diff' }
>>               )
>>
>>
>> for d in data:
>>    self.liststore.insert( 0, ( d.get("v1"), d.get("v2") ))
>>
>>
>> ...is there a better way than doing a for loop?
>> ...or a way to not have to interate over the 10.000 dicts?
>>
>> ...or is there a cool reading on performance tuning pyton?
>
>
>
> I really don't know, but... already read
> http://faq.pygtk.org/index.py?req=show&file=faq13.043.htp
> ?
>
> Pietro
>
> ___
> pygtk mailing list   pygtk@daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/



-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] PyGtk and gtk-3.0 compatibility

2010-07-08 Thread Gerald Britton
On Thu, Jul 8, 2010 at 4:03 AM, Tomeu Vizoso  wrote:
> On Mon, Jul 5, 2010 at 15:48, John Stowers  
> wrote:
>> Hi,
>>
>> First of all, PyGI and GObject introspection is the way forward.
>>
>> Now, that being said, it seems a little silly to spend all this effort
>> porting C apps in GNOME to gtk-3.0 only to see the first PyGtk app drag
>> back in the gtk-2.0 libraries with "import gtk".
>>
>> So I spent a little time trying to get PyGtk to build with GSEAL. Turns
>> out it wasn't that hard [1][2].
>>
>> Only a few accessors were missing
>>  * GtkWindow.has_user_ref_count
>>  * GtkInvisible.has_user_ref_count
>>    These both are used in the sink funcs, and seem to be a synonym
>>    for checking the object has not been destroyed.
>>  * gtk_menu_get_position_func{,_data}
>>
>> So, what is the opinion on this? Is it worth me continuing? My idea
>> would be to make *only one* PyGtk release that builds against gtk-3.0,
>> it would see no new features.
>
> Sounds like a good idea to me, given how much PyGTK application
> authors seem to lag behind platform changes.
>
> That said, I think distros should focus on moving to introspection
> because it allows them to drop maintenance of a lot of packages. But
> anything that makes this move easier for people is important.

I've trying to get a handle on PyGI for a while now, but I'm still in
a bit of a fog.  I've worked on some PyGTK apps so understand that OK,
but what I'm really looking for are answers to questions like:

1. What problem is PyGI trying to solve?
2. What advantage will I see by using PyGI over PyGTK?
3. How do I port my application from PyGTK to PyGI?

>
> Regards,
>
> Tomeu
>
>> John
>>
>> [1] http://github.com/nzjrs/pygtk/commits/gtk-3.0
>> [2] http://github.com/nzjrs/pygobject/tree/gtk-3.0
>>
>> ___
>> pygtk mailing list   pygtk@daa.com.au
>> http://www.daa.com.au/mailman/listinfo/pygtk
>> Read the PyGTK FAQ: http://faq.pygtk.org/
>>
> ___
> pygtk mailing list   pygtk@daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
>



-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] Refresh data on TreeView

2010-03-19 Thread Gerald Britton
Some style suggestions below

2010/3/18 Julián Alarcón :
> 2010/3/18 Vermeersch Simon :
>> 2010/3/18 Julián Alarcón :
>>> Hi guys, I don't know if this is the right place to bother you with
>>> this support ask.
>>>
>>> I'm making a little app that takes data from PostgreSQL and show it on
>>> a TreeView. But, I need to update the data every 5 minutes, but I
>>> don't know how to make this. I tried some while loops but the window
>>> didn't appear.
>>>
>>> This is the code: http://paste.ubuntu.com/397321/
>>>
>>> And this is a little screenshot: http://i42.tinypic.com/14yaazs.jpg
>>>
>>> Thanks!
>>> ___
>>> pygtk mailing list   pygtk@daa.com.au
>>> http://www.daa.com.au/mailman/listinfo/pygtk
>>> Read the PyGTK FAQ: http://faq.pygtk.org/
>>>
>>
>> You can use the gobject.timeout_add function to update your treeview.
>> Something like that:
>>
>> def __init__(self):
>>    
>>    gobject.timeout_add(30, self.refresh_treeview)
>>
>> def refresh_treeview(self):
>>    #reload your data and refresh the treeview here
>>    return True
>>
>>
>> --
>> Simon Vermeersch
>>
> 
>
>
> Hi Simon, I just made some changes and add this:
>
>
>    def refresh_treeview(self):
>        try:
>                conexiondb = psycopg2.connect("dbname='databas' user='user'
> host='172.16.0.1' password='password'");
>                print "Conexion exitosa"
>        except:
>                print "No se pudo conectar a la base de datos"
>                gtk.main_quit()
>        cursor = conexiondb.cursor()
>        cursor.execute("SELECT * FROM datos_aplicacion")
>        consulta = cursor.fetchall()
>        datos = gtk.TreeStore(str,str,str,str,str,str,str,str,str,str)

>        for fila in consulta:
>                print fila[0], fila[1], fila[2], fila[3], fila[4], fila[5], 
> fila[6],
> fila[7], fila[8], fila[9]

Why not use a slice here?  Something like:

  for file in consulta:
  print fila[0:10]

>                datos.append(None,
> [fila[0],fila[1],fila[2],fila[3],fila[4],fila[5],fila[6],fila[7],fila[8],fila[9]])

Here too:

 datos.extend(None, *fila[0:10])

>
>        self.treeview = gtk.TreeView(datos)
>        # create a CellRendererText to render the data
>        self.cell = gtk.CellRendererText()
>
>        # add the cell to the tvcolumn and allow it to expand
>        self.tvcolumna1.pack_start(self.cell, True)
>        self.tvcolumna2.pack_start(self.cell, True)
>        self.tvcolumna3.pack_start(self.cell, True)
>        self.tvcolumna4.pack_start(self.cell, True)
>        self.tvcolumna5.pack_start(self.cell, True)
>        self.tvcolumna6.pack_start(self.cell, True)
>        self.tvcolumna7.pack_start(self.cell, True)
>        self.tvcolumna8.pack_start(self.cell, True)
>        self.tvcolumna9.pack_start(self.cell, True)
>        self.tvcolumna10.pack_start(self.cell, True)

Why not put this in a for-loop?  Something like:

  for i in range(10):
  getattr(self, 'tvcolumna%s' % i).pack_start(self.cell. True)

>
>        # set the cell "text" attribute to column 0 - retrieve text
>        # from that column in treestore
>        self.tvcolumna1.add_attribute(self.cell, 'text', 0)
>        self.tvcolumna2.add_attribute(self.cell, 'text', 1)
>        self.tvcolumna3.add_attribute(self.cell, 'text', 2)
>        self.tvcolumna4.add_attribute(self.cell, 'text', 3)
>        self.tvcolumna5.add_attribute(self.cell, 'text', 4)
>        self.tvcolumna6.add_attribute(self.cell, 'text', 5)
>        self.tvcolumna7.add_attribute(self.cell, 'text', 6)
>        self.tvcolumna8.add_attribute(self.cell, 'text', 7)
>        self.tvcolumna9.add_attribute(self.cell, 'text', 8)
>        self.tvcolumna10.add_attribute(self.cell, 'text', 9)

Here too:

  for i in range(10):
  getattr(self, 'tvcolumna%s' % i).add_attribute(self.cell. True)

Just an idea.  Plus, I would put the number of columns in a constant
somewhere instead of hard-coding it.  That way, if you add or remove
columns, your code doesn't have to change.


>
>        self.window.show_all()
>
>        return True
>
> 
>
>
> The output of my sql query is working, but the refresh of TreeView is
> not working, I just need that. Can you help me? Where is my mistake?
>
> Thanks for your help, my app is getting close to my wish :)
> ___
> pygtk mailing list   pygtk@daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/



-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] Porting pygtk to python 3

2010-02-03 Thread Gerald Britton
Any news on this initiative?  I work on a pygtk-based project that is
considering moving to Python 3.x but we cannot until there is a
function pygtk availalble.

Is there a ETA or a roadmap?

On Mon, Nov 9, 2009 at 3:11 PM, Alex Dedul  wrote:
> On Mon, Nov 9, 2009 at 11:14 AM, Tomeu Vizoso  wrote:
>> On Mon, Nov 9, 2009 at 09:22, Rafael Villar Burke (Pachi)
>>  wrote:
>>> Alex Dedul wrote:
>>>> Hi!
>>>>
>>>> Any news on porting pygtk to python 3 ? I would be glad to help maybe
>>>> almost full-time on this. Just would be good to know current status on
>>>> this matters first.. And if none projects or initiatives were already
>>>> started on this - is to okay then to just clone git repo and start
>>>> hacking ? Any things i better do before that like to notify some
>>>> people about this or the like ?
>>>>
>>> AFAIK, the expected way to support python 3.x is through
>>> gobject-introspection generated bindings.
>>>
>>> If you want to help pushing forward python 3 support then, IMHO, it
>>> would be a good idea to help with the pybank and pygobject introspection
>>> work. This last project was mentioned on the mailing list some days ago.
>>> You should read the "[pygtk] introspection pygobject branch" thread
>>> starting on the 13rd of october this year for more information and
>>> pending tasks and try to contact the people working on it.
>>>
>>> Regards, and thanks for helping,
>>
>> Yes, having introspection support means we don't have to port the
>> existing static bindings, making the move to 3.0 (and maybe pypy?)
>> more doable.
>>
>> Some info:
>>
>> http://live.gnome.org/PyGObject
>> http://live.gnome.org/PyGI
>>
>> All help is welcome.
>>
>> Regards,
>>
>> Tomeu
>
> Thanks guys! I'll do some research on those matters and we'll see what
> do we have and what to do with all of that.
>
> With best regards from the Soul, Alex.
> ___
> pygtk mailing list   pygtk@daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
>



-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] gtk.TreeModel.iter_children() method, how often should it be called?

2009-06-22 Thread Gerald Britton
I don't think that makes sense.  For example, it does stop calling
iter_children at some point and display the tree.  In my case, the
first time the tree is build, it makes two calls to iter_children and
then displays the tree and waits for something to happen (I still
think that two is one too many, but I can live with it).  The next
time, it calls iter_children over 2000 times before it displays the
tree.

That can't be right!

So, the question remains, "When does the TreeModel stop calling
iter_children and display the tree?"

It obviously does stop calling iter_children at some point,  I can
show that. But, what are the circumstances?  What is it looking for?

On Mon, Jun 22, 2009 at 6:28 AM, Chris Camacho wrote:
>
> As far as I could tell that's just the way it works *if* you could
> suspend the calls to iter_children it would stop working...
>
> --- On Sat, 20/6/09, Gerald Britton  wrote:
>
>> From: Gerald Britton 
>> Subject: Re: [pygtk] gtk.TreeModel.iter_children() method, how often should 
>> it  be called?
>> To: "Chris Camacho" 
>> Cc: pygtk@daa.com.au
>> Date: Saturday, 20 June, 2009, 11:11 PM
>> I hear you, but I still need a direct
>> answer to the question, "What
>> makes the TreeModel stop calling iter_children?  I
>> can't find a clear
>> explanation and I can't figure it out by looking at the
>> calls that
>> come into my method either.
>>
>> On Thu, Jun 18, 2009 at 11:18 AM, Chris Camacho
>> wrote:
>> >
>> > jeeze not being able to just reply is a pain
>> anyhow
>> >
>> > I looked into using treemodels connecting to
>> databases
>> >
>> > from what I could tell it seems to initially iterate
>> all items
>> > and either copies them or creates meta data about the
>> items
>> > (I didnt look into the implementation)
>> > Depending on how things were added it would also seem
>> to iterate the whole
>> > set again!
>> > I think the standard treemodel is ok for small numbers
>> (sub 200)
>> > but I had to end up paging 1,000's of items 100 at a
>> time
>> > (interestingly this is what the gnome db widgets
>> do...)
>> >
>> > I've been tempted to weld together my own data grid
>> with a viewport
>> > and moving entry widgets but this would at a guess
>> need C and I haven't
>> > had the time to look into it
>> >
>> >
>> > --- On Thu, 18/6/09, Gerald Britton 
>> wrote:
>> >
>> >> From: Gerald Britton 
>> >> Subject: [pygtk] gtk.TreeModel.iter_children()
>> method, how often should it be called?
>> >> To: pygtk@daa.com.au
>> >> Date: Thursday, 18 June, 2009, 2:50 PM
>> >> Hi -- I think I have a problem but
>> >> I'm not sure since I'm relatively
>> >> new to the TreeModel and how it works.  Here's
>> the
>> >> scenario:
>> >>
>> >> I use TreeModel to display rows of data from a
>> >> database.  Upon
>> >> startup, the TreeModel is built and I notice two
>> calls to
>> >> the
>> >> gtk.TreeModel.iter_children() method.  Later, I
>> change
>> >> some data in
>> >> one of the rows.  The next time the TreeModel is
>> >> built,
>> >> gtk.TreeModel.iter_children() is called thousands
>> of times
>> >> before the
>> >> display is refreshed. Oh, the database has less
>> than 50
>> >> rows of data
>> >> in it!
>> >>
>> >> So, two questions:
>> >>
>> >> 1. Is this normal (I hope not!) behavior?
>> >>
>> >> 2. What tells the TreeModel to stop calling
>> >> gtk.TreeModel.iter_children()?  How does the TM
>> know
>> >> that it has done
>> >> everything it needs to do?
>> >>
>> >> --
>> >> Gerald Britton
>> >> ___
>> >> pygtk mailing list   py...@daa.com.au
>> >> http://www.daa.com.au/mailman/listinfo/pygtk
>> >> Read the PyGTK FAQ: http://faq.pygtk.org/
>> >>
>> >
>> >
>> >
>> >
>>
>>
>>
>> --
>> Gerald Britton
>>
>
>
>
>



-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] gtk.TreeModel.iter_children() method, how often should it be called?

2009-06-20 Thread Gerald Britton
I hear you, but I still need a direct answer to the question, "What
makes the TreeModel stop calling iter_children?  I can't find a clear
explanation and I can't figure it out by looking at the calls that
come into my method either.

On Thu, Jun 18, 2009 at 11:18 AM, Chris Camacho wrote:
>
> jeeze not being able to just reply is a pain anyhow
>
> I looked into using treemodels connecting to databases
>
> from what I could tell it seems to initially iterate all items
> and either copies them or creates meta data about the items
> (I didnt look into the implementation)
> Depending on how things were added it would also seem to iterate the whole
> set again!
> I think the standard treemodel is ok for small numbers (sub 200)
> but I had to end up paging 1,000's of items 100 at a time
> (interestingly this is what the gnome db widgets do...)
>
> I've been tempted to weld together my own data grid with a viewport
> and moving entry widgets but this would at a guess need C and I haven't
> had the time to look into it
>
>
> --- On Thu, 18/6/09, Gerald Britton  wrote:
>
>> From: Gerald Britton 
>> Subject: [pygtk] gtk.TreeModel.iter_children() method, how often should it 
>> be called?
>> To: pygtk@daa.com.au
>> Date: Thursday, 18 June, 2009, 2:50 PM
>> Hi -- I think I have a problem but
>> I'm not sure since I'm relatively
>> new to the TreeModel and how it works.  Here's the
>> scenario:
>>
>> I use TreeModel to display rows of data from a
>> database.  Upon
>> startup, the TreeModel is built and I notice two calls to
>> the
>> gtk.TreeModel.iter_children() method.  Later, I change
>> some data in
>> one of the rows.  The next time the TreeModel is
>> built,
>> gtk.TreeModel.iter_children() is called thousands of times
>> before the
>> display is refreshed. Oh, the database has less than 50
>> rows of data
>> in it!
>>
>> So, two questions:
>>
>> 1. Is this normal (I hope not!) behavior?
>>
>> 2. What tells the TreeModel to stop calling
>> gtk.TreeModel.iter_children()?  How does the TM know
>> that it has done
>> everything it needs to do?
>>
>> --
>> Gerald Britton
>> ___
>> pygtk mailing list   py...@daa.com.au
>> http://www.daa.com.au/mailman/listinfo/pygtk
>> Read the PyGTK FAQ: http://faq.pygtk.org/
>>
>
>
>
>



-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


[pygtk] gtk.TreeModel.iter_children() method, how often should it be called?

2009-06-18 Thread Gerald Britton
Hi -- I think I have a problem but I'm not sure since I'm relatively
new to the TreeModel and how it works.  Here's the scenario:

I use TreeModel to display rows of data from a database.  Upon
startup, the TreeModel is built and I notice two calls to the
gtk.TreeModel.iter_children() method.  Later, I change some data in
one of the rows.  The next time the TreeModel is built,
gtk.TreeModel.iter_children() is called thousands of times before the
display is refreshed. Oh, the database has less than 50 rows of data
in it!

So, two questions:

1. Is this normal (I hope not!) behavior?

2. What tells the TreeModel to stop calling
gtk.TreeModel.iter_children()?  How does the TM know that it has done
everything it needs to do?

-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


[pygtk] GtkBuilder and large files

2009-05-01 Thread Gerald Britton
I ran into this interesting discussion that pertains to my situation
of converting from libglade to GtkBuilder:

http://mail.gnome.org/archives/gtk-devel-list/2007-June/msg00313.html

I'm not sure if this discussion was ever resolved, but there are at
least two questions in it that interest me greatly:

1. does GtkBuilder cache the files it reads to save work on future
add_from_file calls?

2. What are the performance implications of having one big glade file
per application (maybe with scores of toplevels in it) versus one
toplevel per file or perhaps one glade file with a few toplevels per
functional area?

In my application, I have one big glade file (38 top levels at the
moment).  I'm concerned about the performance of rereading and
reparsing this file every time it is used by add_from_file (at the
moment I call this function from 40 separate places).  I'm prepared to
work on splitting it up by functional area, depending on the answers
to the questions above.

The other surprise in converting from libglade to GtkBuilder is, as
previously disussed, that libglade apparently has a hierarchical
namespace while GtkBuilder apparently has a flat one.  This is an
issue with multiple toplevels where they have children with the same
name(s).  I submitted a bug report on that already:

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




-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


[pygtk] custom handlers in libglade and gtk builder

2009-05-01 Thread Gerald Britton
Hi -- I'm converting a project from libglade to gtkbuilder and I've
run into a snag with custom objects.  In the code I'm working on there
is the line:

   from gtk.glade import set_custom_handler

followed by a function definition:

   def get_custom_handler(glade, function_name, widget_name,
                      str1, str2, int1, int2)

   ...

and

   set_custom_handler(get_custom_handler)

I need to know how to do the same sort of thing in the gtkbuilder
world.  So, how does one set up custom handlers in the gtk.builder
world?

Could someone provide an example that I can use as a basis?

--
Gerald Britton



-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] automagical glade

2009-04-14 Thread Gerald Britton
I think you can already do this with gtkbuilder.  something like:

builder.connect_signals(self)

will use introspection to match up signals with methods.

On Tue, Apr 14, 2009 at 3:02 PM, Chris Camacho  wrote:
> I've seen a lot of code with reams of variable=xml.get_widget statements
> and manually updated dictionaries of handler functions all of which is
> deeply unsatisfying, inelegant and prone to error
>
> Taking inspiration from a number of sources I have pieced together a very
> simple and short framework which integrates tightly with a .glade file
>
> It has the following features:-
>
> glade handlers are automatically mapped to functions within the handlers
> class
>
> All most all of your code will end up in handler class functions with very
> little setup code
>
> All widgets are mapped to a user interface object via their glade id and so
> they can be accessed like this...
>
> ui.entry1.set_text("hello world")
>
> The code is commented, it should be simple to follow and in addition
> techniques like __getattr__ should be useful for novice pythonites
>
> I'd appreciate any improvements providing they don't add extra complexity
>
> Hope this helps
> Chris_C
>
>
>
>
> ___
> pygtk mailing list   pygtk@daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
>



-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] Looking for help with comboboxes

2009-04-14 Thread Gerald Britton
Ok I think I found it.  The thing that made it work for me is changing:


  
   
 0
   

to:


  
   
 0
   

Is it true that the id="text" in the object must correspond to the
name="text" in the attribute?

On Tue, Apr 14, 2009 at 2:06 PM, Neil Muller  wrote:
> On Tue, Apr 14, 2009 at 6:25 PM, Gerald Britton
>  wrote:
>> Thanks Neil,
>>
>> So, with your suggestion in place, I have the program below.  I still
>> must be missing something though, since my combobox is still empty.
>
> I'm puzzled by that. It works fine for me (with minor modifications
> since I'm not running against gtk+ 2.16).  It correctly populates the
> list store, and the values are available in the combobox drop-down..
>
> The comobox doesn't have a default value though, so the initial
> display will be empty. This can be fixed by adding a call to
> set_active after filling the list store (c.set_active(0) for example)
>
>> I'm wondering about your comment about linking the model to the
>> renderer.
>
> The CellRendere needs to be told which column from the model to grab
> values from, This is accomplished by using the  property
> in GtkBuilder or the add_attributes method.
>
> --
> Neil Muller
> drnlmul...@gmail.com
>
> I've got a gmail account. Why haven't I become cool?
>



-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] Looking for help with comboboxes

2009-04-14 Thread Gerald Britton
Thanks Neil,

So, with your suggestion in place, I have the program below.  I still
must be missing something though, since my combobox is still empty.
I'm wondering about your comment about linking the model to the
renderer.  I tried coping the property line from the combobox, but the
builder didn't like that.  What is the correct way?

glade = """


  
  
  

  
  

  
  
Sample window with combo
box
440
250


  
True
liststore

  
   
 0
   

  

  

"""

import gtk
g = gtk.Builder()
g.add_from_string(glade)
g.connect_signals({ "on_window_destroy" : gtk.main_quit })

w = g.get_object('window')
c = g.get_object('combobox')
l = g.get_object('liststore')

for i in range(10):
#  c.append_text("line %d" % i)
  l.append(["line %d" % i])

w.show()
gtk.main()
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] Looking for help with comboboxes

2009-04-14 Thread Gerald Britton
Thanks for the tip.  I hope I can make it work for me.  I'm using
gtkbuilder instead of libglade but the builder combox has no
set_text_column method.  Not sure what to use.  I tried
set_column_span_column but that didn't do it

On Tue, Apr 14, 2009 at 10:48 AM, Lupine  wrote:
> Gerald,
>
> This is how I use a combobox.  For this example, read_hostsfile() just
> pulls in an array of hosts:
>
> def populate_cmbox_hostlist(self):
>    """Read in the HOSTSFILE and populate the drop down hosts list"""
>    filelines = read_hostsfile()
>    if filelines:
>        hosts = gtk.ListStore(str)
>        for fileline in filelines:
>            fileline = fileline.strip('\n')
>            hosts.prepend ([fileline])
>        self.widgets.get_widget('host_entry_cmbox').set_model(hosts)
>        self.widgets.get_widget('host_entry_cmbox').set_text_column(0)
>
>
> Doing it this way, also allows me to use entry completion (very cool
> stuff):
>
> def populate_cmbox_hostlist_entry_completion(self):
>    """Read in the HOSTSFILE and populate the entry completion"""
>    filelines = read_hostsfile()
>    if filelines:
>        completion = gtk.EntryCompletion()
>        hosts = gtk.ListStore(str)
>        for fileline in filelines:
>            fileline = fileline.strip('\n')
>            iter = hosts.append()
>            hosts.set(iter, 0, fileline)
>        self.widgets.get_widget('host_entry').set_completion(completion)
>        completion.set_model(hosts)
>        completion.set_text_column(0)
>
>
> Let me know if this points you in the right direction.
> -Lup
>
>
>
> On Tue, 2009-04-14 at 10:39 -0400, Gerald Britton wrote:
>> Hi -- I'm trying to learn how to use comboboxes.  I worked up a little
>> program to try to test it out (below, with imbedded glade).  I tried
>> two methods to get stuff to show in the box, but to no avail.  In the
>> first method I used the append_text method on the combobox.  In the
>> second method I used the append method on the liststore.  Obviously
>> I'm missing something but this newbie can't see what.  I tried both
>> methods separately and together with the same (bad) result.
>>
>> Would someone be able to point out what I am missing?
>>
>> glade = """
>> 
>> 
>>   
>>   
>>   
>>     
>>       
>>       
>>     
>>   
>>   
>>     Sample window with combo
>> box
>>     440
>>     250
>>     
>>     
>>       
>>         True
>>         liststore
>>       
>>     
>>   
>> 
>> """
>>
>> import gtk
>> g = gtk.Builder()
>> g.add_from_string(glade)
>> g.connect_signals({ "on_window_destroy" : gtk.main_quit })
>>
>> w = g.get_object('window')
>> c = g.get_object('combobox')
>> l = g.get_object('liststore')
>>
>> for i in range(10):
>>   c.append_text("line %d" % i)  # 1. try to append the text to the combobox
>>   l.append(["line %d" % i])        # 2. try to add the text to the
>> liststore in the combobox.
>>
>> w.show()
>> gtk.main()
>>
>>
>
>



-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


[pygtk] Looking for help with comboboxes

2009-04-14 Thread Gerald Britton
Hi -- I'm trying to learn how to use comboboxes.  I worked up a little
program to try to test it out (below, with imbedded glade).  I tried
two methods to get stuff to show in the box, but to no avail.  In the
first method I used the append_text method on the combobox.  In the
second method I used the append method on the liststore.  Obviously
I'm missing something but this newbie can't see what.  I tried both
methods separately and together with the same (bad) result.

Would someone be able to point out what I am missing?

glade = """


  
  
  

  
  

  
  
Sample window with combo
box
440
250


  
True
liststore
  

  

"""

import gtk
g = gtk.Builder()
g.add_from_string(glade)
g.connect_signals({ "on_window_destroy" : gtk.main_quit })

w = g.get_object('window')
c = g.get_object('combobox')
l = g.get_object('liststore')

for i in range(10):
  c.append_text("line %d" % i)  # 1. try to append the text to the combobox
  l.append(["line %d" % i])    # 2. try to add the text to the
liststore in the combobox.

w.show()
gtk.main()


-- 
Gerald Britton
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/