Skip to content
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

pep8 + Flake8 fixes #37

Merged
merged 5 commits into from
Dec 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
[pytest]
addopts = -rsx --exitfirst todotxt_machine/test/

[bdist_wheel]
universal=1

[pep8]
ignore=E501
max-line-length=100

[flake8]
ignore=E501
max-line-length=100
exclude=.svn,CVS,.bzr,.hg,.git,__pycache,.venv,.cache,todotxt_machine/test/*
21 changes: 16 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,24 @@
"""

from setuptools import setup, find_packages
from sys import version_info

from setuptools.command.test import test as TestCommand
import todotxt_machine
import sys

import todotxt_machine

class PyTest(TestCommand):

def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True

def run_tests(self):
# import here, cause outside the eggs aren't loaded
import pytest
errno = pytest.main(self.test_args)
sys.exit(errno)

NAME = "todotxt-machine"

Expand All @@ -50,8 +62,7 @@
packages=find_packages(exclude=["todotxt_machine/test*"]),
include_package_data=True,
entry_points={
'console_scripts':
['todotxt-machine = todotxt_machine.cli:main']
'console_scripts': ['todotxt-machine = todotxt_machine.cli:main']
},
classifiers=[
"Development Status :: 4 - Beta",
Expand All @@ -67,4 +78,4 @@
],
install_requires=['setuptools', 'docopt>=0.6.2', 'urwid>=1.2.1'],
tests_require=['pytest'],
)
cmdclass={'test': PyTest})
1 change: 0 additions & 1 deletion todotxt-machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
import todotxt_machine.cli

todotxt_machine.cli.main()

45 changes: 23 additions & 22 deletions todotxt_machine/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
import random
import threading
from collections import OrderedDict
from time import sleep
from docopt import docopt

# import ipdb; # ipdb.set_trace()
import todotxt_machine
from todotxt_machine.todo import Todos
from todotxt_machine.urwid_ui import UrwidUI
from todotxt_machine.colorscheme import ColorScheme
from todotxt_machine.keys import KeyBindings

# import pprint
# pp = pprint.PrettyPrinter(indent=4).pprint

# Import the correct version of configparser
if sys.version_info[0] >= 3:
Expand All @@ -37,16 +39,10 @@
import ConfigParser
config_parser_module = ConfigParser

from docopt import docopt

import todotxt_machine
from todotxt_machine.todo import Todos
from todotxt_machine.urwid_ui import UrwidUI
from todotxt_machine.colorscheme import ColorScheme
from todotxt_machine.keys import KeyBindings

autosave_lock = threading.Lock()


def autosave():
if not enable_autosave:
return
Expand All @@ -63,13 +59,16 @@ def autosave():
timer = threading.Timer(30.0, autosave)
timer.start()


timer = threading.Timer(30.0, autosave)


def exit_with_error(message):
sys.stderr.write(message.strip(' \n')+'\n')
sys.stderr.write(message.strip(' \n') + '\n')
print(__doc__.split('\n\n')[1])
exit(1)


def get_real_path(filename, description):
# expand enviroment variables and username, get canonical path
file_path = os.path.realpath(os.path.expanduser(os.path.expandvars(filename)))
Expand All @@ -87,6 +86,7 @@ def get_real_path(filename, description):

return file_path


def get_boolean_config_option(cfg, section, option, default=False):
value = dict(cfg.items(section)).get(option, default)
if (type(value) != bool and
Expand All @@ -98,6 +98,7 @@ def get_boolean_config_option(cfg, section, option, default=False):
value = False
return value


def main():
random.seed()

Expand All @@ -114,7 +115,7 @@ def main():
cfg.add_section('keys')

if arguments['--show-default-bindings']:
d = {k: ", ".join(v) for k,v in KeyBindings({}).key_bindings.items()}
d = {k: ", ".join(v) for k, v in KeyBindings({}).key_bindings.items()}
cfg._sections['keys'] = OrderedDict(sorted(d.items(), key=lambda t: t[0]))
cfg.write(sys.stdout)
exit(0)
Expand All @@ -123,18 +124,18 @@ def main():
cfg.read(os.path.expanduser(arguments['--config']))

# Load keybindings specified in the [keys] section of the config file
keyBindings = KeyBindings(dict( cfg.items('keys') ))
keyBindings = KeyBindings(dict(cfg.items('keys')))

# load the colorscheme defined in the user config, else load the default scheme
colorscheme = ColorScheme(dict( cfg.items('settings') ).get('colorscheme', 'default'), cfg)
colorscheme = ColorScheme(dict(cfg.items('settings')).get('colorscheme', 'default'), cfg)

# Get auto-saving setting (defaults to False)
global enable_autosave
enable_autosave = get_boolean_config_option(cfg, 'settings', 'auto-save', default=False)

# Load the todo.txt file specified in the [settings] section of the config file
# a todo.txt file on the command line takes precedence
todotxt_file = dict( cfg.items('settings') ).get('file', arguments['TODOFILE'])
todotxt_file = dict(cfg.items('settings')).get('file', arguments['TODOFILE'])
if arguments['TODOFILE']:
todotxt_file = arguments['TODOFILE']

Expand All @@ -143,11 +144,10 @@ def main():

# Load the done.txt file specified in the [settings] section of the config file
# a done.txt file on the command line takes precedence
donetxt_file = dict( cfg.items('settings') ).get('archive', arguments['DONEFILE'])
donetxt_file = dict(cfg.items('settings')).get('archive', arguments['DONEFILE'])
if arguments['DONEFILE']:
donetxt_file = arguments['DONEFILE']


todotxt_file_path = get_real_path(todotxt_file, 'todo.txt')

if donetxt_file is not None:
Expand All @@ -162,17 +162,17 @@ def main():
exit_with_error("ERROR: unable to open {0}\n\nEither specify one as an argument on the command line or set it in your configuration file ({0}).".format(todotxt_file_path, arguments['--config']))
todos = Todos([], todotxt_file_path, donetxt_file_path)

show_toolbar = get_boolean_config_option(cfg, 'settings', 'show-toolbar')
show_toolbar = get_boolean_config_option(cfg, 'settings', 'show-toolbar')
show_filter_panel = get_boolean_config_option(cfg, 'settings', 'show-filter-panel')
enable_borders = get_boolean_config_option(cfg, 'settings', 'enable-borders')
enable_word_wrap = get_boolean_config_option(cfg, 'settings', 'enable-word-wrap')
enable_borders = get_boolean_config_option(cfg, 'settings', 'enable-borders')
enable_word_wrap = get_boolean_config_option(cfg, 'settings', 'enable-word-wrap')

global view
view = UrwidUI(todos, keyBindings, colorscheme)

timer.start()

view.main( # start up the urwid UI event loop
view.main( # start up the urwid UI event loop
enable_borders,
enable_word_wrap,
show_toolbar,
Expand All @@ -191,5 +191,6 @@ def main():

exit(0)


if __name__ == '__main__':
main()
12 changes: 5 additions & 7 deletions todotxt_machine/colorscheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import ConfigParser
config_parser_module = ConfigParser


class ColorScheme:

def __init__(self, name, user_config):
Expand All @@ -27,7 +28,7 @@ def load_colors(self, name):

# Use user defined theme in the user_config if it exists
if self.user_config.has_section(colorscheme_section):
self.colors = dict( self.user_config.items(colorscheme_section) )
self.colors = dict(self.user_config.items(colorscheme_section))
else:
# Try to load a built in theme
cfg = config_parser_module.ConfigParser()
Expand All @@ -38,7 +39,7 @@ def load_colors(self, name):
cfg.read(self.built_in_colors_directory + "/default")
colorscheme_section = "colorscheme-default"
if cfg.has_section(colorscheme_section):
self.colors = dict( cfg.items(colorscheme_section) )
self.colors = dict(cfg.items(colorscheme_section))

# Split foreground and background values
for key, value in self.colors.items():
Expand All @@ -50,12 +51,9 @@ def load_colors(self, name):
# Create Selected attributes using the selected_background_color
selected_background_color = self.colors['selected']['bg']
dialog_color = self.colors['dialog_color']['bg']
# dialog_button_color = self.colors['dialog_button_color']['bg']
for key, value in list(self.colors.items()):
if key not in ['selected', 'dialog_color', 'dialog_button_color']:
self.colors[key+'_selected'] = {'fg': self.colors[key]['fg'], 'bg': selected_background_color}
self.colors[key+'_dialog_color'] = {'fg': self.colors[key]['fg'], 'bg': dialog_color}
# self.colors[key+'_dialog_button_color'] = {'fg': self.colors[key]['fg'], 'bg': dialog_button_color}
self.colors[key + '_selected'] = {'fg': self.colors[key]['fg'], 'bg': selected_background_color}
self.colors[key + '_dialog_color'] = {'fg': self.colors[key]['fg'], 'bg': dialog_color}
self.focus_map[key] = key + '_selected'
self.dialog_focus_map[key] = key + '_dialog_color'
# self.dialog_focus_map[key] = key + '_dialog_button_color'
93 changes: 46 additions & 47 deletions todotxt_machine/keys.py
Original file line number Diff line number Diff line change
@@ -1,66 +1,65 @@
class KeyBindings:
user_keys = []
user_keys = []
key_bindings = {}

def __init__(self, user_keys):
self.user_keys = user_keys
self.fillWithDefault();
self.fillWithDefault()
self.fillWithUserKeys(user_keys)

def fillWithUserKeys(self, users_keys):
for bind in users_keys:
key = self.userKeysToList(users_keys[bind])
try:
default = self.key_bindings[bind]
self.key_bindings[bind] = key
except KeyError:
print("KeyBind \""+bind+"\" not found")
print("KeyBind \"" + bind + "\" not found")

def fillWithDefault(self):
self.key_bindings['toggle-help'] = ['h', '?']
self.key_bindings['quit'] = ['q']
self.key_bindings['toggle-toolbar'] = ['t']
self.key_bindings['toggle-borders'] = ['b']
self.key_bindings['toggle-wrapping'] = ['w']
self.key_bindings['save'] = ['S']
self.key_bindings['reload'] = ['R']
self.key_bindings['down'] = ['j', 'down']
self.key_bindings['up'] = ['k', 'up']
self.key_bindings['top'] = ['g']
self.key_bindings['right'] = ['L', 'right']
self.key_bindings['left'] = ['H', 'left']
self.key_bindings['bottom'] = ['G']
self.key_bindings['change-focus'] = ['tab']
self.key_bindings['toggle-complete'] = ['x']
self.key_bindings['archive'] = ['X']
self.key_bindings['append'] = ['n']
self.key_bindings['insert-after'] = ['o']
self.key_bindings['insert-before'] = ['O']
self.key_bindings['priority-up'] = ['p']
self.key_bindings['priority-down'] = ['P']
self.key_bindings['save-item'] = ['enter']
self.key_bindings['edit'] = ['enter', 'A', 'e']
self.key_bindings['delete'] = ['D']
self.key_bindings['swap-down'] = ['J']
self.key_bindings['swap-up'] = ['K']
self.key_bindings['edit-complete'] = ['tab']
self.key_bindings['edit-save'] = ['return']
self.key_bindings['edit-move-left'] = ['left']
self.key_bindings['edit-move-right'] = ['right']
self.key_bindings['edit-word-left'] = ['meta b', 'ctrl b']
self.key_bindings['edit-word-right'] = ['meta f', 'ctrl f']
self.key_bindings['edit-end'] = ['ctrl e', 'end']
self.key_bindings['edit-home'] = ['ctrl a', 'home']
self.key_bindings['toggle-help'] = ['h', '?']
self.key_bindings['quit'] = ['q']
self.key_bindings['toggle-toolbar'] = ['t']
self.key_bindings['toggle-borders'] = ['b']
self.key_bindings['toggle-wrapping'] = ['w']
self.key_bindings['save'] = ['S']
self.key_bindings['reload'] = ['R']
self.key_bindings['down'] = ['j', 'down']
self.key_bindings['up'] = ['k', 'up']
self.key_bindings['top'] = ['g']
self.key_bindings['right'] = ['L', 'right']
self.key_bindings['left'] = ['H', 'left']
self.key_bindings['bottom'] = ['G']
self.key_bindings['change-focus'] = ['tab']
self.key_bindings['toggle-complete'] = ['x']
self.key_bindings['archive'] = ['X']
self.key_bindings['append'] = ['n']
self.key_bindings['insert-after'] = ['o']
self.key_bindings['insert-before'] = ['O']
self.key_bindings['priority-up'] = ['p']
self.key_bindings['priority-down'] = ['P']
self.key_bindings['save-item'] = ['enter']
self.key_bindings['edit'] = ['enter', 'A', 'e']
self.key_bindings['delete'] = ['D']
self.key_bindings['swap-down'] = ['J']
self.key_bindings['swap-up'] = ['K']
self.key_bindings['edit-complete'] = ['tab']
self.key_bindings['edit-save'] = ['return']
self.key_bindings['edit-move-left'] = ['left']
self.key_bindings['edit-move-right'] = ['right']
self.key_bindings['edit-word-left'] = ['meta b', 'ctrl b']
self.key_bindings['edit-word-right'] = ['meta f', 'ctrl f']
self.key_bindings['edit-end'] = ['ctrl e', 'end']
self.key_bindings['edit-home'] = ['ctrl a', 'home']
self.key_bindings['edit-delete-word'] = ['ctrl w']
self.key_bindings['edit-delete-end'] = ['ctrl k']
self.key_bindings['edit-delete-beginning'] = ['ctrl u']
self.key_bindings['edit-paste'] = ['ctrl y']
self.key_bindings['toggle-filter'] = ['f']
self.key_bindings['clear-filter'] = ['F']
self.key_bindings['toggle-sorting'] = ['s']
self.key_bindings['search'] = ['/']
self.key_bindings['search-end'] = ['enter']
self.key_bindings['search-clear'] = ['C']
self.key_bindings['edit-delete-end'] = ['ctrl k']
self.key_bindings['edit-delete-beginning'] = ['ctrl u']
self.key_bindings['edit-paste'] = ['ctrl y']
self.key_bindings['toggle-filter'] = ['f']
self.key_bindings['clear-filter'] = ['F']
self.key_bindings['toggle-sorting'] = ['s']
self.key_bindings['search'] = ['/']
self.key_bindings['search-end'] = ['enter']
self.key_bindings['search-clear'] = ['C']

def __getitem__(self, index):
return ", ".join(self.key_bindings[index])
Expand Down
Loading