예제 #1
0
파일: style.py 프로젝트: apt-shansen/siding
def reload(style=None):
    """ Reload the active style, or the provided style. """
    if style:
        addons.get('style', style).load_information()
    elif _current_style:
        _current_style.load_information()

    # Now, to be safe, reapply the style.
    if _current_style:
        activate_style(_current_style)
예제 #2
0
    def load(self, ignore_blacklist=False):
        """ Attempt to load the plugin we represent. """
        if self.is_loaded:
            log.warning('Trying to load already loaded plugin %r.' %
                        self.data['name'])
            return

        if not ignore_blacklist and self.is_blacklisted:
            raise addons.DependencyError('Plugin %r is blacklisted.' % 
                                         self.data['name'])

        # Check our dependencies for safety.
        addons.check_dependencies(self)

        # Load our dependencies.
        for name in self.requires.iterkeys():
            if name == '__app__' or (':' in name and not
                    name.startswith('plugin:')):
                continue
            dep = addons.get('plugin', name)

            # Make sure we're needed.
            if not self.name in dep.needed_by:
                dep.needed_by.append(self.name)

            # If it's loaded, just continue.
            if dep.is_loaded:
                continue
            dep.load()

        # Okay, now load!
        self._do_load()
예제 #3
0
 def _deactivate_dependants(self):
     """ Make sure all our dependants are deactivated. """
     for name in self._info.needed_by:
         dep = addons.get('plugin', name)
         if not dep.is_active:
             continue
         dep.plugin.deactivate()
예제 #4
0
파일: qss.py 프로젝트: apt-shansen/siding
def find_url(style, url):
    if style.path.exists(url):
        return style.path.abspath(url)

    elif style.inherits:
        for parent in style.inherits:
            result = find_url(addons.get('style', parent), url)
            if result:
                return result
예제 #5
0
파일: style.py 프로젝트: apt-shansen/siding
def activate_style(style):
    """
    Activate the given style, or reapply it if it's already the active style at
    this time.
    """
    global _current_style

    if isinstance(style, basestring):
        style = addons.get('style', style)
    elif not isinstance(style, StyleInfo):
        raise TypeError("Can only activate StyleInfo instances!")

    # Check our inheritance.
    addons.check_inheritance(style)

    # Now that we have our style, activate it.
    _current_style = style
    _apply_style()

    # Now, sent out a signal.
    style_reloaded.emit()
예제 #6
0
    def _activate_dependencies(self):
        """ Make sure all our dependencies are active. """
        for name in self._info.requires.iterkeys():
            if name == '__app__' or (':' in name and not
                    name.startswith('plugin:')):
                continue
            dep = addons.get('plugin', name)

            # Make sure we're needed.
            if not self._name in dep.needed_by:
                dep.needed_by.append(self._name)

            # If it's active, just continue.
            if dep.is_active:
                continue

            # Not active? Make sure it's loaded.
            if not dep.is_loaded:
                dep.load()

            # Now activate it.
            dep.plugin.activate()
예제 #7
0
파일: qss.py 프로젝트: apt-shansen/siding
def do_import(path, style, match, _always_return=True):
    """ Parse and expand an @import statement. """
    url = match.group(1)
    if url.startswith('url('):
        if not url.endswith(')'):
            return match.group(0)
        url = url[4:-1]

    # Try parsing the URL.
    url = handle_url(path, style, url, True)
    if not url or not style.path.exists(url):
        if style.inherits:
            for parent in style.inherits:
                result = do_import(path, addons.get('style', parent),
                                   match, False)
                if isinstance(result, basestring):
                    return result
            if _always_return:
                return ''
            return

    # Alright, we've got a URL. Load it.
    return style_module.load_qss(url, style)
예제 #8
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)
예제 #9
0
파일: style.py 프로젝트: apt-shansen/siding
def icon(name, extension=None, style=None, use_inheritance=True,
         allow_theme=True, _always_return=True):
    """
    Find an icon with the given ``name`` and ``extension`` and return a
    :class:`PySide.QtGui.QIcon` for that icon.

    ================  ===========  ============
    Argument          Default      Description
    ================  ===========  ============
    name                           The name of the icon to load.
    extension                      The desired filename extension of the icon to load. If this isn't set, a list of supported formats will be used.
    style                          The style to load the icon from. If this isn't set, the current style will be assumed.
    use_inheritance   ``True``     Whether or not to search the parent style if the given style doesn't contain an icon.
    allow_theme       ``True``     Whether or not to fall back on Qt icon themes if an icon cannot be found.
    ================  ===========  ============
    """
    if style:
        if isinstance(style, basestring):
            style = addons.get('style', style)
        elif not isinstance(style, StyleInfo):
            raise TypeError("Can only activate StyleInfo instances!")
    else:
        style = _current_style

    # If we don't have a style, return a null icon now.
    if not style:
        return QIcon()

    # Right, time to find the icon.
    if isinstance(extension, (tuple, list)):
        extensions = extension
    elif extension:
        extensions = [extension]
    else:
        extensions = (str(ext) for ext in QImageReader.supportedImageFormats())

    # Iteration powers, activate!
    for ext in extensions:
        filename = '%s.%s' % (name, ext)
        icon_path = path.join('images', filename)
        if style.path.exists(icon_path):
            # We've got it, but what is it?
            if (not isinstance(style.path_source, basestring) or
                    style.path_source.startswith('py:')):
                # pkg_resource! Do things the fun and interesting way.
                with style.path.open(icon_path) as f:
                    pixmap = QPixmap()
                    pixmap.loadFromData(f.read())
                    return QIcon(pixmap)

            # Just a regular file. Open normally.
            return QIcon(style.path.abspath(icon_path))

    # Still here? We didn't find our icon then. If we're inheriting, then call
    # icon again for the style we inherit from.
    if use_inheritance and style.inherits:
        for parent in style.inherits:
            result = icon(name, extension, parent, True, False, False)
            if result:
                return result

    # For one last try, see if we can use the theme icons.
    if allow_theme and QIcon.hasThemeIcon(name):
        return QIcon.fromTheme(name)

    # We don't have an icon. Return a null QIcon.
    if _always_return:
        return QIcon()