python-printer-escpos icon indicating copy to clipboard operation
python-printer-escpos copied to clipboard

NetworkPrinter object has no attribute _usePrintMode

Open Lion3000 opened this issue 2 years ago • 1 comments

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'?

Lion3000 avatar Apr 23 '22 14:04 Lion3000

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

Lion3000 avatar Apr 23 '22 15:04 Lion3000