Sendkey function needed
#1
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:
Reply
#2
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.
xbmcscripts.com administrator
Reply
#3
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 !
Reply
#4
@solexalex & enderw
thanks for the suggestions, they gave me some new ideas!
Reply
#5
(enderw @ june 22 2005,20:11 Wrote: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:
Reply
#6
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 Smile
xbmcscripts.com administrator
Reply
#7
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
Quote: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:
Reply
#8
def (self):
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#9
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.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#10
Quote: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 Wink
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...
xbmcscripts.com administrator
Reply
#11
ok, about the ..init..
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#12
i misread your post, thus i removed the quote but apperantly too late...sorry bout that.
xbmcscripts.com administrator
Reply
#13
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 Smile
Reply
#14
does posting in code blocks allow ..init..


if so post the whole thing.

i edited my above post too enderw.  Smile

edit: i guess not. can you post a link to it instead?
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#15
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

edit:
please download from xbmcscripts.com
Reply

Logout Mark Read Team Forum Stats Members Help
Sendkey function needed0