~ubuntu-branches/debian/sid/guake/sid

« back to all changes in this revision

Viewing changes to src/guake/globalhotkeys/example.py

  • Committer: Package Import Robot
  • Author(s): Daniel Echeverry
  • Date: 2015-04-26 19:15:06 UTC
  • mfrom: (1.1.7)
  • mto: This revision was merged to the branch mainline in revision 26.
  • Revision ID: package-import@ubuntu.com-20150426191506-mo8037vk6pueer5b
Tags: upstream-0.7.0
ImportĀ upstreamĀ versionĀ 0.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
Copyright (C) 2007 Lincoln de Sousa <lincoln@archlinux-br.org>
 
3
 
 
4
This program is free software; you can redistribute it and/or
 
5
modify it under the terms of the GNU General Public License as
 
6
published by the Free Software Foundation; either version 2 of the
 
7
License, or (at your option) any later version.
 
8
 
 
9
This program is distributed in the hope that it will be useful,
 
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
General Public License for more details.
 
13
 
 
14
You should have received a copy of the GNU General Public
 
15
License along with this program; if not, write to the
 
16
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
17
Boston, MA 02110-1301 USA
 
18
"""
 
19
 
 
20
"""
 
21
Globahotkeys test file
 
22
======================
 
23
 
 
24
Intro
 
25
~~~~~
 
26
This is a really simple test of globalhotkeys module.
 
27
 
 
28
To use this you must compile globalhotkeys module, and run this file with
 
29
python. Please only remember to copy your globalhotkeys.so file to a path
 
30
contained in sys.path (maybe you can use PYTHONPATH).
 
31
 
 
32
The module contains only 3 functions, init/bind/unbind and they are very simple
 
33
to use.
 
34
 
 
35
What you can not forget?
 
36
~~~~~~~~~~~~~~~~~~~~~~~~
 
37
 - Compile your module with debug flag, it will help you find a possible
 
38
   problem.
 
39
 
 
40
 - Run every test from a terminal, all messages will be displayed there.
 
41
 
 
42
 - Globalhotkeys module depends on gtk, so if you don't import gtk before call
 
43
   any funcion in that module, you will see some warnings on your terminal =D
 
44
 
 
45
 - globalhotkeys.init MUST be called before binding/unbinding keys.
 
46
 
 
47
 
 
48
What shoud happen here?
 
49
~~~~~~~~~~~~~~~~~~~~~~~
 
50
This script is a simple test that initializes globalhotkeys machinery and
 
51
bindings a key to a simple function. So after running this program, you shoud
 
52
se a message 'great =D' or 'bad =('. If every thing goes right, when you press
 
53
the F12 key, you should see ('F12',) on your terminal otherwise, you will see a
 
54
warning saying that binding has failed.
 
55
 
 
56
A really important thing is that globalhotkeys.bind returns boolean values, so
 
57
if you want to know if binding works properly, only test this with a simple if.
 
58
 
 
59
A cool test
 
60
~~~~~~~~~~~
 
61
if you want to test your program when it shoud say to the user that the binding
 
62
failed, you can simply use this program to bind the key that you're running.
 
63
Because you can bind a key once.
 
64
"""
 
65
import globalhotkeys
 
66
import gtk
 
67
 
 
68
 
 
69
def hammer(*args):
 
70
    print args
 
71
 
 
72
globalhotkeys.init()
 
73
binded = globalhotkeys.GlobalHotkey().bind('F12', hammer)
 
74
if binded:
 
75
    print 'great =D'
 
76
else:
 
77
    print 'bad =('
 
78
 
 
79
gtk.main()