Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
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: ...
  1. #1
    Just 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

  2. #2
    Linux Guru coopstah13's Avatar
    Join Date
    Nov 2007
    Location
    NH, USA
    Posts
    3,149
    can you post this in code tags so it is easier to read?

  3. #3
    Just Joined!
    Join Date
    Aug 2008
    Posts
    17
    Quote Originally Posted by coopstah13 View Post
    can you post this in code tags so it is easier to read?
    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

  4. #4
    Linux Guru coopstah13's Avatar
    Join Date
    Nov 2007
    Location
    NH, USA
    Posts
    3,149
    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)?

  5. #5
    Just Joined!
    Join Date
    Aug 2008
    Posts
    17
    Quote Originally Posted by coopstah13 View Post
    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)?
    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

  6. #6
    Linux Guru coopstah13's Avatar
    Join Date
    Nov 2007
    Location
    NH, USA
    Posts
    3,149
    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.

  7. #7
    Linux Guru coopstah13's Avatar
    Join Date
    Nov 2007
    Location
    NH, USA
    Posts
    3,149
    Code:
    >>> 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)

  8. #8
    Just Joined!
    Join Date
    Aug 2008
    Posts
    17
    Quote Originally Posted by coopstah13 View Post
    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.
    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

  9. #9
    Linux Guru coopstah13's Avatar
    Join Date
    Nov 2007
    Location
    NH, USA
    Posts
    3,149
    that bug could be in the version you are using, depending on what distro you have, you might not have the bug fixed version

  10. #10
    Just Joined!
    Join Date
    Aug 2008
    Posts
    17
    Quote Originally Posted by coopstah13 View Post
    that bug could be in the version you are using, depending on what distro you have, you might not have the bug fixed version
    uhm... ok.

    the python I am using: Python 2.6.2

    On Ubuntu 9.04 (2.6.28-17)

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...