|
|
@@ -2,9 +2,9 @@ from krita import DockWidget
|
|
|
from PyQt5.QtWidgets import QWidget, QDialog, QVBoxLayout, QHBoxLayout, QLabel, QComboBox, QPushButton
|
|
|
from PyQt5.QtCore import QByteArray
|
|
|
|
|
|
-DOCKER_TITLE = 'Button Shy PNP Expander'
|
|
|
+DOCKER_TITLE = 'Button Shy PNP Tools'
|
|
|
|
|
|
-class BsPnpExpander(DockWidget):
|
|
|
+class BsPnpTools(DockWidget):
|
|
|
|
|
|
def __init__(self):
|
|
|
super().__init__()
|
|
|
@@ -31,6 +31,13 @@ class BsPnpExpander(DockWidget):
|
|
|
goButton.setIcon( Krita.instance().icon('animation_play') )
|
|
|
layout.addWidget(goButton)
|
|
|
|
|
|
+ crop3Button = QPushButton("Create 3x2 Cropmarks")
|
|
|
+ crop3Button.setIcon( Krita.instance().icon('animation_play') )
|
|
|
+ layout.addWidget(crop3Button)
|
|
|
+ crop4Button = QPushButton("Create 4x2 Cropmarks")
|
|
|
+ crop4Button.setIcon( Krita.instance().icon('animation_play') )
|
|
|
+ layout.addWidget(crop4Button)
|
|
|
+
|
|
|
# Add a stretch to prevent the rest of the content from stretching.
|
|
|
layout.addStretch()
|
|
|
|
|
|
@@ -39,6 +46,8 @@ class BsPnpExpander(DockWidget):
|
|
|
|
|
|
# Hook up the action to the button.
|
|
|
goButton.clicked.connect( self.expandBsPnp )
|
|
|
+ crop3Button.clicked.connect( self.add3x2CropMarks )
|
|
|
+ crop4Button.clicked.connect( self.add4x2CropMarks )
|
|
|
|
|
|
|
|
|
# notifies when views are added or removed
|
|
|
@@ -74,7 +83,7 @@ class BsPnpExpander(DockWidget):
|
|
|
direction = self.expandDir.currentText()
|
|
|
layerPos = layer.position()
|
|
|
|
|
|
- # Move layer 411 pixels left or right
|
|
|
+ # Move layer 411 pixels left or right, which is half a card and gap width: (752 + 70) / 2
|
|
|
xDiff = 411 if direction == 'Left' else -411
|
|
|
layer.move(layerPos.x() + xDiff, layerPos.y())
|
|
|
|
|
|
@@ -90,39 +99,87 @@ class BsPnpExpander(DockWidget):
|
|
|
layer.setPixelData(whiteFill, fillX, fillY, fillWidth, fillHeight)
|
|
|
|
|
|
# Create horizontal cropmarks at image edges.
|
|
|
- # positions 106 1153 1228 2276. 61px long.
|
|
|
+ # Vertical distances (px): 1047 (38 midY 37) 1048
|
|
|
+ # 61px long.
|
|
|
blackPixel = b'\x00\x00\x00\xff'
|
|
|
cropMarkWidth = 61
|
|
|
cropMarkHeight = 2
|
|
|
cropMark = QByteArray(blackPixel * cropMarkWidth * cropMarkHeight)
|
|
|
- ySet = [106, 1153, 1228, 2276]
|
|
|
- for x in [0, doc.width() - cropMarkWidth]:
|
|
|
+ midX = doc.width() / 2
|
|
|
+ midY = doc.height() / 2
|
|
|
+ ySet = [ midY - 1085, midY - 38, midY + 37, midY + 1085 ]
|
|
|
+ for x in [midX - 1706, midX + 1645]:
|
|
|
for y in ySet:
|
|
|
- layer.setPixelData(cropMark, x, y, cropMarkWidth, cropMarkHeight)
|
|
|
+ layer.setPixelData(cropMark, x, y - 1, cropMarkWidth, cropMarkHeight)
|
|
|
|
|
|
# Create vertical cropmarks for new card spaces
|
|
|
- # positions 96 848 2562 3314. 37px long.
|
|
|
+ # Horizontal distances (px): 752 70 752 (35 midX 35) 752 70 752
|
|
|
+ # For these marks, we only want either the first or last 2 positions.
|
|
|
+ # 37px long.
|
|
|
cropMarkWidth = 2
|
|
|
cropMarkHeight = 37
|
|
|
cropMark = QByteArray(blackPixel * cropMarkWidth * cropMarkHeight)
|
|
|
- xSet = [96, 848] if direction == 'Left' else [2562, 3314]
|
|
|
- for y in [0, doc.height() - cropMarkHeight]:
|
|
|
+ xSet = [ midX - 1609, midX - 857 ] if direction == 'Left' else [ midX + 857, midX + 1609 ]
|
|
|
+ for y in [ midY - 1192, midY + 1155 ]:
|
|
|
for x in xSet:
|
|
|
- layer.setPixelData(cropMark, x, y, cropMarkWidth, cropMarkHeight)
|
|
|
+ layer.setPixelData(cropMark, x - 1, y, cropMarkWidth, cropMarkHeight)
|
|
|
|
|
|
# Place guides on crop marks for new card spaces
|
|
|
vList = doc.verticalGuides()
|
|
|
hList = doc.horizontalGuides()
|
|
|
vList.clear()
|
|
|
hList.clear()
|
|
|
- for x in xSet:
|
|
|
- vList.append(x + 1)
|
|
|
- for y in ySet:
|
|
|
- hList.append(y + 1)
|
|
|
- doc.setVerticalGuides(vList)
|
|
|
- doc.setHorizontalGuides(hList)
|
|
|
+ doc.setVerticalGuides(xSet)
|
|
|
+ doc.setHorizontalGuides(ySet)
|
|
|
doc.setGuidesLocked(True)
|
|
|
doc.setGuidesVisible(True)
|
|
|
|
|
|
# Refresh the view, or the moved will not be immediately reflected.
|
|
|
doc.refreshProjection()
|
|
|
+
|
|
|
+ # Add 3x2 Internal cropmarks.
|
|
|
+ def add3x2CropMarks(self, e):
|
|
|
+ self.addCropMarks(3)
|
|
|
+
|
|
|
+ # Add 4x2 Internal cropmarks.
|
|
|
+ def add4x2CropMarks(self, e):
|
|
|
+ self.addCropMarks(4)
|
|
|
+
|
|
|
+ def addCropMarks(self, gridSize):
|
|
|
+ # Cropmarks will be on a new layer.
|
|
|
+ doc = Krita.instance().activeDocument()
|
|
|
+ layer = doc.createNode('BSCropmarks', 'paintLayer')
|
|
|
+ root = doc.rootNode()
|
|
|
+ root.addChildNode(layer, None)
|
|
|
+
|
|
|
+ # Calculate grid dimensions, assuming page is in centre position.
|
|
|
+ midX = doc.width() / 2
|
|
|
+ midY = doc.height() / 2
|
|
|
+ xSet = []
|
|
|
+ ySet = []
|
|
|
+
|
|
|
+ if gridSize == 3:
|
|
|
+ # Horizontal distances (px): 752 70 (376 midX 376) 70 752
|
|
|
+ # Vertical distances (px): 1047 (38 midY 37) 1048
|
|
|
+ xSet = [ midX - 1198, midX - 446, midX - 376, midX + 376, midX + 446, midX + 1198 ]
|
|
|
+ ySet = [ midY - 1085, midY - 38, midY + 37, midY + 1085 ]
|
|
|
+
|
|
|
+ else:
|
|
|
+ # Horizontal distances (px): 752 70 752 (35 midX 35) 752 70 752
|
|
|
+ # Vertical distances (px): 1047 (38 midY 37) 1048
|
|
|
+ xSet = [ midX - 1609, midX - 857, midX - 787, midX - 35, midX + 35, midX + 787, midX + 857, midX + 1609 ]
|
|
|
+ ySet = [ midY - 1085, midY - 38, midY + 37, midY + 1085 ]
|
|
|
+
|
|
|
+ # Create cropmarks.
|
|
|
+ blackPixel = b'\x00\x00\x00\xff'
|
|
|
+ cropMarkWidth = 2
|
|
|
+ cropMarkHeight = 48
|
|
|
+ cropMark = QByteArray(blackPixel * cropMarkWidth * cropMarkHeight)
|
|
|
+ for x in xSet:
|
|
|
+ for y in ySet:
|
|
|
+ layer.setPixelData(cropMark, x - 1, y - cropMarkHeight/2, cropMarkWidth, cropMarkHeight) # vertical line
|
|
|
+ layer.setPixelData(cropMark, x - cropMarkHeight/2, y - 1, cropMarkHeight, cropMarkWidth) # horizontal line
|
|
|
+
|
|
|
+ # Refresh the view, or the cropmarks will not be immediately shown.
|
|
|
+ doc.refreshProjection()
|
|
|
+
|