PDA

View Full Version : Sendkey function needed


psychotik
2005-06-22, 20:48
hi,

at the moment iīm working on a script which starts a given action after a certain time without user interaction.
is there a idle time available in xbmc phyton? i havenīt found anything.
therefore i try to create a transparent window on top of everything and look for input. that works most of the time, however the key the user is pressing is only coming to my window. iīm now looking for a way to pass this key to the original visible window.

does that make sense to you?
anybody out there with an idea?

maybe iīm going the wrong direction as i#m only used to vb :verysad:

EnderW
2005-06-22, 22:11
import time

time.sleep(x)

x = time in seconds

anyhow, a send function isn't needed. on the new class (your new overlay) you can call the old overlay object's function -which you want to run - when a button is pressed.

solexalex
2005-06-22, 23:31
time.sleep will freeze your script until delay finished...
if you need to do some more actions while time is running, you may use threading...
some scripts are using threading. you can try my mycalendar. i have another script that use thread, but can't remember the name... lol this script launch a default playlist after a time if no actions has been taken by user.... you may use the search engine to find it !

psychotik
2005-06-23, 21:45
@solexalex & enderw
thanks for the suggestions, they gave me some new ideas!

psychotik
2005-06-23, 23:09
import time

time.sleep(x)

x = time in seconds

anyhow, a send function isn't needed. on the new class (your new overlay) you can call the old overlay object's function -which you want to run - when a button is pressed.
how do i get a handle of the old overlay or parent window?
for example the main menu of xbmc is active. then after a a few seconds i create my overlay window. in this window i can us onaction to get all inputs, but i see no way of finding out what the parent window is.
i think a possible way is using xbmcgui.window(someid), but i havenīt found out how to find the correct id as there is no findwindow function :help:

EnderW
2005-06-24, 00:07
pass on self to the new object (from within window1's class). like:
w2 = window2(self)
w2.domodal()

window2's init function should have (self, selfinstance, ...)
selfintance would now be the first window's class/object.

then you can do:

self.window1 = selfinstance

and in onaction:

if action == 7:
self.window1.function()


i believe you can do something like that, but i haven't thought this through very much..also, my python knowlegde is rather limited.

good luck :)

psychotik
2005-06-24, 22:29
i think i got it sort of working, but now i have a new strange problem.
i made a few changes on my ui and now my xbox crashes when i execute the script :angry:
import xbmc, xbmcgui, time, os

class mywindow(xbmcgui.windowdialog):

def (self):

w=self.getwidth()
h=self.getheight()
panelx=int(w/2-(269/2))
panely=int(h/2-(235/2))
panelw=int(269)
panelh=int(235)
self.home=os.getcwd()[:-1]+'\\'
self.panel = xbmcgui.controlimage(panelx,panely,panelw,panelh, self.home+'panel2.png')
self.addcontrol(self.panel)
try:

self.label1 = xbmcgui.controllabel(int(panelx+20),int(panely+40) , 200, 25)
self.addcontrol(self.label1)
self.label2 = xbmcgui.controllabel(int(panelx+45),int(panely+40) , 200, 25, "timeout is " + " seconds", 'font14','0xffffffff')
self.addcontrol(self.label2)
self.label3 = xbmcgui.controllabel(int(panelx+70),int(panely+40) , 200, 25, "press any key to abort!", 'font14','0xffffffff')
self.addcontrol(self.label3)
self.labeltimeout = xbmcgui.controllabel(int(panelx+95),int(panely+40) , 200, 25, "remaining seconds:", 'font14','0xffffffff')
self.addcontrol(self.labeltimeout)
self.label1.setlabel("starting ")
except:
xbmc.output("label error")

def onaction(self, action):
try:
print "abort!"

self.close
except:
xbmc.output("error aborting!")

mc=mywindow()
mc.show()

i can't see what i'm doiong wrong, but it's an instant kill :bomb:

Nuka1195
2005-06-24, 23:29
def (self):

Nuka1195
2005-06-24, 23:39
also when using division.

this:
panelx=int(float(w)/2-(float(269)/2))

will give a more accurate result than:
panelx=int(w/2-(269/2))

it probably only matters on real complex formulas though.

EnderW
2005-06-25, 00:24
def (self):

his code is probably correct on that point, this board doesn't show ..init.. (dot = underscore).

i notice that your code lacks indentation, but i can only assume that it's there in the file you run ;)
try to setthe label's height to more than 50. i dunno if labels are affected, but most controls need a height more than 50 or else xbmc locks up.

also, why do you do show() and not domodal()? show() only shows the screen for a split second, so you'll not see any of it. *if it's just for testing if things work it's cool, was just wondering if you knew the difference...

Nuka1195
2005-06-25, 00:40
ok, about the ..init..

EnderW
2005-06-25, 00:44
i misread your post, thus i removed the quote but apperantly too late...sorry bout that.

psychotik
2005-06-25, 01:11
you are right about the ..init.. its in my code, also the indentation is ok.
i tried to increase the label high but it didn't help.

the reason i don't use domodal is a bit more complicated...
what i'm doing at the moment is a sort of idle timer which can run i three modes:
1. silent
2. progressbar
3. overlay window

so the timeout code is already there and depending on the mode i show a progressbar or a window.
in case i have to show the window i have use window.show or my timeout class is paused and the window will never close.

part 2 is working well.
part 3 is where i have problems now
part 1 will hopefully run after solving part3.

the weird thing with the previous code is that i had before a singel fadelabel there and this worked without problems...
if you are interested i post the complete code here, but at the moment it needs a bit of cleaning up :)

Nuka1195
2005-06-25, 01:15
does posting in code blocks allow ..init..



if so post the whole thing.

i edited my above post too enderw. *:)

edit: i guess not. can you post a link to it instead?

psychotik
2005-06-25, 01:23
i packed everything in an archiv.
test.py is the code i posted earlier.
timeout.py is the complete code
use config.py to change from overlay to progressbar
timeout.rar (http://)

edit:
please download from xbmcscripts.com

Nuka1195
2005-06-25, 02:24
down where you set your labels, you need to add a default label. i guess that's what you would call it. in bold.

self.label1 = xbmcgui.controllabel(int(panelx+20),int(panely+40) , 200, 25, "")

and it looks like you may have gotten your x and y's mixed up???

edit: you can't really tell what's bold it's the: , ""

psychotik
2005-06-25, 02:48
thanks nuka1195 i must be blind :blush:
the strange thing is i changed this only because it gave syntax errors before...
is there something in the python engine i have to keep in mind?
i had this before were i had a code which gave strange syntax errors and after changing it to something different and then back to the original ( and a few reboots in between) it suddenly worked ???

Nuka1195
2005-06-25, 05:17
i think if you wouldn't have had the try/except, it may have given you the syntax error???

psychotik
2005-06-25, 20:30
one sep further :thumbsup:
but now i have the problem i can not update the labels from other classes:

class mywindow(xbmcgui.windowdialog):

def ..init..(self):
self.label1 = xbmcgui.controllabel(int(panelx+20),int(panely+40) , 200, 50,"starting")
self.addcontrol(self.label1)

#change labeltext try1
mw=mywindow()
mw.show
mw.label1.setlabel("test")
# --> xbox hangs


#change labeltext try2
mw=mywindow()
mw.show
lbl=mw.label1
lbl.setlabel("test")
# --> xbox hangs


how can i get the reference to the label back to the outside of the class ?
do i have to mark the label somehow as public/friend in order to access it?

EnderW
2005-06-25, 23:33
you shouldn't have to as far as i know...dunno why that problem occours. python in xbmc is kinda buggy though (or i suck at coding). i suggest you make a function in the first class instead, like:

def changelabel1(self, text):
* self.labelname.setlabel(text)

then you call mw.changelabel1("test") instead. that should work.

-edit-

eh...the show() command could perhaps cause some problems in this case, depending on how it actually works (which i don't know). you could try doing domodal() instead and see if you can change the label then. just a wild guess - i suggest you try the first thing i mentioned first.

-edit2-

i hope you didnt' copy and paste from your code, since you are calling it mw=mywindow() instead of mw=mywindow()

psychotik
2005-06-25, 23:49
thank you enderw! that worked :kickass:

the show works in my code as expected, so i think there is no problem there.

does upper/lower case of functions and variables matter in python?
sorry for the stupid question, i just started python a few days ago and in vb nobody cares about that :d

EnderW
2005-06-26, 02:17
upper/lower case matters very much. "object1" and "object1" aren't the same objects. glad to hear that it worked out.

unless you're using show for a specific reason you might want to know that domodal() is much faster at updating and generally better to use. but if it works fine, why change it...i believe the advantage is only seen in certain circumstances.

psychotik
2005-06-26, 02:24
thanks for the clarification.

the reason i use show is that i show and close the window from a different function, if i would use domodal my code would stop.

i finished version 0.1 in which everything except the "silent-mode" works. i just uploaded it to xbmcscripts.com.

EnderW
2005-06-26, 02:30
congrats with the release, just approved it. i haven't tried it myself and have no time to do so, but i am sure it works fine *;)


it is possible to use domodal() and achieve what you want, unless i misunderstand you completely. i don't have time to dig into your code and make corrections though, it's of no use and would be nit-picking.

psychotik
2005-06-26, 02:37
thanks,

so now i just need some guineapig to test and give feedback :evil:

EnderW
2005-06-26, 02:39
i believe i might have found a bug though:

if boldebug:
xbmc.output("starting script timeout in mode:" + str(mode))

#try:
* * * *if mode==3:
* * * * * * * *mydisplay = mywindow()
* * * * * * * *mydisplay.show()
* * * * * * * *
* * * *if boldebug:
* * * * * * * *xbmc.output("before starttimeout()")
* * * *starttimeout(mydisplay)
* * * *if boldebug:
* * * * * * * *xbmc.output("after starttimeout()")
* * * * * * * *
* * * *if mode==3:
* * * * * * * *mydisplay.close()
* * * * * * * *del mydisplay
* * * * * * * *if boldebug:
* * * * * * * * * * * *xbmc.output("after del mydisplay")
* *#except:
# xbmc.output("error in main function")

notice the indentation (look in the file please, the board messes it up). it will only run that code if boldebug = true, but i think you'd actually want to either remove the commenting of try and except, or remove indentation of the code.

also in the xml the <execute> is set as xbmclyrics.py :)

psychotik
2005-06-26, 02:57
the strange thing is that it worked... ???
i corrected it and also updated the script.xml (long life cut 'n' past)

i uploaded it as timeout2.zip, maybe you can change it. timeout.zip was already there.

EnderW
2005-06-26, 03:01
changed...

time to finally hit the bed now, if you make corrections please upload (when you're done) and i'll update tomorrow.