Introduction
This script demostrate the usage of notebook dialog. Three tabs with different settings of gtk+-2.0
Details
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211 | #! /bin/sh
# -*- mode: sh -*-
#
# Author: Victor Ananjevsky <ananasik@gmail.com>, 2013
#
KEY="12345"
res1=$(mktemp --tmpdir iface1.XXXXXXXX)
res2=$(mktemp --tmpdir iface2.XXXXXXXX)
res3=$(mktemp --tmpdir iface3.XXXXXXXX)
rc_file="${XDG_CONFIG_HOME:-$HOME/.config}/gtk-2.0/gtkrc"
# parse rc file
PARSER='
BEGIN { FS="="; OFS="\n"; }
/^gtk-theme-name/ {printf "GTKTHEME=%s\n", $2}
/^gtk-key-theme-name/ {printf "KEYTHEME=%s\n", $2}
/^gtk-icon-theme-name/ {printf "ICONTHEME=%s\n", $2}
/^gtk-cursor-theme-name/ {printf "CURSORTHEME=%s\n", $2}
/^gtk-toolbar-style/ {printf "TBSTYLE=%s\n", $2}
/^gtk-toolbar-icon-size/ {printf "TBICONSIZE=%s\n", $2}
/^gtk-button-images/ {printf "BUTTONIMAGE=%s\n", ($2 == 1) ? "TRUE" : "FALSE"}
/^gtk-menu-images/ {printf "MENUIMAGE=%s\n", ($2 == 1) ? "TRUE" : "FALSE"}
/^gtk-font-name/ {printf "FONTDESCR=%s\n", $2}
/^gtk-xft-antialiasing/ {printf "ANTIALIASING=%s\n", ($2 == 1) ? "TRUE" : "FALSE"}
/^gtk-xft-hinting/ {printf "HINTING=%s\n", ($2 == 1) ? "TRUE" : "FALSE"}
/^gtk-xft-hintstyle/ {printf "HINTSTYLE=%s\n", $2}
/^gtk-xft-rgba/ {printf "RGBA=%s\n", $2}
/^gtk-color-scheme/ {printf "COLORSCHEME=%s\n", $2}
'
eval $(sed -r "s/[ \t]*=[ \t]*/=/" $rc_file | awk "$PARSER")
# create list of gtk themes
themelist=
keythemelist="Default"
for d in /usr/share/themes/*; do
theme=${d##*/}
if [[ -e $d/gtk-2.0/gtkrc ]]; then
[[ $themelist ]] && themelist="$themelist!"
[[ $theme == $GTKTHEME ]] && theme="^$theme"
themelist+="$theme"
fi
if [[ -e $d/gtk-2.0-key/gtkrc ]]; then
[[ $theme == $KEYTHEME ]] && theme="^$theme"
keythemelist+="!$theme"
fi
done
# create list of icon and cursor themes
iconthemelist="Default"
cursorthemelist="Default"
for d in /usr/share/icons/*; do
theme=${d##*/}
if [[ -e $d/index.theme ]]; then
[[ $theme == $ICONTHEME ]] && theme="^$theme"
iconthemelist+="!$theme"
fi
if [[ -d $d/cursors ]]; then
[[ $theme == $CURSORTHEME ]] && theme="^$theme"
cursorthemelist+="!$theme"
fi
done
# create toolbar styles list
tbstylelist="Icons only"!
[[ $TBSTYLE == GTK_TOOLBAR_TEXT ]] && tbstylelist+="^"
tbstylelist+="Text only"!
[[ $TBSTYLE == GTK_TOOLBAR_BOTH ]] && tbstylelist+="^"
tbstylelist+="Text below icons"!
[[ $TBSTYLE == GTK_TOOLBAR_BOTH_HORIZ ]] && tbstylelist+="^"
tbstylelist+="Text beside icons"
# create list of toolbar icons sizes
tbiconsizelist="Menu"!
[[ $TBSTYLE == GTK_ICON_SIZE_SMALL_TOOLBAR ]] && tbiconsizelist+="^"
tbiconsizelist+="Small toolbar"!
[[ $TBSTYLE == GTK_ICON_SIZE_LARGE_TOOLBAR ]] && tbiconsizelist+="^"
tbiconsizelist+="Large toolbar"!
[[ $TBSTYLE == GTK_ICON_SIZE_BUTTON ]] && tbiconsizelist+="^"
tbiconsizelist+="Buttons"!
[[ $TBSTYLE == GTK_ICON_SIZE_DND ]] && tbiconsizelist+="^"
tbiconsizelist+="DND"!
[[ $TBSTYLE == GTK_ICON_SIZE_DIALOG ]] && tbiconsizelist+="^"
tbiconsizelist+="Dialog"
# theme page
yad --plug=$KEY --tabnum=1 --form --separator='\n' --quoted-output \
--field="GTK+ theme::cb" "$themelist" \
--field="GTK+ key theme::cb" "$keythemelist" \
--field="Icons theme::cb" "$iconthemelist" \
--field="Cursor theme::cb" "$cursorthemelist" \
--field="Toolbar style::cb" "$tbstylelist" \
--field="Toolbar icon size::cb" "$tbiconsizelist" \
--field="Button images:chk" "$BUTTONIMAGE" \
--field="Menu images:chk" "$MENUIMAGE" > $res1 &
# create list of hinting styles
hintstylelist="None"!
[[ $HINTSTYLE == hintslight ]] && hintstylelist+="^"
hintstylelist+="Slight"!
[[ $HINTSTYLE == hintmedium ]] && hintstylelist+="^"
hintstylelist+="Medium"!
[[ $HINTSTYLE == hintfull ]] && hintstylelist+="^"
hintstylelist+="Full"
# create list of rgba types
rgbalist="None"!
[[ $RGBA == rgb ]] && rgbalist+="^"
rgbalist+="RGB"!
[[ $RGBA == gbr ]] && rgbalist+="^"
rgbalist+="BGR"!
[[ $RGBA == vrgb ]] && rgbalist+="^"
rgbalist+="VRGB"!
[[ $RGBA == vgbr ]] && rgbalist+="^"
rgbalist+="VBGR"
# fonts page
yad --plug=$KEY --tabnum=2 --form --separator='\n' --quoted-output \
--field="Font::fn" "$FONTDESCR" --field=":lbl" "" \
--field="Use antialiasing:chk" "$ANTIALIASING" \
--field="Use hinting:chk" "$HINTING" \
--field="Hinting style::cb" "$hintstylelist" \
--field="RGBA type::cb" "$rgbalist" > $res2 &
# parse color scheme
eval $(echo -e $COLORSCHEME | tr ';' '\n' | sed -r 's/:(.*)$/="\1"/')
# colors page
yad --plug=$KEY --tabnum=3 --form --separator='\n' --quoted-output \
--field="Foreground::clr" $fg_color \
--field="Background::clr" $bg_color \
--field="Text::clr" $text_color \
--field="Base::clr" $base_color \
--field="Selected fore::clr" $selected_fg_color \
--field="Selected back::clr" $selected_bg_color \
--field="Tooltip fore::clr" $tooltip_fg_color \
--field="Tooltip back::clr" $tooltip_bg_color > $res3 &
# run main dialog
yad --notebook --key=$KEY --tab="Theme" --tab="Fonts" --tab="Colors" \
--title="Interface settings" --image=gnome-settings-theme \
--width=400 --image-on-top --text="Common interface settings"
# recreate rc file
if [[ $? -eq 0 ]]; then
eval TAB1=($(< $res1))
eval TAB2=($(< $res2))
eval TAB3=($(< $res3))
echo -e "\n# This file was generated automatically\n" > $rc_file
echo "gtk-theme-name = \"${TAB1[0]}\"" >> $rc_file
[[ ${TAB1[1]} != Default ]] && echo "gtk-key-theme-name = \"${TAB1[1]}\"" >> $rc_file
[[ ${TAB1[2]} != Default ]] && echo "gtk-icon-theme-name = \"${TAB1[2]}\"" >> $rc_file
[[ ${TAB1[3]} != Default ]] && echo "gtk-cursor-theme-name = \"${TAB1[3]}\"" >> $rc_file
echo >> $rc_file
case ${TAB1[4]} in
"Icons only") echo "gtk-toolbar-style = GTK_TOOLBAR_ICONS" >> $rc_file ;;
"Text only") echo "gtk-toolbar-style = GTK_TOOLBAR_TEXT" >> $rc_file ;;
"Text below icons") echo "gtk-toolbar-style = GTK_TOOLBAR_BOTH" >> $rc_file ;;
"Text beside icons") echo "gtk-toolbar-style = GTK_TOOLBAR_BOTH_HORIZ" >> $rc_file ;;
esac
case ${TAB1[5]} in
"Menu") echo "gtk-toolbar-icon-size = GTK_ICON_SIZE_MENU" >> $rc_file ;;
"Small toolbar") echo "gtk-toolbar-icon-size = GTK_ICON_SIZE_SMALL_TOOLBAR" >> $rc_file ;;
"Large toolbar") echo "gtk-toolbar-icon-size = GTK_ICON_SIZE_LARGE_TOOLBAR" >> $rc_file ;;
"Buttons") echo "gtk-toolbar-icon-size = GTK_ICON_SIZE_BUTTON" >> $rc_file ;;
"DND") echo "gtk-toolbar-icon-size = GTK_ICON_SIZE_DND" >> $rc_file ;;
"Dialog") echo "gtk-toolbar-icon-size = GTK_ICON_SIZE_DIALOG" >> $rc_file ;;
esac
echo >> $rc_file
echo -n "gtk-button-images = " >> $rc_file
[[ ${TAB1[6]} == TRUE ]] && echo 1 >> $rc_file || echo 0 >> $rc_file
echo -n "gtk-menu-images = " >> $rc_file
[[ ${TAB1[7]} == TRUE ]] && echo 1 >> $rc_file || echo 0 >> $rc_file
echo >> $rc_file
echo -e "gtk-font-name = \"${TAB2[0]}\"\n" >> $rc_file
echo -n "gtk-xft-antialiasing = " >> $rc_file
[[ ${TAB2[2]} == TRUE ]] && echo 1 >> $rc_file || echo 0 >> $rc_file
echo -n "gtk-xft-hinting = " >> $rc_file
[[ ${TAB2[3]} == TRUE ]] && echo 1 >> $rc_file || echo 0 >> $rc_file
if [[ ${TAB2[4]} != $"None" ]]; then
case ${TAB2[4]} in
"Slight") echo 'gtk-xft-hintstyle = "hintslight"' >> $rc_file ;;
"Medium") echo 'gtk-xft-hintstyle = "hintmedium"' >> $rc_file ;;
"Full") echo 'gtk-xft-hintstyle = "hintful"' >> $rc_file ;;
esac
fi
if [[ ${TAB2[5]} != $"None" ]]; then
case ${TAB2[5]} in
"RGB") echo 'gtk-xft-rgba = "rgb"' >> $rc_file ;;
"BGR") echo 'gtk-xft-rgba = "bgr"' >> $rc_file ;;
"VRGB") echo 'gtk-xft-rgba = "vrgb"' >> $rc_file ;;
"VBGR") echo 'gtk-xft-rgba = "vbgr"' >> $rc_file ;;
esac
fi
echo >> $rc_file
echo "gtk-color-scheme = \"fg_color:${TAB3[0]};bg_color:${TAB3[1]};text_color:${TAB3[2]};base_color:${TAB3[3]};selected_fg_color:${TAB3[4]};selected_bg_color:${TAB3[5]};tooltip_fg_color:${TAB3[6]};tooltip_bg_color:${TAB3[7]}\"" >> $rc_file
echo -e "\n# Custom settings\ninclude \"$rc_file.mine\"" >> $rc_file
fi
# cleanup
rm -f $res1 $res2 $res3
|
Hi
Thanks for the great example, it's really interesting.
However, if you're like me and have installed yad using debian package management then the above script won't work. As yad isn't located in /usr/desktop/bin/ (not sure if this is the make install location), its installed in /usr/bin/,
You could of course do a find replace through the script to update the location, or you can use the slight variation attached, that will automatically check the location of yad and update the script on the fly.
The modification, checks the original location in the example, as well as /usr/bin. If they both fail it which attempt to find yad in the environment path. If that also fails, it will exit with an error asking the user to update the variable "YadLocal" near the top of the script with the correct yad location. Finally it confirms YadLocal is an executable file before attempting to use it.
Hope this is helpful and saves some frustration.
Cheers
Luke
PS There seems to be some issue with the text mark-up, if I attempted to use either "#! /bin/sh" or ":::sh" to highlight the code block it turned it in to some sort of MS Word type doc, stripping '#' and turning those lines into 16+pt bold headings. Only the 6 tildes seems to work as referenced in the formatting help.
Last edit: Luke Mitchell 2015-05-19