Esempio n. 1
0
 def removeBindingForAction(self, actionName, binding):
     binding = tuple(sorted(binding))
     if actionName not in self.actionsByName:
         ERROR_MSG("Action '%s' is unknown" % (actionName,))
         return
     action = self.actionsByName[actionName]
     bindings = action.getBindings()
     if binding not in bindings:
         ERROR_MSG("Action '%s' does not have the binding %s" % (actionName, binding))
         return
     return self.actionsByName[actionName].removeBinding(binding)
Esempio n. 2
0
 def addBindingForAction(self, actionName, binding):
     binding = tuple(sorted(binding))
     if actionName not in self.actionsByName:
         ERROR_MSG("Action '%s' is unknown" % (actionName,))
         return
     action = self.actionsByName[actionName]
     bindings = action.getBindings()
     if binding in bindings:
         ERROR_MSG("Action '%s' already has the binding %s" % (actionName, binding))
         return
     return action.addBinding(binding)
 def setVisualState(self, stateName):
     state = self._visualStates.get(stateName, None)
     if state:
         state.apply(self)
     else:
         ERROR_MSG("No Visual State '%s' on %s" % (stateName, self))
     return
def setStyle(component, styleName):
    if styles.has_key(styleName):
        style = styles[styleName]
        component.font = fontAliases.get(style[0], style[0])
        component.colour = style[1]
    else:
        ERROR_MSG("No style named '%s'." % (styleName, ))
Esempio n. 5
0
 def setupToolTip(self, component, toolTipInfo):
     if not self.toolTipGUIs.has_key(toolTipInfo.templateName):
         ERROR_MSG("Setting up tool tip with missing template '%s'" %
                   (toolTipInfo.templateName, ))
         return
     else:
         if self.toolTipGUI != self.toolTipGUIs[
                 toolTipInfo.
                 templateName] and self.toolTipGUI in self.rootGUI.children:
             self.rootGUI.delChild(self.toolTipGUI)
             self.toolTipGUI = None
         if toolTipInfo.infoArea:
             infoArea = toolTipInfo.infoArea
         else:
             infoArea = (0.0, 0.0, component.width, component.height)
         self.infoAreaLeft, self.infoAreaTop = component.localToScreen(
             (infoArea[0], infoArea[1]))
         self.infoAreaRight, self.infoAreaBottom = component.localToScreen(
             (infoArea[2], infoArea[3]))
         showFunction = partial(self._showToolTip, component, toolTipInfo)
         if self.showToolTipCallback is not None:
             BigWorld.cancelCallback(self.showToolTipCallback)
             self.showToolTipCallback = None
         if toolTipInfo.delayType and toolTipInfo.delayType == ToolTip.IMMEDIATE_TOOL_TIP:
             showFunction()
             self.showToolTipCallback = None
         else:
             self.showToolTipCallback = BigWorld.callback(
                 ToolTip.DELAY_TIME, showFunction)
         return
Esempio n. 6
0
def getContents(obj, indent=''):
    """
    Get a string representing an object or the first few items in a sequence.
    """
    result = ''
    try:
        import pprint
        pp = pprint.PrettyPrinter(depth=MAX_DEPTH)
        if LIMIT_LEN:
            if len(obj) <= MAX_LEN:
                result += '%s contents: %s\n' % (indent, pp.pformat(obj))
            else:
                short = obj[:MAX_LEN]
                result += '%s partial contents (first %u): %s ...\n' % (
                    indent, MAX_LEN, pp.pformat(short))
        else:
            result += '%s contents: %s\n' % (indent, pp.pformat(obj))
    except ImportError as e:
        from bwdebug import ERROR_MSG
        ERROR_MSG('Error: could not import pprint: %s' % (e, ))
        raise
    except AttributeError:
        result += '%s str : %s\n' % (indent, pp.pformat(obj))
    except TypeError:
        result += '%s str : %s\n' % (indent, pp.pformat(obj))

    return result
def gcDump():
    try:
        import gc
    except ImportError:
        ERROR_MSG('Could not import gc module; ' + 'garbage collection support is not compiled in')
        return

    leakCount = 0
    gcDebugEnable()
    DEBUG_MSG('Forcing a garbage collection...')
    leakCount = gc.collect()
    s = 'Total garbage: %u' % (leakCount,)
    gcWriteLog(None, s, isError=leakCount > 0)
    if leakCount:
        gc_dump = gc.garbage[:]
        if len(gc_dump) > 0:
            garbage_ids = {id(x):x for x in gc_dump}
            garbage_list = []
            gc_refs, _ = get_refs(gc_dump, garbage_list, garbage_ids)
            del garbage_list[:]
            graph_info = get_graph_text_repr(gc_refs, garbage_ids, shortnames=False)
            for obj in graph_info['nodes'].values():
                gcWriteLog(None, repr(obj))

            for obj in graph_info['edges']:
                gcWriteLog(None, repr(obj))

            graph_info['nodes'].clear()
            del graph_info['edges'][:]
            garbage_ids.clear()
            del gc_refs[:]
            del gc_dump[:]
    del gc.garbage[:]
    return leakCount
Esempio n. 8
0
def gcWriteLog(file, s, isError = False):
    if isError:
        ERROR_MSG(s)
    else:
        DEBUG_MSG(s)
    if file is not None:
        file.write(s + '\n')
        file.flush()
    return
def gcIsLeakDetect():
    try:
        import gc
        if (gc.isenabled() and gc.get_debug() & gc.DEBUG_LEAK) > 0:
            return True
    except ImportError:
        ERROR_MSG('Could not import gc module; garbage collection support is not compiled in')

    return False
Esempio n. 10
0
def gcDebugEnable():
    """
    Call this function to enable garbage collection debugging. Prints a warning
    message if there is no support for garbage collection.
    """
    try:
        import gc
        gc.set_debug(GC_DEBUG_FLAGS)
    except ImportError:
        ERROR_MSG('Could not import gc module; ' + 'garbage collection support is not compiled in')
Esempio n. 11
0
    def readFromDataSection(self, dataSection):
        self.actionName = dataSection._name.asString
        for key, value in dataSection.items():
            if key == 'keys':
                keys = value.asString.split()
                keys = [ _stringToKey(key) for key in keys ]
                if 0 in keys:
                    ERROR_MSG("Action '%s' is bound to one more more invalid keys" % (self.actionName,))
                if len(keys) > 0:
                    self.bindings += (tuple(sorted(keys)),)

        self.defaultBindings = self.bindings
def getContents(obj, indent=''):
    result = ''
    try:
        import pprint
        pp = pprint.PrettyPrinter(depth=MAX_DEPTH)
        if LIMIT_LEN:
            if len(obj) <= MAX_LEN:
                result += '%s contents: %s\n' % (indent, pp.pformat(obj))
            else:
                short = obj[:MAX_LEN]
                result += '%s partial contents (first %u): %s ...\n' % (indent, MAX_LEN, pp.pformat(short))
        else:
            result += '%s contents: %s\n' % (indent, pp.pformat(obj))
    except ImportError as e:
        ERROR_MSG('Error: could not import pprint: %s' % (e,))
        raise
    except AttributeError:
        result += '%s str : %s\n' % (indent, pp.pformat(obj))
    except TypeError:
        result += '%s str : %s\n' % (indent, pp.pformat(obj))

    return result
    def onLoad(self, dataSection):
        if dataSection.has_key('visualStates'):
            visualStatesSection = dataSection._visualStates
            if visualStatesSection.has_key('external'):
                extName = visualStatesSection._external.asString
                ext = ResMgr.openSection(extName)
                if ext is not None:
                    visualStatesSection = ext
                else:
                    ERROR_MSG("Failed to open external visual state '%s'." % extName)
            self.visualStateClassName = visualStatesSection.asString
            components = self.visualStateClassName.strip('"').split('.')
            module = __import__('__main__')
            for comp in components[:-1]:
                module = getattr(module, comp)

            visualStateClass = getattr(module, components[-1])
            for stateName, stateSection in visualStatesSection.items():
                visualState = visualStateClass()
                visualState.onLoad(stateSection)
                self._visualStates[stateName] = visualState

        return
Esempio n. 14
0
def gcDump(doFullCheck=False, logName=DUMP_PATH):
    """
    Performs a garbage collect and then print a dump of what has been
    collected.
    
    doFullCheck if True, do a collect and iterate over collected garbage
    and print info.
    Otherwise, do a collect and just print the number of objects collected.
    logName the name of the file to log to.
    """
    from bwdebug import DEBUG_MSG
    from bwdebug import ERROR_MSG
    try:
        import gc
    except ImportError:
        ERROR_MSG('Could not import gc module; ' +
                  'garbage collection support is not compiled in')
        return

    createTestLeaks()
    leakCount = 0
    gcDebugEnable()
    DEBUG_MSG('Forcing a garbage collection...')
    leakCount = gc.collect()
    if doFullCheck:
        copy = gc.garbage[:]
        del gc.garbage[:]
        try:
            file = open(logName, 'w')
            s = 'Total garbage: %u' % (leakCount, )
            DEBUG_MSG(s)
            file.write(s + '\n')
            if len(copy) > 0:
                DEBUG_MSG('Writing objects in garbage to file: "%s"' %
                          (logName, ))
                file.write('Objects in garbage:\n')
            i = 0
            for g in copy:
                try:
                    s = 'Garbage item %u\n' % (i, )
                    s += getObjectData(g)
                    s += getObjectReferrers(g, [gc.garbage, copy])
                    file.write('\n' + s)
                    file.flush()
                except ReferenceError as e:
                    s = 'Error: Object referenced in garbage list no longer exists: %s' % (
                        e, )
                    file.write('\n' + s)
                    ERROR_MSG(s)

                i += 1

            file.flush()
            file.close()
        except IOError as e:
            ERROR_MSG(e)
        except:
            file.write('Error printing garbage dump, see console.\n')
            ERROR_MSG('Error printing garbage dump.')
            file.flush()
            file.close()
            raise

    else:
        del gc.garbage[:]
    return leakCount
def gcDebugEnable():
    try:
        import gc
        gc.set_debug(GC_DEBUG_FLAGS)
    except ImportError:
        ERROR_MSG('Could not import gc module; ' + 'garbage collection support is not compiled in')