Sendkey function needed

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
psychotik Offline
Junior Member
Posts: 14
Joined: Jun 2005
Reputation: 0
Post: #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:
find quote
EnderW Offline
Skilled Python Coder
Posts: 249
Joined: Feb 2005
Reputation: 0
Post: #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
find quote
solexalex Offline
Skilled Python Coder
Posts: 706
Joined: Jul 2004
Reputation: 6
Post: #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 !
find quote
psychotik Offline
Junior Member
Posts: 14
Joined: Jun 2005
Reputation: 0
Post: #4
@solexalex & enderw
thanks for the suggestions, they gave me some new ideas!
find quote
psychotik Offline
Junior Member
Posts: 14
Joined: Jun 2005
Reputation: 0
Post: #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:
find quote
EnderW Offline
Skilled Python Coder
Posts: 249
Joined: Feb 2005
Reputation: 0
Post: #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
find quote
psychotik Offline
Junior Member
Posts: 14
Joined: Jun 2005
Reputation: 0
Post: #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:
find quote
Nuka1195 Online
Skilled Python Coder
Posts: 3,914
Joined: Dec 2004
Reputation: 17
Post: #8
def (self):

For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
find quote
Nuka1195 Online
Skilled Python Coder
Posts: 3,914
Joined: Dec 2004
Reputation: 17
Post: #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/
find quote
EnderW Offline
Skilled Python Coder
Posts: 249
Joined: Feb 2005
Reputation: 0
Post: #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
find quote
Post Reply