开发者

PyGTK - polling GTK table for locations of widgets

开发者 https://www.devze.com 2023-01-15 19:51 出处:网络
I\'m working on a Python application involving the use of a GTK table.The application requires that widgets of various sizes be added to a table dynamically.Because of this, I need to be able to ask t

I'm working on a Python application involving the use of a GTK table. The application requires that widgets of various sizes be added to a table dynamically. Because of this, I need to be able to ask the table what cells are in use (more accurately, NOT in use) so that I know where I can place a new widget without overlapping.

Based on the information in the reference manual (http://www.pygtk.org/docs/pygtk/) I have been unable to find a way to get that information directly from the table. The only other option I can think of is to create a map object that holds used cell information, and have it updated upon changes to the table.

Since I'm sure someone has dealt with this before me, and I would hope GTK would provide a better way, it see开发者_如何学运维med wise to ask around before trying to implement the map.

Help would be greatly appreciated.


This function should give you a set of the free cells in the table:

def free_cells(table):
    free_cells = set([(x,y) for x in range(table.props.n_columns) for y in range(table.props.n_rows)])

    def func(child):
        (l,r,t,b) = table.child_get(child, 'left-attach','right-attach','top-attach','bottom-attach')
        used_cells = set([(x,y) for x in range(l,r) for y in range(t,b)])
        free_cells.difference_update(used_cells)

    table.foreach(func)

    return free_cells

It starts with a set of all the table cells, then iterates over the children of the table, removing the cells occupied by each child.


I'm the original poster, was logged into wrong account when posting question.

Anyway, this appears to be exactly what I'm looking for! Thanks Geoff!

0

精彩评论

暂无评论...
验证码 换一张
取 消