2 # -*- coding: utf-8 -*-
4 # Very simple chars indicator.
5 # Author: Tobias Schlitt <toby@php.net>
7 # Copyright (c) 2011, Tobias Schlitt
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions are met:
13 # Redistributions of source code must retain the above copyright notice,
14 # this list of conditions and the following disclaimer. Redistributions
15 # in binary form must reproduce the above copyright notice, this list of
16 # conditions and the following disclaimer in the documentation and/or
17 # other materials provided with the distribution.
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24 # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30 # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
40 APP_NAME
= 'indicator-chars'
44 CHARS_PATH
= os
.getenv('HOME') + '/.indicator-chars'
47 self
.ind
= appindicator
.Indicator("Chars", "gnome-character-map", appindicator
.CATEGORY_APPLICATION_STATUS
)
48 self
.ind
.set_status(appindicator
.STATUS_ACTIVE
)
52 def create_menu_item(self
, label
):
57 def on_chars_changed(self
, filemonitor
, file, other_file
, event_type
):
58 if event_type
== gio
.FILE_MONITOR_EVENT_CHANGES_DONE_HINT
:
59 print 'Characters changed, updating menu...'
62 def update_menu(self
, widget
= None, data
= None):
64 charDef
= open(self
.CHARS_PATH
).readlines()
70 self
.ind
.set_menu(menu
)
72 for charLine
in charDef
:
73 charLine
= unicode(charLine
)
74 charLine
= charLine
.strip()
75 parentItem
= self
.create_menu_item(charLine
)
78 subItem
= self
.create_menu_item(char
)
79 subItem
.connect("activate", self
.on_char_click
, char
)
80 subMenu
.append(subItem
)
81 parentItem
.set_submenu(subMenu
)
82 menu
.append(parentItem
)
87 def on_char_click(self
, widget
, char
):
88 cb
= gtk
.Clipboard(selection
="PRIMARY")
91 if __name__
== "__main__":
93 signal
.signal(signal
.SIGINT
, lambda signal
, frame
: gtk
.main_quit())
98 # Monitor bookmarks changes
99 file = gio
.File(i
.CHARS_PATH
)
100 monitor
= file.monitor_file()
101 monitor
.connect("changed", i
.on_chars_changed
)