Commit 0879f6b7 authored by Damien Naudet's avatar Damien Naudet

Added icons management. Actualy a copy from silx.

parent 81aac45b
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2016 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/
"""Set of icons for buttons.
Use :func:`getQIcon` to create Qt QIcon from the name identifying an icon.
"""
__authors__ = ["T. Vincent"]
__license__ = "MIT"
__date__ = "15/09/2016"
import logging
import weakref
from silx.gui import qt
from ..resources import resource_filename
_logger = logging.getLogger(__name__)
"""Module logger"""
_cached_icons = weakref.WeakValueDictionary()
"""Cache loaded icons in a weak structure"""
_supported_formats = None
"""Order of file format extension to check"""
_process_working = None
"""Cache an AnimatedIcon for working process"""
def getQIcon(name):
"""Create a QIcon from its name.
:param str name: Name of the icon, in one of the defined icons
in this module.
:return: Corresponding QIcon
:raises: ValueError when name is not known
"""
if name not in _cached_icons:
qfile = getQFile(name)
icon = qt.QIcon(qfile.fileName())
_cached_icons[name] = icon
else:
icon = _cached_icons[name]
return icon
def getQPixmap(name):
"""Create a QPixmap from its name.
:param str name: Name of the icon, in one of the defined icons
in this module.
:return: Corresponding QPixmap
:raises: ValueError when name is not known
"""
qfile = getQFile(name)
return qt.QPixmap(qfile.fileName())
def getQFile(name):
"""Create a QFile from an icon name. Filename is found
according to supported Qt formats.
:param str name: Name of the icon, in one of the defined icons
in this module.
:return: Corresponding QFile
:rtype: qt.QFile
:raises: ValueError when name is not known
"""
global _supported_formats
if _supported_formats is None:
_supported_formats = []
supported_formats = qt.supportedImageFormats()
order = ["mng", "gif", "svg", "png", "jpg"]
for format_ in order:
if format_ in supported_formats:
_supported_formats.append(format_)
if len(_supported_formats) == 0:
_logger.error("No format supported for icons")
else:
_logger.debug("Format %s supported", ", ".join(_supported_formats))
for format_ in _supported_formats:
format_ = str(format_)
filename = resource_filename('gui/icons/%s.%s' % (name, format_))
qfile = qt.QFile(filename)
if qfile.exists():
return qfile
raise ValueError('Not an icon name: %s' % name)
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2016 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/
"""Access project's data and documentation files.
All access to data and documentation files MUST be made through the functions
of this modules to ensure access accross different distribution schemes:
- Installing from source or from wheel
- Installing package as a zip (through the use of pkg_resources)
- Linux packaging willing to install data files (and doc files) in
alternative folders. In this case, this file must be patched.
- Frozen fat binary application using xsocs (forzen with cx_Freeze or py2app).
This needs special care for the resource files in the setup:
- With cx_Freeze, add xsocs/resources to include_files:
.. code-block:: python
import xsocs.resources
xsocs_include_files = (os.path.dirname(xsocs.resources.__file__),
os.path.join('xsocs', 'resources'))
setup(...
options={'build_exe': {'include_files': [xsocs_include_files]}}
)
- With py2app, add xsocs in the packages list of the py2app options:
.. code-block:: python
setup(...
options={'py2app': {'packages': ['xsocs']}}
)
"""
__authors__ = ["V.A. Sole", "Thomas Vincent", "D. Naudet"]
__license__ = "MIT"
__date__ = "24/10/2016"
import os
import sys
# pkg_resources is useful when this package is stored in a zip
# When pkg_resources is not available, the resources dir defaults to the
# directory containing this module.
try:
import pkg_resources
except ImportError:
pkg_resources = None
# For packaging purpose, patch this variable to use an alternative directory
# E.g., replace with _RESOURCES_DIR = '/usr/share/xsocs/data'
_RESOURCES_DIR = None
# For packaging purpose, patch this variable to use an alternative directory
# E.g., replace with _RESOURCES_DIR = '/usr/share/xsocs/doc'
# Not in use, uncomment when functionnality is needed
# _RESOURCES_DOC_DIR = None
# cx_Freeze forzen support
# See http://cx-freeze.readthedocs.io/en/latest/faq.html#using-data-files
if getattr(sys, 'frozen', False):
# Running in a frozen application:
# We expect resources to be located either in a xsocs/resources/ dir
# relative to the executable or within this package.
_dir = os.path.join(os.path.dirname(sys.executable), 'xsocs', 'resources')
if os.path.isdir(_dir):
_RESOURCES_DIR = _dir
def resource_filename(resource):
"""Return filename corresponding to resource.
resource can be the name of either a file or a directory.
The existence of the resource is not checked.
:param str resource: Resource path relative to resource directory
using '/' path separator.
:return: Absolute resource path in the file system
"""
# Not in use, uncomment when functionnality is needed
# If _RESOURCES_DOC_DIR is set, use it to get resources in doc/ subflodler
# from an alternative directory.
# if _RESOURCES_DOC_DIR is not None and (resource is 'doc' or
# resource.startswith('doc/')):
# # Remove doc folder from resource relative path
# return os.path.join(_RESOURCES_DOC_DIR, *resource.split('/')[1:])
if _RESOURCES_DIR is not None: # if set, use this directory
return os.path.join(_RESOURCES_DIR, *resource.split('/'))
elif pkg_resources is None: # Fallback if pkg_resources is not available
return os.path.join(os.path.abspath(os.path.dirname(__file__)),
*resource.split('/'))
else: # Preferred way to get resources as it supports zipfile package
return pkg_resources.resource_filename(__name__, resource)
This source diff could not be displayed because it is too large. You can view the blob instead.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="64px"
height="64px"
id="svg2998"
version="1.1"
inkscape:version="0.48.5 r10040"
sodipodi:docname="spec.svg">
<defs
id="defs3000" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="5.5"
inkscape:cx="18.610523"
inkscape:cy="32"
inkscape:current-layer="layer1"
showgrid="true"
inkscape:document-units="px"
inkscape:grid-bbox="true"
inkscape:window-width="971"
inkscape:window-height="1024"
inkscape:window-x="923"
inkscape:window-y="74"
inkscape:window-maximized="0" />
<metadata
id="metadata3003">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="layer1"
inkscape:label="Layer 1"
inkscape:groupmode="layer">
<text
xml:space="preserve"
style="font-size:35.54850388px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"
x="-35.960915"
y="56.297951"
id="text3059"
sodipodi:linespacing="125%"
transform="matrix(0.70622747,-0.70798719,0.70622747,0.70798719,0,0)"><tspan
sodipodi:role="line"
id="tspan3061"
x="-35.960915"
y="56.297951"
style="font-style:normal;font-variant:normal;font-weight:500;font-stretch:normal;font-family:Inconsolata;-inkscape-font-specification:Inconsolata Medium">SPEC</tspan></text>
</g>
</svg>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="50"
height="400"
id="svg2"
version="1.1"
inkscape:version="0.48.5 r10040"
sodipodi:docname="xsocs.svg"
inkscape:export-filename="/users/naudet/workspace/dau/id01/devs/kmap/kmap/resources/gui/icons/xsocs.png"
inkscape:export-xdpi="90"
inkscape:export-ydpi="90">
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="1.4"
inkscape:cx="314.45552"
inkscape:cy="267.91873"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="1920"
inkscape:window-height="1110"
inkscape:window-x="0"
inkscape:window-y="27"
inkscape:window-maximized="1" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-652.3622)">
<text
xml:space="preserve"
style="font-size:41.56947327px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"
x="-268.19458"
y="267.89536"
id="text2985"
sodipodi:linespacing="125%"
transform="matrix(0.23262859,-2.1166954,0.27723596,1.7761184,0,0)"><tspan
sodipodi:role="line"
id="tspan2987"
x="-268.19458"
y="267.89536">X-SOCS</tspan></text>
<flowRoot
xml:space="preserve"
id="flowRoot2989"
style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"><flowRegion
id="flowRegion2991"><rect
id="rect2993"
width="222.85715"
height="94.285713"
x="225.71428"
y="463.79074" /></flowRegion><flowPara
id="flowPara2995" /></flowRoot> <flowRoot
xml:space="preserve"
id="flowRoot2997"
style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"><flowRegion
id="flowRegion2999"><rect
id="rect3001"
width="102.85714"
height="80"
x="348.57144"
y="463.79074" /></flowRegion><flowPara
id="flowPara3003" /></flowRoot> </g>
</svg>
......@@ -36,6 +36,7 @@ def configuration(parent_package='', top_path=None):
config.add_subpackage('gui')
config.add_subpackage('io')
config.add_subpackage('process')
config.add_subpackage('resources')
config.add_subpackage('test')
config.add_subpackage('util')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment