3
# Ubuntu Tweak - PyGTK based desktop configuration tool
5
# Copyright (C) 2007-2008 TualatriX <tualatrix@gmail.com>
7
# Ubuntu Tweak is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2 of the License, or
10
# (at your option) any later version.
12
# Ubuntu Tweak is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with Ubuntu Tweak; if not, write to the Free Software Foundation, Inc.,
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
30
from ubuntutweak.modules import TweakModule
31
from ubuntutweak.utils import icon
32
from ubuntutweak.common.consts import DATA_DIR, CONFIG_ROOT
33
from ubuntutweak.ui import DirView, FlatView
34
from ubuntutweak.ui.dialogs import WarningDialog
36
log = logging.getLogger('Script')
45
class AbstractScripts:
46
system_dir = os.path.join(CONFIG_ROOT, 'scripts')
48
#TODO maybe remove these code in the future
49
old_system_dir = os.path.join(os.path.expanduser('~'), '.ubuntu-tweak/scripts')
50
if os.path.exists(old_system_dir) and not os.path.exists(system_dir):
51
log.debug('Move the old_system_dir to new system_dir')
52
shutil.move(old_system_dir, system_dir)
54
user_dir = os.path.join(os.getenv('HOME'), '.gnome2', 'nautilus-scripts')
56
class DefaultScripts(AbstractScripts):
57
'''This class use to create the default scripts'''
59
'create-launcher': _('Create Launcher ...'),
60
'copy-to': _('Copy to ...'),
61
'copy-to-desktop': _('Copy to Desktop'),
62
'copy-to-download': _('Copy to Download'),
63
'copy-to-home': _('Copy to Home'),
64
'check-md5-sum': _('Check md5 sum'),
65
'compress-pdf': _('Compress PDF'),
66
'move-to': _('Move to ...'),
67
'move-to-desktop': _('Move to Desktop'),
68
'move-to-download': _('Move to Download'),
69
'move-to-home': _('Move to Home'),
70
'hardlink-to': _('Create hardlink to ...'),
71
'link-to': _('Link to ...'),
72
'link-to-desktop': _('Link to Desktop'),
73
'link-to-download': _('Link to Download'),
74
'link-to-home': _('Link to Home'),
75
'open-with-your-favourite-text-editor': _('Open with your favourite text editor'),
76
'open-with-your-favourite-text-editor-as-root': _('Open with your favourite text editor (as root)'),
77
'browse-as-root': _('Browse as root'),
78
'search-in-current': _('Search in current folder'),
79
'convert-image-to-jpg': _('Convert image to JPG'),
80
'convert-image-to-png': _('Convert image to PNG'),
81
'convert-image-to-gif': _('Convert image to GIF'),
82
'set-image-as-wallpaper': _('Set image as wallpaper'),
83
'make-hard-shadow-to-image': _('Make hard shadow to image'),
87
if not os.path.exists(self.system_dir):
88
os.makedirs(self.system_dir)
89
for file, des in self.scripts.items():
91
if not os.path.exists(os.path.join(self.system_dir,realname)):
92
shutil.copy(os.path.join(DATA_DIR, 'scripts/%s' % file), os.path.join(self.system_dir,realname))
95
if not os.path.exists(self.system_dir):
97
if os.path.isdir(self.system_dir):
98
for root, dirs, files in os.walk(self.system_dir, topdown=False):
100
os.remove(os.path.join(root, name))
102
os.rmdir(os.path.join(root, name))
103
os.rmdir(self.system_dir)
105
os.unlink(self.system_dir)
108
class EnableScripts(DirView, AbstractScripts):
109
'''The treeview to display the enable scripts'''
110
type = _('Enabled Scripts')
113
DirView.__init__(self, self.user_dir)
115
def do_update_model(self, dir, iter):
116
for item in os.listdir(dir):
117
fullname = os.path.join(dir, item)
118
pixbuf = icon.guess_from_path(fullname)
120
child_iter = self.model.append(iter)
121
self.model.set(child_iter,
123
COLUMN_TITLE, os.path.basename(fullname),
124
COLUMN_PATH, fullname,
125
COLUMN_EDITABLE, False)
127
if os.path.isdir(fullname):
128
self.do_update_model(fullname, child_iter)
130
if not os.access(fullname, os.X_OK):
132
os.chmod(fullname, stat.S_IRWXU)
136
class DisableScripts(FlatView, AbstractScripts):
137
'''The treeview to display the system template'''
138
type = _('Disabled Scripts')
141
FlatView.__init__(self, self.system_dir, self.user_dir)
143
class Scripts(TweakModule, AbstractScripts):
144
__title__ = _('Manage Scripts')
145
__desc__ = _("Scripts can be used to complete all kinds of tasks.\n"
146
"You can drag and drop scripts here from File Manager.\n"
147
"'Scripts' will then be added to the context menu.")
148
__icon__ = 'text-x-script'
149
__category__ = 'personal'
150
__desktop__ = ['gnome', 'une']
153
TweakModule.__init__(self)
155
self.default = DefaultScripts()
158
hbox = gtk.HBox(False, 10)
161
sw = gtk.ScrolledWindow()
162
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
165
self.enable_scripts = EnableScripts()
166
sw.add(self.enable_scripts)
168
sw = gtk.ScrolledWindow()
169
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
172
self.disable_scripts = DisableScripts()
173
sw.add(self.disable_scripts)
175
hbox = gtk.HBox(False, 0)
176
self.add_start(hbox, False, False, 0)
178
button = gtk.Button(_('Rebuild System Scripts'))
179
button.connect('clicked', self.on_rebuild_clicked)
180
hbox.pack_end(button, False, False, 5)
182
self.enable_scripts.connect('drag_data_received', self.on_enable_drag_data_received)
183
self.enable_scripts.connect('deleted', self.on_enable_deleted)
184
self.disable_scripts.connect('drag_data_received', self.on_disable_drag_data_received)
186
def on_enable_deleted(self, widget):
187
self.disable_scripts.update_model()
189
def on_enable_drag_data_received(self, treeview, context, x, y, selection, info, etime):
190
self.disable_scripts.update_model()
192
def on_disable_drag_data_received(self, treeview, context, x, y, selection, info, etime):
193
self.enable_scripts.update_model()
195
def on_rebuild_clicked(self, widget):
196
dialog = WarningDialog(_('This will delete all disabled scripts.\nDo you wish to continue?'))
197
if dialog.run() == gtk.RESPONSE_YES:
198
self.default.remove()
199
self.default.create()
200
self.disable_scripts.update_model()
203
def config_test(self):
204
if not os.path.exists(self.system_dir):
205
self.default.create()