problem withsetting the background color of a gadget in gtk

Linux specific forum
Bitblazer
Enthusiast
Enthusiast
Posts: 733
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

problem withsetting the background color of a gadget in gtk

Post by Bitblazer »

OS Debian 10 x64 - Gnome desktop with gtk2/gtk3/qt support, PB 5.70 x64

target subsystems GTK2 and QT, the executables launched side by side

Purebasic command used to set the background color

Code: Select all

SetGadgetColor(#Fieldtoken2, #PB_Gadget_BackColor, BGColor)
GTK vs QT - side by side

Source : SystemInfo095.tar.gz
webpage - discord chat links -> purebasic GPT4All
John Duchek
User
User
Posts: 83
Joined: Mon May 16, 2005 4:19 pm
Location: St. Louis, MO

Re: problem withsetting the background color of a gadget in

Post by John Duchek »

This appears to be a continuing problem. I am running fedora 33 using xfce4. I am building a window and want a colored button. Purebasic 5.73 LTS-(x64)
ButtonGadget(41, 975, 30, 125, 40, "Start Distillation",#PB_Button_MultiLine)
SetGadgetColor(41, #PB_Gadget_BackColor, $0000FF)
;SetGadgetColor(41,#PB_Gadget_BackColor,RGB(200,20,20))

I have tried both of the setgadgetcolor commands, but the button remains grey.

I would appreciate any ideas on how to get the button colored.

John
John R. Duchek
St. Louis,MO
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: problem withsetting the background color of a gadget in

Post by IdeasVacuum »

The button gadget does not accept a background colour

https://www.purebasic.com/documentation ... adget.html

You can either create your own buttons (Canvas) or use a Button image gadget.
On Windows, it is possible via the API, but requires a lot of code for such a small requirement.

Thorsten1867 has made a really nice Module that should suit your requirements:

viewtopic.php?f=27&t=72520
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: problem withsetting the background color of a gadget in

Post by Shardik »

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
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: problem withsetting the background color of a gadget in

Post by TI-994A »

John Duchek wrote:...any ideas on how to get the button colored.
Take a look at the ButtonGadgetEx() function. It's a ready-to-use, single-call, single-procedure, cross-platform solution.

> ButtonGadgetEx() with foreground & background colour settings, and text formatting

(underlining not supported on Linux)
Image
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Post Reply