我有Gtk.Grid,在调整窗口大小后,它不会刷新(事件列和所有内容都设置正确),但是当你再次调整大小或点击项目时,它会重新绘制。
Gtk.main_iteration()导致python3中的段错误
from gi.repository import GLib, Gtk
class Grid(Gtk.Grid):
min_width = 400
min_height = 300
min_spacing = 20
def __init__(self):
Gtk.Grid.__init__(self, name='feed_grid',
row_spacing=20, column_spacing=20)
self.set_column_homogeneous(True)
self.set_size_request(self.min_width, self.min_height)
self.connect('size-allocate', self._on_size_allocate)
self._cols = 2
def _on_size_allocate(self, widget, allocation):
self.set_width(allocation.width)
def set_width(self, width):
self._cols = (width + self.min_spacing) // self.min_width
self._rebuild_grid()
def get_columns(self):
return self._cols
def add_feed(self, feed):
feed.set_order(len(self.get_children()))
self._attach_feed(feed)
feed.show_all()
def _rebuild_grid(self):
for feed in self.get_children():
self.remove(feed)
self._attach_feed(feed)
def _attach_feed(self, feed):
y, x = divmod(feed.get_order(), self.get_columns())
self.attach(feed, x, y, 1, 1)
错误报告 https://bugs.launchpad.net/ubuntu/+source/gtk+3.0/+bug/987565
视频 https://launchpadlibrarian.net/102937139/floaty%20resize.ogv