Skip to content

Commit

Permalink
Improve EscPComandos action handling and enhance printTexto method fo…
Browse files Browse the repository at this point in the history
…r better parameter support
  • Loading branch information
alevilar committed Dec 22, 2024
1 parent b177c6a commit 464eab9
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/common/EscPComandos.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,21 @@ def run(self, jsonTicket):
actions = jsonTicket.keys()
rta = []
for action in actions:
fnAction = getattr(self, action)
fnAction = getattr(self, action, None)

if isinstance(jsonTicket[action], list):
res = fnAction(escpos, *jsonTicket[action])
rta.append({"action": action, "rta": res})
if fnAction:
params = jsonTicket[action]

if isinstance(params, list):
res = fnAction(escpos, *params)
elif isinstance(params, dict):
res = fnAction(escpos, **params)
else:
res = fnAction(escpos, params)

elif isinstance(jsonTicket[action], dict):
res = fnAction(escpos, **jsonTicket[action])
rta.append({"action": action, "rta": res})
else:
res = fnAction(escpos)
rta.append({"action": action, "rta": res})
rta.append({"action": action, "rta": "Function not found"})

return rta

Expand All @@ -81,8 +84,16 @@ def getStatus(self):
else:
return False

def printTexto(self, printer, texto):
printer.text(texto)
def printTexto(self, escpos: EscposIO, texto=None, **kwargs):
printer = escpos.printer
self.__initPrinter(printer)

if texto:
printer.text(texto)
elif 'texto' in kwargs:
printer.text(kwargs['texto'])
else:
raise ValueError("No text provided to print")


def openDrawer(self, escpos: EscposIO, **kwargs):
Expand Down

0 comments on commit 464eab9

Please sign in to comment.