2010-01-05 22:29:02 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# Terminator by Chris Jones <cmsj@tenshu.net>
|
2010-01-05 17:57:46 +00:00
|
|
|
# GPL v2 only
|
2010-01-05 22:29:02 +00:00
|
|
|
"""custom_commands.py - Terminator Plugin to add custom command menu entries"""
|
2010-01-05 17:57:46 +00:00
|
|
|
import sys
|
|
|
|
import os
|
2010-01-05 22:29:02 +00:00
|
|
|
|
|
|
|
# Fix imports when testing this file directly
|
2010-01-05 17:57:46 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.path.append( os.path.join(os.path.dirname(__file__), "../.."))
|
2010-01-05 22:29:02 +00:00
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
from gi.repository import Gtk
|
|
|
|
from gi.repository import GObject
|
2010-01-05 17:57:46 +00:00
|
|
|
import terminatorlib.plugin as plugin
|
2010-01-05 22:29:02 +00:00
|
|
|
from terminatorlib.config import Config
|
2010-01-05 17:57:46 +00:00
|
|
|
from terminatorlib.translation import _
|
2013-10-29 13:57:01 +00:00
|
|
|
from terminatorlib.util import get_config_dir, err, dbg
|
2010-01-05 17:57:46 +00:00
|
|
|
|
|
|
|
(CC_COL_ENABLED, CC_COL_NAME, CC_COL_COMMAND) = range(0,3)
|
|
|
|
|
2010-06-10 15:56:17 +00:00
|
|
|
# Every plugin you want Terminator to load *must* be listed in 'AVAILABLE'
|
|
|
|
AVAILABLE = ['CustomCommandsMenu']
|
2010-01-05 17:57:46 +00:00
|
|
|
|
2010-01-05 22:29:02 +00:00
|
|
|
class CustomCommandsMenu(plugin.MenuItem):
|
|
|
|
"""Add custom commands to the terminal menu"""
|
2010-01-05 17:57:46 +00:00
|
|
|
capabilities = ['terminal_menu']
|
2011-12-28 22:00:52 +00:00
|
|
|
cmd_list = {}
|
2010-01-05 17:57:46 +00:00
|
|
|
conf_file = os.path.join(get_config_dir(),"custom_commands")
|
|
|
|
|
|
|
|
def __init__( self):
|
2013-07-16 17:56:14 +00:00
|
|
|
config = Config()
|
|
|
|
sections = config.plugin_get_config(self.__class__.__name__)
|
|
|
|
if not isinstance(sections, dict):
|
|
|
|
return
|
|
|
|
noord_cmds = []
|
|
|
|
for part in sections:
|
|
|
|
s = sections[part]
|
|
|
|
if not (s.has_key("name") and s.has_key("command")):
|
|
|
|
print "CustomCommandsMenu: Ignoring section %s" % s
|
|
|
|
continue
|
|
|
|
name = s["name"]
|
|
|
|
command = s["command"]
|
|
|
|
enabled = s["enabled"] and s["enabled"] or False
|
|
|
|
if s.has_key("position"):
|
|
|
|
self.cmd_list[int(s["position"])] = {'enabled' : enabled,
|
|
|
|
'name' : name,
|
|
|
|
'command' : command
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
noord_cmds.append(
|
2010-01-05 17:57:46 +00:00
|
|
|
{'enabled' : enabled,
|
|
|
|
'name' : name,
|
|
|
|
'command' : command
|
|
|
|
}
|
|
|
|
)
|
2011-12-28 22:00:52 +00:00
|
|
|
for cmd in noord_cmds:
|
|
|
|
self.cmd_list[len(self.cmd_list)] = cmd
|
|
|
|
|
2010-01-05 17:57:46 +00:00
|
|
|
def callback(self, menuitems, menu, terminal):
|
|
|
|
"""Add our menu items to the menu"""
|
2014-09-19 14:08:08 +00:00
|
|
|
item = Gtk.MenuItem(_('Custom Commands'))
|
2010-01-05 17:57:46 +00:00
|
|
|
menuitems.append(item)
|
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
submenu = Gtk.Menu()
|
2010-01-05 17:57:46 +00:00
|
|
|
item.set_submenu(submenu)
|
|
|
|
|
2015-02-25 14:25:41 +00:00
|
|
|
menuitem = Gtk.MenuItem(_('Preferences'))
|
2010-01-05 17:57:46 +00:00
|
|
|
menuitem.connect("activate", self.configure)
|
|
|
|
submenu.append(menuitem)
|
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
menuitem = Gtk.SeparatorMenuItem()
|
2010-01-05 17:57:46 +00:00
|
|
|
submenu.append(menuitem)
|
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
theme = Gtk.IconTheme()
|
2011-12-28 22:00:52 +00:00
|
|
|
for command in [ self.cmd_list[key] for key in sorted(self.cmd_list.keys()) ] :
|
2010-01-05 17:57:46 +00:00
|
|
|
if not command['enabled']:
|
|
|
|
continue
|
|
|
|
exe = command['command'].split(' ')[0]
|
2014-09-19 14:08:08 +00:00
|
|
|
iconinfo = theme.choose_icon([exe], Gtk.IconSize.MENU, Gtk.IconLookupFlags.USE_BUILTIN)
|
2010-01-05 17:57:46 +00:00
|
|
|
if iconinfo:
|
2014-09-19 14:08:08 +00:00
|
|
|
image = Gtk.Image()
|
|
|
|
image.set_from_icon_name(exe, Gtk.IconSize.MENU)
|
|
|
|
menuitem = Gtk.ImageMenuItem(command['name'])
|
2010-01-05 17:57:46 +00:00
|
|
|
menuitem.set_image(image)
|
|
|
|
else:
|
2014-09-19 14:08:08 +00:00
|
|
|
menuitem = Gtk.MenuItem(command["name"])
|
2015-02-25 16:30:37 +00:00
|
|
|
terminals = terminal.terminator.get_target_terms(terminal)
|
|
|
|
menuitem.connect("activate", self._execute, {'terminals' : terminals, 'command' : command['command'] })
|
2010-01-05 17:57:46 +00:00
|
|
|
submenu.append(menuitem)
|
|
|
|
|
|
|
|
def _save_config(self):
|
2010-01-05 22:29:02 +00:00
|
|
|
config = Config()
|
2011-12-28 22:00:52 +00:00
|
|
|
config.plugin_del_config(self.__class__.__name__)
|
2010-01-05 17:57:46 +00:00
|
|
|
i = 0
|
2011-12-28 22:00:52 +00:00
|
|
|
for command in [ self.cmd_list[key] for key in sorted(self.cmd_list.keys()) ] :
|
|
|
|
enabled = command['enabled']
|
|
|
|
name = command['name']
|
|
|
|
command = command['command']
|
2010-01-05 22:29:02 +00:00
|
|
|
|
|
|
|
item = {}
|
|
|
|
item['enabled'] = enabled
|
|
|
|
item['name'] = name
|
|
|
|
item['command'] = command
|
2011-12-28 22:00:52 +00:00
|
|
|
item['position'] = i
|
2010-01-05 17:57:46 +00:00
|
|
|
|
2010-01-05 22:29:02 +00:00
|
|
|
config.plugin_set(self.__class__.__name__, name, item)
|
|
|
|
i = i + 1
|
2011-12-28 22:00:52 +00:00
|
|
|
config.save()
|
2010-01-05 17:57:46 +00:00
|
|
|
|
|
|
|
def _execute(self, widget, data):
|
|
|
|
command = data['command']
|
2015-02-25 16:30:37 +00:00
|
|
|
if command[-1] != '\n':
|
2010-01-05 17:57:46 +00:00
|
|
|
command = command + '\n'
|
2015-02-25 16:30:37 +00:00
|
|
|
for terminal in data['terminals']:
|
|
|
|
terminal.vte.feed_child(command, len(command))
|
2010-01-05 17:57:46 +00:00
|
|
|
|
|
|
|
def configure(self, widget, data = None):
|
|
|
|
ui = {}
|
2014-09-19 14:08:08 +00:00
|
|
|
dbox = Gtk.Dialog(
|
2010-01-05 17:57:46 +00:00
|
|
|
_("Custom Commands Configuration"),
|
|
|
|
None,
|
2014-09-19 14:08:08 +00:00
|
|
|
Gtk.DialogFlags.MODAL,
|
2010-01-05 17:57:46 +00:00
|
|
|
(
|
2014-09-19 14:08:08 +00:00
|
|
|
Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,
|
|
|
|
Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT
|
2010-01-05 17:57:46 +00:00
|
|
|
)
|
|
|
|
)
|
2013-10-29 13:57:01 +00:00
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
icon_theme = Gtk.IconTheme()
|
2013-10-29 13:57:01 +00:00
|
|
|
try:
|
|
|
|
icon = icon_theme.load_icon('terminator-custom-commands', 48, 0)
|
2014-09-19 14:08:08 +00:00
|
|
|
except (NameError, GObject.GError):
|
2013-10-29 13:57:01 +00:00
|
|
|
dbg('Unable to load 48px Terminator preferences icon')
|
2014-09-19 14:08:08 +00:00
|
|
|
icon = dbox.render_icon(Gtk.STOCK_DIALOG_INFO, Gtk.IconSize.BUTTON)
|
2013-10-29 13:57:01 +00:00
|
|
|
dbox.set_icon(icon)
|
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
store = Gtk.ListStore(bool, str, str)
|
2010-01-05 17:57:46 +00:00
|
|
|
|
2011-12-28 22:00:52 +00:00
|
|
|
for command in [ self.cmd_list[key] for key in sorted(self.cmd_list.keys()) ]:
|
2010-01-05 17:57:46 +00:00
|
|
|
store.append([command['enabled'], command['name'], command['command']])
|
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
treeview = Gtk.TreeView(store)
|
2010-01-05 17:57:46 +00:00
|
|
|
#treeview.connect("cursor-changed", self.on_cursor_changed, ui)
|
|
|
|
selection = treeview.get_selection()
|
2014-09-19 14:08:08 +00:00
|
|
|
selection.set_mode(Gtk.SelectionMode.SINGLE)
|
2010-01-05 17:57:46 +00:00
|
|
|
selection.connect("changed", self.on_selection_changed, ui)
|
|
|
|
ui['treeview'] = treeview
|
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
renderer = Gtk.CellRendererToggle()
|
2010-01-05 17:57:46 +00:00
|
|
|
renderer.connect('toggled', self.on_toggled, ui)
|
2014-09-19 14:08:08 +00:00
|
|
|
column = Gtk.TreeViewColumn("Enabled", renderer, active=CC_COL_ENABLED)
|
2010-01-05 17:57:46 +00:00
|
|
|
treeview.append_column(column)
|
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
renderer = Gtk.CellRendererText()
|
|
|
|
column = Gtk.TreeViewColumn("Name", renderer, text=CC_COL_NAME)
|
2010-01-05 17:57:46 +00:00
|
|
|
treeview.append_column(column)
|
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
renderer = Gtk.CellRendererText()
|
|
|
|
column = Gtk.TreeViewColumn("Command", renderer, text=CC_COL_COMMAND)
|
2010-01-05 17:57:46 +00:00
|
|
|
treeview.append_column(column)
|
|
|
|
|
2015-02-25 14:25:41 +00:00
|
|
|
scroll_window = Gtk.ScrolledWindow()
|
|
|
|
scroll_window.set_size_request(500, 250)
|
|
|
|
scroll_window.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
|
|
|
|
scroll_window.add_with_viewport(treeview)
|
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
hbox = Gtk.HBox()
|
2015-02-25 14:25:41 +00:00
|
|
|
hbox.pack_start(scroll_window, True, True, 0)
|
2014-09-19 14:08:08 +00:00
|
|
|
dbox.vbox.pack_start(hbox, True, True, 0)
|
2010-01-05 17:57:46 +00:00
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
button_box = Gtk.VBox()
|
2010-01-05 17:57:46 +00:00
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
button = Gtk.Button(stock=Gtk.STOCK_GOTO_TOP)
|
2015-02-25 14:25:41 +00:00
|
|
|
button_box.pack_start(button, False, True, 0)
|
2010-01-05 17:57:46 +00:00
|
|
|
button.connect("clicked", self.on_goto_top, ui)
|
|
|
|
button.set_sensitive(False)
|
|
|
|
ui['button_top'] = button
|
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
button = Gtk.Button(stock=Gtk.STOCK_GO_UP)
|
2015-02-25 14:25:41 +00:00
|
|
|
button_box.pack_start(button, False, True, 0)
|
2010-01-05 17:57:46 +00:00
|
|
|
button.connect("clicked", self.on_go_up, ui)
|
|
|
|
button.set_sensitive(False)
|
|
|
|
ui['button_up'] = button
|
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
button = Gtk.Button(stock=Gtk.STOCK_GO_DOWN)
|
2015-02-25 14:25:41 +00:00
|
|
|
button_box.pack_start(button, False, True, 0)
|
2010-01-05 17:57:46 +00:00
|
|
|
button.connect("clicked", self.on_go_down, ui)
|
|
|
|
button.set_sensitive(False)
|
|
|
|
ui['button_down'] = button
|
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
button = Gtk.Button(stock=Gtk.STOCK_GOTO_LAST)
|
2015-02-25 14:25:41 +00:00
|
|
|
button_box.pack_start(button, False, True, 0)
|
2010-01-05 17:57:46 +00:00
|
|
|
button.connect("clicked", self.on_goto_last, ui)
|
|
|
|
button.set_sensitive(False)
|
|
|
|
ui['button_last'] = button
|
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
button = Gtk.Button(stock=Gtk.STOCK_NEW)
|
2015-02-25 14:25:41 +00:00
|
|
|
button_box.pack_start(button, False, True, 0)
|
2010-01-05 17:57:46 +00:00
|
|
|
button.connect("clicked", self.on_new, ui)
|
|
|
|
ui['button_new'] = button
|
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
button = Gtk.Button(stock=Gtk.STOCK_EDIT)
|
2015-02-25 14:25:41 +00:00
|
|
|
button_box.pack_start(button, False, True, 0)
|
2010-01-05 17:57:46 +00:00
|
|
|
button.set_sensitive(False)
|
|
|
|
button.connect("clicked", self.on_edit, ui)
|
|
|
|
ui['button_edit'] = button
|
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
button = Gtk.Button(stock=Gtk.STOCK_DELETE)
|
2015-02-25 14:25:41 +00:00
|
|
|
button_box.pack_start(button, False, True, 0)
|
2010-01-05 17:57:46 +00:00
|
|
|
button.connect("clicked", self.on_delete, ui)
|
|
|
|
button.set_sensitive(False)
|
|
|
|
ui['button_delete'] = button
|
|
|
|
|
2013-07-16 17:56:14 +00:00
|
|
|
|
|
|
|
|
2015-02-25 14:25:41 +00:00
|
|
|
hbox.pack_start(button_box, False, True, 0)
|
2010-01-05 17:57:46 +00:00
|
|
|
dbox.show_all()
|
|
|
|
res = dbox.run()
|
2014-09-19 14:08:08 +00:00
|
|
|
if res == Gtk.ResponseType.ACCEPT:
|
2011-12-28 22:00:52 +00:00
|
|
|
self.update_cmd_list(store)
|
|
|
|
self._save_config()
|
|
|
|
dbox.destroy()
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
def update_cmd_list(self, store):
|
2010-01-05 17:57:46 +00:00
|
|
|
iter = store.get_iter_first()
|
2011-12-28 22:00:52 +00:00
|
|
|
self.cmd_list = {}
|
|
|
|
i=0
|
2010-01-05 17:57:46 +00:00
|
|
|
while iter:
|
|
|
|
(enabled, name, command) = store.get(iter,
|
|
|
|
CC_COL_ENABLED,
|
|
|
|
CC_COL_NAME,
|
|
|
|
CC_COL_COMMAND)
|
2011-12-28 22:00:52 +00:00
|
|
|
self.cmd_list[i] = {'enabled' : enabled,
|
2010-01-05 17:57:46 +00:00
|
|
|
'name': name,
|
|
|
|
'command' : command}
|
|
|
|
iter = store.iter_next(iter)
|
2011-12-28 22:00:52 +00:00
|
|
|
i = i + 1
|
2010-01-05 17:57:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
def on_toggled(self, widget, path, data):
|
|
|
|
treeview = data['treeview']
|
|
|
|
store = treeview.get_model()
|
|
|
|
iter = store.get_iter(path)
|
|
|
|
(enabled, name, command) = store.get(iter,
|
|
|
|
CC_COL_ENABLED,
|
|
|
|
CC_COL_NAME,
|
|
|
|
CC_COL_COMMAND
|
|
|
|
)
|
|
|
|
store.set_value(iter, CC_COL_ENABLED, not enabled)
|
2011-12-28 22:00:52 +00:00
|
|
|
|
2010-01-05 17:57:46 +00:00
|
|
|
|
|
|
|
def on_selection_changed(self,selection, data=None):
|
|
|
|
treeview = selection.get_tree_view()
|
|
|
|
(model, iter) = selection.get_selected()
|
|
|
|
data['button_top'].set_sensitive(iter is not None)
|
|
|
|
data['button_up'].set_sensitive(iter is not None)
|
|
|
|
data['button_down'].set_sensitive(iter is not None)
|
|
|
|
data['button_last'].set_sensitive(iter is not None)
|
|
|
|
data['button_edit'].set_sensitive(iter is not None)
|
|
|
|
data['button_delete'].set_sensitive(iter is not None)
|
|
|
|
|
|
|
|
def _create_command_dialog(self, enabled_var = False, name_var = "", command_var = ""):
|
2014-09-19 14:08:08 +00:00
|
|
|
dialog = Gtk.Dialog(
|
2010-01-05 17:57:46 +00:00
|
|
|
_("New Command"),
|
|
|
|
None,
|
2014-09-19 14:08:08 +00:00
|
|
|
Gtk.DialogFlags.MODAL,
|
2010-01-05 17:57:46 +00:00
|
|
|
(
|
2014-09-19 14:08:08 +00:00
|
|
|
Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,
|
|
|
|
Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT
|
2010-01-05 17:57:46 +00:00
|
|
|
)
|
|
|
|
)
|
2014-09-19 14:08:08 +00:00
|
|
|
table = Gtk.Table(3, 2)
|
2010-01-05 17:57:46 +00:00
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
label = Gtk.Label(label=_("Enabled:"))
|
2010-01-05 17:57:46 +00:00
|
|
|
table.attach(label, 0, 1, 0, 1)
|
2014-09-19 14:08:08 +00:00
|
|
|
enabled = Gtk.CheckButton()
|
2010-01-05 17:57:46 +00:00
|
|
|
enabled.set_active(enabled_var)
|
|
|
|
table.attach(enabled, 1, 2, 0, 1)
|
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
label = Gtk.Label(label=_("Name:"))
|
2010-01-05 17:57:46 +00:00
|
|
|
table.attach(label, 0, 1, 1, 2)
|
2014-09-19 14:08:08 +00:00
|
|
|
name = Gtk.Entry()
|
2010-01-05 17:57:46 +00:00
|
|
|
name.set_text(name_var)
|
|
|
|
table.attach(name, 1, 2, 1, 2)
|
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
label = Gtk.Label(label=_("Command:"))
|
2010-01-05 17:57:46 +00:00
|
|
|
table.attach(label, 0, 1, 2, 3)
|
2014-09-19 14:08:08 +00:00
|
|
|
command = Gtk.Entry()
|
2010-01-05 17:57:46 +00:00
|
|
|
command.set_text(command_var)
|
|
|
|
table.attach(command, 1, 2, 2, 3)
|
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
dialog.vbox.pack_start(table, True, True, 0)
|
2010-01-05 17:57:46 +00:00
|
|
|
dialog.show_all()
|
|
|
|
return (dialog,enabled,name,command)
|
|
|
|
|
|
|
|
def _error(self, msg):
|
2014-09-19 14:08:08 +00:00
|
|
|
err = Gtk.MessageDialog(dialog,
|
|
|
|
Gtk.DialogFlags.MODAL,
|
|
|
|
Gtk.MessageType.ERROR,
|
|
|
|
Gtk.ButtonsType.CLOSE,
|
2010-01-05 17:57:46 +00:00
|
|
|
msg
|
|
|
|
)
|
|
|
|
err.run()
|
|
|
|
err.destroy()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def on_new(self, button, data):
|
|
|
|
(dialog,enabled,name,command) = self._create_command_dialog()
|
|
|
|
res = dialog.run()
|
|
|
|
item = {}
|
2014-09-19 14:08:08 +00:00
|
|
|
if res == Gtk.ResponseType.ACCEPT:
|
2010-01-05 17:57:46 +00:00
|
|
|
item['enabled'] = enabled.get_active()
|
|
|
|
item['name'] = name.get_text()
|
|
|
|
item['command'] = command.get_text()
|
|
|
|
if item['name'] == '' or item['command'] == '':
|
2014-09-19 14:08:08 +00:00
|
|
|
err = Gtk.MessageDialog(dialog,
|
|
|
|
Gtk.DialogFlags.MODAL,
|
|
|
|
Gtk.MessageType.ERROR,
|
|
|
|
Gtk.ButtonsType.CLOSE,
|
2010-01-05 17:57:46 +00:00
|
|
|
_("You need to define a name and command")
|
|
|
|
)
|
|
|
|
err.run()
|
|
|
|
err.destroy()
|
|
|
|
else:
|
|
|
|
# we have a new command
|
|
|
|
store = data['treeview'].get_model()
|
|
|
|
iter = store.get_iter_first()
|
|
|
|
name_exist = False
|
|
|
|
while iter != None:
|
|
|
|
if store.get_value(iter,CC_COL_NAME) == item['name']:
|
|
|
|
name_exist = True
|
|
|
|
break
|
|
|
|
iter = store.iter_next(iter)
|
|
|
|
if not name_exist:
|
|
|
|
store.append((item['enabled'], item['name'], item['command']))
|
|
|
|
else:
|
|
|
|
self._err(_("Name *%s* already exist") % item['name'])
|
|
|
|
dialog.destroy()
|
|
|
|
|
|
|
|
def on_goto_top(self, button, data):
|
|
|
|
treeview = data['treeview']
|
|
|
|
selection = treeview.get_selection()
|
|
|
|
(store, iter) = selection.get_selected()
|
|
|
|
|
|
|
|
if not iter:
|
|
|
|
return
|
|
|
|
firstiter = store.get_iter_first()
|
|
|
|
store.move_before(iter, firstiter)
|
|
|
|
|
|
|
|
def on_go_up(self, button, data):
|
|
|
|
treeview = data['treeview']
|
|
|
|
selection = treeview.get_selection()
|
|
|
|
(store, iter) = selection.get_selected()
|
|
|
|
|
|
|
|
if not iter:
|
|
|
|
return
|
|
|
|
|
|
|
|
tmpiter = store.get_iter_first()
|
|
|
|
|
|
|
|
if(store.get_path(tmpiter) == store.get_path(iter)):
|
|
|
|
return
|
|
|
|
|
|
|
|
while tmpiter:
|
|
|
|
next = store.iter_next(tmpiter)
|
|
|
|
if(store.get_path(next) == store.get_path(iter)):
|
|
|
|
store.swap(iter, tmpiter)
|
|
|
|
break
|
|
|
|
tmpiter = next
|
|
|
|
|
|
|
|
def on_go_down(self, button, data):
|
|
|
|
treeview = data['treeview']
|
|
|
|
selection = treeview.get_selection()
|
|
|
|
(store, iter) = selection.get_selected()
|
|
|
|
|
|
|
|
if not iter:
|
|
|
|
return
|
|
|
|
next = store.iter_next(iter)
|
|
|
|
if next:
|
|
|
|
store.swap(iter, next)
|
|
|
|
|
|
|
|
def on_goto_last(self, button, data):
|
|
|
|
treeview = data['treeview']
|
|
|
|
selection = treeview.get_selection()
|
|
|
|
(store, iter) = selection.get_selected()
|
|
|
|
|
|
|
|
if not iter:
|
|
|
|
return
|
|
|
|
lastiter = iter
|
|
|
|
tmpiter = store.get_iter_first()
|
|
|
|
while tmpiter:
|
|
|
|
lastiter = tmpiter
|
|
|
|
tmpiter = store.iter_next(tmpiter)
|
|
|
|
|
|
|
|
store.move_after(iter, lastiter)
|
|
|
|
|
|
|
|
|
|
|
|
def on_delete(self, button, data):
|
|
|
|
treeview = data['treeview']
|
|
|
|
selection = treeview.get_selection()
|
|
|
|
(store, iter) = selection.get_selected()
|
|
|
|
if iter:
|
|
|
|
store.remove(iter)
|
2013-07-16 17:56:14 +00:00
|
|
|
|
2010-01-05 17:57:46 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
def on_edit(self, button, data):
|
|
|
|
treeview = data['treeview']
|
|
|
|
selection = treeview.get_selection()
|
|
|
|
(store, iter) = selection.get_selected()
|
2013-07-16 17:56:14 +00:00
|
|
|
|
2010-01-05 17:57:46 +00:00
|
|
|
if not iter:
|
|
|
|
return
|
2013-07-16 17:56:14 +00:00
|
|
|
|
2010-01-05 17:57:46 +00:00
|
|
|
(dialog,enabled,name,command) = self._create_command_dialog(
|
|
|
|
enabled_var = store.get_value(iter, CC_COL_ENABLED),
|
|
|
|
name_var = store.get_value(iter, CC_COL_NAME),
|
|
|
|
command_var = store.get_value(iter, CC_COL_COMMAND)
|
|
|
|
)
|
|
|
|
res = dialog.run()
|
|
|
|
item = {}
|
2014-09-19 14:08:08 +00:00
|
|
|
if res == Gtk.ResponseType.ACCEPT:
|
2010-01-05 17:57:46 +00:00
|
|
|
item['enabled'] = enabled.get_active()
|
|
|
|
item['name'] = name.get_text()
|
|
|
|
item['command'] = command.get_text()
|
|
|
|
if item['name'] == '' or item['command'] == '':
|
2014-09-19 14:08:08 +00:00
|
|
|
err = Gtk.MessageDialog(dialog,
|
|
|
|
Gtk.DialogFlags.MODAL,
|
|
|
|
Gtk.MessageType.ERROR,
|
|
|
|
Gtk.ButtonsType.CLOSE,
|
2010-01-05 17:57:46 +00:00
|
|
|
_("You need to define a name and command")
|
|
|
|
)
|
|
|
|
err.run()
|
|
|
|
err.destroy()
|
|
|
|
else:
|
|
|
|
tmpiter = store.get_iter_first()
|
|
|
|
name_exist = False
|
|
|
|
while tmpiter != None:
|
|
|
|
if store.get_path(tmpiter) != store.get_path(iter) and store.get_value(tmpiter,CC_COL_NAME) == item['name']:
|
|
|
|
name_exist = True
|
|
|
|
break
|
|
|
|
tmpiter = store.iter_next(tmpiter)
|
|
|
|
if not name_exist:
|
|
|
|
store.set(iter,
|
|
|
|
CC_COL_ENABLED,item['enabled'],
|
|
|
|
CC_COL_NAME, item['name'],
|
|
|
|
CC_COL_COMMAND, item['command']
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
self._err(_("Name *%s* already exist") % item['name'])
|
|
|
|
|
|
|
|
dialog.destroy()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
c = CustomCommandsMenu()
|
|
|
|
c.configure(None, None)
|
2014-09-19 14:08:08 +00:00
|
|
|
Gtk.main()
|
2010-01-05 17:57:46 +00:00
|
|
|
|