Added menu to enable/disable hosts on demand. github#13

This commit is contained in:
Graeme Humphries 2012-05-15 11:46:22 -07:00
parent f57955594b
commit 3689a251a8

View File

@ -133,6 +133,7 @@ class CruSSH:
LayoutTable = gtk.Table() LayoutTable = gtk.Table()
EntryBox = gtk.Entry() EntryBox = gtk.Entry()
Clipboard = gtk.Clipboard() Clipboard = gtk.Clipboard()
ActiveHostsMenu = gtk.Menu()
### Methods ### ### Methods ###
def reflowTable(self, cols=1, rows=1): def reflowTable(self, cols=1, rows=1):
@ -219,6 +220,19 @@ class CruSSH:
EditItem = gtk.MenuItem(label="Edit") EditItem = gtk.MenuItem(label="Edit")
EditMenu = gtk.Menu() EditMenu = gtk.Menu()
EditItem.set_submenu(EditMenu) EditItem.set_submenu(EditMenu)
def toggle_func(checkitem, host):
self.Terminals[host].copy_input = checkitem.get_active()
ActiveHostsItem = gtk.MenuItem(label="Active Hosts")
ActiveHostsItem.set_submenu(self.ActiveHostsMenu)
hosts = sorted(self.Terminals.keys(), reverse=True)
for host in hosts:
hostitem = gtk.CheckMenuItem(label=host)
hostitem.set_active(True)
hostitem.connect("toggled", toggle_func, host)
self.ActiveHostsMenu.append(hostitem)
EditMenu.append(ActiveHostsItem)
PrefsItem = gtk.MenuItem(label="Preferences") PrefsItem = gtk.MenuItem(label="Preferences")
def save_func(new_config): def save_func(new_config):
@ -251,18 +265,21 @@ class CruSSH:
self.EntryBox.set_visibility(False) self.EntryBox.set_visibility(False)
self.EntryBox.set_invisible_char(' ') self.EntryBox.set_invisible_char(' ')
# forward key events to all terminals # forward key events to all terminals with copy_input set
def feed_input(widget, event): def feed_input(widget, event):
self.EntryBox.props.buffer.delete_text(0, -1) self.EntryBox.props.buffer.delete_text(0, -1)
# propagate to every terminal # propagate to every terminal
for host in self.Terminals: for host in self.Terminals:
t_event = event.copy() t_event = event.copy()
self.Terminals[host].event(t_event) if self.Terminals[host].copy_input:
self.Terminals[host].event(t_event)
# this stops regular handler from firing, switching focus. # this stops regular handler from firing, switching focus.
return True return True
def feed_paste(widget): def feed_paste(widget):
for host in self.Terminals: for host in self.Terminals:
self.Terminals[host].feed_child(self.Clipboard.wait_for_text()) if self.Terminals[host].copy_input:
self.Terminals[host].feed_child(self.Clipboard.wait_for_text())
self.EntryBox.props.buffer.delete_text(0, -1) self.EntryBox.props.buffer.delete_text(0, -1)
self.EntryBox.connect("key_press_event", feed_input) self.EntryBox.connect("key_press_event", feed_input)
@ -296,6 +313,8 @@ class CruSSH:
cmd_str += " " + host cmd_str += " " + host
cmd = cmd_str.split(' ') cmd = cmd_str.split(' ')
terminal.fork_command(command=cmd[0], argv=cmd) terminal.fork_command(command=cmd[0], argv=cmd)
# track whether we mirror output to this terminal
terminal.copy_input = True
self.Terminals[host] = terminal self.Terminals[host] = terminal
# hook terminals so they reflow layout on exit # hook terminals so they reflow layout on exit