root/trunk/src/message_window.py

Revision 10732, 38.2 kB (checked in by asterix, 7 hours ago)

revert r10690 and r10691, it's not translatable

Line 
1# -*- coding:utf-8 -*-
2## src/message_window.py
3##
4## Copyright (C) 2003-2008 Yann Leboulanger <asterix AT lagaule.org>
5## Copyright (C) 2005-2008 Travis Shirk <travis AT pobox.com>
6##                         Nikos Kouremenos <kourem AT gmail.com>
7## Copyright (C) 2006 Geobert Quach <geobert AT gmail.com>
8##                    Dimitur Kirov <dkirov AT gmail.com>
9## Copyright (C) 2006-2008 Jean-Marie Traissard <jim AT lapin.org>
10## Copyright (C) 2007 Julien Pivotto <roidelapluie AT gmail.com>
11##                    Stephan Erb <steve-e AT h3c.de>
12## Copyright (C) 2008 Brendan Taylor <whateley AT gmail.com>
13##                    Jonathan Schleifer <js-gajim AT webkeks.org>
14##
15## This file is part of Gajim.
16##
17## Gajim is free software; you can redistribute it and/or modify
18## it under the terms of the GNU General Public License as published
19## by the Free Software Foundation; version 3 only.
20##
21## Gajim is distributed in the hope that it will be useful,
22## but WITHOUT ANY WARRANTY; without even the implied warranty of
23## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24## GNU General Public License for more details.
25##
26## You should have received a copy of the GNU General Public License
27## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
28##
29
30import gtk
31import gobject
32import time
33
34import common
35import gtkgui_helpers
36import message_control
37from chat_control import ChatControlBase
38
39from common import gajim
40
41####################
42
43class MessageWindow(object):
44        '''Class for windows which contain message like things; chats,
45        groupchats, etc.'''
46
47        # DND_TARGETS is the targets needed by drag_source_set and drag_dest_set
48        DND_TARGETS = [('GAJIM_TAB', 0, 81)]
49        hid = 0 # drag_data_received handler id
50        (
51                CLOSE_TAB_MIDDLE_CLICK,
52                CLOSE_ESC,
53                CLOSE_CLOSE_BUTTON,
54                CLOSE_COMMAND,
55                CLOSE_CTRL_KEY
56        ) = range(5)
57
58        def __init__(self, acct, type_, parent_window=None, parent_paned=None):
59                # A dictionary of dictionaries
60                # where _contacts[account][jid] == A MessageControl
61                self._controls = {}
62
63                # If None, the window is not tied to any specific account
64                self.account = acct
65                # If None, the window is not tied to any specific type
66                self.type_ = type_
67                # dict { handler id: widget}. Keeps callbacks, which
68                # lead to cylcular references
69                self.handlers = {}
70                # Don't show warning dialogs when we want to delete the window
71                self.dont_warn_on_delete = False
72
73                self.widget_name = 'message_window'
74                self.xml = gtkgui_helpers.get_glade('%s.glade' % self.widget_name)
75                self.window = self.xml.get_widget(self.widget_name)
76                self.notebook = self.xml.get_widget('notebook')
77                self.parent_paned = None
78
79                if parent_window:
80                        orig_window = self.window
81                        self.window = parent_window
82                        self.parent_paned = parent_paned
83                        self.notebook.reparent(self.parent_paned)
84                        self.parent_paned.pack2(self.notebook, resize=True, shrink=True)
85                        orig_window.destroy()
86                        del orig_window
87
88                # NOTE: we use 'connect_after' here because in
89                # MessageWindowMgr._new_window we register handler that saves window
90                # state when closing it, and it should be called before
91                # MessageWindow._on_window_delete, which manually destroys window
92                # through win.destroy() - this means no additional handlers for
93                # 'delete-event' are called.
94                id = self.window.connect_after('delete-event', self._on_window_delete)
95                self.handlers[id] = self.window
96                id = self.window.connect('destroy', self._on_window_destroy)
97                self.handlers[id] = self.window
98                id = self.window.connect('focus-in-event', self._on_window_focus)
99                self.handlers[id] = self.window
100
101                keys=['<Control>f', '<Control>g', '<Control>h', '<Control>i',
102                        '<Control>l', '<Control>L', '<Control>n', '<Control>u', '<Control>v',
103                        '<Control>b', '<Control><Shift>Tab', '<Control>Tab', '<Control>F4',
104                        '<Control>w', '<Control>Page_Up', '<Control>Page_Down', '<Alt>Right',
105                        '<Alt>Left', '<Alt>a', '<Alt>c', '<Alt>m', '<Alt>t', 'Escape'] + \
106                        ['<Alt>'+str(i) for i in xrange(10)]
107                accel_group = gtk.AccelGroup()
108                for key in keys:
109                        keyval, mod = gtk.accelerator_parse(key)
110                        accel_group.connect_group(keyval, mod, gtk.ACCEL_VISIBLE,
111                                self.accel_group_func)
112                self.window.add_accel_group(accel_group)
113
114                # gtk+ doesn't make use of the motion notify on gtkwindow by default
115                # so this line adds that
116                self.window.add_events(gtk.gdk.POINTER_MOTION_MASK)
117                self.alignment = self.xml.get_widget('alignment')
118
119                id = self.notebook.connect('switch-page',
120                        self._on_notebook_switch_page)
121                self.handlers[id] = self.notebook
122                id = self.notebook.connect('key-press-event',
123                        self._on_notebook_key_press)
124                self.handlers[id] = self.notebook
125
126                # Remove the glade pages
127                while self.notebook.get_n_pages():
128                        self.notebook.remove_page(0)
129                # Tab customizations
130                pref_pos = gajim.config.get('tabs_position')
131                if pref_pos == 'bottom':
132                        nb_pos = gtk.POS_BOTTOM
133                elif pref_pos == 'left':
134                        nb_pos = gtk.POS_LEFT
135                elif pref_pos == 'right':
136                        nb_pos = gtk.POS_RIGHT
137                else:
138                        nb_pos = gtk.POS_TOP
139                self.notebook.set_tab_pos(nb_pos)
140                window_mode = gajim.interface.msg_win_mgr.mode
141                if gajim.config.get('tabs_always_visible') or \
142                window_mode == MessageWindowMgr.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER:
143                        self.notebook.set_show_tabs(True)
144                        self.alignment.set_property('top-padding', 2)
145                else:
146                        self.notebook.set_show_tabs(False)
147                self.notebook.set_show_border(gajim.config.get('tabs_border'))
148
149                # if GTK+ version < 2.10, use OUR way to reorder tabs (set up DnD)
150                if gtk.pygtk_version < (2, 10, 0) or gtk.gtk_version < (2, 10, 0):
151                        self.hid = self.notebook.connect('drag_data_received',
152                                self.on_tab_label_drag_data_received_cb)
153                        self.handlers[self.hid] = self.notebook
154                        self.notebook.drag_dest_set(gtk.DEST_DEFAULT_ALL, self.DND_TARGETS,
155                                gtk.gdk.ACTION_MOVE)
156
157        def change_account_name(self, old_name, new_name):
158                if old_name in self._controls:
159                        self._controls[new_name] = self._controls[old_name]
160                        del self._controls[old_name]
161
162                for ctrl in self.controls():
163                        if ctrl.account == old_name:
164                                ctrl.account = new_name
165                if self.account == old_name:
166                        self.account = new_name
167
168        def get_num_controls(self):
169                n = 0
170                for dict in self._controls.values():
171                        n += len(dict)
172                return n
173
174        def resize(self, width, height):
175                gtkgui_helpers.resize_window(self.window, width, height)
176
177        def _on_window_focus(self, widget, event):
178                # window received focus, so if we had urgency REMOVE IT
179                # NOTE: we do not have to read the message (it maybe in a bg tab)
180                # to remove urgency hint so this functions does that
181                gtkgui_helpers.set_unset_urgency_hint(self.window, False)
182
183                ctrl = self.get_active_control()
184                if ctrl:
185                        ctrl.set_control_active(True)
186                        # Undo "unread" state display, etc.
187                        if ctrl.type_id == message_control.TYPE_GC:
188                                self.redraw_tab(ctrl, 'active')
189                        else:
190                                # NOTE: we do not send any chatstate to preserve
191                                # inactive, gone, etc.
192                                self.redraw_tab(ctrl)
193
194        def _on_window_delete(self, win, event):
195                if self.dont_warn_on_delete:
196                        # Destroy the window
197                        return False
198
199                def on_yes(ctrl):
200                        if self.on_delete_ok == 1:
201                                self.dont_warn_on_delete = True
202                                win.destroy()
203                        self.on_delete_ok -= 1
204
205                def on_no(ctrl):
206                        return
207
208                def on_minimize(ctrl):
209                        ctrl.minimize()
210                        if self.on_delete_ok == 1:
211                                self.dont_warn_on_delete = True
212                                win.destroy()
213                        self.on_delete_ok -= 1
214
215                # Make sure all controls are okay with being deleted
216                ctrl_to_minimize = []
217                self.on_delete_ok = self.get_nb_controls()
218                for ctrl in self.controls():
219                        ctrl.allow_shutdown(self.CLOSE_CLOSE_BUTTON, on_yes, on_no,
220                                on_minimize)
221                return True # halt the delete for the moment
222
223        def _on_window_destroy(self, win):
224                for ctrl in self.controls():
225                        ctrl.shutdown()
226                self._controls.clear()
227                # Clean up handlers connected to the parent window, this is important since
228                # self.window may be the RosterWindow
229                for i in self.handlers.keys():
230                        if self.handlers[i].handler_is_connected(i):
231                                self.handlers[i].disconnect(i)
232                        del self.handlers[i]
233                del self.handlers
234
235        def new_tab(self, control):
236                fjid = control.get_full_jid()
237
238                if control.account not in self._controls:
239                        self._controls[control.account] = {}
240
241                self._controls[control.account][fjid] = control
242
243                if self.get_num_controls() == 2:
244                        # is first conversation_textview scrolled down ?
245                        scrolled = False
246                        first_widget = self.notebook.get_nth_page(0)
247                        ctrl = self._widget_to_control(first_widget)
248                        conv_textview = ctrl.conv_textview
249                        if conv_textview.at_the_end():
250                                scrolled = True
251                        self.notebook.set_show_tabs(True)
252                        if scrolled:
253                                gobject.idle_add(conv_textview.scroll_to_end_iter)
254                        self.alignment.set_property('top-padding', 2)
255
256                # Add notebook page and connect up to the tab's close button
257                xml = gtkgui_helpers.get_glade('message_window.glade', 'chat_tab_ebox')
258                tab_label_box = xml.get_widget('chat_tab_ebox')
259                widget = xml.get_widget('tab_close_button')
260                id = widget.connect('clicked', self._on_close_button_clicked, control)
261                control.handlers[id] = widget
262
263                id = tab_label_box.connect('button-press-event', self.on_tab_eventbox_button_press_event,
264                                        control.widget)
265                control.handlers[id] = tab_label_box
266                self.notebook.append_page(control.widget, tab_label_box)
267
268                # If GTK+ version >= 2.10, use gtk native way to reorder tabs
269                if gtk.pygtk_version >= (2, 10, 0) and gtk.gtk_version >= (2, 10, 0):
270                        self.notebook.set_tab_reorderable(control.widget, True)
271                else:
272                        self.setup_tab_dnd(control.widget)
273
274                self.redraw_tab(control)
275                if self.parent_paned:
276                        self.notebook.show_all()
277                else:
278                        self.window.show_all()
279                # NOTE: we do not call set_control_active(True) since we don't know whether
280                # the tab is the active one.
281                self.show_title()
282
283        def on_tab_eventbox_button_press_event(self, widget, event, child):
284                if event.button == 3: # right click
285                        n = self.notebook.page_num(child)
286                        self.notebook.set_current_page(n)
287                        self.popup_menu(event)
288                elif event.button == 2: # middle click
289                        ctrl = self._widget_to_control(child)
290                        self.remove_tab(ctrl, self.CLOSE_TAB_MIDDLE_CLICK)
291
292        def _on_message_textview_mykeypress_event(self, widget, event_keyval,
293                event_keymod):
294                # NOTE: handles mykeypress which is custom signal; see message_textview.py
295
296                # construct event instance from binding
297                event = gtk.gdk.Event(gtk.gdk.KEY_PRESS) # it's always a key-press here
298                event.keyval = event_keyval
299                event.state = event_keymod
300                event.time = 0 # assign current time
301
302                if event.state & gtk.gdk.CONTROL_MASK:
303                        # Tab switch bindings
304                        if event.keyval == gtk.keysyms.Tab: # CTRL + TAB
305                                self.move_to_next_unread_tab(True)
306                        elif event.keyval == gtk.keysyms.ISO_Left_Tab: # CTRL + SHIFT + TAB
307                                self.move_to_next_unread_tab(False)
308                        elif event.keyval == gtk.keysyms.Page_Down: # CTRL + PAGE DOWN
309                                self.notebook.emit('key_press_event', event)
310                        elif event.keyval == gtk.keysyms.Page_Up: # CTRL + PAGE UP
311                                self.notebook.emit('key_press_event', event)
312
313        def accel_group_func(self, accel_group, acceleratable, keyval, modifier):
314                st = '1234567890' # alt+1 means the first tab (tab 0)
315                control = self.get_active_control()
316                if not control:
317                        # No more control in this window
318                        return
319
320                # CTRL mask
321                if modifier & gtk.gdk.CONTROL_MASK:
322                        if keyval == gtk.keysyms.h: # CTRL + h
323                                control._on_history_menuitem_activate()
324                        elif control.type_id == message_control.TYPE_CHAT and \
325                        keyval == gtk.keysyms.f: # CTRL + f
326                                control._on_send_file_menuitem_activate(None)
327                        elif control.type_id == message_control.TYPE_CHAT and \
328                        keyval == gtk.keysyms.g: # CTRL + g
329                                control._on_convert_to_gc_menuitem_activate(None)
330                        elif control.type_id in (message_control.TYPE_CHAT,
331                        message_control.TYPE_PM) and keyval == gtk.keysyms.i: # CTRL + i
332                                control._on_contact_information_menuitem_activate(None)
333                        elif keyval == gtk.keysyms.l or keyval == gtk.keysyms.L: # CTRL + l|L
334                                control.conv_textview.clear()
335                        elif control.type_id == message_control.TYPE_GC and \
336                        keyval == gtk.keysyms.n: # CTRL + n
337                                control._on_change_nick_menuitem_activate(None)
338                        elif keyval == gtk.keysyms.u: # CTRL + u: emacs style clear line
339                                control.clear(control.msg_textview)
340                        elif keyval == gtk.keysyms.v: # CTRL + v: Paste into msg_textview
341                                if not control.msg_textview.is_focus():
342                                        control.msg_textview.grab_focus()
343                                # Paste into the msg textview
344                                event = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
345                                event.window = self.window.window
346                                event.time = int(time.time())
347                                event.state = gtk.gdk.CONTROL_MASK
348                                event.keyval = gtk.keysyms.v
349                                control.msg_textview.emit('key_press_event', event)
350                        elif control.type_id == message_control.TYPE_GC and \
351                        keyval == gtk.keysyms.b: # CTRL + b
352                                control._on_bookmark_room_menuitem_activate(None)
353                        # Tab switch bindings
354                        elif keyval == gtk.keysyms.ISO_Left_Tab: # CTRL + SHIFT + TAB
355                                self.move_to_next_unread_tab(False)
356                        elif keyval == gtk.keysyms.Tab: # CTRL + TAB
357                                self.move_to_next_unread_tab(True)
358                        elif keyval == gtk.keysyms.F4: # CTRL + F4
359                                self.remove_tab(control, self.CLOSE_CTRL_KEY)
360                        elif keyval == gtk.keysyms.w: # CTRL + w
361                                # CTRL + w removes latest word before sursor when User uses emacs
362                                # theme
363                                if not gtk.settings_get_default().get_property(
364                                'gtk-key-theme-name') == 'Emacs':
365                                        self.remove_tab(control, self.CLOSE_CTRL_KEY)
366                        elif keyval in (gtk.keysyms.Page_Up, gtk.keysyms.Page_Down):
367                                # CTRL + PageUp | PageDown
368                                # Create event and send it to notebook
369                                event = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
370                                event.window = self.window.window
371                                event.time = int(time.time())
372                                event.state = gtk.gdk.CONTROL_MASK
373                                event.keyval = int(keyval)
374                                self.notebook.emit('key_press_event', event)
375
376                # MOD1 (ALT) mask
377                elif modifier & gtk.gdk.MOD1_MASK:
378                        # Tab switch bindings
379                        if keyval == gtk.keysyms.Right: # ALT + RIGHT
380                                new = self.notebook.get_current_page() + 1
381                                if new >= self.notebook.get_n_pages():
382                                        new = 0
383                                self.notebook.set_current_page(new)
384                        elif keyval == gtk.keysyms.Left: # ALT + LEFT
385                                new = self.notebook.get_current_page() - 1
386                                if new < 0:
387                                        new = self.notebook.get_n_pages() - 1
388                                self.notebook.set_current_page(new)
389                        elif chr(keyval) in st: # ALT + 1,2,3..
390                                self.notebook.set_current_page(st.index(chr(keyval)))
391                        elif keyval == gtk.keysyms.c: # ALT + C toggles chat buttons
392                                control.chat_buttons_set_visible(not control.hide_chat_buttons)
393                        elif keyval == gtk.keysyms.m: # ALT + M show emoticons menu
394                                control.show_emoticons_menu()
395                        elif keyval == gtk.keysyms.a: # ALT + A show actions menu
396                                control.on_actions_button_clicked(control.actions_button)
397                        elif control.type_id == message_control.TYPE_GC and \
398                        keyval == gtk.keysyms.t: # ALT + t
399                                control._on_change_subject_menuitem_activate(None)
400                # Close tab bindings
401                elif keyval == gtk.keysyms.Escape and \
402                                gajim.config.get('escape_key_closes'): # Escape
403                        self.remove_tab(control, self.CLOSE_ESC)
404
405        def _on_close_button_clicked(self, button, control):
406                '''When close button is pressed: close a tab'''
407                self.remove_tab(control, self.CLOSE_CLOSE_BUTTON)
408
409        def show_title(self, urgent=True, control=None):
410                '''redraw the window's title'''
411                if not control:
412                        control = self.get_active_control()
413                if not control:
414                        # No more control in this window
415                        return
416                unread = 0
417                for ctrl in self.controls():
418                        if ctrl.type_id == message_control.TYPE_GC and not \
419                        gajim.config.get('notify_on_all_muc_messages') and not \
420                        ctrl.attention_flag:
421                                # count only pm messages
422                                unread += ctrl.get_nb_unread_pm()
423                                continue
424                        unread += ctrl.get_nb_unread()
425
426                unread_str = ''
427                if unread > 1:
428                        unread_str = '[' + unicode(unread) + '] '
429                elif unread == 1:
430                        unread_str = '* '
431                else:
432                        urgent = False
433
434                if control.type_id == message_control.TYPE_GC:
435                        name = control.room_jid.split('@')[0]
436                        urgent = control.attention_flag
437                else:
438                        name = control.contact.get_shown_name()
439                        if control.resource:
440                                name += '/' + control.resource
441
442                window_mode = gajim.interface.msg_win_mgr.mode
443                if window_mode == MessageWindowMgr.ONE_MSG_WINDOW_PERTYPE:
444                        # Show the plural form since number of tabs > 1
445                        if self.type_ == 'chat':
446                                label = _('Chats')
447                        elif self.type_ == 'gc':
448                                label = _('Group Chats')
449                        else:
450                                label = _('Private Chats')
451                elif window_mode == MessageWindowMgr.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER:
452                        label = None
453                elif self.get_num_controls() == 1:
454                        label = name
455                else:
456                        label = _('Messages')
457
458                title = 'Gajim'
459                if label:
460                        title = '%s - %s' % (label, title)
461
462                if window_mode == MessageWindowMgr.ONE_MSG_WINDOW_PERACCT:
463                        title = title + ": " + control.account
464
465                self.window.set_title(unread_str + title)
466
467                if urgent:
468                        gtkgui_helpers.set_unset_urgency_hint(self.window, unread)
469                else:
470                        gtkgui_helpers.set_unset_urgency_hint(self.window, False)
471
472        def set_active_tab(self, ctrl):
473                ctrl_page = self.notebook.page_num(ctrl.widget)
474                self.notebook.set_current_page(ctrl_page)
475                self.window.present()
476
477        def remove_tab(self, ctrl, method, reason = None, force = False):
478                '''reason is only for gc (offline status message)
479                if force is True, do not ask any confirmation'''
480                def close(ctrl):
481                        if reason is not None: # We are leaving gc with a status message
482                                ctrl.shutdown(reason)
483                        else: # We are leaving gc without status message or it's a chat
484                                ctrl.shutdown()
485                        # Update external state
486                        gajim.events.remove_events(ctrl.account, ctrl.get_full_jid,
487                                types = ['printed_msg', 'chat', 'gc_msg'])
488
489                        fjid = ctrl.get_full_jid()
490                        jid = gajim.get_jid_without_resource(fjid)
491
492                        fctrl = self.get_control(fjid, ctrl.account)
493                        bctrl = self.get_control(jid, ctrl.account)
494                        # keep last_message_time around unless this was our last control with
495                        # that jid
496                        if not fctrl and not bctrl:
497                                del gajim.last_message_time[ctrl.account][fjid]
498
499                        # Disconnect tab DnD only if GTK version < 2.10
500                        if gtk.pygtk_version < (2, 10, 0) or gtk.gtk_version < (2, 10, 0):
501                                self.disconnect_tab_dnd(ctrl.widget)
502
503                        self.notebook.remove_page(self.notebook.page_num(ctrl.widget))
504
505                        del self._controls[ctrl.account][fjid]
506
507                        if len(self._controls[ctrl.account]) == 0:
508                                del self._controls[ctrl.account]
509
510                        self.check_tabs()
511                        self.show_title()
512
513                def on_yes(ctrl):
514                        close(ctrl)
515
516                def on_no(ctrl):
517                        return
518
519                def on_minimize(ctrl):
520                        if method != self.CLOSE_COMMAND:
521                                ctrl.minimize()
522                                self.check_tabs()
523                                return
524                        close(ctrl)
525
526                # Shutdown the MessageControl
527                if force:
528                        close(ctrl)
529                else:
530                        ctrl.allow_shutdown(method, on_yes, on_no, on_minimize)
531
532        def check_tabs(self):
533                if self.get_num_controls() == 0:
534                        # These are not called when the window is destroyed like this, fake it
535                        gajim.interface.msg_win_mgr._on_window_delete(self.window, None)
536                        gajim.interface.msg_win_mgr._on_window_destroy(self.window)
537                        # dnd clean up
538                        self.notebook.drag_dest_unset()
539                        if self.parent_paned:
540                                # Don't close parent window, just remove the child
541                                child = self.parent_paned.get_child2()
542                                self.parent_paned.remove(child)
543                        else:
544                                self.window.destroy()
545                        return # don't show_title, we are dead
546                elif self.get_num_controls() == 1: # we are going from two tabs to one
547                        window_mode = gajim.interface.msg_win_mgr.mode
548                        show_tabs_if_one_tab = gajim.config.get('tabs_always_visible') or \
549                                window_mode == MessageWindowMgr.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER
550                        self.notebook.set_show_tabs(show_tabs_if_one_tab)
551                        if not show_tabs_if_one_tab:
552                                self.alignment.set_property('top-padding', 0)
553
554
555        def redraw_tab(self, ctrl, chatstate = None):
556                hbox = self.notebook.get_tab_label(ctrl.widget).get_children()[0]
557                status_img = hbox.get_children()[0]
558                nick_label = hbox.get_children()[1]
559
560                # Optionally hide close button
561                close_button = hbox.get_children()[2]
562                if gajim.config.get('tabs_close_button'):
563                        close_button.show()
564                else:
565                        close_button.hide()
566
567                # Update nick
568                nick_label.set_max_width_chars(10)
569                (tab_label_str, tab_label_color) = ctrl.get_tab_label(chatstate)
570                nick_label.set_markup(tab_label_str)
571                if tab_label_color:
572                        nick_label.modify_fg(gtk.STATE_NORMAL, tab_label_color)
573                        nick_label.modify_fg(gtk.STATE_ACTIVE, tab_label_color)
574
575                tab_img = ctrl.get_tab_image()
576                if tab_img:
577                        if tab_img.get_storage_type() == gtk.IMAGE_ANIMATION:
578                                status_img.set_from_animation(tab_img.get_animation())
579                        else:
580                                status_img.set_from_pixbuf(tab_img.get_pixbuf())
581
582        def repaint_themed_widgets(self):
583                '''Repaint controls in the window with theme color'''
584                # iterate through controls and repaint
585                for ctrl in self.controls():
586                        ctrl.repaint_themed_widgets()
587
588        def _widget_to_control(self, widget):
589                for ctrl in self.controls():
590                        if ctrl.widget == widget:
591                                return ctrl
592                return None
593
594        def get_active_control(self):
595                notebook = self.notebook
596                active_widget = notebook.get_nth_page(notebook.get_current_page())
597                return self._widget_to_control(active_widget)