我想使用DeployScreen从LogViewScreen更新变量。每个类都是我的NucleusPanel中的一个选项卡/子代,它继承了TabbedPanel。我注意到,当我迭代父类的孩子时(NucleusPanel),我只能看到我当前正在使用的孩子对孩子进行迭代。如何从任一选项卡访问父母的所有孩子?
class DeployScreen(RelativeLayout):
def __init__(self, **kwargs):
super(DeployScreen, self).__init__(**kwargs)
....
def getTaskList(self, event, tasklist):
for c in self.parent.children:
print(c)
# update LogViewScreen button text
self.parent.ids.LogViewTab.selected_tasklist = tasklist
....
class LogViewScreen(RelativeLayout):
selected_tasklist = StringProperty(" ")
def __init__(self, **kwargs):
super(LogViewScreen, self).__init__(**kwargs)
# defaults
self.canvas.clear()
self.ViewingIndicatorBox = Button(
text=self.selected_tasklist,
size_hint=(1,None),
size=(self.size),
)
self.ViewingIndicatorBox.disabled = True
self.add_widget(self.ViewingIndicatorBox)
return(None)
pass
class NucleusPanel(TabbedPanel):
def __init__(self, **kwargs):
super(NucleusPanel, self).__init__(**kwargs)
self.tab_pos = "top_left"
self.tab_width = 265
self.default_tab_text = "Deploy"
self.default_tab.id ='DeployTab'
self.default_tab_content = DeployScreen()
self.lv_tab = TabbedPanelHeader(text='Log Viewer')
self.lv_tab.id = 'LogViewTab'
self.add_widget(self.lv_tab)
self.lv_tab.content = LogViewScreen()
pass
class NucleusApp(App):
def build(self):
return(NucleusPanel())
我希望能够从DeployScreen看到NucleusPanel下的所有孩子,但我只会看到DeployScreen:
<__main__.DeployScreen object at 0x000002262937DCE0>
答案 0 :(得分:0)
您可以使用以下方法遍历tab_list
来查看所有标签:
for c in App.get_running_app().root.tab_list:
print(c.content)
您可以在App
中的任何位置使用它。
答案 1 :(得分:0)
要从DeployScreen更新LogViewScreen中的ViewingIndicatorBox小部件,我只需为该按钮创建ID并使用收到的帮助,就可以遍历每个选项卡的内容并将搜索固定到Button实例的子项具有各自的ID。这是我的方法。
class DeployScreen(RelativeLayout):
def __init__(self, **kwargs):
super(DeployScreen, self).__init__(**kwargs)
....
def getTaskList(self, event, tasklist):
for c in NucleusApp.get_running_app().root.tab_list:
if 'LogView' in str(c.content):
for child in c.content.children:
if isinstance(child, Button) and child.id == 'VIB':
child.text = tasklist
....
class LogViewScreen(RelativeLayout):
selected_tasklist = StringProperty(" ")
def __init__(self, **kwargs):
super(LogViewScreen, self).__init__(**kwargs)
# defaults
self.canvas.clear()
self.ViewingIndicatorBox = Button(
id='VIB',
text='Current running log - {}'.format(self.selected_tasklist),
size_hint=(1,None),
size=(self.size),
background_normal='',
background_color=[0.18, 0.18, 0.31, 1],
pos_hint={'top':1},
height=50
)