I am a new user of Kivy and frankly I am confused regarding RecycleView and Screen managers. I am accumulating values for a total line below the recycle view in the class which adds the items to the RecycleView. I cannot seem to reference the label to put the total in. I am sure I just have things in the wrong place but the t-pay id is what needs to be updated. I think the screen manager as root is confusing me.
My python file:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.popup import Popup
from kivy.uix.behaviors import ButtonBehavior
from kivy.uix.image import Image
from kivy.uix.dropdown import DropDown
from kivy.uix.recycleview import RecycleView
from kivy.properties import ObjectProperty
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivy.uix.recyclegridlayout import RecycleGridLayout
import csv
class Nq_rv(RecycleView):
def __init__(self, **kwargs):
super(Nq_rv, self).__init__(**kwargs)
bill_text = []
self.total_bill = 0.0
with open('bill.csv') as bill:
bill_reader = csv.reader(bill)
for row in bill_reader:
for item in range(len(row)):
if item < 2:
item_text = row[item]
else:
item_text = '{0:.2f}'.format(float(row[2]))
self.total_bill += float(row[2])
text_row = {'text': item_text}
bill_text.append(text_row)
self.data = bill_text
#self.total_pay.text = self.total_bill
#a=Sm
#a.update_total(the_value=self.total_bill)
class Nq_drop_down(DropDown):
pass
class ImageButton(ButtonBehavior, Image):
pass
class Pay_screen(Screen):
pass
#total_pay = ObjectProperty()
#def update_total(the_value=0):
#self.total_pay.text = the_value
class Survey_screen(Screen):
pass
class Finish_screen(Screen):
pass
class Sm(ScreenManager):
total_pay = ObjectProperty()
def update_total(self, the_value=0):
self.total_pay = the_value
def send_survey(self):
mypopup = MyPopup()
mypopup.show_popup('Survey', 'Survey sent!', 'OK!')
def add_comment(self):
mypopup = MyPopup()
mypopup.show_popup('Comment', 'This is where a comment is added.', 'OK!')
def pay(self):
mypopup = MyPopup()
mypopup.show_popup('Pay', 'Please put your card in the card reader and follow the prompts.', 'OK!')
def points(self):
mypopup = MyPopup()
mypopup.show_popup('Pay with points', 'This meal will be deducted from your points balance.', 'OK!')
def close_app(self):
App.get_running_app().stop()
class Nq_disagree_label(Label):
pass
class Nq_question_label(Label):
pass
class Nq_button(Button):
pass
class survey_form(BoxLayout):
pass
class MyPopup(Popup):
def show_popup(self, title_text, label_text, button_text):
mytext= label_text
content = BoxLayout(orientation="vertical")
content.add_widget(Label(text=mytext, font_size=20, text_size=(300, None)))
mybutton = Button(text="Ok!", size_hint=(1,.20), font_size=20)
content.add_widget(mybutton)
mypopup = Popup(content = content,
title = title_text,
auto_dismiss = False,
size_hint = (.5, .5)) #,
#font_size = 20)
mybutton.bind(on_press=mypopup.dismiss)
mypopup.open()
class nextqualApp(App):
icon = 'nextqual.png'
title = 'Pay / survey / join'
if __name__ == '__main__':
nextqualApp().run()
#: import ListItemButton kivy.uix.listview.ListItemButton
#: import ListAdapter kivy.adapters.listadapter.ListAdapter
#: import FadeTransition kivy.uix.screenmanager.FadeTransition
Sm:
transition: FadeTransition()
Pay_screen:
Survey_screen:
<nq_button@Button>:
halign: "center"
text: "Add\ncomment"
size_hint_x: 10
<Nq_disagree_label@Label>:
halign: "left"
size_hint_x: 10
text:"Strongly\ndisagree"
<Nq_agree_label@Label>:
halign: "left"
size_hint_x: 10
text:"Strongly\nagree"
<Nq_question_label@Label>:
halign: "left"
font_size: "24"
size_hint_x: 25
<Nq_check_label@Label>:
markup: True
#text: "[color=050505]Description[/color]"
multiline: True
#color: 100,100,100,100
<Nq_drop_down>:
auto_dismiss: False
Button:
text: 'Person'
size_hint_y: None
height: 44
on_release: root.select('item1')
Button:
text: 'Item'
size_hint_y: None
height: 44
on_release: root.select('item2')
<Nq_check_items@Label>:
color: 0,0,0,1
<Nq_rv>:
viewclass: 'Nq_check_items'
RecycleGridLayout:
cols: 3
default_size: None, dp(20)
default_size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
<Pay_screen>:
name: 'pay'
#total_pay: total_pay
BoxLayout:
orientation: "vertical"
padding: 6
font_size: '24'
BoxLayout:
size_hint_y: None
height: "40dp"
Button:
text: "Pay your bill"
on_release: app.root.current = 'pay'
Button:
text: "Tell us how we did"
on_release: app.root.current = 'survey'
Button:
text: "I'm finished"
BoxLayout:
BoxLayout:
padding: 12
orientation: 'vertical'
BoxLayout:
height: "40dp"
size_hint_y: None
Label:
text: 'Table: 4'
Label:
text: 'Server: Julie'
Label:
text: 'Check # 58645'
BoxLayout:
canvas:
Color:
rgb: 255,255,255,255
Rectangle:
size: self.size
pos: self.pos
Nq_rv:
BoxLayout:
height: "30dp"
size_hint_y: None
Label:
text: 'Total check:'
size_hint_x: 75
Label:
text: '£150.33'
halign: 'right'
size_hint_x: 25
BoxLayout:
height: '30dp'
size_hint_y: None
Label:
text: 'Plus tip:'
size_hint_x: 75
halign: 'left'
Label:
id: 'tip'
text: '0.00'
halign: 'right'
size_hint_x: 25
multiline: False
BoxLayout:
height: '30dp'
size_hint_y: None
Label:
text: 'Total to pay:'
size_hint_x: 75
Label:
id: t_pay
text: '£175.33'
halign: 'right'
size_hint_x: 25
BoxLayout:
height: "40dp"
size_hint_y: None
Label:
text: 'How to pay...'
BoxLayout:
height: "40dp"
size_hint_y: None
ImageButton:
source: 'mc.png'
size_hint: .9, .9
on_press: app.root.pay()
ImageButton:
source: 'visa.png'
size_hint: .9, .9
on_press: app.root.pay()
ImageButton:
source: 'Amex-icon.jpg'
size_hint: .9, .9
ImageButton:
source: 'apple-pay-logo.jpg'
size_hint: .9, .9
on_press: app.root.pay()
ImageButton:
source: 'googlepaylogotitle-3.jpg'
size_hint: .9, .9
on_press: app.root.pay()
ImageButton:
source: 'cash.png'
size_hint: .9, .9
on_press: app.root.pay()
ImageButton:
source: 'points.png'
size_hint: .9, .9
on_press: app.root.points()
BoxLayout:
padding: 12
orientation: 'vertical'
BoxLayout:
height: "40dp"
size_hint_y: None
Label:
text: "Split bill by "
Nq_drop_down:
Label:
text: 'by'
TextInput:
text: '1'
Label:
text: 'Persons'
BoxLayout:
BoxLayout:
height: "40dp"
size_hint_y: None
Label:
text: "Add tip:"
BoxLayout:
height: "40dp"
size_hint_y: None
Label:
text: "Amount"
size_hint_x: 10
Label:
text: 'Slide to change'
size_hint_x: 80
Label:
text: 'Percent'
size_hint_x: 10
BoxLayout:
height: "40dp"
size_hint_y: None
TextInput:
id: 'tip_amt'
text: '0.00'
halign: 'right'
size_hint_x: 10
multiline: False
Slider:
size_hint_x: 80
value: 0
value_track: True
value_track_color: 1, 0,0,1
value_track_width: '5dp'
TextInput:
id: 'tip_percent'
text: '0'
halign: 'right'
size_hint_x: 10
multiline: False
<Survey_screen>:
name: "survey"
BoxLayout:
orientation: "vertical"
padding: 6
font_size: "24"
BoxLayout:
height: "40dp"
size_hint_y: None
Button:
text: "Pay your bill"
on_release: app.root.current = 'pay'
Button:
text: "Tell us how we did"
on_release: app.root.current = 'survey'
Button:
text: "I'm finished"
BoxLayout:
halign: "center"
Image:
source: "logo.jpg"
#size: self.size
BoxLayout:
height: "80dp"
size_hint_y: None
Label:
bold: True
#color: 10,10,10,10
#halign: "center"
#text_size: self.size
markup: True
text: "[0=f9f752]Description[/color]"
multiline: True
#size_hint_x: 25
text_size: self.size
halign: 'center'
valign: 'middle'
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_question_label:
text: "The service I recieved from start to finish was excellent."
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_disagree_label:
Slider:
size_hint_x: 80
value: 50
Nq_agree_label:
nq_button:
on_press: app.root.add_comment()
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_question_label:
text: "I waited an appropriate amount of time for my food and drink."
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_disagree_label:
Slider:
size_hint_x: 80
value: 50
Nq_agree_label:
nq_button:
on_press: app.root.add_comment()
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_question_label:
text: "The quality and presentation of the food was outstanding."
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_disagree_label:
Slider:
size_hint_x: 80
value: 50
Nq_agree_label:
nq_button:
on_press: app.root.add_comment()
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_question_label:
text: "The prices provide good value for money."
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_disagree_label:
Slider:
size_hint_x: 80
value: 50
Nq_agree_label:
nq_button:
on_press: app.root.add_comment()
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_question_label:
text: "The atmosphere was relaxing and enjoyable."
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_disagree_label:
Slider:
size_hint_x: 80
value: 50
Nq_agree_label:
nq_button:
on_press: app.root.add_comment()
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_question_label:
text: "The overall cleanliness was very acceptable."
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_disagree_label:
Slider:
size_hint_x: 80
value: 50
Nq_agree_label:
nq_button:
on_press: app.root.add_comment()
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_question_label:
text: "I will recommend Synterest to my friends and family."
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_disagree_label:
Slider:
size_hint_x: 80
value: 50
Nq_agree_label:
nq_button:
on_press: app.root.add_comment()
BoxLayout:
height: "100dp"
size_hint_y: None
Label:
size_hint_x: 40
Button:
size_hint_x: 20
text:"Send survey"
halign: "center"
on_press: app.root.send_survey()
Label:
size_hint_x: 40
I am sorry but I am still confused. If the class Nq_rv and the class Sm is instantiated in the .kv file, there is no self.manager object I can reference in the __init__ in Nq_rv. So my question is from the Nq_rv which sets up the recycle view, how can I reference a total field outside the recycleview?
Dave
--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/_9WHI7ZFrbE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To post to this group, send email to kivy-...@googlegroups.com.
Visit this group at https://groups.google.com/group/kivy-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/2b19c6f8-b5af-4cec-9996-702701562027%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.