File: open_terminal_here.py

package info (click to toggle)
docky 2.0.6-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 6,280 kB
  • ctags: 5,001
  • sloc: cs: 30,675; python: 1,670; sh: 1,276; makefile: 900; xml: 16
file content (75 lines) | stat: -rwxr-xr-x 2,157 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python

#  
#  Copyright (C) 2009 Jason Smith
# 
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
# 
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
# 
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import atexit
import gconf
import gobject
import glib
import sys
import urllib
import os

try:
	from docky.docky import DockyItem, DockySink
	from signal import signal, SIGTERM
	from sys import exit
except ImportError, e:
	exit()

class DockyTerminalItem(DockyItem):
	def __init__(self, path):
		DockyItem.__init__(self, path)
		
		client = gconf.client_get_default()
		self.terminal = client.get_string("/desktop/gnome/applications/terminal/exec")
		if self.terminal == None:
			self.terminal = "gnome-terminal"
		
		self.path = urllib.unquote(str(self.iface.GetUri ()[7:]))
		if not os.path.isdir (self.path):
			self.path = os.path.dirname (self.path)
		
		self.add_menu_item("Open Terminal Here", "terminal")

	def menu_pressed(self, menu_id):
		if self.id_map[menu_id] == "Open Terminal Here":
			os.chdir(self.path);
			os.system ('%s &' % self.terminal)
		
	def add_menu_item(self, name, icon):
		menu_id = self.iface.AddMenuItem(name, icon, "actions")
		self.id_map[menu_id] = name
			
class DockyTerminalSink(DockySink):
	def item_path_found(self, pathtoitem, item):
		if item.GetOwnsUri() and item.GetUri().startswith ("file://"):
			self.items[pathtoitem] = DockyTerminalItem(pathtoitem)

dockysink = DockyTerminalSink()

def cleanup ():
	dockysink.dispose ()

if __name__ == "__main__":
	mainloop = gobject.MainLoop(is_running=True)

	atexit.register (cleanup)
	signal(SIGTERM, lambda signum, stack_frame: exit(1))

	mainloop.run()