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.
Retrieve a Theme's name ?
-
- Posts: 84
- Joined: Wednesday 22nd August 2018 7:55am
Retrieve a Theme's name ?
Old african saying:
You eat an elephant one small bite at a time.
You eat an elephant one small bite at a time.
Re: Retrieve a Theme's name ?
I looked at this a few days ago with your problem in mind, and came to the conclusion that it would be difficult.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?...
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:-
If so, you may find that you can change your theme by typing something like this:-gsettings get org.gnome.desktop.interface gtk-theme
But it doesn't work on my Peppermint system. If I type:-gsettings set org.gnome.desktop.interface gtk-theme {themename}
I get 'Adwaita' but I'm actually using; Clearlooksgsettings get org.gnome.desktop.interface gtk-theme
So to return the correct theme for any system you may need a lot of conditional code. e.g.
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.If such-and-such Distrubution Then
If this-or-that WindowManager Then
...and so on...
- BruceSteers
- Posts: 1589
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Retrieve a Theme's name ?
try.
dconf read /org/$XDG_SESSION_DESKTOP/desktop/interface/gtk-theme
(cannot test it on peppermint)
or in gambas that would be...
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
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 1st March 2021 3:22pm, edited 1 time in total.
If at first you don't succeed , try doing something differently.
BruceS
BruceS
- BruceSteers
- Posts: 1589
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Retrieve a Theme's name ?
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.
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.
If at first you don't succeed , try doing something differently.
BruceS
BruceS
- grayghost4
- Posts: 187
- Joined: Wednesday 5th December 2018 5:00am
- Location: Marengo, Illinois usa
Re: Retrieve a Theme's name ?
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:~$
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:~$
- BruceSteers
- Posts: 1589
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Retrieve a Theme's name ?
do they show up as Env variables if you type export in a shell?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:~$
If at first you don't succeed , try doing something differently.
BruceS
BruceS
- BruceSteers
- Posts: 1589
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Retrieve a Theme's name ?
I tried on debian 10 mategrayghost4 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:~$
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:~$
If at first you don't succeed , try doing something differently.
BruceS
BruceS
Re: Retrieve a Theme's name ?
I opened the dconf editor on Peppermint and did a search for gtk-theme
I got this:-
...which is the wrong theme.
I got this:-
...which is the wrong theme.
- BruceSteers
- Posts: 1589
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Retrieve a Theme's name ?
Oh dear lord what have Pepermint linux gone and done?
surely one of the known methods has to return the right theme ?
(I've just downloaded peppermint , gonna try it out)
If at first you don't succeed , try doing something differently.
BruceS
BruceS
-
- Posts: 84
- Joined: Wednesday 22nd August 2018 7:55am
Re: Retrieve a Theme's name ?
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 ………...
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.
You eat an elephant one small bite at a time.