Exemplo n.º 1
0
def initialize(log_level=None,
               log_format=None,
               stream=None,
               file_name=None,
               file_size=None,
               file_number=None):
    """Initializes logging. Configures the Root logger with the given
    log_level. If file_name is given, a rotating log file handler is added.
    Otherwise, adds a default output stream handler with the given
    log_format."""

    global __logging_initialized

    if __logging_initialized:
        return

    root = logging.getLogger()
    if log_level is None:
        log_level = config.LOG_LEVEL
    if log_format is None:
        log_format = config.LOG_FORMAT
    if file_name is None:
        file_name = config.LOG_FILE_NAME
    if file_size is None:
        file_size = config.LOG_FILE_SIZE
    if file_number is None:
        file_number = config.LOG_FILE_NUMBER
    if stream is None:
        stream = config.LOG_STREAM

    for handler in set(root.handlers):
        root.removeHandler(handler)

    __set_log_file(file_name, file_size, file_number, log_format)

    __set_log_stream(stream, log_format)

    if isString(log_level):
        log_level = log_level.upper()
        if hasattr(logging, log_level):
            log_level = getattr(logging, log_level)

    if log_level is not None:
        try:
            root.setLevel(log_level)
        except:
            warnings.warn('Invalid log level specified in ' \
                          'qarbon.util.initLogging')

    __logging_initialized = True
Exemplo n.º 2
0
def getIcon(icon):
    """Returns a QIcon for the given icon.

    Example::

        from qarbon.external.qt import QtGui
        from qarbon.qt.qui.application import Application
        from qarbon.qt.gui.icon import getIcon

        app = Application()

        # == getThemeIcon("folder-open")
        icon = getIcon("folder-open")

        # == getQarbonIcon(":/controls/collapse.png")
        icon = getIcon(":/controls/collapse.png")

        # == Qt.QIcon("MyResource:/bla.png")
        icon = getIcon("MyResource:/bla.png")

        # == getStandardIcon(QtGui.QStyle.SP_MessageBoxWarning)
        icon = getIcon(QtGui.QStyle.SP_MessageBoxWarning)

        button = QtGui.QPushButton(icon, "Something")
        button.show()
        app.exec_()

    :param icon: icon name or ID
    :type icon: str or int
    :return: the QIcon corresponding to the given icon. If the icon
             doesn't exist it returns a Null icon
    :rtype: QtGui.QIcon
    """
    if icon is None:
        return QtGui.QIcon()
    elif isinstance(icon, QtGui.QIcon):
        return QtGui.QIcon(icon)
    elif isString(icon):
        if icon.startswith(":"):
            return getQarbonIcon(icon)
        elif ":" in icon:
            return QtGui.QIcon(icon)
        # TODO: distinguish between theme icon and absolute path icon
        # "folder-open" and "c:\logo.png" or "/tmp/logo.png"
        else:
            return getThemeIcon(icon)
    else:
        return getStandardIcon(icon)
Exemplo n.º 3
0
def getIcon(icon):
    """Returns a QIcon for the given icon.

    Example::

        from qarbon.external.qt import QtGui
        from qarbon.qt.qui.application import Application
        from qarbon.qt.gui.icon import getIcon

        app = Application()

        # == getThemeIcon("folder-open")
        icon = getIcon("folder-open")

        # == getQarbonIcon(":/controls/collapse.png")
        icon = getIcon(":/controls/collapse.png")

        # == Qt.QIcon("MyResource:/bla.png")
        icon = getIcon("MyResource:/bla.png")

        # == getStandardIcon(QtGui.QStyle.SP_MessageBoxWarning)
        icon = getIcon(QtGui.QStyle.SP_MessageBoxWarning)

        button = QtGui.QPushButton(icon, "Something")
        button.show()
        app.exec_()

    :param icon: icon name or ID
    :type icon: str or int
    :return: the QIcon corresponding to the given icon. If the icon
             doesn't exist it returns a Null icon
    :rtype: QtGui.QIcon
    """
    if icon is None:
        return QtGui.QIcon()
    elif isinstance(icon, QtGui.QIcon):
        return QtGui.QIcon(icon)
    elif isString(icon):
        if icon.startswith(":"):
            return getQarbonIcon(icon)
        elif ":" in icon:
            return QtGui.QIcon(icon)
        # TODO: distinguish between theme icon and absolute path icon
        # "folder-open" and "c:\logo.png" or "/tmp/logo.png"
        else:
            return getThemeIcon(icon)
    else:
        return getStandardIcon(icon)
Exemplo n.º 4
0
def initialize(log_level=None, log_format=None, stream=None,
               file_name=None, file_size=None, file_number=None):
    """Initializes logging. Configures the Root logger with the given
    log_level. If file_name is given, a rotating log file handler is added.
    Otherwise, adds a default output stream handler with the given
    log_format."""

    global __logging_initialized

    if __logging_initialized:
        return

    root = logging.getLogger()
    if log_level is None:
        log_level = config.LOG_LEVEL
    if log_format is None:
        log_format = config.LOG_FORMAT
    if file_name is None:
        file_name = config.LOG_FILE_NAME
    if file_size is None:
        file_size = config.LOG_FILE_SIZE
    if file_number is None:
        file_number = config.LOG_FILE_NUMBER
    if stream is None:
        stream = config.LOG_STREAM

    for handler in set(root.handlers):
        root.removeHandler(handler)

    __set_log_file(file_name, file_size, file_number, log_format)

    __set_log_stream(stream, log_format)

    if isString(log_level):
        log_level = log_level.upper()
        if hasattr(logging, log_level):
            log_level = getattr(logging, log_level)

    if log_level is not None:
        try:
            root.setLevel(log_level)
        except:
            warnings.warn('Invalid log level specified in ' \
                          'qarbon.util.initLogging')

    __logging_initialized = True
Exemplo n.º 5
0
 def toDataType(dtype):
     """Convert from type to DataType"""
     if isString(dtype):
         dtype = dtype.lower()
     return DataType.__DTYPE_MAP[dtype]
Exemplo n.º 6
0
 def toDataType(dtype):
     """Convert from type to DataType"""
     if isString(dtype):
         dtype = dtype.lower()
     return DataType.__DTYPE_MAP[dtype]