add in_menu option to registering commands so that barcodes don't show up in the menu for parameterized methods.

workspace
Brendan Howell 4 years ago
parent f0ec073f08
commit a398bc044e

@ -35,7 +35,7 @@ def update_commands(cls):
return cls return cls
def add_command(comstr, name=""): def add_command(comstr, name="", in_menu=True):
""" decorator for making a method into a command """ """ decorator for making a method into a command """
def decorator(func): def decorator(func):
""" the decorator itself """ """ the decorator itself """
@ -45,6 +45,7 @@ def add_command(comstr, name=""):
return func(*args, **kwargs) return func(*args, **kwargs)
func_wrap.command = comstr func_wrap.command = comstr
func_wrap.name = name func_wrap.name = name
func_wrap.in_menu = in_menu
return func_wrap return func_wrap
return decorator return decorator
@ -373,7 +374,8 @@ class Bureau(object):
cmd_detail = {"cmdname": method.name, cmd_detail = {"cmdname": method.name,
"prefix": self.prefix, "prefix": self.prefix,
"cmd": method.command, "cmd": method.command,
"desc": method.__doc__} "desc": method.__doc__,
"in_menu": method.in_menu}
if self.prefix == "IR": if self.prefix == "IR":
method = getattr(self, "add_cmd") method = getattr(self, "add_cmd")
method(cmd_detail) method(cmd_detail)
@ -411,12 +413,15 @@ class Bureau(object):
returns an instance of the small escpos printer returns an instance of the small escpos printer
""" """
if (self.smprint["inep"] is None) and (self.smprint["outep"] is None): if (self.smprint["inep"] is None) and (self.smprint["outep"] is None):
prn = printer.Usb(self.smprint["vendorid"], self.smprint["productid"]) prn = printer.Usb(self.smprint["vendorid"],
self.smprint["productid"],
profile=self.smprint["profile"])
else: else:
prn = printer.Usb(self.smprint["vendorid"], prn = printer.Usb(self.smprint["vendorid"],
self.smprint["productid"], self.smprint["productid"],
in_ep=self.smprint["inep"], in_ep=self.smprint["inep"],
out_ep=self.smprint["outep"]) out_ep=self.smprint["outep"],
profile=self.smprint["profile"])
return prn return prn

@ -75,11 +75,15 @@ class InhumanResources(Bureau):
cmdname = data["cmdname"] cmdname = data["cmdname"]
desc = data["desc"] desc = data["desc"]
cmd_code = prefix + cmd + "." cmd_code = prefix + cmd + "."
in_menu = data["in_menu"]
#bc = barcode.generate("code128", prefix + cmd + ".", writer=barcode.writer.ImageWriter(), output=barcode_png) #bc = barcode.generate("code128", prefix + cmd + ".", writer=barcode.writer.ImageWriter(), output=barcode_png)
if in_menu:
bc = kode256.svg(cmd_code) bc = kode256.svg(cmd_code)
encoded_svg = b64encode(bc.encode()).decode() encoded_svg = b64encode(bc.encode()).decode()
encoded_data = "data:image/svg+xml;charset=utf-8;base64," + encoded_svg encoded_data = "data:image/svg+xml;charset=utf-8;base64," + encoded_svg
bc = '<img src="%s" />' % encoded_data bc = '<img src="%s" />' % encoded_data
else:
bc = ""
except KeyError as e: except KeyError as e:
print("cannot add invalid command:", str(e)) print("cannot add invalid command:", str(e))
return return

@ -87,6 +87,10 @@ class Publications(Bureau):
the document camera as the index page. Finally, it will print out the document camera as the index page. Finally, it will print out
the main page with commands for working with the site. the main page with commands for working with the site.
""" """
self.print_small("SORRY! the publication/site feature is not done yet. So this does nothing for now.")
return
#TODO: finish and test this stuff
site_dir = os.path.join(self.db, "1") site_dir = os.path.join(self.db, "1")
site_id = 1 site_id = 1
while os.path.exists(site_dir): while os.path.exists(site_dir):

Loading…
Cancel
Save