2016-08-31 6 views
2

리눅스에서 메이트 패널 용 애플릿을 만들려고합니다. 모듈 Window.pyApplet.py을 가지고 있습니다. 이 오류 얻을 :클래스 안에있는 함수에 객체 인 기본 매개 변수 추가하기

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 

을 그리고 wnck이 librally atribute 가까이라는 이름의 이후 이유를 모르겠어요. 두 번째로 묻는 것은 클래스를 호출 할 때마다 클래스를 초기화해야하는 이유입니다. Applet.py

#!/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) 

Window.py

#!/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() 

답변

1

당신이 self에 대한 참조 놓치고 : A와

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

을 여기

은에서 코드입니다 결과 WindowActions 닫기가 정의되지 않은 인스턴스가 전달됩니다. 메서드를 선택하고 실제 선택된 윈도우는 Timestamp으로 전달됩니다.

self을 메서드 정의에 추가하면 해결됩니다.

+0

문제를 해결해 주셔서 감사합니다. 내가 어떻게 그것을 놓쳤는 지 궁금해. – IKRadulov