Using a textbox as a progress indicator
#1
Sad 
hi

i've been trying to use a textbox as progress/status indicator. however, the gui doesn't draw the status text when i want it to. is there anyway of forcing the gui to redraw the screen?


to be more specific. in my ooba script i have a list of menuitems. when the user clicks an normal menuitem i do the following
* removecontrol(list)
* addcontrol(textbox)
* textbox.settext("reading url:"+url)
* reset list and add new sub items
* removecontrol(textbox)
* addcontrol(list)

and that works fine. but when the user clicks an url to a jpg, then the flow is different:

* removecontrol(list)
* addcontrol(textbox)
* textbox.settext("downloading image:"+url)
* urllib.urlretrieve(....)
* image=....
* removecontrol(textbox)
* addcontrol(image)

and that does not work. the list is removed while downloading and the image ends up being displayed but there is no status text in the mean time.
Reply
#2
im leaning on it being some little bug somewhere.
i recommend refactoring the code such that the setting up and destroying of the textbox is the same and the only thing that differs is the stuff in the middle (pass the text as an arg). if not that try disabling the download and put a simple sleep in there so you can see the box...
Reply
#3
you are probably right. however, in my code i am actually using the same code for switching between list,textbox and image (just as you suggest). i use a function called set_viewstate (see below). and in both the cases described above i call like this:

* win.showtext('something')
* downloaddata and so on....
* win.set_viewstate(menustate) or win.set_viewstate(imagestate)


Quote: def set_viewstate(self,state):
state2control={menustate:self.list,imagestate:self.image,textstate:self.textbox}
control=state2control[state]
if not debug: xbmcgui.lock()
try:
print('setviewstate1a')
print('setviewstate1b')
if self.viewstate==state:
print('setviewstate1c')
self.setfocus(control)
if not debug: xbmcgui.unlock()
return
try:
print('setviewstate1d')
self.removecontrol(state2control[self.viewstate])
except:
pass
print('setviewstate1d')
self.viewstate=state
self.addcontrol(control)
print('setviewstate1e')
except:
print('error in oobas set_viewstate()')
if not debug: xbmcgui.unlock()
print('setviewstate1f')
if state==menustate:
self.updatemenu()
print('setviewstate1g')
self.setfocus(control)

       def showtext(self,txt):
               if emulating: self.textbox.settext(txt)
               self.set_viewstate(textstate)
               self.textbox.reset()
               self.textbox.settext(txt)

the weird thing i'm having now is that an error occurs so that the last output is:

Quote:setviewstate1a error in oobas set_viewstate()

how is that possible at all? there is obviously something spooky going on here.
Reply
#4
still not really closer to a solution except that i managed to make it alot more stable by removing all calls to lock and unlock.  Huh

just now i got setviewstate1e as the last output. makes no sense at all... frustrating.
Reply
#5
do you think the problem could be in that dictionary you have at

state2control={menustateConfusedelf.list,imagestateConfusedelf.image,textstateConfusedelf.textbox}

im not sure of python specifics but i would be worried if that list is created statically... im probably wrong about this part though. i dont think you can change an imagecontrol on the fly so every time you need to look it up you need a recent reference to the new control, which would not be true of the other two cases... if i am wrong still make sure you are actually setting self.image somewhere everytime you get a new image.

also make sure your self.viewstate is properly setup in the init.. and that those three states are different values of course..

if its still not working instead of adding and removing controls to try using setvisible(false)... though you'd still probably want to remove the image control...

im not sure what that error message is... oobas? spooky is right.
Reply
#6
thanks for the suggestions. i think the dictionary thing is working because it is now working almost all the time. (i can show many different images in a row.)

i do create a new imagecontrol everytime. the latest version of ooba is however much more stable. i've given up on lock and unlock since they seem to be the main cause in my case.

by the way is there some way of selecting item number 7 in a listcontrol from code. i want to preserve the state so that when the user presses "b" then it returns to the parent menu standing on the relevant item.
Reply
#7
selecting a listcontrol should select its last selected item in most cases...

im not sure if thats true after you setvisible(false) or remove/add it.

no interface for doing it manually afaik.

edit: ok im playing around with the ooba script now... i think you would have to keep a stack of lists with only the top most one visible. i remember now in my script that i do have a list that i hide with setvisible(false) and the position is remembered.
Reply

Logout Mark Read Team Forum Stats Members Help
Using a textbox as a progress indicator0