更新Kivy ListProperty项在一个函数中工作,但在另一个函数中抛出TypeError

时间:2017-09-07 05:03:11

标签: python kivy

我和Kivy一起工作了几个星期的Python应用程序(我第一次真正深入Python)并且使用链接到kv Label文本的ListProperty()项目遇到了麻烦。

正在创建列表,并使用.kv文件中的root.var [indx]填充Label文本。我的问题在于更新ListProperty中的特定索引点。我有一个功能,它每次都有效。然后另一个总是错误:

  

TypeError:'kivy.properties.ListProperty'对象不支持项目分配

我的部分代码:

from kivy.properties import StringProperty, ObjectProperty, ListProperty, NumericProperty
import... #continued

class setScreen(screen):
    #other variables here
    trig0 = ['tr0', 'Pre-Mass', 'yuo', '4', 1, colNorm, 'trig0p']
    ...
    trigIndex = {}
    trigList = [trig0, ...]
    trigDict = {'trig0p':trig0p, ...}
    trig0p = ListProperty(trig0[:])
    ...

    def __init__(self, **kwargs):
        #do init here

    def custController(self):
        #this screen's main functions

#The following function works and the Kivy Label text is updated without issue
    def changeProcess(self, x): #x is list from custController button eg.['trig0p', 'Text', 'New Text', 'more new text', #, 'something']
        itemToChange = x[0]
        self.trigDict[itemToChange][2] = x[2]
        self.trigDict[itemToChange][3] = x[3]


#The following function is for a remote update from a different class
#This fails with a 'TypeError:'
    def progUpdate(self, y): #y again is a list
        itemToChange = y[0]
        self.trigDict[itemToChange][2] = y[2]
        self.trigDict[itemToChange][3] = y[3]

class ...other screens and manager

#The following Popup is called from a button in the main functions
class MassSetPopup(Popup):
    settingID = ''
    settingPart = StringProperty()
    settingLoc = StringProperty()
    settingNum = StringProperty()
    full_num = ''
    new_lineData = []

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


    def on_parent(self, *args):
            self.settingPart = self.new_lineData[1]
            self.settingLoc = self.new_lineData[2]
            self.settingNum = self.new_lineData[3]


    def num_clk(self, x):
            if x == 'Bksp':
                    self.full_num = self.full_num[:-1]
                    self.settingNum = self.full_num
                    self.new_lineData[3] = self.full_num

            elif len(x) > 3:
                    self.settingLoc = x
                    self.new_lineData[2] = x

            elif len(self.full_num) == 4:
                    pass

            else:
                    self.full_num = self.full_num+x
                    self.settingNum = self.full_num
                    self.new_lineData[3] = self.full_num

    def save_point(self):
            setScreen.progUpdate(setScreen, self.new_lineData)
            self.dismiss()

    def cancel_point(self):
            print(self.new_lineData)
            self.dismiss()

我已将返回的数据放在setScreen类的非ListProperty列表中作为测试,并且它正在从Popup类中正确更新。

所有.kv小部件都正确加载,屏幕/弹出窗口按预期执行。

我一直在努力解决这个问题,并且已经找到了一个低点,但找不到任何适合这个问题的东西,或者甚至指出了我正确的方向,至少对我的新手Python编码。

0 个答案:

没有答案