|
|
|
@ -1,8 +1,13 @@ |
|
|
|
import argparse |
|
|
|
from string import ascii_lowercase |
|
|
|
import cmd2 |
|
|
|
import re |
|
|
|
import os |
|
|
|
|
|
|
|
from candidates import candidates, filter_possibilities |
|
|
|
from dictionary import DEFAULT, ALTERNATE |
|
|
|
from word_remove_dialog import RemoveWordsActivity |
|
|
|
|
|
|
|
|
|
|
|
LOWERCASE = set(ascii_lowercase) |
|
|
|
DICTS = {"default": DEFAULT, "alt": ALTERNATE} |
|
|
|
@ -15,7 +20,10 @@ commands.add_argument( |
|
|
|
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("letter", nargs="+") |
|
|
|
|
|
|
|
guessing = argparse.ArgumentParser() |
|
|
|
guessing.add_argument("pattern", help="Pattern to match") |
|
|
|
|
|
|
|
|
|
|
|
class MainLoop(cmd2.Cmd): |
|
|
|
@ -23,14 +31,22 @@ class MainLoop(cmd2.Cmd): |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
prompt = "?$ " |
|
|
|
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.excludes = set() |
|
|
|
self.init_letters(input("Enter letters: ")) |
|
|
|
super().__init__() |
|
|
|
|
|
|
|
def init_letters(self, letters): |
|
|
|
if not isinstance(letters, str): |
|
|
|
letters = "".join(letters) |
|
|
|
letters = letters.lower() |
|
|
|
self.letters = [l for l in letters if l in LOWERCASE] |
|
|
|
self.prompt = MainLoop.prompt.format(", ".join(self.letters)) |
|
|
|
self.candidates = candidates(self.letters, DICTS[self.dict], self.excludes) |
|
|
|
|
|
|
|
@cmd2.with_argparser(dictionary_manage_parser) |
|
|
|
def do_dict(self, args): |
|
|
|
"""list/switch dict""" |
|
|
|
@ -49,7 +65,22 @@ class MainLoop(cmd2.Cmd): |
|
|
|
|
|
|
|
@cmd2.with_argparser(letter_set_manage) |
|
|
|
def do_change_letters(self, args): |
|
|
|
pass |
|
|
|
"""Change the letters on the board""" |
|
|
|
self.init_letters(args.letter) |
|
|
|
|
|
|
|
@cmd2.with_argparser(guessing) |
|
|
|
def do_find(self, args): |
|
|
|
"""Find words that match a pattern""" |
|
|
|
pattern = re.compile(args.pattern + "$") |
|
|
|
matching_words = filter_possibilities(self.candidates, pattern) |
|
|
|
app = RemoveWordsActivity(matching_words, self.excludes) |
|
|
|
if os.name == "nt": |
|
|
|
app.run(fork=False) |
|
|
|
else: |
|
|
|
app.run() |
|
|
|
was_canceled, new_exludes = app.get_results() |
|
|
|
if not was_canceled: |
|
|
|
self.excludes.update(new_exludes) |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
|