我有一个清单字典。在我的应用程序中,用户将从微调器中选择一个选项,该选项将更新微调器中的文本和绑定的StringProperty
,用作字典的键。然后,我使用RecycleView
显示和使用RecycleGridLayout
显示列表。
我想以微调框文本作为“选择您的选项”开始;但是,这将引发错误,因为“选择您的选项”不是字典键。有没有办法仅在选择微调器之后填充RecycleView? (我意识到我可以将“选择您的选项”添加为具有空列表的字典键;但是,这些列表将对象传递给也需要填充的其他小部件-这是一个级联的问题!)
这是一些示例代码:
class Overmind(RelativeLayout):
inventory = ObjectProperty(None, rebind = True)
current_faction = StringProperty('')
class FactionSelector(BoxLayout):
faction = StringProperty(None)
class StatViewerApp(App):
with open('Data\MasterUnitLists\master_inventory.p', 'rb') as file:
ModelsMaster = load(file)
def build(self):
return self.root
if __name__ == '__main__':
StatViewerApp().run()
Kivy lang:
Overmind:
current_faction: faction_selector.faction
inventory: app.ModelsMaster[root.current_faction]
AnchorLayout:
anchor_y: 'top'
anchor_x: 'left'
FactionSelector:
id: faction_selector
size_hint: (0.25,0.2)
orientation: 'horizontal'
RecycleView:
size_hint: (1,0.8)
viewclass: 'UnitThumbnail'
data: [{'unit':unit} for unit in root.inventory]
RecycleGridLayout:
size_hint: (1,None)
cols: 5
spacing: 10
col_default_width: self.width//5
height: self.minimum_height
<FactionSelector>:
faction: facspin.text if facspin.text != 'Select your faction:' else None
Image:
size_hint: (0.75,1)
source: 'Images\\' + root.faction + '\\' + root.faction + '.png' if root.faction else None
Spinner:
id: facspin
text: 'Select your faction:'
values: (faction for faction in app.ModelsMaster)
FactionSelector的微调器更新StringProperty'faction',该绑定到StringProperty'current_faction',该字符串用作“ MasterModels”字典的键。此值提供给“清单” ObjectProperty,该属性用于填充RecycleView的数据。 RecycleView(和UnitThumbnail)是基于清单中的数据绘制的-那么如何防止在用户做出选择之前绘制它们?