mirror of
https://github.com/OMGeeky/Kivy-Shopping-List.git
synced 2026-01-19 18:01:18 +01:00
Add Top(Bottom)AppBar, fix ListItems
This commit is contained in:
19
src/main.py
19
src/main.py
@@ -9,6 +9,7 @@ from kivymd.app import MDApp
|
||||
from kivymd.uix.button import MDFlatButton
|
||||
from kivymd.uix.card.card import MDBoxLayout
|
||||
from kivymd.uix.dialog import MDDialog
|
||||
from kivymd.uix.list import OneLineAvatarIconListItem
|
||||
|
||||
Config.set('graphics', 'resizable', '0')
|
||||
Config.set('graphics', 'height', '1000')
|
||||
@@ -47,6 +48,16 @@ class MainScreen(Screen):
|
||||
class SettingsScreen(Screen):
|
||||
pass"""
|
||||
|
||||
class ShoppingEntry(OneLineAvatarIconListItem):
|
||||
def __init__(self, text, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
self.text = text
|
||||
self.is_checked = False
|
||||
|
||||
def delete(self, shopping_entry):
|
||||
self.parent.remove_widget(shopping_entry)
|
||||
|
||||
class AddDialog(MDBoxLayout):
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
@@ -54,15 +65,15 @@ class AddDialog(MDBoxLayout):
|
||||
|
||||
class ShoppingListApp(MDApp):
|
||||
add_dialog: MDDialog | None = None
|
||||
|
||||
|
||||
def build(self):
|
||||
self.theme_cls.primary_palette = "Teal"
|
||||
self.theme_cls.theme_style = "Light"
|
||||
self.title = 'Shopping List App'
|
||||
|
||||
def add_shopping_entry(self):
|
||||
pass
|
||||
def add_shopping_entry(self, text):
|
||||
self.root.ids['shopping_list'].add_widget(ShoppingEntry(text=text))
|
||||
self.close_add_popup()
|
||||
|
||||
def open_add_popup(self):
|
||||
if self.add_dialog:
|
||||
@@ -71,7 +82,7 @@ class ShoppingListApp(MDApp):
|
||||
# SPRACHE
|
||||
buttons = [
|
||||
MDFlatButton(text='Abbrechen', on_release=self.close_add_popup),
|
||||
MDFlatButton(text='Bestätigen')
|
||||
MDFlatButton(text='Bestätigen', on_release=lambda args: self.add_shopping_entry("Text"))
|
||||
]
|
||||
# SPRACHE
|
||||
self.add_dialog = MDDialog(
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<ShoppingEntry>:
|
||||
orientation: 'horizontal'
|
||||
CheckBox:
|
||||
active: root.is_checked
|
||||
Label:
|
||||
text: root.text
|
||||
Button:
|
||||
background_normal: 'res/delete.png'
|
||||
#<ShoppingEntry>:
|
||||
# orientation: 'horizontal'
|
||||
# CheckBox:
|
||||
# active: root.is_checked
|
||||
# Label:
|
||||
# text: root.text
|
||||
# Button:
|
||||
# background_normal: 'res/delete.png'
|
||||
|
||||
<FloatButton@FloatLayout>
|
||||
id: float_root # Giving id to button
|
||||
@@ -85,11 +85,25 @@
|
||||
# MainScreen:
|
||||
# SettingsScreen
|
||||
|
||||
<ShoppingEntry>:
|
||||
id: shopping_entry
|
||||
markup: True
|
||||
|
||||
ImageLeftWidget:
|
||||
MDCheckbox:
|
||||
id: shopping_entry_check
|
||||
# bind to property
|
||||
|
||||
IconRightWidget:
|
||||
icon: 'res/delete.png'
|
||||
on_release: root.delete(shopping_entry)
|
||||
|
||||
<AddDialog>:
|
||||
size_hint: 1, None
|
||||
height: '40dp'
|
||||
orientation: 'vertical'
|
||||
scpaing: '5dp'
|
||||
spacing: '5dp'
|
||||
|
||||
MDTextField:
|
||||
id: shopping_entry_text
|
||||
pos_hint: { 'center_y': 0.4 }
|
||||
@@ -98,11 +112,19 @@
|
||||
|
||||
|
||||
MDFloatLayout:
|
||||
|
||||
MDTopAppBar:
|
||||
#SPRACHE
|
||||
title: 'Shopping-List-App'
|
||||
md_bg_color: app.theme_cls.accent_color
|
||||
right_action_items: [['res/settings.png', lambda x: app.navigate_to_settings()]]
|
||||
|
||||
ScrollView:
|
||||
size_hint: 0.9, 0.9
|
||||
pos_hint: { 'center_y': 0.5, 'center_x': 0.5 }
|
||||
MDList:
|
||||
id: shopping_list
|
||||
|
||||
MDFloatingActionButton:
|
||||
icon: 'plus'
|
||||
elevation_normal: 5
|
||||
|
||||
Reference in New Issue
Block a user