Utils
index
/home/david/Projects/Jokosher/trunk/Jokosher/Utils.py

#       THIS FILE IS PART OF THE JOKOSHER PROJECT AND LICENSED UNDER THE GPL. SEE
#       THE 'COPYING' FILE FOR DETAILS
#
#       Utils.py
#       
#       This module contains a bunch of useful helper methods used elsewhere in
#       the code, that are not specific to any particular class.
#
#-------------------------------------------------------------------------------

 
Modules
       
gtk
math
xml.dom.minidom

 
Functions
       
DbToFloat(f)
Converts f from the decibel scale to a float.
 
Parameters:
        f -- number in decibel format.
 
Returns:
        a float in the [0,1] range.
LoadDictionaryFromXML(parentElement)
For those times when you don't want to fill module variables with
parameters from the XML but just want to fill a dictionary instead.
 
Parameters:
        parentElement -- XML element from which the dictionary is loaded.
 
Returns:
        a dictionary with the loaded values in (type, value) format.
LoadListFromXML(parentElement)
Loads a list from an XML file.
 
Parameters:
        parentElement -- block of XML with the list nodes.
        
Returns:
        a list with the loaded values.
LoadParametersFromXML(self, parentElement)
Loads parameters from an XML and fills variables of the same name
in that module.
 
Parameters:
        parentElement -- block of XML with the parameters.
LoadVariableFromNode(node, typeAttr='type', valueAttr='value')
Loads a variable from an specific XML node.
 
Example:
        Please refer to the StoreVariableToNode example
        for the explanation of the typeAttr and valueAttr
        parameters.
 
Parameters:
        node -- node from which the variable is loaded.
        typeAttr -- string of the attribute name that the
                                variable's type will be saved under.
        valueAttr -- string of the attribute name that the
                                variable's value will be saved under.
 
Returns:
        the loaded variable.
OpenExternalURL(url, message, parent)
Opens a given url in the user's default web browser.
It'll try launchers in the following order:
        xdg-open
        gnome-open
        kfmclient exec
        exo-open
        
Parameters:
        url -- the url the user's default web browser will open.
        message -- the error message in the dialog window. the error message dialog will show if a link cannot be opened.
        parent -- parent window of the error message dialog.
StoreDictionaryToXML(doc, parent, dict, tagName=None)
Saves a dictionary of settings in an XML document.
 
Parameters:
        doc -- name of the XML document to save the settings into.
        parent -- XML parent tag to use in doc.
        dict -- dictionary to be saved in doc.
        tagName -- name used for all tag names.
        
Considerations:
        If tagName is not given, the dictionary keys will be used for the tag names.
        This means that the keys must all be strings and can't have any invalid XML
        characters in them.
        If tagName is given, it is used for all the tag names, and the key is stored
        in the keyvalue attribute and its type in the keytype attribute.
StoreListToXML(doc, parent, itemList, tagName)
Saves a list of items in an XML document.
 
Parameters:
        doc -- name of the XML document to save the items into.
        parent -- XML parent tag to use in doc.
        itemList -- list of items to be saved in doc.
        tagName -- name used for all tag names.
StoreParametersToXML(self, doc, parent, parameters)
Saves the variables indicated by the parameters in an XML document.
 
Parameters:
        doc -- name of the XML document to save the settings into.
        parent -- XML parent tag to use in doc.
        parameters -- list of variable names whose value, save in doc.
StoreVariableToNode(value, node, typeAttr='type', valueAttr='value')
Saves a variable to an specific XML node.
 
Example:
        typeAttr = "foo"
        valueAttr = "bar"
        value = "mystring"
        
        would result in the following XML code:
                <foo="str" bar="mystring" />
 
Parameters:
        value -- the value of the variable.
        node -- node to save the variable value to.
        typeAttr -- type of the variable to be saved.
        valueAttr -- value of the variable to be loaded. TODO
floatRange(start, end=None, inc=None)
A range function capable of performing float increments.
 
Parameters:
        start -- minimum value of the range list.
        end -- maximum value of the range list.
        inc -- delta between values in the range list.
 
Considerations:
        If start is the only parameter given, the range goes from [0.0, start].
 
Returns:
        A list with the range [start, end] in inc increments.