Я столкнулся с проблемой, из-за которой я не совсем понимаю, почему она возникает. У меня есть класс под названием ListViewContainer
, который в основном создает основную gui моей программы ...
Эта функция (popup_function
) (внутри ListViewConatiner) вызывается всякий раз, когда я нажимаю на элемент в моем пользовательский интерфейс. Он отображает соответствующие сведения об этом элементе, по которому был выполнен щелчок.
def popup_function(self, instance):
mycursor.execute(Particular_element_selection, (instance.name,))
self.data = mycursor.fetchone()
self.win_pos_height = instance.to_window(instance.x, instance.y)[1]
self.popup_card_height = Window.height - 3* Window.height/10
self.container = FloatLayout(size = Window.size,
y = self.win_pos_height,
)
self.popup_card = MDCard(size = (Window.width- Window.width/21,0),
pos = self.container.pos,
pos_hint = {"center_x": 0.5},
radius = (40,40,40,40),
padding = (5,5,5,5),
size_hint = (None, None),
elevation = 0,
opacity = 0
)
self.layout = ModalView(
size = (Window.width- Window.width/21,self.popup_card_height),
pos = self.popup_card.pos,
size_hint = (None,None),
background_color = (0,0,0,.7)
)
self.popup_view = Popup_view()
self.popup_view.ids.title.text = self.data[1]
self.popup_view.ids.description.text = self.data[2]
if self.data[3][2].isalpha():
global current_view
current_view = 'days'
self.days_view = Days_view()
self.popup_view.ids.popup_container.add_widget(self.days_view)
self.popup_view.ids.days.color = theme_cls.primary_color
self.Color_setter()
self.popup_card.add_widget(self.popup_view)
self.container.add_widget(self.popup_card)
self.layout.add_widget(self.container)
self.layout.open()
anim1 = Animation(size = (Window.width- Window.width/21,self.popup_card_height),
pos = (0,(Window.height - self.popup_card_height)/2
),
duration = .2)
anim1 &= Animation(opacity = 1, duration = .5)
anim1.start(self.popup_card)
Всплывающая функция также добавляет еще один настраиваемый виджет, который я определил как Popup_View()
. Этот виджет полностью определен внутри kv следующим кодом ...
Python
class Popup_view(Widget):
variable = ListViewContainer
Переменная используется, чтобы MDchip мог получить доступ к соответствующая функция внутри класса ListViewContainer
Kv
<Popup_view>:
FloatLayout:
id:popup_container
size: self.parent.size
pos: self.parent.pos
size_hint: None, None
MDTextField:
id:title
hint_text: "Title"
font_name: "Roboto-Black"
font_size:"20sp"
color_mode: 'custom'
line_color_focus: app.theme_cls.text_color
multiline: True
size_hint_x:.9
size_hint_y: None
pos_hint:{"top": 0.95, "center_x":.5}
MDTextField:
id:description
hint_text: "Description"
font_name: "Roboto-Regular"
font_size:"15sp"
color_mode: 'custom'
line_color_focus: app.theme_cls.text_color
multiline: True
size_hint_y: None
size_hint_x:.9
pos_hint:{"top": .75, "center_x":.5}
MDLabel:
text: "Reminding you on these "
theme_text_color: "Primary"
pos_hint:{"top": 1, "center_x":.5}
font_name: "Roboto-Black"
font_size:"15sp"
size_hint_x:.9
MDChooseChip:
pos_hint:{"center_x": 1, "center_y":.5}
MDChip:
id:dates
label: 'Dates'
icon: 'calendar-range'
selected_chip_color:app.theme_cls.primary_color
text_color:app.theme_cls.text_color
callback:self.parent.parent.parent.variable.test(self,'Dates')
MDChip:
id:days
label: 'Days'
icon: 'calendar-today'
selected_chip_color:app.theme_cls.primary_color
text_color:app.theme_cls.text_color
callback:self.parent.parent.parent.variable.test(self,'Days')
Теперь, когда я нажимаю один из чипов выбора, он запускает другую функцию, которая написана внутри ListViewContainer
класс называется test
. Функция test
должна удалить виджет Days_view
, который был добавлен в popup_function
.
def test(self, value):
#The code that deletes the widget Days_view
Но как бы я ни старался, я не могу получить доступ к этому виджету. Это вообще возможно? и, как вы можете ясно видеть из моего запутанного кода, я не настолько хорош в программировании OOP :). Спасибо за помощь