# HG changeset patch # User Goffi # Date 1282135845 -28800 # Node ID 757518d0583387c23dd2ca7ef1bad54582b6a1b5 # Parent 22cbd3837233bee3b9289005c8abc903c0c82c66 Primitivus: added nick completion diff -r 22cbd3837233 -r 757518d05833 frontends/primitivus/primitivus --- a/frontends/primitivus/primitivus Wed Aug 18 17:27:33 2010 +0800 +++ b/frontends/primitivus/primitivus Wed Aug 18 20:50:45 2010 +0800 @@ -227,11 +227,38 @@ #self.center_part = urwid.Columns([('weight',2,self.contactList),('weight',8,Chat('',self))]) self.center_part = urwid.Columns([('weight',2,self.contactList), ('weight',8,urwid.Filler(urwid.Text('')))]) self.editBar = custom_widgets.AdvancedEdit('> ') + self.editBar.setCompletionMethod(self._nick_completion) urwid.connect_signal(self.editBar,'click',self.onTextEntered) self.menu_roller = self.__buildMenuRoller() self.main_widget = custom_widgets.FocusFrame(self.center_part, header=self.menu_roller, footer=self.editBar, focus_part='footer') return self.main_widget + def _nick_completion(self, text, completion_data): + """Completion method which complete pseudo in group chat + for params, see AdvancedEdit""" + contact = self.contactList.get_contact() ###Based on the fact that there is currently only one contact selectableat once + if contact: + chat = self.chat_wins[contact] + if chat.type != "group": + return text + space = text.rfind(" ") + start = text[space+1:] + nicks = list(chat.occupants) + nicks.sort() + try: + start_idx=nicks.index(completion_data['last_nick'])+1 + if start_idx == len(nicks): + start_idx = 0 + except (KeyError,ValueError): + start_idx = 0 + for idx in range(start_idx,len(nicks)) + range(0,start_idx): + if nicks[idx].lower().startswith(start.lower()): + completion_data['last_nick'] = nicks[idx] + return text[:space+1] + nicks[idx] + (': ' if space < 0 else '') + return text + + + def plug_profile(self, profile_key='@DEFAULT@'): self.loop.widget = self.__buildMainWidget() QuickApp.plug_profile(self, profile_key)