File: icons.py

package info (click to toggle)
turing 0.11-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,340 kB
  • sloc: python: 106,582; xml: 101; makefile: 53; sh: 29
file content (57 lines) | stat: -rw-r--r-- 1,929 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
This module contains a wrapper api over the various icon source pyqode
could use:
    - icon from theme (linux only)
    - icon from qrc
    - icon from qtawesome

qtawesome is an optional dependency, it is disabled by default.
If your application use qtawesome, just set ``USE_QTAWESOME`` to True.
"""
from pyqode.qt import QtGui
try:
    import qtawesome as qta
except ImportError:
    qta = None

#: This flag controls qtawesome icons should be preferred to theme/qrc icons.
USE_QTAWESOME = False

#: Default options used for rendering an icon from qtawesome.
#: Options cannot be changed after the icon has been rendered so make sure
#: to setup those options at startup (i.e. before you create any icon).
QTA_OPTIONS = {
    'color': '',
    'color_disabled': ''
}


def icon(theme_name='', path='', qta_name='', qta_options=None, use_qta=None):
    """
    Creates an icon from qtawesome, from theme or from path.

    :param theme_name: icon name in the current theme (GNU/Linux only)
    :param path: path of the icon (from file system or qrc)
    :param qta_name: icon name in qtawesome
    :param qta_options: the qtawesome options to use for controlling icon
                        rendering. If None, QTA_OPTIONS are used.
    :param use_qta: True to use qtawesome, False to use icon from theme/path.
                    None to use the global setting: USE_QTAWESOME.

    :returns: QtGui.QIcon
    """
    ret_val = None
    if use_qta is None:
        use_qta = USE_QTAWESOME
    if qta_options is None:
        qta_options = QTA_OPTIONS
    if qta is not None and use_qta is True:
        ret_val = qta.icon(qta_name, **qta_options)
    else:
        if theme_name and path:
            ret_val = QtGui.QIcon.fromTheme(theme_name, QtGui.QIcon(path))
        elif theme_name:
            ret_val = QtGui.QIcon.fromTheme(theme_name)
        elif path:
            ret_val = QtGui.QIcon(path)
    return ret_val