From b7c2fdc66268d79966f60f8dc593b5fa3284d71f Mon Sep 17 00:00:00 2001 From: Vincent Hanquez Date: Fri, 22 Apr 2005 01:35:36 +0000 Subject: [PATCH] remove too long lines fix too long variables etc... --- src/history_window.py | 36 ++++++----- src/roster_window.py | 107 +++++++++++++++----------------- src/systray.py | 27 ++++---- src/vcard_information_window.py | 5 +- 4 files changed, 86 insertions(+), 89 deletions(-) diff --git a/src/history_window.py b/src/history_window.py index 6b875fad9..4da13e5e8 100644 --- a/src/history_window.py +++ b/src/history_window.py @@ -122,25 +122,27 @@ class History_window: def new_line(self, date, type, data): """write a new line""" - start_iter = self.history_buffer.get_start_iter() - end_iter = self.history_buffer.get_end_iter() + buffer = self.history_buffer + start_iter = buffer.get_start_iter() + end_iter = buffer.get_end_iter() tim = time.strftime('[%x %X] ', time.localtime(float(date))) - self.history_buffer.insert(start_iter, tim) + buffer.insert(start_iter, tim) if type == 'recv': msg = ':'.join(data[0:]) msg = msg.replace('\\n', '\n') - self.history_buffer.insert_with_tags_by_name(start_iter, msg, \ - 'incoming') + buffer.insert_with_tags_by_name(start_iter, msg, + 'incoming') elif type == 'sent': msg = ':'.join(data[0:]) msg = msg.replace('\\n', '\n') - self.history_buffer.insert_with_tags_by_name(start_iter, msg, \ - 'outgoing') + buffer.insert_with_tags_by_name(start_iter, msg, + 'outgoing') else: msg = ':'.join(data[1:]) msg = msg.replace('\\n', '\n') - self.history_buffer.insert_with_tags_by_name(start_iter, \ - _('Status is now: ') + data[0]+': ' + msg, 'status') + buffer.insert_with_tags_by_name(start_iter, + _('Status is now: ') + data[0] + + ': ' + msg, 'status') def __init__(self, plugin, jid): self.plugin = plugin @@ -154,15 +156,19 @@ class History_window: self.forward_button = xml.get_widget('forward_button') self.latest_button = xml.get_widget('latest_button') xml.signal_autoconnect(self) - tagIn = self.history_buffer.create_tag('incoming') + + tag = self.history_buffer.create_tag('incoming') color = gajim.config.get('inmsgcolor') - tagIn.set_property('foreground', color) - tagOut = self.history_buffer.create_tag('outgoing') + tag.set_property('foreground', color) + + tag = self.history_buffer.create_tag('outgoing') color = gajim.config.get('outmsgcolor') - tagOut.set_property('foreground', color) - tagStatus = self.history_buffer.create_tag('status') + tag.set_property('foreground', color) + + tag = self.history_buffer.create_tag('status') color = gajim.config.get('statusmsgcolor') - tagStatus.set_property('foreground', color) + tag.set_property('foreground', color) + begin = 0 if self.nb_line > 50: begin = self.nb_line - 50 diff --git a/src/roster_window.py b/src/roster_window.py index f712f9220..d5d2862c6 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -52,34 +52,24 @@ class Roster_window: if self.regroup: return None model = self.tree.get_model() - fin = False account = model.get_iter_root() - if not account: - return None - while not fin: + while account: account_name = model.get_value(account, 3) if name == account_name: - return account + break account = model.iter_next(account) - if not account: - fin = True - return None + return account def get_group_iter(self, name, account): model = self.tree.get_model() root = self.get_account_iter(account) - fin = False group = model.iter_children(root) - if not group: - fin = True - while not fin: + while group: group_name = model.get_value(group, 3) if name == group_name: - return group + break group = model.iter_next(group) - if not group: - fin = True - return None + return group def get_user_iter(self, jid, account): model = self.tree.get_model() @@ -87,22 +77,13 @@ class Roster_window: found = [] fin = False group = model.iter_children(acct) - if not group: - return found - while not fin: - fin2 = False + while group: user = model.iter_children(group) - if not user: - fin2 = True - while not fin2: + while user: if jid == model.get_value(user, 3): found.append(user) user = model.iter_next(user) - if not user: - fin2 = True group = model.iter_next(group) - if not group: - fin = True return found def add_account_to_roster(self, account): @@ -111,11 +92,11 @@ class Roster_window: model = self.tree.get_model() if self.get_account_iter(account): return - statuss = ['offline', 'connecting', 'online', 'away', 'xa', 'dnd', - 'invisible'] + statuss = ['offline', 'connecting', 'online', + 'away', 'xa', 'dnd', 'invisible'] status = statuss[gajim.connections[account].connected] - model.append(None, (self.pixbufs[status], account, 'account', account, - account, False)) + model.append(None, (self.pixbufs[status], account, + 'account', account, account, False)) def remove_newly_added(self, jid, account): if jid in self.newly_added[account]: @@ -134,9 +115,9 @@ class Roster_window: elif user.groups == []: user.groups.append('General') - if (user.show == 'offline' or user.show == 'error') and not showOffline\ - and not 'Agents' in user.groups and \ - not self.plugin.queues[account].has_key(user.jid): + if (user.show == 'offline' or user.show == 'error') and \ + not showOffline and not 'Agents' in user.groups and \ + not self.plugin.queues[account].has_key(user.jid): return model = self.tree.get_model() @@ -148,11 +129,12 @@ class Roster_window: (self.pixbufs['closed'], g, 'group', g, account, False)) if not self.groups[account].has_key(g): #It can probably never append if account + g in self.hidden_lines: - self.groups[account][g] = {'expand': False} + ishidden = False else: - self.groups[account][g] = {'expand': True} - if not account in self.hidden_lines and not gajim.config.get( - 'mergeaccounts'): + ishidden = True + self.groups[account][g] = { 'expand': ishidden } + if not account in self.hidden_lines and \ + not gajim.config.get('mergeaccounts'): self.tree.expand_row((model.get_path(iterG)[0]), False) typestr = 'user' @@ -160,10 +142,11 @@ class Roster_window: typestr = 'agent' model.append(iterG, (self.pixbufs[user.show], user.name, - typestr, user.jid, account, False)) + typestr, user.jid, account, False)) if self.groups[account][g]['expand']: - self.tree.expand_row(model.get_path(iterG), False) + self.tree.expand_row(model.get_path(iterG), + False) self.redraw_jid(jid, account) def really_remove_user(self, user, account): @@ -357,18 +340,23 @@ class Roster_window: if not show: show = 'offline' - user1 = User(ji, name, array[jid]['groups'], show, - array[jid]['status'], array[jid]['sub'], - array[jid]['ask'], resource, 0, '') - #when we draw the roster, we can't have twice the same user with - # 2 resources + user1 = User(ji, name, array[jid]['groups'], + show, array[jid]['status'], + array[jid]['sub'], array[jid]['ask'], + resource, 0, '') + + # when we draw the roster, we can't have twice the same + # user with 2 resources self.contacts[account][ji] = [user1] for g in array[jid]['groups'] : - if not g in self.groups[account].keys(): - if account + g in self.hidden_lines: - self.groups[account][g] = {'expand': False} - else: - self.groups[account][g] = {'expand': True} + if g in self.groups[account].keys(): + continue + + if account + g in self.hidden_lines: + ishidden = False + else: + ishidden = True + self.groups[account][g] = { 'expand': ishidden } def chg_user_status(self, user, show, status, account): '''When a user change his status''' @@ -378,7 +366,7 @@ class Roster_window: user.show = show user.status = status if (show == 'offline' or show == 'error') and \ - not self.plugin.queues[account].has_key(user.jid): + not self.plugin.queues[account].has_key(user.jid): if len(luser) > 1: luser.remove(user) self.redraw_jid(user.jid, account) @@ -401,11 +389,12 @@ class Roster_window: def on_info(self, widget, user, account): '''Call vcard_information_window class to display user's information''' - if self.plugin.windows[account]['infos'].has_key(user.jid): - self.plugin.windows[account]['infos'][user.jid].window.present() + info = self.plugin.windows[account]['infos'] + if info.has_key(user.jid): + info[user.jid].window.present() else: - self.plugin.windows[account]['infos'][user.jid] = \ - Vcard_information_window(user, self.plugin, account) + info[user.jid] = Vcard_information_window(user, + self.plugin, account) def on_agent_logging(self, widget, jid, state, account): '''When an agent is requested to log in or off''' @@ -1146,9 +1135,11 @@ class Roster_window: iconset = 'sun' self.path = '../data/iconsets/' + iconset + '/' self.pixbufs = {} - for state in ('connecting', 'online', 'chat', 'away', 'xa', 'dnd', - 'invisible', 'offline', 'error', 'requested', 'message', - 'opened', 'closed', 'not in the roster'): + for state in ('connecting', 'online', 'chat', 'away', 'xa', + 'dnd', 'invisible', 'offline', 'error', + 'requested', 'message', 'opened', 'closed', + 'not in the roster'): + # try to open a pixfile with the correct method state_file = state.replace(' ', '_') files = [] diff --git a/src/systray.py b/src/systray.py index bae40a778..26fb6b164 100644 --- a/src/systray.py +++ b/src/systray.py @@ -55,9 +55,10 @@ class Systray: for acct in gajim.connections: #in chat / groupchat windows for kind in ['chats', 'gc']: - for jid in self.plugin.windows[acct][kind]: + jids = self.plugin.windows[acct][kind] + for jid in jids: if jid != 'tabbed': - nb += self.plugin.windows[acct][kind][jid].nb_unread[jid] + nb += jids[jid].nb_unread[jid] if nb > 1: label = _('Gajim - %s unread messages') % nb else: @@ -110,12 +111,9 @@ class Systray: new_message_menuitem = self.xml.get_widget('new_message_menuitem') #menu.append(new_message_menuitem) - if len(gajim.connections.keys()) > 0: - chat_with_menuitem.set_sensitive(True) - new_message_menuitem.set_sensitive(True) - else: - chat_with_menuitem.set_sensitive(False) - new_message_menuitem.set_sensitive(False) + iskey = len(gajim.connections.keys()) > 0 + chat_with_menuitem.set_sensitive(iskey) + new_message_menuitem.set_sensitive(iskey) if len(gajim.connections.keys()) >= 2: # 2 or more accounts? make submenus account_menu_for_chat_with = gtk.Menu() @@ -199,12 +197,13 @@ class Systray: else: account = self.jids[0][0] jid = self.jids[0][1] - if self.plugin.windows[account]['gc'].has_key(jid): - self.plugin.windows[account]['gc'][jid].active_tab(jid) - self.plugin.windows[account]['gc'][jid].window.present() - elif self.plugin.windows[account]['chats'].has_key(jid): - self.plugin.windows[account]['chats'][jid].active_tab(jid) - self.plugin.windows[account]['chats'][jid].window.present() + acc = self.plugin.windows[account] + if acc['gc'].has_key(jid): + acc['gc'][jid].active_tab(jid) + acc['gc'][jid].window.present() + elif acc['chats'].has_key(jid): + acc['chats'][jid].active_tab(jid) + acc['chats'][jid].window.present() else: self.plugin.roster.new_chat( self.plugin.roster.contacts[account][jid][0], account) diff --git a/src/vcard_information_window.py b/src/vcard_information_window.py index 42a6f5a1c..32da07ddb 100644 --- a/src/vcard_information_window.py +++ b/src/vcard_information_window.py @@ -95,10 +95,11 @@ class Vcard_information_window: self.xml.get_widget('nickname_label').set_text(self.user.name) self.xml.get_widget('jid_label').set_text(self.user.jid) self.xml.get_widget('subscription_label').set_text(self.user.sub) + label = self.xml.get_widget('ask_label') if self.user.ask: - self.xml.get_widget('ask_label').set_text(self.user.ask) + label.set_text(self.user.ask) else: - self.xml.get_widget('ask_label').set_text('None') + label.set_text('None') self.xml.get_widget('nickname_entry').set_text(self.user.name) log = 1 if self.user.jid in gajim.config.get_per('accounts', self.account, \