Removing Widgets
Posted: 09 June 2011 01:11 PM   [ Ignore ]
Rank
Joined  2011-06-05
Total Posts:  8
New Member

This has been giving me grief for a while now, and should have asked this from the start to save myself a lot of time.

I am making a database using SQLite, and I am able to add all the titles to a MTKineticList as a button. When one of them has been pushed, it adds a Title as a MTLabel, and a description of the item into another MTKineticList beside the previous one. What I am having problems with is, when I click on a button on the first MTKineticList to bring up a new MTLabel, and MTKineticList, I have to remove the old ones previously added. I have tried this by using two functions, one to set up the new MTLabel, and MTKineticList, and the other to store the old MTLabel and MTKineticList, and afterwards remove these widgets on the next button press. Here is a step by step process of what has to happen if this does not make sense

1st Click
1.) Store the newly added MTLabel and description in order to remove it later
2.) Add the MTLabel and description using add_widget()

2nd Click
1.) Remove the stored data (remove old MTLabel and MTKineticList) using remove_widget
2.) Add The new MTLabel and description
3.) Store the new MTLabel and description

.... Click
Continue 2nd click pattern.

Whenever I try calling my store function to remove the old widgets using the remove_widget function call, it does not remove them. Any help would be great.

Profile
 
 
Posted: 09 June 2011 03:57 PM   [ Ignore ]   [ # 1 ]
Rank
Joined  2011-06-05
Total Posts:  8
New Member

Well, I solved my own problem with global variables which I was trying to avoid.

Here is how I did it:

Flag = False
oldtitle = str
olddesc = str

def do_stuff(menu, w, y, x, *largs):
global Flag
global oldtitle
global olddesc

m = getWindow()
desc = MTDescription(...)
title = MTLabel(...)
description = MTKineticItem(...) #Label settings

close_stuff()
if Flag == False:
oldtitle = title
olddesc = desc

desc.add_widget(description) #Draws description widget (off screen)
desc.goto_head()
m.add_widget(desc)
m.add_widget(title) #Draws title widget (off screen)
Flag = True

def close_stuff():
global Flag
global oldtitle
global olddesc

if Flag == True:
oldtitle.parent.remove_widget(oldtitle)
olddesc.parent.remove_widget(olddesc)
Flag = False

Profile
 
 
   
 
 
‹‹ on_press function      MT4J Fiducials ››