Last active
February 7, 2023 11:56
-
-
Save dogtopus/7ec62b35c8daaf5903cba86e44935ac8 to your computer and use it in GitHub Desktop.
PTouch tape template for Inkscape 1.x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<inkscape-extension xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"> | |
<_name>PTouch Tape</_name> | |
<id>org.inkscape.render.ptouch_tape2</id> | |
<dependency type="executable" location="extensions">ptouch_tape2.py</dependency> | |
<dependency type="executable" location="extensions">inkex.py</dependency> | |
<!-- TODO Not sure about the valid printing region (conflicts with what | |
datasheet says). More tests needed. --> | |
<!-- Format: width,valid_width,offset --> | |
<param name="type" _gui-text="Tape type:" type="enum"> | |
<item value="3.5,3.5,0.0">TZe 3.5mm</item> | |
<item value="6,4.6,0.7">TZe 6mm</item> | |
<item value="9,6,1.5">TZe 9mm</item> | |
<item value="12,9,1.5">TZe 12mm</item> | |
<item value="18,15,1.5">TZe 18mm</item> | |
<item value="24,18,3.0">TZe 24mm</item> | |
</param> | |
<param name="length" _gui-text="Print length (mm):" type="float" min="4.4" max="1000">100.0</param> | |
<param name="gen-grid" _gui-text="Generate grid" type="boolean">true</param> | |
<param name="boundary" _gui-text="Generate boundary guide" type="boolean">true</param> | |
<param name="note_gen" _gui-text="Grid and boundary guide generation only works on supported tape width." type="description"/> | |
<effect needs-live-preview="false"> | |
<object-type>all</object-type> | |
<effects-menu hidden="true" /> | |
</effect> | |
<inkscape:_templateinfo> | |
<inkscape:_name>PTouch Tape...</inkscape:_name> | |
<inkscape:author>dogtopus</inkscape:author> | |
<inkscape:_shortdesc>PTouch tape template.</inkscape:_shortdesc> | |
<inkscape:date>2018-06-15</inkscape:date> | |
<inkscape:_keywords>ptouch label tape</inkscape:_keywords> | |
</inkscape:_templateinfo> | |
<script> | |
<command reldir="extensions" interpreter="python">ptouch_tape2.py</command> | |
</script> | |
</inkscape-extension> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import inkex | |
from collections import namedtuple | |
TapeType = namedtuple('TapeType', ('width', 'valid_width', 'offset')) | |
def parse_tape_type(str_): | |
width, valid_width, offset = str_.split(',') | |
return TapeType(float(width), float(valid_width), float(offset)) | |
class PTouchTape(inkex.extensions.TemplateExtension): | |
def add_arguments(self, p): | |
p.add_argument('--type', | |
type=parse_tape_type, | |
dest='type_', | |
default=TapeType(12.0, 9.0, 1.5), | |
help='Tape type') | |
p.add_argument('--length', | |
type=float, | |
default=100.0, | |
help='Print length (mm)') | |
p.add_argument('--gen-grid', | |
type=inkex.utils.Boolean, | |
default=True, | |
help='Generate grid') | |
p.add_argument('--boundary', | |
type=inkex.utils.Boolean, | |
default=True, | |
help='Generate boundary guide') | |
def get_size(self): | |
return (self.options.length, 'mm', self.options.type_.width, 'mm') | |
def set_namedview(self, width, height, unit): | |
super().set_namedview(width, height, unit) | |
width, valid_width, offset = self.options.type_ | |
self.svg.namedview.set('inkscape:document-units', 'mm') | |
self.svg.namedview.set('inkscape:pageopacity', '1.0') | |
if self.options.gen_grid: | |
grid = inkex.Grid() | |
grid.set('type', 'xygrid') | |
grid.set('units', 'mm') | |
grid.set('spacingx', '0.5') | |
grid.set('spacingy', '0.5') | |
grid.set('originx', '0.0') | |
grid.set('originy', str(width-valid_width-offset)) | |
grid.set('enabled', 'true') | |
grid.set('snapvisiblegridlinesonly', 'true') | |
grid.set('visible', 'true') | |
grid.set('dotted', 'false') | |
self.svg.namedview.add(grid) | |
if self.options.boundary: | |
self.svg.namedview.new_guide(width-valid_width-offset, name='Label Boundary') | |
self.svg.namedview.new_guide(width-offset, name='Label Boundary') | |
if __name__ == '__main__': | |
PTouchTape().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment