Mercurial > libervia-backend
changeset 1382:b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
- remove QuickChat.id, use QuickChat.target instead
- rename Chat.present_panel to Chat.occupants_panel
- rename Chat.present_wid to Chat.occupants_list
author | souliane <souliane@mailoo.org> |
---|---|
date | Sun, 22 Mar 2015 14:20:19 +0100 |
parents | 0d12d4e32664 |
children | 59c48796759e |
files | frontends/src/primitivus/chat.py frontends/src/quick_frontend/quick_app.py |
diffstat | 2 files changed, 51 insertions(+), 57 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/src/primitivus/chat.py Fri Mar 20 20:49:58 2015 +0100 +++ b/frontends/src/primitivus/chat.py Sun Mar 22 14:20:19 2015 +0100 @@ -52,7 +52,7 @@ def keypress(self, size, key): return key - def rows(self,size,focus=False): + def rows(self, size, focus=False): return self.display_widget(size, focus).rows(size, focus) def render(self, size, focus=False): @@ -62,19 +62,18 @@ return canvas def get_cursor_coords(self, size): - #(maxcol,) = size return 0, 0 def display_widget(self, size, focus): render_txt = [] if not self.is_info: if self.parent.show_timestamp: - time_format = "%c" if self.timestamp < self.parent.day_change else "%H:%M" #if the message was sent before today, we print the full date - render_txt.append(('date',"[%s]" % time.strftime(time_format, self.timestamp).decode('utf-8'))) + time_format = "%c" if self.timestamp < self.parent.day_change else "%H:%M" # if the message was sent before today, we print the full date + render_txt.append(('date', "[%s]" % time.strftime(time_format, self.timestamp).decode('utf-8'))) if self.parent.show_short_nick: - render_txt.append(('my_nick' if self.my_mess else 'other_nick',"**" if self.my_mess else "*")) + render_txt.append(('my_nick' if self.my_mess else 'other_nick', "**" if self.my_mess else "*")) else: - render_txt.append(('my_nick' if self.my_mess else 'other_nick',"[%s] " % self.nick)) + render_txt.append(('my_nick' if self.my_mess else 'other_nick', "[%s] " % self.nick)) render_txt.append(self.message) txt_widget = urwid.Text(render_txt, align=self.align) if self.is_info: @@ -99,39 +98,39 @@ self.historyPrint(profile=self.profile) elif type_ == C.CHAT_GROUP: if len(self.chat_colums.contents) == 1: - present_widget = self._buildPresentList() - self.present_panel = sat_widgets.VerticalSeparator(present_widget) - self._appendPresentPanel() + self.occupants_list = sat_widgets.GenericList([], option_type=sat_widgets.ClickableText, on_click=self._occupantsClicked) + self.occupants_panel = sat_widgets.VerticalSeparator(self.occupants_list) + self._appendOccupantsPanel() - self.day_change = time.strptime(time.strftime("%a %b %d 00:00:00 %Y")) #struct_time of day changing time + self.day_change = time.strptime(time.strftime("%a %b %d 00:00:00 %Y")) # struct_time of day changing time self.show_timestamp = True self.show_short_nick = False - self.show_title = 1 #0: clip title; 1: full title; 2: no title + self.show_title = 1 # 0: clip title; 1: full title; 2: no title self.subject = None def keypress(self, size, key): - if key == a_key['OCCUPANTS_HIDE']: #user wants to (un)hide the presents panel + if key == a_key['OCCUPANTS_HIDE']: # user wants to (un)hide the occupants panel if self.type == C.CHAT_GROUP: widgets = [widget for (widget, options) in self.chat_colums.contents] - if self.present_panel in widgets: - self._removePresentPanel() + if self.occupants_panel in widgets: + self._removeOccupantsPanel() else: - self._appendPresentPanel() - elif key == a_key['TIMESTAMP_HIDE']: #user wants to (un)hide timestamp + self._appendOccupantsPanel() + elif key == a_key['TIMESTAMP_HIDE']: # user wants to (un)hide timestamp self.show_timestamp = not self.show_timestamp for wid in self.content: wid._invalidate() - elif key == a_key['SHORT_NICKNAME']: #user wants to (not) use short nick + elif key == a_key['SHORT_NICKNAME']: # user wants to (not) use short nick self.show_short_nick = not self.show_short_nick for wid in self.content: wid._invalidate() - elif key == a_key['SUBJECT_SWITCH']: #user wants to (un)hide group's subject or change its apperance + elif key == a_key['SUBJECT_SWITCH']: # user wants to (un)hide group's subject or change its apperance if self.subject: self.show_title = (self.show_title + 1) % 3 if self.show_title == 0: - self.setSubject(self.subject,'clip') + self.setSubject(self.subject, 'clip') elif self.show_title == 1: - self.setSubject(self.subject,'space') + self.setSubject(self.subject, 'space') elif self.show_title == 2: self.chat_widget.header = None self._invalidate() @@ -156,12 +155,12 @@ @param occupant_jid (jid.JID): occupant to update @param states (dict{unicode: unicode}): new states """ - options = self.present_wid.getAllValues() + options = self.occupants_list.getAllValues() for index in xrange(0, len(options)): nick = options[index].value if nick == occupant_jid.resource: options[index] = (nick, "%s %s" % (u''.join(states.values()), nick)) - self.present_wid.changeValues(options) + self.occupants_list.changeValues(options) break self.host.redraw() @@ -174,31 +173,27 @@ self.title_dynamic = ' '.join([u'({})'.format(state) for state in states.values()]) self.host.redraw() - def _presentClicked(self, list_wid, clicked_wid): + def _occupantsClicked(self, list_wid, clicked_wid): assert self.type == C.CHAT_GROUP nick = clicked_wid.getValue().value if nick == self.getUserNick(): - #We ignore clicks on our own nick + # We ignore clicks on our own nick return contact_list = self.host.contact_lists[self.profile] full_jid = jid.JID("%s/%s" % (self.target.bare, nick)) - #we have a click on a nick, we need to create the widget if it doesn't exists + # we have a click on a nick, we need to create the widget if it doesn't exists self.getOrCreatePrivateWidget(full_jid) - #now we select the new window + # now we select the new window contact_list.setFocus(full_jid, True) - def _buildPresentList(self): - self.present_wid = sat_widgets.GenericList([],option_type = sat_widgets.ClickableText, on_click=self._presentClicked) - return self.present_wid + def _appendOccupantsPanel(self): + self.chat_colums.contents.append((self.occupants_panel, ('weight', 2, False))) - def _appendPresentPanel(self): - self.chat_colums.contents.append((self.present_panel,('weight', 2, False))) - - def _removePresentPanel(self): + def _removeOccupantsPanel(self): for widget, options in self.chat_colums.contents: - if widget is self.present_panel: + if widget is self.occupants_panel: self.chat_colums.contents.remove((widget, options)) break @@ -225,27 +220,27 @@ """Set title for a group chat""" QuickChat.setSubject(self, subject) self.subject = subject - self.subj_wid = urwid.Text(unicode(subject.replace('\n','|') if wrap == 'clip' else subject ), - align='left' if wrap=='clip' else 'center',wrap=wrap) - self.chat_widget.header = urwid.AttrMap(self.subj_wid,'title') + self.subj_wid = urwid.Text(unicode(subject.replace('\n', '|') if wrap == 'clip' else subject), + align='left' if wrap == 'clip' else 'center', wrap=wrap) + self.chat_widget.header = urwid.AttrMap(self.subj_wid, 'title') self.host.redraw() def addUser(self, param_nick): """Add user if it is not in the group list""" - nick = unicode(param_nick) #FIXME: should be done in DBus bridge + nick = unicode(param_nick) # FIXME: should be done in DBus bridge QuickChat.addUser(self, nick) - presents = self.present_wid.getAllValues() - if nick not in [present.value for present in presents]: - presents.append(nick) - presents.sort(cmp=lambda a, b: cmp(a.value if hasattr(a, 'value') else a, b.value if hasattr(b, 'value') else b)) - self.present_wid.changeValues(presents) + occupants = self.occupants_list.getAllValues() + if nick not in [occupants.value for occupants in occupants]: + occupants.append(nick) + occupants.sort(cmp=lambda a, b: cmp(a.value if hasattr(a, 'value') else a, b.value if hasattr(b, 'value') else b)) + self.occupants_list.changeValues(occupants) self.host.redraw() def removeUser(self, param_nick): """Remove a user from the group list""" - nick = unicode(param_nick) #FIXME: should be done in DBus bridge + nick = unicode(param_nick) # FIXME: should be done in DBus bridge QuickChat.removeUser(self, nick) - self.present_wid.deleteValue(nick) + self.occupants_list.deleteValue(nick) self.host.redraw() def clearHistory(self): @@ -268,7 +263,7 @@ try: timestamp = float(extra['timestamp']) except KeyError: - timestamp=None + timestamp = None try: nick, mymess = QuickChat.printMessage(self, from_jid, msg, extra, profile) except TypeError: @@ -283,7 +278,7 @@ if older and idx > 0: continue # the new message is older, we need to insert it upper - #we discard double messages, to avoid backlog / history conflict + # we discard double messages, to avoid backlog / history conflict # FIXME: messages that have been sent several times will be displayed only once if ((idx and self.content[idx - 1].message == msg) or (self.content[idx].message == msg) or @@ -313,7 +308,7 @@ try: timestamp = float(extra['timestamp']) except KeyError: - timestamp=None + timestamp = None _widget = ChatText(self, timestamp, None, False, msg, is_info=True) self.content.append(_widget) self._notify(msg=msg) @@ -326,8 +321,8 @@ if msg == "": return if self.text_list.get_focus()[1] == len(self.content) - 2: - #we don't change focus if user is not at the bottom - #as that mean that he is probably watching discussion history + # we don't change focus if user is not at the bottom + # as that mean that he is probably watching discussion history self.text_list.focus_position = len(self.content) - 1 self.host.redraw() if not self.host.x_notify.hasFocus(): @@ -336,36 +331,36 @@ elif self.getUserNick().lower() in msg.lower(): self.host.x_notify.sendNotification(_("Primitivus: %(user)s mentioned you in room '%(room)s'") % {'user': from_jid, 'room': self.target}) - #MENU EVENTS# + # MENU EVENTS # def onTarotRequest(self, menu): # TODO: move this to plugin_misc_tarot with dynamic menu if len(self.occupants) != 4: self.host.showPopUp(sat_widgets.Alert(_("Can't start game"), _("You need to be exactly 4 peoples in the room to start a Tarot game"), ok_cb=self.host.removePopUp)) else: - self.host.bridge.tarotGameCreate(self.id, list(self.occupants), self.profile) + self.host.bridge.tarotGameCreate(self.target, list(self.occupants), self.profile) def onSendFileRequest(self, menu): # TODO: move this to core with dynamic menus dialog = FileDialog(ok_cb=self.onFileSelected, cancel_cb=self.host.removePopUp) self.host.showPopUp(dialog, 80, 80) - #MISC EVENTS# + # MISC EVENTS # def onFileSelected(self, filepath): self.host.removePopUp() try: - filepath = filepath.decode('utf-8') # FIXME: correctly manage unicode + filepath = filepath.decode('utf-8') # FIXME: correctly manage unicode except UnicodeError: log.error("FIXME: filepath with unicode error are not managed yet") self.host.showDialog(_(u"File has a unicode error in its name, it's not yet managed by SàT"), title=_("Can't send file"), type_="error") return - #FIXME: check last_resource: what if self.target.resource exists ? + # FIXME: check last_resource: what if self.target.resource exists ? last_resource = self.host.bridge.getMainResource(unicode(self.target.bare), self.profile) if last_resource: full_jid = jid.JID("%s/%s" % (self.target.bare, last_resource)) else: full_jid = self.target progress_id = self.host.bridge.sendFile(full_jid, filepath, {}, self.profile) - self.host.addProgress(progress_id,filepath) + self.host.addProgress(progress_id, filepath) self.host.showDialog(_(u"You file request has been sent, we are waiting for your contact answer"), title=_("File request sent"))
--- a/frontends/src/quick_frontend/quick_app.py Fri Mar 20 20:49:58 2015 +0100 +++ b/frontends/src/quick_frontend/quick_app.py Sun Mar 22 14:20:19 2015 +0100 @@ -533,7 +533,6 @@ room_jid = jid.JID(room_jid_s) chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, profile=profile) chat_widget.setUserNick(user_nick) - chat_widget.id = room_jid # FIXME: to be removed self.contact_lists[profile].setSpecial(room_jid, C.CONTACT_SPECIAL_GROUP) def roomLeftHandler(self, room_jid_s, profile):