control is CTRL not CTL

This commit is contained in:
Nikos Kouremenos 2006-01-11 22:30:49 +00:00
parent 7b926a5639
commit 3dfb3cdcd8
1 changed files with 77 additions and 77 deletions

View File

@ -96,27 +96,27 @@ class MessageWindow:
if widget.props.urgency_hint: if widget.props.urgency_hint:
widget.props.urgency_hint = False widget.props.urgency_hint = False
ctl = self.get_active_control() ctrl = self.get_active_control()
if ctl: if ctrl:
ctl.set_control_active(True) ctrl.set_control_active(True)
# Undo "unread" state display, etc. # Undo "unread" state display, etc.
if ctl.type_id == message_control.TYPE_GC: if ctrl.type_id == message_control.TYPE_GC:
self.redraw_tab(ctl.contact, 'active') self.redraw_tab(ctrl.contact, 'active')
else: else:
# NOTE: we do not send any chatstate to preserve # NOTE: we do not send any chatstate to preserve
# inactive, gone, etc. # inactive, gone, etc.
self.redraw_tab(ctl.contact) self.redraw_tab(ctrl.contact)
def _on_window_delete(self, win, event): def _on_window_delete(self, win, event):
# Make sure all controls are okay with being deleted # Make sure all controls are okay with being deleted
for ctl in self._controls.values(): for ctrl in self._controls.values():
if not ctl.allow_shutdown(): if not ctrl.allow_shutdown():
return True # halt the delete return True # halt the delete
return False return False
def _on_window_destroy(self, win): def _on_window_destroy(self, win):
for ctl in self._controls.values(): for ctrl in self._controls.values():
ctl.shutdown() ctrl.shutdown()
self._controls.clear() self._controls.clear()
def new_tab(self, control): def new_tab(self, control):
@ -176,8 +176,8 @@ class MessageWindow:
def show_title(self, urgent = True, control = None): def show_title(self, urgent = True, control = None):
'''redraw the window's title''' '''redraw the window's title'''
unread = 0 unread = 0
for ctl in self._controls.values(): for ctrl in self._controls.values():
unread += ctl.nb_unread unread += ctrl.nb_unread
unread_str = '' unread_str = ''
if unread > 1: if unread > 1:
unread_str = '[' + unicode(unread) + '] ' unread_str = '[' + unicode(unread) + '] '
@ -198,24 +198,24 @@ class MessageWindow:
gtkgui_helpers.set_unset_urgency_hint(self.window, unread) gtkgui_helpers.set_unset_urgency_hint(self.window, unread)
def set_active_tab(self, jid): def set_active_tab(self, jid):
ctl = self._controls[jid] ctrl = self._controls[jid]
ctl_page = self.notebook.page_num(ctl.widget) ctrl_page = self.notebook.page_num(ctrl.widget)
self.notebook.set_current_page(ctl_page) self.notebook.set_current_page(ctrl_page)
def remove_tab(self, contact): def remove_tab(self, contact):
# Shutdown the MessageControl # Shutdown the MessageControl
ctl = self.get_control(contact.jid) ctrl = self.get_control(contact.jid)
if not ctl.allow_shutdown(): if not ctrl.allow_shutdown():
return return
ctl.shutdown() ctrl.shutdown()
# Update external state # Update external state
if gajim.interface.systray_enabled: if gajim.interface.systray_enabled:
gajim.interface.systray.remove_jid(contact.jid, ctl.account, gajim.interface.systray.remove_jid(contact.jid, ctrl.account,
ctl.type_id) ctrl.type_id)
del gajim.last_message_time[ctl.account][ctl.contact.jid] del gajim.last_message_time[ctrl.account][ctrl.contact.jid]
self.notebook.remove_page(self.notebook.page_num(ctl.widget)) self.notebook.remove_page(self.notebook.page_num(ctrl.widget))
del self._controls[contact.jid] del self._controls[contact.jid]
if len(self._controls) == 1: # we are going from two tabs to one if len(self._controls) == 1: # we are going from two tabs to one
@ -231,10 +231,10 @@ class MessageWindow:
self.window.destroy() self.window.destroy()
def redraw_tab(self, contact, chatstate = None): def redraw_tab(self, contact, chatstate = None):
ctl = self._controls[contact.jid] ctrl = self._controls[contact.jid]
ctl.update_ui() ctrl.update_ui()
hbox = self.notebook.get_tab_label(ctl.widget).get_children()[0] hbox = self.notebook.get_tab_label(ctrl.widget).get_children()[0]
status_img = hbox.get_children()[0] status_img = hbox.get_children()[0]
nick_label = hbox.get_children()[1] nick_label = hbox.get_children()[1]
@ -247,13 +247,13 @@ class MessageWindow:
# Update nick # Update nick
nick_label.set_max_width_chars(10) nick_label.set_max_width_chars(10)
(tab_label_str, tab_label_color) = ctl.get_tab_label(chatstate) (tab_label_str, tab_label_color) = ctrl.get_tab_label(chatstate)
nick_label.set_markup(tab_label_str) nick_label.set_markup(tab_label_str)
if tab_label_color: if tab_label_color:
nick_label.modify_fg(gtk.STATE_NORMAL, tab_label_color) nick_label.modify_fg(gtk.STATE_NORMAL, tab_label_color)
nick_label.modify_fg(gtk.STATE_ACTIVE, tab_label_color) nick_label.modify_fg(gtk.STATE_ACTIVE, tab_label_color)
tab_img = ctl.get_tab_image() tab_img = ctrl.get_tab_image()
if tab_img: if tab_img:
if tab_img.get_storage_type() == gtk.IMAGE_ANIMATION: if tab_img.get_storage_type() == gtk.IMAGE_ANIMATION:
status_img.set_from_animation(tab_img.get_animation()) status_img.set_from_animation(tab_img.get_animation())
@ -263,13 +263,13 @@ class MessageWindow:
def repaint_themed_widgets(self): def repaint_themed_widgets(self):
'''Repaint controls in the window with theme color''' '''Repaint controls in the window with theme color'''
# iterate through controls and repaint # iterate through controls and repaint
for ctl in self._controls.values(): for ctrl in self._controls.values():
ctl.repaint_themed_widgets() ctrl.repaint_themed_widgets()
def _widget_to_control(self, widget): def _widget_to_control(self, widget):
for ctl in self._controls.values(): for ctrl in self._controls.values():
if ctl.widget == widget: if ctrl.widget == widget:
return ctl return ctrl
return None return None
def get_active_control(self): def get_active_control(self):
@ -277,9 +277,9 @@ class MessageWindow:
active_widget = notebook.get_nth_page(notebook.get_current_page()) active_widget = notebook.get_nth_page(notebook.get_current_page())
return self._widget_to_control(active_widget) return self._widget_to_control(active_widget)
def get_active_contact(self): def get_active_contact(self):
ctl = self.get_active_control() ctrl = self.get_active_control()
if ctl: if ctrl:
return ctl.contact return ctrl.contact
return None return None
def get_active_jid(self): def get_active_jid(self):
contact = self.get_active_contact() contact = self.get_active_contact()
@ -293,14 +293,14 @@ class MessageWindow:
return self.window.window.get_origin() return self.window.window.get_origin()
def toggle_emoticons(self): def toggle_emoticons(self):
for ctl in self._controls.values(): for ctrl in self._controls.values():
ctl.toggle_emoticons() ctrl.toggle_emoticons()
def update_font(self): def update_font(self):
for ctl in self._controls.values(): for ctrl in self._controls.values():
ctl.update_font() ctrl.update_font()
def update_tags(self): def update_tags(self):
for ctl in self._controls.values(): for ctrl in self._controls.values():
ctl.update_tags() ctrl.update_tags()
def get_control(self, key): def get_control(self, key):
'''Return the MessageControl for jid or n, where n is the notebook page index''' '''Return the MessageControl for jid or n, where n is the notebook page index'''
@ -309,9 +309,9 @@ class MessageWindow:
if isinstance(key, unicode): if isinstance(key, unicode):
jid = key jid = key
for ctl in self._controls.values(): for ctrl in self._controls.values():
if ctl.contact.jid == jid: if ctrl.contact.jid == jid:
return ctl return ctrl
return None return None
else: else:
page_num = key page_num = key
@ -322,21 +322,21 @@ class MessageWindow:
return self._widget_to_control(nth_child) return self._widget_to_control(nth_child)
def controls(self): def controls(self):
for ctl in self._controls.values(): for ctrl in self._controls.values():
yield ctl yield ctrl
def update_print_time(self): def update_print_time(self):
if gajim.config.get('print_time') != 'sometimes': if gajim.config.get('print_time') != 'sometimes':
for ctl in self.controls(): for ctrl in self.controls():
if ctl.print_time_timeout_id: if ctrl.print_time_timeout_id:
gobject.source_remove(ctl.print_time_timeout_id) gobject.source_remove(ctrl.print_time_timeout_id)
del ctl.print_time_timeout_id del ctrl.print_time_timeout_id
else: else:
for ctl in self.controls(): for ctrl in self.controls():
if not ctl.print_time_timeout_id: if not ctrl.print_time_timeout_id:
ctl.print_time_timeout() ctrl.print_time_timeout()
ctl.print_time_timeout_id = gobject.timeout_add(300000, ctrl.print_time_timeout_id = gobject.timeout_add(300000,
ctl.print_time_timeout, None) ctrl.print_time_timeout, None)
def move_to_next_unread_tab(self, forward): def move_to_next_unread_tab(self, forward):
ind = self.notebook.get_current_page() ind = self.notebook.get_current_page()
@ -354,8 +354,8 @@ class MessageWindow:
ind = self.notebook.get_n_pages() - 1 ind = self.notebook.get_n_pages() - 1
if ind == current: if ind == current:
break # a complete cycle without finding an unread tab break # a complete cycle without finding an unread tab
ctl = self.get_control(ind) ctrl = self.get_control(ind)
if ctl.nb_unread > 0: if ctrl.nb_unread > 0:
found = True found = True
break # found break # found
if found: if found:
@ -377,11 +377,11 @@ class MessageWindow:
# common menuitems (tab switches) # common menuitems (tab switches)
if len(self._controls) > 1: # if there is more than one tab if len(self._controls) > 1: # if there is more than one tab
menu.append(gtk.SeparatorMenuItem()) # seperator menu.append(gtk.SeparatorMenuItem()) # seperator
for ctl in self._controls.values(): for ctrl in self._controls.values():
jid = ctl.contact.jid jid = ctrl.contact.jid
if jid != self.get_active_jid(): if jid != self.get_active_jid():
item = gtk.ImageMenuItem(_('Switch to %s') %\ item = gtk.ImageMenuItem(_('Switch to %s') %\
ctl.contact.get_shown_name()) ctrl.contact.get_shown_name())
img = gtk.image_new_from_stock(gtk.STOCK_JUMP_TO, img = gtk.image_new_from_stock(gtk.STOCK_JUMP_TO,
gtk.ICON_SIZE_MENU) gtk.ICON_SIZE_MENU)
item.set_image(img) item.set_image(img)
@ -394,18 +394,18 @@ class MessageWindow:
def _on_notebook_switch_page(self, notebook, page, page_num): def _on_notebook_switch_page(self, notebook, page, page_num):
old_no = notebook.get_current_page() old_no = notebook.get_current_page()
old_ctl = self._widget_to_control(notebook.get_nth_page(old_no)) old_ctrl = self._widget_to_control(notebook.get_nth_page(old_no))
old_ctl.set_control_active(False) old_ctrl.set_control_active(False)
new_ctl = self._widget_to_control(notebook.get_nth_page(page_num)) new_ctrl = self._widget_to_control(notebook.get_nth_page(page_num))
new_ctl.set_control_active(True) new_ctrl.set_control_active(True)
self.show_title(control = new_ctl) self.show_title(control = new_ctrl)
def _on_notebook_key_press(self, widget, event): def _on_notebook_key_press(self, widget, event):
st = '1234567890' # alt+1 means the first tab (tab 0) st = '1234567890' # alt+1 means the first tab (tab 0)
ctl = self.get_active_control() ctrl = self.get_active_control()
contact = ctl.contact contact = ctrl.contact
jid = ctl.contact.jid jid = ctrl.contact.jid
# CTRL mask # CTRL mask
if event.state & gtk.gdk.CONTROL_MASK: if event.state & gtk.gdk.CONTROL_MASK:
@ -444,17 +444,17 @@ class MessageWindow:
(event.state & gtk.gdk.MOD1_MASK): # ALT + 1,2,3.. (event.state & gtk.gdk.MOD1_MASK): # ALT + 1,2,3..
self.notebook.set_current_page(st.index(event.string)) self.notebook.set_current_page(st.index(event.string))
elif event.keyval == gtk.keysyms.c: # ALT + C toggles compact view elif event.keyval == gtk.keysyms.c: # ALT + C toggles compact view
ctl.set_compact_view(not ctl.compact_view_current) ctrl.set_compact_view(not ctrl.compact_view_current)
# Close tab bindings # Close tab bindings
elif event.keyval == gtk.keysyms.Escape: # ESCAPE elif event.keyval == gtk.keysyms.Escape: # ESCAPE
if ctl.type_id == message_control.TYPE_CHAT: if ctrl.type_id == message_control.TYPE_CHAT:
self.remove_tab(contact) self.remove_tab(contact)
else: else:
# If the active control has a message_textview pass the event to it # If the active control has a message_textview pass the event to it
active_ctl = self.get_active_control() active_ctrl = self.get_active_control()
if isinstance(active_ctl, ChatControlBase): if isinstance(active_ctrl, ChatControlBase):
active_ctl.msg_textview.emit('key_press_event', event) active_ctrl.msg_textview.emit('key_press_event', event)
active_ctl.msg_textview.grab_focus() active_ctrl.msg_textview.grab_focus()
################################################################################ ################################################################################
class MessageWindowMgr: class MessageWindowMgr:
@ -637,11 +637,11 @@ class MessageWindowMgr:
return None return None
def get_controls(self, type): def get_controls(self, type):
ctls = [] ctrls = []
for c in self.controls(): for c in self.controls():
if c.type_id == type: if c.type_id == type:
ctls.append(c) ctrls.append(c)
return ctls return ctrls
def windows(self): def windows(self):
for w in self._windows.values(): for w in self._windows.values():