Merge pull request #105 from python-escpos/feature-disable-panel-buttons
FEATURE disable panel buttons
This commit is contained in:
commit
916b09a84c
|
@ -54,6 +54,11 @@ _CUT_PAPER = lambda m: GS + b'V' + m
|
||||||
PAPER_FULL_CUT = _CUT_PAPER(b'\x00') # Full cut paper
|
PAPER_FULL_CUT = _CUT_PAPER(b'\x00') # Full cut paper
|
||||||
PAPER_PART_CUT = _CUT_PAPER(b'\x01') # Partial cut paper
|
PAPER_PART_CUT = _CUT_PAPER(b'\x01') # Partial cut paper
|
||||||
|
|
||||||
|
# Panel buttons (e.g. the FEED button)
|
||||||
|
_PANEL_BUTTON = lambda n: ESC + b'c5' + six.int2byte(n)
|
||||||
|
PANEL_BUTTON_ON = _PANEL_BUTTON(0) # enable all panel buttons
|
||||||
|
PANEL_BUTTON_OFF = _PANEL_BUTTON(1) # disable all panel buttons
|
||||||
|
|
||||||
# Text format
|
# Text format
|
||||||
# TODO: Acquire the "ESC/POS Application Programming Guide for Paper Roll
|
# TODO: Acquire the "ESC/POS Application Programming Guide for Paper Roll
|
||||||
# Printers" and tidy up this stuff too.
|
# Printers" and tidy up this stuff too.
|
||||||
|
|
|
@ -674,3 +674,26 @@ class Escpos(object):
|
||||||
self._raw(CTL_HT)
|
self._raw(CTL_HT)
|
||||||
elif ctl.upper() == "VT":
|
elif ctl.upper() == "VT":
|
||||||
self._raw(CTL_VT)
|
self._raw(CTL_VT)
|
||||||
|
|
||||||
|
def panel_buttons(self, enable=True):
|
||||||
|
""" Controls the panel buttons on the printer (e.g. FEED)
|
||||||
|
|
||||||
|
When enable is set to False the panel buttons on the printer will be disabled. Calling the method with
|
||||||
|
enable=True or without argument will enable the panel buttons.
|
||||||
|
|
||||||
|
If panel buttons are enabled, the function of the panel button, such as feeding, will be executed upon pressing
|
||||||
|
the button. If the panel buttons are disabled, pressing them will not have any effect.
|
||||||
|
|
||||||
|
This command is effective until the printer is initialized, reset or power-cycled. The default is enabled panel
|
||||||
|
buttons.
|
||||||
|
|
||||||
|
Some panel buttons will always work, especially when printer is opened. See for more information the manual
|
||||||
|
of your printer and the escpos-command-reference.
|
||||||
|
|
||||||
|
:param enable: controls the panel buttons
|
||||||
|
:rtype: None
|
||||||
|
"""
|
||||||
|
if enable:
|
||||||
|
self._raw(PANEL_BUTTON_ON)
|
||||||
|
else:
|
||||||
|
self._raw(PANEL_BUTTON_OFF)
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
"""tests for panel button function
|
||||||
|
|
||||||
|
:author: `Patrick Kanzler <patrick.kanzler@fablab.fau.de>`_
|
||||||
|
:organization: `python-escpos <https://github.com/python-escpos>`_
|
||||||
|
:copyright: Copyright (c) 2016 `python-escpos <https://github.com/python-escpos>`_
|
||||||
|
:license: GNU GPL v3
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import absolute_import
|
||||||
|
from __future__ import division
|
||||||
|
from __future__ import print_function
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from nose.tools import with_setup
|
||||||
|
|
||||||
|
import escpos.printer as printer
|
||||||
|
import os
|
||||||
|
|
||||||
|
devfile = 'testfile'
|
||||||
|
|
||||||
|
|
||||||
|
def setup_testfile():
|
||||||
|
"""create a testfile as devfile"""
|
||||||
|
fhandle = open(devfile, 'a')
|
||||||
|
try:
|
||||||
|
os.utime(devfile, None)
|
||||||
|
finally:
|
||||||
|
fhandle.close()
|
||||||
|
|
||||||
|
|
||||||
|
def teardown_testfile():
|
||||||
|
"""destroy testfile again"""
|
||||||
|
os.remove(devfile)
|
||||||
|
|
||||||
|
|
||||||
|
@with_setup(setup_testfile, teardown_testfile)
|
||||||
|
def test_function_panel_button_on():
|
||||||
|
"""test the panel button function (enabling) by comparing output"""
|
||||||
|
instance = printer.File(devfile=devfile)
|
||||||
|
instance.panel_buttons()
|
||||||
|
instance.flush()
|
||||||
|
with open(devfile, "rb") as f:
|
||||||
|
assert(f.read() == b'\x1B\x63\x35\x00')
|
||||||
|
|
||||||
|
|
||||||
|
@with_setup(setup_testfile, teardown_testfile)
|
||||||
|
def test_function_panel_button_off():
|
||||||
|
"""test the panel button function (disabling) by comparing output"""
|
||||||
|
instance = printer.File(devfile=devfile)
|
||||||
|
instance.panel_buttons(False)
|
||||||
|
instance.flush()
|
||||||
|
with open(devfile, "rb") as f:
|
||||||
|
assert(f.read() == b'\x1B\x63\x35\x01')
|
Loading…
Reference in New Issue