From be362973f3ff9f64a130332b565b2258f34730db Mon Sep 17 00:00:00 2001 From: Hemish Date: Tue, 4 May 2021 00:15:12 +0530 Subject: [PATCH] Code refinements and added budgie support --- README.md | 9 ++-- .../desktop_linux_themer.desktop | 2 +- desktop_linux_themer/desktop_linux_themer.py | 2 + .../lib_desktop_linux_themer.py | 50 +++++++++++++++---- 4 files changed, 47 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 09f5551..ae01aa5 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ Desktop Linux Themer is intended to be used by beginners on Linux to theme their # Installation The following steps should be followed for downloading: - Make sure that you are using a desktop environment listed here: -GNOME, XFCE, Cinnamon -If you are on vanilla Ubuntu, Xubuntu, Linux Mint Cinnamon, Linux Mint XFCE, Zorin OS, Zorin OS Lite, vanilla Fedora, Fedora XFCE spin, Fedora Cinnamon spin, vanilla RHEL, Manjaro XFCE, Manjaro GNOME, Manjaro Cinnamon or any other distro using this desktop environment, you are good to go. +GNOME, XFCE, Cinnamon, Budgie +If you are on vanilla Ubuntu, Ubuntu-Budgie, Xubuntu, Linux Mint Cinnamon, Linux Mint XFCE, Zorin OS, Zorin OS Lite, vanilla Fedora, Fedora XFCE spin, Fedora Cinnamon spin, vanilla RHEL, Manjaro XFCE, Manjaro GNOME, Manjaro Cinnamon, Manjaro Budgie or any other distro using this desktop environment, you are good to go. - Make sure that you have Python 3 installed on your system. (Most GNU/Linux distros have python3 preinstalled.) To check if it is installed or not, simply open Terminal and type "python3" (without quotes) and press Enter. If you see a message that the command was not found or something wrong happened, it means that if you don't have Python3 installed. If you see something like this: ```bash @@ -22,13 +22,14 @@ If on Ubuntu or Debian or distros based on these two: open terminal and type "su If on Fedora or Red Hat Enterprise Linux or distros based on these: open terminal and type "sudo dnf install tk tcl python3-tk python3-pip -y" (without quotes) and press enter and put in your account password and wait for the installation to complete. If on Arch Linux or Manjaro or Garuda or distros based on Arch: open terminal and type "sudo pacman -S tk tcl python3-tk python3-pip -y" (without quotes) and press enter and put in your account password and wait for the installation to complete. - Then in terminal, (for all distros) type "sudo pip install pysimplegui" (without quotes) and type in your account password and wait for the installation to complete. -- Download the latest installer script from release page: https://github.com/hemish04082005/desktop_linux_themer/releases/ and open terminal and navigate to folder containing the downloaded script using "cd" command and then type "sudo ./installer.sh" (without quotes) and put in your account password and wait for the installation to succeeed. Finally, you have installed it! -- Additional step for GNOME users: Make sure that user-theme extension is installed through https://extensions.gnome.org/extension/19/user-themes/ and enabled too. +- Download the latest installer script by clicking this link: https://github.com/hemish04082005/desktop_linux_themer/releases/latest/download/installer.sh and open terminal and navigate to folder containing the downloaded script using "cd" command and then type "sudo ./installer.sh" (without quotes). If you get an error claiming "Command not found", type this in terminal "chmod +x installer.sh" (without quotest). Then, put in your account password and wait for the installation to succeeed. Finally, you have installed it! +- Additional step for GNOME and Budgie users: Make sure that user-theme extension is installed through https://extensions.gnome.org/extension/19/user-themes/ and enabled too. # Usage: Use applications menu/whisker menu/start menu/gnome app drawer or anything like start menu on your desktop and search for "Desktop Linux Themer" and launch the application. Then use it to switch GTK, Window Manager, Desktop, Icons, Cursors theme through drop down menus and buttons provided. # To do: +- add lxde desktop support - provide mechanism for downloading and installing popular themes within the application - make installation simple \ No newline at end of file diff --git a/desktop_linux_themer/desktop_linux_themer.desktop b/desktop_linux_themer/desktop_linux_themer.desktop index 1539331..b348478 100755 --- a/desktop_linux_themer/desktop_linux_themer.desktop +++ b/desktop_linux_themer/desktop_linux_themer.desktop @@ -2,7 +2,7 @@ Version=1.1 Type=Application Name=Desktop Linux Themer -Comment=Theme GNOME, Cinnamon and XFCE +Comment=Theme GNOME, Cinnamon, Budgie and XFCE Icon=preferences-desktop-theme Exec=/usr/bin/env python3 /usr/bin/desktop_linux_themer.py Actions= diff --git a/desktop_linux_themer/desktop_linux_themer.py b/desktop_linux_themer/desktop_linux_themer.py index 36cd201..ac28536 100755 --- a/desktop_linux_themer/desktop_linux_themer.py +++ b/desktop_linux_themer/desktop_linux_themer.py @@ -13,6 +13,8 @@ ] if themerobj.memCurrentSession in themerobj.XFCEsessions: # Beacuse we dont have desktop themes in xfce, xfce interface is guided by gtk. Layout.pop(3) +if themerobj.memCurrentSession in themerobj.GNOMEsessions or themerobj.memCurrentSession in themerobj.BudgieSessions: # Budgie and GNOME don't respect window manager theme and rely on GTK for window manager + Layout.pop(2) Window = sg.Window("Linux Themer", Layout) while True: event, values = Window.read() diff --git a/desktop_linux_themer/lib_desktop_linux_themer.py b/desktop_linux_themer/lib_desktop_linux_themer.py index 76c1109..254999b 100755 --- a/desktop_linux_themer/lib_desktop_linux_themer.py +++ b/desktop_linux_themer/lib_desktop_linux_themer.py @@ -22,8 +22,9 @@ def sanitiseString(suppliedArg): return temp # To do: -# chech gnome user themes extension and enable it +# check gnome user themes extension and enable it # if the user is root, then instead of /root use /usr/share/themes and usr/share/icons +# Add support for lxde class themer(object): @@ -32,9 +33,10 @@ class themer(object): XFCEsessions = ["Xubuntu", "XFCE", "xfce", "Xfce"] GNOMEsessions = ["Ubuntu", "Ubuntu on Wayland", "Ubuntu on Xorg", "GNOME", "GNOME on Wayland", "GNOME on Xorg", "gnome", "Gnome"] CinnamonSessions = ["Cinnamon", "Cinnnamon (Software Rendering)", "cinnamon", "CINNAMON", "X-Cinnamon"] + BudgieSessions = ["Budgie", "Budgie:GNOME"] - def confPath(self, arg): - return str(os.path.join(self.confPathRoot, (arg+".conf"))) + # def confPath(self, arg): + # return str(os.path.join(self.confPathRoot, (arg+".conf"))) @staticmethod def createDirIfNotExists(path): @@ -107,7 +109,7 @@ def checkXfceCompatibility(self, path): # Xfce compatibility means xfwm themes def checkGtkCompatibility(self, path): return self.checkThemeCompatibility(path)["gtk"] - def checkMetacityCompatibility(self, path): # metacity is primarily for gnome and cinnamon + def checkMetacityCompatibility(self, path): # metacity is primarily for cinnamon return self.checkThemeCompatibility(path)["metacity"] def update(self): @@ -152,7 +154,7 @@ def update(self): if value in anothertemplist: self.WMthemes[key] = str(value) - if self.memCurrentSession in self.CinnamonSessions or self.memCurrentSession in self.GNOMEsessions: + if self.memCurrentSession in self.CinnamonSessions: templist = list(self.memThemes.values()) anothertemplist = list(filter(self.checkMetacityCompatibility, templist)) for key, value in self.memThemes.items(): @@ -173,6 +175,12 @@ def update(self): for key, value in self.memThemes.items(): if value in anothertemplist: self.desktopThemes[key] = str(value) + if self.memCurrentSession in self.BudgieSessions: # Budgie's themeing works the same as GNOME + templist = list(self.memThemes.values()) + anothertemplist = list(filter(self.checkGnomeCompatibility, templist)) + for key, value in self.memThemes.items(): + if value in anothertemplist: + self.desktopThemes[key] = str(value) # --------------------------- # ----- Icons -------- @@ -197,6 +205,8 @@ def getCurrentIconTheme(self): self.update() if (self.memCurrentSession in self.GNOMEsessions) == True: tempTheme = os.popen("gsettings get org.gnome.desktop.interface icon-theme").readline().rstrip() + elif (self.memCurrentSession in self.BudgieSessions) == True: # same as gnome + tempTheme = os.popen("gsettings get org.gnome.desktop.interface icon-theme").readline().rstrip() elif (self.memCurrentSession in self.XFCEsessions) == True: tempTheme = str(os.popen("xfconf-query -lvc xsettings -p /Net/IconThemeName").readline().rstrip()).split("Name ")[1] elif (self.memCurrentSession in self.CinnamonSessions) == True: @@ -209,6 +219,8 @@ def getCurrentGtkTheme(self): self.update() if (self.memCurrentSession in self.GNOMEsessions) == True: tempTheme = os.popen("gsettings get org.gnome.desktop.interface gtk-theme").readline().rstrip() + elif (self.memCurrentSession in self.BudgieSessions) == True: + tempTheme = os.popen("gsettings get org.gnome.desktop.interface gtk-theme").readline().rstrip() #same as gnome elif (self.memCurrentSession in self.XFCEsessions) == True: tempTheme = str(os.popen("xfconf-query -lvc xsettings -p /Net/ThemeName").readline().rstrip()).split("Name ")[1] elif (self.memCurrentSession in self.CinnamonSessions) == True: @@ -221,6 +233,8 @@ def getCurrentWMtheme(self): self.update() if (self.memCurrentSession in self.GNOMEsessions) == True: tempTheme = os.popen("gsettings get org.gnome.desktop.wm.preferences theme").readline().rstrip() + elif (self.memCurrentSession in self.BudgieSessions) == True: # same as gnome + tempTheme = os.popen("gsettings get org.gnome.desktop.wm.preferences theme").readline().rstrip() elif (self.memCurrentSession in self.XFCEsessions) == True: tempTheme = str(os.popen("xfconf-query -lvc xfwm4 -p /general/theme").readline().rstrip()).split("/theme ")[1] elif (self.memCurrentSession in self.CinnamonSessions) == True: @@ -233,6 +247,8 @@ def getCurrentCursorTheme(self): self.update() if (self.memCurrentSession in self.GNOMEsessions) == True: tempTheme = os.popen("gsettings get org.gnome.desktop.interface cursor-theme").readline().rstrip() + elif (self.memCurrentSession in self.BudgieSessions) == True: #same as gnome + tempTheme = os.popen("gsettings get org.gnome.desktop.interface cursor-theme").readline().rstrip() elif (self.memCurrentSession in self.XFCEsessions) == True: tempTheme = str(os.popen("xfconf-query -lvc xsettings -p /Gtk/CursorThemeName").readline().rstrip()).split("Name ")[1] elif (self.memCurrentSession in self.CinnamonSessions) == True: @@ -245,6 +261,8 @@ def getCurrentDesktopTheme(self): self.update() if (self.memCurrentSession in self.GNOMEsessions) == True: tempTheme = os.popen("gsettings get org.gnome.shell.extensions.user-theme name").readline().rstrip() + elif (self.memCurrentSession in self.BudgieSessions) == True: # same as gnome + tempTheme = os.popen("gsettings get org.gnome.shell.extensions.user-theme name").readline().rstrip() elif (self.memCurrentSession in self.XFCEsessions) == True: return self.getCurrentGtkTheme() # XFCE does not have any desktop theme of its own and everything including panel depend on gtk theme elif (self.memCurrentSession in self.CinnamonSessions) == True: @@ -256,6 +274,8 @@ def getCurrentDesktopTheme(self): def changeGtkTheme(self, suppliedArg): if self.memCurrentSession in self.GNOMEsessions: stream = os.popen("gsettings set org.gnome.desktop.interface gtk-theme '{}'".format(suppliedArg)) + elif self.memCurrentSession in self.BudgieSessions: # same as gnome + stream = os.popen("gsettings set org.gnome.desktop.interface gtk-theme '{}'".format(suppliedArg)) elif self.memCurrentSession in self.XFCEsessions: stream = os.popen("xfconf-query -c xsettings -p /Net/ThemeName -s '{}'".format(suppliedArg)) elif self.memCurrentSession in self.CinnamonSessions: @@ -267,6 +287,8 @@ def changeGtkTheme(self, suppliedArg): def changeIconTheme(self, suppliedArg): if self.memCurrentSession in self.GNOMEsessions: stream = os.popen("gsettings set org.gnome.desktop.interface icon-theme '{}'".format(suppliedArg)) + elif self.memCurrentSession in self.BudgieSessions: # same as gnome + stream = os.popen("gsettings set org.gnome.desktop.interface icon-theme '{}'".format(suppliedArg)) elif self.memCurrentSession in self.XFCEsessions: stream = os.popen("xfconf-query -c xsettings -p /Net/IconThemeName -s '{}'".format(suppliedArg)) elif self.memCurrentSession in self.CinnamonSessions: @@ -278,6 +300,8 @@ def changeIconTheme(self, suppliedArg): def changeWMtheme(self, suppliedArg): if self.memCurrentSession in self.GNOMEsessions: stream = os.popen("gsettings set org.gnome.desktop.wm.preferences theme '{}'".format(suppliedArg)) + elif self.memCurrentSession in self.BudgieSessions: #same as gnome + stream = os.popen("gsettings set org.gnome.desktop.wm.preferences theme '{}'".format(suppliedArg)) elif self.memCurrentSession in self.XFCEsessions: stream = os.popen("xfconf-query -c xfwm4 -p /general/theme -s '{}'".format(suppliedArg)) elif self.memCurrentSession in self.CinnamonSessions: @@ -289,6 +313,8 @@ def changeWMtheme(self, suppliedArg): def changeCursorTheme(self, suppliedArg): if self.memCurrentSession in self.GNOMEsessions: stream = os.popen("gsettings set org.gnome.desktop.interface cursor-theme '{}'".format(suppliedArg)) + elif self.memCurrentSession in self.BudgieSessions: # same as gnome + stream = os.popen("gsettings set org.gnome.desktop.interface cursor-theme '{}'".format(suppliedArg)) elif self.memCurrentSession in self.XFCEsessions: stream = os.popen("xfconf-query -c xsettings -p /Gtk/CursorThemeName -s '{}'".format(suppliedArg)) elif self.memCurrentSession in self.CinnamonSessions: @@ -300,6 +326,8 @@ def changeCursorTheme(self, suppliedArg): def changeDesktopTheme(self, suppliedArg): if self.memCurrentSession in self.GNOMEsessions: stream = os.popen("gsettings set org.gnome.shell.extensions.user-theme name '{}'".format(suppliedArg)) + elif self.memCurrentSession in self.BudgieSessions: #same as gnome + stream = os.popen("gsettings set org.gnome.shell.extensions.user-theme name '{}'".format(suppliedArg)) elif self.memCurrentSession in self.XFCEsessions: self.changeGtkTheme(suppliedArg) # XFCE relies on GTK for desktop appearance stream = os.popen("echo dummycommand") @@ -309,12 +337,12 @@ def changeDesktopTheme(self, suppliedArg): stream = os.popen("echo notFound") stream.close() -themerobj = themer() -print(themerobj.getCurrentIconTheme()) -print(themerobj.getCurrentGtkTheme()) -print(themerobj.getCurrentWMtheme()) -print(themerobj.getCurrentCursorTheme()) -print(themerobj.getCurrentDesktopTheme()) +# themerobj = themer() +# print(themerobj.getCurrentIconTheme()) +# print(themerobj.getCurrentGtkTheme()) +# print(themerobj.getCurrentWMtheme()) +# print(themerobj.getCurrentCursorTheme()) +# print(themerobj.getCurrentDesktopTheme()) # themerobj.changeGtkTheme("WhiteSur-dark") # themerobj.changeIconTheme("ePapirus") # themerobj.changeWMtheme("WhiteSur-dark")