Skip to content

Commit

Permalink
Add function to get namebar main directory with an automated migratio…
Browse files Browse the repository at this point in the history
…n path.
  • Loading branch information
denisfa committed Nov 14, 2018
1 parent f8d8b3b commit b316119
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 18 deletions.
45 changes: 36 additions & 9 deletions dockx_applets/namebar.py
Expand Up @@ -56,6 +56,31 @@
action_unminimize = 1 << 13
action_maximize = 1 << 14

def get_namebar_homedir():
homedir = os.environ['HOME']
default = os.path.join(homedir, '.local', 'share')
appdir = os.path.join(
os.getenv('XDG_DATA_HOME', default),
'namebar'
)
"""
Migration Path
From "$HOME/.namebar" to "${XDG_DATA_HOME:-$HOME/.local/share}/namebar"
"""
old_appdir = os.path.join(homedir, '.namebar')
if os.path.exists(old_appdir) and os.path.isdir(old_appdir):
try:
os.rename(old_appdir, appdir)
except OSError:
sys.stderr.write('Could not move dir "%s" to "%s". \
Move the contents of "%s" to "%s" manually \
and then remove the first location.'
% (old_appdir, appdir, old_appdir, appdir))
"""
End Migration Path
"""
return appdir

class AboutDialog():
__instance = None

Expand Down Expand Up @@ -91,7 +116,7 @@ def __init__ (self, namebar=None):
self.dialog = gtk.Dialog("NameBar preferences")
self.dialog.connect("response",self.dialog_close)

self.namebar= namebar
self.namebar = namebar

try:
ca = self.dialog.get_content_area()
Expand Down Expand Up @@ -337,12 +362,13 @@ def color_reset(self, button, text):
GCONF_CLIENT.set_int(key, alpha)

def find_themes(self):
# Reads the themes from /usr/share/dockbarx/themes and ~/.dockbarx/themes
# Reads the themes from /usr/share/namebar/themes and
# ${XDG_DATA_HOME:-$HOME/.local/share}/namebar/themes
# and returns a dict of the theme names and paths so that
# a theme can be loaded
themes = {}
theme_paths = []
dirs = ["/usr/share/namebar/themes", "%s/.namebar/themes" % os.path.expanduser("~")]
dirs = ["/usr/share/namebar/themes", os.path.join(get_namebar_homedir(), "themes")]
for dir in dirs:
if os.path.exists(dir):
for f in os.listdir(dir):
Expand All @@ -356,10 +382,10 @@ def find_themes(self):
md = gtk.MessageDialog(None,
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE,
'No working themes found in "/usr/share/namebar/themes" or "~/.namebar/themes"')
'No working themes found in "/usr/share/namebar/themes" or "${XDG_DATA_HOME:-$HOME/.local/share}/namebar/themes"')
md.run()
md.destroy()
print 'Preference dialog error: No working themes found in "/usr/share/namebar/themes" or "~/.namebar/themes"'
print 'Preference dialog error: No working themes found in "/usr/share/namebar/themes" or "${XDG_DATA_HOME:-$HOME/.local/share}/namebar/themes"'
return themes

def change_theme(self, button=None):
Expand Down Expand Up @@ -622,12 +648,13 @@ def repack(self):
self.container.pack_end(pack_dict[item], False)

def find_themes(self):
# Reads the themes from /usr/share/dockbarx/themes and ~/.dockbarx/themes
# Reads the themes from /usr/share/namebar/themes and
# ${XDG_DATA_HOME:-$HOME/.local/share}/namebar/themes
# and returns a dict of the theme names and paths so that
# a theme can be loaded
themes = {}
theme_paths = []
dirs = ["/usr/share/namebar/themes", "%s/.namebar/themes"%os.path.expanduser("~")]
dirs = ["/usr/share/namebar/themes", os.path.join(get_namebar_homedir(), "themes")]
for dir in dirs:
if os.path.exists(dir):
for f in os.listdir(dir):
Expand All @@ -641,10 +668,10 @@ def find_themes(self):
md = gtk.MessageDialog(None,
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE,
'No working themes found in "/usr/share/namebar/themes" or "~/.namebar/themes"')
'No working themes found in "/usr/share/namebar/themes" or "${XDG_DATA_HOME:-$HOME/.local/share}/namebar/themes"')
md.run()
md.destroy()
print 'No working themes found in "/usr/share/namebar/themes" or "~/.namebar/themes"'
print 'No working themes found in "/usr/share/namebar/themes" or "${XDG_DATA_HOME:-$HOME/.local/share}/namebar/themes"'
sys.exit(1)
return themes

Expand Down
21 changes: 12 additions & 9 deletions dockx_applets/namebar_window_buttons.py
Expand Up @@ -25,6 +25,7 @@
import gconf
from tarfile import open as taropen
from dockbarx.applets import DockXApplet, DockXAppletDialog
from namebar import get_namebar_homedir

VERSION = '0.1'

Expand Down Expand Up @@ -91,7 +92,7 @@ def __init__ (self, namebar=None):
self.dialog = gtk.Dialog("WindowButtonApplet preferences")
self.dialog.connect("response",self.dialog_close)

self.namebar= namebar
self.namebar = namebar

try:
ca = self.dialog.get_content_area()
Expand Down Expand Up @@ -204,12 +205,13 @@ def set_custom_layout(self, *args):
GCONF_CLIENT.set_string("%s/custom_layout" % GCONF_DIR, text)

def find_themes(self):
# Reads the themes from /usr/share/dockbarx/themes and ~/.dockbarx/themes
# Reads the themes from /usr/share/namebar/themes and
# ${XDG_DATA_HOME:-$HOME/.local/share}/namebar/themes
# and returns a dict of the theme names and paths so that
# a theme can be loaded
themes = {}
theme_paths = []
dirs = ["/usr/share/namebar/themes", "%s/.namebar/themes" % os.path.expanduser("~")]
dirs = ["/usr/share/namebar/themes", os.path.join(get_namebar_homedir(), "themes")]
for dir in dirs:
if os.path.exists(dir):
for f in os.listdir(dir):
Expand All @@ -223,10 +225,10 @@ def find_themes(self):
md = gtk.MessageDialog(None,
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE,
'No working themes found in "/usr/share/namebar/themes" or "~/.namebar/themes"')
'No working themes found in "/usr/share/namebar/themes" or "${XDG_DATA_HOME:-$HOME/.local/share}/namebar/themes"')
md.run()
md.destroy()
print 'Preference dialog error: No working themes found in "/usr/share/namebar/themes" or "~/.namebar/themes"'
print 'Preference dialog error: No working themes found in "/usr/share/namebar/themes" or "${XDG_DATA_HOME:-$HOME/.local/share}/namebar/themes"'
return themes

def change_theme(self, button=None):
Expand Down Expand Up @@ -461,12 +463,13 @@ def repack(self):
self.container.pack_end(pack_dict[item], False)

def find_themes(self):
# Reads the themes from /usr/share/dockbarx/themes and ~/.dockbarx/themes
# Reads the themes from /usr/share/namebar/themes and
# ${XDG_DATA_HOME:-$HOME/.local/share}/namebar/themes
# and returns a dict of the theme names and paths so that
# a theme can be loaded
themes = {}
theme_paths = []
dirs = ["/usr/share/namebar/themes", "%s/.namebar/themes"%os.path.expanduser("~")]
dirs = ["/usr/share/namebar/themes", os.path.join(get_namebar_homedir(), "themes")]
for dir in dirs:
if os.path.exists(dir):
for f in os.listdir(dir):
Expand All @@ -480,10 +483,10 @@ def find_themes(self):
md = gtk.MessageDialog(None,
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE,
'No working themes found in "/usr/share/namebar/themes" or "~/.namebar/themes"')
'No working themes found in "/usr/share/namebar/themes" or "${XDG_DATA_HOME:-$HOME/.local/share}/namebar/themes"')
md.run()
md.destroy()
print 'No working themes found in "/usr/share/namebar/themes" or "~/.namebar/themes"'
print 'No working themes found in "/usr/share/namebar/themes" or "${XDG_DATA_HOME:-$HOME/.local/share}/namebar/themes"'
sys.exit(1)
return themes

Expand Down

0 comments on commit b316119

Please sign in to comment.