PyQt color selector, notifications when in copy mode
parent
c4f0271e61
commit
e9a3fd7333
|
@ -1,14 +1,11 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Copyright (C) Daniel Napora 2021 <napcok@gmail.com>
|
# Copyright (C) Daniel Napora 2021 <napcok@gmail.com>
|
||||||
# Dependencies: jgmenu, xdotool, colorpicker, xdg-utils, xclip
|
# Dependencies: jgmenu, xdotool, colorpicker, xdg-utils, xclip
|
||||||
# TODO Built-in palettes read-only pre-generated like HTML colors amd not copied to ~/.../palettes
|
|
||||||
# DONE self made palettes in ~/.../palettes
|
|
||||||
# TODO notifications when copying to clipboard (imagick needed to create icon)
|
|
||||||
# TODO check for other color-tools like gpick,gcolor2 and add launchers to menu
|
# TODO check for other color-tools like gpick,gcolor2 and add launchers to menu
|
||||||
# TODO export to .gpl (GIMP,Inkscape)
|
# TODO export to .gpl (GIMP,Inkscape)
|
||||||
# DONE quicly remove colors from picked (with sed)
|
|
||||||
|
|
||||||
|
|
||||||
|
VERSION="0.1.7"
|
||||||
|
TEMP_DIR=/tmp/colormenu
|
||||||
ME=${0##*/}
|
ME=${0##*/}
|
||||||
|
|
||||||
CNF_DIR="$HOME/.config/mbxcolors"
|
CNF_DIR="$HOME/.config/mbxcolors"
|
||||||
|
@ -64,6 +61,7 @@ pickcolor() {
|
||||||
scale=${xcolor_scale:-8}
|
scale=${xcolor_scale:-8}
|
||||||
command="xcolor --preview-size ${size} --scale ${scale}"
|
command="xcolor --preview-size ${size} --scale ${scale}"
|
||||||
color="$(${command})"
|
color="$(${command})"
|
||||||
|
if [ -n "${color}" ]; then
|
||||||
echo "$color " > "$RECENT".tmp
|
echo "$color " > "$RECENT".tmp
|
||||||
# add on top deduplicate
|
# add on top deduplicate
|
||||||
awk '!x[$0]++' "$RECENT" >> "$RECENT".tmp
|
awk '!x[$0]++' "$RECENT" >> "$RECENT".tmp
|
||||||
|
@ -71,6 +69,39 @@ pickcolor() {
|
||||||
[ -n "$1" ] && file="$1"
|
[ -n "$1" ] && file="$1"
|
||||||
echo "$color " >> "$file"
|
echo "$color " >> "$file"
|
||||||
setvar expose=picked
|
setvar expose=picked
|
||||||
|
fi
|
||||||
|
$ME
|
||||||
|
}
|
||||||
|
pycolor() {
|
||||||
|
read -r -d '' script <<-"----EOF"
|
||||||
|
import sys
|
||||||
|
from PyQt5.QtWidgets import QApplication, QMainWindow, QColorDialog
|
||||||
|
|
||||||
|
class App(QMainWindow):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
color = QColorDialog.getColor()
|
||||||
|
if color.isValid():
|
||||||
|
print(color.name())
|
||||||
|
self.deleteLater()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
win = App()
|
||||||
|
----EOF
|
||||||
|
python -c "$script"
|
||||||
|
}
|
||||||
|
addcolor() {
|
||||||
|
color=$(pycolor)
|
||||||
|
if [ -n "${color}" ]; then
|
||||||
|
echo "$color " > "$RECENT".tmp
|
||||||
|
# add on top deduplicate
|
||||||
|
awk '!x[$0]++' "$RECENT" >> "$RECENT".tmp
|
||||||
|
awk '!x[$0]++' "$RECENT".tmp > "$RECENT"
|
||||||
|
[ -n "$1" ] && file="$1"
|
||||||
|
echo "$color " >> "$file"
|
||||||
|
setvar expose=picked
|
||||||
|
fi
|
||||||
$ME
|
$ME
|
||||||
}
|
}
|
||||||
getcolorcode() {
|
getcolorcode() {
|
||||||
|
@ -84,8 +115,12 @@ getcolorcode() {
|
||||||
case "$format" in
|
case "$format" in
|
||||||
rgb) clr=$(hex2rgb $1);echo $clr | tr -d "\n" | xclip -sel c;;
|
rgb) clr=$(hex2rgb $1);echo $clr | tr -d "\n" | xclip -sel c;;
|
||||||
rgba) clr=$(hex2rgba $1);echo $clr | tr -d "\n" | xclip -sel c;;
|
rgba) clr=$(hex2rgba $1);echo $clr | tr -d "\n" | xclip -sel c;;
|
||||||
*) echo "$1" | tr -d "\n" | xclip -sel c;;
|
*) clr="$1";echo "$1" | tr -d "\n" | xclip -sel c;;
|
||||||
esac
|
esac
|
||||||
|
mkdir -p $TEMP_DIR
|
||||||
|
FNAME="$TEMP_DIR/$clr.png"
|
||||||
|
convert -size 100x100 xc:"$1" "$FNAME"
|
||||||
|
notify-send ColorMenu "$clr" --icon="$FNAME" --expire-time=10000
|
||||||
fi
|
fi
|
||||||
echo "$1" > "$USED".tmp
|
echo "$1" > "$USED".tmp
|
||||||
# add on top and deduplicate
|
# add on top and deduplicate
|
||||||
|
@ -275,6 +310,7 @@ trap "rm -f ${CONFIG_FILE} ${MENU_ITEMS}" EXIT
|
||||||
out+=("^sep(mbxcolors <sup><span font_weight='light'> [$action $format]</span></sup>)")
|
out+=("^sep(mbxcolors <sup><span font_weight='light'> [$action $format]</span></sup>)")
|
||||||
#out+=("^sep(<span bgcolor='#800000'> </span><span fgcolor='#800000' bgcolor='#FABD2F'> mbx </span><span fgcolor='#FABD2F' bgcolor='#800000'> colors </span><span bgcolor='#FABD2F'> </span> <sup><span font_weight='light'>[$action $format]</span></sup>)")
|
#out+=("^sep(<span bgcolor='#800000'> </span><span fgcolor='#800000' bgcolor='#FABD2F'> mbx </span><span fgcolor='#FABD2F' bgcolor='#800000'> colors </span><span bgcolor='#FABD2F'> </span> <sup><span font_weight='light'>[$action $format]</span></sup>)")
|
||||||
out+=("<b>Pick</b> color from screen...,$ME pickcolor")
|
out+=("<b>Pick</b> color from screen...,$ME pickcolor")
|
||||||
|
out+=("<b>Add</b> color...,$ME addcolor")
|
||||||
# exposed thing
|
# exposed thing
|
||||||
case "$expose" in
|
case "$expose" in
|
||||||
used)
|
used)
|
||||||
|
@ -430,7 +466,8 @@ fi
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-h|--help|help) usage;;
|
-h|--help|help) usage;;
|
||||||
-a|--pickcolor|pickcolor) pickcolor "$2";;
|
--pickcolor|pickcolor) pickcolor "$2";;
|
||||||
|
--addcolor|addcolor) addcolor "$2" ;;
|
||||||
-g|--getcolorcode|getcolorcode) getcolorcode "$2" "$3";;
|
-g|--getcolorcode|getcolorcode) getcolorcode "$2" "$3";;
|
||||||
-p|preferences) preferences;;
|
-p|preferences) preferences;;
|
||||||
-s|setvar) setvar "$2";;
|
-s|setvar) setvar "$2";;
|
||||||
|
|
Loading…
Reference in New Issue