PyQt color selector, notifications when in copy mode
parent
c4f0271e61
commit
e9a3fd7333
|
@ -1,14 +1,11 @@
|
|||
#!/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
|
||||
# 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 export to .gpl (GIMP,Inkscape)
|
||||
# DONE quicly remove colors from picked (with sed)
|
||||
|
||||
|
||||
VERSION="0.1.7"
|
||||
TEMP_DIR=/tmp/colormenu
|
||||
ME=${0##*/}
|
||||
|
||||
CNF_DIR="$HOME/.config/mbxcolors"
|
||||
|
@ -64,6 +61,7 @@ pickcolor() {
|
|||
scale=${xcolor_scale:-8}
|
||||
command="xcolor --preview-size ${size} --scale ${scale}"
|
||||
color="$(${command})"
|
||||
if [ -n "${color}" ]; then
|
||||
echo "$color " > "$RECENT".tmp
|
||||
# add on top deduplicate
|
||||
awk '!x[$0]++' "$RECENT" >> "$RECENT".tmp
|
||||
|
@ -71,6 +69,39 @@ pickcolor() {
|
|||
[ -n "$1" ] && file="$1"
|
||||
echo "$color " >> "$file"
|
||||
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
|
||||
}
|
||||
getcolorcode() {
|
||||
|
@ -84,8 +115,12 @@ getcolorcode() {
|
|||
case "$format" in
|
||||
rgb) clr=$(hex2rgb $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
|
||||
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
|
||||
echo "$1" > "$USED".tmp
|
||||
# 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(<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>Add</b> color...,$ME addcolor")
|
||||
# exposed thing
|
||||
case "$expose" in
|
||||
used)
|
||||
|
@ -430,7 +466,8 @@ fi
|
|||
|
||||
case "$1" in
|
||||
-h|--help|help) usage;;
|
||||
-a|--pickcolor|pickcolor) pickcolor "$2";;
|
||||
--pickcolor|pickcolor) pickcolor "$2";;
|
||||
--addcolor|addcolor) addcolor "$2" ;;
|
||||
-g|--getcolorcode|getcolorcode) getcolorcode "$2" "$3";;
|
||||
-p|preferences) preferences;;
|
||||
-s|setvar) setvar "$2";;
|
||||
|
|
Loading…
Reference in New Issue