コード例 #1
0
    def apply(self):
        """ Apply this style to the application. """
        log.info('Applying style: %s' % self.name)

        app = QApplication.instance()

        if self.data.get('aero'):
            self._enable_aero()
        else:
            self._disable_aero()

        # The Widget Style
        ui = self.data.get('ui', profile.get('siding/widget-style'))
        app.setStyle(ui)

        # Now, load the application QSS.
        qss = self.load_qss('application.qss')
        app.setStyleSheet(qss)

        # Restyle every styled widget.
        for ref in _managed_widgets.keys():
            self.style_widget(None, ref)

        # Set this as the current style.
        if not self.active:
            loaded_styles[None] = self
コード例 #2
0
ファイル: style.py プロジェクト: apt-shansen/siding
def _apply_style():
    """ Apply the current style to the application. """
    # Rebind for easier use and log.
    style = _current_style
    log.info('Applying style %r.' % style.data['name'])

    # Get the app.
    app = QApplication.instance()
    if not app:
        raise RuntimeError("You can't apply a style without a QApplication.")

    # Enable or disable Aero.
    if _aeroglass:
        if style.aero:
            _aeroglass.enable()
        else:
            _aeroglass.disable()

    # Set the widget style.
    app.setStyle(style.ui if style.ui else profile.get('siding/widget-style'))

    # Load the main stylesheet.
    app.setStyleSheet(load_qss('application.qss'))

    # Restyle every styled widget.
    for ref in _managed_widgets.keys():
        _style_widget(ref)
コード例 #3
0
ファイル: style.py プロジェクト: mornhuang/study
   def apply(self):
       """ Apply this style to the application. """
       log.info('Applying style: %s' % self.name)
 
       app = QApplication.instance()
 
       if self.data.get('aero'):
           self._enable_aero()
       else:
           self._disable_aero()
 
       # The Widget Style
       ui = self.data.get('ui', profile.get('siding/widget-style'))
       app.setStyle(ui)
 
       # Now, load the application QSS.
       qss = self.load_qss('application.qss')
       app.setStyleSheet(qss)
 
       # Restyle every styled widget.
       for ref in _managed_widgets.keys():
           self.style_widget(None, ref)
 
       # Set this as the current style.
       if not self.active:
           loaded_styles[None] = self
コード例 #4
0
ファイル: base.py プロジェクト: sl5net/a2
 def is_blacklisted(self):
     """ Whether or not the add-on is blacklisted. """
     return bool(profile.get('siding/addons/blacklist/%s/%s' %
                             (self._type_name, self.name)))
コード例 #5
0
ファイル: style.py プロジェクト: apt-shansen/siding
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)
コード例 #6
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
コード例 #7
0
ファイル: plugins.py プロジェクト: gitter-badger/a2
def isblacklisted(name):
    """ Return True if the given name is blacklisted, otherwise False. """
    return bool(profile.get('siding/plugins/blacklist/%s' % name))
コード例 #8
0
ファイル: main_window.py プロジェクト: sl5net/a2
 def init_settings(self):
     self.restoreGeometry(profile.get("geometry"))
     self.restoreState(profile.get("state"))
コード例 #9
0
ファイル: main_window.py プロジェクト: apt-shansen/siding
 def init_settings(self):
     self.restoreGeometry(profile.get("geometry"))
     self.restoreState(profile.get("state"))
コード例 #10
0
ファイル: plugins.py プロジェクト: sl5net/a2
def isblacklisted(name):
    """ Return True if the given name is blacklisted, otherwise False. """
    return bool(profile.get('siding/plugins/blacklist/%s' % name))
コード例 #11
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