Adding default parameter that is object to a function that is inside a class
<p>I am trying to make a applet for mate-panel in linux . I have to modules <code>Window.py</code> and <code>Applet.py</code>. I get this error: </p>

<pre><code>Traceback (most recent call last):
File "./Applet.py", line 37, in WindowButtonsAppletFactory
WindowButtonsApplet(applet)
File "./Applet.py", line 23, in WindowButtonsApplet
CloseButton.connect("Clicked",WindowActions().win_close(SelectedWindow))
File "WindowButtonsApplet/Window.py", line 23, in win_close
Window.close(Timestamp)
AttributeError: 'WindowActions' object has no attribute 'close'

** (Applet.py:2191): WARNING **: need to free the control here
</code></pre>

<p>And I don't know why since the wnck librally has atribute named close.
The second thing I wan't to ask is why do I need to init the Class every time I call it .</p>

<p>Here is the code from:
Applet.py</p>

<pre><code>#!/bin/env python3

import gi
import Window

gi.require_version("Gtk","3.0")
gi.require_version("MatePanelApplet", "4.0")

from gi.repository import Gtk
from gi.repository import MatePanelApplet
from Window import *


def WindowButtonsApplet(applet):

    Box = Gtk.Box("Horizontal")

    CloseButton = Gtk.Button("x")
    MinButton = Gtk.Button("_")
    UmaximizeButton = Gtk.Button("[]")

    SelectedWindow = WindowActions().active_window()
    CloseButton.connect("Clicked",WindowActions().win_close(SelectedWindow))
    Box.pack_start(CloseButton)

    applet.add(Box)
    applet.show_all()

// Hack for transparent background

applet.set_background_widget(applet)

def WindowButtonsAppletFactory(applet, iid,data):
    if iid != "WindowButtonsApplet":
        return False

    WindowButtonsApplet(applet)

    return True

 //Mate panel procedure to load the applet on panel

 MatePanelApplet.Applet.factory_main("WindowButtonsAppletFactory", True,
                                    MatePanelApplet.Applet.__gtype__,
                                    WindowButtonsAppletFactory, None)
</code></pre>

<p>Window.py</p>

<pre><code>#!/usr/bin/env python3

import time
import gi

gi.require_version("Gtk","3.0")
gi.require_version("Wnck","3.0")

from gi.repository import Gtk
from gi.repository import Wnck

class WindowActions:

DefaultScreen = Wnck.Screen.get_default()
DTimestamp = int(time.time())

def active_window(self,Screen=DefaultScreen): 
    Screen.force_update()
    self.ActiveWindow = Screen.get_active_window()
    return self.ActiveWindow

def win_close(Window,Timestamp=DTimestamp):
    Window.close(Timestamp)

def win_minimize(self,Window):
    Window.minimize()

def win_umaximize(self,Window):
    self.Window.maximize()
</code></pre>

<p>You're missing the reference to <code>self</code> in:</p>

<pre><code>def win_close(Window,Timestamp=DTimestamp):
    Window.close(Timestamp)
</code></pre>

<p>as a result an <code>WindowActions</code> instance is passed which doesn't define a close method and your actual selected window is passed to <code>Timestamp</code>.</p>

<p>Add <code>self</code> to your method definition and that should solve it.</p>

python python-3.x gtk3 pygobject wnck