-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Load COL_SCHEMEs from json files #166
base: master
Are you sure you want to change the base?
Changes from all commits
2a7ca00
83fc445
87dfa06
bdfd177
a4d4c0e
317be5e
0d30bed
c3fc84f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import sys | ||
import urwid | ||
import readlike | ||
import json | ||
|
||
import hangups | ||
from hangups.ui.notify import Notifier | ||
|
@@ -829,13 +830,48 @@ def main(): | |
default_log_path = os.path.join(dirs.user_log_dir, 'hangups.log') | ||
default_token_path = os.path.join(dirs.user_cache_dir, 'refresh_token.txt') | ||
default_config_path = os.path.join(dirs.user_config_dir, 'hangups.conf') | ||
default_colors_path = os.path.join(dirs.user_config_dir, 'colors') | ||
|
||
# Create a default empty config file if does not exist. | ||
dir_maker(default_config_path) | ||
if not os.path.isfile(default_config_path): | ||
with open(default_config_path, 'a') as cfg: | ||
cfg.write("") | ||
|
||
# Create empty colors directory if there is none | ||
dir_maker(default_colors_path) | ||
|
||
# Read .col files | ||
attributes = {'active_tab', 'inactive_tab', 'msg_date', 'msg_sender', 'msg_text', 'status_line', 'tab_background'} | ||
for root, dirs, files in os.walk(default_colors_path): | ||
for filename in files: | ||
splitName = os.path.splitext(filename) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variable names should be lowercase with underscores, eg. |
||
if splitName[1] == '.json': | ||
obj = [] | ||
usedAttrs = [] | ||
|
||
name = splitName[0] | ||
|
||
with open(os.path.join(root, filename), "r") as f: | ||
try: | ||
data = json.load(f) | ||
except: | ||
print("Error loading JSON file (" + filename + ")") | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's always better to catch a specific exceptions, and you can use except ValueError:
sys.exit('Error loading JSON file: {}'.format(filename)) |
||
for key, subdict in data.items(): | ||
retList = [key,'',''] | ||
if 'foreground' in subdict: | ||
retList[1] = subdict['foreground'] | ||
if 'background' in subdict: | ||
retList[2] = subdict['background'] | ||
usedAttrs.append(key) | ||
obj.append(tuple(retList)) | ||
|
||
for attr in (attributes - set(usedAttrs)): | ||
obj.append(tuple([attr, '', ''])) | ||
|
||
COL_SCHEMES[name] = set(obj) | ||
|
||
parser = configargparse.ArgumentParser( | ||
prog='hangups', default_config_files=[default_config_path], | ||
formatter_class=configargparse.ArgumentDefaultsHelpFormatter, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a waste to load all the colour schemes when we already know which one the user wants. Can you make it just load the file that's specified?