Skip to main content

Darkdetect-angr

This package allows to detect if the user is using Dark Mode on:

The main application of this package is to detect the Dark mode from your GUI Python application (Tkinter/wx/pyqt/qt for python (pyside)/...) and apply the needed adjustments to your interface. Darkdetect is particularly useful if your GUI library does not provide a public API for this detection (I am looking at you, Qt). In addition, this package does not depend on other modules or packages that are not already included in standard Python distributions.

Install

The preferred channel is PyPI:

pip install darkdetect_angr

Alternatively, you are free to vendor directly a copy of Darkdetect in your app. Further information on vendoring can be found here.

macOS Listener Support

To enable the macOS listener, additional components are required, these can be installed via:

pip install darkdetect[macos-listener]

Usage

import darkdetect

>>> darkdetect.theme()
'Dark'

>>> darkdetect.isDark()
True

>>> darkdetect.isLight()
False

It's that easy.

Listener

darkdetect_angr exposes a listener API which is far more efficient than busy waiting on theme() changes. This API is exposed primarily via a Listener class. Detailed API documentation can be found here. For a quick overview: the darkdetect.Listener class exposes the following methods / members:

  1. .__init__(callback: Optional[Callable[[str], None]]): The constructor simply sets .callback to the given callback argument
  2. .callback: Optional[Callable[[str], None]]: The settable callback function that the listener uses; it will be passed "Dark" or "Light" when the theme is changed.
  3. .listen(): This starts listening for theme changes, it will invoke self.callback(theme_name) when a change is detected.
  4. .stop(timeout: Optional[int]) -> bool: This function attempts to stop the listener, waiting at most timeout seconds (None means infinite), returning True on success, False on timeout. Regardless of the result, after .stop returns, theme changes will no longer trigger callback, though running callbacks will not be interrupted. .stop may safely be re-invoked any number of times, but must succeed at before re-calling .listen().
Wrapper Function

The simplest method of using this API is the darkdetect.listener function, which takes a callback function as an argument. This function is a small wrapper around Listener(callback).listen(). In this mode, the listener cannot be stopped; forceful stops may not clean up resources (such as subprocesses if applicable).

Examples

Below are 2 examples of basic usage; additional examples can be found here.

A simple listener:
import threading
import darkdetect

listener = darkdetect.Listener(print)
t = threading.Thread(target=listener.listen, daemon=True)
# OR: t = threading.Thread(target=darkdetect.listener, args=(print,), daemon=True)
t.start()
User input controlling listener
import threading
import darkdetect
import time

listener = darkdetect.Listener(print)
t = threading.Thread(target=listener.listen)
t.start()

txt = ""
while txt != "quit":
  txt = input()
  if txt == "print":
    listener.callback = print
  elif txt == "verbose":
    listener.callback = lambda x: print(f"The theme changed to {x} as {time.time()}")
listener.stop(0)

print("Waiting for running callbacks to complete and the listener to terminate")
if not listener.stop(timeout=5):
  print("Callbacks/listener are still running after 5 seconds!")

Known Issues

  1. On macOS, detection of the dark menu bar and dock option (available from macOS 10.10) is not supported.
  2. On macOS, using the listener API in a bundled app where sys.executable is not a python interpreter is not supported (though it may still work as it uses the same code path as multiprocessing).
  3. On Windows, the after Listener.stop(None) is not supported as it may not die until another theme change is detected. Future invocations of callback will not be made, but the listener itself will persist.

Notes

  • This software is licensed under the terms of the 3-clause BSD License.
  • This package can be installed on any operative system, but theme(), isDark(), and isLight() will always return None unless executed on a OS that supports Dark Mode, including older versions of macOS and Windows.
  • Details on the detection method used on macOS.
  • Details on the experimental detection method used on Linux.

Metadata

Release files for darkdetect-angr 0.9.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for darkdetect-angr 0.9.1
File Size Uploaded Provenance Actions
darkdetect_angr-0.9.1.tar.gz 12.6 kB Without provenance Details for darkdetect_angr-0.9.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for darkdetect-angr 0.9.1
File Interpreter ABI Platform Actions
darkdetect_angr-0.9.1-py3-none-any.whl Python 3 none any Details for darkdetect_angr-0.9.1-py3-none-any.whl

Total release size: 25.5 kB

Release files / darkdetect_angr-0.9.1.tar.gz

Download URL darkdetect_angr-0.9.1.tar.gz
Size 12.6 kB
Tags Source
SHA-256 checksum
How to use checksums
78a608e193b023a679a901d3f77bc018b1323addcebb30584f3777892b1fd20c
BLAKE2b-256 checksum
How to use checksums
19b6e1c27de08839daafb7719ea48edd2b264ea3ccf77f8197e9ac02cfc29646
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / darkdetect_angr-0.9.1-py3-none-any.whl

Download URL darkdetect_angr-0.9.1-py3-none-any.whl
Size 12.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eeb02537e5ecadd50788406b9d66747be15a8a5cb8418e864314291136f1b16e
BLAKE2b-256 checksum
How to use checksums
3f473d9c54c0bd36fdb3fe4d930be5ac5268518233ecb266613e204afb0c43e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Security for darkdetect-angr 0.9.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.9.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page