49
49
_DOUBLE_HEIGHT_MASK = const (1 << 4 )
50
50
_DOUBLE_WIDTH_MASK = const (1 << 5 )
51
51
_STRIKE_MASK = const (1 << 6 )
52
+
53
+ # External constants:
54
+ JUSTIFY_LEFT = const (0 )
55
+ JUSTIFY_CENTER = const (1 )
56
+ JUSTIFY_RIGHT = const (2 )
57
+ SIZE_SMALL = const (0 )
58
+ SIZE_MEDIUM = const (1 )
59
+ SIZE_LARGE = const (2 )
60
+ UNDERLINE_THIN = const (0 )
61
+ UNDERLINE_THICK = const (1 )
52
62
# pylint: enable=bad-whitespace
53
63
54
64
@@ -344,9 +354,9 @@ def set_defaults(self):
344
354
to a good state after printing different size, weight, etc. text.
345
355
"""
346
356
self .online ()
347
- self .justify_left ()
348
- self .set_size_small ()
349
- self .underline_off ()
357
+ self .justify = JUSTIFY_LEFT
358
+ self .size = SIZE_SMALL
359
+ self .underline = None
350
360
self .inverse = False
351
361
self .upside_down = False
352
362
self .double_height = False
@@ -358,50 +368,61 @@ def set_defaults(self):
358
368
self ._set_charset ()
359
369
self ._set_code_page ()
360
370
361
- def justify_left (self ):
362
- """Set left justification of text."""
363
- self .send_command ('\x1B a\x00 ' ) # ESC + 'a' + 0
364
-
365
- def justify_center (self ):
366
- """Set center justification of text."""
367
- self .send_command ('\x1B a\x01 ' ) # ESC + 'a' + 1
368
-
369
- def justify_right (self ):
370
- """Set right justification of text."""
371
- self .send_command ('\x1B a\x02 ' ) # ESC + 'a' + 2
371
+ def _set_justify (self , val ):
372
+ assert 0 <= val <= 2
373
+ if val == JUSTIFY_LEFT :
374
+ self .send_command ('\x1B a\x00 ' ) # ESC + 'a' + 0
375
+ elif val == JUSTIFY_CENTER :
376
+ self .send_command ('\x1B a\x01 ' ) # ESC + 'a' + 1
377
+ elif val == JUSTIFY_RIGHT :
378
+ self .send_command ('\x1B a\x02 ' ) # ESC + 'a' + 2
372
379
373
- def set_size_small (self ):
374
- """Set small text size."""
375
- self ._char_height = 24
376
- self ._max_column = 32
377
- self .send_command ('\x1D !\x00 ' ) # ASCII GS + '!' + 0x00
378
- self ._column = 0
379
-
380
- def set_size_medium (self ):
381
- """Set medium (double height) text size."""
382
- self ._char_height = 48
383
- self ._max_column = 32
384
- self .send_command ('\x1D !\x01 ' ) # ASCII GS + '!' + 0x01
385
- self ._column = 0
380
+ # pylint: disable=line-too-long
381
+ # Write-only property, can't assume we can read state from the printer
382
+ # since there is no command for it and hooking up RX is discouraged
383
+ # (5V will damage many boards).
384
+ justify = property (None , _set_justify , None , "Set the justification of text, must be a value of JUSTIFY_LEFT, JUSTIFY_CENTER, or JUSTIFY_RIGHT." )
385
+ # pylint: enable=line-too-long
386
386
387
- def set_size_large (self ):
388
- """Set large (double height & width) text size."""
389
- self ._char_height = 48
390
- self ._max_column = 16
391
- self .send_command ('\x1D !\x11 ' ) # ASCII GS + '!' + 0x11
387
+ def _set_size (self , val ):
388
+ assert 0 <= val <= 2
389
+ if val == SIZE_SMALL :
390
+ self ._char_height = 24
391
+ self ._max_column = 32
392
+ self .send_command ('\x1D !\x00 ' ) # ASCII GS + '!' + 0x00
393
+ elif val == SIZE_MEDIUM :
394
+ self ._char_height = 48
395
+ self ._max_column = 32
396
+ self .send_command ('\x1D !\x01 ' ) # ASCII GS + '!' + 0x01
397
+ elif val == SIZE_LARGE :
398
+ self ._char_height = 48
399
+ self ._max_column = 16
400
+ self .send_command ('\x1D !\x11 ' ) # ASCII GS + '!' + 0x11
392
401
self ._column = 0
393
402
394
- def underline_off (self ):
395
- """Turn off underline printing."""
396
- self .send_command ('\x1B -\x00 ' ) # ESC + '-' + 0
403
+ # pylint: disable=line-too-long
404
+ # Write-only property, can't assume we can read state from the printer
405
+ # since there is no command for it and hooking up RX is discouraged
406
+ # (5V will damage many boards).
407
+ size = property (None , _set_size , None , "Set the size of text, must be a value of SIZE_SMALL, SIZE_MEDIUM, or SIZE_LARGE." )
408
+ # pylint: enable=line-too-long
397
409
398
- def underline_thin (self ):
399
- """Turn on normal/thin underline printing."""
400
- self .send_command ('\x1B -\x01 ' ) # ESC + '-' + 1
410
+ def _set_underline (self , val ):
411
+ assert val is None or (0 <= val <= 1 )
412
+ if val is None :
413
+ # Turn off underline.
414
+ self .send_command ('\x1B -\x00 ' ) # ESC + '-' + 0
415
+ elif val == UNDERLINE_THIN :
416
+ self .send_command ('\x1B -\x01 ' ) # ESC + '-' + 1
417
+ elif val == UNDERLINE_THICK :
418
+ self .send_command ('\x1B -\x02 ' ) # ESC + '-' + 2
401
419
402
- def underline_thick (self ):
403
- """Turn on thick underline printing."""
404
- self .send_command ('\x1B -\x02 ' ) # ESC + '-' + 2
420
+ # pylint: disable=line-too-long
421
+ # Write-only property, can't assume we can read state from the printer
422
+ # since there is no command for it and hooking up RX is discouraged
423
+ # (5V will damage many boards).
424
+ underline = property (None , _set_underline , None , "Set the underline state of the text, must be None (off), UNDERLINE_THIN, or UNDERLINE_THICK." )
425
+ # pylint: enable=line-too-long
405
426
406
427
def _set_inverse (self , inverse ):
407
428
# Set the inverse printing state to enabled disabled with the specified
0 commit comments