Skip to content

Commit

Permalink
Added multi printer hack
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeoLacruz committed Apr 6, 2024
1 parent a42f5d6 commit 22f9ad0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion inventree_zebra/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ZEBRA_PLUGIN_VERSION = "0.5.2"
ZEBRA_PLUGIN_VERSION = "0.6.0"
19 changes: 15 additions & 4 deletions inventree_zebra/zebra_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ZebraLabelPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlugin):
},
'THRESHOLD': {
'name': _('Threshold'),
'description': _('Threshold for converting grayscale to BW (0-255)'),
'description': _('Threshold for converting gray scale to BW (0-255)'),
'validator': [int, MinValueValidator(0), MaxValueValidator(255)],
'default': 200,
},
Expand All @@ -79,7 +79,6 @@ class ZebraLabelPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlugin):
def print_label(self, **kwargs):

# Read settings
ip_address = self.get_setting('IP_ADDRESS')
connection = self.get_setting('CONNECTION')
interface = self.get_setting('LOCAL_IF')
port = int(self.get_setting('PORT'))
Expand All @@ -97,7 +96,7 @@ def print_label(self, **kwargs):
fn = lambda x: 255 if x > threshold else 0
label_image = label_image.convert('L').point(fn, mode='1')

# Uncomment this if you need the intermetiate png file for debugging.
# Uncomment this if you need the intermediate png file for debugging.
# label_image.save('/home/user/label.png')

# Convert image to Zebra zpl
Expand All @@ -109,11 +108,23 @@ def print_label(self, **kwargs):
li.write_graphic(label_image, width)
li.endorigin()

# Uncomment this if you need the intermetiate zpl file for debugging.

# Uncomment this if you need the intermediate zpl file for debugging.
# datafile=open('/home/user/label.txt','w')
# datafile.write(li.dumpZPL())
# datafile.close()

# Select the right printer.
# This is a multi printer hack. In case the label has an IP address in the metadata
# the address in the settings is overwritten be the metadata. By this you can
# specify a separate printer for each label.

label=kwargs['label_instance']
try:
ip_address = label.metadata['ip_address']
except:
ip_address = self.get_setting('IP_ADDRESS')

# Send the label to the printer
if (connection == 'local'):
try:
Expand Down

0 comments on commit 22f9ad0

Please sign in to comment.