From b89fe57543084f5d6e285118cb410e28db8ca50e Mon Sep 17 00:00:00 2001 From: Nikos Kouremenos Date: Mon, 7 Nov 2005 11:07:55 +0000 Subject: [PATCH] inital patch to make status msg change color in gc too [does not work yet] --- src/groupchat_window.py | 52 ++++++++++++++++++++++++++++++++++++++--- src/gtkgui_helpers.py | 15 ++++++++++++ src/roster_window.py | 17 +------------- 3 files changed, 65 insertions(+), 19 deletions(-) diff --git a/src/groupchat_window.py b/src/groupchat_window.py index 9415c78d3..06875acce 100644 --- a/src/groupchat_window.py +++ b/src/groupchat_window.py @@ -365,9 +365,12 @@ class GroupchatWindow(chat.Chat): # add status msg, if not empty, under contact name in the treeview if status and gajim.config.get('show_status_msgs_in_roster'): status = status.strip() - if status != '': + if status != '': + colorstring = 'dimgrey' # escape markup entities and make them small italic and fg color - colorstring = gajim.config.get('color_for_status_msg_in_roster') + #color = gtkgui_helpers._get_fade_color(self.list_treeview[room_jid], + # selected) + #colorstring = "#%04x%04x%04x" % (color.red, color.green, color.blue) name += '\n' '%s'\ % (colorstring, gtkgui_helpers.escape_for_pango_markup(status)) @@ -1294,6 +1297,44 @@ current room topic.') % command, room_jid) message_textview = self.message_textviews[room_jid] message_textview.set_sensitive(False) self.xmls[room_jid].get_widget('send_button').set_sensitive(False) + + def iter_contact_rows(self): + '''iterate over all contact rows in the tree model''' + return # FIXME: impl + model = self.tree.get_model() + account_iter = model.get_iter_root() + while account_iter: + group_iter = model.iter_children(account_iter) + while group_iter: + contact_iter = model.iter_children(group_iter) + while contact_iter: + yield model[contact_iter] + contact_iter = model.iter_next(contact_iter) + group_iter = model.iter_next(group_iter) + account_iter = model.iter_next(account_iter) + + def _on_list_treeview_style_set(self, treeview, style): + '''When style (theme) changes, redraw all contacts''' + return # FIXME: impl + for contact in self.iter_contact_rows(): + self.draw_contact(contact[C_JID], contact[C_ACCOUNT]) + + def _on_list_treeview_selection_changed(self, selection): + return # FIXME: impl + model, selected_iter = selection.get_selected() + if self._last_selected_contact is not None: + # update unselected row + jid, account = self._last_selected_contact + self.draw_contact(jid, account) + if selected_iter is None: + self._last_selected_contact = None + return + contact = model[selected_iter] + self._last_selected_contact = (contact[C_JID], contact[C_ACCOUNT]) + if contact[C_TYPE] != 'contact': + return + self.draw_contact(contact[C_JID], contact[C_ACCOUNT], selected=True) + def new_room(self, room_jid, nick): self.names[room_jid] = room_jid.split('@')[0] @@ -1308,8 +1349,13 @@ current room topic.') % command, room_jid) self.allow_focus_out_line[room_jid] = True self.last_key_tabs[room_jid] = False self.hpaneds[room_jid] = self.xmls[room_jid].get_widget('hpaned') - self.list_treeview[room_jid] = self.xmls[room_jid].get_widget( + list_treeview = self.list_treeview[room_jid] = self.xmls[room_jid].get_widget( 'list_treeview') + list_treeview.get_selection().connect('changed', + self._on_list_treeview_selection_changed) + list_treeview.connect('style-set', self._on_list_treeview_style_set) + self._last_selected_contact = None # None or holds jid, account tupple + self.subject_tooltip[room_jid] = gtk.Tooltips() chat.Chat.new_tab(self, room_jid) diff --git a/src/gtkgui_helpers.py b/src/gtkgui_helpers.py index 1d91cb0e5..49ef6134b 100644 --- a/src/gtkgui_helpers.py +++ b/src/gtkgui_helpers.py @@ -383,3 +383,18 @@ def file_is_locked(path_to_file): else: # in case all went ok, close file handle (go to hell WinAPI) hfile.Close() return False + +def _get_fade_color(treeview, selected): + '''get a gdk color that is halfway between foreground and background + colors of the cell for the given treeview''' + style = treeview.style + if selected: + state = gtk.STATE_SELECTED + else: + state = gtk.STATE_NORMAL + bg = style.base[state] + fg = style.text[state] + + return gtk.gdk.Color((bg.red + fg.red)/2, + (bg.green + fg.green)/2, + (bg.blue + fg.blue)/2) diff --git a/src/roster_window.py b/src/roster_window.py index a8222635e..df78d5825 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -215,21 +215,6 @@ class RosterWindow: return self.transports_state_images[transport] return self.jabber_state_images - def _get_fade_color(self, selected): - '''get a gdk color that is halfway between foreground and background - colors of the cell''' - style = self.tree.style - if selected: - state = gtk.STATE_SELECTED - else: - state = gtk.STATE_NORMAL - bg = style.base[state] - fg = style.text[state] - - return gtk.gdk.Color((bg.red + fg.red)/2, - (bg.green + fg.green)/2, - (bg.blue + fg.blue)/2) - def draw_contact(self, jid, account, selected=False): '''draw the correct state image and name''' model = self.tree.get_model() @@ -248,7 +233,7 @@ class RosterWindow: status = contact.status.strip() if status != '': # escape markup entities and make them small italic and fg color - color = self._get_fade_color(selected) + color = gtkgui_helpers._get_fade_color(self.tree, selected) colorstring = "#%04x%04x%04x" % (color.red, color.green, color.blue) name += '\n%s'\ % (colorstring, gtkgui_helpers.escape_for_pango_markup(status))