KPA
KPA

Reputation: 173

Kivy - doesn't refresh/change data when the data has been modified?

So I'm creating a video player that is like a Youtube but not online. So I have my active-video layout which consist of the title and the video and the other layout is the related-videos which consists of the title of other videos for now.

class MainApp(Screen):
    vid = "Top 10 Plays of 2015"
    title = "Top 10 Plays of 2015"

    def __init__(self,**kwargs):
        super(MainApp,self).__init__(**kwargs)
    pass

class OtherVideos(BoxLayout): 
    def __init__(self, **kwargs):
        super(OtherVideos,self).__init__(**kwargs)

        self.loadVideos()

    def loadVideos(self):

        con = MongoClient()
        db = con.nba
        vids = db.videos.find()

        vidnum = 1
        for filename in vids:
            myid = "vid" + str(vidnum)
            label = Label(id=myid,
                          markup=True,
                          text="[ref=act]" + filename['filename'] + "[/ref]",
                          color=[0,0.7,1],
                          bold=1)

            label.bind(on_ref_press=lambda inst, val:self.change_Title(filename['filename']))

            self.add_widget(label)

            vidnum += 1

    def change_Title(self, next_title):
        MainApp.title = next_title
    pass

in my kivy code:

 Label:
      id: lblTitle
      text: root.title

So what I am suppose to do is to edit the title variable in Class MainApp, so by doing that I need to click the Label (this is the title in other-videos layout) and the title variable should be changed. The labels are dynamically created based on the data from a database.

I can see the title variable changing on the shell by doing (print (MainApp.title)) but its not changing on my layout screen. its still "Top 10 Plays of 2015".

TLDR; The variable 'title' is changing on shell but not on the layout screen.

Upvotes: 1

Views: 600

Answers (1)

Yoav Glazner
Yoav Glazner

Reputation: 8066

You need to use StringProperty.

example:

class MainApp(Screen):
    vid = StringProperty("Top 10 Plays of 2015")
    title = StringProperty("Top 10 Plays of 2015") #yay!!!

    def __init__(self,**kwargs):
        super(MainApp,self).__init__(**kwargs)

Upvotes: 2

Related Questions