draw the crosshair toolbar icon from inline XPM data

The crosshair toggle button loaded the "crosshairs" icon from the
icon theme inside a bare try/except, so on systems without that
icon the button was empty and invisible. Replace it with a
self-contained red reticle (circle, center dot, cross arms) drawn
from inline XPM data, and set always-show-image so the desktop
default gtk-button-images=False cannot hide it.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
markusro committed 2026-10-18 17:47:59 +02:00
1 parent 9cc449d6e1
commit fe65073988
1 file changed
+39 -7
+39 -7
View File
@@ -17,6 +17,7 @@ import tempfile
import gi import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
gi.require_version('GtkSource', '3.0') gi.require_version('GtkSource', '3.0')
gi.require_version('GdkPixbuf', '2.0')
# import 3rd party modules # import 3rd party modules
# gui graphics # gui graphics
@@ -32,6 +33,7 @@ if gtk_version_missmatch:
raise Exception( "insufficient gtk version: " + gtk_version_missmatch ) raise Exception( "insufficient gtk version: " + gtk_version_missmatch )
from gi.repository import Gdk as gdk from gi.repository import Gdk as gdk
from gi.repository import GdkPixbuf
from gi.repository import GtkSource as gtksourceview from gi.repository import GtkSource as gtksourceview
@@ -2976,6 +2978,39 @@ pygobject version %(pygobject)s
configfile.write( "</damaris>\n" ) configfile.write( "</damaris>\n" )
# crosshair icon for the display toolbar, drawn from inline XPM data
# so it does not depend on an installed icon theme
crosshair_xpm = (
"24 24 2 1",
" c None",
". c #cc0000",
" .. ",
" .. ",
" .. ",
" .. ",
" .. ",
" ",
" ",
" ...... ",
" . . ",
" . . ",
" . .... . ",
"..... . .... . .....",
"..... . .... . .....",
" . .... . ",
" . . ",
" . . ",
" ...... ",
" ",
" ",
" .. ",
" .. ",
" .. ",
" .. ",
" .. ",
)
class MonitorWidgets: class MonitorWidgets:
"""Manages the matplotlib-based data visualization panel. """Manages the matplotlib-based data visualization panel.
@@ -3082,13 +3117,10 @@ class MonitorWidgets:
self.matplot_toolbar.remove(self.matplot_toolbar.get_nth_item(6)) self.matplot_toolbar.remove(self.matplot_toolbar.get_nth_item(6))
# now let's add a button to the toolbar # now let's add a button to the toolbar
self.matplot_cursor_button = gtk.ToggleButton(label='') self.matplot_cursor_button = gtk.ToggleButton(label='')
try: cursor_icon = GdkPixbuf.Pixbuf.new_from_xpm_data( crosshair_xpm )
icon_theme = gtk.IconTheme.get_default() self.matplot_cursor_button.set_image( gtk.Image.new_from_pixbuf( cursor_icon ) )
icon = icon_theme.load_icon("crosshairs", 24, 0) # gtk-button-images is False on many desktops, which would hide the icon
image = gtk.Image.new_from_pixbuf(icon) self.matplot_cursor_button.set_always_show_image( True )
self.matplot_cursor_button.set_image(image)
except:
pass
self.matplot_cursor_button.set_tooltip_text('Enable Crosshairs') self.matplot_cursor_button.set_tooltip_text('Enable Crosshairs')
self.matplot_cursor_button.show() self.matplot_cursor_button.show()
self.matplot_cursor_button.connect('toggled', self.toggle_cursor) self.matplot_cursor_button.connect('toggled', self.toggle_cursor)