1
# -*- coding: utf-8 -*-
3
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
4
#Copyright (c) 2005 Ali Afshar aafshar@gmail.com
6
#Permission is hereby granted, free of charge, to any person obtaining a copy
7
#of this software and associated documentation files (the "Software"), to deal
8
#in the Software without restriction, including without limitation the rights
9
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
#copies of the Software, and to permit persons to whom the Software is
11
#furnished to do so, subject to the following conditions:
13
#The above copyright notice and this permission notice shall be included in
14
#all copies or substantial portions of the Software.
16
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36
class content_view(gtk.VBox):
37
__gsignals__ = {'short-title-changed': (
38
gobject.SIGNAL_RUN_LAST,
41
'long-title-changed': (
42
gobject.SIGNAL_RUN_LAST,
46
gobject.SIGNAL_RUN_LAST,
48
(gobject.TYPE_PYOBJECT,)),
50
gobject.SIGNAL_RUN_LAST,
54
gobject.SIGNAL_RUN_LAST,
63
HAS_CONTROL_BOX = True
64
HAS_CLOSE_BUTTON = True
65
HAS_DETACH_BUTTON = True
75
def __init__(self, service, prefix, widget=None, icon_name=None,
76
short_title=None, **kw):
77
gtk.VBox.__init__(self)
78
self.__uid = time.time()
79
self.__service = service
80
self.__prefix = prefix
81
self.__init_icon(icon_name)
82
self.__init_short_title(short_title)
83
self.__init_long_title()
84
self.__init_widgets(widget)
86
self.set_size_request(0,0)
89
def __init_icon(self, icon_name):
90
if icon_name is not None:
91
self.icon_name = icon_name
92
elif self.ICON_NAME is not None:
93
self.icon_name = self.ICON_NAME
95
self.icon_name = 'terminal'
97
def __init_short_title(self, short_title):
99
self.short_title = short_title
100
elif self.SHORT_TITLE:
101
self.short_title = self.SHORT_TITLE
103
self.short_title = 'Untitled'
105
def __init_long_title(self):
106
if self.LONG_TITLE is not None:
107
self.long_title = self.LONG_TITLE
109
self.long_title = 'Long title'
111
def __init_widgets(self, widget):
114
self.pack_start(topbar, expand=False)
116
titlebar = gtk.HBox()
118
self.pack_start(titlebar, expand=False)
120
if widget is not None:
121
self.pack_start(widget)
122
self.__widget = widget
123
elif self.WIDGET_TYPE is not None:
124
self.__widget = self.WIDGET_TYPE
125
self.pack_start(self.__widget)
127
self.__widget = gtk.VBox()
128
self.pack_start(self.__widget)
131
self.__init_topbar(topbar)
133
def __init_topbar(self, topbar):
134
self.__toolbar_area = gtk.HBox()
135
self.__toolbar_area.show()
137
topbar.pack_start(self.__toolbar_area, expand=False)
138
# TODO: check if toolbar.Toolbar needs work too
139
self.__toolbar = toolbar.Toolbar()
140
self.__toolbar.show()
142
self.__toolbar_area.pack_start(self.__toolbar, expand=False)
143
self.__toolbar.connect('clicked', self.cb_toolbar_clicked)
144
for name, icon, tooltip in self.BUTTONS:
145
self.__toolbar.add_button(name, icon, tooltip)
146
if self.HAS_CONTROL_BOX:
147
if self.HAS_DETACH_BUTTON:
148
detbut = paned.sizer('menu', tooltip='Detach this view')
149
#self.__toolbar_area.pack_start(detbut, expand=False)
150
detbut.connect('clicked',
151
self.cb_controlbar_detach_clicked)
152
self.__long_title_label = gtk.Label(self.__long_title)
153
self.__long_title_label.show()
156
self.__toolbar_area.pack_start(self.__long_title_label, padding=6)
157
self.__long_title_label.set_alignment(0.0, 0.5)
158
self.__long_title_label.set_selectable(True)
159
if self.HAS_CONTROL_BOX:
160
if self.HAS_CLOSE_BUTTON:
161
align = gtk.Alignment()
163
self.__toolbar_area.pack_start(align)
165
closebut = paned.sizer('close', tooltip='Close this view')
168
self.__toolbar_area.pack_start(closebut, expand=False)
169
closebut.connect('clicked',
170
self.cb_controlbar_close_clicked)
171
self.__close_button = closebut
176
def toolbar_add_button(self, name, icon, tooltip):
177
self.__toolbar.add_button(name, icon, tooltip)
179
def toolbar_add_widget(self, widget, **kw):
181
self.__toolbar.add_widget(widget, **kw)
183
def toolbar_add_separator(self):
184
self.__toolbar.add_separator()
190
if self.__holder is not None:
191
self.__holder.remove_page(self)
194
if self.__holder is not None:
195
self.__holder.detach_page(self)
197
def raise_page(self):
198
if self.__holder is not None:
199
self.__holder.set_page(self)
201
def hide_title(self):
202
self.__long_title_label.hide()
204
def hide_controlbox(self):
205
if self.HAS_CLOSE_BUTTON:
206
self.__close_button.hide()
208
def cb_toolbar_clicked(self, toolbar, name):
209
func = 'cb_%s_toolbar_clicked_%s' % (self.__prefix, name)
210
cb = getattr(self.service, func, None)
212
cb(self, toolbar, name)
213
self.emit('action', name)
215
def cb_controlbar_close_clicked(self, controlbox):
216
self.__controlbar_clicked('close')
218
def cb_controlbar_detach_clicked(self, controlbox):
219
self.__controlbar_clicked('detach')
221
def __controlbar_clicked(self, name):
222
func = 'cb_%s_controlbar_clicked_%s' % (self.__prefix, name)
223
cb = getattr(self.service, func, None)
225
cb(self, toolbar, name)
227
def get_service(self):
228
return self.__service
229
service = property(get_service)
231
def get_unique_id(self):
233
unique_id = property(get_unique_id)
235
def get_short_title(self):
236
return self.__short_title
237
def set_short_title(self, value):
238
self.__short_title = value
239
self.emit('short-title-changed')
240
short_title = property(get_short_title, set_short_title)
242
def get_long_title(self):
243
return self.__long_title
244
def set_long_title(self, value):
245
self.__long_title = value
247
self.__long_title_label.set_label(value)
248
except AttributeError:
250
self.emit('long-title-changed')
251
long_title = property(get_long_title, set_long_title)
253
def get_icon_name(self):
254
return self.__icon_name
255
def set_icon_name(self, value):
256
self.__icon_name = value
257
icon_name = property(get_icon_name, set_icon_name)
260
return self.create_icon()
261
icon = property(get_icon)
263
def get_holder(self):
265
def set_holder(self, value):
266
self.__holder = value
267
holder = property(get_holder, set_holder)
269
def get_widget(self):
271
widget = property(get_widget)
273
def get_prefix(self):
275
prefix = property(get_prefix)
277
def create_icon(self):
279
icon = icons.icons.get_image(self.icon_name)
280
eb = self.create_tooltip_box()
284
def create_tooltip_box(self):
286
eb.add_events(gtk.gdk.BUTTON_PRESS_MASK)
287
def _click(_eb, event):
288
if event.button == 3:
289
self.create_detach_popup(event)
291
eb.connect('button-press-event', _click)
294
def create_detach_popup(self, event):
295
if self.HAS_CONTROL_BOX and (self.HAS_CLOSE_BUTTON or
296
self.HAS_DETACH_BUTTON):
298
if self.HAS_DETACH_BUTTON:
299
act = gtk.Action(name='detach',
301
tooltip='Detach this view',
304
self.__controlbar_clicked('detach')
305
act.connect('activate', _det)
306
mi = act.create_menu_item()
308
if self.HAS_CLOSE_BUTTON:
309
act = gtk.Action(name='close',
311
tooltip='Close this view',
312
stock_id=gtk.STOCK_CLOSE)
314
self.__controlbar_clicked('close')
315
act.connect('activate', _close)
316
mi = act.create_menu_item()
319
menu.popup(None, None, None, event.button, event.time)
322
gobject.type_register(content_view)