
    Dfe4                        d Z ddlZddlZddlZddlZddlZddlmZ ddlm	Z	 ddl
mZ dZ ej                  e      Zej                   j#                  ej                   j%                  ej                   j#                  e                  Zej                   j+                  ed      Zej                   j+                  edd	      Zej                   j+                  ed
      Zej                   j+                  ed      Zej                   j+                  ed      ZdZdZdZdZd
ZdZ dZ!dZ"dZ#d Z$d Z%d Z&d Z'd"dZ(d Z)d Z*d Z+d Z,d Z-d Z.d  Z/d#d!Z0y)$a  The most complete dark/light style sheet for Qt applications (Qt4, Qt5,
PySide, PySide2, PyQt4, PySide6, PyQt5, PyQt6, QtPy, PyQtGraph, Qt.Py) for
Python 2/3 and C++.

Python 2, as well as Qt4 (PyQt4 and PySide), will not be supported anymore.
They are still there as it is, but no back-compatibility, fixes, nor features
will be implemented.


Check the `documentation <https://qdarkstylesheet.readthedocs.io/en/stable>`__
to see how to set the desirable theme palette.

This module provides a function to load the stylesheets transparently
with the right resources file.

First, start importing our module

.. code-block:: python

    import qdarkstyle

Then you can get the stylesheet provided by QDarkStyle for various Qt wrappers
as shown below

.. code-block:: python

    # PySide 2
    dark_stylesheet = qdarkstyle.load_stylesheet_pyside2()
    # PyQt5
    dark_stylesheet = qdarkstyle.load_stylesheet_pyqt5()
    # PySide 6
    dark_stylesheet = qdarkstyle.load_stylesheet_pyside6()
    # PyQt6
    dark_stylesheet = qdarkstyle.load_stylesheet_pyqt6()

Alternatively, from environment variables provided by QtPy, PyQtGraph, Qt.Py

.. code-block:: python

    # QtPy
    dark_stylesheet = qdarkstyle.load_stylesheet()
    # PyQtGraph
    dark_stylesheet = qdarkstyle.load_stylesheet(qt_api=os.environ('PYQTGRAPH_QT_LIB'))
    # Qt.Py
    dark_stylesheet = qdarkstyle.load_stylesheet(qt_api=Qt.__binding__)

Finally, set your QApplication with it

.. code-block:: python

    app.setStyleSheet(dark_stylesheet)

Enjoy!

    N)DarkPalette)LightPalette)Palettez3.2.3exampledocsimages
qdarkstyleqsssvgz	main.scssz_styles.scssz_variables.scss	qss_iconsz	style.qssz	style.qrczThis function will be deprecated in v4.0.
Please, set the wanted binding by using QtPy environment variable QT_API,
then use load_stylesheet() passing the argument qt_api='wanted_binding'.zPyQt4/PySide use will be deprecated in v4.0,
by the lack of support. We will follow the minimum requirements given by QtPy,
project since QDarkStyle is dependent on it.c                     d}t        j                         j                         dk(  rdj                  | j                        }|rt
        j                  d       |S )zh
    Apply OS-only specific stylesheet patches.

    Returns:
        str: stylesheet string (css).
     darwinz
        QDockWidget::title
        {{
            background-color: {color};
            text-align: center;
            height: 12px;
        }}
        QTabBar::close-button {{
            padding: 2px;
        }}
        )colorzFound OS patches to be applied.)platformsystemlowerformatCOLOR_BACKGROUND_4_loggerinfo)paletteos_fixs     5/usr/lib/python3/dist-packages/qdarkstyle/__init__.py_apply_os_patchesr   g   sV     F H,
 F33F4 	 67M    c                  8    d} | rt         j                  d       | S )z}
    Apply binding-only specific stylesheet patches for the same OS.

    Returns:
        str: stylesheet string (css).
    r   z$Found binding patches to be applied.)r   r   )binding_fixs    r   _apply_binding_patchesr      s     K;<r   c                     d}| j                  d      \  }}}t        |      t        |      t        |      }}}|dk(  r|dk\  rd}|rt        j                  d       |S )z
    Apply version-only specific stylesheet patches for the same binding.

    Args:
        qt_version (str): Qt string version.

    Returns:
        str: stylesheet string (css).
    r   .      zP
        QMenu::item {
            padding: 4px 24px 4px 6px;
        }
        z$Found version patches to be applied.)splitintr   r   )
qt_versionversion_fixmajorminorpatchs        r   _apply_version_patchesr+      se     K$**3/E5%e*c%j#e*%5Ezerk ;<r   c                 6   |j                   } ||      }| j                         }t        j                  d       |rI|j	                         }|j                  |j                  |j                  |       |j                  |       yt        j                  d       y)z
    Apply application-level fixes on the QPalette.

    The import names args must be passed here because the import is done
    inside the load_stylesheet() function, as QtPy is only imported in
    that moment for setting reasons.
    z(Found application patches to be applied.zNo QCoreApplication instance found. Application patches not applied. You have to call load_stylesheet function after instantiation of QApplication to take effect. N)
COLOR_ACCENT_3instancer   r   r   setColorNormalLink
setPalettewarning)QCoreApplicationQPaletteQColorr   r   qcolorappapp_palettes           r   _apply_application_patchesr:      s|     ""EE]F 
#
#
%CLL;<
kkmX__hmmVD{# I 	Jr   c                    | r| t         j                  d<   ddlm}m}m} ddlm}m} ddl	m
} |ddlm} t        }nX|j                  dk(  rddlm} t        }n<|j                  dk(  rdd	lm}	 t"        }n t%        d
       t'        j(                  d       t         j*                  j-                  t.              }
t         j*                  j1                  |
|j                        }dt         j*                  j1                  ||j                  t2        z         z   }t4        j7                  d|         ||      }|j9                         rV|j;                  |j<                  |j>                  z          ||      }|jA                         }t4        jC                  d       nd}tE        djG                  |            t4        j7                  d       |tI        |      z  }|tK               z  }|tM        |      z  }tO        ||||       |S )a  
    Load the stylesheet based on QtPy abstraction layer environment variable.

    If the argument is not passed, it uses the current QT_API environment
    variable to make the imports of Qt bindings. If passed, it sets this
    variable and then makes the imports.

    Args:
        qt_api (str): qt binding name to set QT_API environment variable.
                      Default is ''. Possible values are pyside, pyside2
                      pyqt4, pyqt5. Not case sensitive.
        palette (Palette): Palette class that inherits from Palette.

    Note:
        - Note that the variable QT_API is read when first imported. So,
          pay attention to the import order.
        - If you are using another abstraction layer, i.e PyQtGraph to do
          imports on Qt things you must set both to use the same Qt
          binding (PyQt, PySide).
        - OS, binding and binding version number, and application-specific
          patches are applied in this order.

    Returns:
        str: stylesheet string (css).
    QT_APIr   )r4   QFileQTextStream)r6   r5   )
QT_VERSION)darkstyle_rcdarklight)lightstyle_rcz'Not recognized ID for palette! Exiting!   :zReading QSS file in: zQSS file successfully loaded.r   z*Unable to find QSS file '{}' in resources.z#Checking patches for being applied.)(osenvironqtpy.QtCorer4   r=   r>   
qtpy.QtGuir6   r5   qtpyr?   qdarkstyle.darkr@   r   IDqdarkstyle.lightrC   r   printsysexitpathbasenamePACKAGE_PATHjoinQSS_FILE_SUFFIXr   debugexistsopenReadOnlyTextreadAllr   FileNotFoundErrorr   r   r   r+   r:   )qt_apir   r4   r=   r>   r6   r5   r?   r@   rC   package_dirpalette_dirqss_rc_pathqss_filetext_stream
stylesheets                   r   _load_stylesheetrd      s   6 %

8 A@+ 0	v	0	w	278 ''""<0K'',,{GJJ7K['**2NOOKMM)+78 [!Hennuzz12!(+ ((*
45
 !006{0CE 	E MM78 #G,,J (**J (44J /67Kr   c                     d}d}	 | d   }|j                  dd      }|r| st        |       dkD  st        |      dkD  rt        d      |s| st	        d      }|S d	|v st        |t              rm|j                  d	|      }|rt	        d
|      }|s*t	        d	|      }nt	        d|      }|st	        d|      }t        j                  t        t               |S d|v st        |t              r!|j                  d|      }t	        ||      }|S d|v st        |t              r |j                  d|      }t	        |      }|S t        d      # t         $ r Y Pw xY w)a  
    Load the stylesheet. Takes care of importing the rc module.

    Args:
        pyside (bool): True to load the PySide (or PySide2) rc file,
                       False to load the PyQt4 (or PyQt5) rc file.
                       Default is False.
        or

        qt_api (str): Qt binding name to set QT_API environment variable.
                      Default is '', i.e PyQt5 the default QtPy binding.
                      Possible values are pyside, pyside2 pyqt4, pyqt5.
                      Not case sensitive.

        or

        palette (Palette): Class (not instance) that inherits from Palette.

    Raises:
        TypeError: If arguments do not match: type, keyword name nor quantity.

    Returns:
        str: the stylesheet string.
    r   Nr   r      zload_stylesheet() takes zero, one or two arguments: (new) string type qt_api='pyqt5' or (old) boolean type pyside='False' or (new) palette type palette=Palette.pyqt5r]   pysidepyside2)r]   r   pyqt4r]   )r   zload_stylesheet() takes only zero, one or two arguments: (new) string type qt_api='pyqt5' or (new) palette type palette=Palette or (old) boolean type pyside='False'.)
IndexErrorgetlen	TypeErrorrd   
isinstanceboolwarningswarnDEPRECATION_MSGDeprecationWarningstr
issubclassr   )argskwargsrc   argr   ri   r]   palette_args           r   load_stylesheetr|   &  s   4 J
C1g jjD)G 	4CIMS[1_ > ? 	? $%W5
H C 
V	z#t4Hc*)GLJ-XwO
 *'JJ-WgN
 	o'9:& ! 
V	z#s3Hc*%VWE
  
f	
3 8jjC0%k:
   = > 	>_  s   E 	EEc                      t        d      S )zp
    Load the stylesheet for use in a PySide application.

    Returns:
        str: the stylesheet string.
    ri   rh   rd    r   r   load_stylesheet_pysider   |  s     8,,r   c                      t        d      S )zq
    Load the stylesheet for use in a PySide2 application.

    Returns:
        str: the stylesheet string.
    rj   rh   r~   r   r   r   load_stylesheet_pyside2r          9--r   c                      t        d      S )zq
    Load the stylesheet for use in a PySide6 application.

    Returns:
        str: the stylesheet string.
    pyside6rh   r~   r   r   r   load_stylesheet_pyside6r     r   r   c                      t        d      S )zo
    Load the stylesheet for use in a PyQt4 application.

    Returns:
        str: the stylesheet string.
    rk   rh   r~   r   r   r   load_stylesheet_pyqtr          7++r   c                      t        d      S )zo
    Load the stylesheet for use in a PyQt5 application.

    Returns:
        str: the stylesheet string.
    rg   rh   r~   r   r   r   load_stylesheet_pyqt5r     r   r   c                      t        d      S )zo
    Load the stylesheet for use in a PyQt6 application.

    Returns:
        str: the stylesheet string.
    pyqt6rh   r~   r   r   r   load_stylesheet_pyqt6r     r   r   c                     t        j                  t        t               | r,t	        t
        j                  j                  dd            }|S t	               }|S )a"  
    Load the stylesheet from QT_API (or PYQTGRAPH_QT_LIB) environment variable.

    Args:
        is_pyqtgraph (bool): True if it is to be set using PYQTGRAPH_QT_LIB.

    Raises:
        KeyError: if PYQTGRAPH_QT_LIB does not exist.

    Returns:
        str: the stylesheet string.
    PYQTGRAPH_QT_LIBNrh   )rr   rs   rt   ru   rd   rF   rG   rm   )is_pyqtgraphrc   s     r    load_stylesheet_from_environmentr     sI     MM/#56%RZZ^^<NPT-UV
  &'
r   )r   N)F)1__doc__loggingrF   r   rO   rr   qdarkstyle.dark.paletter   qdarkstyle.light.paletter   qdarkstyle.paletter   __version__	getLogger__name__r   rQ   dirnameabspath__file__	REPO_PATHrT   EXAMPLE_PATHIMAGES_PATHrS   QSS_PATHSVG_PATHMAIN_SCSS_FILESTYLES_SCSS_FILEVARIABLES_SCSS_FILERESOURCE_PREFIXSTYLE_PREFIXrU   QRC_FILE_SUFFIXrt   DEPRECATION_MSG_UNSUPPORTEDr   r   r+   r:   rd   r|   r   r   r   r   r   r   r   r   r   r   <module>r      sQ  6r  	  
  0 1 &
'

H
% GGOOBGGOOBGGOOH,EFG	ww||Iy1ggll9fh7ww||I|477<<e,77<<e, ! '  L0 
<:J8VrSl-..,,,r   