Results 1 to 10 of 12
Hello,
I am (trying) to write a plugin for rhythmbox and keep running into an error msg from an action from the toolbar
this is the msg I get.
TypeError: ...
- 12-29-2009 #1Just Joined!
- Join Date
- Aug 2008
- Posts
- 17
TypeError: startView() takes exactly 1 argument (3 given)
Hello,
I am (trying) to write a plugin for rhythmbox and keep running into an error msg from an action from the toolbar
this is the msg I get.
TypeError: startView() takes exactly 1 argument (3 given)
No matter how many arguments I define startView with, I always get this error:
Here is the code snippet:
#
# the activate thing
#
def activate(self, shell):
self.shell = shell
view_button = """
<ui>
<toolbar name="ToolBar">
<placeholder name="startView">
<toolitem name="startView" action="viewAction">
</toolitem>
</placeholder>
</toolbar>
</ui>
"""
# create a new action
action = gtk.Action('viewAction',
_('Start _View'),
_('Browse'), "")
# connect it
action.connect('activate', self.startView, shell)
action_group = gtk.ActionGroup('NewActionGroup')
action_group.add_action(action)
shell.get_ui_manager().insert_action_group(action_ group)
# add it to the toolbar
ui_manager = shell.get_ui_manager()
ui_manager.add_ui_from_string(view_button)
#
# Start the View
#
def startView(self, b, c, d): # tried this with 1, 2, 3, 4, 5... arguments
return
- 12-29-2009 #2
can you post this in code tags so it is easier to read?
- 12-29-2009 #3Just Joined!
- Join Date
- Aug 2008
- Posts
- 17
sure...
Code:# # the activate thing # def activate(self, shell): self.shell = shell view_button = """ <ui> <toolbar name="ToolBar"> <placeholder name="startView"> <toolitem name="startView" action="viewAction"> </toolitem> </placeholder> </toolbar> </ui> """ # create a new action action = gtk.Action('viewAction', _('Start _View'), _('Browse'), "") # connect it action.connect('activate', self.startView, shell) action_group = gtk.ActionGroup('NewActionGroup') action_group.add_action(action) shell.get_ui_manager().insert_action_group(action_ group) # add it to the toolbar ui_manager = shell.get_ui_manager() ui_manager.add_ui_from_string(view_button) # # Start the View # def startView(self, b, c, d): # tried this with 1, 2, 3, 4, 5... arguments return
- 12-29-2009 #4
i'm guessing that you are overriding the startView class method of a parent class, or the calling class is expecting startView with 0 arguments, what happens when you try to define it just as startView(self)?
- 12-30-2009 #5Just Joined!
- Join Date
- Aug 2008
- Posts
- 17
I don't think I am overriding a class. All the methods are in the same class. The method I am trying to write is just an action to a button in the toolbar of rhythmbox.
I'll repost the code so you can see the whole class (I missed the top iI noticed.)
(oh btw, changing the number of arguments to just be one didn't help, I tried a few of those things. I think it is weird that how ever many arguments I use, it keeps complaining about getting 3 and 'needing' 1.)
Code:class tb_button (rb.Plugin): # # the init thing # def __init__(self): rb.Plugin.__init__(self) # # the activate thing # def activate(self, shell): self.shell = shell view_button = """ <ui> <toolbar name="ToolBar"> <placeholder name="View"> <toolitem name="View" action="viewAction"> </toolitem> </placeholder> </toolbar> </ui> """ # create a new action action = gtk.Action('viewAction', _(' _View'), _('Browse Track '), "") # connect it action.connect('activate', self.startView, shell) action_group = gtk.ActionGroup('NewActionGroup') action_group.add_action(action) shell.get_ui_manager().insert_action_group(action_group) # add it to the toolbar ui_manager = shell.get_ui_manager() ui_manager.add_ui_from_string(view_button) # # Start the View # def startView(self, widget, shell): # nothing yet return
- 12-30-2009 #6
I don't know much about the API, have you looked at a tutorial? What I am saying is, startView must only be defined with 1 argument, and that is self. Whatever is calling the startView function is expecting it to have 1 argument, that is the self argument and you don't need to pass it since it is a member function. You can see this by making your own class and create a member function with def func(self) and call that function with 1 argument, you will get an error similar to the one you posted.
- 12-30-2009 #7Code:
>>> class MyClass: ... def __init__(self, a): ... self.a = a ... def noargs(self): ... print self.a ... def onearg(self, b): ... print self.a + b ... >>> test = MyClass(5) >>> test.noargs() 5 >>> test.noargs(1) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: noargs() takes exactly 1 argument (2 given) >>> test.onearg(5) 10 >>> test.onearg(5,5) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: onearg() takes exactly 2 arguments (3 given)
- 12-30-2009 #8Just Joined!
- Join Date
- Aug 2008
- Posts
- 17
I don't know that much about the API either. Yes I did look at the manual, as a matter of fact that part of the code came from the manual.
I also found (a few times on google) that this was a known bug. But that bug popped up over a year ago. So it is very likely it was fixed. Also, since I am new to python, the chances of me running into a bug in python vs me making a mistake is probably 1:9999
- 12-30-2009 #9
that bug could be in the version you are using, depending on what distro you have, you might not have the bug fixed version
- 12-30-2009 #10Just Joined!
- Join Date
- Aug 2008
- Posts
- 17


Reply With Quote
