Browse Source

Added mechanism to hide words that you don't want to see.

cache_money
Raphael Roberts 7 years ago
parent
commit
3a2a9b61b3
  1. 46
      main.py

46
main.py

@ -26,6 +26,24 @@ letter_set_manage.add_argument("letter", nargs="+")
guessing = argparse.ArgumentParser()
guessing.add_argument("pattern", help="Pattern to match")
hide_exclude = argparse.ArgumentParser()
commands = hide_exclude.add_mutually_exclusive_group()
commands.add_argument(
"-e",
"--edit",
help="Change which words will be hidden from view",
action="store_true",
)
commands.add_argument(
"-c", "--commit", help="Move excluded words to be hidden words", action="store_true"
)
commands.add_argument(
"-s",
"--show",
help="Show which words are in the current exclude list",
action="store_true",
)
class MainLoop(cmd2.Cmd):
"""Loop for wordscape commands
@ -37,6 +55,7 @@ class MainLoop(cmd2.Cmd):
def __init__(self):
self.dict = "default"
self.excludes = set()
self.hidden = set()
self.init_letters(input("Enter letters: "))
super().__init__()
@ -74,7 +93,7 @@ class MainLoop(cmd2.Cmd):
"""Find words that match a pattern"""
pattern = re.compile(args.pattern + "$")
matching_words = filter_possibilities(self.candidates, pattern)
app = RemoveWordsActivity(matching_words, self.excludes)
app = RemoveWordsActivity(matching_words - self.hidden, self.excludes)
if os.name == "nt":
app.run(fork=False)
else:
@ -83,6 +102,31 @@ class MainLoop(cmd2.Cmd):
if not was_canceled:
self.excludes.update(new_exludes)
@cmd2.with_argparser(hide_exclude)
def do_hide(self, args):
"""Hide words that are in the exclude list"""
if args.show:
print("\n".join(sorted(self.excludes)))
return
if args.commit:
self.hidden.update(self.excludes)
self.excludes = set()
return
if args.edit:
app = RemoveWordsActivity(self.excludes, self.hidden)
if os.name == "nt":
app.run(fork=False)
else:
app.run()
was_canceled, results = app.get_results()
if not was_canceled:
result_set = set(results)
self.excludes = self.hidden - result_set
self.hidden = result_set
return
if __name__ == "__main__":
MainLoop().cmdloop()
Loading…
Cancel
Save