大家好,我有个问题,不知道该怎么办。我有一些位图是根据一个查询生成的,这里的问题是,一旦查询变大一点,我的应用程序就使用了所有允许windows使用的10000个GDI对象,然后就崩溃了。我不太熟悉w/GDI资源,但也许有一种方法可以解决这个问题。下面是失败的代码片段
图例文件
def _init_ui(self):
"""Initialize UI components."""
# Add layout management
self.hbox = wx.BoxSizer(wx.HORIZONTAL)
self.fgs = wx.FlexGridSizer(rows=self.n_items, cols=2, vgap=0, hgap=0)
# Create items to add
for _i, (key, value) in enumerate(zip(self.labels, self.colors)):
self.label = wx.StaticText(self,
label=str(key),
style=wx.ALIGN_LEFT,
)
self.colorbox = csel.ColourSelect(self,
_i,
"",
tuple(value),
style=wx.NO_BORDER,
size=(20, 20 ))
self.Bind(csel.EVT_COLOURSELECT, self.on_color_pick, id=_i)
self.fgs.Add(self.label, flag=wx.ALIGN_CENTER_VERTICAL)
self.fgs.Add(self.colorbox)
# Add our items to the layout manager and set the sizer.
self.hbox.Add(self.fgs)
self.SetSizer(self.hbox)
在线路尺寸(20,20)处失效 然后这个文件调用我的 颜色选择文件
def __init__(self, parent, id=wx.ID_ANY, label="", colour=wx.BLACK,
pos=wx.DefaultPosition, size=wx.DefaultSize,
callback=None, style=0):
size = wx.Size(*size)
if label:
mdc = wx.MemoryDC(wx.Bitmap(1,1))
w, h = mdc.GetTextExtent(label)
w += 8
h += 8
else:
w, h = 22, 22
size.width = size.width if size.width != -1 else w
size.height = size.height if size.height != -1 else h
super(ColourSelect, self).__init__(parent, id, wx.Bitmap(w,h,32),
pos=pos, size=size, style=style,
name='ColourSelect')
if type(colour) == type( () ):
colour = wx.Colour(*colour)
self.colour = colour
self.SetLabel(label)
self.callback = callback
bmp = self.MakeBitmap()
self.SetBitmap(bmp)
self.customColours = None
parent.Bind(wx.EVT_BUTTON, self.OnClick, self)
调用时失败自我设置映射(bmp)
在同一个文件中调用这个小函数
def SetBitmap(self, bmp):
"""
Sets the bitmap representation of the current selected colour to the button.
:param wx.Bitmap `bmp`: the new bitmap.
"""
self.SetBitmapLabel(bmp)
self.Refresh()
最后是追溯到我的文件中的最后一个函数buttons
def SetBitmapLabel(self, bitmap, createOthers=True):
self.bmpLabel = bitmap
if bitmap is not None and createOthers:
image = bitmap.ConvertToImage()
imageutils.grayOut(image)
self.SetBitmapDisabled(wx.Bitmap(image))
失败发生在**image=位图.ConvertToImage() ** 如果有人能提出任何改变,以帮助优化我的程序,我将非常感谢。很多代码都是从其他库导入的,所以我对其中的一部分不是很熟悉。希望有人有主意
目前没有回答
相关问题 更多 >
编程相关推荐