我有一个带有wx.Grid的wx.Dialog,它包含在ScrolledWindow面板中。该对话框由主框架上的菜单项启动,该菜单项不是对话框的父框架。
我正在执行GUI组件创建过程中的打印语句,所以我不确定为什么Dialog中偶尔没有内容?
当这种情况开始发生时,我关闭并重新启动对话框,但它经常连续多次发生,然后看似自行解决,正常显示在第5次+尝试。
还有其他人遇到过这个吗?原因是什么?
我正在使用Ubuntu 16.04 LTS和wx.Python 3.0
编辑:包括我认为问题所在的代码示例。
我有一个'重绘'由于ScrolledWindow而被调用以计算Dialog大小的方法。 wx.Grid的每一行旁边都有按钮,所以我不能让wx.Grid处理它自己的滚动。在向wx.Grid添加新行之后调用此方法。
重绘方法如下:
def redraw(self):
# a change has been made to the file, reset saved boolean
self.m_saved_or_cancelled = False
# call these to update the view
self.m_list_view.AutoSize() # this is the wx.Grid
self.m_list_view.Fit()
self.scrolled_panel.Layout()
self.Layout()
self.Fit()
# as we have a scrolledWindow panel - we must update the minimum size in order to display the view
# the maximum size is the display size
display_width, display_height = wx.DisplaySize()
w, sizer_height = self.main_sizer.GetSize()
# height of the rows
button_height = 10
# number of items
items = self.m_list_view.GetNumberRows() + 1
cols = self.m_list_view.GetNumberCols()
# column widths added together
col_width = 100
for col in range(cols):
col_width += self.m_list_view.GetColSize(col)
print "col_width %s" % col_width
# height is at least the minimum or the row height * number of items
height = button_height * items
print "sizer_height %s, height %s" % (sizer_height, height)
if height < self.MIN_WINDOW_HEIGHT:
height = self.MIN_WINDOW_HEIGHT
print "sizer_heighth %s, height %s" % (sizer_height, height)
if height <= sizer_height:
# increase by a factor of this space 2/3
height += ((sizer_height)/3)
print "height %s" % height
if height > (display_height - self.MAX_WINDOW_HEIGHT_OFFSET):
self.SetMinSize((col_width, display_height - self.MAX_WINDOW_HEIGHT_OFFSET))
self.SetSize((col_width, display_height - self.MAX_WINDOW_HEIGHT_OFFSET))
else:
self.SetMinSize((col_width, height))
self.SetSize((col_width, height))
# the virtual size has to be greater than required space rather significantly in order to display correctly
self.scrolled_panel.SetVirtualSize((col_width, height))
self.scrolled_panel.AdjustScrollbars()
self.scrolled_panel.Layout()
# centered
self.CenterOnScreen()