├── .gitignore
├── README.md
├── textlines.py
└── textlines16x16.png
/.gitignore:
--------------------------------------------------------------------------------
1 | !textlines16x16.png
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Textlines Indicator
2 |
3 | Simple GTK+ script for Ubuntu's "Unity desktop" indicator menu.
4 |
5 | Looks for a file ~/.textlines that contains lines of text you often use. Shows the lines in an indicator menu. Clicking a line will insert it into the clipboard, ready to Ctrl+P post.
6 |
7 |
8 |
9 |
10 |
11 | Based on https://github.com/tobyS/indicator-chars
12 |
--------------------------------------------------------------------------------
/textlines.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # -*- coding: utf-8 -*-
3 | #
4 | # Simple GTK+ script for Ubuntu Unity indicator menu.
5 | #
6 | # Looks for a file ~/.textlines that contains lines of text you often use.
7 | # Shows the lines in an indicator menu. Clicking a line will insert it into
8 | # the clipboard, ready to Ctrl+P post.
9 | #
10 | # Based on https://github.com/tobyS/indicator-chars
11 |
12 | import os
13 | import re
14 | import gtk
15 | import gio
16 | import signal
17 | import subprocess
18 | import appindicator
19 |
20 | APP_NAME = 'textlines-indicator'
21 | APP_VERSION = '0.2'
22 |
23 | class TextLinesIndicator:
24 | CHARS_PATH = os.path.join(os.getenv('HOME'), '.textlines')
25 | SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
26 |
27 | def __init__(self):
28 | self.ind = appindicator.Indicator(
29 | "TextLines", os.path.join(self.SCRIPT_DIR, 'textlines16x16.png'),
30 | appindicator.CATEGORY_APPLICATION_STATUS)
31 | self.ind.set_status(appindicator.STATUS_ACTIVE)
32 |
33 | self.update_menu()
34 |
35 | def create_menu_item(self, label):
36 | item = gtk.MenuItem()
37 | item.set_label(label)
38 | return item
39 |
40 | def on_chars_changed(self, filemonitor, file, other_file, event_type):
41 | if event_type == gio.FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
42 | print 'Textlines changed, updating menu...'
43 | self.update_menu()
44 |
45 | def update_menu(self, widget=None, data=None):
46 | try:
47 | charDef = open(self.CHARS_PATH).readlines()
48 | except IOError:
49 | charDef = []
50 |
51 | menu = gtk.Menu()
52 |
53 | for charLine in charDef:
54 | charLine = unicode(charLine)
55 | charLine = charLine.strip()
56 | parentItem = self.create_menu_item(charLine)
57 | parentItem.connect("activate", self.on_char_click, charLine)
58 | menu.append(parentItem)
59 |
60 | menu.append(gtk.SeparatorMenuItem())
61 | quit_item = self.create_menu_item('Quit')
62 | quit_item.connect("activate", self.on_quit)
63 | menu.append(quit_item)
64 |
65 | self.ind.set_menu(menu)
66 | menu.show_all()
67 |
68 | def on_char_click(self, widget, text):
69 | if text != None:
70 | cb = gtk.Clipboard()
71 | cb.set_text(text)
72 |
73 | def on_quit(self, widget):
74 | gtk.main_quit()
75 |
76 | if __name__ == "__main__":
77 | # Catch CTRL-C
78 | signal.signal(signal.SIGINT, lambda signal, frame: gtk.main_quit())
79 |
80 | # Run the indicator
81 | i = TextLinesIndicator()
82 |
83 | # Monitor bookmarks changes
84 | file = gio.File(i.CHARS_PATH)
85 | monitor = file.monitor_file()
86 | monitor.connect("changed", i.on_chars_changed)
87 |
88 | # Main gtk loop
89 | gtk.main()
90 |
--------------------------------------------------------------------------------
/textlines16x16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/C14L/textlines-indicator/473053fe0ebf9ac453145668d06ddcc45cd2a655/textlines16x16.png
--------------------------------------------------------------------------------