2009-08-18 12:45:57 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# Terminator by Chris Jones <cmsj@tenshu.net>
|
|
|
|
# GPL v2 only
|
|
|
|
"""titlebar.py - classes necessary to provide a terminal title bar"""
|
|
|
|
|
|
|
|
import gtk
|
|
|
|
import gobject
|
|
|
|
|
2009-09-02 22:17:54 +00:00
|
|
|
from version import APP_NAME
|
2009-10-15 13:17:37 +00:00
|
|
|
from util import dbg
|
2009-09-03 12:59:17 +00:00
|
|
|
from newterminator import Terminator
|
2009-09-02 21:38:27 +00:00
|
|
|
from editablelabel import EditableLabel
|
|
|
|
|
2009-08-18 12:52:02 +00:00
|
|
|
# pylint: disable-msg=R0904
|
2009-09-03 09:34:31 +00:00
|
|
|
# pylint: disable-msg=W0613
|
2009-08-18 12:45:57 +00:00
|
|
|
class Titlebar(gtk.EventBox):
|
|
|
|
"""Class implementing the Titlebar widget"""
|
|
|
|
|
2009-09-02 22:17:54 +00:00
|
|
|
terminator = None
|
2009-09-02 20:10:28 +00:00
|
|
|
oldtitle = None
|
2009-09-02 21:38:27 +00:00
|
|
|
termtext = None
|
|
|
|
sizetext = None
|
|
|
|
label = None
|
|
|
|
ebox = None
|
|
|
|
groupicon = None
|
|
|
|
grouplabel = None
|
2009-10-15 13:17:37 +00:00
|
|
|
groupentry = None
|
2009-09-02 20:10:28 +00:00
|
|
|
|
2009-09-02 23:52:36 +00:00
|
|
|
__gsignals__ = {
|
|
|
|
'clicked': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
|
|
|
|
'edit-done': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
|
2009-10-15 13:17:37 +00:00
|
|
|
'create-group': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
|
|
|
|
(gobject.TYPE_STRING,)),
|
2009-09-02 23:52:36 +00:00
|
|
|
}
|
|
|
|
|
2009-08-18 12:45:57 +00:00
|
|
|
def __init__(self):
|
|
|
|
"""Class initialiser"""
|
|
|
|
gtk.EventBox.__init__(self)
|
2009-08-19 00:05:44 +00:00
|
|
|
self.__gobject_init__()
|
2009-08-18 12:45:57 +00:00
|
|
|
|
2009-09-02 22:17:54 +00:00
|
|
|
self.terminator = Terminator()
|
|
|
|
|
2009-09-02 21:38:27 +00:00
|
|
|
self.label = EditableLabel()
|
2009-09-02 23:52:36 +00:00
|
|
|
self.label.connect('edit-done', self.on_edit_done)
|
2009-09-02 21:38:27 +00:00
|
|
|
self.ebox = gtk.EventBox()
|
2009-09-06 22:53:21 +00:00
|
|
|
grouphbox = gtk.HBox()
|
2009-09-02 21:38:27 +00:00
|
|
|
self.grouplabel = gtk.Label()
|
|
|
|
self.groupicon = gtk.Image()
|
|
|
|
|
2009-10-15 13:17:37 +00:00
|
|
|
self.groupentry = gtk.Entry()
|
|
|
|
self.groupentry.set_no_show_all(True)
|
|
|
|
self.groupentry.connect('focus-out-event', self.groupentry_cancel)
|
|
|
|
self.groupentry.connect('activate', self.groupentry_activate)
|
|
|
|
self.groupentry.connect('key-press-event', self.groupentry_keypress)
|
|
|
|
|
2009-09-03 12:59:17 +00:00
|
|
|
groupsend_type = self.terminator.groupsend_type
|
2009-09-02 22:17:54 +00:00
|
|
|
if self.terminator.groupsend == groupsend_type['all']:
|
|
|
|
icon_name = 'all'
|
|
|
|
elif self.terminator.groupsend == groupsend_type['group']:
|
|
|
|
icon_name = 'group'
|
|
|
|
elif self.terminator.groupsend == groupsend_type['off']:
|
|
|
|
icon_name = 'off'
|
|
|
|
self.set_from_icon_name('_active_broadcast_%s' % icon_name,
|
|
|
|
gtk.ICON_SIZE_MENU)
|
2009-09-02 21:38:27 +00:00
|
|
|
|
2009-09-06 22:53:21 +00:00
|
|
|
grouphbox.pack_start(self.groupicon, False, True, 2)
|
|
|
|
grouphbox.pack_start(self.grouplabel, False, True, 2)
|
2009-10-15 13:17:37 +00:00
|
|
|
grouphbox.pack_start(self.groupentry, False, True, 2)
|
|
|
|
|
2009-09-06 22:53:21 +00:00
|
|
|
self.ebox.add(grouphbox)
|
2009-09-02 21:38:27 +00:00
|
|
|
self.ebox.show_all()
|
|
|
|
|
2009-09-06 22:53:21 +00:00
|
|
|
hbox = gtk.HBox()
|
|
|
|
hbox.pack_start(self.ebox, False, True, 0)
|
|
|
|
hbox.pack_start(gtk.VSeparator(), False, True, 0)
|
|
|
|
hbox.pack_start(self.label, True, True)
|
2009-09-02 21:38:27 +00:00
|
|
|
|
2009-09-06 22:53:21 +00:00
|
|
|
self.add(hbox)
|
2009-09-02 21:38:27 +00:00
|
|
|
self.show_all()
|
2009-08-18 12:45:57 +00:00
|
|
|
|
2009-09-02 23:52:36 +00:00
|
|
|
self.connect('button-press-event', self.on_clicked)
|
|
|
|
|
2009-08-19 00:05:44 +00:00
|
|
|
def connect_icon(self, func):
|
|
|
|
"""Connect the supplied function to clicking on the group icon"""
|
2009-09-02 23:52:36 +00:00
|
|
|
self.ebox.connect('button-release-event', func)
|
2009-08-19 00:05:44 +00:00
|
|
|
|
2009-08-28 00:11:13 +00:00
|
|
|
def update(self):
|
|
|
|
"""Update our contents"""
|
2009-09-02 21:38:27 +00:00
|
|
|
self.label.set_text("%s %s" % (self.termtext, self.sizetext))
|
2009-11-22 03:53:01 +00:00
|
|
|
# FIXME: Aren't we supposed to be setting a colour here too?
|
2009-08-28 00:11:13 +00:00
|
|
|
|
2009-09-02 22:17:54 +00:00
|
|
|
def set_from_icon_name(self, name, size = gtk.ICON_SIZE_MENU):
|
|
|
|
"""Set an icon for the group label"""
|
|
|
|
if not name:
|
|
|
|
self.groupicon.hide()
|
|
|
|
return
|
|
|
|
|
|
|
|
self.groupicon.set_from_icon_name(APP_NAME + name, size)
|
|
|
|
self.groupicon.show()
|
|
|
|
|
2009-08-19 18:01:11 +00:00
|
|
|
def update_terminal_size(self, width, height):
|
|
|
|
"""Update the displayed terminal size"""
|
2009-09-02 21:38:27 +00:00
|
|
|
self.sizetext = "%sx%s" % (width, height)
|
|
|
|
self.update()
|
2009-08-19 18:01:11 +00:00
|
|
|
|
2009-09-02 20:18:36 +00:00
|
|
|
def set_terminal_title(self, widget, title):
|
2009-09-02 20:10:28 +00:00
|
|
|
"""Update the terminal title"""
|
2009-09-02 21:38:27 +00:00
|
|
|
self.termtext = title
|
|
|
|
self.update()
|
2009-12-10 13:20:03 +00:00
|
|
|
# Return False so we don't interrupt any chains of signal handling
|
|
|
|
return False
|
2009-09-02 21:38:27 +00:00
|
|
|
|
|
|
|
def set_group_label(self, name):
|
|
|
|
"""Set the name of the group"""
|
|
|
|
if name:
|
|
|
|
self.grouplabel.set_text(name)
|
|
|
|
self.grouplabel.show()
|
|
|
|
else:
|
|
|
|
self.grouplabel.hide()
|
|
|
|
|
|
|
|
def on_clicked(self, widget, event):
|
|
|
|
"""Handle a click on the label"""
|
2009-09-02 23:52:36 +00:00
|
|
|
self.emit('clicked')
|
|
|
|
|
|
|
|
def on_edit_done(self, widget):
|
|
|
|
"""Re-emit an edit-done signal from an EditableLabel"""
|
|
|
|
self.emit('edit-done')
|
2009-09-02 20:10:28 +00:00
|
|
|
|
2009-10-15 13:17:37 +00:00
|
|
|
def create_group(self):
|
|
|
|
"""Create a new group"""
|
|
|
|
self.groupentry.show()
|
|
|
|
self.groupentry.grab_focus()
|
|
|
|
|
|
|
|
def groupentry_cancel(self, widget, event):
|
|
|
|
"""Hide the group name entry"""
|
|
|
|
self.groupentry.set_text('')
|
|
|
|
self.groupentry.hide()
|
2009-11-20 05:42:49 +00:00
|
|
|
self.get_parent().grab_focus()
|
2009-10-15 13:17:37 +00:00
|
|
|
|
|
|
|
def groupentry_activate(self, widget):
|
|
|
|
"""Actually cause a group to be created"""
|
|
|
|
groupname = self.groupentry.get_text()
|
2009-11-20 05:40:31 +00:00
|
|
|
dbg('Titlebar::groupentry_activate: creating group: %s' % groupname)
|
2009-10-15 13:17:37 +00:00
|
|
|
self.groupentry_cancel(None, None)
|
|
|
|
self.emit('create-group', groupname)
|
|
|
|
|
|
|
|
def groupentry_keypress(self, widget, event):
|
|
|
|
"""Handle keypresses on the entry widget"""
|
|
|
|
key = gtk.gdk.keyval_name(event.keyval)
|
|
|
|
if key == 'Escape':
|
|
|
|
self.groupentry_cancel(None, None)
|
|
|
|
|
2009-08-18 12:45:57 +00:00
|
|
|
gobject.type_register(Titlebar)
|