Skip to content

Commit

Permalink
Refactoring. Additional themes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Xifax committed Feb 17, 2014
1 parent 771ce58 commit adaeab9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 26 deletions.
47 changes: 25 additions & 22 deletions prettify.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
#encoding: utf-8
import uuid
import ConfigParser
import os

# init paths and commands
dconf_path = '/org/gnome/terminal/legacy/profiles:'
# TODO: get dconf as env variable?
dconf = 'dconf'
dconf = os.popen('which dconf').read().strip()
dconf_write = dconf + ' write'
dconf_list = dconf + ' list'

def create_profile(theme_name):
"""Create new profile and update profile list"""
profile_id = str(uuid.uuid4())
profile_dir = dconf_path + '/:' + profile_id

# create new profile
os.system("dconf write %s/default \"'%s'\"" % (dconf_path, profile_id))
os.system("%s %s/default \"'%s'\"" % (dconf_write, dconf_path, profile_id))

# update profile list
existing_profiles = os.popen(
'dconf list /org/gnome/terminal/legacy/profiles:/'
'%s /org/gnome/terminal/legacy/profiles:/' % dconf_list
).read().split('\n')

# clean-up profile list
Expand All @@ -33,12 +36,12 @@ def create_profile(theme_name):

profiles = "','".join(existing_profiles)
os.system(
"dconf write %s/list \"['%s']\"" % (dconf_path, profiles)
"%s %s/list \"['%s']\"" % (dconf_write, dconf_path, profiles)
)

# set visible name
os.system(
"dconf write %s/visible-name \"'%s'\"" % (profile_dir, theme_name)
"%s %s/visible-name \"'%s'\"" % (dconf_write, profile_dir, theme_name)
)

return profile_id
Expand All @@ -51,34 +54,34 @@ def write_theme(theme_name, colors):
# set color palette
palette = "', '".join(colors['palette'].split(':'))
os.system(
"dconf write %s/:%s/palette \"['%s']\"" %
(dconf_path, profile_id, palette)
"%s %s/:%s/palette \"['%s']\"" %
(dconf_write, dconf_path, profile_id, palette)
)

# set foreground, background and highlight color
os.system(
"%s write %s/:%s/bold-color \"'%s'\"" %
(dconf, dconf_path, profile_id, colors['bold'])
"%s %s/:%s/bold-color \"'%s'\"" %
(dconf_write, dconf_path, profile_id, colors['bold'])
)
os.system(
"%s write %s/:%s/background-color \"'%s'\"" %
(dconf, dconf_path, profile_id, colors['background'])
"%s %s/:%s/background-color \"'%s'\"" %
(dconf_write, dconf_path, profile_id, colors['background'])
)
os.system(
"%s write %s/:%s/foreground-color \"'%s'\"" %
(dconf, dconf_path, profile_id, colors['foreground'])
"%s %s/:%s/foreground-color \"'%s'\"" %
(dconf_write, dconf_path, profile_id, colors['foreground'])
)

# make sure the profile is set to not use theme colors
os.system(
'%s write %s/:%s/use-theme-colors "false"' %
(dconf, dconf_path, profile_id)
'%s %s/:%s/use-theme-colors "false"' %
(dconf_write, dconf_path, profile_id)
)

# set highlighted color to be different from foreground color
os.system(
'%s write %s/:%s/bold-color-same-as-fg "false"' %
(dconf, dconf_path, profile_id)
'%s %s/:%s/bold-color-same-as-fg "false"' %
(dconf_write, dconf_path, profile_id)
)


Expand All @@ -89,10 +92,10 @@ def get_themes(theme_list='themes'):
config.read(theme_list)
for section in config.sections():
theme = {}
theme['palette'] = config.get(section, 'palette').strip('"')
theme['background'] = config.get(section, 'bg_color').strip('"')
theme['foreground'] = config.get(section, 'fg_color').strip('"')
theme['bold'] = config.get(section, 'bd_color').strip('"')
theme['palette'] = config.get(section, 'palette')
theme['background'] = config.get(section, 'bg_color')
theme['foreground'] = config.get(section, 'fg_color')
theme['bold'] = config.get(section, 'bd_color')
themes[section] = theme

return themes
Expand Down
16 changes: 12 additions & 4 deletions themes
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
[molokai]
palette="#1B1B1D1D1E1E:#F9F926267272:#8282B4B41414:#FDFD97971F1F:#5656C2C2D6D6:#8C8C5454FEFE:#464654545757:#CCCCCCCCC6C6:#505053535454:#FFFF59599595:#B6B6E3E35454:#FEFEEDED6C6C:#8C8CEDEDFFFF:#9E9E6F6FFEFE:#89899C9CA1A1:#F8F8F8F8F2F2"
bd_color="#000000000000"
fg_color="#A0A0A0A0A0A0"
bg_color="#1C1C1C1C1C1C"
palette=#1B1B1D1D1E1E:#F9F926267272:#8282B4B41414:#FDFD97971F1F:#5656C2C2D6D6:#8C8C5454FEFE:#464654545757:#CCCCCCCCC6C6:#505053535454:#FFFF59599595:#B6B6E3E35454:#FEFEEDED6C6C:#8C8CEDEDFFFF:#9E9E6F6FFEFE:#89899C9CA1A1:#F8F8F8F8F2F2
bd_color=#000000000000
fg_color=#A0A0A0A0A0A0
bg_color=#1C1C1C1C1C1C

[monokai]
palette=#494948483E3E:#F9F926267272:#A6A6E2E22E2E:#FDFD97971F1F:#6666D9D9EFEF:#AEAE8181FFFF:#A1A1EFEFE4E4:#F8F8F8F8F2F2:#757571715E5E:#FCFC5C5C9494:#C1C1F1F16161:#FEFEB2B25757:#8D8DE6E6F7F7:#C2C2A1A1FFFF:#BBBBF7F7EFEF:#F8F8F8F8F0F0
bd_color=#000000000000
fg_color=#F8F8F8F8F2F2
bg_color=#272728282222


0 comments on commit adaeab9

Please sign in to comment.