-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathopen_guake_here.py
88 lines (77 loc) · 3.73 KB
/
open_guake_here.py
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
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""This module adds a menu item to the nautilus right-click menu which allows to Open the Terminal
on the Selected Folder/Current Directory at predefined Geometry just through the right-clicking"""
# open-terminal-geometry.py version 3.0
#
# Copyright 2009-2011 Giuseppe Penone <[email protected]>
#
# 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 2 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
from gi.repository import Nautilus, GObject, Gtk, GdkPixbuf
import urllib, os, subprocess
import locale, gettext
APP_NAME = "nautilus-pyextensions"
LOCALE_PATH = "/usr/share/locale/"
GEOMETRY = "100x25"
ICONPATH = "/usr/share/icons/gnome/48x48/apps/terminal.png"
# internationalization
locale.setlocale(locale.LC_ALL, '')
gettext.bindtextdomain(APP_NAME, LOCALE_PATH)
gettext.textdomain(APP_NAME)
_ = gettext.gettext
# post internationalization code starts here
class OpenTerminalGeometry(GObject.GObject, Nautilus.MenuProvider):
"""Implements the 'Open Guake here' extension to the nautilus right-click menu"""
def __init__(self):
"""Nautilus crashes if a plugin doesn't implement the __init__ method"""
try:
factory = Gtk.IconFactory()
pixbuf = GdkPixbuf.Pixbuf.new_from_file(ICONPATH)
iconset = Gtk.IconSet.new_from_pixbuf(pixbuf)
factory.add("terminal", iconset)
factory.add_default()
except: pass
def run(self, menu, selected):
"""Runs the Open guake here on the given Directory"""
uri_raw = selected.get_uri()
if len(uri_raw) < 7: return
cur_dir = urllib.unquote(uri_raw[7:]).decode('utf8')
if os.path.isfile(cur_dir): cur_dir = os.path.dirname(cur_dir)
subprocess.call([
u'guake',
u'--new-tab=%s' % cur_dir,
u'--show',
u'--rename-current-tab=%s' % os.path.basename(cur_dir)
])
def get_file_items(self, window, sel_items):
"""Adds the 'Open guake here' menu item to the Nautilus right-click menu,
connects its 'activate' signal to the 'run' method passing the selected Directory/File"""
if len(sel_items) != 1 or sel_items[0].get_uri_scheme() != 'file': return
item = Nautilus.MenuItem(name='NautilusPython::terminal',
label=_('Open Guake Here'),
tip=_('Open Guake on the Current/Selected Directory'),
icon='terminal')
item.connect('activate', self.run, sel_items[0])
return [item]
def get_background_items(self, window, current_directory):
"""Adds the 'Open guake here' menu item to the Nautilus right-click menu,
connects its 'activate' signal to the 'run' method passing the current Directory"""
item = Nautilus.MenuItem(name='NautilusPython::terminal',
label=_('Open Guake Here'),
tip=_('Open Guake on the Current Directory'),
icon='terminal')
item.connect('activate', self.run, current_directory)
return [item]