-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Gonçalo Negrier Duarte <[email protected]>
- Loading branch information
1 parent
af2bc92
commit 3d583e0
Showing
5 changed files
with
262 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
%global srcname darkdetect | ||
%global libname %{srcname} | ||
%global pkgname %{srcname} | ||
|
||
Summary: Detect OS Dark Mode from Python | ||
Name: python-%{pkgname} | ||
Version: 0.8.0 | ||
Release: 1 | ||
Source0: https://github.com/albertosottile/darkdetect/archive/refs/tags/v%{version}.tar.gz | ||
Source1: https://raw.githubusercontent.com/johnfanv2/LenovoLegionLinux/main/deploy/build_packages/setup.cfg | ||
Source2: https://raw.githubusercontent.com/johnfanv2/LenovoLegionLinux/main/deploy/build_packages/setup.py | ||
License: Custom | ||
Group: Development/Libraries | ||
BuildArch: noarch | ||
BuildRequires: python3-devel | ||
BuildRequires: python3-setuptools | ||
BuildRequires: python3-wheel | ||
BuildRequires: python3-pip | ||
Vendor: Alberto Sottile <[email protected]> | ||
Packager: Gonçalo Negrier Duarte <[email protected]> | ||
Url: https://github.com/albertosottile/darkdetect | ||
|
||
%description | ||
# Darkdetect (UNOFFICIAL RPM) | ||
|
||
This package allows to detect if the user is using Dark Mode on: | ||
|
||
- [macOS 10.14+](https://support.apple.com/en-us/HT208976) | ||
- [Windows 10 1607+](https://blogs.windows.com/windowsexperience/2016/08/08/windows-10-tip-personalize-your-pc-by-enabling-the-dark-theme/) | ||
- Linux with [a dark GTK theme](https://www.gnome-look.org/browse/cat/135/ord/rating/?tag=dark). | ||
|
||
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. | ||
|
||
|
||
## Usage | ||
|
||
``` | ||
import darkdetect | ||
|
||
>>> darkdetect.theme() | ||
'Dark' | ||
|
||
>>> darkdetect.isDark() | ||
True | ||
|
||
>>> darkdetect.isLight() | ||
False | ||
``` | ||
It's that easy. | ||
|
||
You can create a dark mode switch listener daemon thread with `darkdetect.listener` and pass a callback function. The function will be called with string "Dark" or "Light" when the OS switches the dark mode setting. | ||
|
||
``` python | ||
import threading | ||
import darkdetect | ||
|
||
# def listener(callback: typing.Callable[[str], None]) -> None: ... | ||
|
||
t = threading.Thread(target=darkdetect.listener, args=(print,)) | ||
t.daemon = True | ||
t.start() | ||
``` | ||
|
||
## Install | ||
|
||
The preferred channel is PyPI: | ||
``` | ||
pip install darkdetect | ||
``` | ||
|
||
Alternatively, you are free to vendor directly a copy of Darkdetect in your app. Further information on vendoring can be found [here](https://medium.com/underdog-io-engineering/vendoring-python-dependencies-with-pip-b9eb6078b9c0). | ||
|
||
## Optional Installs | ||
|
||
To enable the macOS listener, additional components are required, these can be installed via: | ||
```bash | ||
pip install darkdetect[macos-listener] | ||
``` | ||
|
||
## Notes | ||
|
||
- This software is licensed under the terms of the 3-clause BSD License. | ||
- This package can be installed on any operative system, but it will always return `None` unless executed on a OS that supports Dark Mode, including older versions of macOS and Windows. | ||
- On macOS, detection of the dark menu bar and dock option (available from macOS 10.10) is not supported. | ||
- [Details](https://stackoverflow.com/questions/25207077/how-to-detect-if-os-x-is-in-dark-mode) on the detection method used on macOS. | ||
- [Details](https://askubuntu.com/questions/1261366/detecting-dark-mode#comment2132694_1261366) on the experimental detection method used on Linux. | ||
|
||
|
||
%prep | ||
%autosetup -p1 -n %{pkgname}-%{version} | ||
cp %{SOURCE1} %{SOURCE2} . | ||
sed -i "s/version = _VERSION/version = %{version}/g" setup.cfg | ||
|
||
%build | ||
%pyproject_wheel | ||
|
||
%install | ||
%pyproject_install | ||
%pyproject_save_files darkdetect | ||
|
||
%files -n python-%{pkgname} | ||
%doc README.md | ||
%license LICENSE | ||
%{python3_sitelib}/%{libname}/ | ||
%{python3_sitelib}/%{libname}-%{version}.dist-info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# norootforbuild | ||
%define srcname LenovoLegionLinux | ||
%global dkms_name %{srcname} | ||
|
||
Name: dkms-%{srcname} | ||
License: GPL-2.0 | ||
Group: System/Kernel | ||
Summary: LenovoLegionLinux Kernel Module Package | ||
Version: 0.0.16 | ||
Release: 0 | ||
Source0: https://github.com/johnfanv2/LenovoLegionLinux/archive/refs/tags/v%{version}.tar.gz | ||
|
||
Requires: dkms | ||
|
||
%description | ||
Driver for controlling Lenovo Legion laptops including fan control and power mode. | ||
|
||
%prep | ||
%autosetup -p1 -n %{srcname}-%{version} | ||
|
||
%install | ||
mkdir -p %{buildroot}%{_usrsrc}/%{dkms_name}-%{version}/ | ||
cp -fr kernel_module/* %{buildroot}%{_usrsrc}/%{dkms_name}-%{version}/ | ||
|
||
%post | ||
dkms add -m %{dkms_name} -v %{version} -q || : | ||
# Rebuild and make available for the currently running kernel: | ||
dkms build -m %{dkms_name} -v %{version} -q || : | ||
dkms install -m %{dkms_name} -v %{version} -q --force || : | ||
|
||
%preun | ||
# Remove all versions from DKMS registry: | ||
dkms remove -m %{dkms_name} -v %{version} -q --all || : | ||
|
||
%files | ||
%license LICENSE | ||
%doc README.md | ||
%{_usrsrc}/%{dkms_name}-%{version} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
%define srcname LenovoLegionLinux | ||
%global libname legion_linux | ||
|
||
Summary: Control Lenovo Legion laptop | ||
Name: python-%{srcname} | ||
Version: 0.0.16 | ||
Release: 0 | ||
Source0: https://github.com/johnfanv2/LenovoLegionLinux/archive/refs/tags/v%{version}.tar.gz | ||
License: GPL-2.0 | ||
Group: Development/Libraries | ||
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot | ||
Prefix: %{_prefix} | ||
BuildArch: noarch | ||
BuildRequires: python3-devel | ||
BuildRequires: python3-setuptools | ||
BuildRequires: python3-wheel | ||
BuildRequires: python3-pip | ||
BuildRequires: make | ||
BuildRequires: clang | ||
BuildRequires: gcc | ||
BuildRequires: inih-cpp | ||
BuildRequires: systemd-rpm-macros | ||
Vendor: johnfan <[email protected]> | ||
Packager: Gonçalo Negrier Duarte <[email protected]> | ||
Url: https://github.com/johnfanv2/LenovoLegionLinux | ||
|
||
Requires: PyQt6 | ||
Requires: python-yaml | ||
Requires: python-argcomplete | ||
Requires: python-darkdetect | ||
Requires: acpid | ||
|
||
%description | ||
See documenation of LenovoLegionLinux | ||
|
||
%prep | ||
%autosetup -p1 -n %{srcname}-%{version} | ||
cd python/legion_linux | ||
sed -i "s/version = _VERSION/version = %{version}/g" setup.cfg | ||
|
||
%build | ||
cd python/legion_linux | ||
%pyproject_wheel | ||
cd legion_linux/extra/service/legiond | ||
make | ||
|
||
%install | ||
%pyproject_install | ||
%pyproject_save_files legion_linux | ||
|
||
install -D -m 0644 %{_builddir}/%{srcname}-%{version}-prerelease/python/legion_linux/legion_linux/extra/service/legiond.service %{_unitdir}/legiond.service | ||
install -D -m 0644 %{_builddir}/%{srcname}-%{version}-prerelease/python/legion_linux/legion_linux/extra/service/legiond-onresume.service %{_unitdir}/legiond-onresume.service | ||
install -D -m 0644 %{_builddir}/%{srcname}-%{version}-prerelease/python/legion_linux/legion_linux/extra/service/legiond.service %{_unitdir}/legiond-cpuset.service | ||
install -D -m 0644 %{_builddir}/%{srcname}-%{version}-prerelease/python/legion_linux/legion_linux/extra/service/legiond.service %{_unitdir}/legiond-cpuset.timer | ||
install -D -m 0755 %{_builddir}/%{srcname}-%{version}-prerelease/python/legion_linux/legion_linux/extra/service/legiond/legiond-ctl %{_bindir}/legiond-ctl | ||
install -D -m 0755 %{_builddir}/%{srcname}-%{version}-prerelease/python/legion_linux/legion_linux/extra/service/legiond/legiond %{_bindir}/legiond | ||
install -D -m 0644 %{_builddir}/%{srcname}-%{version}-prerelease/python/legion_linux/legion_linux/extra/acpi/events/legion-ppd /etc/acpi/events/legion-ppd | ||
install -D -m 0644 %{_builddir}/%{srcname}-%{version}-prerelease/python/legion_linux/legion_linux/extra/acpi/events/legion-ac /etc/acpi/events/legion_ac | ||
%files -n python-%{srcname} | ||
%doc README.md | ||
%license LICENSE | ||
%{python3_sitelib}/%{libname} | ||
%{python3_sitelib}/%{libname}-%{version}.dist-info | ||
%{_bindir}/fancurve-set | ||
%{_bindir}/legion_cli | ||
%{_bindir}/legion_gui | ||
%{_datadir}/applications/legion_gui.desktop | ||
%{_datadir}/applications/legion_gui_user.desktop | ||
%{_datadir}/legion_linux/.env | ||
%{_datadir}/legion_linux/balanced-ac.yaml | ||
%{_datadir}/legion_linux/balanced-battery.yaml | ||
%{_datadir}/legion_linux/balanced-performance-ac.yaml | ||
%{_datadir}/legion_linux/balanced-performance-battery.yaml | ||
%{_datadir}/legion_linux/performance-ac.yaml | ||
%{_datadir}/legion_linux/performance-battery.yaml | ||
%{_datadir}/legion_linux/quiet-ac.yaml | ||
%{_datadir}/legion_linux/quiet-battery.yaml | ||
%{_datadir}/pixmaps/legion_logo.png | ||
%{_datadir}/pixmaps/legion_logo_dark.png | ||
%{_datadir}/pixmaps/legion_logo_light.png | ||
%{_datadir}/polkit-1/actions/legion_cli.policy | ||
%{_datadir}/polkit-1/actions/legion_gui.policy | ||
|
||
%post | ||
echo "Frist install?! Pls copy /usr/share/legion_linux folder to /etc/legion_linux.\n" | ||
echo "Command: sudo cp /usr/share/legion_linux /etc/legion_linux" | ||
|
||
%preun | ||
echo "After uninstall you can remover /etc/legion_linux to get rid of the configuration file!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[metadata] | ||
name = darkdetect | ||
version = _VERSION | ||
author = albertosottile | ||
author_email = [email protected] | ||
description = Detect OS Dark Mode from Python | ||
long_description = file: README.md | ||
long_description_content_type = text/markdown | ||
license = Custom License | ||
license_files = LICENSE | ||
url = https://github.com/albertosottile/darkdetect | ||
project_urls = | ||
Bug Tracker = https://github.com/albertosottile/darkdetect/issues | ||
repository = https://github.com/albertosottile/darkdetect | ||
classifiers = | ||
Programming Language :: Python :: 3 | ||
|
||
[options] | ||
python_requires = >=3.6 | ||
packages = find: | ||
|
||
[options.packages.find] | ||
exclude = | ||
tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env python | ||
|
||
import setuptools | ||
|
||
if __name__ == "__main__": | ||
setuptools.setup() |