日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

wxpython下载缓慢_我可以在wxPython的wx.grid.Grid中加速优化GridCellAttr的使用吗?

發(fā)布時(shí)間:2023/12/2 python 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 wxpython下载缓慢_我可以在wxPython的wx.grid.Grid中加速优化GridCellAttr的使用吗? 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

設(shè)置單元格屬性將新GridCellAttr添加到GridCellAttrProvider名單。 隨著列表的增長,查找單元格的特定屬性(通過遍歷列表和比較坐標(biāo))變得越來越慢。

您可以嘗試通過PyGridTableBase.SetAttr和GetAttr(例如使用字典)實(shí)現(xiàn)自己的加快步伐:

編輯:更新后的代碼,以允許重寫屬性和仿效的默認(rèn)實(shí)現(xiàn)屬性的所有權(quán)。

class MyTable(wx.grid.PyGridTableBase):

atts = {}

def Hash(self,row,col):

#FIXME: assumes a constant number of rows and rows > cols

return col + row * self.GetNumberRows()

def SetAttr(self,attr,row,col):

HASH = self.Hash(row, col)

if HASH in self.atts:

# decrement usage count of existing attr

self.atts[HASH].DecRef()

#assign new attribute

self.atts[HASH] = attr

def GetAttr(self,row,col,kind):

HASH = self.Hash(row, col)

if HASH in self.atts:

attr = self.atts[HASH]

attr.IncRef() # increment reference count

return attr

return None

要允許設(shè)置整個(gè)行和列,你還必須實(shí)現(xiàn):

def SetRowAttr(self,attr,row):

for col in range(self.GetNumberCols()):

attr.IncRef() # increment reference count for SetAttr

self.SetAttr(attr,row,col)

attr.DecRef() # attr passed to SetRowAttr no longer needed

def SetColAttr(self,attr,col):

for row in range(self.GetNumberRows()):

attr.IncRef()

self.SetAttr(attr,row,col)

attr.DecRef()

注:路過時(shí)GridCellAttr到Set*Attr(),默認(rèn)的實(shí)現(xiàn)將采取屬性的所有權(quán)。 要重新使用相同的屬性(例如存儲在類變量中),您必須先將其使用Clone()或?qū)⑵涫褂糜?jì)數(shù)遞增(IncRef()) ,然后再將其傳遞給Set*Attr()方法(克隆可能會增加內(nèi)存消耗)。

上述示例沒有正確刪除屬性:SetAttr()可能會檢查無attr并在指定的坐標(biāo)處遞減ref計(jì)數(shù),然后從dict中刪除條目。 SetCol/RowAttr()可以通過添加為ROW和COL,類似于SetAttr() http://stardict.sourceforge.net/Dictionaries.php下載進(jìn)行優(yōu)化。 GetAttr()然后可以檢查行和冒號中的現(xiàn)有條目,并使用單元格dict中的屬性(這是默認(rèn)實(shí)現(xiàn)使用的原則)合并/覆蓋該屬性。要正確清理字典,請?jiān)?clear()之前的每個(gè)條目上撥打DecRef。

或者,您可以從wx.grid.GridCellAttrProvider派生并附加PyGridTableBase.SetAttrProvider()。但是,這會阻止直接訪問表格。

總結(jié)

以上是生活随笔為你收集整理的wxpython下载缓慢_我可以在wxPython的wx.grid.Grid中加速优化GridCellAttr的使用吗?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。