2
# Terminator by Chris Jones <cmsj@tenshu.net>
4
"""titlebar.py - classes necessary to provide a terminal title bar"""
9
from version import APP_NAME
11
from terminator import Terminator
12
from editablelabel import EditableLabel
14
# pylint: disable-msg=R0904
15
# pylint: disable-msg=W0613
16
class Titlebar(gtk.EventBox):
17
"""Class implementing the Titlebar widget"""
33
'clicked': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
34
'edit-done': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
35
'create-group': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
36
(gobject.TYPE_STRING,)),
39
def __init__(self, terminal):
40
"""Class initialiser"""
41
gtk.EventBox.__init__(self)
42
self.__gobject_init__()
44
self.terminator = Terminator()
45
self.terminal = terminal
46
self.config = self.terminal.config
48
self.label = EditableLabel()
49
self.label.connect('edit-done', self.on_edit_done)
50
self.ebox = gtk.EventBox()
51
grouphbox = gtk.HBox()
52
self.grouplabel = gtk.Label()
53
self.groupicon = gtk.Image()
54
self.bellicon = gtk.Image()
55
self.bellicon.set_no_show_all(True)
57
self.groupentry = gtk.Entry()
58
self.groupentry.set_no_show_all(True)
59
self.groupentry.connect('focus-out-event', self.groupentry_cancel)
60
self.groupentry.connect('activate', self.groupentry_activate)
61
self.groupentry.connect('key-press-event', self.groupentry_keypress)
63
groupsend_type = self.terminator.groupsend_type
64
if self.terminator.groupsend == groupsend_type['all']:
66
elif self.terminator.groupsend == groupsend_type['group']:
68
elif self.terminator.groupsend == groupsend_type['off']:
70
self.set_from_icon_name('_active_broadcast_%s' % icon_name,
73
grouphbox.pack_start(self.groupicon, False, True, 2)
74
grouphbox.pack_start(self.grouplabel, False, True, 2)
75
grouphbox.pack_start(self.groupentry, False, True, 2)
77
self.ebox.add(grouphbox)
80
self.bellicon.set_from_icon_name('terminal-bell', gtk.ICON_SIZE_MENU)
82
hbox.pack_start(self.ebox, False, True, 0)
83
hbox.pack_start(gtk.VSeparator(), False, True, 0)
84
hbox.pack_start(self.label, True, True)
85
hbox.pack_end(self.bellicon, False, False, 2)
89
self.set_no_show_all(True)
92
self.connect('button-press-event', self.on_clicked)
94
def connect_icon(self, func):
95
"""Connect the supplied function to clicking on the group icon"""
96
self.ebox.connect('button-release-event', func)
98
def update(self, other=None):
99
"""Update our contents"""
101
self.label.set_text("%s %s" % (self.termtext, self.sizetext))
105
terminator = self.terminator
106
if term != other and term.group and term.group == other.group:
107
if terminator.groupsend == terminator.groupsend_type['off']:
108
title_fg = self.config['title_inactive_fg_color']
109
title_bg = self.config['title_inactive_bg_color']
110
icon = '_receive_off'
113
title_fg = self.config['title_receive_fg_color']
114
title_bg = self.config['title_receive_bg_color']
116
group_fg = self.config['title_receive_fg_color']
117
group_bg = self.config['title_receive_bg_color']
118
elif term != other and not term.group or term.group != other.group:
119
if terminator.groupsend == terminator.groupsend_type['all']:
120
title_fg = self.config['title_receive_fg_color']
121
title_bg = self.config['title_receive_bg_color']
124
title_fg = self.config['title_inactive_fg_color']
125
title_bg = self.config['title_inactive_bg_color']
126
icon = '_receive_off'
128
group_fg = self.config['title_inactive_fg_color']
129
group_bg = self.config['title_inactive_bg_color']
131
title_fg = self.config['title_transmit_fg_color']
132
title_bg = self.config['title_transmit_bg_color']
133
if terminator.groupsend == terminator.groupsend_type['all']:
134
icon = '_active_broadcast_all'
135
elif terminator.groupsend == terminator.groupsend_type['group']:
136
icon = '_active_broadcast_group'
138
icon = '_active_broadcast_off'
139
group_fg = self.config['title_transmit_fg_color']
140
group_bg = self.config['title_transmit_bg_color']
142
self.label.modify_fg(gtk.STATE_NORMAL,
143
gtk.gdk.color_parse(title_fg))
144
self.grouplabel.modify_fg(gtk.STATE_NORMAL,
145
gtk.gdk.color_parse(group_fg))
146
self.modify_bg(gtk.STATE_NORMAL,
147
gtk.gdk.color_parse(title_bg))
148
if not self.get_desired_visibility():
149
if default_bg == True:
150
color = term.get_style().bg[gtk.STATE_NORMAL]
152
color = gtk.gdk.color_parse(title_bg)
153
self.set_size_request(-1, 2)
156
self.set_size_request(-1, -1)
158
self.ebox.modify_bg(gtk.STATE_NORMAL,
159
gtk.gdk.color_parse(group_bg))
160
self.set_from_icon_name(icon, gtk.ICON_SIZE_MENU)
162
def get_desired_visibility(self):
163
"""Returns True if the titlebar is supposed to be visible. False if
165
if self.editing() == True:
168
return(self.config['show_titlebar'])
170
def set_from_icon_name(self, name, size = gtk.ICON_SIZE_MENU):
171
"""Set an icon for the group label"""
173
self.groupicon.hide()
176
self.groupicon.set_from_icon_name(APP_NAME + name, size)
177
self.groupicon.show()
179
def update_terminal_size(self, width, height):
180
"""Update the displayed terminal size"""
181
self.sizetext = "%sx%s" % (width, height)
184
def set_terminal_title(self, widget, title):
185
"""Update the terminal title"""
186
self.termtext = title
188
# Return False so we don't interrupt any chains of signal handling
191
def set_group_label(self, name):
192
"""Set the name of the group"""
194
self.grouplabel.set_text(name)
195
self.grouplabel.show()
197
self.grouplabel.hide()
199
def on_clicked(self, widget, event):
200
"""Handle a click on the label"""
201
self.set_size_request(-1, -1)
205
def on_edit_done(self, widget):
206
"""Re-emit an edit-done signal from an EditableLabel"""
207
self.emit('edit-done')
210
"""Determine if we're currently editing a group name or title"""
211
return(self.groupentry.get_property('visible') or self.label.editing())
213
def create_group(self):
214
"""Create a new group"""
215
self.groupentry.show()
216
self.groupentry.grab_focus()
218
def groupentry_cancel(self, widget, event):
219
"""Hide the group name entry"""
220
self.groupentry.set_text('')
221
self.groupentry.hide()
222
self.get_parent().grab_focus()
224
def groupentry_activate(self, widget):
225
"""Actually cause a group to be created"""
226
groupname = self.groupentry.get_text()
227
dbg('Titlebar::groupentry_activate: creating group: %s' % groupname)
228
self.groupentry_cancel(None, None)
229
self.emit('create-group', groupname)
231
def groupentry_keypress(self, widget, event):
232
"""Handle keypresses on the entry widget"""
233
key = gtk.gdk.keyval_name(event.keyval)
235
self.groupentry_cancel(None, None)
238
"""A bell signal requires we display our bell icon"""
240
gobject.timeout_add(1000, self.icon_bell_hide)
242
def icon_bell_hide(self):
243
"""Handle a timeout which means we now hide the bell icon"""
247
gobject.type_register(Titlebar)