Skip to content

Commit

Permalink
Replace pyinstaller with cx-freeze (#7)
Browse files Browse the repository at this point in the history
* create setup.py

* update readme

* modify setup.py

* use latest version

* include missing files

* fix incorrect order

* update README

* add jpeg to allowed extensions

* fix console
  • Loading branch information
lukaszKielar authored Apr 20, 2021
1 parent 26cb192 commit 7353465
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 72 deletions.
16 changes: 8 additions & 8 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ verify_ssl = true
name = "pypi"

[packages]
pypdf4 = "~=1.27.0"
pyinstaller = ">=4.2"
pyqt5 = "~=5.15.2"
qdarkstyle = "~=2.8.1"
pillow = "~=8.2.0"
pypdf4 = "*"
pyqt5 = "*"
qdarkstyle = "*"
pillow = "*"

[dev-packages]
pylint = ">=2.6.0"
mypy = ">=0.800"
black = ">=20.8b1"
pylint = "*"
mypy = "*"
black = "*"
rope = "*"
isort = "*"
cx-freeze = "*"

[requires]
python_version = "3.8"
Expand Down
112 changes: 56 additions & 56 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ Simple Python tool for merging PDF files on a local machine.
```bash
git clone [email protected]:lukaszKielar/merge-pdfs.git
cd merge-pdfs

python -m venv ./.venv

# adding --pre due to black version https://github.com/microsoft/vscode-python/issues/5171
pipenv install --pre
pipenv install --dev
```

## Building process

### Create installer

```bash
python setup.py bdist_msi
```

### Create executable

```bash
pyinstaller --noconsole --onefile --windowed --name MergePDFs .\merge_pdfs\gui\app.py
python setup.py build
```
3 changes: 2 additions & 1 deletion merge_pdfs/backend/pdf_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ def merge_files(self, *files: List[Union[str, Path]]) -> None:
self._merger.append(f)

def save(self, out_path: Union[str, Path]) -> Path:
logger.debug("Saving '%s' file", out_path)
# add extension if doesn't exist
if not str(out_path).lower().endswith(".pdf"):
out_path += ".pdf"

logger.debug("Saving '%s' file", out_path)

with open(out_path, "wb") as fd:
self._merger.write(fd)

Expand Down
9 changes: 7 additions & 2 deletions merge_pdfs/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def addItemsFromDialog(self):
self,
"Add file(s)",
openDir,
"PDF Files (*.pdf);;Images (*.png *.jpg)",
"PDF Files (*.pdf);;Images (*.png *.jpg *.jpeg)",
options=QFileDialog.DontUseNativeDialog,
)

Expand Down Expand Up @@ -141,8 +141,13 @@ def saveFile(self):
if not newFile:
return

# make sure files will be saved in correct order
# save as they appear in the UI
orderedKeys = [self.item(item).text() for item in range(self.count())]
orteredValues = [self._addedFiles[key] for key in orderedKeys]

pdfWriter = PDFWriter()
pdfWriter.merge_files(*self._addedFiles.values())
pdfWriter.merge_files(*orteredValues)
pdfWriter.save(newFile)

QMessageBox.information(
Expand Down
26 changes: 26 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
import sys

import PyQt5
from cx_Freeze import Executable, setup

base = "Win32GUI" if sys.platform == "win32" else None
include_files = [
os.path.join(os.path.dirname(PyQt5.__file__), "Qt5", "plugins"),
"c:\windows\syswow64\MSVCR100.dll",
"c:\windows\syswow64\MSVCP100.dll",
]

setup(
name="merge_pdfs",
version="0.0.1",
author="Lukasz Kielar",
description="Tool for merging PDF files without sending them over the Network",
executables=[Executable("merge_pdfs/gui/app.py", base=base)],
options={
"build_exe": {
"packages": ["PyQt5.QtCore", "PyQt5.QtGui", "PyQt5.QtWidgets"],
"include_files": include_files,
}
},
)

0 comments on commit 7353465

Please sign in to comment.