Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cfcurtis committed Aug 12, 2024
2 parents 398579b + 5ef0f0e commit 213c6b8
Show file tree
Hide file tree
Showing 25 changed files with 1,064 additions and 1,044 deletions.
2 changes: 1 addition & 1 deletion build/update_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def update():

def compile():
print("**compile**")
run(f"pybabel compile -D pdfstitcher -d {locale_path}", shell=True)
run(f"pybabel compile --use-fuzzy -D pdfstitcher -d {locale_path}", shell=True)


if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion pdfstitcher/gui/main_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def __init__(self, *args, **kw):
self.splitter.SplitHorizontally(nb, pnl)
self.splitter.SetMinimumPaneSize(40)

self.main_process = MainProcess()
warning_win = wx.MessageDialog(self, message="", style=wx.OK | wx.ICON_WARNING)
self.main_process = MainProcess(warning_win=warning_win)

self.make_menu_bar()
# connect the on_close event
Expand Down
6 changes: 3 additions & 3 deletions pdfstitcher/processing/mainproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def __init__(self, *args, **kw) -> None:
super().__init__(*args, **kw)

self.pipeline = {
"LayerFilter": LayerFilter(),
"PageTiler": PageTiler(),
"PageFilter": PageFilter(),
"LayerFilter": LayerFilter(warning_win=self.warning_win),
"PageTiler": PageTiler(warning_win=self.warning_win),
"PageFilter": PageFilter(warning_win=self.warning_win),
}
self.active = {
"LayerFilter": False,
Expand Down
5 changes: 4 additions & 1 deletion pdfstitcher/processing/pagefilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ def run(self, **kwargs) -> None:
float(self.out_doc.pages[-1].MediaBox[3]) + margin,
]
print(_("Page" + f" {p}: "), end="")
utils.print_media_box(media_box, user_unit)

size_warning = utils.print_media_box(media_box, user_unit)
if size_warning:
self._warn(size_warning)

self.out_doc.pages[-1].MediaBox = media_box
self.out_doc.pages[-1].CropBox = media_box
Expand Down
12 changes: 7 additions & 5 deletions pdfstitcher/processing/pagetiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ def _build_pagelist(self) -> tuple:
prev_height = info[-1]["height"]

if len(different_size) > 0:
print(
_("Warning: The pages {} have a different size than the page before").format(
self._warn(
_("Warning: pages {} have a different size than the page before").format(
different_size
)
)
Expand Down Expand Up @@ -345,7 +345,7 @@ def _calc_rows_cols(self, n_tiles: int) -> bool:
self.cols = self.p["cols"]
self.rows = math.ceil(n_tiles / self.cols)
if self.rows == 1 and self.cols > n_tiles:
print(
self._warn(
_("Warning: requested {} columns, but there are only {} pages").format(
self.cols, n_tiles
)
Expand All @@ -356,7 +356,7 @@ def _calc_rows_cols(self, n_tiles: int) -> bool:
self.rows = self.p["rows"]
self.cols = math.ceil(n_tiles / self.rows)
if self.cols == 1 and self.rows > n_tiles:
print(
self._warn(
_("Warning: requested {} rows, but there are only {} pages").format(
self.rows, n_tiles
)
Expand Down Expand Up @@ -642,7 +642,9 @@ def run(self, progress_win=None) -> bool:
dims[1] + margin,
]

utils.print_media_box(media_box, self.output_uu)
size_warning = utils.print_media_box(media_box, self.output_uu)
if size_warning:
self._warn(size_warning)

# add the new page to the document
tiled_page = pikepdf.Dictionary(
Expand Down
16 changes: 15 additions & 1 deletion pdfstitcher/processing/procbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class ProcessingBase(ABC):
Base class for processing units.
"""

def __init__(self, params: dict = {}, doc: Union[Pdf, str, Path] = None) -> None:
def __init__(
self, params: dict = {}, doc: Union[Pdf, str, Path] = None, warning_win=None
) -> None:
self.p = None
self._in_doc = None
self._page_range = None
Expand All @@ -27,6 +29,7 @@ def __init__(self, params: dict = {}, doc: Union[Pdf, str, Path] = None) -> None

# keep track of whether the unit needs to run
self.needs_run = True
self.warning_win = warning_win

# ---------------------------------------------------------------------
# Property getters and setters
Expand Down Expand Up @@ -112,6 +115,17 @@ def _validate_page_range(self) -> None:
print(_("Page {} is out of range. Removing from page list.".format(p)))
self._page_range.remove(p)

def _warn(self, message: str) -> None:
"""
Displays a warning message to the user.
Assumes either a wx.MessageDialog or console output.
"""
if self.warning_win:
self.warning_win.SetMessage(message)
self.warning_win.ShowModal()
else:
print(message)

def load_doc(self, doc: Union[Pdf, str, Path], password: str = "") -> None:
if isinstance(doc, Pdf):
self.in_doc = doc
Expand Down
19 changes: 8 additions & 11 deletions pdfstitcher/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import sys
import os
from typing import Union
import pikepdf
from enum import IntEnum

Expand Down Expand Up @@ -344,23 +345,13 @@ def get_page_dims(
return page_width, page_height


def print_media_box(media_box, user_unit: float = 1) -> None:
def print_media_box(media_box, user_unit: float = 1) -> Union[None, str]:
"""
Display the media box in the requested units.
Also checks to see if the size exceeds Adobe's max size.
"""
width = abs(float(media_box[2]) - float(media_box[0]))
height = abs(float(media_box[3]) - float(media_box[1]))
if width > MAX_SIZE_PX or height > MAX_SIZE_PX:
# check if it exceeds Adobe's 200 inch maximum size
print(62 * "*")
print(
_("Warning! Output is larger than {} {}, may not open correctly.").format(
round(Config.general["units"].pts_to_units(MAX_SIZE_PX, user_unit)),
Config.general["units"],
)
)
print(62 * "*")
# just print it out for info
print(
_("Output size:")
Expand All @@ -370,6 +361,12 @@ def print_media_box(media_box, user_unit: float = 1) -> None:
Config.general["units"],
)
)
if width > MAX_SIZE_PX or height > MAX_SIZE_PX:
# check if it exceeds Adobe's 200 inch maximum size
return _("Warning! Output is larger than {} {}, may not open correctly.").format(
round(Config.general["units"].pts_to_units(MAX_SIZE_PX, user_unit)),
Config.general["units"],
)


def normalize_boxes(page: pikepdf.Page) -> None:
Expand Down
Loading

0 comments on commit 213c6b8

Please sign in to comment.