本文整理汇总了Python中albow.TableView.slots方法的典型用法代码示例。如果您正苦于以下问题:Python TableView.slots方法的具体用法?Python TableView.slots怎么用?Python TableView.slots使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类albow.TableView
的用法示例。
在下文中一共展示了TableView.slots方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_inventory
# 需要导入模块: from albow import TableView [as 别名]
# 或者: from albow.TableView import slots [as 别名]
def build_inventory(self, items):
print "build_inventory"
print "Inventory" in self.data.keys()
# print type(self.data['Inventory'])
inventory = self.data.get('Player', {}).get('Inventory', TAG_List()) or self.data.get('Inventory', TAG_List())
rows = []
items = items[0]
slots = [["%s"%i,"","0","0"] for i in range(36)]
slots_set = []
for item in items:
s = int(item['Slot'].value)
slots_set.append(s)
slots[s] = item['Slot'].value, item['id'].value.split(':')[-1], item['Count'].value, item['Damage'].value
width = self.width / 2 - self.margin * 4
c0w = max(15, self.font.size("00")[0]) + 4
c2w = max(15, self.font.size("00")[0]) + 4
c3w = max(15, self.font.size("000")[0]) + 4
c1w = width - c0w - c2w - c3w
font_height = self.font.size("qd")[1]
tableCols = [TableColumn("#", c0w),
TableColumn("ID", c1w),
TableColumn("C", c2w),
TableColumn("D", c3w),
]
height = self.displayRow.subwidgets[0].height
table = TableView(height=height - (self.margin * 2),
width=width,
nrows=((height - (self.margin * 2) - font_height / 2) / font_height),
columns=tableCols,
row_height=font_height,
header_height=font_height / 2)
table.rows.tooltipText = "Double-click to edit"
table.selected_row = None
table.slots = slots
def num_rows():
return len(slots)
table.num_rows = num_rows
def row_data(n):
return slots[n]
table.row_data = row_data
def click_row(n, e):
table.selected_row = n
if e.num_clicks > 1:
SlotEditor(table, row_data(n)).present()
table.click_row = click_row
def row_is_selected(n):
return n == table.selected_row
table.row_is_selected = row_is_selected
def change_value(data):
s, i, c, d = data
s = int(s)
s_idx = 0
if s in slots_set:
# for slot in self.data['Player']['Inventory']:
for slot in inventory:
if slot['Slot'].value == s:
if not i or int(c) < 1:
del inventory[s_idx]
i = ""
c = u'0'
d = u'0'
else:
slot['id'].value = 'minecraft:%s'%i
slot['Count'].value = int(c)
slot['Damage'].value = int(d)
break
s_idx += 1
else:
new_slot = TAG_Compound()
new_slot['Slot'] = TAG_Byte(s)
new_slot['id'] = TAG_String('minecraft:%s'%i)
new_slot['Count'] = TAG_Byte(int(c))
new_slot['Damage'] = TAG_Short(int(d))
idx = s
for slot in inventory:
if slot['Slot'].value >= s:
idx = slot['Slot'].value
break
inventory.insert(s, new_slot)
slots_set.append(s)
table.slots[s] = slots[s] = s, i, c, d
table.change_value = change_value
rows.append(table)
return rows
示例2: build_inventory
# 需要导入模块: from albow import TableView [as 别名]
# 或者: from albow.TableView import slots [as 别名]
def build_inventory(self, items):
inventory = self.data.get('Player', {}).get('Inventory', TAG_List()) or self.data.get('Inventory', TAG_List())
rows = []
items = items[0]
slots = [["%s"%i,"","0","0"] for i in range(36)]
slots += [["%s"%i,"","0","0"] for i in range(100, 104)]
slots_set = []
for item in items:
#&# Prototype for blocks/items names
item_dict = mcitems.items.get(item['id'].value, None)
if item_dict == None:
name = item['id'].value
else:
if type(item_dict['name']) == list:
if int(item['Damage'].value) >= len(item_dict['name']):
block_id = map_block.get(item['id'].value, None)
name = alphaMaterials.get((int(block_id), int(item['Damage'].value))).name.rsplit('(', 1)[0].strip()
else:
name = item_dict['name'][int(item['Damage'].value)]
else:
name = item_dict['name']
s = int(item['Slot'].value)
slots_set.append(s)
if s >= 100:
s = s - 100 + 36
slots[s] = item['Slot'].value, mclangres.translate(name), item['Count'].value, item['Damage'].value
#slots[s] = item['Slot'].value, item['id'].value.split(':')[-1], item['Count'].value, item['Damage'].value
#&#
width = self.side_panel_width - self.margin * 5
c0w = max(15, self.font.size("000")[0]) + 4
c2w = max(15, self.font.size("00")[0]) + 4
c3w = max(15, self.font.size("000")[0]) + 4
c1w = width - c0w - c2w - c3w
font_height = self.font.size("qd")[1]
tableCols = [TableColumn("#", c0w),
TableColumn("ID", c1w),
TableColumn("C", c2w),
TableColumn("D", c3w),
]
height = self.displayRow.subwidgets[0].height
table = TableView(height=height - (self.margin * 2),
width=width,
nrows=((height - (self.margin * 2) - font_height / 2) / font_height),
columns=tableCols,
row_height=font_height,
header_height=font_height / 2)
table.rows.tooltipText = "Double-click to edit"
table.selected_row = None
table.slots = slots
def num_rows():
return len(slots)
table.num_rows = num_rows
def row_data(n):
return slots[n]
table.row_data = row_data
def click_row(n, e):
table.selected_row = n
if e.num_clicks > 1:
SlotEditor(table, row_data(n)).present()
table.click_row = click_row
def row_is_selected(n):
return n == table.selected_row
table.row_is_selected = row_is_selected
def change_value(data):
s, i, c, d = data
s = int(s)
s_idx = 0
#&# Prototype for blocks/items names
name, state = map_items.get(mclangres.untranslate(i), (i, '0'))
if ':' not in name:
name = 'minecraft:%s'%name
#&#
if s in slots_set:
for slot in inventory:
if slot['Slot'].value == s:
if not i or int(c) < 1:
del inventory[s_idx]
i = ""
c = u'0'
d = u'0'
else:
#&# Prototype for blocks/items names
#slot['id'].value = 'minecraft:%s'%i
slot['id'].value = name
#&#
slot['Count'].value = int(c)
slot['Damage'].value = int(state)
break
s_idx += 1
else:
new_slot = TAG_Compound()
new_slot['Slot'] = TAG_Byte(s)
#&# Prototype for blocka/items names
#new_slot['id'] = TAG_String('minecraft:%s'%i)
#.........这里部分代码省略.........
示例3: build_inventory
# 需要导入模块: from albow import TableView [as 别名]
# 或者: from albow.TableView import slots [as 别名]
def build_inventory(self, items):
if 'playerGameType' in self.tree.get_item_parent(self.displayed_item)[9].keys():
player = True
else:
player = False
inventory = self.tree.get_item_parent(self.displayed_item)[9].get('Inventory', TAG_List())
rows = []
items = items[0]
slots = [["%s"%i,"","0","0"] for i in range(36)]
slots += [["%s"%i,"","0","0"] for i in range(100, 104)]
slots_set = []
for item, i in zip(items, range(len(items))):
#&# Prototype for blocks/items names
item_dict = mcitems.items.get(item['id'].value, None)
if item_dict == None:
name = item['id'].value
else:
if type(item_dict['name']) == list:
if int(item['Damage'].value) >= len(item_dict['name']):
block_id = map_block.get(item['id'].value, None)
name = alphaMaterials.get((int(block_id), int(item['Damage'].value))).name.rsplit('(', 1)[0].strip()
else:
name = item_dict['name'][int(item['Damage'].value)]
else:
name = item_dict['name']
s = i
_s = 0 + i
if player:
s = int(item['Slot'].value)
_s = 0 + s
slots_set.append(s)
if s >= 100:
s = s - 100 + 36
slots[s] = _s, mclangres.translate(name), item['Count'].value, item['Damage'].value
#slots[s] = item['Slot'].value, item['id'].value.split(':')[-1], item['Count'].value, item['Damage'].value
#&#
width = self.side_panel_width - self.margin * 5
c0w = max(15, self.font.size("000")[0]) + 4
c2w = max(15, self.font.size("00")[0]) + 4
c3w = max(15, self.font.size("000")[0]) + 4
c1w = width - c0w - c2w - c3w
font_height = self.font.size("qd")[1]
tableCols = [TableColumn("#", c0w),
TableColumn("ID", c1w),
TableColumn("C", c2w),
TableColumn("D", c3w),
]
height = self.displayRow.subwidgets[0].height
table = TableView(height=height - (self.margin * 2),
width=width,
nrows=((height - (self.margin * 2) - font_height / 2) / font_height),
columns=tableCols,
row_height=font_height,
header_height=font_height / 2)
table.rows.tooltipText = "Double-click to edit"
table.selected_row = None
table.slots = slots
def num_rows():
return len(slots)
table.num_rows = num_rows
def row_data(n):
return slots[n]
table.row_data = row_data
def click_row(n, e):
table.focus()
table.selected_row = n
if e.num_clicks > 1:
SlotEditor(table, row_data(n)).present()
table.click_row = click_row
def row_is_selected(n):
return n == table.selected_row
table.row_is_selected = row_is_selected
def change_value(data):
s, i, c, d = data
s = int(s)
s_idx = 0
#&# Prototype for blocks/items names
name, state = map_items.get(mclangres.untranslate(i), (i, '0'))
if ':' not in name:
name = 'minecraft:%s'%name
#&#
if s in slots_set:
for slot in inventory:
ok1 = False
if player:
ok1 = slot['Slot'].value == s
else:
ok1 = inventory.index(slot) == s
if ok1:
if not i or int(c) < 1:
del inventory[s_idx]
i = ""
c = u'0'
d = u'0'
#.........这里部分代码省略.........