函数至少需要2个参数

时间:2014-01-07 17:13:17

标签: python python-2.7 xbmc

我使用python脚本编写xbmc程序,我可以打开addons.py而不会有任何问题,但是我无法从addons.py打开test.py.我目前在两个不同的文件addons.py和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()

我真的需要你的帮助,因为当我打开addons.py时,我无法从addons.py打开test.py.它会给我一个function takes at least 2 arguments (0 given)的错误。我不知道该怎么做。

这是日志: http://pastebin.com/Qacy0UnA

有没有人知道如何从addons.py脚本中打开test.py?

2 个答案:

答案 0 :(得分:0)

16:55:23 T:4196错误:mydisplay = MyClass()
16:55:23 T:4196 ERROR:TypeError:函数至少需要2个参数(给定0)

挖掘xbmcgui.WindowXML的文档,看看构造函数的参数是什么。

答案 1 :(得分:0)

更改

mydisplay = MyClass()

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

这是因为WindowXMLMyClass的超类,有两个参数,文件名和路径。它在http://mirrors.xbmc.org/docs/python-docs/stable/xbmcgui.html#WindowXML

中定义得很好
相关问题