diff browser_side/panels.py @ 210:3092f6b1710c

browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...) fix bug 15 fix bug 33
author souliane <souliane@mailoo.org>
date Fri, 06 Sep 2013 15:40:33 +0200
parents 4d7054542751
children 8bbac49765d6
line wrap: on
line diff
--- a/browser_side/panels.py	Fri Jun 28 00:06:31 2013 +0200
+++ b/browser_side/panels.py	Fri Sep 06 15:40:33 2013 +0200
@@ -48,6 +48,7 @@
 from pyjamas import Window
 from __pyjamas__ import doc
 
+
 class UniBoxPanel(SimplePanel):
     """Panel containing the UniBox"""
 
@@ -58,13 +59,14 @@
         self.unibox.setWidth('100%')
         self.add(self.unibox)
 
+
 class UniBox(TextArea, MouseHandler): #AutoCompleteTextBox):
     """This text box is used as a main typing point, for message, microblog, etc"""
 
     def __init__(self, host):
         TextArea.__init__(self)
         #AutoCompleteTextBox.__init__(self)
-        self.__size = (0,0)
+        self.__size = (0, 0)
         self._popup = None
         self._timer = Timer(notify=self._timeCb)
         self.host = host
@@ -85,7 +87,6 @@
         except KeyError:
             print "WARNING: trying to remove an unknown key"
 
-
     def showWarning(self, target_data):
         target_hook, _type, msg = target_data
         if _type == "NONE":
@@ -115,7 +116,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()
 
@@ -221,15 +222,16 @@
         #XXX: fixed directly on pyjamas, if the patch is accepted, no need to walk around this
         return AutoCompleteTextBox.complete(self)"""
 
+
 class MicroblogItem():
     #XXX: should be moved in a separated module
 
     def __init__(self, data):
         self.id = data['id']
-        self.type = data.get('type','main_item')
+        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:
@@ -244,6 +246,7 @@
             self.node = data["node"]
             self.hash = (self.service, self.node)
 
+
 class MicroblogEntry(SimplePanel, ClickHandler):
 
     def __init__(self, blog_panel, mblog_entry):
@@ -334,7 +337,7 @@
         else:
             # we only accept one group at the moment
             # FIXME: manage several groups
-            return ("GROUP", self.warning_msg_group %  self.accepted_groups[0])
+            return ("GROUP", self.warning_msg_group % self.accepted_groups[0])
 
     def onTextEntered(self, text):
         if self.selected_entry:
@@ -383,7 +386,7 @@
             mblog_item = MicroblogItem(mblog)
             self.addEntry(mblog_item)
 
-    def _chronoInsert(self, vpanel, entry, reverse = True):
+    def _chronoInsert(self, vpanel, entry, reverse=True):
         """ Insert an entry in chronological order
         @param vpanel: VerticalPanel instance
         @param entry: MicroblogEntry
@@ -395,7 +398,7 @@
 
         for child in vpanel.children:
             if not isinstance(child, MicroblogEntry):
-                idx+=1
+                idx += 1
                 continue
             if reverse:
                 if child.timestamp < entry.timestamp:
@@ -403,7 +406,7 @@
             else:
                 if child.timestamp > entry.timestamp:
                     break
-            idx+=1
+            idx += 1
 
         vpanel.insert(entry, idx)
 
@@ -455,7 +458,6 @@
             entry.addStyleName('selected_entry')
         self.selected_entry = entry
 
-
     def updateValue(self, type, jid, value):
         """Update a jid value in entries
         @param type: one of 'avatar', 'nick'
@@ -467,7 +469,7 @@
                     child.updateAvatar(value)
                 elif isinstance(child, VerticalPanel):
                     updateVPanel(child)
-        if type=='avatar':
+        if type == 'avatar':
             updateVPanel(self.vpanel)
 
     def setAcceptedGroup(self, group):
@@ -490,6 +492,7 @@
                 return True
         return False
 
+
 class StatusPanel(HTMLPanel, ClickHandler):
     def __init__(self, host, status=''):
         self.host = host
@@ -500,7 +503,7 @@
         self.addClickListener(self)
 
     def __getContent(self):
-        return "<span class='status'>%(status)s</span>" % {'status':html_sanitize(self.status)}
+        return "<span class='status'>%(status)s</span>" % {'status': html_sanitize(self.status)}
 
     def changeStatus(self, new_status):
         self.status = new_status or '&nbsp;'
@@ -510,6 +513,7 @@
         #As status is the default target of uniBar, we don't want to select anything if click on it
         self.host.setSelected(None)
 
+
 class ChatText(HTMLPanel):
 
     def __init__(self, timestamp, nick, mymess, msg):
@@ -518,13 +522,14 @@
         if mymess:
             _msg_class.append("chat_text_mymess")
         HTMLPanel.__init__(self, "<span class='chat_text_timestamp'>%(timestamp)s</span> <span class='chat_text_nick'>%(nick)s</span> <span class='%(msg_class)s'>%(msg)s</span>" %
-            {"timestamp": _date.strftime("%H:%M"),
-            "nick": "[%s]" % html_sanitize(nick),
-            "msg_class": ' '.join(_msg_class),
-            "msg": html_sanitize(msg)}
-            )
+                           {"timestamp": _date.strftime("%H:%M"),
+                            "nick": "[%s]" % html_sanitize(nick),
+                            "msg_class": ' '.join(_msg_class),
+                            "msg": html_sanitize(msg)}
+                           )
         self.setStyleName('chatText')
 
+
 class Occupant(HTML):
     """Occupant of a MUC room"""
 
@@ -535,6 +540,7 @@
     def __str__(self):
         return self.nick
 
+
 class OccupantsList(AbsolutePanel):
     """Panel user to show occupants of a room"""
 
@@ -558,6 +564,7 @@
         self.occupants_list.clear()
         AbsolutePanel.clear(self)
 
+
 class ChatPanel(base_widget.LiberviaWidget):
 
     def __init__(self, host, target, type_='one2one'):
@@ -565,9 +572,9 @@
         @param host: SatWebFrontend instance
         @param target: entity (JID) with who we have a conversation (contact's jid for one 2 one chat, or MUC room)
         @param type: one2one for simple conversation, group for MUC"""
-        base_widget.LiberviaWidget.__init__(self, host, target.bare, selectable = True)
+        base_widget.LiberviaWidget.__init__(self, host, target.bare, selectable=True)
         self.vpanel = VerticalPanel()
-        self.vpanel.setSize('100%','100%')
+        self.vpanel.setSize('100%', '100%')
         self.type = type_
         self.nick = None
         if not target:
@@ -623,7 +630,7 @@
         return ("ONE2ONE" if self.type == "one2one" else "GROUP", msg)
 
     def onTextEntered(self, text):
-        mess_type = "groupchat" if self.type=='group' else "chat"
+        mess_type = "groupchat" if self.type == 'group' else "chat"
         self.host.bridge.call('sendMessage', None, str(self.target), text, '', mess_type)
 
     def onQuit(self):
@@ -631,7 +638,6 @@
         if self.type == 'group':
             self.host.bridge.call('mucLeave', None, self.target.bare)
 
-
     def setUserNick(self, nick):
         """Set the nick of the user, usefull for e.g. change the color of the user"""
         self.nick = nick
@@ -675,27 +681,26 @@
             _wid.setStyleName('chatTextInfo')
         self.content.add(_wid)
 
-
     def printMessage(self, from_jid, msg, timestamp=None):
         """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
+        _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
         if msg.startswith('/me '):
-            self.printInfo('* %s %s' % (nick, msg[4:]),type='me')
+            self.printInfo('* %s %s' % (nick, msg[4:]), type='me')
             return
         self.content.add(ChatText(timestamp, nick, mymess, msg))
         self.content_scroll.scrollToBottom()
 
     def startGame(self, game_type, referee, players):
         """Configure the chat window to start a game"""
-        if game_type=="Tarot":
+        if game_type == "Tarot":
             if hasattr(self, "tarot_panel"):
                 return
             self.tarot_panel = CardPanel(self, referee, players, self.nick)
             self.vpanel.insert(self.tarot_panel, 0)
             self.vpanel.setCellHeight(self.tarot_panel, self.tarot_panel.getHeight())
-        elif game_type=="RadioCol":
+        elif game_type == "RadioCol":
             #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"):
@@ -707,11 +712,12 @@
     def getGame(self, game_type):
         """Return class managing the game type"""
         #TODO: check that the game is launched, and manage errors
-        if game_type=="Tarot":
+        if game_type == "Tarot":
             return self.tarot_panel
-        elif game_type=="RadioCol":
+        elif game_type == "RadioCol":
             return self.radiocol_panel
 
+
 class WebPanel(base_widget.LiberviaWidget):
     """ (mini)browser like widget """
 
@@ -722,7 +728,7 @@
         base_widget.LiberviaWidget.__init__(self, host)
         self._vpanel = VerticalPanel()
         self._vpanel.setSize('100%', '100%')
-        self._url = dialog.ExtTextBox(enter_cb = self.onUrlClick)
+        self._url = dialog.ExtTextBox(enter_cb=self.onUrlClick)
         self._url.setText(url or "")
         self._url.setWidth('100%')
         hpanel = HorizontalPanel()
@@ -743,10 +749,11 @@
     def onUrlClick(self, sender):
         self._frame.setUrl(self._url.getText())
 
+
 class MainPanel(AbsolutePanel):
 
     def __init__(self, host):
-        self.host=host
+        self.host = host
         AbsolutePanel.__init__(self)
 
         #menu
@@ -773,7 +780,7 @@
         self.tab_panel.add(self.discuss_panel, "Discussions")
         self.tab_panel.selectTab(0)
 
-        header=AbsolutePanel()
+        header = AbsolutePanel()
         header.add(menu)
         header.add(unibox_panel)
         header.add(status)
@@ -802,5 +809,4 @@
         else:
             tab_bar_h = _elts.item(0).offsetHeight
         ideal_height = Window.getClientHeight() - tab_bar_h
-        self.setHeight("%s%s" % (ideal_height, "px"));
-
+        self.setHeight("%s%s" % (ideal_height, "px"))