当前位置: 首页 > 工具软件 > Urwid > 使用案例 >

python listbox失去焦点_Python urwid.TreeListBox方法代码示例

董高逸
2023-12-01

# 需要导入模块: import urwid [as 别名]

# 或者: from urwid import TreeListBox [as 别名]

def __init__(self, chat_widget, close_callback=None):

self.chat_widget = chat_widget

self.ui = chat_widget.ui

self.close_callback = close_callback

items = []

for server in sorted(chat_widget.discord.servers,

key=lambda s: s.name):

node = {"name": server.name,

'server_tree': self,

'server': server,

"children": []}

for ch in server.channels:

if ch.type == discord.ChannelType.text:

node['children'].append({

'name': ch.name,

'server_tree': self,

'channel': ch

})

nodeobj = TreeNodeServer(node)

nodeobj.expanded = False

items.append(nodeobj)

if len(chat_widget.discord.private_channels) > 0:

node = {"name": "Private Chats",

'server_tree': self,

'server': None,

"children": []}

for ch in chat_widget.discord.private_channels:

name = ''

if ch.type == discord.ChannelType.private:

name = ch.user.display_name

elif ch.type == discord.ChannelType.group:

name = ch.name or ', '.join(u.display_name for u in ch.recipients)

else:

continue

node['children'].append({

'name': name,

'server_tree': self,

'channel': ch

})

nodeobj = TreeNodeServer(node)

nodeobj.expanded = False

items.append(nodeobj)

self.w_listbox = urwid.TreeListBox(TreeWalker(items))

self.__super.__init__(self.w_listbox)

 类似资料: