X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=indicator-chars.py;h=b57981af28753480cd2634083323e32783b99fde;hb=51a9e97c84875def009af7faf7f41566aed7d0a9;hp=7111568a42b29ba73c5fde9edee0d93e2ea11198;hpb=9119151680c58f984c8bb688706cafed9e4b0573;p=indicator-chars.git diff --git a/indicator-chars.py b/indicator-chars.py index 7111568..b57981a 100755 --- a/indicator-chars.py +++ b/indicator-chars.py @@ -1,9 +1,11 @@ -#!/usr/bin/python +#!/usr/bin/env python # -*- coding: utf-8 -*- # # Very simple chars indicator. # Author: Tobias Schlitt # +# Hacked by Cyrille37 on 2016-02-03 +# # Copyright (c) 2011, Tobias Schlitt # All rights reserved. # @@ -31,21 +33,31 @@ # DAMAGE. import os +import re import gtk import gio import signal import subprocess +# sudo apt-get install python-appindicator import appindicator APP_NAME = 'indicator-chars' -APP_VERSION = '0.1' +APP_VERSION = '0.2' class IndicatorChars: - CHARS_PATH = os.getenv('HOME') + '/.indicator-chars' + CHARS_PATH = os.path.join(os.getenv('HOME'), '.indicator-chars') SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) + submenu_title_pattern = re.compile(r'\[([^]]+)\] *') + description_pattern = re.compile(r' *(\([^)]+\)) *') + def __init__(self): - self.ind = appindicator.Indicator("Chars", self.SCRIPT_DIR + '/light16x16.png', appindicator.CATEGORY_APPLICATION_STATUS) + self.ind = appindicator.Indicator( + # Custom icon seems to doesn't work on my Ubuntu 12.04 LTS running Unity 2D + #"Chars", os.path.join(self.SCRIPT_DIR, 'light16x16.png'), + # So fallback to an referenced theme's icon name + "Chars", "accessories-character-map", + appindicator.CATEGORY_APPLICATION_STATUS) self.ind.set_status(appindicator.STATUS_ACTIVE) self.update_menu() @@ -68,26 +80,54 @@ class IndicatorChars: # Create menu menu = gtk.Menu() - self.ind.set_menu(menu) for charLine in charDef: charLine = unicode(charLine) charLine = charLine.strip() - parentItem = self.create_menu_item(charLine) + submenu_match = self.submenu_title_pattern.match(charLine) + if submenu_match: + submenu_title = submenu_match.group(1) + # remove title part from remainder: + charLine = charLine[submenu_match.end():] + else: + submenu_title = ''.join( + self.description_pattern.split(charLine)[::2]) + parentItem = self.create_menu_item(submenu_title) subMenu = gtk.Menu() - for char in charLine: - subItem = self.create_menu_item(char) + while charLine: + char = charLine[0] + charLine = charLine[1:] + description_match = self.description_pattern.match(charLine) + if description_match: + item_title = char + ' ' + description_match.group(1) + # remove description part from remainder: + charLine = charLine[description_match.end():] + else: + item_title = char + subItem = self.create_menu_item(item_title) subItem.connect("activate", self.on_char_click, char) subMenu.append(subItem) parentItem.set_submenu(subMenu) menu.append(parentItem) + menu.append(gtk.SeparatorMenuItem()) + quit_item = self.create_menu_item('Quit') + quit_item.connect("activate", self.on_quit) + menu.append(quit_item) + # Show the menu + self.ind.set_menu(menu) menu.show_all() def on_char_click(self, widget, char): cb = gtk.Clipboard(selection="PRIMARY") cb.set_text(char) + cb = gtk.Clipboard(selection="CLIPBOARD") + cb.set_text(char) + + def on_quit(self, widget): + gtk.main_quit() + if __name__ == "__main__": # Catch CTRL-C