示例#1
0
def initialize(args=None, **kwargs):
    """
    Initialize the style system. You may use the following arguments to
    configure the style system:

    ==============  ==============  ============
    Argument        Default         Description
    ==============  ==============  ============
    style                           The name of the style to load. If this isn't specified, the set style will be loaded from the current profile.
    default_style   ``"default"``   The name of the default style, to be used if a style isn't specified here, in the profile, or in the command line.
    ==============  ==============  ============

    In addition, you can provide a list of command line arguments to have
    siding load them automatically. Example::

        siding.style.initialize(sys.argv[1:])

    The following command line arguments are supported:

    ================  ============
    Argument          Description
    ================  ============
    ``--safe-mode``   When safe mode is enabled, add-ons, including styles, won't be loaded automatically.
    ``--style``       The name of the style to load.
    ================  ============
    """

    # Get the default style and start our list.
    default_style = kwargs.get('default_style', 'default')
    styles = [default_style]

    # Add the profile's current style to the list.
    style = profile.get('siding/style/current-style')
    if style:
        styles.insert(0, style)

    # Add the passed style to the list.
    style = kwargs.get('style')
    if style:
        styles.insert(0, style)

    # Parse any options we've got.
    if args:
        if args is True:
            args = sys.argv[1:]

        parser = argparse.ArgumentParser(add_help=False)
        parser.add_argument('--safe-mode', action='store_true')
        parser.add_argument('--style')
        options = parser.parse_known_args(args)[0]

        # Store those results.
        if options.safe_mode:
            addons.safe_mode = True

        if options.style:
            # Add the CLI style to the list.
            styles.insert(0, options.style)

    # Save the current widget style.
    widget_style = QApplication.instance().style().metaObject().className()
    widget_style = STYLE_KEYS.get(widget_style)
    if widget_style:
        profile.set('siding/style/widget-style', widget_style)

    # Discover our styles.
    addons.discover('style')

    # If safe-mode is enabled, just quit now.
    if addons.safe_mode:
        log.info('Not loading a style due to safe-mode.')
        return

    # Get the style.
    for style in styles:
        try:
            activate_style(addons.get('style', style))
            break
        except (IOError, ValueError), err:
            log.error('Error loading style %r: %s' % (style, err))
        except KeyError:
            log.error('No such style: %s' % style)
示例#2
0
文件: style.py 项目: mornhuang/study
def initialize(args=None, **kwargs):
    """
    Initialize the style system. You may use the following arguments to
    configure the style system:
  
    ==============  ============  ============
    Argument        Default       Description
    ==============  ============  ============
    safe_mode       ``False``     When safe mode is enabled, styles won't be loaded automatically.
    style                         The name of the style to load. This overrides the profile value.
    default_style   ``default``   The name of the default style to use if one isn't chosen.
    ==============  ============  ============
  
    In addition, you can provide a list of command line arguments to have
    siding load them automatically. Example::
  
        siding.style.initialize(sys.argv[1:])
  
    The following command line arguments are supported:
  
    ================  ============
    Argument          Description
    ================  ============
    ``--safe-mode``   When safe mode is enabled, styles won't be loaded automatically.
    ``--style``       The name of the style to load.
    ================  ============
    """
    global safe_mode
  
    # Set the defaults now.
    safe_mode = kwargs.get('safe_mode', safe_mode)
    style = kwargs.get('style')
    default_style = kwargs.get('default_style', 'default')
  
    # We require the profile for this.
    if not profile.settings:
        raise RuntimeError("siding.style requires you to call siding.profile.initialize() first.")
  
    # Now, parse the options we've got.
    if args:
        if args is True:
            args = sys.argv[1:]
  
        parser = argparse.ArgumentParser(add_help=False)
        parser.add_argument('--safe-mode', action='store_true', default=None)
        parser.add_argument('--style')
  
        options = parser.parse_known_args(args)[0]
  
        # Store that then.
        if options.safe_mode is not None:
            safe_mode = options.safe_mode
  
        if options.style:
            style = options.style
  
    # If we don't have a style, get it from the profile or fall back to
    if not style:
        style = profile.get('siding/current-style', default_style)
  
    # Save the current widget style.
    widget_style = QApplication.instance().style().metaObject().className()
    widget_style = STYLE_KEYS.get(widget_style)
    if widget_style:
        profile.set('siding/widget-style', widget_style)
  
    # Load the style. That is, if safe mode isn't on.
    if safe_mode:
        log.info('Not loading style %r due to safe mode.' % style)
        return
  
    try:
        load(style)
    except (IOError, ValueError):
        # If we weren't using the default style, then eat the error and try
        # loading the default style.
        if style != default_style:
            try:
                load(default_style)
            except (IOError, ValueError):
                pass
示例#3
0
 def save_settings(self):
     profile.set("geometry", self.saveGeometry())
     profile.set("state", self.saveState())
示例#4
0
文件: main_window.py 项目: sl5net/a2
 def save_settings(self):
     profile.set("geometry", self.saveGeometry())
     profile.set("state", self.saveState())
示例#5
0
def initialize(args=None, **kwargs):
    """
    Initialize the style system. You may use the following arguments to
    configure the style system:
    
    ==============  ============  ============
    Argument        Default       Description
    ==============  ============  ============
    safe_mode       ``False``     When safe mode is enabled, styles won't be loaded automatically.
    style                         The name of the style to load. This overrides the profile value.
    default_style   ``default``   The name of the default style to use if one isn't chosen.
    ==============  ============  ============

    In addition, you can provide a list of command line arguments to have
    siding load them automatically. Example::

        siding.style.initialize(sys.argv[1:])

    The following command line arguments are supported:
    
    ================  ============
    Argument          Description
    ================  ============
    ``--safe-mode``   When safe mode is enabled, styles won't be loaded automatically.
    ``--style``       The name of the style to load.
    ================  ============
    """
    global safe_mode

    # Set the defaults now.
    safe_mode = kwargs.get('safe_mode', safe_mode)
    style = kwargs.get('style')
    default_style = kwargs.get('default_style', 'default')

    # We require the profile for this.
    if not profile.settings:
        raise RuntimeError(
            "siding.style requires you to call siding.profile.initialize() first."
        )

    # Now, parse the options we've got.
    if args:
        if args is True:
            args = sys.argv[1:]

        parser = argparse.ArgumentParser(add_help=False)
        parser.add_argument('--safe-mode', action='store_true', default=None)
        parser.add_argument('--style')

        options = parser.parse_known_args(args)[0]

        # Store that then.
        if options.safe_mode is not None:
            safe_mode = options.safe_mode

        if options.style:
            style = options.style

    # If we don't have a style, get it from the profile or fall back to
    if not style:
        style = profile.get('siding/current-style', default_style)

    # Save the current widget style.
    widget_style = QApplication.instance().style().metaObject().className()
    widget_style = STYLE_KEYS.get(widget_style)
    if widget_style:
        profile.set('siding/widget-style', widget_style)

    # Load the style. That is, if safe mode isn't on.
    if safe_mode:
        log.info('Not loading style %r due to safe mode.' % style)
        return

    try:
        load(style)
    except (IOError, ValueError):
        # If we weren't using the default style, then eat the error and try
        # loading the default style.
        if style != default_style:
            try:
                load(default_style)
            except (IOError, ValueError):
                pass