[Python-modules-commits] [python-qtawesome] 01/04: Imported Upstream version 0.3.2

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Wed Mar 23 12:18:30 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch master
in repository python-qtawesome.

commit 6cb450240d67892d1649be1e83c3e9d8747915ec
Author: Ghislain Antony Vaillant <ghisvail at gmail.com>
Date:   Wed Mar 23 11:38:28 2016 +0000

    Imported Upstream version 0.3.2
---
 RELEASE.md               |  26 ++++++----
 example.py               |  27 +++++++++--
 qtawesome/.project       |  17 -------
 qtawesome/.pydevproject  |   8 ----
 qtawesome/__init__.py    |   2 +-
 qtawesome/_version.py    |   2 +-
 qtawesome/iconic_font.py | 121 ++++++++++++++++++++++++++++++++++++-----------
 7 files changed, 135 insertions(+), 68 deletions(-)

diff --git a/RELEASE.md b/RELEASE.md
index fa749fa..a12c891 100644
--- a/RELEASE.md
+++ b/RELEASE.md
@@ -1,11 +1,19 @@
 To release a new version of qtawesome on PyPI:
 
-Update _version.py (set release version, remove 'dev')
-git add and git commit
-python setup.py sdist upload
-python setup.py bdist_wheel upload
-git tag -a vX.X.X -m 'comment'
-Update _version.py (add 'dev' and increment minor)
-git add and git commit
-git push
-git push --tags
+* Update _version.py (set release version, remove 'dev')
+
+* git add and git commit
+
+* python setup.py sdist upload
+
+* python setup.py bdist_wheel upload
+
+* git tag -a vX.X.X -m 'comment'
+
+* Update _version.py (add 'dev' and increment minor)
+
+* git add and git commit
+
+* git push
+
+* git push --tags
diff --git a/example.py b/example.py
index 2896c81..e4a58b6 100644
--- a/example.py
+++ b/example.py
@@ -1,8 +1,15 @@
+# -*- coding: utf-8 -*-
+
+# Standard library imports
 import sys
+
+# Third party imports
 from qtpy import QtCore, QtWidgets
-import qtawesome as qta
 from six import unichr
 
+# Local imports
+import qtawesome as qta
+
 
 class AwesomeExample(QtWidgets.QDialog):
 
@@ -23,6 +30,15 @@ class AwesomeExample(QtWidgets.QDialog):
                                 color_active='orange')
         music_button = QtWidgets.QPushButton(styling_icon, 'Styling')
 
+        # Toggle
+        toggle_icon = qta.icon('fa.home', selected='fa.legal',
+                               color_off='black',
+                               color_off_active='blue',
+                               color_on='orange',
+                               color_on_active='yellow')
+        toggle_button = QtWidgets.QPushButton(toggle_icon, 'Toggle')
+        toggle_button.setCheckable(True)
+
         # Render a label with this font
         label = QtWidgets.QLabel(unichr(0xf19c) + ' ' + 'Label')
         label.setFont(qta.font('fa', 16))
@@ -56,6 +72,7 @@ class AwesomeExample(QtWidgets.QDialog):
                                    options=options)
         stack_spin_button.setIcon(stack_spin_icon)
         stack_spin_button.setIconSize(QtCore.QSize(32, 32))
+
         # Stack and offset icons
         saveall = qta.icon('fa.save', 'fa.save',
                            options=[{'scale_factor': 0.8,
@@ -66,9 +83,10 @@ class AwesomeExample(QtWidgets.QDialog):
 
         # Layout
         vbox = QtWidgets.QVBoxLayout()
-        widgets = [fa_button, elusive_button, music_button, stack_button,
-                   saveall_button, spin_button, pulse_button,
+        widgets = [fa_button, elusive_button, music_button, toggle_button,
+                   stack_button, saveall_button, spin_button, pulse_button,
                    stack_spin_button, label]
+
         for w in widgets:
             vbox.addWidget(w)
 
@@ -79,10 +97,11 @@ class AwesomeExample(QtWidgets.QDialog):
 
 def main():
     app = QtWidgets.QApplication(sys.argv)
+
     # Enable High DPI display with PyQt5
     if hasattr(QtCore.Qt, 'AA_UseHighDpiPixmaps'):
         app.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps)
-    QtCore.QTimer.singleShot(5000, app.exit)
+    QtCore.QTimer.singleShot(10000, app.exit)
     _ = AwesomeExample()
     sys.exit(app.exec_())
 
diff --git a/qtawesome/.project b/qtawesome/.project
deleted file mode 100644
index ebc607d..0000000
--- a/qtawesome/.project
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
-	<name>QtAwesome</name>
-	<comment></comment>
-	<projects>
-	</projects>
-	<buildSpec>
-		<buildCommand>
-			<name>org.python.pydev.PyDevBuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-	</buildSpec>
-	<natures>
-		<nature>org.python.pydev.pythonNature</nature>
-	</natures>
-</projectDescription>
diff --git a/qtawesome/.pydevproject b/qtawesome/.pydevproject
deleted file mode 100644
index 037bd25..0000000
--- a/qtawesome/.pydevproject
+++ /dev/null
@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<?eclipse-pydev version="1.0"?><pydev_project>
-<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
-<path>/${PROJECT_DIR_NAME}</path>
-</pydev_pathproperty>
-<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
-<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
-</pydev_project>
diff --git a/qtawesome/__init__.py b/qtawesome/__init__.py
index 070fced..704254f 100644
--- a/qtawesome/__init__.py
+++ b/qtawesome/__init__.py
@@ -150,7 +150,7 @@ def load_font(prefix, ttf_filename, charmap_filename, directory=None):
         qta.load_font('spyder', 'spyder.ttf', 'spyder-charmap.json')
 
     """
-    return _instance().load_font(*args, **kwargs)
+    return _instance().load_font(prefix, ttf_filename, charmap_filename, directory)
 
 
 def charmap(prefixed_name):
diff --git a/qtawesome/_version.py b/qtawesome/_version.py
index ce79add..8b2ddd0 100644
--- a/qtawesome/_version.py
+++ b/qtawesome/_version.py
@@ -1,2 +1,2 @@
-version_info = (0, 3, 0)
+version_info = (0, 3, 2)
 __version__ = '.'.join(map(str, version_info))
diff --git a/qtawesome/iconic_font.py b/qtawesome/iconic_font.py
index b029087..2a488ed 100644
--- a/qtawesome/iconic_font.py
+++ b/qtawesome/iconic_font.py
@@ -13,12 +13,15 @@ methods returning instances of ``QIcon``.
 
 """
 
+# Standard library imports
 from __future__ import print_function
-from qtpy.QtCore import Qt, QObject, QPoint, QRect, qRound, QByteArray
-from qtpy.QtGui import (QIcon, QColor, QIconEngine, QPainter, QPixmap,
-                        QFontDatabase, QFont)
 import json
 import os
+
+# Third party imports
+from qtpy.QtCore import QObject, QPoint, QRect, qRound, Qt
+from qtpy.QtGui import (QColor, QFont, QFontDatabase, QIcon, QIconEngine,
+                        QPainter, QPixmap)
 from six import unichr
 
 
@@ -26,16 +29,24 @@ _default_options = {
     'color': QColor(50, 50, 50),
     'color_disabled': QColor(150, 150, 150),
     'opacity': 1.0,
-    'scale_factor': 1.0
+    'scale_factor': 1.0,
 }
 
 
 def set_global_defaults(**kwargs):
-    """Set global defaults for the options passed to the icon painter.
-    """
-    valid_options = ['active', 'animation', 'color', 'color_active',
-        'color_disabled', 'color_selected', 'disabled', 'offset',
-        'scale_factor', 'selected']
+    """Set global defaults for the options passed to the icon painter."""
+
+    valid_options = [
+        'active', 'selected', 'disabled', 'on', 'off',
+        'on_active', 'on_selected', 'on_disabled',
+        'off_active', 'off_selected', 'off_disabled',
+        'color', 'color_on', 'color_off',
+        'color_active', 'color_selected', 'color_disabled',
+        'color_on_selected', 'color_on_active', 'color_on_disabled',
+        'color_off_selected', 'color_off_active', 'color_off_disabled',
+        'animation', 'offset', 'scale_factor',
+        ]
+
     for kw in kwargs:
         if kw in valid_options:
             _default_options[kw] = kwargs[kw]
@@ -56,17 +67,32 @@ class CharIconPainter:
     def _paint_icon(self, iconic, painter, rect, mode, state, options):
         """Paint a single icon."""
         painter.save()
-        color, char = options['color'], options['char']
-
-        if mode == QIcon.Disabled:
-            color = options.get('color_disabled', color)
-            char = options.get('disabled', char)
-        elif mode == QIcon.Active:
-            color = options.get('color_active', color)
-            char = options.get('active', char)
-        elif mode == QIcon.Selected:
-            color = options.get('color_selected', color)
-            char = options.get('selected', char)
+        color = options['color']
+        char = options['char']
+
+        color_options = {
+            QIcon.On: {
+                QIcon.Normal: (options['color_on'], options['on']),
+                QIcon.Disabled: (options['color_on_disabled'],
+                                 options['on_disabled']),
+                QIcon.Active: (options['color_on_active'],
+                               options['on_active']),
+                QIcon.Selected: (options['color_on_selected'],
+                                 options['on_selected']) 
+            },
+
+            QIcon.Off: {
+                QIcon.Normal: (options['color_off'], options['off']),
+                QIcon.Disabled: (options['color_off_disabled'],
+                                 options['off_disabled']),
+                QIcon.Active: (options['color_off_active'],
+                               options['off_active']),
+                QIcon.Selected: (options['color_off_selected'],
+                                 options['off_selected']) 
+            }
+        }
+
+        color, char = color_options[state][mode]
 
         painter.setPen(QColor(color))
 
@@ -181,7 +207,8 @@ class IconicFont(QObject):
             print('Font is empty')
 
     def icon(self, *names, **kwargs):
-        """Return a QIcon object corresponding to the provided icon name.
+        """
+        Return a QIcon object corresponding to the provided icon name.
         """
         options_list = kwargs.pop('options', [{}] * len(names))
         general_options = kwargs
@@ -206,17 +233,55 @@ class IconicFont(QObject):
         options = dict(_default_options, **general_options)
         options.update(specific_options)
 
-        # Handle icons for states
-        icon_kw = ['disabled', 'active', 'selected', 'char']
-        names = [options.get(kw, name) for kw in icon_kw]
+        # Handle icons for modes (Active, Disabled, Selected, Normal)
+        # and states (On, Off)
+        icon_kw = ['char', 'on', 'off', 'active', 'selected', 'disabled',
+                   'on_active', 'on_selected', 'on_disabled', 'off_active',
+                   'off_selected', 'off_disabled']
+        char = options.get('char', name)
+        on = options.get('on', char)
+        off = options.get('off', char)
+        active = options.get('active', on)
+        selected = options.get('selected', active)
+        disabled = options.get('disabled', char)
+        on_active = options.get('on_active', active)
+        on_selected = options.get('on_selected', selected)
+        on_disabled = options.get('on_disabled', disabled)
+        off_active = options.get('off_active', active)
+        off_selected = options.get('off_selected', selected)
+        off_disabled = options.get('off_disabled', disabled)
+
+        icon_dict = {'char': char,
+                     'on': on,
+                     'off': off,
+                     'active': active,
+                     'selected': selected,
+                     'disabled': disabled,
+                     'on_active': on_active,
+                     'on_selected': on_selected,
+                     'on_disabled': on_disabled,
+                     'off_active': off_active,
+                     'off_selected': off_selected,
+                     'off_disabled': off_disabled,
+                     }
+        names = [icon_dict.get(kw, name) for kw in icon_kw]
         prefix, chars = self._get_prefix_chars(names)
         options.update(dict(zip(*(icon_kw, chars))))
         options.update({'prefix': prefix})
 
-        # Handle colors for states
-        color_kw = ['color_active', 'color_selected']
-        colors = [options.get(kw, options['color']) for kw in color_kw]
-        options.update(dict(zip(*(color_kw, colors))))
+        # Handle colors for modes (Active, Disabled, Selected, Normal)
+        # and states (On, Off)
+        color = options.get('color')
+        options.setdefault('color_on', color)
+        options.setdefault('color_active', options['color_on'])
+        options.setdefault('color_selected', options['color_active'])
+        options.setdefault('color_on_active', options['color_active'])
+        options.setdefault('color_on_selected', options['color_selected'])
+        options.setdefault('color_on_disabled', options['color_disabled'])
+        options.setdefault('color_off', color)
+        options.setdefault('color_off_active', options['color_active'])
+        options.setdefault('color_off_selected', options['color_selected'])
+        options.setdefault('color_off_disabled', options['color_disabled'])
 
         return options
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-qtawesome.git



More information about the Python-modules-commits mailing list