# HG changeset patch # User souliane # Date 1380198744 -7200 # Node ID 744426c2b699b4419944bf7785c0143e86fc0132 # Parent 9b93a21dc5e27473b83bd0788ab914051d9cb00f browser_side, misc: better PEP8 compliance diff -r 9b93a21dc5e2 -r 744426c2b699 browser_side/contact.py --- a/browser_side/contact.py Thu Sep 26 11:39:54 2013 +0200 +++ b/browser_side/contact.py Thu Sep 26 14:32:24 2013 +0200 @@ -19,7 +19,7 @@ along with this program. If not, see . """ -import pyjd # this is dummy in pyjs +import pyjd # this is dummy in pyjs from pyjamas.ui.SimplePanel import SimplePanel from pyjamas.ui.ScrollPanel import ScrollPanel from pyjamas.ui.VerticalPanel import VerticalPanel @@ -54,7 +54,7 @@ self.host = host self.name = name or jid self.waiting = False - self.jid=jid + self.jid = jid self._fill() self.setStyleName('contact') DragLabel.__init__(self, jid, "CONTACT") @@ -94,7 +94,7 @@ for wid in self: if isinstance(wid, GroupLabel) and wid.group == group: VerticalPanel.remove(self, wid) - + class ContactList(VerticalPanel): def __init__(self, host): @@ -151,6 +151,7 @@ elif type == 'messageWaiting': _item.setMessageWaiting(state) + class ContactTitleLabel(DragLabel, Label, ClickHandler): def __init__(self, host, text): Label.__init__(self, text) #, Element=DOM.createElement('div') @@ -166,15 +167,15 @@ class ContactPanel(SimplePanel): """Manage the contacts and groups""" - + def __init__(self, host): SimplePanel.__init__(self) self.scroll_panel = ScrollPanel() - + self.host = host - self.groups={} - self.connected = {} #jid connected as key and their status + self.groups = {} + self.connected = {} # jid connected as key and their status self.vPanel = VerticalPanel() _title = ContactTitleLabel(host, 'Contacts') @@ -184,7 +185,7 @@ self._contact_list.setStyleName('contactList') self._groupList = GroupList(self) self._groupList.setStyleName('groupList') - + self.vPanel.add(_title) self.vPanel.add(self._groupList) self.vPanel.add(self._contact_list) @@ -200,11 +201,11 @@ print ("ERROR: no TabBar found, it should exist !") tab_bar_h = height else: - tab_bar_h = DOM.getAbsoluteTop( _elts.item(0)) or height #getAbsoluteTop can be 0 if tabBar is hidden + tab_bar_h = DOM.getAbsoluteTop(_elts.item(0)) or height # getAbsoluteTop can be 0 if tabBar is hidden ideal_height = tab_bar_h - DOM.getAbsoluteTop(contact_panel_elt) - 5 self.scroll_panel.setHeight("%s%s" % (ideal_height, "px")); - + def updateContact(self, jid, attributes, groups): """Add a contact to the panel if it doesn't exist, update it else @@ -216,39 +217,39 @@ _key = "@%s: " for group in _current_groups.difference(_new_groups): - #We remove the contact from the groups where he isn't anymore + # We remove the contact from the groups where he isn't anymore self.groups[group].remove(jid) if not self.groups[group]: - #The group is now empty, we must remove it + # The group is now empty, we must remove it del self.groups[group] self._groupList.remove(group) self.host.uni_box.removeKey(_key % group) for group in _new_groups.difference(_current_groups): - #We add the contact to the groups he joined + # We add the contact to the groups he joined if not self.groups.has_key(group): self.groups[group] = set() self._groupList.add(group) self.host.uni_box.addKey(_key % group) self.groups[group].add(jid) - - #We add the contact to contact list, it will check if contact already exists + + # We add the contact to contact list, it will check if contact already exists self._contact_list.add(jid) def removeContact(self, jid): """Remove contacts from groups where he is and contact list""" - self.updateContact(jid, {}, []) #we remove contact from every group + self.updateContact(jid, {}, []) # we remove contact from every group self._contact_list.remove(jid) def setConnected(self, jid, resource, availability, priority, statuses): """Set connection status""" - if availability=='unavailable': + if availability == 'unavailable': if self.connected.has_key(jid): if self.connected[jid].has_key(resource): del self.connected[jid][resource] if not self.connected[jid]: del self.connected[jid] - else: + else: if not self.connected.has_key(jid): self.connected[jid] = {} self.connected[jid][resource] = (availability, priority, statuses) @@ -260,8 +261,6 @@ @param waiting: True if message are waiting""" self._contact_list.setState(jid, "messageWaiting", waiting) - - def getConnected(self): """return a list of all jid (bare jid) connected""" return self.connected.keys() @@ -271,7 +270,7 @@ @param group: string of single group, or list of string @param contact_jid: jid to test """ - result=set() + result = set() for group in self.groups: if self.isContactInGroup(group, contact_jid): result.add(group) @@ -301,7 +300,7 @@ def onMouseMove(self, sender, x, y): pass - + def onMouseDown(self, sender, x, y): pass @@ -313,7 +312,7 @@ for contact in self._contact_list: if contact.jid in self.groups[sender.group]: contact.addStyleName("selected") - + def onMouseLeave(self, sender): if isinstance(sender, GroupLabel): for contact in self._contact_list: diff -r 9b93a21dc5e2 -r 744426c2b699 browser_side/panels.py --- a/browser_side/panels.py Thu Sep 26 11:39:54 2013 +0200 +++ b/browser_side/panels.py Thu Sep 26 14:32:24 2013 +0200 @@ -19,7 +19,7 @@ along with this program. If not, see . """ -import pyjd # this is dummy in pyjs +import pyjd # this is dummy in pyjs from pyjamas.ui.SimplePanel import SimplePanel from pyjamas.ui.AbsolutePanel import AbsolutePanel from pyjamas.ui.VerticalPanel import VerticalPanel @@ -117,7 +117,7 @@ self._popup.addStyleName(style) left = 0 - top = 0 #max(0, self.getAbsoluteTop() - contents.getOffsetHeight() - 2) + top = 0 # max(0, self.getAbsoluteTop() - contents.getOffsetHeight() - 2) self._popup.setPopupPosition(left, top) self._popup.show() @@ -138,7 +138,7 @@ def getSelectedOrStatus(): if target: _type, msg = target.getWarningData() - target_hook = None # we use the selected widget, not a hook + target_hook = None # we use the selected widget, not a hook else: _type, msg = "STATUS", "This will be your new status message" target_hook = (txt, None) @@ -155,7 +155,7 @@ if _end == -1: target_hook, _type, msg = getSelectedOrStatus() else: - group = txt[1:_end] #only one target group is managed for the moment + group = txt[1:_end] # only one target group is managed for the moment if not group or not group in self.host.contact_panel.getGroups(): # the group doesn't exists, we ignore the key group = None @@ -163,7 +163,7 @@ else: _type = "GROUP" msg = MicroblogPanel.warning_msg_group % group - target_hook = (txt[_end+2:], group) + target_hook = (txt[_end + 2:], group) else: print "ERROR: Unknown target" target_hook, _type, msg = getSelectedOrStatus() @@ -171,7 +171,7 @@ return (target_hook, _type, msg) def onBrowserEvent(self, event): - #XXX: woraroung a pyjamas bug: self.currentEvent is not set + # XXX: woraroung a pyjamas bug: self.currentEvent is not set # so the TextBox's cancelKey doens't work. This is a workaround # FIXME: fix the bug upstream self.currentEvent = event @@ -183,12 +183,12 @@ if not self._popup: self.showWarning(target) elif target != self._popup.target_data: - self._timeCb(None) #we remove the popup + self._timeCb(None) # we remove the popup self.showWarning(target) self._timer.schedule(2000) - #if keycode == KEY_ENTER and not self.visible: + # if keycode == KEY_ENTER and not self.visible: if keycode == KEY_ENTER: if _txt: target_hook, _type, msg = target @@ -202,10 +202,10 @@ self.host.bridge.call('setStatus', None, parsed_txt) else: print "ERROR: Unknown target hook type" - else: #we send the message to the selected target + else: # we send the message to the selected target self._selected_cache.onTextEntered(_txt) self.setText('') - self._timeCb(None) #we remove the popup + self._timeCb(None) # we remove the popup sender.cancelKey() else: self.__onComposing() @@ -232,14 +232,14 @@ class MicroblogItem(): - #XXX: should be moved in a separated module + # XXX: should be moved in a separated module def __init__(self, data): self.id = data['id'] self.type = data.get('type', 'main_item') self.content = data['content'] self.author = data['author'] - self.timestamp = float(data.get('timestamp', 0)) #XXX: int doesn't work here + self.timestamp = float(data.get('timestamp', 0)) # XXX: int doesn't work here self.comments = data.get('comments', False) if self.comments: try: @@ -249,7 +249,7 @@ except KeyError: print "Warning: can't manage comment [%s], some keys are missing in microblog data (%s)" % (data["comments"], data.keys()) self.comments = False - if set(("service","node")).issubset(data.keys()): + if set(("service", "node")).issubset(data.keys()): self.service = data["service"] self.node = data["node"] self.hash = (self.service, self.node) @@ -431,14 +431,14 @@ parent_idx = self.vpanel.getWidgetIndex(parent) # we find or create the panel where the comment must be inserted try: - sub_panel = self.vpanel.getWidget(parent_idx+1) + sub_panel = self.vpanel.getWidget(parent_idx + 1) except IndexError: sub_panel = None if not sub_panel or not isinstance(sub_panel, VerticalPanel): sub_panel = VerticalPanel() sub_panel.setStyleName('microblogPanel') sub_panel.addStyleName('subPanel') - self.vpanel.insert(sub_panel, parent_idx+1) + self.vpanel.insert(sub_panel, parent_idx + 1) # we want comments to be inserted in chronological order self._chronoInsert(sub_panel, _entry, reverse=False) @@ -518,7 +518,7 @@ self.setHTML(self.__getContent()) def onClick(self, sender): - #As status is the default target of uniBar, we don't want to select anything if click on it + # As status is the default target of uniBar, we don't want to select anything if click on it self.host.setSelected(None) @@ -625,7 +625,7 @@ def createChat(cls, host, item): _contact = JID(item) host.contact_panel.setContactMessageWaiting(_contact.bare, False) - _new_panel = ChatPanel(host, _contact) #XXX: pyjamas doesn't seems to support creating with cls directly + _new_panel = ChatPanel(host, _contact) # XXX: pyjamas doesn't seems to support creating with cls directly _new_panel.historyPrint() return _new_panel @@ -702,7 +702,7 @@ """Print message in chat window. Must be implemented by child class""" _jid = JID(from_jid) nick = _jid.node if self.type == 'one2one' else _jid.resource - mymess = _jid.resource == self.nick if self.type == "group" else _jid.bare == self.host.whoami.bare #mymess = True if message comes from local user + mymess = _jid.resource == self.nick if self.type == "group" else _jid.bare == self.host.whoami.bare # mymess = True if message comes from local user if msg.startswith('/me '): self.printInfo('* %s %s' % (nick, msg[4:]), type='me') return @@ -718,7 +718,7 @@ self.vpanel.insert(self.tarot_panel, 0) self.vpanel.setCellHeight(self.tarot_panel, self.tarot_panel.getHeight()) elif game_type == "RadioCol": - #XXX: We can have double panel if we join quickly enough to have the group chat start signal + # XXX: We can have double panel if we join quickly enough to have the group chat start signal # on invitation + the one triggered on room join if hasattr(self, "radiocol_panel"): return @@ -728,7 +728,7 @@ def getGame(self, game_type): """Return class managing the game type""" - #TODO: check that the game is launched, and manage errors + # TODO: check that the game is launched, and manage errors if game_type == "Tarot": return self.tarot_panel elif game_type == "RadioCol": @@ -773,17 +773,17 @@ self.host = host AbsolutePanel.__init__(self) - #menu + # menu self.menu = Menu(host) - #unibox + # unibox unibox_panel = UniBoxPanel(host) self.host.setUniBox(unibox_panel.unibox) - #status bar + # status bar status = host.status_panel - #contacts + # contacts _contacts = HorizontalPanel() _contacts.addStyleName('globalLeftArea') contacts_switch = Button(u'«', self._contactsSwitch) @@ -791,7 +791,7 @@ _contacts.add(contacts_switch) _contacts.add(self.host.contact_panel) - #tabs + # tabs self.tab_panel = base_widget.MainTabPanel(host) self.discuss_panel = base_widget.WidgetsPanel(self.host, locked=True) self.tab_panel.add(self.discuss_panel, "Discussions") diff -r 9b93a21dc5e2 -r 744426c2b699 libervia.py --- a/libervia.py Thu Sep 26 11:39:54 2013 +0200 +++ b/libervia.py Thu Sep 26 14:32:24 2013 +0200 @@ -19,7 +19,7 @@ along with this program. If not, see . """ -import pyjd # this is dummy in pyjs +import pyjd # this is dummy in pyjs from pyjamas.ui.RootPanel import RootPanel from pyjamas.ui.HTML import HTML from pyjamas.ui.KeyboardListener import KEY_ESCAPE @@ -39,12 +39,12 @@ class LiberviaJsonProxy(JSONProxy): def __init__(self, *args, **kwargs): JSONProxy.__init__(self, *args, **kwargs) - self.handler=self - self.cb={} - self.eb={} + self.handler = self + self.cb = {} + self.eb = {} def call(self, method, cb, *args): - _id = self.callMethod(method,args) + _id = self.callMethod(method, args) if cb: if isinstance(cb, tuple): if len(cb) != 2: @@ -69,7 +69,7 @@ del self.cb[request_info.id] if request_info.id in self.eb: del self.eb[request_info.id] - + def onRemoteError(self, code, errobj, request_info): """def dump(obj): print "\n\nDUMPING %s\n\n" % obj @@ -86,7 +86,7 @@ """for o in code, error, request_info: dump(o)""" else: - if isinstance(errobj['message'],dict): + if isinstance(errobj['message'], dict): print("Error %s: %s" % (errobj['message']['faultCode'], errobj['message']['faultString'])) else: print("Error: %s" % errobj['message']) @@ -94,7 +94,7 @@ class RegisterCall(LiberviaJsonProxy): def __init__(self): LiberviaJsonProxy.__init__(self, "/register_api", - ["isRegistered","isConnected","connect"]) + ["isRegistered", "isConnected", "connect"]) class BridgeCall(LiberviaJsonProxy): def __init__(self): @@ -114,12 +114,12 @@ def __init__(self, host): self.host = host - self.retry_delay = self.RETRY_BASE_DELAY + self.retry_delay = self.RETRY_BASE_DELAY LiberviaJsonProxy.__init__(self, "/json_signal_api", ["getSignals"]) def onRemoteResponse(self, response, request_info): - self.retry_delay = self.RETRY_BASE_DELAY + self.retry_delay = self.RETRY_BASE_DELAY LiberviaJsonProxy.onRemoteResponse(self, response, request_info) @@ -166,9 +166,9 @@ DOM.addEventPreview(self) self.resize() self._register = RegisterCall() - self._register.call('isRegistered',self._isRegisteredCB) + self._register.call('isRegistered', self._isRegisteredCB) self.initialised = False - self.init_cache = [] # used to cache events until initialisation is done + self.init_cache = [] # used to cache events until initialisation is done def addSelectedListener(self, callback): self._selected_listeners.add(callback) @@ -193,9 +193,9 @@ if selected: selected.removeStyleName('selected_widget') - + widgets_panel.selected = widget - + if widget: widgets_panel.selected.addStyleName('selected_widget') @@ -230,7 +230,7 @@ def avatarError(error_data): # The jid is maybe not in our roster, we ask for the VCard self.bridge.call("getCard", None, jid_str) - + if jid_str not in self.avatars_cache: self.bridge.call('getEntityData', (dataReceived, avatarError), jid_str, ['avatar']) self.avatars_cache[jid_str] = "/media/misc/empty_avatar" @@ -276,14 +276,14 @@ def _isConnectedCB(self, connected): if not connected: - self._register.call('connect',lambda x:self.logged()) + self._register.call('connect', lambda x:self.logged()) else: self.logged() def logged(self): if self._register_box: self._register_box.hide() - del self._register_box # don't work if self._register_box is None + del self._register_box # don't work if self._register_box is None #it's time to fill the page self.bridge.call('getContacts', self._getContactsCB) @@ -299,8 +299,8 @@ def _getSignalsCB(self, signal_data): self.bridge_signals.call('getSignals', self._getSignalsCB) - print('Got signal ==> name: %s, params: %s' % (signal_data[0],signal_data[1])) - name,args = signal_data + print('Got signal ==> name: %s, params: %s' % (signal_data[0], signal_data[1])) + name, args = signal_data if name == 'personalEvent': self._personalEventCb(*args) elif name == 'newMessage': @@ -361,12 +361,12 @@ if mblog.has_key('groups'): _groups = set(mblog['groups'].split() if mblog['groups'] else []) else: - _groups=None + _groups = None mblog_entry = MicroblogItem(mblog) self.mblog_cache.append((_groups, mblog_entry)) if len(self.mblog_cache) > MAX_MBLOG_CACHE: - del self.mblog_cache[0:len(self.mblog_cache-MAX_MBLOG_CACHE)] + del self.mblog_cache[0:len(self.mblog_cache - MAX_MBLOG_CACHE)] for lib_wid in self.libervia_widgets: if isinstance(lib_wid, panels.MicroblogPanel): self.FillMicroblogPanel(lib_wid) @@ -407,17 +407,17 @@ if 'groups' in data: _groups = set(data['groups'].split() if data['groups'] else []) else: - _groups=None + _groups = None mblog_entry = MicroblogItem(data) - + for lib_wid in self.libervia_widgets: if isinstance(lib_wid, panels.MicroblogPanel): - self.addBlogEntry(lib_wid, sender, _groups, mblog_entry) + self.addBlogEntry(lib_wid, sender, _groups, mblog_entry) if sender == self.whoami.bare: self.mblog_cache.append((_groups, mblog_entry)) if len(self.mblog_cache) > MAX_MBLOG_CACHE: - del self.mblog_cache[0:len(self.mblog_cache-MAX_MBLOG_CACHE)] + del self.mblog_cache[0:len(self.mblog_cache - MAX_MBLOG_CACHE)] def addBlogEntry(self, mblog_panel, sender, _groups, mblog_entry): """Check if an entry can go in MicroblogPanel and add to it @@ -435,7 +435,7 @@ """ #XXX: only our own entries are cached for cache_entry in self.mblog_cache: - _groups, mblog_entry = cache_entry + _groups, mblog_entry = cache_entry self.addBlogEntry(mblog_panel, self.whoami.bare, *cache_entry) def getEntityMBlog(self, entity): @@ -458,7 +458,7 @@ #The message has not been showed, we must indicate it other = _to if _from.bare == self.whoami.bare else _from self.contact_panel.setContactMessageWaiting(other.bare, True) - + def _presenceUpdateCb(self, entity, show, priority, statuses): _entity = JID(entity) #XXX: QnD way to get our status @@ -483,34 +483,34 @@ def _roomUserJoinedCb(self, room_jid_s, user_nick, user_data): for lib_wid in self.libervia_widgets: - if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: + if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: lib_wid.userJoined(user_nick, user_data) def _roomUserLeftCb(self, room_jid_s, user_nick, user_data): for lib_wid in self.libervia_widgets: - if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: + if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: lib_wid.userLeft(user_nick, user_data) - + def _tarotGameStartedCb(self, room_jid_s, referee, players): print ("Tarot Game Started \o/") for lib_wid in self.libervia_widgets: - if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: + if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: lib_wid.startGame("Tarot", referee, players) def _tarotGameGenericCb(self, event_name, room_jid_s, args): for lib_wid in self.libervia_widgets: - if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: - getattr(lib_wid.getGame("Tarot"), event_name)(*args) + if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: + getattr(lib_wid.getGame("Tarot"), event_name)(*args) def _radioColStartedCb(self, room_jid_s, referee): for lib_wid in self.libervia_widgets: - if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: + if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: lib_wid.startGame("RadioCol", referee) def _radioColGenericCb(self, event_name, room_jid_s, args): for lib_wid in self.libervia_widgets: - if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: - getattr(lib_wid.getGame("RadioCol"), event_name)(*args) + if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: + getattr(lib_wid.getGame("RadioCol"), event_name)(*args) def _getPresenceStatusCb(self, presence_data): @@ -540,12 +540,12 @@ #The user want to subscribe to our presence _dialog = None msg = HTML('The contact %s want to add you in his/her contact list, do you accept ?' % html_sanitize(entity)) - + def ok_cb(ignore): self.bridge.call('subscription', None, "subscribed", entity, '', _dialog.getSelectedGroups()) def cancel_cb(ignore): self.bridge.call('subscription', None, "unsubscribed", entity, '', '') - + _dialog = dialog.GroupSelector([msg], self.contact_panel.getGroups(), [], ok_cb, cancel_cb) _dialog.setHTML('Add contact request') _dialog.show()