dictation-toolbox / Caster

Dragonfly-Based Voice Programming and Accessibility Toolkit
Other
336 stars 122 forks source link

printer.out flexibility #908

Closed synkarius closed 2 years ago

synkarius commented 2 years ago

Improve Console Output Flexibility

Description

After speaking with @LexiconCode about some upcoming changes, I suggested that he could avoid adding lots of UI code to _caster.py by making printer.py a bit more flexible. This PR is the implementation of that suggestion.

dh = printer.get_delegating_handler()
dh.register_handler(SimplePrintMessageHandler())
dh.start()

I put the above chunk of code in settings.py, but it could be moved to anywhere (anywhere that it's called only once) and it would work the same. (You don't have to worry about printer.out being called first, or import order or anything.) Switching output to the HUD would be as simple as replacing SimplePrintMessageHandler with some other implementation of BaseMessageHandler which does HUD stuff. Absolutely do not put said implementation in printer.py.

If the HUD BaseMessageHandler implementation is broken or throws errors when handling printer.out messages, those messages will be printed to the console by a default SimplePrintMessageHandler instead.

Incidentally, you can throw as many printer.out handlers at this thing as you want. It can use more than one.

Related Issue

Is there an issue for the HUD? If so, should link it here.

Motivation and Context

See description.

How Has This Been Tested

Additional unit tests + manual testing to make sure nothing was broken.

Types of changes

Checklist

Maintainer/Reviewer Checklist