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

make printer.out more flexible #909

Merged
merged 9 commits into from
Aug 3, 2021

Conversation

synkarius
Copy link
Collaborator

@synkarius synkarius commented Aug 3, 2021

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

Hud PR #773

Motivation and Context

See description.

How Has This Been Tested

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

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue or bug)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Renamed existing command phrases (we discourage this without a strong rationale).

Checklist

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • I have checked that my code does not duplicate functionality elsewhere in Caster.
  • I have checked for and utilized existing command phrases from within Caster (delete if not applicable).
  • My code implements all the features I wish to merge in this pull request.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests pass.

Maintainer/Reviewer Checklist

  • Basic functionality has been tested and works as claimed.
  • New documentation is clear and complete.
  • Code is clear and readable.

@LexiconCode
Copy link
Member

LexiconCode commented Aug 3, 2021

One last issue referring back to the comment with get_current_engine with DNS

Error loading _caster from D:\Backup\Library\Documents\Caster\_caster.py
Traceback (most recent call last):
  File "c:\users\main\appdata\local\programs\python\python38-32\lib\site-packages\natlinkcore\natlinkmain.py", line 386, in loadFile
    imp.load_module(modName,fndFile,fndName,fndDesc)
  File "C:\Users\Main\AppData\Local\Programs\Python\Python38-32\Lib\imp.py", line 234, in load_module
    return load_source(name, filename, file)
  File "C:\Users\Main\AppData\Local\Programs\Python\Python38-32\Lib\imp.py", line 171, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 702, in _load
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "D:\Backup\Library\Documents\Caster\_caster.py", line 17, in <module>
    settings.initialize()
  File "D:\Backup\Library\Documents\Caster\castervoice\lib\settings.py", line 512, in initialize
    dh.start()
  File "D:\Backup\Library\Documents\Caster\castervoice\lib\printer.py", line 32, in start
    self._timer = get_current_engine() \
AttributeError: 'NoneType' object has no attribute 'create_timer'

I will fix post-merge as discussed in Chat

@LexiconCode LexiconCode merged commit 0308f18 into dictation-toolbox:master Aug 3, 2021
@synkarius synkarius deleted the printer_out branch August 3, 2021 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants