如何允许 UltimateListCtrl 重新排列自身,wxpython
如何允许 UltimateListCtrl 能够根据用户输入重新排序/重新排列自身?以下显示了该功能,但我不确定如何做到这一点。 数据 = { 0:(“3”,“3”,“1”), 1:(“2”,“1”,“2”), 2:(“1”、“2”、“3”) }
import wx
import wx.lib.mixins.listctrl as listmix
from wx.lib.agw import ultimatelistctrl as ULC
class MyList(ULC.UltimateListCtrl, listmix.ColumnSorterMixin):
def __init__(self, parent, columns):
ULC.UltimateListCtrl.__init__(self, parent, agwStyle=ULC.ULC_REPORT | ULC.ULC_HAS_VARIABLE_ROW_HEIGHT)
self.itemDataMap = DATA
listmix.ColumnSorterMixin.__init__(self, columns)
self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColumn)
def OnColumn(self, e):
self.Refresh()
e.Skip()
def GetListCtrl(self):
return self
class MainWindow(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.list = MyList(self, 3)
self.list.InsertColumn(0, "A")
self.list.InsertColumn(1, "B")
self.list.InsertColumn(2, "C")
items = DATA.items()
for key, data in items:
index = self.list.Append(data)
self.list.SetItemData(index, key)
self.Show()
app = wx.App(False)
win = MainWindow(None)
app.MainLoop()
how can I allow a UltimateListCtrl, to be able to reorder/rearrange itself with the users input? The following shows the ability however i am not sure how it can be done.
DATA = {
0 : ("3", "3", "1"),
1 : ("2", "1", "2"),
2 : ("1", "2", "3")
}
import wx
import wx.lib.mixins.listctrl as listmix
from wx.lib.agw import ultimatelistctrl as ULC
class MyList(ULC.UltimateListCtrl, listmix.ColumnSorterMixin):
def __init__(self, parent, columns):
ULC.UltimateListCtrl.__init__(self, parent, agwStyle=ULC.ULC_REPORT | ULC.ULC_HAS_VARIABLE_ROW_HEIGHT)
self.itemDataMap = DATA
listmix.ColumnSorterMixin.__init__(self, columns)
self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColumn)
def OnColumn(self, e):
self.Refresh()
e.Skip()
def GetListCtrl(self):
return self
class MainWindow(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.list = MyList(self, 3)
self.list.InsertColumn(0, "A")
self.list.InsertColumn(1, "B")
self.list.InsertColumn(2, "C")
items = DATA.items()
for key, data in items:
index = self.list.Append(data)
self.list.SetItemData(index, key)
self.Show()
app = wx.App(False)
win = MainWindow(None)
app.MainLoop()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您需要这样的东西:
请注意,您还应该自动执行 InsertColumn 过程,以通过编程方式考虑列数。如果您不需要特殊的列名并且只使用几个列名,则可以使用 string.ascii_uppercase 来获取每列的字母。
然后在框架中实例化该类:
我将 DATA 放在这里,但稍微修改一下代码,它可以通过像 MainWindow(self, DATA) 这样的调用从外部发送。
Maybe you are asking for something like this:
Note you should also automate the InsertColumn process to take into account the number of columns programmatically. If you dont need special column names and you are only to use a few, you could use string.ascii_uppercase to get the letter for each column.
Then you instantiate the class in your Frame:
I put DATA here but modifying the code a bit it could be send from outside with a call like MainWindow(self, DATA).