From 1b5b9138a40342f52f51cbbf39bb1de511b46f60 Mon Sep 17 00:00:00 2001 From: Stephan Erb Date: Sat, 5 Jan 2008 22:07:53 +0000 Subject: [PATCH] Kill risk of double color usage when color pool is not exhausted. Make code a bit more pythonic. --- src/conversation_textview.py | 5 ++--- src/groupchat_control.py | 13 +++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/conversation_textview.py b/src/conversation_textview.py index 9a88e9586..27ee3bdc3 100644 --- a/src/conversation_textview.py +++ b/src/conversation_textview.py @@ -213,10 +213,9 @@ class ConversationTextview: colors = gajim.config.get('gc_nicknames_colors') colors = colors.split(':') - for color in xrange(len(colors)): - tagname = 'gc_nickname_color_' + str(color) + for i,color in enumerate(colors): + tagname = 'gc_nickname_color_' + str(i) tag = buffer.create_tag(tagname) - color = colors[color] tag.set_property('foreground', color) tag = buffer.create_tag('marked') diff --git a/src/groupchat_control.py b/src/groupchat_control.py index 297c90fe2..13b52fb05 100644 --- a/src/groupchat_control.py +++ b/src/groupchat_control.py @@ -235,6 +235,12 @@ class GroupchatControl(ChatControlBase): self.tooltip = tooltips.GCTooltip() + # nickname coloring + self.gc_count_nicknames_colors = 0 + self.gc_custom_colors = {} + self.number_of_colors = len(gajim.config.get('gc_nicknames_colors').\ + split(':')) + # connect the menuitems to their respective functions xm = gtkgui_helpers.get_glade('gc_control_popup_menu.glade') @@ -652,9 +658,6 @@ class GroupchatControl(ChatControlBase): fin = True return None - gc_count_nicknames_colors = 0 - gc_custom_colors = {} - def print_old_conversation(self, text, contact = '', tim = None, xhtml = None): if isinstance(text, str): @@ -705,9 +708,7 @@ class GroupchatControl(ChatControlBase): str(self.gc_custom_colors[contact])) else: self.gc_count_nicknames_colors += 1 - number_of_colors = len(gajim.config.get('gc_nicknames_colors').\ - split(':')) - if self.gc_count_nicknames_colors == number_of_colors: + if self.gc_count_nicknames_colors == self.number_of_colors: self.gc_count_nicknames_colors = 0 self.gc_custom_colors[contact] = \ self.gc_count_nicknames_colors