206 if len(sizesList.keys()) < 1:
207 QMessageBox.warning(
None, i18n(
"Export not Possible"), i18n(
"Export failed because there's no export settings configured."), QMessageBox.StandardButton.Ok)
208 print(
"CPMT: Export failed because there's no export methods set.")
211 for key
in sizesList.keys():
218 fileName = str(exportPath)
221 Mini function to handle the setup of this string.
223 def timeString(timePassed, timeEstimated):
224 return str(i18n(
"Time passed: {passedString}\n Estimated: {estimated}")).format(passedString=timePassed, estimated=timeEstimated)
226 for p
in range(0, len(pagesList)):
227 pagesDone = str(i18n(
"{pages} of {pagesTotal} done.")).format(pages=p, pagesTotal=len(pagesList))
231 timePassed = self.
timer.elapsed()
233 timeEstimated = (len(pagesList) - p) * (timePassed / p)
234 estimatedString = self.
parseTime(timeEstimated)
236 estimatedString = str(
u"\u221E")
237 passedString = self.
parseTime(timePassed)
238 self.
progress.setLabelText(
"\n".join([pagesDone, timeString(passedString, estimatedString), i18n(
"Opening next page")]))
239 QApplication.instance().processEvents()
241 url = str(Path(self.
projectURL) / pagesList[p])
242 page = Application.openDocument(url)
246 self.
progress.setLabelText(
"\n".join([pagesDone, timeString(self.
parseTime(self.
timer.elapsed()), estimatedString), i18n(
"Cleaning up page")]))
253 root = page.rootNode()
256 page.refreshProjection()
260 pageData[
"vector"] = panelsAndText
261 tree = ET.fromstring(page.documentInfo())
262 pageData[
"title"] = page.name()
263 calligra =
"{http://www.calligra.org/DTD/document-info}"
264 about = tree.find(calligra +
"about")
265 keywords = about.find(calligra +
"keyword")
266 keys = str(keywords.text).split(
",")
271 pageData[
"keys"] = pKeys
274 batchsave = Application.batchmode()
275 Application.setBatchmode(
True)
277 for key
in sizesList.keys():
280 self.
progress.setLabelText(
"\n".join([pagesDone, timeString(self.
parseTime(self.
timer.elapsed()), estimatedString), str(i18n(
"Exporting for {key}")).format(key=key)]))
284 projection = page.clone()
285 projection.setBatchmode(
True)
287 if w[
"Crop"]
is True:
289 listHGuides = page.horizontalGuides()
291 for i
in range(len(listHGuides) - 1, 0, -1):
292 if listHGuides[i] < 0
or listHGuides[i] > page.height():
294 listVGuides = page.verticalGuides()
296 for i
in range(len(listVGuides) - 1, 0, -1):
297 if listVGuides[i] < 0
or listVGuides[i] > page.width():
300 cropx = listVGuides[0]
301 cropw = listVGuides[-1] - cropx
306 cropy = listHGuides[0]
307 croph = listHGuides[-1] - cropy
311 projection.crop(int(cropx), int(cropy), int(cropw), int(croph))
312 projection.waitForDone()
313 QApplication.instance().processEvents()
318 res = page.resolution()
319 listScales = [projection.width(), projection.height(), res, res]
320 projectionOldSize = [projection.width(), projection.height()]
322 listScales = sizesCalc.get_scale_from_resize_config(config=w, listSizes=listScales)
323 projection.scaleImage(listScales[0], listScales[1], listScales[2], listScales[3],
"bicubic")
324 projection.waitForDone()
325 QApplication.instance().processEvents()
328 if (projection.colorModel() !=
"RGBA" and projection.colorModel() !=
"GRAYA")
or projection.colorDepth() !=
"U8":
329 projection.setColorSpace(
"RGBA",
"U8",
"sRGB built-in")
333 if projection.colorDepth() !=
"U8" or projection.colorDepth() !=
"U16":
334 projection.setColorSpace(page.colorModel(),
"U16", page.colorProfile())
338 folderName = str(key +
"-" + w[
"FileType"])
339 if Path(exportPath / folderName).exists()
is False:
340 Path.mkdir(exportPath / folderName)
342 fn = str(Path(exportPath / folderName) / str(
"page_" + format(p,
"03d") +
"_" + str(listScales[0]) +
"x" + str(listScales[1]) +
"." + w[
"FileType"]))
345 projection.exportImage(fn, InfoObject())
346 projection.waitForDone()
347 QApplication.instance().processEvents()
348 if key ==
"CBZ" or key ==
"EPUB":
350 transform[
"offsetX"] = cropx
351 transform[
"offsetY"] = cropy
352 transform[
"resDiff"] = page.resolution() / 72
353 transform[
"scaleWidth"] = projection.width() / projectionOldSize[0]
354 transform[
"scaleHeight"] = projection.height() / projectionOldSize[1]
355 pageData[
"transform"] = transform
360 self.
progress.setValue(len(pagesList))
361 Application.setBatchmode(batchsave)
363 print(
"CPMT: Export has finished. If there are memory leaks, they are caused by file layers.")
365 print(
"CPMT: Export not happening because there aren't any pages.")
366 QMessageBox.warning(
None, i18n(
"Export not Possible"), i18n(
"Export not happening because there are no pages."), QMessageBox.StandardButton.Ok)