Skip to content

Commit eb7cace

Browse files
committed
Linting, some documentation, updated README
1 parent 53047ae commit eb7cace

2 files changed

Lines changed: 25 additions & 13 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
5151

5252
- [X] Join Tab Functionality
5353
- [X] Split Tab Functionality
54-
- [ ] Refactor to avoid code repetition in save, file info, etc methods
54+
- [X] Refactor to avoid code repetition in save, file info, etc methods
5555
- [ ] User Documentation (mostly self-explanatory)
5656
- [ ] Developer Documentation
5757
- [ ] Write tests
5858
- [ ] Error checking user input
5959
- [ ] Error/Exception Handling
6060
- [ ] Failover to system PDF Tools (e.g. Poppler)
61-
- [ ] Stamp/Background/Number Tab
61+
- [X] Stamp/Background/Number Tab
6262
- [X] Rotate Pages
6363
- [X] Menus
64-
- [ ] Persistent User Settings
64+
- [X] Persistent User Settings
6565
- [ ] Package via pyInstaller
6666
- [ ] Distribution via Releases on GitHub

pypdfbuilder.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,12 @@ def __save_user_data(self):
9797
print('Something went horribly wrong while trying to save your current user data.')
9898

9999
def save_success(self):
100+
'''Gets called when a PDF file was processed successfully. Currently only
101+
increases the `number_of_processed_files´-counter by 1
102+
'''
100103
self.number_of_processed_files += 1
101104

102105

103-
104-
105106
class PDFInfo:
106107
'''File info class for PDF files.
107108
@@ -111,6 +112,7 @@ class PDFInfo:
111112
Args:
112113
filepath (str): Path to PDF File
113114
'''
115+
114116
def __init__(self, filepath):
115117
self.__filepath = filepath
116118

@@ -176,14 +178,16 @@ def parent(self, val):
176178
self.__parent = val
177179

178180
def choose_source_file(self):
179-
choose_source_file = self.parent.get_file_dialog(func=filedialog.askopenfilename, widget_title='Choose Source PDF …')
181+
choose_source_file = self.parent.get_file_dialog(
182+
func=filedialog.askopenfilename, widget_title='Choose Source PDF …')
180183
if choose_source_file:
181184
self.__source_filepath = choose_source_file
182185
self.__source_file_info = PDFInfo(self.__source_filepath)
183186
self.__show_source_file_info()
184187

185188
def choose_bg_file(self):
186-
choose_bg_file = self.parent.get_file_dialog(func=filedialog.askopenfilename, widget_title='Choose Background PDF …')
189+
choose_bg_file = self.parent.get_file_dialog(
190+
func=filedialog.askopenfilename, widget_title='Choose Background PDF …')
187191
if choose_bg_file:
188192
self.__bg_filepath = choose_bg_file
189193
self.__bg_file_info = PDFInfo(self.__bg_filepath)
@@ -209,7 +213,7 @@ def save_as(self):
209213
out_pdf = PdfFileWriter()
210214
command = self.__bg_command.get()
211215
with open(self.__source_filepath, "rb") as source_pdf_stream, \
212-
open(self.__bg_filepath, "rb") as bg_pdf_stream:
216+
open(self.__bg_filepath, "rb") as bg_pdf_stream:
213217
for p in range(self.__source_file_info.pages):
214218
# new PdfFileReader instances needed for every page merged. See here:
215219
# https://github.com/mstamy2/PyPDF2/issues/100#issuecomment-43145634
@@ -239,6 +243,7 @@ class SplitTabManager:
239243
Args:
240244
parent (PyPDFBuilderApplication): Application that created the instance and that contains the Split Tab.
241245
'''
246+
242247
def __init__(self, parent=None):
243248
self.parent = parent
244249
self.__split_filepath = None
@@ -255,7 +260,8 @@ def parent(self, val):
255260
self.__parent = val
256261

257262
def open_file(self):
258-
choose_split_file = self.parent.get_file_dialog(func=filedialog.askopenfilename, widget_title='Choose PDF to Split…')
263+
choose_split_file = self.parent.get_file_dialog(
264+
func=filedialog.askopenfilename, widget_title='Choose PDF to Split…')
259265
if choose_split_file:
260266
self.__split_filepath = choose_split_file
261267
self.__split_file_info = PDFInfo(self.__split_filepath)
@@ -304,7 +310,8 @@ def parent(self, val):
304310
self.__parent = val
305311

306312
def open_file(self):
307-
chose_rotate_file = self.parent.get_file_dialog(func=filedialog.askopenfilename, widget_title='Choose PDF to Rotate…')
313+
chose_rotate_file = self.parent.get_file_dialog(
314+
func=filedialog.askopenfilename, widget_title='Choose PDF to Rotate…')
308315
if chose_rotate_file:
309316
self.__rotate_filepath = chose_rotate_file
310317
self.__rotate_file_info = PDFInfo(self.__rotate_filepath)
@@ -326,7 +333,8 @@ def save_as(self):
326333
out_pdf = PdfFileWriter()
327334
for p in range(self.__rotate_file_info.pages):
328335
if p in range(*page_range):
329-
out_pdf.addPage(in_pdf.getPage(p).rotateClockwise(ROTATE_DEGREES[self.__rotate_amount_widget.get()]))
336+
out_pdf.addPage(in_pdf.getPage(p).rotateClockwise(
337+
ROTATE_DEGREES[self.__rotate_amount_widget.get()]))
330338
else:
331339
out_pdf.addPage(in_pdf.getPage(p))
332340
with open(save_filepath, "wb") as out_pdf_stream:
@@ -406,7 +414,8 @@ def add_file(self):
406414

407415
def save_as(self):
408416
if len(self.__get_join_files()) > 0:
409-
save_filepath = self.parent.get_file_dialog(func=filedialog.asksaveasfilename, widget_title='Save Joined PDF to…')
417+
save_filepath = self.parent.get_file_dialog(
418+
func=filedialog.asksaveasfilename, widget_title='Save Joined PDF to…')
410419
if save_filepath:
411420
merger = PdfFileMerger()
412421
for f in self.__get_join_files():
@@ -433,7 +442,7 @@ def move_down(self):
433442
selected_files = list(reversed(self.__selected_files))
434443
last_idx = self.__files_tree_widget.index(selected_files[0])
435444
parent = self.__files_tree_widget.parent(selected_files[0])
436-
last_idx_in_widget = self.__files_tree_widget.index(self.__files_tree_widget.get_children()[-1])
445+
last_idx_in_widget = self.__files_tree_widget.index(self.__files_tree_widget.get_children()[-1])
437446
if last_idx < last_idx_in_widget:
438447
for f in selected_files:
439448
swap_item = self.__files_tree_widget.next(f)
@@ -478,10 +487,13 @@ def __init__(self):
478487
# boy oh boy if there's anyway to do these callsbacks more elegantly, please let me gain that knowledge!
479488
def select_tab_join(self, *args, **kwargs):
480489
self.notebook.select(self.tabs['join'])
490+
481491
def select_tab_split(self, *args, **kwargs):
482492
self.notebook.select(self.tabs['split'])
493+
483494
def select_tab_bg(self, *args, **kwargs):
484495
self.notebook.select(self.tabs['bg'])
496+
485497
def select_tab_rotate(self, *args, **kwargs):
486498
self.notebook.select(self.tabs['rotate'])
487499

0 commit comments

Comments
 (0)