John Duchek wrote:I would appreciate any ideas on how to get the button colored
Because GTK3 has several times changed its API during development of version 3 for getting and setting the color of widgets (Gadgets in PureBasic speek) and thus being a movable target, the PureBasic developers seem to have given up to adapt the SetColor commands.
But you may try the following example to change the backcolor of ButtonGadgets (which is derived from
this much more general color module from mk-soft and others). I have tested the examples successfully on Linux Mint 19.3 'Tricia' x64 with Cinnamon using GTK3 and PureBasic 5.73 x64.
Code: Select all
EnableExplicit
#GTK_STYLE_PROVIDER_PRIORITY_APPLICATION = 600
ImportC ""
gtk_css_provider_load_from_data(*CSSProvider, CSSData.P-UTF8, Length.I,
*Error.GError)
gtk_css_provider_new()
gtk_style_context_add_provider(*CSSContext, *CSSProvider, Priority.I)
gtk_style_context_remove_provider(*CSSContext, *CSSProvider)
gtk_widget_get_style_context(*Widget.GtkWidget)
EndImport
NewMap CSSProviderMap()
Procedure SetButtonBackColor(ButtonID.I, BackColor.I)
Shared CSSProviderMap()
Protected CSSColor.S
Protected CSSContext.I
Protected CSSButton.S
Protected CSSProvider.I
Protected Screen.I
CSSColor = "#" + RSet(Hex(Red(BackColor)), 2, "0") +
RSet(Hex(Green(BackColor)), 2, "0") +
RSet(Hex(Blue(BackColor)), 2, "0")
CSSButton = "* button {background: " + CSSColor + ";}"
CSSProvider = gtk_css_provider_new()
CSSContext = gtk_widget_get_style_context(GadgetID(ButtonID))
If FindMapElement(CSSProviderMap(), Hex(ButtonID))
gtk_style_context_remove_provider(CSSContext, CSSProviderMap())
EndIf
CSSProviderMap(Hex(ButtonID)) = CSSProvider
gtk_css_provider_load_from_data(CSSProvider, CSSButton, -1, 0)
gtk_style_context_add_provider(CSSContext, CSSProvider,
#GTK_STYLE_PROVIDER_PRIORITY_APPLICATION)
g_object_unref_(CSSProvider)
EndProcedure
OpenWindow(0, 100, 140, 280, 140, "Set backcolor of ButtonGadget")
ButtonGadget(0, 80, 30, 100, 30, "Button 1")
SetButtonBackColor(0, #Yellow)
ButtonGadget(1, 80, 80, 100, 30, "Button 2")
SetButtonBackColor(1, #Green)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
If you include mk-soft's color module, the actual example will become much shorter:
Code: Select all
EnableExplicit
XIncludeFile "/path/to/color-module.PBI"
OpenWindow(0, 100, 140, 280, 140, "Set backcolor of ButtonGadget")
ButtonGadget(0, 80, 30, 100, 30, "Button 1")
GtkGadgetColor::GtkSetGadgetColor(0, #PB_Gadget_BackColor, #Yellow)
ButtonGadget(1, 80, 80, 100, 30, "Button 2")
GtkGadgetColor::GtkSetGadgetColor(1, #PB_Gadget_BackColor, #Red)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow