~ubuntu-branches/debian/sid/docky/sid

« back to all changes in this revision

Viewing changes to scripts/open_terminal_here.py

  • Committer: Package Import Robot
  • Author(s): Rico Tzschichholz
  • Date: 2012-01-19 19:03:38 UTC
  • mfrom: (1.1.14) (10.1.9 experimental)
  • Revision ID: package-import@ubuntu.com-20120119190338-n44q7tmqsrkudvk7
Tags: 2.1.3-2
* Upload to unstable
* debian/watch:
  + Look for xz tarballs from now on

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
 
3
 
#  
4
 
#  Copyright (C) 2009 Jason Smith
5
 
6
 
#  This program is free software: you can redistribute it and/or modify
7
 
#  it under the terms of the GNU General Public License as published by
8
 
#  the Free Software Foundation, either version 3 of the License, or
9
 
#  (at your option) any later version.
10
 
11
 
#  This program is distributed in the hope that it will be useful,
12
 
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
#  GNU General Public License for more details.
15
 
16
 
#  You should have received a copy of the GNU General Public License
17
 
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 
#
19
 
 
20
 
import atexit
21
 
import gconf
22
 
import gobject
23
 
import glib
24
 
import sys
25
 
import urllib
26
 
import os
27
 
 
28
 
try:
29
 
        from docky.docky import DockyItem, DockySink
30
 
        from signal import signal, SIGTERM
31
 
        from sys import exit
32
 
except ImportError, e:
33
 
        exit()
34
 
 
35
 
class DockyTerminalItem(DockyItem):
36
 
        def __init__(self, path):
37
 
                DockyItem.__init__(self, path)
38
 
                
39
 
                client = gconf.client_get_default()
40
 
                self.terminal = client.get_string("/desktop/gnome/applications/terminal/exec")
41
 
                if self.terminal == None:
42
 
                        self.terminal = "gnome-terminal"
43
 
                
44
 
                self.path = urllib.unquote(str(self.iface.GetUri ()[7:]))
45
 
                if not os.path.isdir (self.path):
46
 
                        self.path = os.path.dirname (self.path)
47
 
                
48
 
                self.add_menu_item("Open Terminal Here", "terminal")
49
 
 
50
 
        def menu_pressed(self, menu_id):
51
 
                if self.id_map[menu_id] == "Open Terminal Here":
52
 
                        oldDir = os.getcwd()
53
 
                        os.chdir(self.path)
54
 
                        os.system ('%s &' % self.terminal)
55
 
                        os.chdir(oldDir)
56
 
                
57
 
        def add_menu_item(self, name, icon):
58
 
                menu_id = self.iface.AddMenuItem(name, icon, "actions")
59
 
                self.id_map[menu_id] = name
60
 
                        
61
 
class DockyTerminalSink(DockySink):
62
 
        def item_path_found(self, pathtoitem, item):
63
 
                if item.GetOwnsUri() and item.GetUri().startswith ("file://"):
64
 
                        self.items[pathtoitem] = DockyTerminalItem(pathtoitem)
65
 
 
66
 
dockysink = DockyTerminalSink()
67
 
 
68
 
def cleanup ():
69
 
        dockysink.dispose ()
70
 
 
71
 
if __name__ == "__main__":
72
 
        mainloop = gobject.MainLoop(is_running=True)
73
 
 
74
 
        atexit.register (cleanup)
75
 
        signal(SIGTERM, lambda signum, stack_frame: exit(1))
76
 
 
77
 
        mainloop.run()