0

I'm using a python script for xbmc program, I can open addons.py without have any problem, but I can't be able to open test.py from addons.py. I'm currently using the code on two different files addons.py and test.py.

Addons.py:

import xbmcgui
import xbmcaddon
import buggalo
from test import MyClass

buggalo.SUBMIT_URL = 'http://tommy.winther.nu/exception/submit.php'

try:
    w = xbmcgui.WindowXML( "script-tvguide-mainmenu.xml", xbmcaddon.Addon().getAddonInfo('path'), "Default" )
    w.doModal()
    del w
    print 'Hello!'

    mydisplay = MyClass()
    mydisplay.doModal()

except Exception:
    buggalo.onExceptionRaised()

test.py:

print "hello!"
import xbmc 
import xbmcgui

#get actioncodes from https://github.com/xbmc/xbmc/blob/master/xbmc/guilib/Key.h
ACTION_MOVE_LEFT = 1
ACTION_MOVE_RIGHT = 2
ACTION_MOVE_UP = 3
ACTION_MOVE_DOWN = 4

class MyClass(xbmcgui.WindowXML):
  def onAction(self, action):
    if action == ACTION_MOVE_LEFT:
      print "You have press on the left arrow button!"
      self.close()

    if action == ACTION_MOVE_RIGHT:
      print "You have press on the right arrow button!"
      self.close()

    if action == ACTION_MOVE_UP:
      print "You have press on the up arrow button!"
      self.close()

    if action == ACTION_MOVE_DOWN:
      print "You have press on the down arrow button!"
      self.close()

I really need your help because when I open the addons.py, I can't be able to open the test.py from addons.py. It will give me an error of function takes at least 2 arguments (0 given). I don't know what to do.

Here is the log: http://pastebin.com/Qacy0UnA

Does anyone know how I can open the test.py from addons.py script?

  • On what line does that error occur? Can you please post the entire traceback? Also, what does "open" mean? Do you mean "import" or "run"? Finally, I would bet the problem is because the line `w.doModal()` - the function `doModal()` requires 2 arguments, but you have given it zero (place the arguments between the parentheses, like `w.doModal(arg1,arg2)`). – darthbith Jan 07 '14 at 17:23

2 Answers2

0

16:55:23 T:4196 ERROR: mydisplay = MyClass()
16:55:23 T:4196 ERROR: TypeError: function takes at least 2 arguments (0 given)

Dig up the docs for xbmcgui.WindowXML and see what the constructor arguments are.

M4rtini
  • 13,186
  • 4
  • 35
  • 42
  • thank you very much for your advice. I have looked the docs for `xbmcgui.WindowXML`, so I have replaced `MyClass(xbmcgui.WindowXMLDialog)` from `MyClass(xbmcgui.WindowXML)` which it have got rid of the error. I have a little problem, when I use `print` on xbmc, it did not display on the screen. Do you know why? –  Jan 07 '14 at 17:44
  • xbmc probably have their own function for sending text to the screen. – M4rtini Jan 07 '14 at 17:49
  • How I can see the text to the screen using print? –  Jan 07 '14 at 18:07
  • No idea, a new question might attract someone more familiar with the xbmcgui api. – M4rtini Jan 07 '14 at 18:15
  • http://wiki.xbmc.org/index.php?title=HOW-TO:Write_Python_Scripts_for_XBMC Looks like you need to be in debug mode. – M4rtini Jan 07 '14 at 18:36
0

Change

mydisplay = MyClass()

to

mydisplay = MyClass("script-tvguide-mainmenu.xml", xbmcaddon.Addon().getAddonInfo('path'))

This is because WindowXML, the superclass of MyClass, takes two arguments, filename and path. It is very well defined in http://mirrors.xbmc.org/docs/python-docs/stable/xbmcgui.html#WindowXML

Mattias
  • 451
  • 3
  • 13
  • thank you very much for this, but when I select on the main menu button, it will display the background. When i press on the up,down,left or right arrow button on the keyboard it will close and return to the main menu. Do you have any idea why? –  Jan 07 '14 at 17:50
  • Just realised that I'm using the 'self.close' which it will close and return to the main menu. Do you know how I can display the dialog box when I press on the up, down, left and right arrow buttons of the keyboard? because when I try to use print "hello world!", nothing will show on my screen. –  Jan 07 '14 at 17:54
  • Please explain the reason why your answer would work. – Bleeding Fingers Jan 07 '14 at 18:03
  • @chrisoojer Just call whatever method is used for showing the dialog box instead of `self.close`. `print` is writing to standard output so you'll probably have to look in a log or console to see that message. – Mattias Jan 07 '14 at 18:32