Retrieve a Theme's name ?

Post your Gambas programming questions here.
Doctor Watson
Posts: 32
Joined: Wednesday 22nd August 2018 7:55am

Retrieve a Theme's name ?

Post by Doctor Watson » Monday 01st 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?
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.
Old african saying:
You eat an elephant one small bite at a time.

User avatar
stevedee
Posts: 403
Joined: Monday 20th March 2017 6:06pm

Re: Retrieve a Theme's name ?

Post by stevedee » Monday 01st March 2021 2:13pm

Doctor Watson wrote:
Monday 01st 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.

User avatar
BruceSteers
Posts: 441
Joined: Thursday 23rd July 2020 5:20pm

Re: Retrieve a Theme's name ?

Post by BruceSteers » Monday 01st March 2021 2:48pm

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
Last edited by BruceSteers on Monday 01st March 2021 3:22pm, edited 1 time in total.
Wishing well
Bruce

If at first you don't succeed , try it differently.

User avatar
BruceSteers
Posts: 441
Joined: Thursday 23rd July 2020 5:20pm

Re: Retrieve a Theme's name ?

Post by BruceSteers » Monday 01st March 2021 3:21pm

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.
Wishing well
Bruce

If at first you don't succeed , try it differently.

User avatar
grayghost4
Posts: 84
Joined: Wednesday 05th December 2018 5:00am
Location: Marengo, illinois usa

Re: Retrieve a Theme's name ?

Post by grayghost4 » Monday 01st 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:~$

User avatar
BruceSteers
Posts: 441
Joined: Thursday 23rd July 2020 5:20pm

Re: Retrieve a Theme's name ?

Post by BruceSteers » Monday 01st March 2021 4:40pm

grayghost4 wrote:
Monday 01st 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?
Wishing well
Bruce

If at first you don't succeed , try it differently.

User avatar
BruceSteers
Posts: 441
Joined: Thursday 23rd July 2020 5:20pm

Re: Retrieve a Theme's name ?

Post by BruceSteers » Monday 01st March 2021 4:47pm

grayghost4 wrote:
Monday 01st 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:~$
Wishing well
Bruce

If at first you don't succeed , try it differently.

User avatar
stevedee
Posts: 403
Joined: Monday 20th March 2017 6:06pm

Re: Retrieve a Theme's name ?

Post by stevedee » Monday 01st March 2021 5:20pm

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 507 times

...which is the wrong theme.

User avatar
BruceSteers
Posts: 441
Joined: Thursday 23rd July 2020 5:20pm

Re: Retrieve a Theme's name ?

Post by BruceSteers » Monday 01st March 2021 5:57pm

stevedee wrote:
Monday 01st 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)
Wishing well
Bruce

If at first you don't succeed , try it differently.

Doctor Watson
Posts: 32
Joined: Wednesday 22nd August 2018 7:55am

Re: Retrieve a Theme's name ?

Post by Doctor Watson » Tuesday 02nd March 2021 1:54pm

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 ………...
Old african saying:
You eat an elephant one small bite at a time.

Post Reply