python-printer-escpos
python-printer-escpos copied to clipboard
NetworkPrinter object has no attribute _usePrintMode
Hello I fond an issue, When I use printer.bold() or printer.doubleWidth()
Using getNetworkPrinter
Traceback (most recent call last):
File "main.py", line 9, in <module>
printer.bold(True)
File "C:\Python310\lib\site-packages\escpos\commandset\generic.py", line 184, in bold
elif self._usePrintMode:
AttributeError: 'NetworkPrinter' object has no attribute '_usePrintMode'. Did you mean: '_updatePrintMode'?
ok, it comes from bad implementation of inheritance:
commandSetModule = importlib.import_module('..commandset.' + commandSet.lower(), __name__)
commandSetClass = getattr(commandSetModule, commandSet)
class NetworkPrinter(commandSetClass):
def __init__(self, host, port=9100, initialize=True):
self.host = host
self.port = port
self.__open()
if initialize:
self.initialize()
The constructor of the class Generic is never called !!!! So "_usePrintMode" and other are never initialized
class Generic():
def __init__(self):
# Command code configurations
self._usePrintMode = False
self._textFont = 'a'
self._textBold = False
self._textUnderline = False
self._textDoubleHeight = False
self._textDoubleWidth = False