def testDebugMessageOff(self): """ Test use of mooseDebug function, with debugging disabled. """ message.MOOSE_DEBUG_MODE = False message.mooseDebug("You should NOT see this!") output = sys.stdout.getvalue() self.assertNotIn("You should NOT see this!", output)
def testMooseMessageDebugOff(self): """ Test that the debug flag enables debug messages. """ message.MOOSE_DEBUG_MODE = False message.mooseDebug("You should see this!", debug=True) output = sys.stdout.getvalue() self.assertIn("You should see this!", output)
def testDebugMessageOn(self): """ Test use of mooseDebug function, with debugging enabled. """ message.MOOSE_DEBUG_MODE = True message.mooseDebug("You should see this!") output = sys.stdout.getvalue() self.assertIn("You should see this!", output)
def loadWidget(widget, key, **kwargs): """ A function for loading GUI state from a storage structure created with storeWidget. Args: widget[QtWidgets.QWidget]: The widget to load settings. key(s)[int|str|tuple]: The key to extract from the cache. Kwargs: debug[bool]: When True debug messages are printed. block[bool]: When True (default) signals are blocked from the widget. """ # Handle optional inputs and convert name to QString debug = kwargs.pop('debug', message.MOOSE_DEBUG_MODE) block = kwargs.pop('block', True) # The stored state dict() of the widget state = widget.property('state') if not state: return elif (key not in state) and ('default' in state): key = 'default' elif key not in state: return if block: widget.blockSignals(True) # Debug message msg = [ 'Loading State: ' + widget.__class__.__name__ + ' ' + str(widget.objectName()) ] msg += [' key = ' + str(key)] for func in state[key]: msg += [' ' * 4 + str(func[0]) + '(' + str(func[1]) + ')'] func[0](widget, func[1]) # Print debug message message.mooseDebug('\n'.join(msg), debug=debug, color='YELLOW') if block: widget.blockSignals(False) # Call load on children for child in widget.children(): loadWidget(child, key, debug=debug, block=block)
def storeWidget(widget, key, name, **kwargs): """ A function for writing QWidget state into a list of functions to call to restore the state. Args: widget[QtWidgets.QWidget]: The widget to store settings. key(s)[int|str|tuple]: The key to extract from the cache. name[str]: The name of the cache to store widget information into. Kwargs: debug[bool]: When True debug messages are printed. """ # Handle the optional argument and key, value pairs debug = kwargs.pop('debug', message.MOOSE_DEBUG_MODE) # Loop over widget storing pairings for wtype, methods in WIDGET_SETTINGS_CACHE.iteritems(): if isinstance(widget, wtype): # Debugging information msg = [ 'Storing State: ' + widget.__class__.__name__ + ' ' + str(widget.objectName()) ] msg += [' cache = ' + str(name), ' key = ' + str(key)] # Define storage structure for storing state settings state = widget.property('state') if not state: widget.setProperty('state', dict()) # Clear current state state = widget.property('state') state[(name, key)] = [] # Loop through the values to store for s in methods: attr = getattr(widget, s[0]) state[(name, key)].append((s[1], attr())) msg += [' ' * 4 + s[1] + '(' + str(attr()) + ')'] # Print debug message message.mooseDebug('\n'.join(msg), color='GREEN', debug=debug) # Update the stored state widget.setProperty('state', state) # Call store on children for child in widget.children(): storeWidget(child, name, key, debug=debug)
def storeWidget(widget, key, name, **kwargs): """ A function for writing QWidget state into a list of functions to call to restore the state. Args: widget[QtWidgets.QWidget]: The widget to store settings. key(s)[int|str|tuple]: The key to extract from the cache. name[str]: The name of the cache to store widget information into. Kwargs: debug[bool]: When True debug messages are printed. """ # Handle the optional argument and key, value pairs debug = kwargs.pop('debug', message.MOOSE_DEBUG_MODE) # Loop over widget storing pairings for wtype, methods in WIDGET_SETTINGS_CACHE.iteritems(): if isinstance(widget, wtype): # Debugging information msg = ['Storing State: ' + widget.__class__.__name__ + ' ' + str(widget.objectName())] msg += [' cache = ' + str(name), ' key = ' + str(key)] # Define storage structure for storing state settings state = widget.property('state') if not state: widget.setProperty('state', dict()) # Clear current state state = widget.property('state') state[(name, key)] = [] # Loop through the values to store for s in methods: attr = getattr(widget, s[0]) state[(name, key)].append((s[1], attr())) msg += [' '*4 + s[1] + '(' + str(attr()) + ')'] # Print debug message message.mooseDebug('\n'.join(msg), color='GREEN', debug=debug) # Update the stored state widget.setProperty('state', state) # Call store on children for child in widget.children(): storeWidget(child, name, key, debug=debug)
def loadWidget(widget, key, **kwargs): """ A function for loading GUI state from a storage structure created with storeWidget. Args: widget[QtWidgets.QWidget]: The widget to load settings. key(s)[int|str|tuple]: The key to extract from the cache. Kwargs: debug[bool]: When True debug messages are printed. block[bool]: When True (default) signals are blocked from the widget. """ # Handle optional inputs and convert name to QString debug = kwargs.pop('debug', message.MOOSE_DEBUG_MODE) block = kwargs.pop('block', True) # The stored state dict() of the widget state = widget.property('state') if not state: return elif (key not in state) and ('default' in state): key = 'default' elif key not in state: return if block: widget.blockSignals(True) # Debug message msg = ['Loading State: ' + widget.__class__.__name__ + ' ' + str(widget.objectName())] msg += [' key = ' + str(key)] for func in state[key]: msg += [' '*4 + str(func[0]) + '(' + str(func[1]) + ')'] func[0](widget, func[1]) # Print debug message message.mooseDebug('\n'.join(msg), debug=debug, color='YELLOW') if block: widget.blockSignals(False) # Call load on children for child in widget.children(): loadWidget(child, key, debug=debug, block=block)
def loadWidget(widget, key, name, **kwargs): """ A function for loading GUI state from a storage structure created with storeWidget. Args: widget[QtWidgets.QWidget]: The widget to load settings. key(s)[int|str|tuple]: The key to extract from the cache. name[str]: The name of the cache to load widget information into. Kwargs: debug[bool]: When True debug messages are printed. """ # Handle optional inputs and convert name to QString debug = kwargs.pop('debug', message.MOOSE_DEBUG_MODE) # The stored state dict() of the widget state = widget.property('state') # If state exists and the desired name is stored in the state, then load it. if state and ((name, key) in state): # Debug message msg = [ 'Loading State: ' + widget.__class__.__name__ + ' ' + str(widget.objectName()) ] msg += [' cache = ' + str(name), ' key = ' + str(key)] for func in state[(name, key)]: msg += [' ' * 4 + str(func[0]) + '(' + str(func[1]) + ')'] getattr(widget, func[0])(func[1]) # Print debug message message.mooseDebug('\n'.join(msg), debug=debug, color='YELLOW') # Call load on children for child in widget.children(): loadWidget(child, name, key, debug=debug)
def loadWidget(widget, key, name, **kwargs): """ A function for loading GUI state from a storage structure created with storeWidget. Args: widget[QtWidgets.QWidget]: The widget to load settings. key(s)[int|str|tuple]: The key to extract from the cache. name[str]: The name of the cache to load widget information into. Kwargs: debug[bool]: When True debug messages are printed. """ # Handle optional inputs and convert name to QString debug = kwargs.pop('debug', message.MOOSE_DEBUG_MODE) # The stored state dict() of the widget state = widget.property('state') # If state exists and the desired name is stored in the state, then load it. if state and ( (name, key) in state): # Debug message msg = ['Loading State: ' + widget.__class__.__name__ + ' ' + str(widget.objectName())] msg += [' cache = ' + str(name), ' key = ' + str(key)] for func in state[(name,key)]: msg += [' '*4 + str(func[0]) + '(' + str(func[1]) + ')'] getattr(widget, func[0])(func[1]) # Print debug message message.mooseDebug('\n'.join(msg), debug=debug, color='YELLOW') # Call load on children for child in widget.children(): loadWidget(child, name, key, debug=debug)