Krita Source Code Documentation
Loading...
Searching...
No Matches
comics_project_management_tools.comics_exporter.comicsExporter Class Reference

Public Member Functions

 __init__ (self)
 
 export (self)
 
 export_to_cbz (self, exportPath)
 
 getPanelsAndText (self, node, list)
 
 getPanelsAndTextVector (self, group, list, textOnly=False)
 
 handleShapeDescription (self, shape, list, textOnly=False)
 
 package_cbz (self, exportPath)
 
 parseTime (self, time=0)
 
 removeLayers (self, labels, node)
 
 save_out_pngs (self, sizesList)
 
 set_config (self, config, projectURL)
 

Public Attributes

 acbfPageData
 
 configDictionary
 
 pagesLocationList
 
 progress
 
 projectURL
 
 timer
 

Static Public Attributes

 acbfLocation = str()
 
list acbfPageData = []
 
 cometLocation = str()
 
 comicRackInfo = str()
 
list pageKeys = ["acbf_title", "acbf_none", "acbf_fade", "acbf_blend", "acbf_horizontal", "acbf_vertical", "epub_spread"]
 
dict pagesLocationList = {}
 

Detailed Description

Definition at line 77 of file comics_exporter.py.

Constructor & Destructor Documentation

◆ __init__()

comics_project_management_tools.comics_exporter.comicsExporter.__init__ ( self)

Definition at line 87 of file comics_exporter.py.

87 def __init__(self):
88 pass
89

Member Function Documentation

◆ export()

comics_project_management_tools.comics_exporter.comicsExporter.export ( self)

Definition at line 112 of file comics_exporter.py.

112 def export(self):
113 export_success = False
114
115 path = Path(self.projectURL)
116 if path.exists():
117 # Return a failure if we don't have any pages to export
118 if "pages" not in self.configDictionary:
119 QMessageBox.warning(None, i18n("Export not Possible"), i18n("No pages to export."), QMessageBox.StandardButton.Ok)
120 print("CPMT: No pages to export")
121 return False
122
123 # Make a meta-data folder so we keep the export folder nice and clean.
124 exportPath = path / self.configDictionary["exportLocation"]
125 if Path(exportPath / "metadata").exists() is False:
126 Path(exportPath / "metadata").mkdir()
127
128 # Get to which formats to export, and set the sizeslist.
129 lengthProcess = len(self.configDictionary["pages"])
130 sizesList = {}
131 if "CBZ" in self.configDictionary.keys():
132 if self.configDictionary["CBZactive"]:
133 lengthProcess += 5
134 sizesList["CBZ"] = self.configDictionary["CBZ"]
135 if "EPUB" in self.configDictionary.keys():
136 if self.configDictionary["EPUBactive"]:
137 lengthProcess += 1
138 sizesList["EPUB"] = self.configDictionary["EPUB"]
139 if "TIFF" in self.configDictionary.keys():
140 if self.configDictionary["TIFFactive"]:
141 sizesList["TIFF"] = self.configDictionary["TIFF"]
142 # Export the pngs according to the sizeslist.
143 # Create a progress dialog.
144 self.progress = QProgressDialog(i18n("Preparing export."), str(), 0, lengthProcess)
145 self.progress.setWindowTitle(i18n("Exporting Comic..."))
146 self.progress.setCancelButton(None)
147 self.timer = QElapsedTimer()
148 self.timer.start()
149 self.progress.show()
150 QApplication.instance().processEvents()
151 export_success = self.save_out_pngs(sizesList)
152
153 # Export acbf metadata.
154 if export_success:
155 if "CBZ" in sizesList.keys():
156 title = self.configDictionary["projectName"]
157 if "title" in self.configDictionary.keys():
158 title = str(self.configDictionary["title"]).replace(" ", "_")
159
160 self.acbfLocation = str(exportPath / "metadata" / str(title + ".acbf"))
161
162 locationStandAlone = str(exportPath / str(title + ".acbf"))
163 self.progress.setLabelText(i18n("Saving out ACBF and\nACBF standalone"))
164 self.progress.setValue(self.progress.value()+2)
165 export_success = exporters.ACBF.write_xml(self.configDictionary, self.acbfPageData, self.pagesLocationList["CBZ"], self.acbfLocation, locationStandAlone, self.projectURL)
166 print("CPMT: Exported to ACBF", export_success)
167
168 # Export and package CBZ and Epub.
169 if export_success:
170 if "CBZ" in sizesList.keys():
171 export_success = self.export_to_cbz(exportPath)
172 print("CPMT: Exported to CBZ", export_success)
173 if "EPUB" in sizesList.keys():
174 self.progress.setLabelText(i18n("Saving out EPUB"))
175 self.progress.setValue(self.progress.value()+1)
176 export_success = exporters.EPUB.export(self.configDictionary, self.projectURL, self.pagesLocationList["EPUB"], self.acbfPageData)
177 print("CPMT: Exported to EPUB", export_success)
178 else:
179 QMessageBox.warning(None, i18n("Export not Possible"), i18n("Nothing to export, URL not set."), QMessageBox.StandardButton.Ok)
180 print("CPMT: Nothing to export, url not set.")
181
182 return export_success
183
float value(const T *src, size_t ch)

References comics_project_management_tools.comics_exporter.comicsExporter.configDictionary, comics_project_management_tools.comics_exporter.comicsExporter.projectURL, and comics_project_management_tools.comics_project_translation_scraper.translation_scraper.projectURL.

◆ export_to_cbz()

comics_project_management_tools.comics_exporter.comicsExporter.export_to_cbz ( self,
exportPath )

Definition at line 188 of file comics_exporter.py.

188 def export_to_cbz(self, exportPath):
189 title = self.configDictionary["projectName"]
190 if "title" in self.configDictionary.keys():
191 title = str(self.configDictionary["title"]).replace(" ", "_")
192 self.progress.setLabelText(i18n("Saving out CoMet\nmetadata file"))
193 self.progress.setValue(self.progress.value()+1)
194 self.cometLocation = str(exportPath / "metadata" / str(title + " CoMet.xml"))
195 export_success = exporters.CoMet.write_xml(self.configDictionary, self.pagesLocationList["CBZ"], self.cometLocation)
196 self.comicRackInfo = str(exportPath / "metadata" / "ComicInfo.xml")
197 self.progress.setLabelText(i18n("Saving out Comicrack\nmetadata file"))
198 self.progress.setValue(self.progress.value()+1)
199 export_success = exporters.comic_rack_xml.write_xml(self.configDictionary, self.pagesLocationList["CBZ"], self.comicRackInfo)
200 self.package_cbz(exportPath)
201 return export_success
202

References comics_project_management_tools.comics_exporter.comicsExporter.cometLocation, comics_project_management_tools.comics_exporter.comicsExporter.comicRackInfo, comics_project_management_tools.comics_exporter.comicsExporter.configDictionary, comics_project_management_tools.comics_exporter.comicsExporter.package_cbz(), comics_project_management_tools.comics_exporter.comicsExporter.pagesLocationList, KisCageTransformWorker.progress, KisLiquifyTransformWorker.progress, KisAsyncActionFeedback::Private.progress, KoUpdater.progress(), KoUpdaterPrivate.progress(), KisPNGConverter.progress(), comics_project_management_tools.comics_exporter.comicsExporter.progress, and value().

◆ getPanelsAndText()

comics_project_management_tools.comics_exporter.comicsExporter.getPanelsAndText ( self,
node,
list )

Definition at line 379 of file comics_exporter.py.

379 def getPanelsAndText(self, node, list):
380 textLayersToSearch = ["text"]
381 panelLayersToSearch = ["panels"]
382 if "textLayerNames" in self.configDictionary.keys():
383 textLayersToSearch = self.configDictionary["textLayerNames"]
384 if "panelLayerNames" in self.configDictionary.keys():
385 panelLayersToSearch = self.configDictionary["panelLayerNames"]
386 if node.type() == "vectorlayer":
387 for name in panelLayersToSearch:
388 if str(name).lower() in str(node.name()).lower():
389 for shape in node.shapes():
390 if (shape.type() == "groupshape"):
391 self.getPanelsAndTextVector(shape, list)
392 else:
393 self.handleShapeDescription(shape, list)
394 for name in textLayersToSearch:
395 if str(name).lower() in str(node.name()).lower():
396 for shape in node.shapes():
397 if (shape.type() == "groupshape"):
398 self.getPanelsAndTextVector(shape, list, True)
399 else:
400 self.handleShapeDescription(shape, list, True)
401 else:
402 if node.childNodes():
403 for child in node.childNodes():
404 self.getPanelsAndText(node=child, list=list)
405

References comics_project_management_tools.comics_exporter.comicsExporter.configDictionary, comics_project_management_tools.comics_exporter.comicsExporter.getPanelsAndText(), comics_project_management_tools.comics_exporter.comicsExporter.getPanelsAndTextVector(), and comics_project_management_tools.comics_exporter.comicsExporter.handleShapeDescription().

◆ getPanelsAndTextVector()

comics_project_management_tools.comics_exporter.comicsExporter.getPanelsAndTextVector ( self,
group,
list,
textOnly = False )

Definition at line 416 of file comics_exporter.py.

416 def getPanelsAndTextVector(self, group, list, textOnly=False):
417 for shape in group.children():
418 if (shape.type() == "groupshape"):
419 self.getPanelsAndTextVector(shape, list, textOnly)
420 else:
421 self.handleShapeDescription(shape, list, textOnly)

References comics_project_management_tools.comics_exporter.comicsExporter.getPanelsAndTextVector(), and comics_project_management_tools.comics_exporter.comicsExporter.handleShapeDescription().

◆ handleShapeDescription()

comics_project_management_tools.comics_exporter.comicsExporter.handleShapeDescription ( self,
shape,
list,
textOnly = False )

Definition at line 426 of file comics_exporter.py.

426 def handleShapeDescription(self, shape, list, textOnly=False):
427 if (shape.type() != "KoSvgTextShapeID" and textOnly is True):
428 return
429 shapeDesc = {}
430 shapeDesc["name"] = shape.name()
431 rect = shape.boundingBox()
432 listOfPoints = [rect.topLeft(), rect.topRight(), rect.bottomRight(), rect.bottomLeft()]
433 shapeDesc["boundingBox"] = listOfPoints
434 if (shape.type() == "KoSvgTextShapeID" and textOnly is True):
435 shapeDesc["text"] = shape.toSvg()
436 list.append(shapeDesc)
437 return
438 # Turn off shape retrieval for now until the new text tool is finished.
439 r"""
440 shapeDesc = {}
441 shapeDesc["name"] = shape.name()
442 rect = shape.boundingBox()
443 listOfPoints = [rect.topLeft(), rect.topRight(), rect.bottomRight(), rect.bottomLeft()]
444 shapeDoc = minidom.parseString(shape.toSvg())
445 docElem = shapeDoc.documentElement
446 svgRegExp = re.compile(r'[MLCSQHVATmlzcqshva]\d+\.?\d* \d+\.?\d*')
447 transform = docElem.getAttribute("transform")
448 coord = []
449 adjust = QTransform()
450 # TODO: If we get global transform api, use that instead of parsing manually.
451 if "translate" in transform:
452 transform = transform.replace('translate(', '')
453 for c in transform[:-1].split(" "):
454 if "," in c:
455 c = c.replace(",", "")
456 coord.append(float(c))
457 if len(coord) < 2:
458 coord.append(coord[0])
459 adjust = QTransform(1, 0, 0, 1, coord[0], coord[1])
460 if "matrix" in transform:
461 transform = transform.replace('matrix(', '')
462 for c in transform[:-1].split(" "):
463 if "," in c:
464 c = c.replace(",", "")
465 coord.append(float(c))
466 adjust = QTransform(coord[0], coord[1], coord[2], coord[3], coord[4], coord[5])
467 path = QPainterPath()
468 if docElem.localName == "path":
469 dVal = docElem.getAttribute("d")
470 listOfSvgStrings = [" "]
471 listOfSvgStrings = svgRegExp.findall(dVal)
472 if listOfSvgStrings:
473 listOfPoints = []
474 for l in listOfSvgStrings:
475 line = l[1:]
476 coordinates = line.split(" ")
477 if len(coordinates) < 2:
478 coordinates.append(coordinates[0])
479 x = float(coordinates[-2])
480 y = float(coordinates[-1])
481 offset = QPointF()
482 if l.islower():
483 offset = listOfPoints[0]
484 if l.lower().startswith("m"):
485 path.moveTo(QPointF(x, y) + offset)
486 elif l.lower().startswith("h"):
487 y = listOfPoints[-1].y()
488 path.lineTo(QPointF(x, y) + offset)
489 elif l.lower().startswith("v"):
490 x = listOfPoints[-1].x()
491 path.lineTo(QPointF(x, y) + offset)
492 elif l.lower().startswith("c"):
493 path.cubicTo(coordinates[0], coordinates[1], coordinates[2], coordinates[3], x, y)
494 else:
495 path.lineTo(QPointF(x, y) + offset)
496 path.setFillRule(Qt.FillRule.WindingFill)
497 for polygon in path.simplified().toSubpathPolygons(adjust):
498 for point in polygon:
499 listOfPoints.append(point)
500 elif docElem.localName == "rect":
501 listOfPoints = []
502 if (docElem.hasAttribute("x")):
503 x = float(docElem.getAttribute("x"))
504 else:
505 x = 0
506 if (docElem.hasAttribute("y")):
507 y = float(docElem.getAttribute("y"))
508 else:
509 y = 0
510 w = float(docElem.getAttribute("width"))
511 h = float(docElem.getAttribute("height"))
512 path.addRect(QRectF(x, y, w, h))
513 for point in path.toFillPolygon(adjust):
514 listOfPoints.append(point)
515 elif docElem.localName == "ellipse":
516 listOfPoints = []
517 if (docElem.hasAttribute("cx")):
518 x = float(docElem.getAttribute("cx"))
519 else:
520 x = 0
521 if (docElem.hasAttribute("cy")):
522 y = float(docElem.getAttribute("cy"))
523 else:
524 y = 0
525 ry = float(docElem.getAttribute("ry"))
526 rx = float(docElem.getAttribute("rx"))
527 path.addEllipse(QPointF(x, y), rx, ry)
528 for point in path.toFillPolygon(adjust):
529 listOfPoints.append(point)
530 elif docElem.localName == "text":
531 # NOTE: This only works for horizontal preformated text. Vertical text needs a different
532 # ordering of the rects, and wraparound should try to take the shape it is wrapped in.
533 family = "sans-serif"
534 if docElem.hasAttribute("font-family"):
535 family = docElem.getAttribute("font-family")
536 size = "11"
537 if docElem.hasAttribute("font-size"):
538 size = docElem.getAttribute("font-size")
539 multilineText = True
540 for el in docElem.childNodes:
541 if el.nodeType == minidom.Node.TEXT_NODE:
542 multilineText = False
543 if multilineText:
544 listOfPoints = []
545 listOfRects = []
546
547 # First we collect all the possible line-rects.
548 for el in docElem.childNodes:
549 if docElem.hasAttribute("font-family"):
550 family = docElem.getAttribute("font-family")
551 if docElem.hasAttribute("font-size"):
552 size = docElem.getAttribute("font-size")
553 fontsize = int(size)
554 font = QFont(family, fontsize)
555 string = el.toxml()
556 string = re.sub(r"<.*?>", " ", string)
557 string = string.replace(" ", " ")
558 width = min(QFontMetrics(font).horizontalAdvance(string.strip()), rect.width())
559 height = QFontMetrics(font).height()
560 anchor = "start"
561 if docElem.hasAttribute("text-anchor"):
562 anchor = docElem.getAttribute("text-anchor")
563 top = rect.top()
564 if len(listOfRects)>0:
565 top = listOfRects[-1].bottom()
566 if anchor == "start":
567 spanRect = QRectF(rect.left(), top, width, height)
568 listOfRects.append(spanRect)
569 elif anchor == "end":
570 spanRect = QRectF(rect.right()-width, top, width, height)
571 listOfRects.append(spanRect)
572 else:
573 # Middle
574 spanRect = QRectF(rect.center().x()-(width*0.5), top, width, height)
575 listOfRects.append(spanRect)
576 # Now we have all the rects, we can check each and draw a
577 # polygon around them.
578 heightAdjust = (rect.height()-(listOfRects[-1].bottom()-rect.top()))/len(listOfRects)
579 for i in range(len(listOfRects)):
580 span = listOfRects[i]
581 addtionalHeight = i*heightAdjust
582 if i == 0:
583 listOfPoints.append(span.topLeft())
584 listOfPoints.append(span.topRight())
585 else:
586 if listOfRects[i-1].width()< span.width():
587 listOfPoints.append(QPointF(span.right(), span.top()+addtionalHeight))
588 listOfPoints.insert(0, QPointF(span.left(), span.top()+addtionalHeight))
589 else:
590 bottom = listOfRects[i-1].bottom()+addtionalHeight-heightAdjust
591 listOfPoints.append(QPointF(listOfRects[i-1].right(), bottom))
592 listOfPoints.insert(0, QPointF(listOfRects[i-1].left(), bottom))
593 listOfPoints.append(QPointF(span.right(), rect.bottom()))
594 listOfPoints.insert(0, QPointF(span.left(), rect.bottom()))
595 path = QPainterPath()
596 path.moveTo(listOfPoints[0])
597 for p in range(1, len(listOfPoints)):
598 path.lineTo(listOfPoints[p])
599 path.closeSubpath()
600 listOfPoints = []
601 for point in path.toFillPolygon(adjust):
602 listOfPoints.append(point)
603 shapeDesc["boundingBox"] = listOfPoints
604 if (shape.type() == "KoSvgTextShapeID" and textOnly is True):
605 shapeDesc["text"] = shape.toSvg()
606 list.append(shapeDesc)
607 """
608

◆ package_cbz()

comics_project_management_tools.comics_exporter.comicsExporter.package_cbz ( self,
exportPath )

Definition at line 631 of file comics_exporter.py.

631 def package_cbz(self, exportPath):
632
633 # Use the project name if there's no title to avoid sillyness with unnamed zipfiles.
634 title = self.configDictionary["projectName"]
635 if "title" in self.configDictionary.keys():
636 title = str(self.configDictionary["title"]).replace(" ", "_")
637
638 # Get the appropriate path.
639 url = str(exportPath / str(title + ".cbz"))
640
641 # Create a zip file.
642 cbzArchive = zipfile.ZipFile(url, mode="w", compression=zipfile.ZIP_STORED)
643
644 # Add all the meta data files.
645 cbzArchive.write(self.acbfLocation, Path(self.acbfLocation).name)
646 cbzArchive.write(self.cometLocation, Path(self.cometLocation).name)
647 cbzArchive.write(self.comicRackInfo, Path(self.comicRackInfo).name)
648 comic_book_info_json_dump = str()
649 self.progress.setLabelText(i18n("Saving out Comicbook\ninfo metadata file"))
650 self.progress.setValue(self.progress.value()+1)
651 comic_book_info_json_dump = exporters.comic_book_info.writeJson(self.configDictionary)
652 cbzArchive.comment = comic_book_info_json_dump.encode("utf-8")
653
654 # Add the pages.
655 if "CBZ" in self.pagesLocationList.keys():
656 for page in self.pagesLocationList["CBZ"]:
657 if (Path(page).exists()):
658 cbzArchive.write(page, Path(page).name)
659 self.progress.setLabelText(i18n("Packaging CBZ"))
660 self.progress.setValue(self.progress.value()+1)
661 # Close the zip file when done.
662 cbzArchive.close()

References comics_project_management_tools.comics_exporter.comicsExporter.acbfLocation, comics_project_management_tools.comics_exporter.comicsExporter.cometLocation, comics_project_management_tools.comics_exporter.comicsExporter.comicRackInfo, comics_project_management_tools.comics_exporter.comicsExporter.configDictionary, comics_project_management_tools.comics_exporter.comicsExporter.pagesLocationList, KisCageTransformWorker.progress, KisLiquifyTransformWorker.progress, KisAsyncActionFeedback::Private.progress, KoUpdater.progress(), KoUpdaterPrivate.progress(), KisPNGConverter.progress(), comics_project_management_tools.comics_exporter.comicsExporter.progress, and value().

◆ parseTime()

comics_project_management_tools.comics_exporter.comicsExporter.parseTime ( self,
time = 0 )

Definition at line 406 of file comics_exporter.py.

406 def parseTime(self, time = 0):
407 timeList = []
408 timeList.append(str(int(time / 60000)))
409 timeList.append(format(int((time%60000) / 1000), "02d"))
410 timeList.append(format(int(time % 1000), "03d"))
411 return ":".join(timeList)

◆ removeLayers()

comics_project_management_tools.comics_exporter.comicsExporter.removeLayers ( self,
labels,
node )

Definition at line 615 of file comics_exporter.py.

615 def removeLayers(self, labels, node):
616 deleteList = []
617 if node.colorLabel() in labels:
618 node.remove()
619 deleteList.append(node)
620 else:
621 if node.childNodes():
622 for child in node.childNodes():
623 self.removeLayers(labels, node=child)
624 for node in deleteList:
625 del node
626

References comics_project_management_tools.comics_exporter.comicsExporter.removeLayers().

◆ save_out_pngs()

comics_project_management_tools.comics_exporter.comicsExporter.save_out_pngs ( self,
sizesList )

Definition at line 203 of file comics_exporter.py.

203 def save_out_pngs(self, sizesList):
204 # A small fix to ensure crop to guides is set.
205 if "cropToGuides" not in self.configDictionary.keys():
206 self.configDictionary["cropToGuides"] = False
207
208 # Check if we have pages at all...
209 if "pages" in self.configDictionary.keys():
210
211 # Check if there's export methods, and if so make sure the appropriate dictionaries are initialised.
212 if len(sizesList.keys()) < 1:
213 QMessageBox.warning(None, i18n("Export not Possible"), i18n("Export failed because there's no export settings configured."), QMessageBox.StandardButton.Ok)
214 print("CPMT: Export failed because there's no export methods set.")
215 return False
216 else:
217 for key in sizesList.keys():
218 self.pagesLocationList[key] = []
219
220 # Get the appropriate paths.
221 path = Path(self.projectURL)
222 exportPath = path / self.configDictionary["exportLocation"]
223 pagesList = self.configDictionary["pages"]
224 fileName = str(exportPath)
225
226 """
227 Mini function to handle the setup of this string.
228 """
229 def timeString(timePassed, timeEstimated):
230 return str(i18n("Time passed: {passedString}\n Estimated: {estimated}")).format(passedString=timePassed, estimated=timeEstimated)
231
232 for p in range(0, len(pagesList)):
233 pagesDone = str(i18n("{pages} of {pagesTotal} done.")).format(pages=p, pagesTotal=len(pagesList))
234
235 # Update the label in the progress dialog.
236 self.progress.setValue(p)
237 timePassed = self.timer.elapsed()
238 if p > 0:
239 timeEstimated = (len(pagesList) - p) * (timePassed / p)
240 estimatedString = self.parseTime(timeEstimated)
241 else:
242 estimatedString = str(u"\u221E")
243 passedString = self.parseTime(timePassed)
244 self.progress.setLabelText("\n".join([pagesDone, timeString(passedString, estimatedString), i18n("Opening next page")]))
245 QApplication.instance().processEvents()
246 # Get the appropriate url and open the page.
247 url = str(Path(self.projectURL) / pagesList[p])
248 page = Application.openDocument(url)
249 page.waitForDone()
250
251 # Update the progress bar a little
252 self.progress.setLabelText("\n".join([pagesDone, timeString(self.parseTime(self.timer.elapsed()), estimatedString), i18n("Cleaning up page")]))
253
254 # remove layers and flatten.
255 labelList = self.configDictionary["labelsToRemove"]
256 panelsAndText = []
257
258 # These three lines are what is causing the page not to close.
259 root = page.rootNode()
260 self.getPanelsAndText(root, panelsAndText)
261 self.removeLayers(labelList, root)
262 page.refreshProjection()
263 # We'll need the offset and scale for aligning the panels and text correctly. We're getting this from the CBZ
264
265 pageData = {}
266 pageData["vector"] = panelsAndText
267 tree = ET.fromstring(page.documentInfo())
268 pageData["title"] = page.name()
269 calligra = "{http://www.calligra.org/DTD/document-info}"
270 about = tree.find(calligra + "about")
271 keywords = about.find(calligra + "keyword")
272 keys = str(keywords.text).split(",")
273 pKeys = []
274 for key in keys:
275 if key in self.pageKeys:
276 pKeys.append(key)
277 pageData["keys"] = pKeys
278 page.flatten()
279 page.waitForDone()
280 batchsave = Application.batchmode()
281 Application.setBatchmode(True)
282 # Start making the format specific copy.
283 for key in sizesList.keys():
284
285 # Update the progress bar a little
286 self.progress.setLabelText("\n".join([pagesDone, timeString(self.parseTime(self.timer.elapsed()), estimatedString), str(i18n("Exporting for {key}")).format(key=key)]))
287
288 w = sizesList[key]
289 # copy over data
290 projection = page.clone()
291 projection.setBatchmode(True)
292 # Crop. Cropping per guide only happens if said guides have been found.
293 if w["Crop"] is True:
294 listHGuides = []
295 listHGuides = page.guidesConfig().horizontalGuides()
296 listHGuides.sort()
297 for i in range(len(listHGuides) - 1, 0, -1):
298 if listHGuides[i] < 0 or listHGuides[i] > page.height():
299 listHGuides.pop(i)
300 listVGuides = page.guidesConfig().verticalGuides()
301 listVGuides.sort()
302 for i in range(len(listVGuides) - 1, 0, -1):
303 if listVGuides[i] < 0 or listVGuides[i] > page.width():
304 listVGuides.pop(i)
305 if self.configDictionary["cropToGuides"] and len(listVGuides) > 1:
306 cropx = listVGuides[0]
307 cropw = listVGuides[-1] - cropx
308 else:
309 cropx = self.configDictionary["cropLeft"]
310 cropw = page.width() - self.configDictionary["cropRight"] - cropx
311 if self.configDictionary["cropToGuides"] and len(listHGuides) > 1:
312 cropy = listHGuides[0]
313 croph = listHGuides[-1] - cropy
314 else:
315 cropy = self.configDictionary["cropTop"]
316 croph = page.height() - self.configDictionary["cropBottom"] - cropy
317 projection.crop(int(cropx), int(cropy), int(cropw), int(croph))
318 projection.waitForDone()
319 QApplication.instance().processEvents()
320 # resize appropriately
321 else:
322 cropx = 0
323 cropy = 0
324 res = page.resolution()
325 listScales = [projection.width(), projection.height(), res, res]
326 projectionOldSize = [projection.width(), projection.height()]
327 sizesCalc = sizesCalculator()
328 listScales = sizesCalc.get_scale_from_resize_config(config=w, listSizes=listScales)
329 projection.scaleImage(listScales[0], listScales[1], listScales[2], listScales[3], "bicubic")
330 projection.waitForDone()
331 QApplication.instance().processEvents()
332 # png, gif and other webformats should probably be in 8bit srgb at maximum.
333 if key != "TIFF":
334 if (projection.colorModel() != "RGBA" and projection.colorModel() != "GRAYA") or projection.colorDepth() != "U8":
335 projection.setColorSpace("RGBA", "U8", "sRGB built-in")
336 else:
337 # Tiff on the other hand can handle all the colormodels, but can only handle integer bit depths.
338 # Tiff is intended for print output, and 16 bit integer will be sufficient.
339 if projection.colorDepth() != "U8" or projection.colorDepth() != "U16":
340 projection.setColorSpace(page.colorModel(), "U16", page.colorProfile())
341 # save
342 # Make sure the folder name for this export exists. It'll allow us to keep the
343 # export folders nice and clean.
344 folderName = str(key + "-" + w["FileType"])
345 if Path(exportPath / folderName).exists() is False:
346 Path.mkdir(exportPath / folderName)
347 # Get a nice and descriptive file name.
348 fn = str(Path(exportPath / folderName) / str("page_" + format(p, "03d") + "_" + str(listScales[0]) + "x" + str(listScales[1]) + "." + w["FileType"]))
349 # Finally save and add the page to a list of pages. This will make it easy for the packaging function to
350 # find the pages and store them.
351 projection.exportImage(fn, InfoObject())
352 projection.waitForDone()
353 QApplication.instance().processEvents()
354 if key == "CBZ" or key == "EPUB":
355 transform = {}
356 transform["offsetX"] = cropx
357 transform["offsetY"] = cropy
358 transform["resDiff"] = page.resolution() / 72
359 transform["scaleWidth"] = projection.width() / projectionOldSize[0]
360 transform["scaleHeight"] = projection.height() / projectionOldSize[1]
361 pageData["transform"] = transform
362 self.pagesLocationList[key].append(fn)
363 projection.close()
364 self.acbfPageData.append(pageData)
365 page.close()
366 self.progress.setValue(len(pagesList))
367 Application.setBatchmode(batchsave)
368 # TODO: Check what or whether memory leaks are still caused and otherwise remove the entry below.
369 print("CPMT: Export has finished. If there are memory leaks, they are caused by file layers.")
370 return True
371 print("CPMT: Export not happening because there aren't any pages.")
372 QMessageBox.warning(None, i18n("Export not Possible"), i18n("Export not happening because there are no pages."), QMessageBox.StandardButton.Ok)
373 return False
374

References comics_project_management_tools.comics_exporter.comicsExporter.acbfPageData, comics_project_management_tools.comics_exporter.comicsExporter.configDictionary, comics_project_management_tools.comics_exporter.comicsExporter.getPanelsAndText(), comics_project_management_tools.comics_exporter.comicsExporter.pageKeys, comics_project_management_tools.comics_exporter.comicsExporter.pagesLocationList, comics_project_management_tools.comics_exporter.comicsExporter.parseTime(), KisCageTransformWorker.progress, KisLiquifyTransformWorker.progress, KisAsyncActionFeedback::Private.progress, KoUpdater.progress(), KoUpdaterPrivate.progress(), KisPNGConverter.progress(), comics_project_management_tools.comics_exporter.comicsExporter.progress, comics_project_management_tools.comics_exporter.comicsExporter.projectURL, comics_project_management_tools.comics_project_translation_scraper.translation_scraper.projectURL, comics_project_management_tools.comics_exporter.comicsExporter.removeLayers(), KisBusyProgressIndicator::Private.timer, KisQueuesProgressUpdater.timer, KisTimedSignalThreshold::Private.timer, KisAnimationCachePopulator::Private.timer, KisSpeedSmoother::Private.timer, KoItemToolTip.timer, RecorderWriterManager::Private.timer, and comics_project_management_tools.comics_exporter.comicsExporter.timer.

◆ set_config()

comics_project_management_tools.comics_exporter.comicsExporter.set_config ( self,
config,
projectURL )

Definition at line 98 of file comics_exporter.py.

98 def set_config(self, config, projectURL):
99 self.configDictionary = config
100 self.projectURL = projectURL
101 self.pagesLocationList = {}
102 self.acbfLocation = str()
103 self.acbfPageData = []
104 self.cometLocation = str()
105 self.comicRackInfo = str()
106

Member Data Documentation

◆ acbfLocation

comics_project_management_tools.comics_exporter.comicsExporter.acbfLocation = str()
static

Definition at line 78 of file comics_exporter.py.

◆ acbfPageData [1/2]

list comics_project_management_tools.comics_exporter.comicsExporter.acbfPageData = []
static

Definition at line 79 of file comics_exporter.py.

◆ acbfPageData [2/2]

comics_project_management_tools.comics_exporter.comicsExporter.acbfPageData

Definition at line 103 of file comics_exporter.py.

◆ cometLocation

comics_project_management_tools.comics_exporter.comicsExporter.cometLocation = str()
static

Definition at line 80 of file comics_exporter.py.

◆ comicRackInfo

comics_project_management_tools.comics_exporter.comicsExporter.comicRackInfo = str()
static

Definition at line 81 of file comics_exporter.py.

◆ configDictionary

comics_project_management_tools.comics_exporter.comicsExporter.configDictionary

Definition at line 99 of file comics_exporter.py.

◆ pageKeys

list comics_project_management_tools.comics_exporter.comicsExporter.pageKeys = ["acbf_title", "acbf_none", "acbf_fade", "acbf_blend", "acbf_horizontal", "acbf_vertical", "epub_spread"]
static

Definition at line 85 of file comics_exporter.py.

◆ pagesLocationList [1/2]

dict comics_project_management_tools.comics_exporter.comicsExporter.pagesLocationList = {}
static

Definition at line 82 of file comics_exporter.py.

◆ pagesLocationList [2/2]

comics_project_management_tools.comics_exporter.comicsExporter.pagesLocationList

Definition at line 101 of file comics_exporter.py.

◆ progress

comics_project_management_tools.comics_exporter.comicsExporter.progress

Definition at line 144 of file comics_exporter.py.

◆ projectURL

comics_project_management_tools.comics_exporter.comicsExporter.projectURL

Definition at line 100 of file comics_exporter.py.

◆ timer

comics_project_management_tools.comics_exporter.comicsExporter.timer

Definition at line 147 of file comics_exporter.py.


The documentation for this class was generated from the following file: