2013-05-17 5 views
2

주 창을 닫을 때 (즉, 프로세스가 실행 중일 때) t와 같은 키보드 바로 가기를 만들고 싶습니다 (프로그램이 단일 지시자를 가짐). 패키지 키 바인더를 보았지만 Gtk3 및 pygobject와 함께 사용할 수없는 것 같습니다. 아니면 할 수 있을까요? 그러면 어떻게? 그렇지 않다면 다른 방법이 있습니까? 응용 프로그램은 리눅스 (우분투), 나는 파이썬 2.7을 사용합니다.python (및 Gtk3)을 사용하여 글로벌 키보드 단축키를 만드는 방법은 무엇입니까?

+0

메모를 추가하면 2.7 용으로도 제대로 작동하므로 디스크를 어수선하게 정리하고 싶지 않습니다. 나는 2.7을 매우 깨끗하게 유지하고 py3k에서 할 가치가있는 모든 작업을 수행합니다. – RobotHumans

답변

4

Keybinder는 python3, Gtk3 및 pygi에서 잘 작동합니다. 원본 트리에서 작동하는 예제가 없습니다.

#!/usr/bin/env python3 
""" 
example-gi-py3.py 

Looked at a pull request that was built for py2.x, but 
overwrote the original py instead of making a separate example. 
I wouldn't have accepted that pull request either. 

The keybinder.init() part wasn't in the original example. 

[email protected] 

public domain 
""" 

import gi 
gi.require_version('Gtk', '3.0') 
gi.require_version('Keybinder', '3.0') 

from gi.repository import Gtk 
from gi.repository import Keybinder 

def callback(keystr, user_data): 
    print ("Handling", user_data) 
    print ("Event time:", Keybinder.get_current_event_time()) 
    Gtk.main_quit() 

if __name__ == '__main__': 
    keystr = "<Ctrl><Alt>M" 
    Keybinder.init() 
    Keybinder.bind(keystr, callback, "keystring %s (user data)" % keystr) 
    print ("Press", keystr, "to handle keybinding and quit") 
    Gtk.main() 

주 : 은 철저히 테스트하지만, 간단한 예제로는 작동하는 것 같다하지 않습니다.

+0

덧붙여 말하자면, 원래 예제를 따라 가지 않은이 예제를 github에 대한 pull 요청에 넣었습니다. 어쩌면 그 사람이 들어올 것입니다. – RobotHumans

0

가 나는 Gtk3 응용 프로그램에 검색 입력 필드를 활성화하는 것이 Keybinder를 사용 : 다른 응용 프로그램과 응용 프로그램을 사용하는 경우 경우

from gi.repository import Keybinder 
… 
    class MyApp: 
    … 
     Keybinder.init() 
     Keybinder.bind("<Ctrl>F", self.set_search_entry_focus) 
… 
    def set_search_entry_focus(self, keystring): 
     self.search_entry.grab_focus() 

http://lazka.github.io/pgi-docs/Keybinder-3.0/

그러나이 인식이 또한 초점을 훔치는 것 백그라운드에서 실행 중입니다.