From the documentation:
name
Name of the screen which must be unique within a ScreenManager.
I don't see any code creating new GroupScreens
, but wherever you put that code, you must include a unique name="some_group_name"
for it.
I my experience, in order to allow Buttons
to operate in an MDDialog
, you must add auto_dismiss=False
to its declaration:
def show_dialog(self, *args):
'''
Create group creation popup
'''
if not self.dialog:
self.dialog = MDDialog(
text="Create new group",
type="custom",
auto_dismiss=False, # needed to allow Buttons to operate
content_cls=DialogContent(),
)
self.dialog.open()
Then, the new_window()
method can create the new GroupScreen
and the Button
:
def new_window(self, *args):
'''
Create new group button
'''
group_name = self.dialog.content_cls.textfield.text
mylist = TwoLineAvatarListItem(text=group_name,
on_release = partial(self.goto_group, group_name)) # use partial to pass group name
self.mdlist.add_widget(mylist)
sm.add_widget(GroupScreen(name=group_name)) # actually create the new GroupScreen and add it
And the goto_group()
method becomes:
def goto_group(self, group_name, *args):
sm.current = group_name # switch current screen to the passed in group
The App
declaration can be:
class grudget4App(MDApp):
def build(self):
sm.add_widget(MainScreen(name='main'))
# sm.add_widget(GroupScreen(name='group'))
# scroll = ScrollView()
return sm
Note the above requirement for unique name
for Screens
. You should take care that the user doesn't create duplicate group names.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…