Kivy Crashes On Widget Clear

428 views
Skip to first unread message

Yowser MaGuil

unread,
May 1, 2014, 1:08:32 PM5/1/14
to kivy-...@googlegroups.com
Traceback (most recent call last):
   File "newGui.py", line 497, in <module>
   File "/usr/lib/python3.3/site-packages/kivy/app.py", line 792, in run
   File "/usr/lib/python3.3/site-packages/kivy/base.py", line 481, in runTouchApp
     EventLoop.window.mainloop()
   File "/usr/lib/python3.3/site-packages/kivy/core/window/window_pygame.py", line 381, in mainloop
     self._mainloop()
   File "/usr/lib/python3.3/site-packages/kivy/core/window/window_pygame.py", line 287, in _mainloop
     EventLoop.idle()
   File "/usr/lib/python3.3/site-packages/kivy/base.py", line 330, in idle
     Clock.tick_draw()
   File "/usr/lib/python3.3/site-packages/kivy/clock.py", line 429, in tick_draw
     self._process_events_before_frame()
   File "/usr/lib/python3.3/site-packages/kivy/clock.py", line 562, in _process_events_before_frame
     if event.tick(self._last_tick) is False:
   File "/usr/lib/python3.3/site-packages/kivy/clock.py", line 309, in tick
     ret = callback(self._dt)
   File "/usr/lib/python3.3/site-packages/kivy/uix/textinput.py", line 1520, in _update_graphics
     self.canvas.clear()
 AttributeError: 'NoneType' object has no attribute 'clear'

Getting this error when I clear widgets to redraw them. I am not posting any of my code yet, because there is too much of it.

I can provide more info as needed. Does the above error code ring any bells?

Thanks!!

ZenCODE

unread,
May 1, 2014, 2:35:37 PM5/1/14
to kivy-...@googlegroups.com
It's a pretty generic error, indicating one of the TextInput's you are using does not have a canvas at this point, or it has been removed. So, even though it's only a little, please post your code :-)

Thanks

Yowser MaGuil

unread,
May 1, 2014, 3:52:25 PM5/1/14
to kivy-...@googlegroups.com
this seems to be the function causing the crash:

def filterMess(self, convoPerson):

winD = self.message_display_window
winD.clear_widgets()

global currentConversation
currentConversation = int(convoPerson)
recipient = convoPerson
self.send_button.bind(on_press= lambda widget: self.sendMessage(recipient))
global allMessLog
messageArrayAll = allMessLog
messageArray = []

for eachMess in messageArrayAll:
sender = int(eachMess[3])
recip = int(eachMess[4])
if sender == int(convoPerson) or (sender == int(currentUser) and recip == int(convoPerson)):
messageArray.append(eachMess)

i = 0
if len(messageArray) == 0:
self.message_display_window.add_widget(Button(text="Start a conversation", size_hint=(1,1), background_color=(0,0.2,0.5,1)))
self.message_display_window.height = 545

i = len(messageArray)-1

while i>= 0:
curMes = messageArray[i]
mesStr = len(str(curMes[2]))
if mesStr <= 74:
ht = 48
elif mesStr>74 and mesStr<=148:
ht = 68
elif mesStr>148 and mesStr<=222:
ht = 88

if int(curMes[3]) == int(currentUser):
r = 0
g = 0.3
b = 0.7
a = 0.75
theSender = ""
space = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"
else:
r = 0
g = 0.5
b = 0.1
a = 0.75
theSender = "  from  "+str(curMes[1])
space = ""
winD.add_widget(TextInput(text="\""+str(curMes[2])+"\""+"\n"+space+str(curMes[0])+theSender, readonly="true", height=ht, size_hint=(1,None), background_color= (r,g,b,a), foreground_color= (1,1,1,1)))
i = i-1

return recipient

ZenCODE

unread,
May 2, 2014, 1:29:39 AM5/2/14
to kivy-...@googlegroups.com
Okay, to the error is thrown in the TextInput class, so it's probably your:

    winD.add_widget(TextInput(...))

line. Try simplifying it and see if it throws an error then.

    winD.add_widget(TextInput(text="Hello"))

If not, then great. Slowly add back each parameter until the error re-appears. It simplifying does not help, you probably need to investigate the "winD" class. What is it? ("print str(winD)"). Is it doing anything to the TextInput that could cause this?

ps. "readonly" is a boolean property, so the parameter should be "readonly=True".

Peace out

Yowser MaGuil

unread,
May 20, 2014, 9:21:25 AM5/20/14
to kivy-...@googlegroups.com
Ok. Apparently it was the height property being weird. I was setting the height of the text widget dynamically by getting the length of the string it contains and passing that as 'ht'.
 Because I am in the python side, seems that using self.text_size[1] as per this tutorial is not gonna work. 'Self' seems to be referring to the root object, and not to the label. No idea how to make the label(read-only text widget) refer to itself..

Anyways, thanks for the help on this. 

ZenCODE, you da BEST!

ZenCODE

unread,
May 20, 2014, 10:38:04 AM5/20/14
to kivy-...@googlegroups.com
Awww shucks, you're too kind....;-)

Yeah, that example using the magical Kivy kv file binding. But there is always a Python equivalent, it's just a tad more verbose. What you could do is just attach the "on_size" event to your own callback. Something like:

    def context_resized(self, label, *args):
        self.height = label.height
        print "Other params are ", str(args)

    my_scrollview.context_resized = content_resized
    label.bind(on_size=my_scrollview.context_resized)

after you've created it created it. You could do that to call any function, and the label itself would be the first parameter (apart from the "self") passed into the callback and adjust the height/size in that callback?

ps. That just an example. There are probably cleaner ways to do it, but that should at least work...

Cheers
Reply all
Reply to author
Forward
0 new messages