From a4c2bf31c71ece500f9432c0a48f9ffef6d7ed26 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Wed, 8 Oct 2025 10:01:20 +0200 Subject: [PATCH] use python venv for opencv python scripts (#2143) --- .config/quickshell/ii/modules/background/Background.qml | 2 +- .config/quickshell/ii/screenshot.qml | 2 +- .config/quickshell/ii/scripts/images/find-regions-venv.sh | 6 ++++++ .config/quickshell/ii/scripts/images/find_regions.py | 2 +- .../quickshell/ii/scripts/images/least-busy-region-venv.sh | 6 ++++++ dist-arch/illogical-impulse-python/PKGBUILD | 1 - scriptdata/uv/requirements.in | 2 ++ scriptdata/uv/requirements.txt | 4 ++++ 8 files changed, 21 insertions(+), 4 deletions(-) create mode 100755 .config/quickshell/ii/scripts/images/find-regions-venv.sh create mode 100755 .config/quickshell/ii/scripts/images/least-busy-region-venv.sh diff --git a/.config/quickshell/ii/modules/background/Background.qml b/.config/quickshell/ii/modules/background/Background.qml index f354cf6b9..d7c50b74b 100644 --- a/.config/quickshell/ii/modules/background/Background.qml +++ b/.config/quickshell/ii/modules/background/Background.qml @@ -152,7 +152,7 @@ Variants { property int contentHeight: 300 property int horizontalPadding: bgRoot.movableXSpace property int verticalPadding: bgRoot.movableYSpace - command: [Quickshell.shellPath("scripts/images/least_busy_region.py"), "--screen-width", Math.round(bgRoot.screen.width / bgRoot.effectiveWallpaperScale), "--screen-height", Math.round(bgRoot.screen.height / bgRoot.effectiveWallpaperScale), "--width", contentWidth, "--height", contentHeight, "--horizontal-padding", horizontalPadding, "--vertical-padding", verticalPadding, path + command: [Quickshell.shellPath("scripts/images/least-busy-region-venv.sh"), "--screen-width", Math.round(bgRoot.screen.width / bgRoot.effectiveWallpaperScale), "--screen-height", Math.round(bgRoot.screen.height / bgRoot.effectiveWallpaperScale), "--width", contentWidth, "--height", contentHeight, "--horizontal-padding", horizontalPadding, "--vertical-padding", verticalPadding, path // "--visual-output", ,] stdout: StdioCollector { diff --git a/.config/quickshell/ii/screenshot.qml b/.config/quickshell/ii/screenshot.qml index 13e07bb5e..7f3d5d4ef 100644 --- a/.config/quickshell/ii/screenshot.qml +++ b/.config/quickshell/ii/screenshot.qml @@ -307,7 +307,7 @@ ShellRoot { Process { id: imageDetectionProcess - command: ["bash", "-c", `${Directories.scriptPath}/images/find_regions.py ` + command: ["bash", "-c", `${Directories.scriptPath}/images/find-regions-venv.sh ` + `--hyprctl ` + `--image '${StringUtils.shellSingleQuoteEscape(panelWindow.screenshotPath)}' ` + `--max-width ${Math.round(panelWindow.screen.width * root.falsePositivePreventionRatio)} ` diff --git a/.config/quickshell/ii/scripts/images/find-regions-venv.sh b/.config/quickshell/ii/scripts/images/find-regions-venv.sh new file mode 100755 index 000000000..8064256cb --- /dev/null +++ b/.config/quickshell/ii/scripts/images/find-regions-venv.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +source $(eval echo $ILLOGICAL_IMPULSE_VIRTUAL_ENV)/bin/activate +"$SCRIPT_DIR/find_regions.py" "$@" + diff --git a/.config/quickshell/ii/scripts/images/find_regions.py b/.config/quickshell/ii/scripts/images/find_regions.py index e5aa29341..fe68a4dbe 100755 --- a/.config/quickshell/ii/scripts/images/find_regions.py +++ b/.config/quickshell/ii/scripts/images/find_regions.py @@ -1,4 +1,4 @@ -#!/usr/bin/env -S\_/bin/sh\_-c\_"source\_\$(eval\_echo\_\$ILLOGICAL_IMPULSE_VIRTUAL_ENV)/bin/activate&&exec\_python\_-E\_"\$0"\_"\$@"" +#!/usr/bin/env python3 import argparse import cv2 diff --git a/.config/quickshell/ii/scripts/images/least-busy-region-venv.sh b/.config/quickshell/ii/scripts/images/least-busy-region-venv.sh new file mode 100755 index 000000000..c45e9ee04 --- /dev/null +++ b/.config/quickshell/ii/scripts/images/least-busy-region-venv.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +source $(eval echo $ILLOGICAL_IMPULSE_VIRTUAL_ENV)/bin/activate +"$SCRIPT_DIR/least_busy_region.py" "$@" + diff --git a/dist-arch/illogical-impulse-python/PKGBUILD b/dist-arch/illogical-impulse-python/PKGBUILD index d9c6caa55..fc1ac1e05 100644 --- a/dist-arch/illogical-impulse-python/PKGBUILD +++ b/dist-arch/illogical-impulse-python/PKGBUILD @@ -13,5 +13,4 @@ depends=( libportal-gtk4 gobject-introspection sassc - python-opencv ) diff --git a/scriptdata/uv/requirements.in b/scriptdata/uv/requirements.in index 333230580..277a461cb 100644 --- a/scriptdata/uv/requirements.in +++ b/scriptdata/uv/requirements.in @@ -14,3 +14,5 @@ loguru pycairo pygobject tqdm +numpy +opencv-contrib-python diff --git a/scriptdata/uv/requirements.txt b/scriptdata/uv/requirements.txt index 05f9c671a..348b39b5d 100644 --- a/scriptdata/uv/requirements.txt +++ b/scriptdata/uv/requirements.txt @@ -22,8 +22,12 @@ materialyoucolor==2.0.10 # kde-material-you-colors numpy==2.2.2 # via + # -r scriptdata/uv/requirements.in # kde-material-you-colors # material-color-utilities + # opencv-contrib-python +opencv-contrib-python==4.12.0.88 + # via -r scriptdata/uv/requirements.in packaging==24.2 # via # build