def show_cart(self): global cart_list self.ids.cart_listing.clear_widgets() #print('Cart:') for product in cart_list: #print(product) cart_product = BoxLayout(orientation='vertical') cart_item = BoxLayout(orientation='horizontal') cart_image = AsyncImage(source=product['img'], size_hint_x=.3) cart_name = MDLabel(text=product['title'], size_hint_x=.3) cart_price = MDLabel(text=str(product['price']) + 'p', size_hint_x=.1) cart_cancel_button = MDTextButton( id=str(product['id']), text='X', size_hint_x=.1, pos_hint={ 'center_x': 1, 'center_y': .5 }, font_size='25dp', on_release=lambda x: self.remove_from_cart(int(x.id))) cart_empty_space = Widget(size_hint_x=.025) cart_item.add_widget(cart_image) cart_item.add_widget(cart_name) cart_item.add_widget(cart_price) cart_item.add_widget(cart_cancel_button) cart_item.add_widget(cart_empty_space) cart_product.add_widget(cart_item) self.ids.cart_listing.add_widget(cart_product)
def set_content(self, instance_content_dialog): def _events_callback(result_press): self.dismiss() if result_press: self.events_callback(result_press, self) if self.device_ios: # create buttons for iOS self.background = self._background if instance_content_dialog.__class__ is ContentInputDialog: self.text_field = MDTextFieldRect( pos_hint={'center_x': .5}, size_hint=(1, None), multiline=False, height=dp(33), cursor_color=self.theme_cls.primary_color, hint_text=instance_content_dialog.hint_text) instance_content_dialog.ids.box_input.height = dp(33) instance_content_dialog.ids.box_input.add_widget( self.text_field) if self.text_button_cancel != '': anchor = 'left' else: anchor = 'center' box_button_ok = AnchorLayout(anchor_x=anchor) box_button_ok.add_widget( MDTextButton(text=self.text_button_ok, font_size='18sp', on_release=lambda x: _events_callback( self.text_button_ok))) instance_content_dialog.ids.box_buttons.add_widget(box_button_ok) if self.text_button_cancel != '': box_button_ok.anchor_x = 'left' box_button_cancel = AnchorLayout(anchor_x='right') box_button_cancel.add_widget( MDTextButton(text=self.text_button_cancel, font_size='18sp', on_release=lambda x: _events_callback( self.text_button_cancel))) instance_content_dialog.ids.box_buttons.add_widget( box_button_cancel) else: # create buttons for Android if instance_content_dialog.__class__ is ContentInputDialog: self.text_field = MDTextField( size_hint=(1, None), height=dp(48), hint_text=instance_content_dialog.hint_text) instance_content_dialog.ids.box_input.height = dp(48) instance_content_dialog.ids.box_input.add_widget( self.text_field) instance_content_dialog.ids.box_buttons.remove_widget( instance_content_dialog.ids.sep) box_buttons = AnchorLayout(anchor_x='right', size_hint_y=None, height=dp(30)) box = BoxLayout(size_hint_x=None, spacing=dp(5)) box.bind(minimum_width=box.setter('width')) button_ok = MDRaisedButton( text=self.text_button_ok, on_release=lambda x: _events_callback(self.text_button_ok)) box.add_widget(button_ok) if self.text_button_cancel != '': button_cancel = MDFlatButton( text=self.text_button_cancel, theme_text_color='Custom', text_color=self.theme_cls.primary_color, on_release=lambda x: _events_callback(self. text_button_cancel)) box.add_widget(button_cancel) box_buttons.add_widget(box) instance_content_dialog.ids.box_buttons.add_widget(box_buttons) instance_content_dialog.ids.box_buttons.height = button_ok.height instance_content_dialog.remove_widget( instance_content_dialog.ids.sep)