Merge lp:~duanedesign/clicompanion/clicompanion.seperate.merge into lp:clicompanion
- clicompanion.seperate.merge
- Merge into trunk
Proposed by
Duane Hinnen
Status: | Merged |
---|---|
Approved by: | Duane Hinnen |
Approved revision: | 56 |
Merged at revision: | 55 |
Proposed branch: | lp:~duanedesign/clicompanion/clicompanion.seperate.merge |
Merge into: | lp:clicompanion |
Diff against target: |
2240 lines (+1188/-969) 15 files modified
MANIFEST (+12/-0) clicompanion (+37/-0) clicompanion.py (+0/-723) clicompanion/__init__.py (+0/-23) clicompanion/menus_buttons.py (+0/-157) clicompanion/utils.py (+0/-66) clicompanionlib/__init__.py (+23/-0) clicompanionlib/controller.py (+428/-0) clicompanionlib/menus_buttons.py (+175/-0) clicompanionlib/tabs.py (+81/-0) clicompanionlib/utils.py (+56/-0) clicompanionlib/view.py (+279/-0) data/clicompanion.desktop (+7/-0) data/clicompanion2.config (+48/-0) setup.py (+42/-0) |
To merge this branch: | bzr merge lp:~duanedesign/clicompanion/clicompanion.seperate.merge |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Duane Hinnen | Approve | ||
Review via email: mp+42261@code.launchpad.net |
Commit message
Description of the change
merge of lp:clicompanion.seperate
Because of the way that branch was created it was necessary to create clicompanion.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === removed file 'CLIcompanion.16.png' | |||
2 | 0 | Binary files CLIcompanion.16.png 2010-10-06 06:54:47 +0000 and CLIcompanion.16.png 1970-01-01 00:00:00 +0000 differ | 0 | Binary files CLIcompanion.16.png 2010-10-06 06:54:47 +0000 and CLIcompanion.16.png 1970-01-01 00:00:00 +0000 differ |
3 | === added file 'MANIFEST' | |||
4 | --- MANIFEST 1970-01-01 00:00:00 +0000 | |||
5 | +++ MANIFEST 2010-11-30 16:11:27 +0000 | |||
6 | @@ -0,0 +1,12 @@ | |||
7 | 1 | setup.py | ||
8 | 2 | clicompanion | ||
9 | 3 | clicompanionlib/__init__.py | ||
10 | 4 | clicompanionlib/controller.py | ||
11 | 5 | clicompanionlib/menus_buttons.py | ||
12 | 6 | clicompanionlib/tabs.py | ||
13 | 7 | clicompanionlib/utils.py | ||
14 | 8 | clicompanionlib/view.py | ||
15 | 9 | data/ubuntuone-indicator.desktop | ||
16 | 10 | data/clicompanion.config | ||
17 | 11 | data/clicompanion.16.png | ||
18 | 12 | data/clicompanion.64.png | ||
19 | 0 | 13 | ||
20 | === added file 'clicompanion' | |||
21 | --- clicompanion 1970-01-01 00:00:00 +0000 | |||
22 | +++ clicompanion 2010-11-30 16:11:27 +0000 | |||
23 | @@ -0,0 +1,37 @@ | |||
24 | 1 | #! /usr/bin/env python | ||
25 | 2 | |||
26 | 3 | import locale | ||
27 | 4 | import gettext | ||
28 | 5 | import os | ||
29 | 6 | |||
30 | 7 | from clicompanionlib.view import run | ||
31 | 8 | |||
32 | 9 | |||
33 | 10 | BASEDIR = '/usr/share/clicompanion/' | ||
34 | 11 | |||
35 | 12 | def get_language(): | ||
36 | 13 | """Return the language to be used by the system. | ||
37 | 14 | |||
38 | 15 | If it finds the system language in the translated files, it | ||
39 | 16 | returns it, otherwise it just returns None. | ||
40 | 17 | """ | ||
41 | 18 | loc = locale.setlocale(locale.LC_ALL, "") | ||
42 | 19 | loc = loc[:2] | ||
43 | 20 | traducidos = os.listdir(locale_dir) | ||
44 | 21 | if loc in traducidos: | ||
45 | 22 | return loc | ||
46 | 23 | return | ||
47 | 24 | |||
48 | 25 | locale_dir = os.path.join(BASEDIR, "locale") | ||
49 | 26 | gettext.install('clicompanion', locale_dir, unicode=True) | ||
50 | 27 | idioma = get_language() | ||
51 | 28 | if idioma is not None: | ||
52 | 29 | mo = os.path.join(locale_dir, '%s/LC_MESSAGES/clicompanion.mo' % idioma) | ||
53 | 30 | if not os.access(mo, os.F_OK): | ||
54 | 31 | raise IOError("The l10n directory (for language %r) exists but " | ||
55 | 32 | "not the clicompanion.mo file" % idioma) | ||
56 | 33 | trans = gettext.translation('clicompanion', locale_dir, languages=[idioma]) | ||
57 | 34 | trans.install(unicode=True) | ||
58 | 35 | |||
59 | 36 | if __name__ == "__main__": | ||
60 | 37 | run() | ||
61 | 0 | 38 | ||
62 | === removed directory 'clicompanion' | |||
63 | === removed file 'clicompanion.py' | |||
64 | --- clicompanion.py 2010-10-06 06:47:50 +0000 | |||
65 | +++ clicompanion.py 1970-01-01 00:00:00 +0000 | |||
66 | @@ -1,723 +0,0 @@ | |||
67 | 1 | #!/usr/bin/env python | ||
68 | 2 | # -*- coding: utf-8 -*- | ||
69 | 3 | # | ||
70 | 4 | # clicompanion.py - commandline tool. | ||
71 | 5 | # | ||
72 | 6 | # Copyright 2010 Duane Hinnen, Kenny Meyer, Marcos Vanetta | ||
73 | 7 | # | ||
74 | 8 | # This program is free software: you can redistribute it and/or modify it | ||
75 | 9 | # under the terms of the GNU General Public License version 3, as published | ||
76 | 10 | # by the Free Software Foundation. | ||
77 | 11 | # | ||
78 | 12 | # This program is distributed in the hope that it will be useful, but | ||
79 | 13 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
80 | 14 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
81 | 15 | # PURPOSE. See the GNU General Public License for more details. | ||
82 | 16 | # | ||
83 | 17 | # You should have received a copy of the GNU General Public License along | ||
84 | 18 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
85 | 19 | # | ||
86 | 20 | #pdb debugger | ||
87 | 21 | #import pdb; pdb.set_trace() | ||
88 | 22 | # | ||
89 | 23 | |||
90 | 24 | |||
91 | 25 | import re | ||
92 | 26 | import sys | ||
93 | 27 | import pygtk | ||
94 | 28 | pygtk.require('2.0') | ||
95 | 29 | |||
96 | 30 | import os | ||
97 | 31 | import os.path | ||
98 | 32 | |||
99 | 33 | ## Starting with the i18n ### | ||
100 | 34 | import locale | ||
101 | 35 | import gettext | ||
102 | 36 | |||
103 | 37 | BASEDIR = '/usr/share/clicompanion/' | ||
104 | 38 | |||
105 | 39 | def get_language(): | ||
106 | 40 | """Return the language to be used by the system. | ||
107 | 41 | |||
108 | 42 | If it finds the system language in the translated files, it | ||
109 | 43 | returns it, otherwise it just returns None. | ||
110 | 44 | """ | ||
111 | 45 | loc = locale.setlocale(locale.LC_ALL, "") | ||
112 | 46 | loc = loc[:2] | ||
113 | 47 | traducidos = os.listdir(locale_dir) | ||
114 | 48 | if loc in traducidos: | ||
115 | 49 | return loc | ||
116 | 50 | return | ||
117 | 51 | |||
118 | 52 | locale_dir = os.path.join(BASEDIR, "locale") | ||
119 | 53 | gettext.install('clicompanion', locale_dir, unicode=True) | ||
120 | 54 | idioma = get_language() | ||
121 | 55 | if idioma is not None: | ||
122 | 56 | mo = os.path.join(locale_dir, '%s/LC_MESSAGES/clicompanion.mo' % idioma) | ||
123 | 57 | if not os.access(mo, os.F_OK): | ||
124 | 58 | raise IOError("The l10n directory (for language %r) exists but " | ||
125 | 59 | "not the clicompanion.mo file" % idioma) | ||
126 | 60 | trans = gettext.translation('clicompanion', locale_dir, languages=[idioma]) | ||
127 | 61 | trans.install(unicode=True) | ||
128 | 62 | ## End with i18n ### | ||
129 | 63 | |||
130 | 64 | ## import gtk or print error | ||
131 | 65 | try: | ||
132 | 66 | import gtk | ||
133 | 67 | except: | ||
134 | 68 | error = gtk.MessageDialog (None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, | ||
135 | 69 | _("You need to install the python gtk bindings")) | ||
136 | 70 | error.run() | ||
137 | 71 | sys.exit (1) | ||
138 | 72 | |||
139 | 73 | ## import vte or display message dialog | ||
140 | 74 | try: | ||
141 | 75 | import vte | ||
142 | 76 | except: | ||
143 | 77 | error = gtk.MessageDialog (None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, | ||
144 | 78 | _('You need to install python bindings for libvte')) | ||
145 | 79 | error.run() | ||
146 | 80 | sys.exit (1) | ||
147 | 81 | |||
148 | 82 | import clicompanion.menus_buttons | ||
149 | 83 | from clicompanion.utils import get_user_shell, sumfile | ||
150 | 84 | |||
151 | 85 | |||
152 | 86 | #TODO: Get rid of global commands CMNDS and ROW | ||
153 | 87 | CMNDS = [] | ||
154 | 88 | ROW = '' | ||
155 | 89 | CHEATSHEET = os.path.expanduser("~/.clicompanion") | ||
156 | 90 | CHEATSHEETBAK = os.path.expanduser("~/.clicompanion.bak") | ||
157 | 91 | CONFIG_ORIG = "/etc/clicompanion.d/clicompanion.config" | ||
158 | 92 | |||
159 | 93 | |||
160 | 94 | class Companion(object): | ||
161 | 95 | ''' | ||
162 | 96 | All the actions the program can do. | ||
163 | 97 | ''' | ||
164 | 98 | ## copy config file to user $HOME if does not exist | ||
165 | 99 | def setup(self): | ||
166 | 100 | """Create an initial cheatsheet.""" | ||
167 | 101 | if not os.path.exists(CHEATSHEET): | ||
168 | 102 | if os.path.exists(CONFIG_ORIG): | ||
169 | 103 | os.system ("cp %s %s" % (CONFIG_ORIG, CHEATSHEET)) | ||
170 | 104 | else: | ||
171 | 105 | ## Oops! Looks like there's no cheatsheet in CHEATSHEET. | ||
172 | 106 | ## Then, create an empty cheatsheet. | ||
173 | 107 | open(CHEATSHEET, 'w').close() | ||
174 | 108 | |||
175 | 109 | elif os.path.exists(CHEATSHEET): | ||
176 | 110 | if os.path.exists(CONFIG_ORIG): | ||
177 | 111 | md5 = sumfile() | ||
178 | 112 | print md5 | ||
179 | 113 | if md5 == '824868f40cd02f0039d5a1fbdbe642d7' or 'a244f1b197f5cfc6b2f35b65911d3930' or '08e7f4de1838b79ab476fcbfb8074da0' or 'd68d6e9da0a3753c8142b63f0ea74511' or '8ab6d4bf6168c1b775221f466c2fcbbd' or ' 6f4f152766441670a55d3bf00567c92e' or ' f4e73fe22505091d6d75767fafc2848c' or ' 7d2f69943cfe5dbd33a45c63008fca17' or '7fc757ca67121b14e574280a6dbe24ef' or '0e345d5934032aa7fecb23cff56d5407': | ||
180 | 114 | os.system ("cp %s %s" % (CONFIG_ORIG, CHEATSHEET)) | ||
181 | 115 | print '.clicompanion not modified by user' | ||
182 | 116 | #TODO what to do if user has modified command dictionary? | ||
183 | 117 | else: | ||
184 | 118 | os.system ("cp %s %s" % (CHEATSHEET, CHEATSHEETBAK)) | ||
185 | 119 | os.system ("cp %s %s" % (CONFIG_ORIG, CHEATSHEET)) | ||
186 | 120 | print '.clicompanion modified by user' | ||
187 | 121 | |||
188 | 122 | ## close the window and quit | ||
189 | 123 | def delete_event(self, widget, data=None): | ||
190 | 124 | gtk.main_quit() | ||
191 | 125 | return False | ||
192 | 126 | |||
193 | 127 | ## Info Dialog Box | ||
194 | 128 | ## if a command needs more info EX: a package name, a path | ||
195 | 129 | def get_info(self, widget, data=None): | ||
196 | 130 | global ROW | ||
197 | 131 | row_int = int(ROW[0][0]) | ||
198 | 132 | |||
199 | 133 | ## Create Dialog object | ||
200 | 134 | dialog = gtk.MessageDialog( | ||
201 | 135 | None, | ||
202 | 136 | gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, | ||
203 | 137 | gtk.MESSAGE_QUESTION, | ||
204 | 138 | gtk.BUTTONS_OK, | ||
205 | 139 | None) | ||
206 | 140 | |||
207 | 141 | # Primary text | ||
208 | 142 | dialog.set_markup(_("This command requires more information")) | ||
209 | 143 | |||
210 | 144 | ## create the text input field | ||
211 | 145 | entry = gtk.Entry() | ||
212 | 146 | ## allow the user to press enter to do ok | ||
213 | 147 | entry.connect("activate", self.responseToDialog, dialog, gtk.RESPONSE_OK) | ||
214 | 148 | |||
215 | 149 | ## create a horizontal box to pack the entry and a label | ||
216 | 150 | hbox = gtk.HBox() | ||
217 | 151 | hbox.pack_start(gtk.Label(self.liststore[row_int][1]+":"), False, 5, 5) | ||
218 | 152 | hbox.pack_end(entry) | ||
219 | 153 | ## some secondary text | ||
220 | 154 | dialog.format_secondary_markup(_("Please provide a "+self.liststore[row_int][1])) | ||
221 | 155 | ## add it and show it | ||
222 | 156 | dialog.vbox.pack_end(hbox, True, True, 0) | ||
223 | 157 | dialog.show_all() | ||
224 | 158 | |||
225 | 159 | ## Show the dialog | ||
226 | 160 | dialog.run() | ||
227 | 161 | |||
228 | 162 | ## user text assigned to a variable | ||
229 | 163 | text = entry.get_text() | ||
230 | 164 | user_input = text.split(' ') | ||
231 | 165 | |||
232 | 166 | ## The destroy method must be called otherwise the 'Close' button will | ||
233 | 167 | ## not work. | ||
234 | 168 | dialog.destroy() | ||
235 | 169 | return user_input | ||
236 | 170 | |||
237 | 171 | def responseToDialog(self, text, dialog, response): | ||
238 | 172 | dialog.response(response) | ||
239 | 173 | |||
240 | 174 | ## Add command dialog box | ||
241 | 175 | def add_command(self, widget): | ||
242 | 176 | |||
243 | 177 | ## Create Dialog object | ||
244 | 178 | dialog = gtk.MessageDialog( | ||
245 | 179 | None, | ||
246 | 180 | gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, | ||
247 | 181 | gtk.MESSAGE_QUESTION, | ||
248 | 182 | gtk.BUTTONS_OK, | ||
249 | 183 | None) | ||
250 | 184 | |||
251 | 185 | ## primaary text | ||
252 | 186 | dialog.set_markup(_("Add a command to your clicompanion dictionary")) | ||
253 | 187 | |||
254 | 188 | #create the text input field | ||
255 | 189 | entry1 = gtk.Entry() | ||
256 | 190 | entry2 = gtk.Entry() | ||
257 | 191 | entry3 = gtk.Entry() | ||
258 | 192 | ## allow the user to press enter to do ok | ||
259 | 193 | entry1.connect("activate", self.responseToDialog, dialog, gtk.RESPONSE_OK) | ||
260 | 194 | entry2.connect("activate", self.responseToDialog, dialog, gtk.RESPONSE_OK) | ||
261 | 195 | entry3.connect("activate", self.responseToDialog, dialog, gtk.RESPONSE_OK) | ||
262 | 196 | |||
263 | 197 | ## create three labels | ||
264 | 198 | hbox1 = gtk.HBox() | ||
265 | 199 | hbox1.pack_start(gtk.Label(_("Command")), False, 5, 5) | ||
266 | 200 | hbox1.pack_start(entry1, False, 5, 5) | ||
267 | 201 | |||
268 | 202 | hbox1.pack_start(gtk.Label(_("User Input")), False, 5, 5) | ||
269 | 203 | hbox1.pack_start(entry2, False, 5, 5) | ||
270 | 204 | |||
271 | 205 | hbox2 = gtk.HBox() | ||
272 | 206 | hbox2.pack_start(gtk.Label(_("Description")), False, 5, 5) | ||
273 | 207 | hbox2.pack_start(entry3, True, 5, 5) | ||
274 | 208 | |||
275 | 209 | ## cancel button | ||
276 | 210 | dialog.add_button('Cancel', gtk.RESPONSE_DELETE_EVENT) | ||
277 | 211 | ## some secondary text | ||
278 | 212 | dialog.format_secondary_markup(_("Please provide a command. Use a @ symbol where user input is required at runtime. Example: ls /any/direstory would be entered as ls @. Also include a brief description.")) | ||
279 | 213 | |||
280 | 214 | ## add it and show it | ||
281 | 215 | dialog.vbox.pack_end(hbox2, True, True, 0) | ||
282 | 216 | dialog.vbox.pack_end(hbox1, True, True, 0) | ||
283 | 217 | dialog.show_all() | ||
284 | 218 | ## Show the dialog | ||
285 | 219 | result = dialog.run() | ||
286 | 220 | |||
287 | 221 | if result == gtk.RESPONSE_OK: | ||
288 | 222 | ## user text assigned to a variable | ||
289 | 223 | text1 = entry1.get_text() | ||
290 | 224 | text2 = entry2.get_text() | ||
291 | 225 | text3 = entry3.get_text() | ||
292 | 226 | ## open flat file that contains the commands and add the new command | ||
293 | 227 | with open(CHEATSHEET, "a") as cheatfile: | ||
294 | 228 | if text1 != "": | ||
295 | 229 | cheatfile.write(text1+" :"+text2+" : "+text3+'\n') | ||
296 | 230 | cheatfile.close() | ||
297 | 231 | l = str(text1+" :"+text2+" : "+text3) | ||
298 | 232 | ls = l.split(':',2) | ||
299 | 233 | CMNDS.append(ls[0]) | ||
300 | 234 | self.liststore.append([ls[0],ls[1],ls[2]]) | ||
301 | 235 | |||
302 | 236 | ## The destroy method must be called otherwise the 'Close' button will | ||
303 | 237 | ## not work. | ||
304 | 238 | dialog.destroy() | ||
305 | 239 | #return text | ||
306 | 240 | |||
307 | 241 | ## This the edit function | ||
308 | 242 | def edit_command(self, widget , data=None): | ||
309 | 243 | |||
310 | 244 | global ROW | ||
311 | 245 | row_int = int(ROW[0][0]) | ||
312 | 246 | |||
313 | 247 | |||
314 | 248 | row_obj1 = self.liststore[row_int][0] | ||
315 | 249 | text1 = "".join(row_obj1) | ||
316 | 250 | |||
317 | 251 | row_obj2 = self.liststore[row_int][1] | ||
318 | 252 | text2 = "".join(row_obj2) | ||
319 | 253 | |||
320 | 254 | row_obj3 = self.liststore[row_int][2] | ||
321 | 255 | text3 = "".join(row_obj3) | ||
322 | 256 | |||
323 | 257 | ## Create Dialog object | ||
324 | 258 | dialog = gtk.MessageDialog( | ||
325 | 259 | None, | ||
326 | 260 | gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, | ||
327 | 261 | gtk.MESSAGE_QUESTION, | ||
328 | 262 | gtk.BUTTONS_OK, | ||
329 | 263 | None) | ||
330 | 264 | |||
331 | 265 | # primary text | ||
332 | 266 | dialog.set_markup(_("Edit the command in your clicompanion dictionary")) | ||
333 | 267 | |||
334 | 268 | ## create the text input fields | ||
335 | 269 | entry1 = gtk.Entry() | ||
336 | 270 | entry1.set_text(text1) | ||
337 | 271 | entry2 = gtk.Entry() | ||
338 | 272 | entry2.set_text(text2) | ||
339 | 273 | entry3 = gtk.Entry() | ||
340 | 274 | entry3.set_text(text3) | ||
341 | 275 | ## allow the user to press enter to do ok | ||
342 | 276 | entry1.connect("activate", self.responseToDialog, dialog, gtk.RESPONSE_OK) | ||
343 | 277 | |||
344 | 278 | ## create three labels | ||
345 | 279 | hbox1 = gtk.HBox() | ||
346 | 280 | hbox1.pack_start(gtk.Label(_("Command")), False, 5, 5) | ||
347 | 281 | hbox1.pack_start(entry1, False, 5, 5) | ||
348 | 282 | |||
349 | 283 | hbox1.pack_start(gtk.Label(_("User Input")), False, 5, 5) | ||
350 | 284 | hbox1.pack_start(entry2, False, 5, 5) | ||
351 | 285 | |||
352 | 286 | hbox2 = gtk.HBox() | ||
353 | 287 | hbox2.pack_start(gtk.Label(_("Description")), False, 5, 5) | ||
354 | 288 | hbox2.pack_start(entry3, True, 5, 5) | ||
355 | 289 | |||
356 | 290 | ## cancel button | ||
357 | 291 | dialog.add_button('Cancel', gtk.RESPONSE_DELETE_EVENT) | ||
358 | 292 | ## some secondary text | ||
359 | 293 | dialog.format_secondary_markup(_("Please provide a command, description, and what type of user variable, if any, is required.")) | ||
360 | 294 | |||
361 | 295 | ## add it and show it | ||
362 | 296 | dialog.vbox.pack_end(hbox2, True, True, 0) | ||
363 | 297 | dialog.vbox.pack_end(hbox1, True, True, 0) | ||
364 | 298 | dialog.show_all() | ||
365 | 299 | ## Show the dialog | ||
366 | 300 | result = dialog.run() | ||
367 | 301 | |||
368 | 302 | if result == gtk.RESPONSE_OK: | ||
369 | 303 | ## user text assigned to a variable | ||
370 | 304 | text1 = entry1.get_text() | ||
371 | 305 | text2 = entry2.get_text() | ||
372 | 306 | text3 = entry3.get_text() | ||
373 | 307 | |||
374 | 308 | if text1 != "": | ||
375 | 309 | self.remove_command(widget) | ||
376 | 310 | ## open flat file, add the new command | ||
377 | 311 | with open(CHEATSHEET, "a") as cheatfile: | ||
378 | 312 | cheatfile.write(text1+":"+text2+":"+text3+'\n') | ||
379 | 313 | cheatfile.close() | ||
380 | 314 | l = str(text1+":"+text2+":"+text3) | ||
381 | 315 | ls = l.split(':',2) | ||
382 | 316 | CMNDS.append(ls[0]) | ||
383 | 317 | self.liststore.append([ls[0],ls[1],ls[2]]) | ||
384 | 318 | |||
385 | 319 | ## The destroy method must be called otherwise the 'Close' button will | ||
386 | 320 | ## not work. | ||
387 | 321 | dialog.destroy() | ||
388 | 322 | |||
389 | 323 | |||
390 | 324 | ## Remove command from command file and GUI | ||
391 | 325 | def remove_command(self, widget, data=None): | ||
392 | 326 | global ROW | ||
393 | 327 | row_int = int(ROW[0][0]) #convert pathlist into something usable | ||
394 | 328 | |||
395 | 329 | del CMNDS[row_int] | ||
396 | 330 | del self.liststore[row_int] | ||
397 | 331 | |||
398 | 332 | |||
399 | 333 | ## open command file and delete line so the change is persistent | ||
400 | 334 | with open(CHEATSHEET, "r") as cheatfile: | ||
401 | 335 | cheatlines = cheatfile.readlines() | ||
402 | 336 | del cheatlines[row_int] | ||
403 | 337 | cheatfile.close() | ||
404 | 338 | with open(CHEATSHEET, "w") as cheatfile2: | ||
405 | 339 | cheatfile2.writelines(cheatlines) | ||
406 | 340 | cheatfile2.close() | ||
407 | 341 | |||
408 | 342 | |||
409 | 343 | def _filter_commands(self, widget, data=None): | ||
410 | 344 | """ | ||
411 | 345 | Show commands matching a given search term. | ||
412 | 346 | The user should enter a term in the search box and the treeview should | ||
413 | 347 | only display the rows which contain the search term. | ||
414 | 348 | Pretty straight-forward. | ||
415 | 349 | """ | ||
416 | 350 | search_term = self.search_box.get_text() | ||
417 | 351 | |||
418 | 352 | ## Create a TreeModelFilter object which provides auxiliary functions for | ||
419 | 353 | ## filtering data. | ||
420 | 354 | ## http://www.pygtk.org/pygtk2tutorial/sec-TreeModelSortAndTreeModelFilter.html | ||
421 | 355 | modelfilter = self.liststore.filter_new() | ||
422 | 356 | def search(modelfilter, iter, search_term): | ||
423 | 357 | try: | ||
424 | 358 | ## Iterate through every column and row and check if the search | ||
425 | 359 | ## term is there: | ||
426 | 360 | if search_term in modelfilter.get_value(iter, 0) or \ | ||
427 | 361 | search_term in modelfilter.get_value(iter, 1) or \ | ||
428 | 362 | search_term in modelfilter.get_value(iter, 2): | ||
429 | 363 | return True | ||
430 | 364 | except TypeError: | ||
431 | 365 | ## Python raises a TypeError if row data doesn't exist. Catch | ||
432 | 366 | ## that and fail silently. | ||
433 | 367 | pass | ||
434 | 368 | |||
435 | 369 | modelfilter.set_visible_func(search, search_term) | ||
436 | 370 | self.treeview.set_model(modelfilter) | ||
437 | 371 | |||
438 | 372 | ## send the command to the terminal | ||
439 | 373 | def run_command(self, widget, data=None): | ||
440 | 374 | global ROW | ||
441 | 375 | text = "" | ||
442 | 376 | row_int = int(ROW[0][0]) ## removes everything but number from [5,] | ||
443 | 377 | |||
444 | 378 | ## get the current notebook page so the function knows which terminal to run the command in. | ||
445 | 379 | pagenum = self.notebook.get_current_page() | ||
446 | 380 | widget = self.notebook.get_nth_page(pagenum) | ||
447 | 381 | page_widget = widget.get_child() | ||
448 | 382 | |||
449 | 383 | ## CMNDS is where commands are stored | ||
450 | 384 | cmnd = CMNDS[row_int] | ||
451 | 385 | ## find how many @(user arguments) are in command | ||
452 | 386 | match = re.findall('@', cmnd) | ||
453 | 387 | ''' | ||
454 | 388 | Make sure user arguments were found. Replace @ with something | ||
455 | 389 | .format can read. This is done so the user can just enter @, when | ||
456 | 390 | adding a command where arguments are needed, instead | ||
457 | 391 | of {0[1]}, {0[1]}, {0[2]} | ||
458 | 392 | ''' | ||
459 | 393 | if match == False: | ||
460 | 394 | pass | ||
461 | 395 | else: | ||
462 | 396 | num = len(match) | ||
463 | 397 | ran = 0 | ||
464 | 398 | new_cmnd = self.replace(cmnd, num, ran) | ||
465 | 399 | |||
466 | 400 | if not self.liststore[row_int][1] == " ": # command with user input | ||
467 | 401 | text = Companion.get_info(self, text) | ||
468 | 402 | c = new_cmnd.format(text) | ||
469 | 403 | page_widget.feed_child(c+"\n") #send command w/ input | ||
470 | 404 | page_widget.show() | ||
471 | 405 | else: ## command that has no user input | ||
472 | 406 | page_widget.feed_child(cmnd+"\n") #send command | ||
473 | 407 | page_widget.show() | ||
474 | 408 | page_widget.grab_focus() | ||
475 | 409 | |||
476 | 410 | ## replace @ with {0[n]} | ||
477 | 411 | def replace(self, cmnd, num, ran): | ||
478 | 412 | replace_cmnd=re.sub('@', '{0['+str(ran)+']}', cmnd, count=1) | ||
479 | 413 | cmnd = replace_cmnd | ||
480 | 414 | ran += 1 | ||
481 | 415 | if ran < num: | ||
482 | 416 | return self.replace(cmnd, num, ran) | ||
483 | 417 | else: | ||
484 | 418 | pass | ||
485 | 419 | return cmnd | ||
486 | 420 | |||
487 | 421 | ## open the man page for selected command | ||
488 | 422 | def man_page(self, widget, data=None): | ||
489 | 423 | row_int = int(ROW[0][0]) # removes everything but number from EX: [5,] | ||
490 | 424 | cmnd = CMNDS[row_int] #CMNDS is where commands are store | ||
491 | 425 | splitcommand = self._filter_sudo_from(cmnd.split(" ")) | ||
492 | 426 | ## get current notebook tab to use in function | ||
493 | 427 | pagenum = self.notebook.get_current_page() | ||
494 | 428 | widget = self.notebook.get_nth_page(pagenum) | ||
495 | 429 | page_widget = widget.get_child() | ||
496 | 430 | #send command to Terminal | ||
497 | 431 | page_widget.feed_child("man "+splitcommand[0]+"| most \n") | ||
498 | 432 | page_widget.grab_focus() | ||
499 | 433 | page_widget.show() | ||
500 | 434 | |||
501 | 435 | |||
502 | 436 | @staticmethod | ||
503 | 437 | def _filter_sudo_from(command): | ||
504 | 438 | """Filter the sudo from `command`, where `command` is a list. | ||
505 | 439 | Return the command list with the "sudo" filtered out. | ||
506 | 440 | """ | ||
507 | 441 | if command[0].startswith("sudo"): | ||
508 | 442 | del command[0] | ||
509 | 443 | return command | ||
510 | 444 | return command | ||
511 | 445 | |||
512 | 446 | |||
513 | 447 | ## open file containing command dictionary and put it in a variable | ||
514 | 448 | def update(self): | ||
515 | 449 | try: | ||
516 | 450 | with open(CHEATSHEET, "r") as cheatfile: | ||
517 | 451 | bugdata=cheatfile.read() | ||
518 | 452 | cheatfile.close() | ||
519 | 453 | except IOError: | ||
520 | 454 | ## CHEATSHEET is not there. Oh, no! | ||
521 | 455 | ## So, run self.setup() again. | ||
522 | 456 | self.setup() | ||
523 | 457 | ## Then, run me again. | ||
524 | 458 | self.update() | ||
525 | 459 | |||
526 | 460 | global CMNDS | ||
527 | 461 | ## add bug data from .clicompanion to the liststore | ||
528 | 462 | CMNDS = [] | ||
529 | 463 | for line in bugdata.splitlines(): | ||
530 | 464 | l = line.split(':',2) | ||
531 | 465 | CMNDS.append(l[0]) | ||
532 | 466 | self.liststore.append([l[0],l[1],l[2]]) | ||
533 | 467 | |||
534 | 468 | |||
535 | 469 | |||
536 | 470 | ## add a new terminal in a tab above the current terminal | ||
537 | 471 | def add_tab(self, data=None): | ||
538 | 472 | |||
539 | 473 | _vte = vte.Terminal() | ||
540 | 474 | _vte.set_size_request(700, 220) | ||
541 | 475 | _vte.connect ("child-exited", lambda term: gtk.main_quit()) | ||
542 | 476 | _vte.fork_command(get_user_shell()) # Get the user's default shell | ||
543 | 477 | |||
544 | 478 | vte_tab = gtk.ScrolledWindow() | ||
545 | 479 | vte_tab.add(_vte) | ||
546 | 480 | #self.notebook.set_show_tabs(True) | ||
547 | 481 | #self.notebook.set_show_border(True) | ||
548 | 482 | |||
549 | 483 | gcp = self.notebook.get_current_page() +1 | ||
550 | 484 | pagenum = ('Tab %d') % gcp | ||
551 | 485 | |||
552 | 486 | box = gtk.HBox() | ||
553 | 487 | label = gtk.Label(pagenum) | ||
554 | 488 | box.pack_start(label, True, True) | ||
555 | 489 | |||
556 | 490 | ## x image for tab close button | ||
557 | 491 | close_image = gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU) | ||
558 | 492 | ## close button | ||
559 | 493 | closebtn = gtk.Button() | ||
560 | 494 | closebtn.set_relief(gtk.RELIEF_NONE) | ||
561 | 495 | closebtn.set_focus_on_click(True) | ||
562 | 496 | |||
563 | 497 | closebtn.add(close_image) | ||
564 | 498 | ## put button in a box and show box | ||
565 | 499 | box.pack_end(closebtn, False, False) | ||
566 | 500 | box.show_all() | ||
567 | 501 | |||
568 | 502 | self.notebook.prepend_page(vte_tab, box) # add tab | ||
569 | 503 | self.notebook.set_scrollable(True) | ||
570 | 504 | _vte.connect ("button_press_event", self.copy_paste, None) | ||
571 | 505 | vte_tab.grab_focus() | ||
572 | 506 | # signal handler for tab | ||
573 | 507 | closebtn.connect("clicked", self.close_tab, vte_tab) | ||
574 | 508 | self.window.show_all() | ||
575 | 509 | |||
576 | 510 | return vte_tab | ||
577 | 511 | |||
578 | 512 | |||
579 | 513 | ## Remove a page from the notebook | ||
580 | 514 | def close_tab(self, sender, widget): | ||
581 | 515 | ## get the page number of the tab we wanted to close | ||
582 | 516 | pagenum = self.notebook.page_num(widget) | ||
583 | 517 | ## and close it | ||
584 | 518 | self.notebook.remove_page(pagenum) | ||
585 | 519 | |||
586 | 520 | #TODO: Move to menus_buttons | ||
587 | 521 | def copy_paste(self, vte, event, data=None): | ||
588 | 522 | if event.button == 3: | ||
589 | 523 | |||
590 | 524 | time = event.time | ||
591 | 525 | ## right-click popup menu Copy | ||
592 | 526 | popupMenu = gtk.Menu() | ||
593 | 527 | menuPopup1 = gtk.ImageMenuItem (gtk.STOCK_COPY) | ||
594 | 528 | popupMenu.add(menuPopup1) | ||
595 | 529 | menuPopup1.connect('activate', lambda x: vte.copy_clipboard()) | ||
596 | 530 | ## right-click popup menu Paste | ||
597 | 531 | menuPopup2 = gtk.ImageMenuItem (gtk.STOCK_PASTE) | ||
598 | 532 | popupMenu.add(menuPopup2) | ||
599 | 533 | menuPopup2.connect('activate', lambda x: vte.paste_clipboard()) | ||
600 | 534 | |||
601 | 535 | ## Show popup menu | ||
602 | 536 | popupMenu.show_all() | ||
603 | 537 | popupMenu.popup( None, None, None, event.button, time) | ||
604 | 538 | return True | ||
605 | 539 | else: | ||
606 | 540 | pass | ||
607 | 541 | |||
608 | 542 | def about_event(self): | ||
609 | 543 | pass | ||
610 | 544 | def help_event(self): | ||
611 | 545 | pass | ||
612 | 546 | |||
613 | 547 | #liststore in a scrolled window in an expander | ||
614 | 548 | def expanded_cb(self, expander, params): | ||
615 | 549 | if expander.get_expanded(): | ||
616 | 550 | |||
617 | 551 | self.update() | ||
618 | 552 | ## create the TreeView | ||
619 | 553 | self.treeview = gtk.TreeView() | ||
620 | 554 | ## create window with scrollbar | ||
621 | 555 | self.scrolledwindow = gtk.ScrolledWindow() | ||
622 | 556 | self.scrolledwindow.set_size_request(700, 220) | ||
623 | 557 | |||
624 | 558 | ## create the TreeViewColumns to display the data | ||
625 | 559 | self.treeview.columns = [None]*3 | ||
626 | 560 | self.treeview.columns[0] = gtk.TreeViewColumn(_('Command')) | ||
627 | 561 | self.treeview.columns[1] = gtk.TreeViewColumn(_('User Argument')) | ||
628 | 562 | self.treeview.columns[2] = gtk.TreeViewColumn(_('Description')) | ||
629 | 563 | |||
630 | 564 | ## right click menu event capture | ||
631 | 565 | bar = clicompanion.menus_buttons.FileMenu() | ||
632 | 566 | self.treeview.connect ("button_press_event", bar.right_click, self) | ||
633 | 567 | |||
634 | 568 | for n in range(3): | ||
635 | 569 | ## add columns to treeview | ||
636 | 570 | self.treeview.append_column(self.treeview.columns[n]) | ||
637 | 571 | ## create a CellRenderers to render the data | ||
638 | 572 | self.treeview.columns[n].cell = gtk.CellRendererText() | ||
639 | 573 | ## add the cells to the columns | ||
640 | 574 | self.treeview.columns[n].pack_start(self.treeview.columns[n].cell, | ||
641 | 575 | True) | ||
642 | 576 | ## set the cell attributes to the appropriate liststore column | ||
643 | 577 | self.treeview.columns[n].set_attributes( | ||
644 | 578 | self.treeview.columns[n].cell, text=n) | ||
645 | 579 | self.treeview.columns[n].set_resizable(True) | ||
646 | 580 | |||
647 | 581 | ## The set_model() method sets the "model" property for the treeview to the value of model. model : the new tree model to use with the treeview | ||
648 | 582 | self.treeview.set_model(self.liststore) | ||
649 | 583 | self.scrolledwindow.add(self.treeview) | ||
650 | 584 | expander.add(self.scrolledwindow) | ||
651 | 585 | |||
652 | 586 | self.window.show_all() | ||
653 | 587 | |||
654 | 588 | self.treeview.get_selection().set_mode(gtk.SELECTION_SINGLE) | ||
655 | 589 | self.treeview.get_selection().connect('changed',lambda s: mark_selected(s)) | ||
656 | 590 | |||
657 | 591 | def mark_selected(treeselection): | ||
658 | 592 | (model,pathlist)=treeselection.get_selected_rows() | ||
659 | 593 | global ROW | ||
660 | 594 | ROW = pathlist | ||
661 | 595 | |||
662 | 596 | # Activate the search box when not expanded | ||
663 | 597 | self.search_box.set_sensitive(True) | ||
664 | 598 | else: | ||
665 | 599 | # De-activate the search box when not expanded | ||
666 | 600 | self.search_box.set_sensitive(False) | ||
667 | 601 | |||
668 | 602 | expander.remove(expander.child) | ||
669 | 603 | ##reset the size of the window to its original one | ||
670 | 604 | self.window.resize(1, 1) | ||
671 | 605 | return | ||
672 | 606 | |||
673 | 607 | |||
674 | 608 | def __init__(self): | ||
675 | 609 | ##For now TERM is hardcoded to xterm because of a change | ||
676 | 610 | ##in libvte in Ubuntu Maverick | ||
677 | 611 | os.putenv('TERM', 'xterm') | ||
678 | 612 | ## copy config file to user $HOME if does not exist | ||
679 | 613 | self.setup() | ||
680 | 614 | #TODO: do we want to do this? Or just keep the height under 600. | ||
681 | 615 | ##Get user screen size## | ||
682 | 616 | #screen = gtk.gdk.display_get_default().get_default_screen() | ||
683 | 617 | #screen_size = screen.get_monitor_geometry(0) | ||
684 | 618 | #height = screen.get_height() ## screen height ## | ||
685 | 619 | ## Create a new window | ||
686 | 620 | self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) | ||
687 | 621 | ## create a liststore with three string columns | ||
688 | 622 | self.liststore = gtk.ListStore(str, str, str) | ||
689 | 623 | ## Create an expander | ||
690 | 624 | expander = gtk.Expander() | ||
691 | 625 | ## Create Notebook | ||
692 | 626 | self.notebook = gtk.Notebook() | ||
693 | 627 | ## set Window title | ||
694 | 628 | self.window.set_title("CLI Companion") | ||
695 | 629 | ## Adding icon | ||
696 | 630 | icon = gtk.gdk.pixbuf_new_from_file("/usr/share/pixmaps/clicompanion.16.png") | ||
697 | 631 | self.window.set_icon(icon) | ||
698 | 632 | ## Sets the border width of the window. | ||
699 | 633 | self.window.set_border_width(10) | ||
700 | 634 | ## set the size of the window | ||
701 | 635 | self.window.set_default_size(700, 400) | ||
702 | 636 | ## Sets the position of the window relative to the screen | ||
703 | 637 | self.window.set_position(gtk.WIN_POS_CENTER) | ||
704 | 638 | ## Allow user to resize window | ||
705 | 639 | self.window.set_resizable(True) | ||
706 | 640 | |||
707 | 641 | self.window.connect("delete_event", self.delete_event) | ||
708 | 642 | |||
709 | 643 | ## 'File' and 'Help' Drop Down Menu [menus_buttons.py] | ||
710 | 644 | bar = clicompanion.menus_buttons.FileMenu() | ||
711 | 645 | menu_bar = bar.the_menu(self) | ||
712 | 646 | ## The search section | ||
713 | 647 | self.search_label = gtk.Label(_("Search:")) | ||
714 | 648 | self.search_label.set_alignment(xalign=-1, yalign=0) | ||
715 | 649 | self.search_box = gtk.Entry() | ||
716 | 650 | self.search_box.connect("changed", self._filter_commands) | ||
717 | 651 | ## search box tooltip | ||
718 | 652 | self.search_box.set_tooltip_text("Search your list of commands") | ||
719 | 653 | # Set the search box sensitive at program start, because expander is not | ||
720 | 654 | # unfolded by default | ||
721 | 655 | self.search_box.set_sensitive(False) | ||
722 | 656 | ## hbox for menu and search Entry | ||
723 | 657 | menu_search_hbox = gtk.HBox(False) | ||
724 | 658 | menu_search_hbox.pack_end(self.search_box, True) | ||
725 | 659 | menu_search_hbox.pack_end(self.search_label, False, False, 10) | ||
726 | 660 | menu_search_hbox.pack_start(menu_bar, True) | ||
727 | 661 | |||
728 | 662 | ## TODO Do we want to start with the command list open or closed? | ||
729 | 663 | ## This code opens the app with it open | ||
730 | 664 | ## We would also need to change the search field disable code | ||
731 | 665 | ## start program with expander open | ||
732 | 666 | #expander.set_expanded(True) | ||
733 | 667 | #self.expanded_cb(expander, None) | ||
734 | 668 | |||
735 | 669 | ## expander signal | ||
736 | 670 | expander.connect('notify::expanded', self.expanded_cb) | ||
737 | 671 | |||
738 | 672 | ## expander title | ||
739 | 673 | expander_hbox = gtk.HBox() | ||
740 | 674 | image = gtk.Image() | ||
741 | 675 | image.set_from_stock(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON) | ||
742 | 676 | label = gtk.Label(' Command List') | ||
743 | 677 | ## tooltip for the label of the expander | ||
744 | 678 | expander_hbox.set_tooltip_text("Click to show/hide command list") | ||
745 | 679 | |||
746 | 680 | ## add expander widget to hbox | ||
747 | 681 | expander_hbox.pack_start(image, False, False) | ||
748 | 682 | expander_hbox.pack_start(label, True, False) | ||
749 | 683 | expander.set_label_widget(expander_hbox) | ||
750 | 684 | |||
751 | 685 | ## Add the first tab with the Terminal | ||
752 | 686 | self.add_tab() | ||
753 | 687 | self.notebook.set_tab_pos(1) | ||
754 | 688 | |||
755 | 689 | ## The "Add Tab" tab | ||
756 | 690 | add_tab_button = gtk.Button("+") | ||
757 | 691 | ## tooltip for "Add Tab" tab | ||
758 | 692 | add_tab_button.set_tooltip_text("Click to add another Tab") | ||
759 | 693 | add_tab_button.connect("clicked", self.add_tab) | ||
760 | 694 | self.notebook.append_page(gtk.Label(""), add_tab_button) | ||
761 | 695 | |||
762 | 696 | ## buttons at bottom of main window [menus_buttons.py] | ||
763 | 697 | button_box = bar.buttons(self, 10, gtk.BUTTONBOX_END) | ||
764 | 698 | |||
765 | 699 | ## vbox for search, notebook, buttonbar | ||
766 | 700 | self.vbox = gtk.VBox() | ||
767 | 701 | self.window.add(self.vbox) | ||
768 | 702 | ## pack everytyhing in the vbox | ||
769 | 703 | #self.vbox.pack_start(menu_bar, False, False, 0) ##menuBar | ||
770 | 704 | self.vbox.pack_start(menu_search_hbox, False, False, 5) | ||
771 | 705 | self.vbox.pack_start(expander, False, False, 5) | ||
772 | 706 | self.vbox.pack_start(self.notebook, True, True, 10) | ||
773 | 707 | self.vbox.pack_start(button_box, False, False, 5) | ||
774 | 708 | |||
775 | 709 | |||
776 | 710 | #self.vte.grab_focus() | ||
777 | 711 | self.window.show_all() | ||
778 | 712 | return | ||
779 | 713 | |||
780 | 714 | def main(): | ||
781 | 715 | try: | ||
782 | 716 | gtk.main() | ||
783 | 717 | except KeyboardInterrupt: | ||
784 | 718 | pass | ||
785 | 719 | |||
786 | 720 | if __name__ == "__main__": | ||
787 | 721 | companion = Companion() | ||
788 | 722 | main() | ||
789 | 723 | |||
790 | 724 | 0 | ||
791 | === removed file 'clicompanion/__init__.py' | |||
792 | --- clicompanion/__init__.py 2010-10-06 06:54:47 +0000 | |||
793 | +++ clicompanion/__init__.py 1970-01-01 00:00:00 +0000 | |||
794 | @@ -1,23 +0,0 @@ | |||
795 | 1 | #!/usr/bin/env python | ||
796 | 2 | # -*- coding: utf-8 -*- | ||
797 | 3 | # | ||
798 | 4 | # clicompanion.py - commandline tool. | ||
799 | 5 | # | ||
800 | 6 | # Copyright 2010 Duane Hinnen, Kenny Meyer | ||
801 | 7 | # | ||
802 | 8 | # This program is free software: you can redistribute it and/or modify it | ||
803 | 9 | # under the terms of the GNU General Public License version 3, as published | ||
804 | 10 | # by the Free Software Foundation. | ||
805 | 11 | # | ||
806 | 12 | # This program is distributed in the hope that it will be useful, but | ||
807 | 13 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
808 | 14 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
809 | 15 | # PURPOSE. See the GNU General Public License for more details. | ||
810 | 16 | # | ||
811 | 17 | # You should have received a copy of the GNU General Public License along | ||
812 | 18 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
813 | 19 | # | ||
814 | 20 | # | ||
815 | 21 | ''' | ||
816 | 22 | blah, blah, blah | ||
817 | 23 | ''' | ||
818 | 24 | 0 | ||
819 | === removed file 'clicompanion/menus_buttons.py' | |||
820 | --- clicompanion/menus_buttons.py 2010-10-06 06:54:47 +0000 | |||
821 | +++ clicompanion/menus_buttons.py 1970-01-01 00:00:00 +0000 | |||
822 | @@ -1,157 +0,0 @@ | |||
823 | 1 | #!/usr/bin/env python | ||
824 | 2 | # -*- coding: utf-8 -*- | ||
825 | 3 | # | ||
826 | 4 | # Copyright 2010 Duane Hinnen, Kenny Meyer, Marcos Vanetta | ||
827 | 5 | # | ||
828 | 6 | # This file contains the menus, buttons, and right clicks | ||
829 | 7 | # | ||
830 | 8 | #import clicompanion | ||
831 | 9 | import gtk | ||
832 | 10 | |||
833 | 11 | class FileMenu(object): | ||
834 | 12 | def the_menu(self, cli): | ||
835 | 13 | menu = gtk.Menu() | ||
836 | 14 | root_menu = gtk.MenuItem(_("File")) | ||
837 | 15 | root_menu.set_submenu(menu) | ||
838 | 16 | |||
839 | 17 | menu2 = gtk.Menu() | ||
840 | 18 | root_menu2 = gtk.MenuItem(_("Help")) | ||
841 | 19 | root_menu2.set_submenu(menu2) | ||
842 | 20 | |||
843 | 21 | ##FILE MENU ## | ||
844 | 22 | ## Make 'Run' menu entry | ||
845 | 23 | menu_item1 = gtk.MenuItem(_("Run Command")) | ||
846 | 24 | menu.append(menu_item1) | ||
847 | 25 | menu_item1.connect("activate", cli.run_command) | ||
848 | 26 | menu_item1.show() | ||
849 | 27 | |||
850 | 28 | ## Make 'Add' file menu entry | ||
851 | 29 | menu_item2 = gtk.MenuItem(_("Add Command")) | ||
852 | 30 | menu.append(menu_item2) | ||
853 | 31 | menu_item2.connect("activate", cli.add_command) | ||
854 | 32 | menu_item2.show() | ||
855 | 33 | |||
856 | 34 | ## Make 'Remove' file menu entry | ||
857 | 35 | menu_item2 = gtk.MenuItem(_("Remove Command")) | ||
858 | 36 | menu.append(menu_item2) | ||
859 | 37 | menu_item2.connect("activate", cli.remove_command) | ||
860 | 38 | menu_item2.show() | ||
861 | 39 | |||
862 | 40 | ## Make 'Quit' file menu entry | ||
863 | 41 | menu_item3 = gtk.MenuItem(_("Quit")) | ||
864 | 42 | menu.append(menu_item3) | ||
865 | 43 | menu_item3.connect("activate", cli.delete_event) | ||
866 | 44 | menu_item3.show() | ||
867 | 45 | |||
868 | 46 | |||
869 | 47 | ## Make 'Add Tab' file menu entry | ||
870 | 48 | menu_item4 = gtk.MenuItem(_("Add Tab")) | ||
871 | 49 | menu.append(menu_item4) | ||
872 | 50 | menu_item4.connect("activate", cli.add_tab) | ||
873 | 51 | menu_item4.show() | ||
874 | 52 | |||
875 | 53 | |||
876 | 54 | ## HELP MENU ## | ||
877 | 55 | ## Make 'About' file menu entry | ||
878 | 56 | menu_item11 = gtk.MenuItem(_("About")) | ||
879 | 57 | menu2.append(menu_item11) | ||
880 | 58 | menu_item11.connect("activate", cli.about_event) | ||
881 | 59 | menu_item11.show() | ||
882 | 60 | |||
883 | 61 | |||
884 | 62 | ## Make 'Help' file menu entry | ||
885 | 63 | menu_item22 = gtk.MenuItem(_("Help")) | ||
886 | 64 | menu2.append(menu_item22) | ||
887 | 65 | menu_item22.connect("activate", cli.help_event) | ||
888 | 66 | menu_item22.show() | ||
889 | 67 | |||
890 | 68 | |||
891 | 69 | menu_bar = gtk.MenuBar() | ||
892 | 70 | |||
893 | 71 | menu_bar.append (root_menu) ##Menu bar(file) | ||
894 | 72 | menu_bar.append (root_menu2) ##Menu bar(help) | ||
895 | 73 | #menu_bar.show() ##show File Menu # Menu Bar | ||
896 | 74 | ##Show 'File' Menu | ||
897 | 75 | #root_menu.show() | ||
898 | 76 | return menu_bar | ||
899 | 77 | |||
900 | 78 | |||
901 | 79 | |||
902 | 80 | def buttons(self, cli, spacing, layout): | ||
903 | 81 | #button box at bottom of main window | ||
904 | 82 | frame = gtk.Frame() | ||
905 | 83 | bbox = gtk.HButtonBox() | ||
906 | 84 | bbox.set_border_width(5) | ||
907 | 85 | frame.add(bbox) | ||
908 | 86 | |||
909 | 87 | # Set the appearance of the Button Box | ||
910 | 88 | bbox.set_layout(layout) | ||
911 | 89 | bbox.set_spacing(spacing) | ||
912 | 90 | # Run button | ||
913 | 91 | buttonRun = gtk.Button(_("Run")) | ||
914 | 92 | bbox.add(buttonRun) | ||
915 | 93 | buttonRun.connect("clicked", cli.run_command) | ||
916 | 94 | buttonRun.set_tooltip_text("Click to run a highlighted command") | ||
917 | 95 | # Add button | ||
918 | 96 | buttonAdd = gtk.Button(stock=gtk.STOCK_ADD) | ||
919 | 97 | bbox.add(buttonAdd) | ||
920 | 98 | buttonAdd.connect("clicked", cli.add_command) | ||
921 | 99 | buttonAdd.set_tooltip_text("Click to add a command to your command list") | ||
922 | 100 | # Edit button | ||
923 | 101 | buttonEdit = gtk.Button("Edit") | ||
924 | 102 | bbox.add(buttonEdit) | ||
925 | 103 | buttonEdit.connect("clicked", cli.edit_command) | ||
926 | 104 | buttonEdit.set_tooltip_text("Click to edit a command in your command list") | ||
927 | 105 | # Delete button | ||
928 | 106 | buttonDelete = gtk.Button(stock=gtk.STOCK_DELETE) | ||
929 | 107 | bbox.add(buttonDelete) | ||
930 | 108 | buttonDelete.connect("clicked", cli.remove_command) | ||
931 | 109 | buttonDelete.set_tooltip_text("Click to delete a command in your command list") | ||
932 | 110 | #Help Button | ||
933 | 111 | buttonHelp = gtk.Button(stock=gtk.STOCK_HELP) | ||
934 | 112 | bbox.add(buttonHelp) | ||
935 | 113 | buttonHelp.connect("clicked", cli.man_page) | ||
936 | 114 | buttonHelp.set_tooltip_text("Click to get help with a command in your command list") | ||
937 | 115 | # Cancel button | ||
938 | 116 | buttonCancel = gtk.Button(stock=gtk.STOCK_QUIT) | ||
939 | 117 | bbox.add(buttonCancel) | ||
940 | 118 | buttonCancel.connect("clicked", cli.delete_event) | ||
941 | 119 | buttonCancel.set_tooltip_text("Click to quit CLI Companion") | ||
942 | 120 | |||
943 | 121 | return frame | ||
944 | 122 | |||
945 | 123 | |||
946 | 124 | #right-click popup menu for the Liststore(command list) | ||
947 | 125 | def right_click(self, treeview, event, cli): | ||
948 | 126 | if event.button == 3: | ||
949 | 127 | x = int(event.x) | ||
950 | 128 | y = int(event.y) | ||
951 | 129 | time = event.time | ||
952 | 130 | pthinfo = treeview.get_path_at_pos(x, y) | ||
953 | 131 | if pthinfo is not None: | ||
954 | 132 | path, col, cellx, celly = pthinfo | ||
955 | 133 | treeview.grab_focus() | ||
956 | 134 | treeview.set_cursor( path, col, 0) | ||
957 | 135 | |||
958 | 136 | # right-click popup menu Apply(run) | ||
959 | 137 | popupMenu = gtk.Menu() | ||
960 | 138 | menuPopup1 = gtk.ImageMenuItem (gtk.STOCK_APPLY) | ||
961 | 139 | popupMenu.add(menuPopup1) | ||
962 | 140 | menuPopup1.connect("activate", cli.run_command) | ||
963 | 141 | # right-click popup menu Edit | ||
964 | 142 | menuPopup2 = gtk.ImageMenuItem (gtk.STOCK_EDIT) | ||
965 | 143 | popupMenu.add(menuPopup2) | ||
966 | 144 | menuPopup2.connect("activate", cli.edit_command) | ||
967 | 145 | # right-click popup menu Delete | ||
968 | 146 | menuPopup3 = gtk.ImageMenuItem (gtk.STOCK_DELETE) | ||
969 | 147 | popupMenu.add(menuPopup3) | ||
970 | 148 | menuPopup3.connect("activate", cli.remove_command) | ||
971 | 149 | # right-click popup menu Help | ||
972 | 150 | menuPopup4 = gtk.ImageMenuItem (gtk.STOCK_HELP) | ||
973 | 151 | popupMenu.add(menuPopup4) | ||
974 | 152 | menuPopup4.connect("activate", cli.man_page) | ||
975 | 153 | # Show popup menu | ||
976 | 154 | popupMenu.show_all() | ||
977 | 155 | popupMenu.popup( None, None, None, event.button, time) | ||
978 | 156 | return True | ||
979 | 157 | |||
980 | 158 | 0 | ||
981 | === removed file 'clicompanion/utils.py' | |||
982 | --- clicompanion/utils.py 2010-10-06 06:54:47 +0000 | |||
983 | +++ clicompanion/utils.py 1970-01-01 00:00:00 +0000 | |||
984 | @@ -1,66 +0,0 @@ | |||
985 | 1 | # -*- mode: python; coding: utf-8; -*- | ||
986 | 2 | # | ||
987 | 3 | # clicompanion.py - commandline tool. | ||
988 | 4 | # | ||
989 | 5 | # Copyright 2010 Duane Hinnen, Kenny Meyer, Marcos Vanetta | ||
990 | 6 | # | ||
991 | 7 | # This program is free software: you can redistribute it and/or modify it | ||
992 | 8 | # under the terms of the GNU General Public License version 3, as published | ||
993 | 9 | # by the Free Software Foundation. | ||
994 | 10 | # | ||
995 | 11 | # This program is distributed in the hope that it will be useful, but | ||
996 | 12 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
997 | 13 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
998 | 14 | # PURPOSE. See the GNU General Public License for more details. | ||
999 | 15 | # | ||
1000 | 16 | # You should have received a copy of the GNU General Public License along | ||
1001 | 17 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1002 | 18 | # | ||
1003 | 19 | # | ||
1004 | 20 | |||
1005 | 21 | """ | ||
1006 | 22 | A collection of useful functions. | ||
1007 | 23 | """ | ||
1008 | 24 | |||
1009 | 25 | import getpass | ||
1010 | 26 | import hashlib | ||
1011 | 27 | import os | ||
1012 | 28 | |||
1013 | 29 | CHEATSHEET = os.path.expanduser("~/.clicompanion") | ||
1014 | 30 | CONFIG_ORIG = "/etc/clicompanion.d/clicompanion.config" | ||
1015 | 31 | |||
1016 | 32 | def get_user_shell(): | ||
1017 | 33 | """Get the user's shell defined in /etc/passwd .""" | ||
1018 | 34 | data = None | ||
1019 | 35 | try: | ||
1020 | 36 | # Read out the data in /etc/passwd | ||
1021 | 37 | with open('/etc/passwd') as f: | ||
1022 | 38 | data = f.readlines() | ||
1023 | 39 | except e: | ||
1024 | 40 | print "Something unexpected happened!" | ||
1025 | 41 | raise e | ||
1026 | 42 | |||
1027 | 43 | for i in data: | ||
1028 | 44 | tmp = i.split(":") | ||
1029 | 45 | # Check for the entry of the currently logged in user | ||
1030 | 46 | if tmp[0] == getpass.getuser(): | ||
1031 | 47 | # Columns are separated by colons, so split each column. | ||
1032 | 48 | # Sample /etc/passwd entry for a user: | ||
1033 | 49 | # | ||
1034 | 50 | # jorge:x:1001:1002:,,,:/home/jorge:/bin/bash | ||
1035 | 51 | # | ||
1036 | 52 | # The last column is relevant for us. | ||
1037 | 53 | # Don't forget to strip the newline at the end of the string! | ||
1038 | 54 | return i.split(":")[-1:][0].strip('\n') | ||
1039 | 55 | |||
1040 | 56 | |||
1041 | 57 | def sumfile(): | ||
1042 | 58 | '''Returns an md5 hash for an object with read() method.''' | ||
1043 | 59 | m = hashlib.md5() | ||
1044 | 60 | with open(CHEATSHEET, 'rb') as cheatsheet: | ||
1045 | 61 | d = cheatsheet.read() | ||
1046 | 62 | m.update(d) | ||
1047 | 63 | pp = m.hexdigest() | ||
1048 | 64 | print pp | ||
1049 | 65 | return m.hexdigest() | ||
1050 | 66 | |||
1051 | 67 | 0 | ||
1052 | === added directory 'clicompanionlib' | |||
1053 | === added file 'clicompanionlib/__init__.py' | |||
1054 | --- clicompanionlib/__init__.py 1970-01-01 00:00:00 +0000 | |||
1055 | +++ clicompanionlib/__init__.py 2010-11-30 16:11:27 +0000 | |||
1056 | @@ -0,0 +1,23 @@ | |||
1057 | 1 | #!/usr/bin/env python | ||
1058 | 2 | # -*- coding: utf-8 -*- | ||
1059 | 3 | # | ||
1060 | 4 | # clicompanion.py - commandline tool. | ||
1061 | 5 | # | ||
1062 | 6 | # Copyright 2010 Duane Hinnen, Kenny Meyer | ||
1063 | 7 | # | ||
1064 | 8 | # This program is free software: you can redistribute it and/or modify it | ||
1065 | 9 | # under the terms of the GNU General Public License version 3, as published | ||
1066 | 10 | # by the Free Software Foundation. | ||
1067 | 11 | # | ||
1068 | 12 | # This program is distributed in the hope that it will be useful, but | ||
1069 | 13 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1070 | 14 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1071 | 15 | # PURPOSE. See the GNU General Public License for more details. | ||
1072 | 16 | # | ||
1073 | 17 | # You should have received a copy of the GNU General Public License along | ||
1074 | 18 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1075 | 19 | # | ||
1076 | 20 | # | ||
1077 | 21 | ''' | ||
1078 | 22 | blah, blah, blah | ||
1079 | 23 | ''' | ||
1080 | 0 | 24 | ||
1081 | === added file 'clicompanionlib/controller.py' | |||
1082 | --- clicompanionlib/controller.py 1970-01-01 00:00:00 +0000 | |||
1083 | +++ clicompanionlib/controller.py 2010-11-30 16:11:27 +0000 | |||
1084 | @@ -0,0 +1,428 @@ | |||
1085 | 1 | #!/usr/bin/env python | ||
1086 | 2 | # -*- coding: utf-8 -*- | ||
1087 | 3 | # | ||
1088 | 4 | # clicompanion.py - commandline tool. | ||
1089 | 5 | # | ||
1090 | 6 | # Copyright 2010 Duane Hinnen, Kenny Meyer | ||
1091 | 7 | # | ||
1092 | 8 | # This program is free software: you can redistribute it and/or modify it | ||
1093 | 9 | # under the terms of the GNU General Public License version 3, as published | ||
1094 | 10 | # by the Free Software Foundation. | ||
1095 | 11 | # | ||
1096 | 12 | # This program is distributed in the hope that it will be useful, but | ||
1097 | 13 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1098 | 14 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1099 | 15 | # PURPOSE. See the GNU General Public License for more details. | ||
1100 | 16 | # | ||
1101 | 17 | # You should have received a copy of the GNU General Public License along | ||
1102 | 18 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1103 | 19 | # | ||
1104 | 20 | # IMPORTANT: you need to move the .cheatsheet file to your $HOME | ||
1105 | 21 | # | ||
1106 | 22 | |||
1107 | 23 | |||
1108 | 24 | import pygtk | ||
1109 | 25 | pygtk.require('2.0') | ||
1110 | 26 | import re | ||
1111 | 27 | import webbrowser | ||
1112 | 28 | |||
1113 | 29 | import os | ||
1114 | 30 | # import gtk or print error | ||
1115 | 31 | try: | ||
1116 | 32 | import gtk | ||
1117 | 33 | except: | ||
1118 | 34 | print >> sys.stderr, "You need to install the python gtk bindings" | ||
1119 | 35 | sys.exit(1) | ||
1120 | 36 | |||
1121 | 37 | # TODO: these handle the exception different. Which do we like? | ||
1122 | 38 | # import vte or display dialog | ||
1123 | 39 | try: | ||
1124 | 40 | import vte | ||
1125 | 41 | except: | ||
1126 | 42 | error = gtk.MessageDialog (None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, | ||
1127 | 43 | 'You need to install python bindings for libvte') | ||
1128 | 44 | error.run() | ||
1129 | 45 | sys.exit (1) | ||
1130 | 46 | |||
1131 | 47 | from clicompanionlib.utils import get_user_shell | ||
1132 | 48 | import view | ||
1133 | 49 | |||
1134 | 50 | |||
1135 | 51 | CHEATSHEET = os.path.expanduser("~/.clicompanion2") | ||
1136 | 52 | CONFIG_ORIG = "/etc/clicompanion.d/clicompanion2.config" | ||
1137 | 53 | |||
1138 | 54 | |||
1139 | 55 | class Actions(object): | ||
1140 | 56 | ## Info Dialog Box | ||
1141 | 57 | ## if a command needs more info EX: a package name, a path | ||
1142 | 58 | def get_info(self, widget, liststore): | ||
1143 | 59 | |||
1144 | 60 | row_int = int(view.ROW[0][0]) | ||
1145 | 61 | |||
1146 | 62 | ## Create Dialog object | ||
1147 | 63 | dialog = gtk.MessageDialog( | ||
1148 | 64 | None, | ||
1149 | 65 | gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, | ||
1150 | 66 | gtk.MESSAGE_QUESTION, | ||
1151 | 67 | gtk.BUTTONS_OK, | ||
1152 | 68 | None) | ||
1153 | 69 | |||
1154 | 70 | # Primary text | ||
1155 | 71 | dialog.set_markup(_("This command requires more information")) | ||
1156 | 72 | |||
1157 | 73 | ## create the text input field | ||
1158 | 74 | entry = gtk.Entry() | ||
1159 | 75 | ## allow the user to press enter to do ok | ||
1160 | 76 | entry.connect("activate", self.responseToDialog, dialog, gtk.RESPONSE_OK) | ||
1161 | 77 | |||
1162 | 78 | ## create a horizontal box to pack the entry and a label | ||
1163 | 79 | hbox = gtk.HBox() | ||
1164 | 80 | hbox.pack_start(gtk.Label(liststore[row_int][1]+":"), False, 5, 5) | ||
1165 | 81 | hbox.pack_end(entry) | ||
1166 | 82 | ## some secondary text | ||
1167 | 83 | dialog.format_secondary_markup(_("Please provide a "+liststore[row_int][1])) | ||
1168 | 84 | ## add it and show it | ||
1169 | 85 | dialog.vbox.pack_end(hbox, True, True, 0) | ||
1170 | 86 | dialog.show_all() | ||
1171 | 87 | |||
1172 | 88 | ## Show the dialog | ||
1173 | 89 | dialog.run() | ||
1174 | 90 | |||
1175 | 91 | ## user text assigned to a variable | ||
1176 | 92 | text = entry.get_text() | ||
1177 | 93 | user_input = text.split(' ') | ||
1178 | 94 | |||
1179 | 95 | ## The destroy method must be called otherwise the 'Close' button will | ||
1180 | 96 | ## not work. | ||
1181 | 97 | dialog.destroy() | ||
1182 | 98 | return user_input | ||
1183 | 99 | |||
1184 | 100 | def responseToDialog(self, text, dialog, response): | ||
1185 | 101 | dialog.response(response) | ||
1186 | 102 | |||
1187 | 103 | ## Add command dialog box | ||
1188 | 104 | def add_command(self, widget, liststore): | ||
1189 | 105 | |||
1190 | 106 | ## Create Dialog object | ||
1191 | 107 | dialog = gtk.MessageDialog( | ||
1192 | 108 | None, | ||
1193 | 109 | gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, | ||
1194 | 110 | gtk.MESSAGE_QUESTION, | ||
1195 | 111 | gtk.BUTTONS_OK, | ||
1196 | 112 | None) | ||
1197 | 113 | |||
1198 | 114 | ## primaary text | ||
1199 | 115 | dialog.set_markup(_("Add a command to your CLI Companion dictionary")) | ||
1200 | 116 | |||
1201 | 117 | #create the text input field | ||
1202 | 118 | entry1 = gtk.Entry() | ||
1203 | 119 | entry2 = gtk.Entry() | ||
1204 | 120 | entry3 = gtk.Entry() | ||
1205 | 121 | ## allow the user to press enter to do ok | ||
1206 | 122 | entry1.connect("activate", self.responseToDialog, dialog, gtk.RESPONSE_OK) | ||
1207 | 123 | entry2.connect("activate", self.responseToDialog, dialog, gtk.RESPONSE_OK) | ||
1208 | 124 | entry3.connect("activate", self.responseToDialog, dialog, gtk.RESPONSE_OK) | ||
1209 | 125 | |||
1210 | 126 | ## create three labels | ||
1211 | 127 | hbox1 = gtk.HBox() | ||
1212 | 128 | hbox1.pack_start(gtk.Label(_("Command")), False, 5, 5) | ||
1213 | 129 | hbox1.pack_start(entry1, False, 5, 5) | ||
1214 | 130 | |||
1215 | 131 | hbox1.pack_start(gtk.Label(_("User Input")), False, 5, 5) | ||
1216 | 132 | hbox1.pack_start(entry2, False, 5, 5) | ||
1217 | 133 | |||
1218 | 134 | hbox2 = gtk.HBox() | ||
1219 | 135 | hbox2.pack_start(gtk.Label(_("Description")), False, 5, 5) | ||
1220 | 136 | hbox2.pack_start(entry3, True, 5, 5) | ||
1221 | 137 | |||
1222 | 138 | ## cancel button | ||
1223 | 139 | dialog.add_button('Cancel', gtk.RESPONSE_DELETE_EVENT) | ||
1224 | 140 | ## some secondary text | ||
1225 | 141 | dialog.format_secondary_markup(_("When entering a command, use a ? symbol if user input is required at runtime. Example: ls /any/direstory would be entered as ls ? .For each ? in your command, if any, use the User Input field to provide a hint for each variable. Using our example ls ? you could put directory as the User Input. Lastly provide a brief Description.")) | ||
1226 | 142 | |||
1227 | 143 | ## add it and show it | ||
1228 | 144 | dialog.vbox.pack_end(hbox2, True, True, 0) | ||
1229 | 145 | dialog.vbox.pack_end(hbox1, True, True, 0) | ||
1230 | 146 | dialog.show_all() | ||
1231 | 147 | ## Show the dialog | ||
1232 | 148 | result = dialog.run() | ||
1233 | 149 | |||
1234 | 150 | if result == gtk.RESPONSE_OK: | ||
1235 | 151 | ## user text assigned to a variable | ||
1236 | 152 | text1 = entry1.get_text() | ||
1237 | 153 | text2 = entry2.get_text() | ||
1238 | 154 | text3 = entry3.get_text() | ||
1239 | 155 | '''open flat file, add the new command, update CMNDS variable | ||
1240 | 156 | ## update commands in liststore (on screen) ''' | ||
1241 | 157 | with open(CHEATSHEET, "a") as cheatfile: | ||
1242 | 158 | if text1 != "": | ||
1243 | 159 | ## write new commands to .clicompanion2 file | ||
1244 | 160 | cheatfile.write(text1+":"+text2+":"+text3+'\n') | ||
1245 | 161 | cheatfile.close() | ||
1246 | 162 | l = str(text1+":"+text2+":"+text3) | ||
1247 | 163 | ls = l.split(':',2) | ||
1248 | 164 | ## update view.CMNDS variable | ||
1249 | 165 | filteredcommandplus = ls[0], ls[1] | ||
1250 | 166 | view.CMNDS.append(filteredcommandplus) | ||
1251 | 167 | ## update the command list on screen | ||
1252 | 168 | liststore.append([ls[0],ls[1],ls[2]]) | ||
1253 | 169 | |||
1254 | 170 | |||
1255 | 171 | ## The destroy method must be called otherwise the 'Close' button will | ||
1256 | 172 | ## not work. | ||
1257 | 173 | dialog.destroy() | ||
1258 | 174 | #return text | ||
1259 | 175 | |||
1260 | 176 | ## This the edit function | ||
1261 | 177 | def edit_command(self, widget , liststore): | ||
1262 | 178 | |||
1263 | 179 | row_int = int(view.ROW[0][0]) | ||
1264 | 180 | |||
1265 | 181 | row_obj1 = liststore[row_int][0] | ||
1266 | 182 | text1 = "".join(row_obj1) | ||
1267 | 183 | |||
1268 | 184 | row_obj2 = liststore[row_int][1] | ||
1269 | 185 | text2 = "".join(row_obj2) | ||
1270 | 186 | |||
1271 | 187 | row_obj3 = liststore[row_int][2] | ||
1272 | 188 | text3 = "".join(row_obj3) | ||
1273 | 189 | |||
1274 | 190 | ## Create Dialog object | ||
1275 | 191 | dialog = gtk.MessageDialog( | ||
1276 | 192 | None, | ||
1277 | 193 | gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, | ||
1278 | 194 | gtk.MESSAGE_QUESTION, | ||
1279 | 195 | gtk.BUTTONS_OK, | ||
1280 | 196 | None) | ||
1281 | 197 | |||
1282 | 198 | # primary text | ||
1283 | 199 | dialog.set_markup(_("Edit the command in your clicompanion dictionary")) | ||
1284 | 200 | |||
1285 | 201 | ## create the text input fields | ||
1286 | 202 | entry1 = gtk.Entry() | ||
1287 | 203 | entry1.set_text(text1) | ||
1288 | 204 | entry2 = gtk.Entry() | ||
1289 | 205 | entry2.set_text(text2) | ||
1290 | 206 | entry3 = gtk.Entry() | ||
1291 | 207 | entry3.set_text(text3) | ||
1292 | 208 | ## allow the user to press enter to do ok | ||
1293 | 209 | entry1.connect("activate", self.responseToDialog, dialog, gtk.RESPONSE_OK) | ||
1294 | 210 | |||
1295 | 211 | ## create three labels | ||
1296 | 212 | hbox1 = gtk.HBox() | ||
1297 | 213 | hbox1.pack_start(gtk.Label(_("Command")), False, 5, 5) | ||
1298 | 214 | hbox1.pack_start(entry1, False, 5, 5) | ||
1299 | 215 | |||
1300 | 216 | hbox1.pack_start(gtk.Label(_("User Input")), False, 5, 5) | ||
1301 | 217 | hbox1.pack_start(entry2, False, 5, 5) | ||
1302 | 218 | |||
1303 | 219 | hbox2 = gtk.HBox() | ||
1304 | 220 | hbox2.pack_start(gtk.Label(_("Description")), False, 5, 5) | ||
1305 | 221 | hbox2.pack_start(entry3, True, 5, 5) | ||
1306 | 222 | |||
1307 | 223 | ## cancel button | ||
1308 | 224 | dialog.add_button('Cancel', gtk.RESPONSE_DELETE_EVENT) | ||
1309 | 225 | ## some secondary text | ||
1310 | 226 | dialog.format_secondary_markup(_("Please provide a command, description, and what type of user variable, if any, is required.")) | ||
1311 | 227 | |||
1312 | 228 | ## add it and show it | ||
1313 | 229 | dialog.vbox.pack_end(hbox2, True, True, 0) | ||
1314 | 230 | dialog.vbox.pack_end(hbox1, True, True, 0) | ||
1315 | 231 | dialog.show_all() | ||
1316 | 232 | ## Show the dialog | ||
1317 | 233 | result = dialog.run() | ||
1318 | 234 | |||
1319 | 235 | if result == gtk.RESPONSE_OK: | ||
1320 | 236 | ## user text assigned to a variable | ||
1321 | 237 | text1 = entry1.get_text() | ||
1322 | 238 | text2 = entry2.get_text() | ||
1323 | 239 | text3 = entry3.get_text() | ||
1324 | 240 | |||
1325 | 241 | if text1 != "": | ||
1326 | 242 | self.remove_command(widget, liststore) | ||
1327 | 243 | '''open flat file, add the new command, update CMNDS variable | ||
1328 | 244 | ## update commands in liststore (on screen) ''' | ||
1329 | 245 | with open(CHEATSHEET, "a") as cheatfile: | ||
1330 | 246 | ## write new commands to .clicompanion2 file | ||
1331 | 247 | cheatfile.write(text1+":"+text2+":"+text3+'\n') | ||
1332 | 248 | cheatfile.close() | ||
1333 | 249 | l = str(text1+":"+text2+":"+text3) | ||
1334 | 250 | ls = l.split(':',2) | ||
1335 | 251 | ## update view.CMNDS variable | ||
1336 | 252 | filteredcommandplus = ls[0], ls[1] | ||
1337 | 253 | view.CMNDS.append(filteredcommandplus) | ||
1338 | 254 | ## update the command list on screen | ||
1339 | 255 | liststore.append([ls[0],ls[1],ls[2]]) | ||
1340 | 256 | |||
1341 | 257 | ## The destroy method must be called otherwise the 'Close' button will | ||
1342 | 258 | ## not work. | ||
1343 | 259 | dialog.destroy() | ||
1344 | 260 | |||
1345 | 261 | |||
1346 | 262 | ## Remove command from command file and GUI | ||
1347 | 263 | def remove_command(self, widget, liststore): | ||
1348 | 264 | |||
1349 | 265 | row_int = int(view.ROW[0][0]) #convert pathlist into something usable | ||
1350 | 266 | del view.CMNDS[row_int] | ||
1351 | 267 | del liststore[row_int] | ||
1352 | 268 | |||
1353 | 269 | ## open command file and delete line so the change is persistent | ||
1354 | 270 | with open(CHEATSHEET, "r") as cheatfile: | ||
1355 | 271 | cheatlines = cheatfile.readlines() | ||
1356 | 272 | del cheatlines[row_int] | ||
1357 | 273 | cheatfile.close() | ||
1358 | 274 | with open(CHEATSHEET, "w") as cheatfile2: | ||
1359 | 275 | cheatfile2.writelines(cheatlines) | ||
1360 | 276 | cheatfile2.close() | ||
1361 | 277 | |||
1362 | 278 | |||
1363 | 279 | def _filter_commands(self, widget, liststore, treeview): | ||
1364 | 280 | """ | ||
1365 | 281 | Show commands matching a given search term. | ||
1366 | 282 | The user should enter a term in the search box and the treeview should | ||
1367 | 283 | only display the rows which contain the search term. | ||
1368 | 284 | Pretty straight-forward. | ||
1369 | 285 | """ | ||
1370 | 286 | search_term = widget.get_text() | ||
1371 | 287 | |||
1372 | 288 | ## Create a TreeModelFilter object which provides auxiliary functions for | ||
1373 | 289 | ## filtering data. | ||
1374 | 290 | ## http://www.pygtk.org/pygtk2tutorial/sec-TreeModelSortAndTreeModelFilter.html | ||
1375 | 291 | modelfilter = liststore.filter_new() | ||
1376 | 292 | def search(modelfilter, iter, search_term): | ||
1377 | 293 | try: | ||
1378 | 294 | ## Iterate through every column and row and check if the search | ||
1379 | 295 | ## term is there: | ||
1380 | 296 | if search_term in modelfilter.get_value(iter, 0) or \ | ||
1381 | 297 | search_term in modelfilter.get_value(iter, 1) or \ | ||
1382 | 298 | search_term in modelfilter.get_value(iter, 2): | ||
1383 | 299 | return True | ||
1384 | 300 | |||
1385 | 301 | except TypeError: | ||
1386 | 302 | ## Python raises a TypeError if row data doesn't exist. Catch | ||
1387 | 303 | ## that and fail silently. | ||
1388 | 304 | pass | ||
1389 | 305 | |||
1390 | 306 | modelfilter.set_visible_func(search, search_term) | ||
1391 | 307 | treeview.set_model(modelfilter) | ||
1392 | 308 | |||
1393 | 309 | |||
1394 | 310 | #clear CMNDS list then populate it with the filteredlist of commands | ||
1395 | 311 | view.CMNDS = [] | ||
1396 | 312 | for line in modelfilter: | ||
1397 | 313 | linelist = line | ||
1398 | 314 | filteredcommandplus = linelist[0], linelist[1] | ||
1399 | 315 | view.CMNDS.append(filteredcommandplus) | ||
1400 | 316 | |||
1401 | 317 | |||
1402 | 318 | |||
1403 | 319 | ## send the command to the terminal | ||
1404 | 320 | def run_command(self, widget, notebook, liststore): | ||
1405 | 321 | text = "" | ||
1406 | 322 | row_int = int(view.ROW[0][0]) ## removes everything but number from [5,] | ||
1407 | 323 | |||
1408 | 324 | ## get the current notebook page so the function knows which terminal to run the command in. | ||
1409 | 325 | pagenum = notebook.get_current_page() | ||
1410 | 326 | widget = notebook.get_nth_page(pagenum) | ||
1411 | 327 | page_widget = widget.get_child() | ||
1412 | 328 | ## view.CMNDS is where commands are stored | ||
1413 | 329 | cmnd = view.CMNDS[row_int][0] | ||
1414 | 330 | |||
1415 | 331 | ## find how many ?(user arguments) are in command | ||
1416 | 332 | match = re.findall('\?', cmnd) | ||
1417 | 333 | ''' | ||
1418 | 334 | Make sure user arguments were found. Replace ? with something | ||
1419 | 335 | .format can read. This is done so the user can just enter ?, when | ||
1420 | 336 | adding a command where arguments are needed, instead | ||
1421 | 337 | of {0[1]}, {0[1]}, {0[2]} | ||
1422 | 338 | ''' | ||
1423 | 339 | if match == False: | ||
1424 | 340 | pass | ||
1425 | 341 | else: | ||
1426 | 342 | num = len(match) | ||
1427 | 343 | ran = 0 | ||
1428 | 344 | new_cmnd = self.replace(cmnd, num, ran) | ||
1429 | 345 | |||
1430 | 346 | |||
1431 | 347 | if not view.CMNDS[row_int][1] == "": # command with user input | ||
1432 | 348 | text = self.get_info(self, liststore) | ||
1433 | 349 | c = new_cmnd.format(text) | ||
1434 | 350 | page_widget.feed_child(c+"\n") #send command w/ input | ||
1435 | 351 | page_widget.show() | ||
1436 | 352 | page_widget.grab_focus() | ||
1437 | 353 | else: ## command that has no user input | ||
1438 | 354 | page_widget.feed_child(cmnd+"\n") #send command | ||
1439 | 355 | page_widget.show() | ||
1440 | 356 | page_widget.grab_focus() | ||
1441 | 357 | |||
1442 | 358 | ## replace ? with {0[n]} | ||
1443 | 359 | def replace(self, cmnd, num, ran): | ||
1444 | 360 | replace_cmnd=re.sub('\?', '{0['+str(ran)+']}', cmnd, count=1) | ||
1445 | 361 | cmnd = replace_cmnd | ||
1446 | 362 | ran += 1 | ||
1447 | 363 | if ran < num: | ||
1448 | 364 | return self.replace(cmnd, num, ran) | ||
1449 | 365 | else: | ||
1450 | 366 | pass | ||
1451 | 367 | return cmnd | ||
1452 | 368 | |||
1453 | 369 | ## open the man page for selected command | ||
1454 | 370 | def man_page(self, widget, notebook): | ||
1455 | 371 | row_int = int(view.ROW[0][0]) # removes everything but number from EX: [5,] | ||
1456 | 372 | cmnd = view.CMNDS[row_int][0] #CMNDS is where commands are store | ||
1457 | 373 | splitcommand = self._filter_sudo_from(cmnd.split(" ")) | ||
1458 | 374 | ## get current notebook tab to use in function | ||
1459 | 375 | pagenum = notebook.get_current_page() | ||
1460 | 376 | widget = notebook.get_nth_page(pagenum) | ||
1461 | 377 | page_widget = widget.get_child() | ||
1462 | 378 | #send command to Terminal | ||
1463 | 379 | page_widget.feed_child("man "+splitcommand[0]+"| most \n") | ||
1464 | 380 | page_widget.grab_focus() | ||
1465 | 381 | page_widget.show() | ||
1466 | 382 | |||
1467 | 383 | |||
1468 | 384 | @staticmethod | ||
1469 | 385 | def _filter_sudo_from(command): | ||
1470 | 386 | """Filter the sudo from `command`, where `command` is a list. | ||
1471 | 387 | Return the command list with the "sudo" filtered out. | ||
1472 | 388 | """ | ||
1473 | 389 | if command[0].startswith("sudo"): | ||
1474 | 390 | del command[0] | ||
1475 | 391 | return command | ||
1476 | 392 | return command | ||
1477 | 393 | |||
1478 | 394 | |||
1479 | 395 | |||
1480 | 396 | #TODO: Move to menus_buttons | ||
1481 | 397 | def copy_paste(self, vte, event, data=None): | ||
1482 | 398 | if event.button == 3: | ||
1483 | 399 | |||
1484 | 400 | time = event.time | ||
1485 | 401 | ## right-click popup menu Copy | ||
1486 | 402 | popupMenu = gtk.Menu() | ||
1487 | 403 | menuPopup1 = gtk.ImageMenuItem (gtk.STOCK_COPY) | ||
1488 | 404 | popupMenu.add(menuPopup1) | ||
1489 | 405 | menuPopup1.connect('activate', lambda x: vte.copy_clipboard()) | ||
1490 | 406 | ## right-click popup menu Paste | ||
1491 | 407 | menuPopup2 = gtk.ImageMenuItem (gtk.STOCK_PASTE) | ||
1492 | 408 | popupMenu.add(menuPopup2) | ||
1493 | 409 | menuPopup2.connect('activate', lambda x: vte.paste_clipboard()) | ||
1494 | 410 | |||
1495 | 411 | ## Show popup menu | ||
1496 | 412 | popupMenu.show_all() | ||
1497 | 413 | popupMenu.popup( None, None, None, event.button, time) | ||
1498 | 414 | return True | ||
1499 | 415 | else: | ||
1500 | 416 | pass | ||
1501 | 417 | |||
1502 | 418 | ## close the window and quit | ||
1503 | 419 | def delete_event(self, widget, data=None): | ||
1504 | 420 | gtk.main_quit() | ||
1505 | 421 | return False | ||
1506 | 422 | |||
1507 | 423 | def about_event(self, widget, data=None): | ||
1508 | 424 | pass | ||
1509 | 425 | def help_event(self, widget, data=None): | ||
1510 | 426 | webbrowser.open("http://okiebuntu.homelinux.com/okwiki/clicompanion") | ||
1511 | 427 | |||
1512 | 428 | |||
1513 | 0 | 429 | ||
1514 | === added file 'clicompanionlib/menus_buttons.py' | |||
1515 | --- clicompanionlib/menus_buttons.py 1970-01-01 00:00:00 +0000 | |||
1516 | +++ clicompanionlib/menus_buttons.py 2010-11-30 16:11:27 +0000 | |||
1517 | @@ -0,0 +1,175 @@ | |||
1518 | 1 | #!/usr/bin/env python | ||
1519 | 2 | # -*- coding: utf-8 -*- | ||
1520 | 3 | # | ||
1521 | 4 | # Copyright 2010 Duane Hinnen, Kenny Meyer, Marcos Vanetta | ||
1522 | 5 | # | ||
1523 | 6 | # This program is free software: you can redistribute it and/or modify it | ||
1524 | 7 | # under the terms of the GNU General Public License version 3, as published | ||
1525 | 8 | # by the Free Software Foundation. | ||
1526 | 9 | # | ||
1527 | 10 | # This program is distributed in the hope that it will be useful, but | ||
1528 | 11 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1529 | 12 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1530 | 13 | # PURPOSE. See the GNU General Public License for more details. | ||
1531 | 14 | # | ||
1532 | 15 | # You should have received a copy of the GNU General Public License along | ||
1533 | 16 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1534 | 17 | # | ||
1535 | 18 | # | ||
1536 | 19 | # | ||
1537 | 20 | # This file contains the menus, buttons, and right clicks | ||
1538 | 21 | # | ||
1539 | 22 | |||
1540 | 23 | import gtk | ||
1541 | 24 | import clicompanionlib.tabs | ||
1542 | 25 | |||
1543 | 26 | |||
1544 | 27 | class FileMenu(object): | ||
1545 | 28 | |||
1546 | 29 | def the_menu(self, actions, notebook, liststore): | ||
1547 | 30 | menu = gtk.Menu() | ||
1548 | 31 | root_menu = gtk.MenuItem(_("File")) | ||
1549 | 32 | root_menu.set_submenu(menu) | ||
1550 | 33 | |||
1551 | 34 | menu2 = gtk.Menu() | ||
1552 | 35 | root_menu2 = gtk.MenuItem(_("Help")) | ||
1553 | 36 | root_menu2.set_submenu(menu2) | ||
1554 | 37 | |||
1555 | 38 | ##FILE MENU ## | ||
1556 | 39 | ## Make 'Run' menu entry | ||
1557 | 40 | menu_item1 = gtk.MenuItem(_("Run Command")) | ||
1558 | 41 | menu.append(menu_item1) | ||
1559 | 42 | menu_item1.connect("activate", actions.run_command, notebook, liststore) | ||
1560 | 43 | menu_item1.show() | ||
1561 | 44 | |||
1562 | 45 | ## Make 'Add' file menu entry | ||
1563 | 46 | menu_item2 = gtk.MenuItem(_("Add Command")) | ||
1564 | 47 | menu.append(menu_item2) | ||
1565 | 48 | menu_item2.connect("activate", actions.add_command, liststore) | ||
1566 | 49 | menu_item2.show() | ||
1567 | 50 | |||
1568 | 51 | ## Make 'Remove' file menu entry | ||
1569 | 52 | menu_item2 = gtk.MenuItem(_("Remove Command")) | ||
1570 | 53 | menu.append(menu_item2) | ||
1571 | 54 | menu_item2.connect("activate", actions.remove_command, liststore) | ||
1572 | 55 | menu_item2.show() | ||
1573 | 56 | |||
1574 | 57 | ## Make 'Add Tab' file menu entry | ||
1575 | 58 | tabs = clicompanionlib.tabs.Tabs() | ||
1576 | 59 | menu_item4 = gtk.MenuItem(_("Add Tab")) | ||
1577 | 60 | menu.append(menu_item4) | ||
1578 | 61 | menu_item4.connect("activate", tabs.add_tab, notebook) | ||
1579 | 62 | menu_item4.show() | ||
1580 | 63 | |||
1581 | 64 | ## Make 'Quit' file menu entry | ||
1582 | 65 | menu_item3 = gtk.MenuItem(_("Quit")) | ||
1583 | 66 | menu.append(menu_item3) | ||
1584 | 67 | menu_item3.connect("activate", actions.delete_event) | ||
1585 | 68 | menu_item3.show() | ||
1586 | 69 | |||
1587 | 70 | |||
1588 | 71 | ## HELP MENU ## | ||
1589 | 72 | ## Make 'About' file menu entry | ||
1590 | 73 | menu_item11 = gtk.MenuItem(_("About")) | ||
1591 | 74 | menu2.append(menu_item11) | ||
1592 | 75 | menu_item11.connect("activate", actions.about_event) | ||
1593 | 76 | menu_item11.show() | ||
1594 | 77 | |||
1595 | 78 | |||
1596 | 79 | ## Make 'Help' file menu entry | ||
1597 | 80 | menu_item22 = gtk.MenuItem(_("Help")) | ||
1598 | 81 | menu2.append(menu_item22) | ||
1599 | 82 | menu_item22.connect("activate", actions.help_event) | ||
1600 | 83 | menu_item22.show() | ||
1601 | 84 | |||
1602 | 85 | |||
1603 | 86 | menu_bar = gtk.MenuBar() | ||
1604 | 87 | |||
1605 | 88 | menu_bar.append (root_menu) ##Menu bar(file) | ||
1606 | 89 | menu_bar.append (root_menu2) ##Menu bar(help) | ||
1607 | 90 | #menu_bar.show() ##show File Menu # Menu Bar | ||
1608 | 91 | ##Show 'File' Menu | ||
1609 | 92 | #root_menu.show() | ||
1610 | 93 | return menu_bar | ||
1611 | 94 | |||
1612 | 95 | |||
1613 | 96 | |||
1614 | 97 | def buttons(self, actions, spacing, layout, notebook, liststore): | ||
1615 | 98 | #button box at bottom of main window | ||
1616 | 99 | frame = gtk.Frame() | ||
1617 | 100 | bbox = gtk.HButtonBox() | ||
1618 | 101 | bbox.set_border_width(5) | ||
1619 | 102 | frame.add(bbox) | ||
1620 | 103 | |||
1621 | 104 | # Set the appearance of the Button Box | ||
1622 | 105 | bbox.set_layout(layout) | ||
1623 | 106 | bbox.set_spacing(spacing) | ||
1624 | 107 | # Run button | ||
1625 | 108 | buttonRun = gtk.Button(_("Run")) | ||
1626 | 109 | bbox.add(buttonRun) | ||
1627 | 110 | buttonRun.connect("clicked", actions.run_command, notebook, liststore) | ||
1628 | 111 | buttonRun.set_tooltip_text(_("Click to run a highlighted command")) | ||
1629 | 112 | # Add button | ||
1630 | 113 | buttonAdd = gtk.Button(stock=gtk.STOCK_ADD) | ||
1631 | 114 | bbox.add(buttonAdd) | ||
1632 | 115 | buttonAdd.connect("clicked", actions.add_command, liststore) | ||
1633 | 116 | buttonAdd.set_tooltip_text(_("Click to add a command to your command list")) | ||
1634 | 117 | # Edit button | ||
1635 | 118 | buttonEdit = gtk.Button("Edit") | ||
1636 | 119 | bbox.add(buttonEdit) | ||
1637 | 120 | buttonEdit.connect("clicked", actions.edit_command, liststore) | ||
1638 | 121 | buttonEdit.set_tooltip_text(_("Click to edit a command in your command list")) | ||
1639 | 122 | # Delete button | ||
1640 | 123 | buttonDelete = gtk.Button(stock=gtk.STOCK_DELETE) | ||
1641 | 124 | bbox.add(buttonDelete) | ||
1642 | 125 | buttonDelete.connect("clicked", actions.remove_command, liststore) | ||
1643 | 126 | buttonDelete.set_tooltip_text(_("Click to delete a command in your command list")) | ||
1644 | 127 | #Help Button | ||
1645 | 128 | buttonHelp = gtk.Button(stock=gtk.STOCK_HELP) | ||
1646 | 129 | bbox.add(buttonHelp) | ||
1647 | 130 | buttonHelp.connect("clicked", actions.man_page, notebook) | ||
1648 | 131 | buttonHelp.set_tooltip_text(_("Click to get help with a command in your command list")) | ||
1649 | 132 | # Cancel button | ||
1650 | 133 | buttonCancel = gtk.Button(stock=gtk.STOCK_QUIT) | ||
1651 | 134 | bbox.add(buttonCancel) | ||
1652 | 135 | buttonCancel.connect("clicked", actions.delete_event) | ||
1653 | 136 | buttonCancel.set_tooltip_text(_("Click to quit CLI Companion")) | ||
1654 | 137 | |||
1655 | 138 | return frame | ||
1656 | 139 | |||
1657 | 140 | |||
1658 | 141 | #right-click popup menu for the Liststore(command list) | ||
1659 | 142 | def right_click(self, widget, event, actions, treeview, notebook, liststore): | ||
1660 | 143 | if event.button == 3: | ||
1661 | 144 | x = int(event.x) | ||
1662 | 145 | y = int(event.y) | ||
1663 | 146 | time = event.time | ||
1664 | 147 | pthinfo = treeview.get_path_at_pos(x, y) | ||
1665 | 148 | if pthinfo is not None: | ||
1666 | 149 | path, col, cellx, celly = pthinfo | ||
1667 | 150 | treeview.grab_focus() | ||
1668 | 151 | treeview.set_cursor( path, col, 0) | ||
1669 | 152 | |||
1670 | 153 | # right-click popup menu Apply(run) | ||
1671 | 154 | popupMenu = gtk.Menu() | ||
1672 | 155 | menuPopup1 = gtk.ImageMenuItem (gtk.STOCK_APPLY) | ||
1673 | 156 | popupMenu.add(menuPopup1) | ||
1674 | 157 | menuPopup1.connect("activate", actions.run_command, notebook, liststore) | ||
1675 | 158 | # right-click popup menu Edit | ||
1676 | 159 | menuPopup2 = gtk.ImageMenuItem (gtk.STOCK_EDIT) | ||
1677 | 160 | popupMenu.add(menuPopup2) | ||
1678 | 161 | menuPopup2.connect("activate", actions.edit_command, liststore) | ||
1679 | 162 | # right-click popup menu Delete | ||
1680 | 163 | menuPopup3 = gtk.ImageMenuItem (gtk.STOCK_DELETE) | ||
1681 | 164 | popupMenu.add(menuPopup3) | ||
1682 | 165 | menuPopup3.connect("activate", actions.remove_command, liststore) | ||
1683 | 166 | # right-click popup menu Help | ||
1684 | 167 | menuPopup4 = gtk.ImageMenuItem (gtk.STOCK_HELP) | ||
1685 | 168 | popupMenu.add(menuPopup4) | ||
1686 | 169 | menuPopup4.connect("activate", actions.man_page, notebook) | ||
1687 | 170 | # Show popup menu | ||
1688 | 171 | popupMenu.show_all() | ||
1689 | 172 | popupMenu.popup( None, None, None, event.button, time) | ||
1690 | 173 | return True | ||
1691 | 174 | |||
1692 | 175 | |||
1693 | 0 | 176 | ||
1694 | === added file 'clicompanionlib/tabs.py' | |||
1695 | --- clicompanionlib/tabs.py 1970-01-01 00:00:00 +0000 | |||
1696 | +++ clicompanionlib/tabs.py 2010-11-30 16:11:27 +0000 | |||
1697 | @@ -0,0 +1,81 @@ | |||
1698 | 1 | #!/usr/bin/env python | ||
1699 | 2 | # | ||
1700 | 3 | # Copyright 2010 Duane Hinnen, Kenny Meyer, Marcos Vanetta | ||
1701 | 4 | # | ||
1702 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
1703 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
1704 | 7 | # by the Free Software Foundation. | ||
1705 | 8 | # | ||
1706 | 9 | # This program is distributed in the hope that it will be useful, but | ||
1707 | 10 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1708 | 11 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1709 | 12 | # PURPOSE. See the GNU General Public License for more details. | ||
1710 | 13 | # | ||
1711 | 14 | # You should have received a copy of the GNU General Public License along | ||
1712 | 15 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1713 | 16 | # | ||
1714 | 17 | # | ||
1715 | 18 | # | ||
1716 | 19 | |||
1717 | 20 | import pygtk | ||
1718 | 21 | pygtk.require('2.0') | ||
1719 | 22 | import gtk | ||
1720 | 23 | import vte | ||
1721 | 24 | |||
1722 | 25 | from clicompanionlib.utils import get_user_shell | ||
1723 | 26 | import clicompanionlib.controller | ||
1724 | 27 | |||
1725 | 28 | class Tabs(object): | ||
1726 | 29 | |||
1727 | 30 | |||
1728 | 31 | |||
1729 | 32 | ## add a new terminal in a tab above the current terminal | ||
1730 | 33 | def add_tab(self,widget, notebook): | ||
1731 | 34 | |||
1732 | 35 | _vte = vte.Terminal() | ||
1733 | 36 | _vte.set_size_request(700, 220) | ||
1734 | 37 | _vte.connect ("child-exited", lambda term: gtk.main_quit()) | ||
1735 | 38 | _vte.fork_command(get_user_shell()) # Get the user's default shell | ||
1736 | 39 | |||
1737 | 40 | vte_tab = gtk.ScrolledWindow() | ||
1738 | 41 | vte_tab.add(_vte) | ||
1739 | 42 | #notebook.set_show_tabs(True) | ||
1740 | 43 | #notebook.set_show_border(True) | ||
1741 | 44 | |||
1742 | 45 | gcp = notebook.get_current_page() +1 | ||
1743 | 46 | pagenum = ('Tab %d') % gcp | ||
1744 | 47 | |||
1745 | 48 | box = gtk.HBox() | ||
1746 | 49 | label = gtk.Label(pagenum) | ||
1747 | 50 | box.pack_start(label, True, True) | ||
1748 | 51 | |||
1749 | 52 | ## x image for tab close button | ||
1750 | 53 | close_image = gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU) | ||
1751 | 54 | ## close button | ||
1752 | 55 | closebtn = gtk.Button() | ||
1753 | 56 | closebtn.set_relief(gtk.RELIEF_NONE) | ||
1754 | 57 | closebtn.set_focus_on_click(True) | ||
1755 | 58 | |||
1756 | 59 | closebtn.add(close_image) | ||
1757 | 60 | ## put button in a box and show box | ||
1758 | 61 | box.pack_end(closebtn, False, False) | ||
1759 | 62 | box.show_all() | ||
1760 | 63 | |||
1761 | 64 | notebook.prepend_page(vte_tab, box) # add tab | ||
1762 | 65 | notebook.set_scrollable(True) | ||
1763 | 66 | actions = clicompanionlib.controller.Actions() | ||
1764 | 67 | _vte.connect ("button_press_event", actions.copy_paste, None) | ||
1765 | 68 | vte_tab.grab_focus() | ||
1766 | 69 | # signal handler for tab | ||
1767 | 70 | closebtn.connect("clicked", self.close_tab, vte_tab, notebook) | ||
1768 | 71 | vte_tab.show_all() | ||
1769 | 72 | |||
1770 | 73 | return vte_tab | ||
1771 | 74 | |||
1772 | 75 | |||
1773 | 76 | ## Remove a page from the notebook | ||
1774 | 77 | def close_tab(self, sender, widget, notebook): | ||
1775 | 78 | ## get the page number of the tab we wanted to close | ||
1776 | 79 | pagenum = notebook.page_num(widget) | ||
1777 | 80 | ## and close it | ||
1778 | 81 | notebook.remove_page(pagenum) | ||
1779 | 0 | 82 | ||
1780 | === added file 'clicompanionlib/utils.py' | |||
1781 | --- clicompanionlib/utils.py 1970-01-01 00:00:00 +0000 | |||
1782 | +++ clicompanionlib/utils.py 2010-11-30 16:11:27 +0000 | |||
1783 | @@ -0,0 +1,56 @@ | |||
1784 | 1 | #!/usr/bin/env python | ||
1785 | 2 | # -*- coding: utf-8 -*- | ||
1786 | 3 | # | ||
1787 | 4 | # clicompanion.py - commandline tool. | ||
1788 | 5 | # | ||
1789 | 6 | # Copyright 2010 Duane Hinnen, Kenny Meyer, Marcos Vanetta | ||
1790 | 7 | # | ||
1791 | 8 | # This program is free software: you can redistribute it and/or modify it | ||
1792 | 9 | # under the terms of the GNU General Public License version 3, as published | ||
1793 | 10 | # by the Free Software Foundation. | ||
1794 | 11 | # | ||
1795 | 12 | # This program is distributed in the hope that it will be useful, but | ||
1796 | 13 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1797 | 14 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1798 | 15 | # PURPOSE. See the GNU General Public License for more details. | ||
1799 | 16 | # | ||
1800 | 17 | # You should have received a copy of the GNU General Public License along | ||
1801 | 18 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1802 | 19 | # | ||
1803 | 20 | # | ||
1804 | 21 | |||
1805 | 22 | """ | ||
1806 | 23 | A collection of useful functions. | ||
1807 | 24 | """ | ||
1808 | 25 | |||
1809 | 26 | import getpass | ||
1810 | 27 | import os | ||
1811 | 28 | |||
1812 | 29 | CHEATSHEET = os.path.expanduser("~/.clicompanion2") | ||
1813 | 30 | #CONFIG_ORIG = "/etc/clicompanion.d/clicompanion2.config" | ||
1814 | 31 | |||
1815 | 32 | #TODO: Move this to controller.py | ||
1816 | 33 | def get_user_shell(): | ||
1817 | 34 | """Get the user's shell defined in /etc/passwd .""" | ||
1818 | 35 | data = None | ||
1819 | 36 | try: | ||
1820 | 37 | # Read out the data in /etc/passwd | ||
1821 | 38 | with open('/etc/passwd') as f: | ||
1822 | 39 | data = f.readlines() | ||
1823 | 40 | except e: | ||
1824 | 41 | print "Something unexpected happened!" | ||
1825 | 42 | raise e | ||
1826 | 43 | |||
1827 | 44 | for i in data: | ||
1828 | 45 | tmp = i.split(":") | ||
1829 | 46 | # Check for the entry of the currently logged in user | ||
1830 | 47 | if tmp[0] == getpass.getuser(): | ||
1831 | 48 | # Columns are separated by colons, so split each column. | ||
1832 | 49 | # Sample /etc/passwd entry for a user: | ||
1833 | 50 | # | ||
1834 | 51 | # jorge:x:1001:1002:,,,:/home/jorge:/bin/bash | ||
1835 | 52 | # | ||
1836 | 53 | # The last column is relevant for us. | ||
1837 | 54 | # Don't forget to strip the newline at the end of the string! | ||
1838 | 55 | return i.split(":")[-1:][0].strip('\n') | ||
1839 | 56 | |||
1840 | 0 | 57 | ||
1841 | === added file 'clicompanionlib/view.py' | |||
1842 | --- clicompanionlib/view.py 1970-01-01 00:00:00 +0000 | |||
1843 | +++ clicompanionlib/view.py 2010-11-30 16:11:27 +0000 | |||
1844 | @@ -0,0 +1,279 @@ | |||
1845 | 1 | #!/usr/bin/env python | ||
1846 | 2 | # -*- coding: utf-8 -*- | ||
1847 | 3 | # | ||
1848 | 4 | # clicompanion.py - commandline tool. | ||
1849 | 5 | # | ||
1850 | 6 | # Copyright 2010 Duane Hinnen, Kenny Meyer | ||
1851 | 7 | # | ||
1852 | 8 | # This program is free software: you can redistribute it and/or modify it | ||
1853 | 9 | # under the terms of the GNU General Public License version 3, as published | ||
1854 | 10 | # by the Free Software Foundation. | ||
1855 | 11 | # | ||
1856 | 12 | # This program is distributed in the hope that it will be useful, but | ||
1857 | 13 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1858 | 14 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1859 | 15 | # PURPOSE. See the GNU General Public License for more details. | ||
1860 | 16 | # | ||
1861 | 17 | # You should have received a copy of the GNU General Public License along | ||
1862 | 18 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1863 | 19 | # | ||
1864 | 20 | # | ||
1865 | 21 | # | ||
1866 | 22 | |||
1867 | 23 | import pygtk | ||
1868 | 24 | pygtk.require('2.0') | ||
1869 | 25 | import os | ||
1870 | 26 | |||
1871 | 27 | # import gtk or print error | ||
1872 | 28 | try: | ||
1873 | 29 | import gtk | ||
1874 | 30 | except: | ||
1875 | 31 | print >> sys.stderr, "You need to install the python gtk bindings" | ||
1876 | 32 | sys.exit(1) | ||
1877 | 33 | |||
1878 | 34 | # TODO: these handle the exception different. Which do we like? | ||
1879 | 35 | # import vte or display dialog | ||
1880 | 36 | try: | ||
1881 | 37 | import vte | ||
1882 | 38 | except: | ||
1883 | 39 | error = gtk.MessageDialog (None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, | ||
1884 | 40 | 'You need to install python bindings for libvte') | ||
1885 | 41 | error.run() | ||
1886 | 42 | sys.exit (1) | ||
1887 | 43 | |||
1888 | 44 | import clicompanionlib.menus_buttons | ||
1889 | 45 | import clicompanionlib.controller | ||
1890 | 46 | from clicompanionlib.utils import get_user_shell | ||
1891 | 47 | import clicompanionlib.tabs | ||
1892 | 48 | |||
1893 | 49 | |||
1894 | 50 | CHEATSHEET = os.path.expanduser("~/.clicompanion2") | ||
1895 | 51 | CONFIG_ORIG = "/etc/clicompanion.d/clicompanion2.config" | ||
1896 | 52 | CMNDS = [] ## will hold the commands. Actually the first two columns | ||
1897 | 53 | ROW = '1' ## holds the currently selected row | ||
1898 | 54 | |||
1899 | 55 | |||
1900 | 56 | |||
1901 | 57 | class MainWindow(): | ||
1902 | 58 | |||
1903 | 59 | ## open file containing command dictionary and put it in a variable | ||
1904 | 60 | def update(self, liststore): | ||
1905 | 61 | try: | ||
1906 | 62 | with open(CHEATSHEET, "r") as cheatfile: | ||
1907 | 63 | bugdata=cheatfile.read() | ||
1908 | 64 | cheatfile.close() | ||
1909 | 65 | except IOError: | ||
1910 | 66 | ## CHEATSHEET is not there. Oh, no! | ||
1911 | 67 | ## So, run self.setup() again. | ||
1912 | 68 | self.setup() | ||
1913 | 69 | ## Then, run me again. | ||
1914 | 70 | self.update(liststore) | ||
1915 | 71 | |||
1916 | 72 | ## add bug data from .clicompanion --> bugdata --> to the liststore | ||
1917 | 73 | for line in bugdata.splitlines(): | ||
1918 | 74 | l = line.split(':',2) | ||
1919 | 75 | commandplus = l[0], l[1] | ||
1920 | 76 | CMNDS.append(commandplus) | ||
1921 | 77 | liststore.append([l[0],l[1],l[2]]) | ||
1922 | 78 | |||
1923 | 79 | |||
1924 | 80 | #copy config file to user $HOME if does not exist | ||
1925 | 81 | def setup(self): | ||
1926 | 82 | """ | ||
1927 | 83 | Check if ~/.clicompanion2 exists. If not check for original | ||
1928 | 84 | installed in /etc/clicompanion.d/. If origianl exists copy to $HOME. | ||
1929 | 85 | if not create a new, blank ~/.clicompanion2 so program will not crash | ||
1930 | 86 | """ | ||
1931 | 87 | |||
1932 | 88 | if not os.path.exists(CHEATSHEET): | ||
1933 | 89 | if os.path.exists(CONFIG_ORIG): | ||
1934 | 90 | os.system ("cp %s %s" % (CONFIG_ORIG, CHEATSHEET)) | ||
1935 | 91 | else: | ||
1936 | 92 | # Oops! Looks like there's no cheatsheet in CHEATSHEET. | ||
1937 | 93 | # Then, create an empty cheatsheet. | ||
1938 | 94 | open(CHEATSHEET, 'w').close() | ||
1939 | 95 | |||
1940 | 96 | |||
1941 | 97 | #liststore in a scrolled window in an expander | ||
1942 | 98 | def expanded_cb(self, expander, params, notebook, treeview, liststore): | ||
1943 | 99 | if expander.get_expanded(): | ||
1944 | 100 | |||
1945 | 101 | |||
1946 | 102 | # Activate the search box when expanded | ||
1947 | 103 | self.search_box.set_sensitive(True) | ||
1948 | 104 | else: | ||
1949 | 105 | # De-activate the search box when not expanded | ||
1950 | 106 | self.search_box.set_sensitive(False) | ||
1951 | 107 | expander.set_expanded(False) | ||
1952 | 108 | #expander.remove(expander.child) | ||
1953 | 109 | ##reset the size of the window to its original one | ||
1954 | 110 | self.window.resize(1, 1) | ||
1955 | 111 | return | ||
1956 | 112 | |||
1957 | 113 | |||
1958 | 114 | # close the window and quit | ||
1959 | 115 | def delete_event(self, widget, data=None): | ||
1960 | 116 | gtk.main_quit() | ||
1961 | 117 | return False | ||
1962 | 118 | |||
1963 | 119 | def __init__(self): | ||
1964 | 120 | |||
1965 | 121 | ##For now TERM is hardcoded to xterm because of a change | ||
1966 | 122 | ##in libvte in Ubuntu Maverick | ||
1967 | 123 | os.putenv('TERM', 'xterm') | ||
1968 | 124 | ## copy config file to user $HOME if does not exist | ||
1969 | 125 | self.setup() | ||
1970 | 126 | |||
1971 | 127 | #TODO: do we want to do this? Or just keep the height under 600. | ||
1972 | 128 | ##Get user screen size## | ||
1973 | 129 | #screen = gtk.gdk.display_get_default().get_default_screen() | ||
1974 | 130 | #screen_size = screen.get_monitor_geometry(0) | ||
1975 | 131 | #height = screen.get_height() ## screen height ## | ||
1976 | 132 | |||
1977 | 133 | ## Create UI widgets | ||
1978 | 134 | self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) | ||
1979 | 135 | liststore = gtk.ListStore(str, str, str) | ||
1980 | 136 | treeview = gtk.TreeView() | ||
1981 | 137 | expander = gtk.Expander() | ||
1982 | 138 | self.scrolledwindow = gtk.ScrolledWindow() | ||
1983 | 139 | notebook = gtk.Notebook() | ||
1984 | 140 | |||
1985 | 141 | ## set sizes and borders | ||
1986 | 142 | self.scrolledwindow.set_size_request(700, 220) | ||
1987 | 143 | self.window.set_default_size(700, 625) | ||
1988 | 144 | self.window.set_border_width(10) | ||
1989 | 145 | ## Sets the position of the window relative to the screen | ||
1990 | 146 | self.window.set_position(gtk.WIN_POS_CENTER_ALWAYS) | ||
1991 | 147 | ## Allow user to resize window | ||
1992 | 148 | self.window.set_resizable(True) | ||
1993 | 149 | |||
1994 | 150 | ## set Window title and icon | ||
1995 | 151 | self.window.set_title("CLI Companion") | ||
1996 | 152 | icon = gtk.gdk.pixbuf_new_from_file("/usr/share/pixmaps/clicompanion.16.png") | ||
1997 | 153 | self.window.set_icon(icon) | ||
1998 | 154 | |||
1999 | 155 | # get commands and put in liststore | ||
2000 | 156 | self.update(liststore) | ||
2001 | 157 | ## create the TreeViewColumns to display the data | ||
2002 | 158 | treeview.columns = [None]*3 | ||
2003 | 159 | treeview.columns[0] = gtk.TreeViewColumn(_('Command')) | ||
2004 | 160 | treeview.columns[1] = gtk.TreeViewColumn(_('User Input')) | ||
2005 | 161 | treeview.columns[2] = gtk.TreeViewColumn(_('Description')) | ||
2006 | 162 | |||
2007 | 163 | for n in range(3): | ||
2008 | 164 | ## add columns to treeview | ||
2009 | 165 | treeview.append_column(treeview.columns[n]) | ||
2010 | 166 | ## create a CellRenderers to render the data | ||
2011 | 167 | treeview.columns[n].cell = gtk.CellRendererText() | ||
2012 | 168 | ## add the cells to the columns | ||
2013 | 169 | treeview.columns[n].pack_start(treeview.columns[n].cell, | ||
2014 | 170 | True) | ||
2015 | 171 | ## set the cell attributes to the appropriate liststore column | ||
2016 | 172 | treeview.columns[n].set_attributes( | ||
2017 | 173 | treeview.columns[n].cell, text=n) | ||
2018 | 174 | treeview.columns[n].set_resizable(True) | ||
2019 | 175 | |||
2020 | 176 | #set treeview model and put treeview in the scrolled window and the scrolled window in the expander. | ||
2021 | 177 | treeview.set_model(liststore) | ||
2022 | 178 | self.scrolledwindow.add(treeview) | ||
2023 | 179 | expander.add(self.scrolledwindow) | ||
2024 | 180 | #self.window.show_all() | ||
2025 | 181 | |||
2026 | 182 | ## instantiate tabs | ||
2027 | 183 | tabs = clicompanionlib.tabs.Tabs() | ||
2028 | 184 | ## instantiate controller.Actions, where all the button actions are | ||
2029 | 185 | actions = clicompanionlib.controller.Actions() | ||
2030 | 186 | ## instantiate 'File' and 'Help' Drop Down Menu [menus_buttons.py] | ||
2031 | 187 | bar = clicompanionlib.menus_buttons.FileMenu() | ||
2032 | 188 | menu_bar = bar.the_menu(actions, notebook, liststore) | ||
2033 | 189 | |||
2034 | 190 | |||
2035 | 191 | #get row of selection | ||
2036 | 192 | def mark_selected(self, treeselection): | ||
2037 | 193 | global ROW | ||
2038 | 194 | (model, pathlist)=treeselection.get_selected_rows() | ||
2039 | 195 | ROW = pathlist | ||
2040 | 196 | |||
2041 | 197 | |||
2042 | 198 | selection = treeview.get_selection() | ||
2043 | 199 | selection.set_mode(gtk.SELECTION_SINGLE) | ||
2044 | 200 | selection.select_path(0) | ||
2045 | 201 | selection.connect("changed", mark_selected, selection) | ||
2046 | 202 | |||
2047 | 203 | |||
2048 | 204 | ## The search section | ||
2049 | 205 | self.search_label = gtk.Label(_("Search:")) | ||
2050 | 206 | self.search_label.set_alignment(xalign=-1, yalign=0) | ||
2051 | 207 | self.search_box = gtk.Entry() | ||
2052 | 208 | self.search_box.connect("changed", actions._filter_commands, liststore, treeview) | ||
2053 | 209 | ## search box tooltip | ||
2054 | 210 | self.search_box.set_tooltip_text(_("Search your list of commands")) | ||
2055 | 211 | # Set the search box sensitive at program start, because expander is not | ||
2056 | 212 | # unfolded by default | ||
2057 | 213 | self.search_box.set_sensitive(False) | ||
2058 | 214 | ## hbox for menu and search Entry | ||
2059 | 215 | menu_search_hbox = gtk.HBox(False) | ||
2060 | 216 | menu_search_hbox.pack_end(self.search_box, True) | ||
2061 | 217 | menu_search_hbox.pack_end(self.search_label, False, False, 10) | ||
2062 | 218 | menu_search_hbox.pack_start(menu_bar, True) | ||
2063 | 219 | |||
2064 | 220 | |||
2065 | 221 | ## expander title | ||
2066 | 222 | expander_hbox = gtk.HBox() | ||
2067 | 223 | image = gtk.Image() | ||
2068 | 224 | image.set_from_stock(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON) | ||
2069 | 225 | label = gtk.Label(_('Command List')) | ||
2070 | 226 | ## tooltip for the label of the expander | ||
2071 | 227 | expander_hbox.set_tooltip_text(_("Click to show/hide command list")) | ||
2072 | 228 | |||
2073 | 229 | ## add expander widget to hbox | ||
2074 | 230 | expander_hbox.pack_start(image, False, False) | ||
2075 | 231 | expander_hbox.pack_start(label, True, False) | ||
2076 | 232 | expander.set_label_widget(expander_hbox) | ||
2077 | 233 | |||
2078 | 234 | ## Add the first tab with the Terminal | ||
2079 | 235 | tabs.add_tab(self, notebook) | ||
2080 | 236 | notebook.set_tab_pos(1) | ||
2081 | 237 | |||
2082 | 238 | ## The "Add Tab" tab | ||
2083 | 239 | add_tab_button = gtk.Button("+") | ||
2084 | 240 | ## tooltip for "Add Tab" tab | ||
2085 | 241 | add_tab_button.set_tooltip_text(_("Click to add another Tab")) | ||
2086 | 242 | ## create first tab | ||
2087 | 243 | notebook.append_page(gtk.Label(""), add_tab_button) | ||
2088 | 244 | |||
2089 | 245 | ## buttons at bottom of main window [menus_buttons.py] | ||
2090 | 246 | button_box = bar.buttons(actions, 10, gtk.BUTTONBOX_END, notebook, liststore) | ||
2091 | 247 | |||
2092 | 248 | ## vbox for search, notebook, buttonbar | ||
2093 | 249 | self.vbox = gtk.VBox() | ||
2094 | 250 | self.window.add(self.vbox) | ||
2095 | 251 | ## pack everytyhing in the vbox | ||
2096 | 252 | #self.vbox.pack_start(menu_bar, False, False, 0) ##menuBar | ||
2097 | 253 | self.vbox.pack_start(menu_search_hbox, False, False, 5) | ||
2098 | 254 | self.vbox.pack_start(expander, False, False, 5) | ||
2099 | 255 | self.vbox.pack_start(notebook, True, True, 10) | ||
2100 | 256 | self.vbox.pack_start(button_box, False, False, 5) | ||
2101 | 257 | |||
2102 | 258 | ## signals | ||
2103 | 259 | expander.connect('notify::expanded', self.expanded_cb, notebook, treeview, liststore) | ||
2104 | 260 | self.window.connect("delete_event", self.delete_event) | ||
2105 | 261 | add_tab_button.connect("clicked", tabs.add_tab, notebook) | ||
2106 | 262 | ## right click menu event capture | ||
2107 | 263 | treeview.connect ("button_press_event", bar.right_click, actions, treeview, notebook, liststore) | ||
2108 | 264 | |||
2109 | 265 | |||
2110 | 266 | #self.vte.grab_focus() | ||
2111 | 267 | self.window.show_all() | ||
2112 | 268 | return | ||
2113 | 269 | |||
2114 | 270 | def main(self): | ||
2115 | 271 | try: | ||
2116 | 272 | gtk.main() | ||
2117 | 273 | except KeyboardInterrupt: | ||
2118 | 274 | pass | ||
2119 | 275 | |||
2120 | 276 | def run(): | ||
2121 | 277 | |||
2122 | 278 | main_window = MainWindow() | ||
2123 | 279 | main_window.main() | ||
2124 | 0 | 280 | ||
2125 | === added directory 'data' | |||
2126 | === added file 'data/clicompanion.16.png' | |||
2127 | 1 | Binary files data/clicompanion.16.png 1970-01-01 00:00:00 +0000 and data/clicompanion.16.png 2010-11-30 16:11:27 +0000 differ | 281 | Binary files data/clicompanion.16.png 1970-01-01 00:00:00 +0000 and data/clicompanion.16.png 2010-11-30 16:11:27 +0000 differ |
2128 | === added file 'data/clicompanion.64.png' | |||
2129 | 2 | Binary files data/clicompanion.64.png 1970-01-01 00:00:00 +0000 and data/clicompanion.64.png 2010-11-30 16:11:27 +0000 differ | 282 | Binary files data/clicompanion.64.png 1970-01-01 00:00:00 +0000 and data/clicompanion.64.png 2010-11-30 16:11:27 +0000 differ |
2130 | === added file 'data/clicompanion.desktop' | |||
2131 | --- data/clicompanion.desktop 1970-01-01 00:00:00 +0000 | |||
2132 | +++ data/clicompanion.desktop 2010-11-30 16:11:27 +0000 | |||
2133 | @@ -0,0 +1,7 @@ | |||
2134 | 1 | [Desktop Entry] | ||
2135 | 2 | Name=CLI Companion | ||
2136 | 3 | Comment=Run and store terminal commands from a GUI | ||
2137 | 4 | Categories=Utility;GTK; | ||
2138 | 5 | Exec=clicompanion | ||
2139 | 6 | Icon=clicompanion | ||
2140 | 7 | Type=Application | ||
2141 | 0 | 8 | ||
2142 | === added file 'data/clicompanion2.config' | |||
2143 | --- data/clicompanion2.config 1970-01-01 00:00:00 +0000 | |||
2144 | +++ data/clicompanion2.config 2010-11-30 16:11:27 +0000 | |||
2145 | @@ -0,0 +1,48 @@ | |||
2146 | 1 | dpkg -l ?:package:Find version of a package | ||
2147 | 2 | df -h::file system disk space usage | ||
2148 | 3 | free -m::show RAM usage | ||
2149 | 4 | ps auxww | grep ?:process:displays information about the active process | ||
2150 | 5 | iwconfig::Display wireless network information | ||
2151 | 6 | ifconfig -a::displays the status of the currently active interfaces | ||
2152 | 7 | sudo iwlist::scan Scan Wireless networks | ||
2153 | 8 | sudo /etc/init.d/networking restart::Reset the Network | ||
2154 | 9 | lsb_release -a::What version of Ubuntu do I have? | ||
2155 | 10 | uname -a::What kernel am I running | ||
2156 | 11 | sudo apt-get update && sudo apt-get upgrade::Refresh update info and update all packages | ||
2157 | 12 | sudo apt-get clean::clear out all packages in /var/cache/apt/archives | ||
2158 | 13 | sudo apt-get autoclean::clear out obsolete packages(packages with a newer release) | ||
2159 | 14 | apt-cache search ?:package:Find information on a package (not installed) | ||
2160 | 15 | sudo lshw::List hardware | ||
2161 | 16 | lspci::list all PCI devices | ||
2162 | 17 | aplay -l::List all soundcards and digital audio devices | ||
2163 | 18 | cat ?:path:Read File & Print to Standard Output | ||
2164 | 19 | ls ? :path:List Folders Contents | ||
2165 | 20 | ls -lSr ?:path:Show files by size, biggest last | ||
2166 | 21 | mv ?:path:Move (Rename) Files | ||
2167 | 22 | cp ?:path:Copy Files | ||
2168 | 23 | sudo lspci::attached PCI devices | ||
2169 | 24 | chmod ? ?:permissions, file:Change access permissions, change mode | ||
2170 | 25 | chown ? ?:owner,group, file:Change the owner and/or group of each given file | ||
2171 | 26 | dmesg::Print kernel & driver messages | ||
2172 | 27 | history::Command History | ||
2173 | 28 | locate ?:file:Find files (updatedb to update DB) | ||
2174 | 29 | sudo updatedb::update the database for locate | ||
2175 | 30 | which ?:command:Show full path name of command | ||
2176 | 31 | find -maxdepth 1 -type f | xargs grep -F ?:string:Search all regular files for 'string' in this dir | ||
2177 | 32 | gpg -c ?:file:Encypt a file | ||
2178 | 33 | gpg ?:file.gpg:Decrypt a file | ||
2179 | 34 | tar -xjf ?:archive.tar:Extract all files from archive.tar | ||
2180 | 35 | tar -czf ?:Destination.tar.gz Source:Create Destination from Source | ||
2181 | 36 | iostat::cpu and I/O statistics | ||
2182 | 37 | netstat::Print network connections and interface statistics | ||
2183 | 38 | sudo fdisk -l ?:disk:List partition tables for specified devices | ||
2184 | 39 | sudo ufw enable::Enable netfilter firewall | ||
2185 | 40 | sudo ufw allow ?:port:Open a port in netfilter firewall | ||
2186 | 41 | sudo ufw deny ?:port:Close a port in netfilter firewall | ||
2187 | 42 | sudo ufw disable::Disable netfilter firewall | ||
2188 | 43 | cat ? ? | sort | uniq > ? :file1, file2, file3:combine, sort and remove duplicates from 2 files | ||
2189 | 44 | mkisofs -V LABEL -r dir | gzip > ?:isoname.iso.gz:Create cdrom image(iso) from contents of directory(pwd) | ||
2190 | 45 | cdrecord -v dev=/dev/cdrom -audio -pad *.wav::Make audio CD from all wavs in current dir(pwd) | ||
2191 | 46 | dpkg-query -W -f='${Installed-Size;10}\t${Package}\n' | sort -k1,1n::List all installed packages by size | ||
2192 | 47 | tail -f /var/log/messages::Monitor messages log file | ||
2193 | 48 | apropos ?:command or package:search the manual page names and descriptions | ||
2194 | 0 | 49 | ||
2195 | === added file 'setup.py' | |||
2196 | --- setup.py 1970-01-01 00:00:00 +0000 | |||
2197 | +++ setup.py 2010-11-30 16:11:27 +0000 | |||
2198 | @@ -0,0 +1,42 @@ | |||
2199 | 1 | #!/usr/bin/env python | ||
2200 | 2 | # | ||
2201 | 3 | # Copyright 2010 Duane Hinnen | ||
2202 | 4 | # | ||
2203 | 5 | # | ||
2204 | 6 | # This program is free software: you can redistribute it and/or modify it | ||
2205 | 7 | # under the terms of the GNU General Public License version 3, as published | ||
2206 | 8 | # by the Free Software Foundation. | ||
2207 | 9 | # | ||
2208 | 10 | # This program is distributed in the hope that it will be useful, but | ||
2209 | 11 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
2210 | 12 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
2211 | 13 | # PURPOSE. See the GNU General Public License for more details. | ||
2212 | 14 | # | ||
2213 | 15 | # You should have received a copy of the GNU General Public License along | ||
2214 | 16 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2215 | 17 | # | ||
2216 | 18 | # | ||
2217 | 19 | |||
2218 | 20 | import glob | ||
2219 | 21 | from distutils.core import setup | ||
2220 | 22 | from DistUtilsExtra.command import * | ||
2221 | 23 | |||
2222 | 24 | |||
2223 | 25 | |||
2224 | 26 | setup( name='clicompanion', | ||
2225 | 27 | version='0.1.0', | ||
2226 | 28 | description='Run Terminal commands from a GUI. Store commands for later use.', | ||
2227 | 29 | author='Duane Hinnen', | ||
2228 | 30 | author_email='duanedesign@gmail.com', | ||
2229 | 31 | scripts=['clicompanion'], | ||
2230 | 32 | packages=['clicompanionlib'], | ||
2231 | 33 | data_files=[('/etc/clicompanion.d/', ['data/clicompanion2.config']), | ||
2232 | 34 | ('/usr/share/pixmaps', ['data/clicompanion.16.png']), | ||
2233 | 35 | ('/usr/share/applications', ['data/clicompanion.desktop']), | ||
2234 | 36 | ('share/clicompanion/locale/', glob.glob('locale/*/LC_MESSAGES/*.mo')), | ||
2235 | 37 | ], | ||
2236 | 38 | |||
2237 | 39 | cmdclass = { 'build' : build_extra.build_extra, | ||
2238 | 40 | 'build_i18n' : build_i18n.build_i18n, | ||
2239 | 41 | }, | ||
2240 | 42 | ) |
This is actually clicompanion. seperate. I had to create another branch of trunk and do the merge correctly. This is what the clicompanion. seperate. merge is.