diff browser_side/base_widget.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 8ecc5a7062e4
children
line wrap: on
line diff
--- a/browser_side/base_widget.py	Thu May 08 17:21:30 2014 +0200
+++ b/browser_side/base_widget.py	Thu May 08 17:21:34 2014 +0200
@@ -18,6 +18,8 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import pyjd  # this is dummy in pyjs
+from sat.core.log import getLogger
+log = getLogger(__name__)
 from pyjamas.ui.SimplePanel import SimplePanel
 from pyjamas.ui.AbsolutePanel import AbsolutePanel
 from pyjamas.ui.VerticalPanel import VerticalPanel
@@ -116,15 +118,15 @@
             if item_type and item_type[-1] == '\0':  # Workaround for what looks like a pyjamas bug: the \0 should not be there, and
                 item_type = item_type[:-1]           # .strip('\0') and .replace('\0','') don't work. TODO: check this and fill a bug report
             # item_type = dt.getData("type")
-            print "message: %s" % item
-            print "type: %s" % item_type
+            log.debug("message: %s" % item)
+            log.debug("type: %s" % item_type)
         except:
-            print "no message found"
+            log.debug("no message found")
             item = '&nbsp;'
             item_type = None
         if item_type == "WIDGET":
             if not LiberviaDragWidget.current:
-                print "ERROR: No widget registered in LiberviaDragWidget !"
+                log.error("No widget registered in LiberviaDragWidget !")
                 return
             _new_panel = LiberviaDragWidget.current
             if self == _new_panel:  # We can't drop on ourself
@@ -141,13 +143,13 @@
         elif item_type in self.drop_keys:
             _new_panel = self.drop_keys[item_type](self.host, item)
         else:
-            print "WARNING: unmanaged item type"
+            log.warning("unmanaged item type")
             return
         if isinstance(self, LiberviaWidget):
             self.host.unregisterWidget(self)
             self.onQuit()
             if not isinstance(_new_panel, LiberviaWidget):
-                print ('WARNING: droping an object which is not a class of LiberviaWidget')
+                log.warning("droping an object which is not a class of LiberviaWidget")
         _flextable = self.getParent()
         _widgetspanel = _flextable.getParent().getParent()
         row_idx, cell_idx = self._getCellAndRow(_flextable, event)
@@ -229,7 +231,7 @@
         """
         Note: this method overrides pyjamas.ui.Widget.getParent
         @param class_: class of the ancestor to look for or None to return the first parent
-        @param verbose: set to True to log error messages
+        @param verbose: set to True to log error messages # FIXME: must be removed
         @return: the parent/ancestor or None if it has not been found
         """
         current = Widget.getParent(self)
@@ -238,7 +240,7 @@
         while current is not None and not isinstance(current, class_):
             current = Widget.getParent(current)
         if current is None and verbose:
-            print "Can't find parent %s for %s" % (class_, self)
+            log.debug("Can't find parent %s for %s" % (class_, self))
         return current
 
     def onClick(self, sender):
@@ -365,7 +367,7 @@
             - NONE
         """
         if not self.__selectable:
-            print "ERROR: getWarningLevel must not be called for an unselectable widget"
+            log.error("getWarningLevel must not be called for an unselectable widget")
             raise Exception
         # TODO: cleaner warning types (more general constants)
         return ("NONE", None)
@@ -486,19 +488,19 @@
 
     def changeWidget(self, row, col, wid):
         """Change the widget in the given location, add row or columns when necessary"""
-        print "changing widget:", wid.getDebugName(), row, col
+        log.debug("changing widget: %s %s %s" % (wid.getDebugName(), row, col))
         last_row = max(0, self.flextable.getRowCount() - 1)
         try:
             prev_wid = self.flextable.getWidget(row, col)
         except:
-            print "ERROR: Trying to change an unexisting widget !"
+            log.error("Trying to change an unexisting widget !")
             return
 
         cellFormatter = self.flextable.getFlexCellFormatter()
 
         if isinstance(prev_wid, BorderWidget):
             # We are on a border, we must create a row and/or columns
-            print "BORDER WIDGET"
+            log.debug("BORDER WIDGET")
             prev_wid.removeStyleName('dragover')
 
             if isinstance(prev_wid, BottomBorderWidget):
@@ -512,14 +514,14 @@
 
             elif isinstance(prev_wid, LeftBorderWidget):
                 if col != 0:
-                    print "ERROR: LeftBorderWidget must be on the first column !"
+                    log.error("LeftBorderWidget must be on the first column !")
                     return
                 self.flextable.insertCell(row, col + 1)
                 self.flextable.setWidget(row, 1, wid)
 
             elif isinstance(prev_wid, RightBorderWidget):
                 if col != self.flextable.getCellCount(row) - 1:
-                    print "ERROR: RightBorderWidget must be on the last column !"
+                    log.error("RightBorderWidget must be on the last column !")
                     return
                 self.flextable.insertCell(row, col)
                 self.flextable.setWidget(row, col, wid)
@@ -550,7 +552,7 @@
     def addWidget(self, wid):
         """Add a widget to a new cell on the next to last row"""
         last_row = max(0, self.flextable.getRowCount() - 1)
-        print "putting widget %s at %d, %d" % (wid.getDebugName(), last_row, 0)
+        log.debug("putting widget %s at %d, %d" % (wid.getDebugName(), last_row, 0))
         self.changeWidget(last_row, 0, wid)
 
     def removeWidget(self, wid):
@@ -577,7 +579,7 @@
                     current.onWidgetPanelRemove(self)
                     return
                 current = current.getParent()
-            print "Error: no MainTabPanel found !"
+            log.error("no MainTabPanel found !")
 
     def getWidgetCoords(self, wid):
         return self.flextable.getIndex(wid)
@@ -660,22 +662,22 @@
             if item_type and item_type[-1] == '\0':  # Workaround for what looks like a pyjamas bug: the \0 should not be there, and
                 item_type = item_type[:-1]           # .strip('\0') and .replace('\0','') don't work. TODO: check this and fill a bug report
             # item_type = dt.getData("type")
-            print "message: %s" % item
-            print "type: %s" % item_type
+            log.debug("message: %s" % item)
+            log.debug("type: %s" % item_type)
         except:
-            print "no message found"
+            log.debug("no message found")
             item = '&nbsp;'
             item_type = None
         if item_type == "WIDGET":
             if not LiberviaDragWidget.current:
-                print "ERROR: No widget registered in LiberviaDragWidget !"
+                log.error("No widget registered in LiberviaDragWidget !")
                 return
             _new_panel = LiberviaDragWidget.current
             _new_panel.getWidgetsPanel().removeWidget(_new_panel)
         elif item_type in DropCell.drop_keys:
             _new_panel = DropCell.drop_keys[item_type](self.tab_panel.host, item)
         else:
-            print "WARNING: unmanaged item type"
+            log.warning("unmanaged item type")
             return
 
         widgets_panel = self.tab_panel.getWidget(self._getIndex())
@@ -700,7 +702,7 @@
         tab_panel_elt = self.getElement()
         _elts = doc().getElementsByClassName('gwt-TabBar')
         if not _elts.length:
-            print ("ERROR: no TabBar found, it should exist !")
+            log.error("no TabBar found, it should exist !")
             tab_bar_h = 0
         else:
             tab_bar_h = _elts.item(0).offsetHeight