Page 1 of 2

Retrieve a Theme's name ?

Posted: Monday 1st March 2021 1:16pm
by Doctor Watson
Question : Is there a way for a program to figure out which Theme the ‘operating system’ – if I my call it so – is using?
The origin of this post is my earlier post ‘Border problems’. So Steve and Bruce will already know what this is about.
In brief : I am desperately trying to build a programme in which a number of controls with different borders are being used. When I ran the program, those borders didn’t work – at least I thought so. I learned that the way controls appear on screen is mastered by the Theme in use.
I tested my programme with some Themes now and the results vary from No Borders At All to Appalling.
However I found already a couple that do display borders as intended by Gambas (HighContrast and Arc)
Steve also provided a Function that substitutes the border settings provided by Gambas (look in Border Problems if you’re interested)
Now I am wondering if something like the following would be possible :

1. Procedure that ‘retrieves’ the “Theme Name” (that’s the Sine Qua None of course)

2. Select Case “Theme Name”

Case “Arc”, “HighContrast”, "Other Suitable Theme", "....."
‘get out of here, Gambas borders will function

Case else
‘Use Steve’s code and set borders yourself

End Select

This way the GUI would look practically the same.
I would call that The Best Of Both Worlds.

Re: Retrieve a Theme's name ?

Posted: Monday 1st March 2021 2:13pm
by stevedee
Doctor Watson wrote: Monday 1st March 2021 1:16pm Question : Is there a way for a program to figure out which Theme the ‘operating system’ – if I my call it so – is using?...
I looked at this a few days ago with your problem in mind, and came to the conclusion that it would be difficult.

My first stop was Application.Theme which unfortunately only gives info on Icon themes.

Its tricky because different Linux distributions use a variety of Window Managers and different Widget Toolkits. On your Ubuntu system you may find that the following command (when typed into a terminal) may return the name of your theme:-
gsettings get org.gnome.desktop.interface gtk-theme
If so, you may find that you can change your theme by typing something like this:-
gsettings set org.gnome.desktop.interface gtk-theme {themename}
But it doesn't work on my Peppermint system. If I type:-
gsettings get org.gnome.desktop.interface gtk-theme
I get 'Adwaita' but I'm actually using; Clearlooks

So to return the correct theme for any system you may need a lot of conditional code. e.g.
If such-and-such Distrubution Then
If this-or-that WindowManager Then
...and so on...
However, if you find that there is a magic file or system location that stores the theme name for any Linux distribution, please let me know.

Re: Retrieve a Theme's name ?

Posted: Monday 1st March 2021 2:48pm
by BruceSteers
try.
dconf read /org/$XDG_SESSION_DESKTOP/desktop/interface/gtk-theme
(cannot test it on peppermint)

or in gambas that would be...

'' Return the current gtkTheme name
Public Sub GetTheme() As String
 Dim sTheme As String
 Shell "dconf read /org/$XDG_SESSION_DESKTOP/desktop/interface/gtk-theme" To sTheme 
 Return RTrim(sTheme)
End
a handy trick is to run dconf watch / in a terminal then change a setting.
the path of the setting change will show what you need to use for dconf read

[OOPS EDITED]

sorry Steve was using "gnome" desktop in the path and i was (i edited the code) using "mate" desktop.
so I realised we have to find out what desktop the user is using with the $XDG_SESSION_DESKTOP shell variable.
So if the user has XDG (most linux's do) and dconf then you can use default borders.
probably just easier not to lol ;)

BruceS

Re: Retrieve a Theme's name ?

Posted: Monday 1st March 2021 3:21pm
by BruceSteers
there is also a $XDG_CURRENT_DESKTOP variable but it is uppercase so to use it use...

dconf read /org/${XDG_CURRENT_DESKTOP,,}/desktop/interface/gtk-theme

there is also $DESKTOP_SESSION

dconf read /org/$DESKTOP_SESSION/desktop/interface/gtk-theme

I'm not sure what one is best to use.

Re: Retrieve a Theme's name ?

Posted: Monday 1st March 2021 4:22pm
by grayghost4
Neather one works on my Debian Gnome system

mhc@debian:~$ dconf read /org/${XDG_CURRENT_DESKTOP,,}/desktop/interface/gtk-theme
mhc@debian:~$ dconf read /org/$DESKTOP_SESSION/desktop/interface/gtk-theme
mhc@debian:~$

Re: Retrieve a Theme's name ?

Posted: Monday 1st March 2021 4:40pm
by BruceSteers
grayghost4 wrote: Monday 1st March 2021 4:22pm Neather one works on my Debian Gnome system

mhc@debian:~$ dconf read /org/${XDG_CURRENT_DESKTOP,,}/desktop/interface/gtk-theme
mhc@debian:~$ dconf read /org/$DESKTOP_SESSION/desktop/interface/gtk-theme
mhc@debian:~$
do they show up as Env variables if you type export in a shell?

Re: Retrieve a Theme's name ?

Posted: Monday 1st March 2021 4:47pm
by BruceSteers
grayghost4 wrote: Monday 1st March 2021 4:22pm Neather one works on my Debian Gnome system

mhc@debian:~$ dconf read /org/${XDG_CURRENT_DESKTOP,,}/desktop/interface/gtk-theme
mhc@debian:~$ dconf read /org/$DESKTOP_SESSION/desktop/interface/gtk-theme
mhc@debian:~$
I tried on debian 10 mate

XDG_SESSION_DESKTOP and DESKTOP_SESSION reports as lightdm-xsession so gets it wrong for desktop name

but i found
dconf read /org/${XDG_CURRENT_DESKTOP,,}/desktop/interface/gtk-theme
worked fine.

Code: Select all

bonus@debian:~$ dconf read /org/${XDG_CURRENT_DESKTOP,,}/desktop/interface/gtk-theme
'TraditionalOk'
bonus@debian:~$

Re: Retrieve a Theme's name ?

Posted: Monday 1st March 2021 5:20pm
by stevedee
I opened the dconf editor on Peppermint and did a search for gtk-theme

I got this:-
gtk-theme.png
gtk-theme.png (33.84 KiB) Viewed 5502 times

...which is the wrong theme.

Re: Retrieve a Theme's name ?

Posted: Monday 1st March 2021 5:57pm
by BruceSteers
stevedee wrote: Monday 1st March 2021 5:20pm I opened the dconf editor on Peppermint and did a search for gtk-theme

I got this:-

gtk-theme.png


...which is the wrong theme.
Oh dear lord what have Pepermint linux gone and done? :lol:
surely one of the known methods has to return the right theme ?
(I've just downloaded peppermint , gonna try it out)

Re: Retrieve a Theme's name ?

Posted: Tuesday 2nd March 2021 1:54pm
by Doctor Watson
I see that that there’s a lot of activity regarding my question. Thanks for that, but this surpasses my humble Gambas programming knowledge.
Steve, I tried the gsettings and they work fine but then, what can I do with it?
Bruce, I tried your Public Sub, but it didn’t give a result.
To make sure, I put a Label on a Form and then ran:

Public Sub Form_Open()
Dim sTheme As String
sTheme = "this should be replaced with the Theme's name"
Shell "dconf read /org/$XDG_SESSION_DESKTOP/desktop/interface/gtk-theme" To sTheme
Label1.Text = RTrim(sTheme)
If Label1.text = "" Then Label1.text = "Failed to read Theme name"
End


And the result was "Failed to read Theme name".
I also tried the other 2 dconf lines but again the results are empty strings.
So I think it’s better that I stay with something I can handle for the moment, unless someone finds a magic solution.
But perhaps in the future ………...