shantanubhadoria / python-printer-escpos

Talk to Dot Matrix, Thermal POS printers supporting ESCPOS Specification
43 stars 11 forks source link

NetworkPrinter object has no attribute _usePrintMode #10

Open Lion3000 opened 2 years ago

Lion3000 commented 2 years ago

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 commented 2 years ago

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