Palette icons: 16x16 glyph on every widget button

- tools/gen_palette_icons.py draws all 36 glyphs (PIL, same style as
  CWidgets icons: ink + section accent, white turned transparent) into
  icons/<Key>.png; tools/verify_palette_icons.py checks 36/36 distinct.
- src/main.cpp: palette_attach_icons() puts a GtkImage left of each
  button label (icons/ with ../icons/ fallback, text-only if missing);
  self-test asserts 36/36 icons, palette 250x780, no scrolling.
- Fixed the round-3 tight CSS, which never applied: the builder id is
  not the widget name (it stayed GtkWindow), and the per-widget style
  provider never reached the buttons. Name is now set explicitly and
  the provider is screen-wide (selector still scopes it to the palette);
  button labels 9pt so icon + label fit the 250-wide window.
- tests/palette_icons_tests.sh (13 checks) + Memo click coordinate fix
  in tests/palette_window_tests.sh for the shorter rows.
- screenshots 15 (palette with icons) + 16 (three windows with icons).
This commit is contained in:
Muse committed 2026-11-25 15:56:35 -05:00
1 parent 1e2e6f8692
commit 310ff34c47
43 files changed
+600 -5

No files matched your search

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 147 B

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 177 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 193 B

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 150 B

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 135 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 B

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 193 B

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 B

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 157 B

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 166 B

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 185 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 B

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 153 B

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 205 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 B

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 160 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 176 B

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 191 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 B

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 161 B

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 197 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 183 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 KiB

+82 -4
View File
@@ -184,6 +184,8 @@ struct Item {
static Project g_project;
static GtkWidget* g_window = nullptr;
static GtkWidget* g_palette_window = nullptr; // top-level palette window
static GtkWidget* g_palette_scroll = nullptr; // its GtkScrolledWindow
static int g_palette_icons_attached = 0; // palette buttons given a glyph
static GtkWidget* g_palette_menu_item = nullptr; // View -> Widget Palette
static GtkWidget* g_canvas = nullptr; // GtkFixed
static GtkWidget* g_viewport = nullptr; // canvas parent (window background)
@@ -2410,6 +2412,54 @@ static void on_palette_clicked(GtkButton*, gpointer data) {
add_widget((const char*)data);
}
// Attach the 16x16 glyph (icons/<Key>.png) to the left of each palette
// button's label. The button keeps its clicked handler; only its child
// changes, from a bare label to an hbox holding the image + the same label.
// The icon path uses the same lookup as designer.ui: icons/ first, then
// ../icons/. A missing or unreadable icon leaves the button text-only;
// g_palette_icons_attached counts the buttons that got one (36 expected).
static void palette_attach_icons(GtkBuilder* builder) {
for (const TypeInfo& t : kTypes) {
GObject* b = gtk_builder_get_object(builder, t.palette_id);
if (!b) continue;
std::string path;
for (const std::string& cand :
{std::string("icons/") + t.key + ".png",
std::string("../icons/") + t.key + ".png"}) {
if (g_file_test(cand.c_str(), G_FILE_TEST_IS_REGULAR)) {
path = cand;
break;
}
}
if (path.empty()) continue;
GError* err = nullptr;
GdkPixbuf* px = gdk_pixbuf_new_from_file(path.c_str(), &err);
if (!px) {
if (err) g_error_free(err);
continue;
}
GList* kids = gtk_container_get_children(GTK_CONTAINER(b));
GtkWidget* label = kids ? GTK_WIDGET(kids->data) : nullptr;
if (!label) {
g_object_unref(px);
g_list_free(kids);
continue;
}
g_list_free(kids);
GtkWidget* img = gtk_image_new_from_pixbuf(px);
g_object_unref(px);
GtkWidget* box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
g_object_ref(label);
gtk_container_remove(GTK_CONTAINER(b), label);
gtk_container_add(GTK_CONTAINER(box), img);
gtk_container_add(GTK_CONTAINER(box), label);
g_object_unref(label);
gtk_container_add(GTK_CONTAINER(b), box);
gtk_widget_show_all(box);
++g_palette_icons_attached;
}
}
// ------------------------------------------------------- palette window
// The widget palette lives in its own top-level window ("FDesigner —
// Widgets"), opened together with the designer. It is a plain top-level
@@ -4001,6 +4051,27 @@ static gboolean selftest_step(gpointer) {
bsess2.breakpoints()[0].location == "foo.cpp:7");
}
// Palette icons: every button carries its 16x16 glyph, and the
// palette still fits its 250-wide window with no scrolling in either
// direction (page size covers the whole content).
while (gtk_events_pending()) gtk_main_iteration();
check(g_palette_icons_attached == 36);
if (g_palette_window) {
gint pw = 0, ph = 0;
gtk_window_get_size(GTK_WINDOW(g_palette_window), &pw, &ph);
check(pw == 250 && ph == 780);
}
if (g_palette_scroll) {
GtkAdjustment* hadj = gtk_scrolled_window_get_hadjustment(
GTK_SCROLLED_WINDOW(g_palette_scroll));
GtkAdjustment* vadj = gtk_scrolled_window_get_vadjustment(
GTK_SCROLLED_WINDOW(g_palette_scroll));
check(gtk_adjustment_get_page_size(hadj) >=
gtk_adjustment_get_upper(hadj));
check(gtk_adjustment_get_page_size(vadj) >=
gtk_adjustment_get_upper(vadj));
}
std::printf("SELFTEST %s items=%zu\n", ok ? "PASS" : "FAIL",
g_items.size());
std::fflush(stdout);
@@ -4064,6 +4135,9 @@ int main(int argc, char** argv) {
g_signal_connect(b, "clicked", G_CALLBACK(on_palette_clicked),
(gpointer)t.key);
}
g_palette_scroll =
GTK_WIDGET(gtk_builder_get_object(builder, "palette_scroll"));
palette_attach_icons(builder);
// Clicking empty canvas deselects: the GtkFixed has no window of its
// own, so empty-area presses land on its parent GtkViewport.
@@ -4221,15 +4295,19 @@ int main(int argc, char** argv) {
// [palette-window] Tight Lazarus-style packing: small buttons,
// minimal padding, no whitespace between rows. USER priority so
// it wins over the application theme/font providers.
// The builder id is not the widget name (it stays "GtkWindow"), so
// set the name explicitly - the tight CSS below selects on it.
gtk_widget_set_name(g_palette_window, "palette_window");
GtkCssProvider* pal_css = gtk_css_provider_new();
gtk_css_provider_load_from_data(
pal_css,
"#palette_window button { min-height: 20px; padding: 1px 4px; }"
"#palette_window button label { padding: 0px; }"
"#palette_window button { min-height: 20px; padding: 1px 2px; }"
"#palette_window button label { padding: 0px; font-size: 9pt; }"
"#palette_window button image { padding: 0px; }"
"#palette_window label { padding: 0px; }",
-1, nullptr);
gtk_style_context_add_provider(
gtk_widget_get_style_context(g_palette_window),
gtk_style_context_add_provider_for_screen(
gdk_screen_get_default(),
GTK_STYLE_PROVIDER(pal_css),
GTK_STYLE_PROVIDER_PRIORITY_USER);
gtk_widget_show_all(g_palette_window);
+125
View File
@@ -0,0 +1,125 @@
#!/usr/bin/env bash
# Palette-icon tests: every palette button shows its 16x16 glyph left of
# the label, the palette still fits its 250x780 window with no scrolling,
# clicks still place widgets, and the rest of the app is unbroken.
set -u
cd "$(dirname "$0")/.."
pass=0; fail=0; failed=""
ok() { echo "PASS $1"; pass=$((pass+1)); }
bad() { echo "FAIL $1"; fail=$((fail+1)); failed="$failed $1"; }
# Re-run the body under Xvfb when no display is set.
if [ -z "${DISPLAY:-}" ]; then
PALETTE_ICONS_TEST_IN_XVFB=1 xvfb-run -a -s "-screen 0 2560x1440x24" "$0"
exit $?
fi
echo "== generating + verifying icons =="
if python3 tools/gen_palette_icons.py > /tmp/icons_gen.log 2>&1; then
ok icons-generate; cat /tmp/icons_gen.log
else bad icons-generate; cat /tmp/icons_gen.log; fi
if python3 tools/verify_palette_icons.py > /tmp/icons_verify.log 2>&1; then
ok icons-verify; cat /tmp/icons_verify.log
else bad icons-verify; cat /tmp/icons_verify.log; fi
echo "== building fdesigner =="
if make clean > /tmp/icons_make.log 2>&1 && make >> /tmp/icons_make.log 2>&1; then
ok make
if grep -qi "warning" /tmp/icons_make.log; then
bad make-no-warnings; grep -i "warning" /tmp/icons_make.log
else ok make-no-warnings; fi
else bad make; cat /tmp/icons_make.log; exit 1; fi
echo "== self-test (36/36 icons + no-scroll checks are inside) =="
if FDESIGNER_SELFTEST=1 ./fdesigner > /tmp/icons_selftest.log 2>&1; then
grep -q "SELFTEST PASS" /tmp/icons_selftest.log && ok selftest || \
{ bad selftest; tail -3 /tmp/icons_selftest.log; }
else bad selftest; tail -3 /tmp/icons_selftest.log; fi
echo "== launching designer under Xvfb ($DISPLAY) =="
./fdesigner > /tmp/icons_app.log 2>&1 &
APP_PID=$!
trap 'kill $APP_PID 2>/dev/null || true' EXIT
sleep 3
if ! kill -0 $APP_PID 2>/dev/null; then
bad "app-start"; cat /tmp/icons_app.log; exit 1
fi
ok app-start
MAIN=$(xdotool search --name "FDesigner — C\+\+/GTK" | head -1)
PAL=$(xdotool search --name "FDesigner — Widgets" | head -1)
CODE=$(xdotool search --name "FDesigner — Code" | head -1)
[ -n "$PAL" ] && ok palette-window || bad palette-window
# Palette still exactly 250x780.
if [ -n "$PAL" ]; then
geom() { xdotool getwindowgeometry "$1" | sed -n \
-e 's/ *Position: \([0-9]*\),\([0-9]*\).*/X=\1; Y=\2/p' \
-e 's/ *Geometry: \([0-9]*\)x\([0-9]*\)/W=\1; H=\2/p'; }
eval "$(geom "$PAL")"
echo "palette ${W}x${H}@${X},${Y}"
if [ "$W" -eq 250 ] && [ "$H" -eq 780 ]; then ok palette-250x780;
else bad palette-250x780; fi
fi
# Screenshot the palette; count section-accent pixels (icons carry the
# accent, labels are dark ink) - proves glyphs are really painted.
if [ -n "$PAL" ]; then
import -window "$PAL" /tmp/icons_palette.png
ACCENT=$(python3 - "$PAL" << "PYEOF" 2>/dev/null
import sys
from PIL import Image
im = Image.open("/tmp/icons_palette.png").convert("RGB")
accents = [(37, 99, 235), (22, 163, 74), (8, 145, 178),
(234, 88, 12), (147, 51, 234)]
n = 0
for r, g, b in im.getdata():
for (ar, ag, ab) in accents:
if abs(r - ar) <= 10 and abs(g - ag) <= 10 and abs(b - ab) <= 10:
n += 1
break
print(n)
PYEOF
)
echo "accent pixels in palette shot: ${ACCENT:-?}"
if [ "${ACCENT:-0}" -ge 300 ] 2>/dev/null; then ok palette-icons-painted;
else bad palette-icons-painted; fi
fi
# Clicking a palette button still places a widget (canvas changes).
if [ -n "$PAL" ] && [ -n "$MAIN" ]; then
eval "$(xdotool getwindowgeometry "$MAIN" | sed -n \
-e 's/ *Position: \([0-9]*\),\([0-9]*\).*/MX=\1; MY=\2/p')"
eval "$(xdotool getwindowgeometry "$PAL" | sed -n \
-e 's/ *Position: \([0-9]*\),\([0-9]*\).*/PX=\1; PY=\2/p')"
CX=$((MX + 10)); CY=$((MY + 30))
import -window root -crop 500x220+${CX}+${CY} /tmp/icons_before.png
xdotool mousemove $((PX + 62)) $((PY + 39)) click 1; sleep 0.7
# Memo button (Lazarus - Basic, left column, first row of its section).
xdotool mousemove $((PX + 62)) $((PY + 269)) click 1; sleep 0.7
import -window root -crop 500x220+${CX}+${CY} /tmp/icons_after.png
DIFF=$(compare -metric AE -fuzz 5% /tmp/icons_before.png \
/tmp/icons_after.png /tmp/icons_diff.png 2>&1 || true)
echo "canvas pixel diff: $DIFF"
if [ "${DIFF:-0}" -gt 1000 ] 2>/dev/null; then ok palette-click-places;
else bad palette-click-places; fi
fi
# Screenshots for the record.
if [ -n "$PAL" ]; then
import -window "$PAL" screenshots/15_palette_icons.png
ok shot-palette
fi
import -window root screenshots/16_three_windows_icons.png
ok shot-desktop
# No GTK warnings/criticals in the app log.
if grep -qE "Gtk-CRITICAL|Gdk-WARNING" /tmp/icons_app.log; then
bad "app-log-warnings"; grep -E "Gtk-CRITICAL|Gdk-WARNING" /tmp/icons_app.log
else ok app-log-clean; fi
kill $APP_PID 2>/dev/null || true
trap - EXIT
echo "== palette_icons_tests: $pass passed, $fail failed ==$failed"
[ $fail -eq 0 ]
+1 -1
View File
@@ -119,7 +119,7 @@ if [ -n "$PAL" ] && [ -n "$MAIN" ]; then
# First button (Button, left column, first grid row).
xdotool mousemove $((PX + 62)) $((PY + 39)) click 1; sleep 0.7
# Memo button (Lazarus — Basic, left column).
xdotool mousemove $((PX + 62)) $((PY + 350)) click 1; sleep 0.7
xdotool mousemove $((PX + 62)) $((PY + 269)) click 1; sleep 0.7
import -window root -crop 500x220+${CX}+${CY} /tmp/palette_after.png
DIFF=$(compare -metric AE -fuzz 5% /tmp/palette_before.png \
/tmp/palette_after.png /tmp/palette_diff.png 2>&1 || true)
+340
View File
@@ -0,0 +1,340 @@
#!/usr/bin/env python3
"""Generate one 16x16 PNG icon per FDesigner palette widget (icons/<Key>.png).
Purpose-drawn glyphs (PIL ImageDraw), NOT downscaled screenshots: at 16x16
a screenshot is mush, a 2-3 element glyph stays readable.
Style matches the CWidgets icons (tools/gen_icons.py in the CWidgets repo):
dark ink + mid grey + light fill, one accent colour per palette section.
The glyphs are drawn on white and the white is then turned transparent, so
each icon sits directly on the GTK button face with no white box around it.
Glyph functions below are copied verbatim from the CWidgets icon generator
(same style, same constants) except g_stockchart / g_scrollbox / g_listview,
which are new here because FDesigner has no CWidgets twin for them.
Usage: python3 tools/gen_palette_icons.py (run from the repo root)
"""
import os, sys
from PIL import Image, ImageDraw
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
INK = (30, 30, 30)
MID = (140, 140, 140)
LIGHT = (226, 228, 232)
WHITE = (255, 255, 255)
GREEN = (22, 163, 74)
RED = (220, 38, 38)
# Accent colour per palette section (same palette as CWidgets sections).
BLUE = (37, 99, 235) # Widgets
LAZ_GREEN = (22, 163, 74) # Lazarus - Basic
CYAN = (8, 145, 178) # Containers
ORANGE = (234, 88, 12) # Input
PURPLE = (147, 51, 234) # Data / Display
def g_button(d, a):
d.rounded_rectangle([1, 4, 14, 11], radius=2, outline=INK, fill=LIGHT)
d.line([4, 7, 11, 7], fill=a, width=2)
def g_label(d, a):
d.line([2, 4, 13, 4], fill=INK, width=2)
d.line([2, 8, 10, 8], fill=a, width=2)
d.line([2, 12, 13, 12], fill=MID, width=2)
def g_entry(d, a):
d.rectangle([1, 4, 14, 11], outline=INK, fill=WHITE)
d.line([4, 7, 4, 9], fill=a, width=2)
d.line([6, 8, 12, 8], fill=MID)
def g_check(d, a):
d.rectangle([1, 3, 8, 10], outline=INK, fill=WHITE)
d.line([2, 6, 4, 8, 7, 4], fill=a, width=2)
d.line([10, 5, 14, 5], fill=MID); d.line([10, 8, 14, 8], fill=MID)
def g_radio(d, a):
d.ellipse([1, 2, 8, 9], outline=INK, fill=WHITE)
d.ellipse([3, 4, 6, 7], fill=a)
d.line([10, 4, 14, 4], fill=MID); d.line([10, 7, 14, 7], fill=MID)
def g_frame(d, a):
d.rectangle([1, 3, 14, 14], outline=INK)
d.line([1, 3, 4, 3], fill=INK); d.line([9, 3, 14, 3], fill=INK)
d.line([5, 1, 8, 1], fill=a, width=2)
def g_combo(d, a):
d.rectangle([1, 4, 14, 11], outline=INK, fill=WHITE)
d.line([10, 4, 10, 11], fill=INK)
d.polygon([(11, 6), (14, 6), (12, 9)], fill=a)
def g_list(d, a):
d.rectangle([1, 1, 14, 14], outline=INK, fill=WHITE)
for y in (3, 7, 11):
d.rectangle([3, y, 5, y + 1], fill=a)
d.line([7, y, 12, y], fill=MID)
def g_menu(d, a):
d.rectangle([1, 1, 14, 14], outline=INK, fill=WHITE)
d.line([3, 4, 12, 4], fill=INK); d.line([3, 7, 12, 7], fill=MID)
d.line([3, 10, 12, 10], fill=MID); d.line([3, 13, 8, 13], fill=MID)
def g_pencil(d, a):
d.line([3, 12, 11, 4], fill=a, width=2)
d.polygon([(11, 4), (13, 2), (13, 5)], fill=INK)
d.line([2, 13, 5, 13], fill=INK)
def g_slider(d, a):
d.line([1, 8, 14, 8], fill=INK, width=2)
d.rectangle([6, 4, 9, 11], outline=INK, fill=a)
d.line([3, 12, 3, 14], fill=MID); d.line([12, 12, 12, 14], fill=MID)
def g_scrollbar(d, a):
d.rectangle([9, 1, 14, 14], outline=INK, fill=WHITE)
d.rectangle([10, 4, 13, 10], fill=a)
d.rectangle([1, 1, 7, 14], outline=INK, fill=WHITE)
d.line([3, 4, 5, 4], fill=MID); d.line([3, 7, 5, 7], fill=MID); d.line([3, 10, 5, 10], fill=MID)
def g_textview(d, a):
d.rectangle([1, 1, 14, 14], outline=INK, fill=WHITE)
d.line([3, 4, 12, 4], fill=INK); d.line([3, 7, 12, 7], fill=MID)
d.line([3, 10, 9, 10], fill=MID); d.line([3, 12, 12, 12], fill=MID)
def g_window(d, a):
d.rectangle([1, 1, 14, 14], outline=INK, fill=WHITE)
d.rectangle([1, 1, 14, 4], fill=a)
d.point((3, 2), fill=WHITE); d.point((5, 2), fill=WHITE)
d.line([3, 8, 11, 8], fill=MID); d.line([3, 11, 8, 11], fill=MID)
def g_spreadsheet(d, a):
d.rectangle([1, 1, 14, 14], outline=INK, fill=WHITE)
d.rectangle([1, 1, 14, 4], fill=(22, 163, 74))
for x in (5, 10):
d.line([x, 1, x, 14], fill=INK)
for y in (8, 11):
d.line([1, y, 14, y], fill=INK)
def g_memo(d, a):
g_textview(d, a)
d.line([11, 1, 11, 4, 14, 4], fill=INK)
def g_checkgroup(d, a):
d.rectangle([1, 3, 14, 14], outline=INK)
d.line([1, 3, 4, 3], fill=INK); d.line([9, 3, 14, 3], fill=INK)
d.rectangle([3, 6, 6, 9], outline=INK)
d.line([3, 7, 5, 9, 6, 6], fill=a)
d.rectangle([3, 11, 6, 14], outline=INK)
d.line([8, 7, 12, 7], fill=MID); d.line([8, 12, 12, 12], fill=MID)
def g_box(d, a):
d.rectangle([1, 1, 14, 14], outline=INK, fill=WHITE)
d.line([5, 1, 5, 14], fill=a); d.line([10, 1, 10, 14], fill=a)
def g_image(d, a):
d.rectangle([1, 1, 14, 14], outline=INK, fill=WHITE)
d.ellipse([4, 3, 6, 5], fill=a)
d.line([1, 12, 6, 7, 9, 10, 14, 5], fill=INK, width=1)
def g_shape(d, a):
d.ellipse([2, 2, 9, 9], outline=INK)
d.rectangle([7, 7, 14, 14], outline=a, fill=WHITE)
def g_tabs(d, a):
d.rectangle([2, 1, 7, 4], outline=INK, fill=a)
d.rectangle([8, 1, 13, 4], outline=INK, fill=LIGHT)
d.rectangle([1, 4, 14, 14], outline=INK, fill=WHITE)
d.line([3, 8, 11, 8], fill=MID); d.line([3, 11, 8, 11], fill=MID)
def g_splitter(d, a):
d.rectangle([1, 1, 6, 14], outline=INK, fill=WHITE)
d.rectangle([9, 1, 14, 14], outline=INK, fill=WHITE)
d.line([7, 4, 8, 4], fill=a, width=2); d.line([7, 7, 8, 7], fill=a, width=2)
d.line([7, 10, 8, 10], fill=a, width=2)
def g_statusbar(d, a):
d.rectangle([1, 1, 14, 14], outline=INK, fill=WHITE)
d.rectangle([1, 11, 14, 14], fill=LIGHT, outline=INK)
d.line([11, 12, 13, 14], fill=a); d.line([12, 12, 14, 14], fill=a)
def g_toolbar(d, a):
d.rectangle([1, 1, 14, 5], fill=LIGHT, outline=INK)
d.rectangle([2, 2, 5, 4], fill=a)
d.rectangle([7, 2, 9, 4], outline=INK); d.rectangle([11, 2, 13, 4], outline=INK)
d.rectangle([1, 6, 14, 14], outline=INK, fill=WHITE)
d.line([3, 9, 11, 9], fill=MID); d.line([3, 12, 8, 12], fill=MID)
def g_menubar(d, a):
d.rectangle([1, 1, 14, 4], fill=a)
d.rectangle([2, 2, 5, 3], fill=WHITE); d.rectangle([7, 2, 10, 3], fill=WHITE)
d.rectangle([1, 5, 14, 14], outline=INK, fill=WHITE)
d.line([3, 8, 11, 8], fill=MID); d.line([3, 11, 8, 11], fill=MID)
def g_spin(d, a):
d.rectangle([1, 3, 14, 12], outline=INK, fill=WHITE)
d.line([10, 3, 10, 12], fill=INK)
d.polygon([(11, 6), (13, 6), (12, 4)], fill=a)
d.polygon([(11, 9), (13, 9), (12, 11)], fill=a)
d.line([3, 7, 8, 7], fill=MID)
def g_trackbar(d, a):
d.line([1, 8, 14, 8], fill=INK, width=2)
for x in (3, 7, 11, 13):
d.line([x, 5, x, 11], fill=MID)
d.rectangle([6, 4, 9, 11], outline=INK, fill=a)
def g_progress(d, a):
d.rectangle([1, 5, 14, 10], outline=INK, fill=WHITE)
d.rectangle([2, 6, 9, 9], fill=a)
def g_clock(d, a):
d.ellipse([2, 2, 13, 13], outline=INK, width=2)
d.line([7, 7, 7, 4], fill=a, width=2)
d.line([7, 7, 10, 9], fill=INK, width=2)
d.line([7, 1, 7, 2], fill=INK)
def g_color(d, a):
d.rectangle([1, 1, 7, 7], fill=(220, 38, 38))
d.rectangle([8, 1, 14, 7], fill=(234, 179, 8))
d.rectangle([1, 8, 7, 14], fill=(37, 99, 235))
d.rectangle([8, 8, 14, 14], fill=(22, 163, 74))
d.rectangle([1, 1, 14, 14], outline=INK)
def g_tree(d, a):
d.rectangle([1, 1, 14, 14], outline=INK, fill=WHITE)
d.line([3, 3, 3, 12], fill=MID)
for y in (3, 7, 11):
d.line([3, y, 5, y], fill=MID)
d.rectangle([6, y - 1, 8, y + 1], fill=a)
d.line([10, y, 12, y], fill=MID)
def g_grid(d, a):
d.rectangle([1, 1, 14, 14], outline=INK, fill=WHITE)
d.rectangle([1, 1, 14, 4], fill=a)
for x in (5, 10):
d.line([x, 1, x, 14], fill=INK)
for y in (8, 11):
d.line([1, y, 14, y], fill=INK)
def g_graph(d, a):
d.line([2, 2, 2, 13], fill=INK, width=2)
d.line([2, 13, 14, 13], fill=INK, width=2)
d.line([3, 10, 6, 7, 9, 9, 13, 3], fill=a, width=2)
def g_stockchart(d, a):
# Candlestick chart: axes + three candles (up / down / up).
d.line([2, 2, 2, 13], fill=INK, width=2)
d.line([2, 13, 14, 13], fill=INK, width=2)
d.line([4, 5, 4, 12], fill=INK)
d.rectangle([3, 7, 5, 11], fill=GREEN, outline=INK)
d.line([8, 3, 8, 10], fill=INK)
d.rectangle([7, 4, 9, 8], fill=RED, outline=INK)
d.line([12, 6, 12, 12], fill=INK)
d.rectangle([11, 8, 13, 11], fill=a, outline=INK)
def g_scrollbox(d, a):
# Container box with a scrollbar thumb on its right edge.
d.rectangle([1, 1, 14, 14], outline=INK, fill=WHITE)
d.line([5, 1, 5, 14], fill=MID)
d.line([9, 1, 9, 14], fill=MID)
d.rectangle([11, 3, 13, 9], fill=a)
def g_listview(d, a):
# List with a header bar (rows under a coloured header).
d.rectangle([1, 1, 14, 14], outline=INK, fill=WHITE)
d.rectangle([1, 1, 14, 4], fill=a)
for y in (7, 10, 13):
d.rectangle([3, y, 5, y + 1], fill=INK)
d.line([7, y, 12, y], fill=MID)
# type key -> (glyph function, section accent). Keys must match kTypes in
# src/model.h exactly; file names are icons/<key>.png.
MAPPING = {
# Widgets
"Button": ("button", BLUE), "Label": ("label", BLUE),
"Entry": ("entry", BLUE), "Checkbutton": ("check", BLUE),
"Radiobutton": ("radio", BLUE), "Frame": ("frame", BLUE),
"Combobox": ("combo", BLUE), "Listbox": ("list", BLUE),
"Menubutton": ("menu", BLUE), "Canvas": ("pencil", BLUE),
"Scale": ("slider", BLUE), "Scrollbar": ("scrollbar", BLUE),
"Text": ("textview", BLUE), "Toplevel": ("window", BLUE),
"Spreadsheet": ("spreadsheet", BLUE), "StockChart": ("stockchart", BLUE),
# Lazarus - Basic
"Memo": ("memo", LAZ_GREEN), "GroupBox": ("checkgroup", LAZ_GREEN),
"Panel": ("box", LAZ_GREEN), "Image": ("image", LAZ_GREEN),
"Shape": ("shape", LAZ_GREEN),
# Containers
"Notebook": ("tabs", CYAN), "ScrollBox": ("scrollbox", CYAN),
"Splitter": ("splitter", CYAN), "StatusBar": ("statusbar", CYAN),
"ToolBar": ("toolbar", CYAN), "MenuBar": ("menubar", CYAN),
# Input
"SpinEdit": ("spin", ORANGE), "TrackBar": ("trackbar", ORANGE),
"ProgressBar": ("progress", ORANGE), "DateTimePicker": ("clock", ORANGE),
"ColorBox": ("color", ORANGE),
# Data / Display
"ListView": ("listview", PURPLE), "TreeView": ("tree", PURPLE),
"StringGrid": ("grid", PURPLE), "Plot": ("graph", PURPLE),
}
GLYPHS = {
"box": g_box,
"button": g_button,
"check": g_check,
"checkgroup": g_checkgroup,
"clock": g_clock,
"color": g_color,
"combo": g_combo,
"entry": g_entry,
"frame": g_frame,
"graph": g_graph,
"grid": g_grid,
"image": g_image,
"label": g_label,
"list": g_list,
"listview": g_listview,
"memo": g_memo,
"menu": g_menu,
"menubar": g_menubar,
"pencil": g_pencil,
"progress": g_progress,
"radio": g_radio,
"scrollbar": g_scrollbar,
"scrollbox": g_scrollbox,
"shape": g_shape,
"slider": g_slider,
"spin": g_spin,
"splitter": g_splitter,
"spreadsheet": g_spreadsheet,
"statusbar": g_statusbar,
"stockchart": g_stockchart,
"tabs": g_tabs,
"textview": g_textview,
"toolbar": g_toolbar,
"trackbar": g_trackbar,
"tree": g_tree,
"window": g_window,
}
def main():
outdir = os.path.join(ROOT, "icons")
os.makedirs(outdir, exist_ok=True)
for key, (glyph, accent) in sorted(MAPPING.items()):
img = Image.new("RGB", (16, 16), WHITE)
d = ImageDraw.Draw(img)
GLYPHS[glyph](d, accent)
# Exact white -> transparent: the glyph then sits on the button
# face instead of inside a white box.
img = img.convert("RGBA")
px = [(r, g, b, 0) if (r, g, b) == WHITE else (r, g, b, 255)
for (r, g, b, a) in img.getdata()]
img.putdata(px)
img.save(os.path.join(outdir, key + ".png"))
print(f"icons written: {len(MAPPING)} in {outdir}")
return 0
if __name__ == "__main__":
sys.exit(main())
+52
View File
@@ -0,0 +1,52 @@
#!/usr/bin/env python3
"""Verify icons/<Key>.png: one 16x16 RGBA PNG per palette type key in
src/model.h (kTypes), non-blank, all distinct. Run from the repo root:
python3 tools/verify_palette_icons.py"""
import hashlib
import os
import sys
from PIL import Image
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
KEYS = ["Button", "Label", "Entry", "Checkbutton", "Radiobutton", "Frame",
"Combobox", "Listbox", "Menubutton", "Canvas", "Scale", "Scrollbar",
"Text", "Toplevel", "Spreadsheet", "StockChart", "Memo", "GroupBox",
"Panel", "Image", "Shape", "Notebook", "ScrollBox", "Splitter",
"StatusBar", "ToolBar", "MenuBar", "SpinEdit", "TrackBar",
"ProgressBar", "DateTimePicker", "ColorBox", "ListView", "TreeView",
"StringGrid", "Plot"]
def main():
ok = True
hashes = {}
for key in KEYS:
path = os.path.join(ROOT, "icons", key + ".png")
if not os.path.isfile(path):
print(f"MISSING {key}.png")
ok = False
continue
im = Image.open(path)
if im.size != (16, 16) or im.mode != "RGBA":
print(f"BAD FORMAT {key}.png: {im.size} {im.mode}")
ok = False
continue
vis = [p for p in im.getdata() if p[3] > 0]
if len(vis) < 25 or len(set(vis)) < 2:
print(f"BLANK/FLAT {key}.png: {len(vis)} visible px, "
f"{len(set(vis))} colours")
ok = False
continue
h = hashlib.md5(im.tobytes()).hexdigest()
if h in hashes:
print(f"DUPLICATE {key}.png == {hashes[h]}.png")
ok = False
hashes[h] = key
print(f"palette icons: {len(hashes)}/{len(KEYS)} distinct, "
f"{'OK' if ok else 'FAIL'}")
return 0 if ok else 1
if __name__ == "__main__":
sys.exit(main())