Retrieve a Theme's name ?

Post

Posted
Rating:
#1 (In Topic #601)
Regular
Doctor Watson is in the usergroup ‘Regular’
 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.
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
stevedee is in the usergroup ‘Regular’

Doctor Watson said

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.
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
try.
dconf read /org/$XDG_SESSION_DESKTOP/desktop/interface/gtk-theme
(cannot test it on peppermint)

or in gambas that would be…

Code (gambas)

  1.  
  2. '' Return the current gtkTheme name
  3. Public Sub GetTheme() As String
  4.  Dim sTheme As String
  5.  Shell "dconf read /org/$XDG_SESSION_DESKTOP/desktop/interface/gtk-theme" To sTheme
  6.  Return RTrim(sTheme)
  7.  

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
Online now: No Back to the top

Post

Posted
Rating:
#4
Guru
BruceSteers is in the usergroup ‘Guru’
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.
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
 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:~$
Online now: No Back to the top

Post

Posted
Rating:
#6
Guru
BruceSteers is in the usergroup ‘Guru’

grayghost4 said

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?
Online now: No Back to the top

Post

Posted
Rating:
#7
Guru
BruceSteers is in the usergroup ‘Guru’

grayghost4 said

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

bonus@debian:~$ dconf read /org/$\{XDG_CURRENT_DESKTOP,,}/desktop/interface/gtk-theme
'TraditionalOk'
bonus@debian:~$
Online now: No Back to the top

Post

Posted
Rating:
#8
Avatar
Regular
stevedee is in the usergroup ‘Regular’
I opened the dconf editor on Peppermint and did a search for gtk-theme

I got this:-

Image

(Click to enlarge)



…which is the wrong theme.
Online now: No Back to the top

Post

Posted
Rating:
#9
Guru
BruceSteers is in the usergroup ‘Guru’

stevedee said

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)
Online now: No Back to the top

Post

Posted
Rating:
#10
Regular
Doctor Watson is in the usergroup ‘Regular’
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.
Online now: No Back to the top

Post

Posted
Rating:
#11
Guru
BruceSteers is in the usergroup ‘Guru’

Doctor Watson said

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 …………

nothing is ever that easy ;)
the best one to use is $XDG_CURRENT_DESKTOP but it's upper case.
open a terminal and type "import" to see a list of available environment variables.

the expression ${XDG_CURRENT_DESKTOP,,} turns it into lower case but it is a "bash" instruction.
Gambas uses sh not bash by default.  :?

so you need to set bash as the shell to use (a simple addition to the start of the code)

try this..

Code (gambas)

  1. Public Sub Form_Open()
  2.  
  3. System.Shell = System,.Find("bash")
  4.  
  5. Dim sTheme As String
  6. sTheme = "this should be replaced with the Theme's name"
  7. Shell "dconf read /org/$\{XDG_CURRENT_DESKTOP,,}/desktop/interface/gtk-theme" To sTheme
  8. Label1.Text = RTrim(sTheme)
  9. If Label1.text = "" Then Label1.text = "Failed to read Theme name"
  10.  
  11.  
Online now: No Back to the top

Post

Posted
Rating:
#12
Regular
Doctor Watson is in the usergroup ‘Regular’
Hi Bruce,
I added System.Shell = System,.Find("bash")
and got an error Unexpected ‘,’
Removed the offending naughty ‘,’ and it runs fine.
BUT … result is still an empty string.

 Old african saying:
You eat an elephant one small bite at a time.
Online now: No Back to the top

Post

Posted
Rating:
#13
Avatar
Regular
stevedee is in the usergroup ‘Regular’

Doctor Watson said

I see that that there’s a lot of activity regarding my question. Thanks for that, but this surpasses my humble Gambas programming knowledge.

Don't worry about it Doc, sometimes forum Threads/Topics take on a life of their own, even though the original poster may have moved on.

Steve, I tried the gsettings and they work fine but then, what can I do with it?

Well, probably not a lot. What you need is some universal way of determining the current selected theme on any Linux system. The gsettings commands may work on your system but they don't work on either my Peppermint or Lubuntu systems.

GSettings is a Linux system configuration interface which is supposed to work with back-end systems like dconf. But I really have very little understanding of how various Linux distributions use or work with these tools.
Online now: No Back to the top

Post

Posted
Rating:
#14
Guru
BruceSteers is in the usergroup ‘Guru’
 Right well I'm changing my reply to…

NO you cannot get the theme name easily.
Online now: No Back to the top

Post

Posted
Rating:
#15
Avatar
Enthusiast
PJBlack is in the usergroup ‘Enthusiast’
 im not really following that discussion … but may this is helpfull?

Attachment
Online now: No Back to the top

Post

Posted
Rating:
#16
Regular
Doctor Watson is in the usergroup ‘Regular’
 No, it doesn’t seem to be something straightforward, if even experienced gurus are left struggling with it .
Anyway, this goes way beyond my current programming capabilities.
I’m going to try to get my project running first, the embellishments can wait for the time being.
Bruce & Steve, many thanks for your time and effort.
PJBlack, I’ll have a look ASAP.

 Old african saying:
You eat an elephant one small bite at a time.
Online now: No Back to the top

Post

Posted
Rating:
#17
Guru
BruceSteers is in the usergroup ‘Guru’

Doctor Watson said

No, it doesn’t seem to be something straightforward, if even experienced gurus are left struggling with it .
Anyway, this goes way beyond my current programming capabilities.
I’m going to try to get my project running first, the embellishments can wait for the time being.
Bruce & Steve, many thanks for your time and effort.
PJBlack, I’ll have a look ASAP.

Like we tried to say dude , it's actually easier to make your own borders :)
there are so many different linux versions all running different ways, the main ones seem to keep to the standards but others do not and thus makes it impossible to get the info you want.

Steve: if you open the gambas system info page does it report the correct theme there?
I'm pretty sure even gambas gets it wrong in some cases.

On a lot of my systems gambas cannot seem to use the right icon theme. even if set gnome icon theme in my system settings and gambas settings, Fedora, Suse and others all do not display it.

But you can look at it this way , If Steve wants Peppermint that's a bit rubbish at following the standards then so be it, no standard borders for him ;)

there are various controls in the gb.gui.base component that are all hand written unlike the gb.form components that rely on the toolkit themes.

GridView for example ,
the gridview offers much more border configurability and should also hold more to your border settings despite the gui toolkit in use as it's hand made and not a toolkit control.
Online now: No Back to the top

Post

Posted
Rating:
#18
Avatar
Regular
stevedee is in the usergroup ‘Regular’

BruceSteers said

…If Steve wants Peppermint that's a bit rubbish at following the standards then so be it, no standard borders for him ;)
…Jeux sans frontières

Steve: if you open the gambas system info page does it report the correct theme there?

[System]
Gambas=3.15.2
OperatingSystem=Linux
Kernel=5.4.0-66-generic
Architecture=x86_64
Distribution=Peppermint 10 Ten
Desktop=LXDE
Theme=gtk
Language=en_GB.UTF-8
Memory=15258M

[Libraries]
Cairo=libcairo.so.2.11510.0
Curl=libcurl.so.4.5.0
DBus=libdbus-1.so.3.19.4
GDK2=libgdk-x11-2.0.so.0.2400.32
GDK3=libgdk-3.so.0.2200.30
GStreamer=libgstreamer-1.0.so.0.1405.0
GTK+2=libgtk-x11-2.0.so.0.2400.32
GTK+3=libgtk-3.so.0.2200.30
OpenGL=libGL.so.1.0.0
Poppler=libpoppler.so.73.0.0
Poppler=libpoppler.so.90.0.0
QT4=libQtCore.so.4.8.7
QT5=libQt5Core.so.5.9.5
SDL=libSDL-1.2.so.0.11.4
SQLite=libsqlite3.so.0.8.6

[Environment]
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
DEFAULTS_PATH=/usr/share/gconf/Peppermint.default.path
DESKTOP_SESSION=Peppermint
DISPLAY=:0.0
GB_GUI=gb.qt5
GDMSESSION=Peppermint
GDM_LANG=en_GB
GPG_AGENT_INFO=/run/user/1000/gnupg/S.gpg-agent:0:1
HOME=<home>
LANG=en_GB.UTF-8
LANGUAGE=en_GB.UTF-8
LC_ALL=en_GB.UTF-8
LOGNAME=<user>
MANDATORY_PATH=/usr/share/gconf/Peppermint.mandatory.path
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
PWD=<home>
QT_ACCESSIBILITY=1
QT_LOGGING_RULES=*.debug=false
QT_QPA_PLATFORMTHEME=gtk2
SHELL=/bin/bash
SHLVL=0
SSH_AGENT_PID=1143
SSH_AUTH_SOCK=/tmp/ssh-NTAk1Sfnxb0B/agent.1061
TZ=:/etc/localtime
USER=<user>
XAUTHORITY=<home>/.Xauthority
XDG_CONFIG_DIRS=/etc/xdg/peppermint:/etc/xdg
XDG_CONFIG_HOME=<home>/.config
XDG_CURRENT_DESKTOP=LXDE
XDG_DATA_DIRS=/etc/xdg/peppermint:/usr/local/share:/usr/share:/usr/share/gdm:/var/lib/menu-xdg
XDG_GREETER_DATA_DIR=/var/lib/lightdm-data/<user>
XDG_MENU_PREFIX=xfce-
XDG_RUNTIME_DIR=/run/user/1000
XDG_SEAT=seat0
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
XDG_SESSION_DESKTOP=Peppermint
XDG_SESSION_ID=c2
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0
XDG_SESSION_TYPE=x11
XDG_VTNR=7
_LXSESSION_PID=1061
Online now: No Back to the top

Post

Posted
Rating:
#19
Guru
BruceSteers is in the usergroup ‘Guru’

Steve said

[System]
Gambas=3.15.2
OperatingSystem=Linux
Kernel=5.4.0-66-generic
Architecture=x86_64
Distribution=Peppermint 10 Ten
Desktop=LXDE
Theme=gtk
Language=en_GB.UTF-8
Memory=15258M

See on mint for me…
Theme=clearlooks

There is no easy way.
Online now: No Back to the top
1 guest and 0 members have just viewed this.