Retrieve a Theme's name ?
Posted
#1
(In Topic #601)
Regular

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.
You eat an elephant one small bite at a time.
Posted
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.
Posted
Guru

dconf read /org/$XDG_SESSION_DESKTOP/desktop/interface/gtk-theme
(cannot test it on peppermint)
or in gambas that would be…
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
Posted
Guru

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.
Posted
Enthusiast

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:~$
Posted
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?
Posted
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:~$
Posted
Regular

I got this:-
…which is the wrong theme.
Posted
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?
surely one of the known methods has to return the right theme ?
(I've just downloaded peppermint , gonna try it out)
Posted
Regular

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.
Posted
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)
- sTheme = "this should be replaced with the Theme's name"
Posted
Regular

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.
You eat an elephant one small bite at a time.
Posted
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.
Posted
Guru

NO you cannot get the theme name easily.
Posted
Enthusiast

Posted
Regular

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.
You eat an elephant one small bite at a time.
Posted
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.
Posted
Regular

…Jeux sans frontièresBruceSteers said
…If Steve wants Peppermint that's a bit rubbish at following the standards then so be it, no standard borders for him
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
Posted
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.
1 guest and 0 members have just viewed this.



