Browse Source

Using black as code formatter

cache_money
Raphael Roberts 7 years ago
parent
commit
c71bd6ed9b
  1. 22
      dictionary.py
  2. 34
      main.py
  3. 28
      word_remove_dialog.py

22
dictionary.py

@ -2,15 +2,16 @@ import spellchecker
import pathlib
import concurrent
from concurrent.futures import ThreadPoolExecutor
EXECUTOR = ThreadPoolExecutor()
DEFAULT = spellchecker.WordFrequency()
ALTERNATE = spellchecker.WordFrequency()
package_root = pathlib.Path(spellchecker.__file__) / '..'
english = package_root / 'resources' / 'en.json.gz'
package_root = pathlib.Path(spellchecker.__file__) / ".."
english = package_root / "resources" / "en.json.gz"
extra_words = pathlib.Path(__file__, '..', 'extra_words.txt')
extra_words = pathlib.Path(__file__, "..", "extra_words.txt")
def do_operation(bound_method, *args, **kwargs):
@ -19,10 +20,10 @@ def do_operation(bound_method, *args, **kwargs):
return obj
default_load_future = EXECUTOR.submit(
do_operation, DEFAULT.load_dictionary, english)
default_load_future = EXECUTOR.submit(do_operation, DEFAULT.load_dictionary, english)
alternate_load_future = EXECUTOR.submit(
do_operation, ALTERNATE.load_text_file, extra_words)
do_operation, ALTERNATE.load_text_file, extra_words
)
class Dictionary:
@ -40,11 +41,14 @@ class Dictionary:
"""Finds words that are in the dictionary"""
if excludes is None:
def filter_func(word): return word in self.word_frequency
def filter_func(word):
return word in self.word_frequency
else:
def filter_func(
word):
def filter_func(word):
return word not in excludes and word in self.word_frequency
return set(filter(filter_func, wordlist))

34
main.py

@ -1,46 +1,48 @@
import argparse
from string import ascii_lowercase
import cmd2
from dictionary import DEFAULT, ALTERNATE
LOWERCASE = set(ascii_lowercase)
DICTS = {
'default': DEFAULT,
'alt': ALTERNATE,
}
DICTS = {"default": DEFAULT, "alt": ALTERNATE}
# argparsers
dictionary_manage_parser = argparse.ArgumentParser()
commands = dictionary_manage_parser.add_mutually_exclusive_group()
commands.add_argument(
'-l', '--list', action='store_true', help='List available dictionaries')
commands.add_argument(
'-s', '--switch', help='Dictionary to swap to')
"-l", "--list", action="store_true", help="List available dictionaries"
)
commands.add_argument("-s", "--switch", help="Dictionary to swap to")
letter_set_manage = argparse.ArgumentParser()
letter_set_manage.add_argument('new_letters')
letter_set_manage.add_argument("new_letters")
class MainLoop(cmd2.Cmd):
"""Loop for wordscape commands
"""
prompt = "?$ "
def __init__(self):
self.dict = 'default'
self.letters = [l for l in input(
"Enter letters: ").lower() if l in LOWERCASE]
self.prompt = ', '.join(self.letters) + ' ' + MainLoop.prompt
self.dict = "default"
self.letters = [l for l in input("Enter letters: ").lower() if l in LOWERCASE]
self.prompt = ", ".join(self.letters) + " " + MainLoop.prompt
super().__init__()
@cmd2.with_argparser(dictionary_manage_parser)
def do_dict(self, args):
"""list/switch dict"""
if args.list:
print('\n'.join(
('{} {}'.format('*' if key == self.dict else ' ',
key) for key in DICTS.keys())))
print(
"\n".join(
(
"{} {}".format("*" if key == self.dict else " ", key)
for key in DICTS.keys()
)
)
)
else:
DICTS[args.switch]
self.dict = args.switch

28
word_remove_dialog.py

@ -3,7 +3,6 @@ import bisect
class RemovableMulti(npyscreen.MultiLineAction):
def actionHighlighted(self, act_on_this, keypress):
self.remove_item()
@ -30,14 +29,12 @@ class AddRemoveForm(npyscreen.ActionFormV2):
BoxedRemovableMulti,
values=sorted(self.parentApp.starting_values),
name="Words to keep",
max_height=10
max_height=10,
)
self.to_remove = self.add(
BoxedRemovableMulti, values=[], name="Words to remove",
max_height=10
BoxedRemovableMulti, values=[], name="Words to remove", max_height=10
)
self.keepers.entry_widget.register_oppisite(
self.to_remove.entry_widget)
self.keepers.entry_widget.register_oppisite(self.to_remove.entry_widget)
def on_cancel(self):
self.canceled = True
@ -55,23 +52,22 @@ class RemoveWordsActivity(npyscreen.NPSAppManaged):
self.starting_values = starting_values
def onStart(self):
self.addForm('MAIN', AddRemoveForm,
name="Exclude Words", minimum_lines=0, minimum_columns=0)
self.addForm(
"MAIN",
AddRemoveForm,
name="Exclude Words",
minimum_lines=0,
minimum_columns=0,
)
def get_results(self):
form = self.getForm('MAIN')
form = self.getForm("MAIN")
vals = form.to_remove.entry_widget.values
canceled = form.canceled
return canceled, vals
if __name__ == "__main__":
values = [
'hello',
'return',
'butt',
'fuck',
'abcdefghijklmnopqrstuvwxyz'
]
values = ["hello", "return", "butt", "fuck", "abcdefghijklmnopqrstuvwxyz"]
app = RemoveWordsActivity(values)
app.run()
Loading…
Cancel
Save