comparison browser_side/panels.py @ 439:d52f529a6d42

browser side: use of new log system (first draft): - configuration is hardcoded in libervia.py, it will change in the (hopefuly) near future - log level is DEBUG for the moment, will be changed to INFO when configuration will not be hardcoded anymore - the basic log backend is used, in the future, a console.debug/info/etc should be used instead. A log widget which HTML colors is also an option
author Goffi <goffi@goffi.org>
date Thu, 08 May 2014 17:21:34 +0200
parents bbdbee25123a
children 17259c2ff96f
comparison
equal deleted inserted replaced
438:582c435dab6b 439:d52f529a6d42
16 16
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 import pyjd # this is dummy in pyjs 20 import pyjd # this is dummy in pyjs
21 from sat.core.log import getLogger
22 log = getLogger(__name__)
21 from pyjamas.ui.SimplePanel import SimplePanel 23 from pyjamas.ui.SimplePanel import SimplePanel
22 from pyjamas.ui.AbsolutePanel import AbsolutePanel 24 from pyjamas.ui.AbsolutePanel import AbsolutePanel
23 from pyjamas.ui.VerticalPanel import VerticalPanel 25 from pyjamas.ui.VerticalPanel import VerticalPanel
24 from pyjamas.ui.HorizontalPanel import HorizontalPanel 26 from pyjamas.ui.HorizontalPanel import HorizontalPanel
25 from pyjamas.ui.HTMLPanel import HTMLPanel 27 from pyjamas.ui.HTMLPanel import HTMLPanel
185 # maybe it can work on a TextBox but no TextArea. Remove addKey 187 # maybe it can work on a TextBox but no TextArea. Remove addKey
186 # and removeKey methods if they don't serve anymore. 188 # and removeKey methods if they don't serve anymore.
187 try: 189 try:
188 self.getCompletionItems().completions.remove(key) 190 self.getCompletionItems().completions.remove(key)
189 except KeyError: 191 except KeyError:
190 print "WARNING: trying to remove an unknown key" 192 log.warning("trying to remove an unknown key")
191 193
192 def _getTarget(self, txt): 194 def _getTarget(self, txt):
193 """ Say who will receive the messsage 195 """ Say who will receive the messsage
194 @return: a tuple (selected, target_type, target info) with: 196 @return: a tuple (selected, target_type, target info) with:
195 - target_hook: None if we use the selected widget, (msg, data) if we have a hook (e.g. "@@: " for a public blog), where msg is the parsed message (i.e. without the "hook key: "@@: bla" become ("bla", None)) 197 - target_hook: None if we use the selected widget, (msg, data) if we have a hook (e.g. "@@: " for a public blog), where msg is the parsed message (i.e. without the "hook key: "@@: bla" become ("bla", None))
225 else: 227 else:
226 _type = "GROUP" 228 _type = "GROUP"
227 msg = MicroblogPanel.warning_msg_group % group 229 msg = MicroblogPanel.warning_msg_group % group
228 target_hook = (txt[_end + 2:], group) 230 target_hook = (txt[_end + 2:], group)
229 else: 231 else:
230 print "ERROR: Unknown target" 232 log.error("Unknown target")
231 target_hook, _type, msg = getSelectedOrStatus() 233 target_hook, _type, msg = getSelectedOrStatus()
232 234
233 return (target_hook, _type, msg) 235 return (target_hook, _type, msg)
234 236
235 def onKeyPress(self, sender, keycode, modifiers): 237 def onKeyPress(self, sender, keycode, modifiers):
315 @msg: message to be displayed 317 @msg: message to be displayed
316 """ 318 """
317 if type_ == "NONE": 319 if type_ == "NONE":
318 return 320 return
319 if not msg: 321 if not msg:
320 print "WARNING: no msg set uniBox warning" 322 log.warning("no msg set uniBox warning")
321 return 323 return
322 if type_ == "PUBLIC": 324 if type_ == "PUBLIC":
323 style = "targetPublic" 325 style = "targetPublic"
324 elif type_ == "GROUP": 326 elif type_ == "GROUP":
325 style = "targetGroup" 327 style = "targetGroup"
326 elif type_ == "STATUS": 328 elif type_ == "STATUS":
327 style = "targetStatus" 329 style = "targetStatus"
328 elif type_ == "ONE2ONE": 330 elif type_ == "ONE2ONE":
329 style = "targetOne2One" 331 style = "targetOne2One"
330 else: 332 else:
331 print "ERROR: unknown message type" 333 log.error("unknown message type")
332 return 334 return
333 contents = HTML(msg) 335 contents = HTML(msg)
334 336
335 self._popup = dialog.PopupPanelWrapper(autoHide=False, modal=False) 337 self._popup = dialog.PopupPanelWrapper(autoHide=False, modal=False)
336 self._popup.target_data = (type_, msg) 338 self._popup.target_data = (type_, msg)
583 'service': self.comments_service, 585 'service': self.comments_service,
584 'node': self.comments_node 586 'node': self.comments_node
585 } 587 }
586 entry = self._blog_panel.addEntry(data) 588 entry = self._blog_panel.addEntry(data)
587 if entry is None: 589 if entry is None:
588 print "The entry of id %s can not be commented" % self.id 590 log.info("The entry of id %s can not be commented" % self.id)
589 return 591 return
590 entry._parent_entry = self 592 entry._parent_entry = self
591 self._current_comment = entry 593 self._current_comment = entry
592 self.edit(True, entry) 594 self.edit(True, entry)
593 self._blog_panel.setSelectedEntry(entry) 595 self._blog_panel.setSelectedEntry(entry)
731 @param comment: True if the composed message is a comment. If None, consider we are 733 @param comment: True if the composed message is a comment. If None, consider we are
732 composing from the unibox and guess the message type from self.selected_entry 734 composing from the unibox and guess the message type from self.selected_entry
733 @return: a couple (type, msg) for calling self.host.showWarning""" 735 @return: a couple (type, msg) for calling self.host.showWarning"""
734 if comment is None: # composing from the unibox 736 if comment is None: # composing from the unibox
735 if self.selected_entry and not self.selected_entry.comments: 737 if self.selected_entry and not self.selected_entry.comments:
736 print ("ERROR: an item without comment is selected") 738 log.error("an item without comment is selected")
737 return ("NONE", None) 739 return ("NONE", None)
738 comment = self.selected_entry is not None 740 comment = self.selected_entry is not None
739 if comment: 741 if comment:
740 return ("PUBLIC", "This is a <span class='warningTarget'>comment</span> and keep the initial post visibility, so it is potentialy public") 742 return ("PUBLIC", "This is a <span class='warningTarget'>comment</span> and keep the initial post visibility, so it is potentialy public")
741 elif not self._accepted_groups: 743 elif not self._accepted_groups:
771 773
772 def massiveInsert(self, mblogs): 774 def massiveInsert(self, mblogs):
773 """Insert several microblogs at once 775 """Insert several microblogs at once
774 @param mblogs: dictionary of microblogs, as the result of getMassiveLastGroupBlogs 776 @param mblogs: dictionary of microblogs, as the result of getMassiveLastGroupBlogs
775 """ 777 """
776 print "Massive insertion of %d microblogs" % len(mblogs) 778 log.debug("Massive insertion of %d microblogs" % len(mblogs))
777 for publisher in mblogs: 779 for publisher in mblogs:
778 print "adding blogs for [%s]" % publisher 780 log.debug("adding blogs for [%s]" % publisher)
779 for mblog in mblogs[publisher]: 781 for mblog in mblogs[publisher]:
780 if not "content" in mblog: 782 if not "content" in mblog:
781 print ("WARNING: No content found in microblog [%s]", mblog) 783 log.warning("No content found in microblog [%s]", mblog)
782 continue 784 continue
783 self.addEntry(mblog) 785 self.addEntry(mblog)
784 786
785 def mblogsInsert(self, mblogs): 787 def mblogsInsert(self, mblogs):
786 """ Insert several microblogs at once 788 """ Insert several microblogs at once
787 @param mblogs: list of microblogs 789 @param mblogs: list of microblogs
788 """ 790 """
789 for mblog in mblogs: 791 for mblog in mblogs:
790 if not "content" in mblog: 792 if not "content" in mblog:
791 print ("WARNING: No content found in microblog [%s]", mblog) 793 log.warning("No content found in microblog [%s]", mblog)
792 continue 794 continue
793 self.addEntry(mblog) 795 self.addEntry(mblog)
794 796
795 def _chronoInsert(self, vpanel, entry, reverse=True): 797 def _chronoInsert(self, vpanel, entry, reverse=True):
796 """ Insert an entry in chronological order 798 """ Insert an entry in chronological order
895 897
896 def setSelectedEntry(self, entry): 898 def setSelectedEntry(self, entry):
897 try: 899 try:
898 self.vpanel.getParent().ensureVisible(entry) # scroll to the clicked entry 900 self.vpanel.getParent().ensureVisible(entry) # scroll to the clicked entry
899 except AttributeError: 901 except AttributeError:
900 print "FIXME: MicroblogPanel.vpanel should be wrapped in a ScrollPanel!" 902 log.warning("FIXME: MicroblogPanel.vpanel should be wrapped in a ScrollPanel!")
901 removeStyle = lambda entry: entry.removeStyleName('selected_entry') 903 removeStyle = lambda entry: entry.removeStyleName('selected_entry')
902 if not self.host.uni_box or not entry.comments: 904 if not self.host.uni_box or not entry.comments:
903 entry.addStyleName('selected_entry') # blink the clicked entry 905 entry.addStyleName('selected_entry') # blink the clicked entry
904 clicked_entry = entry # entry may be None when the timer is done 906 clicked_entry = entry # entry may be None when the timer is done
905 Timer(500, lambda timer: removeStyle(clicked_entry)) 907 Timer(500, lambda timer: removeStyle(clicked_entry))
910 if self.selected_entry == entry: 912 if self.selected_entry == entry:
911 entry = None 913 entry = None
912 if self.selected_entry: 914 if self.selected_entry:
913 removeStyle(self.selected_entry) 915 removeStyle(self.selected_entry)
914 if entry: 916 if entry:
915 print "microblog entry selected (author=%s)" % entry.author 917 log.debug("microblog entry selected (author=%s)" % entry.author)
916 entry.addStyleName('selected_entry') 918 entry.addStyleName('selected_entry')
917 self.selected_entry = entry 919 self.selected_entry = entry
918 920
919 def updateValue(self, type_, jid, value): 921 def updateValue(self, type_, jid, value):
920 """Update a jid value in entries 922 """Update a jid value in entries
1062 self.vpanel = VerticalPanel() 1064 self.vpanel = VerticalPanel()
1063 self.vpanel.setSize('100%', '100%') 1065 self.vpanel.setSize('100%', '100%')
1064 self.type = type_ 1066 self.type = type_
1065 self.nick = None 1067 self.nick = None
1066 if not target: 1068 if not target:
1067 print "ERROR: Empty target !" 1069 log.error("Empty target !")
1068 return 1070 return
1069 self.target = target 1071 self.target = target
1070 self.__body = AbsolutePanel() 1072 self.__body = AbsolutePanel()
1071 self.__body.setStyleName('chatPanel_body') 1073 self.__body.setStyleName('chatPanel_body')
1072 chat_area = HorizontalPanel() 1074 chat_area = HorizontalPanel()
1234 if waiting or not self.nick in players: 1236 if waiting or not self.nick in players:
1235 return # waiting for player or not playing 1237 return # waiting for player or not playing
1236 attr = "%s_panel" % attr 1238 attr = "%s_panel" % attr
1237 if hasattr(self, attr): 1239 if hasattr(self, attr):
1238 return 1240 return
1239 print ("%s Game Started \o/" % game_type) 1241 log.info("%s Game Started \o/" % game_type)
1240 panel = classes[game_type](self, referee, self.nick, players, *args) 1242 panel = classes[game_type](self, referee, self.nick, players, *args)
1241 setattr(self, attr, panel) 1243 setattr(self, attr, panel)
1242 self.vpanel.insert(panel, 0) 1244 self.vpanel.insert(panel, 0)
1243 self.vpanel.setCellHeight(panel, panel.getHeight()) 1245 self.vpanel.setCellHeight(panel, panel.getHeight())
1244 1246