Page 1 of 1

TypeError: __call__() takes exactly 2 argument

Posted: Mon Oct 14, 2013 11:51 am
by Jostein
Hi.

I am trying to make a plugin but get an error when trying to use a configurable value from the plugin in an action. Have tried from scratch using the examle from the documentation but get the same error. How should the code look?

Code: Select all

13:39:41      Error in Action: "My New Plugin: PrintString"
13:39:41      Traceback (most recent call last) (1630):
13:39:41        File "C:\Program Files (x86)\EventGhost\eg\Classes\ActionBase.py", line 170, in CallWrapper
13:39:41          return self(*args)
13:39:41      TypeError: __call__() takes exactly 2 arguments (1 given)
My plugin looks like this from the example in the documentation:

Code: Select all

import eg

eg.RegisterPlugin(
    name = "My New Plugin",
    author = "Me",
    version = "0.0.1",
    kind = "other",
    description = "This is an example plugin."
)

class MyNewPlugin(eg.PluginBase):

    def __init__(self):
        self.AddAction(PrintString)

    def Configure(self, myString=""):
        panel = eg.ConfigPanel()
        textControl = wx.TextCtrl(panel, -1, myString)
        panel.sizer.Add(textControl, 1, wx.EXPAND)
        while panel.Affirmed():
            panel.SetResult(textControl.GetValue())

            
class PrintString(eg.ActionBase):

    def __call__(self, myString):
        print myString
Have also tryed "print self.myString" and "print self.plugin.myString" instead of "print mystring" but get the same error.

Hope someone can help me get on the right track.

Regards Jostein

Re: TypeError: __call__() takes exactly 2 argument

Posted: Mon Oct 14, 2013 3:11 pm
by Pako
Try the following version:

Code: Select all

import eg

eg.RegisterPlugin(
    name = "My New Plugin",
    author = "Me",
    version = "0.0.2",
    kind = "other",
    description = "This is an example plugin."
)

class MyNewPlugin(eg.PluginBase):

    def __init__(self):
        self.AddAction(PrintString)

    def __start__(self, myString=""):
        self.myString = myString

    def Configure(self, myString=""):
        panel = eg.ConfigPanel()
        textControl = wx.TextCtrl(panel, -1, myString)
        panel.sizer.Add(textControl, 1, wx.EXPAND)
        while panel.Affirmed():
            panel.SetResult(textControl.GetValue())

            
class PrintString(eg.ActionBase):

    def __call__(self):
        print self.plugin.myString
Pako

Re: TypeError: __call__() takes exactly 2 argument

Posted: Mon Oct 14, 2013 6:38 pm
by Jostein
Hi Pako.

Thanks. This works great.

Regards Jostein