-
Notifications
You must be signed in to change notification settings - Fork 307
Feature/kanji commands #680
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
base: master
Are you sure you want to change the base?
Conversation
|
Marking as draft until being able to build docs locally |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #680 +/- ##
==========================================
+ Coverage 81.29% 81.71% +0.41%
==========================================
Files 21 21
Lines 1679 1761 +82
Branches 262 275 +13
==========================================
+ Hits 1365 1439 +74
- Misses 234 240 +6
- Partials 80 82 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
patkan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for this change request. This looks good to me and I will merge it, I just have some small remarks. Please go through them and accept or comment depending on if you think it fits.
examples/kanji.py
Outdated
| p._enter_kanji_mode() | ||
| p._raw(b"\x77\x7e") | ||
| p._exit_kanji_mode() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I understand this feature correctly, this sequence is used to write the user defined kanji? In this case I would propose an API function such as write_user_defined_kanji(string) in order to write the kanji and prevent forcing users to use the "internal" functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. That seems to be a better way to go. I'll implement them but the input will be hex value.
In some encoding system, some code points are left undefined, and in this example we're writing a new glyph to one of those code point. The undefined zone differs by both encoding and maybe printers, so basically user need to input hex value of code point manually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, a hex value is better for the code point (and aligns with the rest of the code that you wrote).
| self._raw(encoded_text) | ||
| self._exit_kanji_mode() | ||
|
|
||
| def _iso2022jp_text(self, text: str) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now this could be kept in escpos.py, but if this functionality grows more, we should think about a separate module (like magicencode)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| def _iso2022jp_text(self, text: str) -> None: | |
| def _iso2022jp_text(self, text: str) -> None: |
Please annotate a return type None for completeness.
| :param code: Encoding. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| :param code: Encoding. | |
| .. todo:: Test the encodings marked above with `FIXME` with a real device. |
Please add a short todo for the FIXME above so that it shows up in this list: https://python-escpos--680.org.readthedocs.build/en/680/dev/todo.html
| self._raw(BUZZER + six.int2byte(times) + six.int2byte(duration)) | ||
|
|
||
| def _enter_kanji_mode(self): | ||
| """Enter Kanji mode.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| """Enter Kanji mode.""" | |
| def _enter_kanji_mode(self) -> None: |
Please annotate a return type None for completeness.
| self._raw(KANJI_ENTER_KANJI_MODE) | ||
|
|
||
| def _exit_kanji_mode(self): | ||
| """Exit Kanji mode.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| """Exit Kanji mode.""" | |
| def _exit_kanji_mode(self) -> None: |
Please annotate a return type None for completeness.
| "gb18030", # FIXME test with real device, | ||
| ], | ||
| ): | ||
| """Select the Kanji encoding. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please annotate a return type None for completeness.
| left_spacing: int, | ||
| right_spacing: int, | ||
| ): | ||
| """Set the Kanji spacing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| """Set the Kanji spacing. | |
| ) -> None: |
Please annotate a return type None for completeness.
| self, | ||
| enable: bool, | ||
| ): | ||
| """Set the Kanji quadruple size. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| """Set the Kanji quadruple size. | |
| ) -> None: |
Please annotate a return type None for completeness.
| self, | ||
| font: Literal[0, 1, 2], | ||
| ): | ||
| """Set the Kanji font. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| """Set the Kanji font. | |
| ) -> None: |
Please annotate a return type None for completeness.
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| def test_kanji_text_without_encoding() -> None: | |
| """Test behavior when no encoding is set.""" | |
| instance = printer.Dummy() | |
| with pytest.raises(ValueError): | |
| instance.kanji_text("Hello世界Hello") | |
Please test also the negative case when no encoding is set.
|
I am sorry, somehow my suggestions moved to the wrong lines 😢 |
Description
This PR adds Kanji-related feature.
Tested with
Note