|
@@ -37,8 +37,8 @@ class BoxGenerator(Extension):
|
|
|
row0.addWidget(desc)
|
|
row0.addWidget(desc)
|
|
|
|
|
|
|
|
# Dimension row.
|
|
# Dimension row.
|
|
|
- self.lengthInput = QLineEdit('95')
|
|
|
|
|
- self.widthInput = QLineEdit('70')
|
|
|
|
|
|
|
+ self.lengthInput = QLineEdit('67')
|
|
|
|
|
+ self.widthInput = QLineEdit('93')
|
|
|
self.heightInput = QLineEdit('20')
|
|
self.heightInput = QLineEdit('20')
|
|
|
self.unitInput = QComboBox()
|
|
self.unitInput = QComboBox()
|
|
|
self.unitInput.addItems( ['mm', 'inch', 'px'] )
|
|
self.unitInput.addItems( ['mm', 'inch', 'px'] )
|
|
@@ -52,10 +52,11 @@ class BoxGenerator(Extension):
|
|
|
row1.addWidget(self.unitInput)
|
|
row1.addWidget(self.unitInput)
|
|
|
|
|
|
|
|
# Decision row.
|
|
# Decision row.
|
|
|
- self.flapCheck = QCheckBox('Flap')
|
|
|
|
|
- self.flapCheck.setChecked(True)
|
|
|
|
|
|
|
+ self.boxTypeInput = QComboBox()
|
|
|
|
|
+ self.boxTypeInput.addItems( ['Tuckbox', 'Telescopic'] )
|
|
|
row2 = QHBoxLayout()
|
|
row2 = QHBoxLayout()
|
|
|
- row2.addWidget(self.flapCheck)
|
|
|
|
|
|
|
+ row2.addWidget(QLabel('Box Type:'))
|
|
|
|
|
+ row2.addWidget(self.boxTypeInput)
|
|
|
|
|
|
|
|
# Do It row.
|
|
# Do It row.
|
|
|
goButton = QPushButton("Create Box")
|
|
goButton = QPushButton("Create Box")
|
|
@@ -71,7 +72,7 @@ class BoxGenerator(Extension):
|
|
|
newDialog.setLayout(layoutMain)
|
|
newDialog.setLayout(layoutMain)
|
|
|
|
|
|
|
|
# hook up the actions.
|
|
# hook up the actions.
|
|
|
- # goButton.clicked.connect( self.generateBox )
|
|
|
|
|
|
|
+ goButton.clicked.connect( self.generateBox )
|
|
|
# self.unitInput.currentIndexChanged.connect( self.convertCount )
|
|
# self.unitInput.currentIndexChanged.connect( self.convertCount )
|
|
|
|
|
|
|
|
# show the dialog.
|
|
# show the dialog.
|
|
@@ -84,62 +85,103 @@ class BoxGenerator(Extension):
|
|
|
|
|
|
|
|
# Actually generates the box!
|
|
# Actually generates the box!
|
|
|
def generateBox(self, e):
|
|
def generateBox(self, e):
|
|
|
-
|
|
|
|
|
- # Calculate how many lines of pixels to copy.
|
|
|
|
|
- unit = self.unitInput.currentIndex()
|
|
|
|
|
- count = float(self.countInput.text())
|
|
|
|
|
- ppi = self.doc.resolution()
|
|
|
|
|
- if unit == 0: # mm
|
|
|
|
|
- count = count * (ppi / 24.5)
|
|
|
|
|
- if unit == 1: # inch
|
|
|
|
|
- count = count * ppi
|
|
|
|
|
- offset = round(float(self.offsetInput.text()))
|
|
|
|
|
- count = round(count) - offset
|
|
|
|
|
- print("Pixel bleed amount: ", count)
|
|
|
|
|
- print("Edge offset: ", offset)
|
|
|
|
|
-
|
|
|
|
|
- # Copy lines for selected sides.
|
|
|
|
|
- if self.topCheck.checkState():
|
|
|
|
|
- bds = self.layer.bounds()
|
|
|
|
|
- xpos = bds.left()
|
|
|
|
|
- ypos = bds.top() - offset
|
|
|
|
|
- len = bds.width()
|
|
|
|
|
- bleedline = self.layer.pixelData(xpos, ypos, len, 1)
|
|
|
|
|
- for c in range(1, count+1):
|
|
|
|
|
- self.layer.setPixelData(bleedline, xpos, (ypos - c), len, 1)
|
|
|
|
|
- print("Top lines cloned: ", count)
|
|
|
|
|
- if self.botCheck.checkState():
|
|
|
|
|
- bds = self.layer.bounds()
|
|
|
|
|
- xpos = bds.left()
|
|
|
|
|
- ypos = bds.bottom() + offset
|
|
|
|
|
- len = bds.width()
|
|
|
|
|
- bleedline = self.layer.pixelData(xpos, ypos, len, 1)
|
|
|
|
|
- for c in range(1, count+1):
|
|
|
|
|
- self.layer.setPixelData(bleedline, xpos, (ypos + c), len, 1)
|
|
|
|
|
- print("Bottom lines cloned: ", count)
|
|
|
|
|
- if self.leftCheck.checkState():
|
|
|
|
|
- bds = self.layer.bounds()
|
|
|
|
|
- xpos = bds.left() - offset
|
|
|
|
|
- ypos = bds.top()
|
|
|
|
|
- len = bds.height()
|
|
|
|
|
- bleedline = self.layer.pixelData(xpos, ypos, 1, len)
|
|
|
|
|
- for c in range(1, count+1):
|
|
|
|
|
- self.layer.setPixelData(bleedline, (xpos - c), ypos, 1, len)
|
|
|
|
|
- print("Left lines cloned: ", count)
|
|
|
|
|
- if self.rightCheck.checkState():
|
|
|
|
|
- bds = self.layer.bounds()
|
|
|
|
|
- xpos = bds.right() + offset
|
|
|
|
|
- ypos = bds.top()
|
|
|
|
|
- len = bds.height()
|
|
|
|
|
- bleedline = self.layer.pixelData(xpos, ypos, 1, len)
|
|
|
|
|
- for c in range(1, count+1):
|
|
|
|
|
- self.layer.setPixelData(bleedline, (xpos + c), ypos, 1, len)
|
|
|
|
|
- print("Right lines cloned: ", count)
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- self.doc.refreshProjection()
|
|
|
|
|
-
|
|
|
|
|
- # Convert count input values to relevant units
|
|
|
|
|
- def convertCount():
|
|
|
|
|
- unitIndex = unitInput.currentIndex()
|
|
|
|
|
- print("Updated unit index: ", unitIndex)
|
|
|
|
|
|
|
+ layer = self.doc.createVectorLayer("Box")
|
|
|
|
|
+ root = self.doc.rootNode()
|
|
|
|
|
+ root.addChildNode(layer, None)
|
|
|
|
|
+
|
|
|
|
|
+ # Get dimensions in points. Points to mm conversion depends on document DPI.
|
|
|
|
|
+ length_mm = float(self.lengthInput.text())
|
|
|
|
|
+ width_mm = float(self.widthInput.text())
|
|
|
|
|
+ height_mm = float(self.heightInput.text())
|
|
|
|
|
+ # Assume input is in mm.
|
|
|
|
|
+ pts_per_mm = 300 / 25.4
|
|
|
|
|
+ length = length_mm * pts_per_mm
|
|
|
|
|
+ height = height_mm * pts_per_mm
|
|
|
|
|
+ width = width_mm * pts_per_mm
|
|
|
|
|
+
|
|
|
|
|
+ # Create outline using SVG.
|
|
|
|
|
+ if self.boxTypeInput.currentIndex() == 0: # Tuckbox
|
|
|
|
|
+ total_length = length * 2 + height * 3
|
|
|
|
|
+ total_width = width + height * 3
|
|
|
|
|
+ leeway = pts_per_mm / 2 # Make certain flaps shorter by 0.5mm to account for paper thickness.
|
|
|
|
|
+
|
|
|
|
|
+ stringy = f"""<svg style="stroke:black; fill:none; stroke-width:1">
|
|
|
|
|
+ <path d="
|
|
|
|
|
+ m {pts_per_mm+height*1.66}
|
|
|
|
|
+ h {length-height*2*0.66}
|
|
|
|
|
+ a {height*0.66} {height*0.66} 0 0 1 {height*0.66} {height*0.66}
|
|
|
|
|
+ v {height}
|
|
|
|
|
+ l {height*0.1} -{height}
|
|
|
|
|
+ h {height*0.4}
|
|
|
|
|
+ a {height*0.5} {height} 0 0 1 {height*0.5} {height}
|
|
|
|
|
+ h {length+height-leeway}
|
|
|
|
|
+ v {width}
|
|
|
|
|
+ h -{height-leeway}
|
|
|
|
|
+ v {height-leeway}
|
|
|
|
|
+ h -{length}
|
|
|
|
|
+ v -{height-leeway}
|
|
|
|
|
+ l -{height*0.1} {height}
|
|
|
|
|
+ h -{height*0.8}
|
|
|
|
|
+ l -{height*0.1} -{height}
|
|
|
|
|
+ v {height}
|
|
|
|
|
+ h -{length}
|
|
|
|
|
+ v -{height}
|
|
|
|
|
+ l -{height*0.1} {height}
|
|
|
|
|
+ h -{height*0.8}
|
|
|
|
|
+ l -{height*0.1} -{height}
|
|
|
|
|
+ v -{width}
|
|
|
|
|
+ a {height*0.5} {height} 0 0 1 {height*0.5} -{height}
|
|
|
|
|
+ h {height*0.4}
|
|
|
|
|
+ l {height*0.1} {height}
|
|
|
|
|
+ v -{height}
|
|
|
|
|
+ a {height*0.66} {height*0.66} 0 0 1 {height*0.66} -{height*0.66}
|
|
|
|
|
+ z
|
|
|
|
|
+ "></path>
|
|
|
|
|
+ <path d="
|
|
|
|
|
+ M {pts_per_mm+height} {height*0.66}
|
|
|
|
|
+ h -{pts_per_mm}
|
|
|
|
|
+ M {pts_per_mm+height+length} {height*0.66}
|
|
|
|
|
+ h {pts_per_mm}
|
|
|
|
|
+ M 0 {height*1.66}
|
|
|
|
|
+ h {pts_per_mm}
|
|
|
|
|
+ M 0 {height*1.66+width}
|
|
|
|
|
+ h {pts_per_mm}
|
|
|
|
|
+ M {pts_per_mm+height*2+length*2} {height*1.66}
|
|
|
|
|
+ v -{pts_per_mm}
|
|
|
|
|
+ "></path>
|
|
|
|
|
+ </svg>"""
|
|
|
|
|
+
|
|
|
|
|
+ else: # Telescopic
|
|
|
|
|
+ total_length = length + 5 * height
|
|
|
|
|
+ total_width = width + 5 * height
|
|
|
|
|
+ stringy = f"""<svg width="{total_length}" height="{total_width}" style="stroke:black; fill:none; stroke-width:1">
|
|
|
|
|
+ <path d="
|
|
|
|
|
+ m {height*3}
|
|
|
|
|
+ h {length-height}
|
|
|
|
|
+ l {height/2} {height/2}
|
|
|
|
|
+ v {height}
|
|
|
|
|
+ a {height} {height} 0 0 1 {height} {height}
|
|
|
|
|
+ h {height}
|
|
|
|
|
+ l {height/2} {height/2}
|
|
|
|
|
+ v {width-height}
|
|
|
|
|
+ l -{height/2} {height/2}
|
|
|
|
|
+ h -{height}
|
|
|
|
|
+ a {height} {height} 0 0 1 -{height} {height}
|
|
|
|
|
+ v {height}
|
|
|
|
|
+ l -{height/2} {height/2}
|
|
|
|
|
+ h -{length-height}
|
|
|
|
|
+ l -{height/2} -{height/2}
|
|
|
|
|
+ v -{height}
|
|
|
|
|
+ a {height} {height} 0 0 1 -{height} -{height}
|
|
|
|
|
+ h -{height}
|
|
|
|
|
+ l -{height/2} -{height/2}
|
|
|
|
|
+ v -{width-height}
|
|
|
|
|
+ l {height/2} -{height/2}
|
|
|
|
|
+ h {height}
|
|
|
|
|
+ a {height} {height} 0 0 1 {height} -{height}
|
|
|
|
|
+ v -{height}
|
|
|
|
|
+ Z
|
|
|
|
|
+ "></path>
|
|
|
|
|
+ </svg>"""
|
|
|
|
|
+
|
|
|
|
|
+ layer.addShapesFromSvg(stringy)
|