Skip to content

Commit

Permalink
Move printer config from printer module to tillconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
sde1000 committed Jan 22, 2024
1 parent f77cf60 commit 1f872fa
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 35 deletions.
2 changes: 1 addition & 1 deletion quicktill/delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def printout(self):
return
menu = [(f"Print labels on {x}",
printer.label_print_delivery, (x, self.dn))
for x in printer.labelprinters]
for x in tillconfig.label_printers]
ui.automenu(menu, title="Delivery print options",
colour=ui.colour_confirm)

Expand Down
4 changes: 2 additions & 2 deletions quicktill/foodcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from . import event
from . import user
from . import ui_ncurses
from . import printer
from . import pdrivers

import logging
Expand Down Expand Up @@ -77,7 +76,8 @@ def add_arguments(parser):
@staticmethod
def run(args):
tillconfig.mainloop = event.SelectorsMainLoop()
printer.driver = pdrivers.nullprinter(name="disabled-printer")
tillconfig.receipt_printer = pdrivers.nullprinter(
name="disabled-printer")
tillconfig.firstpage = lambda: page(commitcode=args.commitcode,
quitcode=args.quitcode,
menuurl=args.url)
Expand Down
10 changes: 5 additions & 5 deletions quicktill/foodorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import datetime
import hashlib
import logging
from . import ui, keyboard, td, printer, tillconfig, user
from . import ui, keyboard, td, tillconfig, user
from . import lockscreen
from . import register
from .models import zero, penny
Expand Down Expand Up @@ -324,7 +324,7 @@ def __init__(self, func, transid, menuurl, kitchenprinters,
self.h = 20
self.w = 64
kpprob = self._kitchenprinter_problem()
rpprob = printer.driver.offline()
rpprob = tillconfig.receipt_printer.offline()
if kpprob and rpprob:
ui.infopopup(
["Both the kitchen printer and receipt printer report "
Expand Down Expand Up @@ -431,7 +431,7 @@ def printkey(self):

def finish(self, tablenumber):
# Check on the printer before we do any work...
rpprob = printer.driver.offline()
rpprob = tillconfig.receipt_printer.offline()
if rpprob:
ui.infopopup(
["The receipt printer is reporting a problem. Please fix it "
Expand Down Expand Up @@ -466,7 +466,7 @@ def finish(self, tablenumber):
if r == True:
user = ui.current_user()
with ui.exception_guard("printing the customer copy"):
print_food_order(printer.driver, number, self.ml,
print_food_order(tillconfig.receipt_printer, number, self.ml,
verbose=True, tablenumber=tablenumber,
footer=self.footer, transid=self.transid,
print_total=self.print_total)
Expand All @@ -482,7 +482,7 @@ def finish(self, tablenumber):
sys.exc_info()[0], sys.exc_info()[1])
try:
print_food_order(
printer.driver, number, self.ml,
tillconfig.receipt_printer, number, self.ml,
verbose=False, tablenumber=tablenumber,
footer=self.footer, transid=self.transid,
user=user.shortname if user else None)
Expand Down
10 changes: 5 additions & 5 deletions quicktill/jsonfoodorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import traceback
import datetime
import logging
from . import ui, keyboard, td, printer, tillconfig, user
from . import ui, keyboard, td, tillconfig, user
from .user import log as userlog
from . import lockscreen
from . import register
Expand Down Expand Up @@ -439,7 +439,7 @@ def __init__(self, func, transid, menuurl, kitchenprinters,
self.h = 20
self.w = 64
kpprob = self._kitchenprinter_problem()
rpprob = printer.driver.offline()
rpprob = tillconfig.receipt_printer.offline()
if kpprob and rpprob:
ui.infopopup(
["Both the kitchen printer and receipt printer report "
Expand Down Expand Up @@ -537,7 +537,7 @@ def printkey(self):

def finish(self, tablenumber):
# Check on the printer before we do any work...
rpprob = printer.driver.offline()
rpprob = tillconfig.receipt_printer.offline()
if rpprob:
ui.infopopup(
["The receipt printer is reporting a problem. Please fix it "
Expand Down Expand Up @@ -571,7 +571,7 @@ def finish(self, tablenumber):
if r == True:
user = ui.current_user()
with ui.exception_guard("printing the customer copy"):
print_food_order(printer.driver, number, self.ml,
print_food_order(tillconfig.receipt_printer, number, self.ml,
verbose=True, tablenumber=tablenumber,
footer=self.menu.footer, transid=self.transid)
try:
Expand All @@ -586,7 +586,7 @@ def finish(self, tablenumber):
sys.exc_info()[0], sys.exc_info()[1])
try:
print_food_order(
printer.driver, number, self.ml,
tillconfig.receipt_printer, number, self.ml,
verbose=False, tablenumber=tablenumber,
footer=self.menu.footer, transid=self.transid,
user=user.shortname)
Expand Down
8 changes: 4 additions & 4 deletions quicktill/managestock.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def print_stocklist_menu(sinfo, title):
td.s.add_all(sinfo)
menu = [(f"Print labels on {x}",
printer.stocklabel_print, (x, sinfo))
for x in printer.labelprinters]
for x in tillconfig.label_printers]
ui.automenu(menu, title="Stock print options", colour=ui.colour_confirm)


Expand Down Expand Up @@ -313,7 +313,7 @@ def correct_stocktype():
@user.permission_required(
'reprint-stocklabel', 'Re-print a single stock label')
def reprint_stocklabel():
if not printer.labelprinters:
if not tillconfig.label_printers:
ui.infopopup(["There are no label printers configured."],
title="Error")
return
Expand All @@ -329,7 +329,7 @@ def reprint_stocklabel_choose_printer(item):
text="Re-printed stock label"))
menu = [(f"Print label on {x}",
printer.stocklabel_print, (x, [item]))
for x in printer.labelprinters]
for x in tillconfig.label_printers]
ui.automenu(menu, title="Choose where to print label",
colour=ui.colour_confirm)

Expand Down Expand Up @@ -451,7 +451,7 @@ def _finish_print_pricelist(dept_id, include_all):
l = l.filter(StockItem.stocklineid != None)
l = l.all()

with printer.driver as d:
with tillconfig.receipt_printer as d:
d.printline(f"\t{tillconfig.pubname}", emph=1)
d.printline()
d.printline("\tPrice List", colour=1)
Expand Down
2 changes: 1 addition & 1 deletion quicktill/managetill.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def long_toast():

def raise_print_exception():
with ui.exception_guard("testing exception raised in printer driver"):
with printer.driver as d:
with tillconfig.receipt_printer as d:
d.printline("This line is printed before the exception")
raise Exception

Expand Down
16 changes: 6 additions & 10 deletions quicktill/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
import datetime
now = datetime.datetime.now

# XXX should be in tillconfig?
driver = None
labelprinters = []

# Do we print check digits on stock labels?
checkdigit_print = config.BooleanConfigItem(
'core:checkdigit_print', False, display_name="Print check digits?",
Expand All @@ -28,7 +24,7 @@ def print_receipt(transid):
return
if not trans.lines:
return
with driver as d:
with tillconfig.receipt_printer as d:
d.printline(f"\t{tillconfig.pubname}", emph=1)
for i in tillconfig.pubaddr().splitlines():
d.printline(f"\t{i}", colour=1)
Expand Down Expand Up @@ -109,7 +105,7 @@ def print_receipt(transid):


def print_sessioncountup(s):
with driver as d:
with tillconfig.receipt_printer as d:
d.printline(f"\t{tillconfig.pubname}", emph=1)
d.printline(f"\tSession {s.id}", colour=1)
d.printline(f"\t{ui.formatdate(s.date)}", colour=1)
Expand Down Expand Up @@ -155,7 +151,7 @@ def print_sessiontotals(session_id):
till_totals = dict(s.payment_totals)
actual_totals = dict((x.paytype, x.amount) for x in s.actual_totals)

with driver as d:
with tillconfig.receipt_printer as d:
d.printline(f"\t{tillconfig.pubname}", emph=1)
d.printline(f"\tSession {s.id}", colour=1)
d.printline(f"\t{ui.formatdate(s.date)}", colour=1)
Expand Down Expand Up @@ -209,7 +205,7 @@ def print_deferred_payment_wrapper(trans, paytype, amount, user_name):
Print a wrapper for money (cash, etc.) to be set aside to use
towards paying a part-paid transaction in a future session.
"""
with driver as d:
with tillconfig.receipt_printer as d:
for i in range(4):
d.printline(f"\t{tillconfig.pubname}", emph=1)
d.printline(f"\tDeferred transaction {trans.id}", emph=1)
Expand Down Expand Up @@ -294,7 +290,7 @@ def print_restock_list(rl):
We can't assume that any of these objects are in the current
session.
"""
with driver as d:
with tillconfig.receipt_printer as d:
d.printline(f"\t{tillconfig.pubname}", emph=1)
d.printline("\tRe-stock list")
d.printline(f"\tPrinted {ui.formattime(now())}")
Expand Down Expand Up @@ -325,7 +321,7 @@ def kickout():
with ui.exception_guard("kicking out the cash drawer",
title="Printer error"):
try:
driver.kickout()
tillconfig.cash_drawer.kickout()
except pdrivers.PrinterError as e:
ui.infopopup([f"Could not kick out the cash drawer: {e.desc}"],
title="Printer problem")
Expand Down
2 changes: 1 addition & 1 deletion quicktill/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def confirmendsession():
if not r:
return
# Check that the printer has paper before ending the session
pp = printer.driver.offline()
pp = tillconfig.receipt_printer.offline()
if pp:
ui.infopopup(["Could not end the session: there is a problem with "
f"the printer: {pp}"], title="Printer problem")
Expand Down
26 changes: 20 additions & 6 deletions quicktill/till.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,17 +570,28 @@ def main():
for opt, val in config.items():
if opt == 'printer':
if args.disable_printer:
printer.driver = pdrivers.nullprinter(name="disabled-printer")
tillconfig.receipt_printer = pdrivers.nullprinter(
name="disabled-printer")
else:
printer.driver = val
lockscreen.CheckPrinter("Receipt printer", printer.driver)
tillconfig.receipt_printer = val
lockscreen.CheckPrinter("Receipt printer", val)
elif opt == "cash_drawer":
if args.disable_printer:
tillconfig.cash_drawer = pdrivers.nullprinter(
name="disabled-cash-drawer")
else:
tillconfig.cash_drawer = val
elif opt == 'labelprinters':
printer.labelprinters = val
tillconfig.label_printers = val
elif opt == 'database':
tillconfig.database = val
elif opt == 'all_payment_methods':
# This will be obsolete as of version 23 and should show
# a warning if present
tillconfig.all_payment_methods = val
elif opt == 'payment_methods':
# This will be obsolete as of version 23 and should show
# a warning if present
tillconfig.payment_methods = val
elif opt == 'keyboard_driver':
tillconfig.keyboard_driver = val
Expand Down Expand Up @@ -609,9 +620,12 @@ def main():
else:
log.warning("Unknown configuration option '%s'", opt)

if printer.driver is None:
if tillconfig.receipt_printer is None:
log.info("no printer configured: using nullprinter()")
printer.driver = pdrivers.nullprinter()
tillconfig.receipt_printer = pdrivers.nullprinter()

if tillconfig.cash_drawer is None:
tillconfig.cash_drawer = tillconfig.receipt_printer

if args.database is not None:
tillconfig.database = args.database
Expand Down
4 changes: 4 additions & 0 deletions quicktill/tillconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
keyboard = None
keyboard_right = None

receipt_printer = None
label_printers = []
cash_drawer = None

pubname = config.ConfigItem(
'core:sitename', "Default site name", display_name="Site name",
description="Site name to be printed on receipts")
Expand Down

0 comments on commit 1f872fa

Please sign in to comment.