mirror of
				https://github.com/python-escpos/python-escpos
				synced 2025-10-23 09:30:00 +00:00 
			
		
		
		
	Add self-open mechanism
This commit is contained in:
		@@ -114,7 +114,7 @@ class Escpos(object):
 | 
				
			|||||||
    class.
 | 
					    class.
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    device = None
 | 
					    _device = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(self, profile=None, magic_encode_args=None, **kwargs) -> None:
 | 
					    def __init__(self, profile=None, magic_encode_args=None, **kwargs) -> None:
 | 
				
			||||||
        """Initialize ESCPOS Printer.
 | 
					        """Initialize ESCPOS Printer.
 | 
				
			||||||
@@ -128,6 +128,22 @@ class Escpos(object):
 | 
				
			|||||||
        """Call self.close upon deletion."""
 | 
					        """Call self.close upon deletion."""
 | 
				
			||||||
        self.close()
 | 
					        self.close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @property
 | 
				
			||||||
 | 
					    def device(self):
 | 
				
			||||||
 | 
					        """Implements a self-open mechanism."""
 | 
				
			||||||
 | 
					        if self._device is False:
 | 
				
			||||||
 | 
					            # Open device if not previously opened
 | 
				
			||||||
 | 
					            self.open()
 | 
				
			||||||
 | 
					        return self._device
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @device.setter
 | 
				
			||||||
 | 
					    def device(self, new_device):
 | 
				
			||||||
 | 
					        self._device = new_device
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def open(self):
 | 
				
			||||||
 | 
					        """Open a printer device/connection."""
 | 
				
			||||||
 | 
					        pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @abstractmethod
 | 
					    @abstractmethod
 | 
				
			||||||
    def _raw(self, msg: bytes) -> None:
 | 
					    def _raw(self, msg: bytes) -> None:
 | 
				
			||||||
        """Send raw data to the printer.
 | 
					        """Send raw data to the printer.
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user