Skip to content

Commit c65cab2

Browse files
committed
Status bar, some refactoring
1 parent 64adedc commit c65cab2

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

mainwindow.ui

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,8 @@
763763
</layout>
764764
<child>
765765
<object class="ttk.Label" id="StatusText">
766-
<property name="text" translatable="yes">PyPDF v0.1</property>
767-
<property name="textvariable">string:status_text</property>
766+
<property name="text" translatable="yes">PyPDF v1.0</property>
767+
<property name="textvariable">string:application_status_text</property>
768768
<layout>
769769
<property name="column">0</property>
770770
<property name="propagate">True</property>

pypdfbuilder.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,6 @@ def __save_user_data(self):
102102
except FileNotFoundError:
103103
print('Something went horribly wrong while trying to save your current user data.')
104104

105-
def save_success(self):
106-
'''Gets called when a PDF file was processed successfully. Currently only
107-
increases the `number_of_processed_files´-counter by 1
108-
'''
109-
self.number_of_processed_files += 1
110-
111105

112106
class PDFInfo:
113107
'''File info class for PDF files.
@@ -238,7 +232,7 @@ def save_as(self):
238232
out_pdf.addPage(bottom_page)
239233
with open(save_filepath, "wb") as out_pdf_stream:
240234
out_pdf.write(out_pdf_stream)
241-
self.parent.user_data.save_success()
235+
self.parent.save_success(status_text=BG_FILE_SUCCESS.format(os.path.basename(save_filepath)))
242236

243237

244238
class SplitTabManager:
@@ -289,7 +283,7 @@ def save_as(self):
289283
out_pdf.addPage(in_pdf.getPage(p))
290284
with open(output_path, "wb") as out_pdf_stream:
291285
out_pdf.write(out_pdf_stream)
292-
self.parent.user_data.save_success()
286+
self.parent.save_success(status_text=SPLIT_FILE_SUCCESS.format(os.path.dirname(self.__split_filepath)))
293287

294288

295289
class RotateTabManager:
@@ -345,7 +339,7 @@ def save_as(self):
345339
out_pdf.addPage(in_pdf.getPage(p))
346340
with open(save_filepath, "wb") as out_pdf_stream:
347341
out_pdf.write(out_pdf_stream)
348-
self.parent.user_data.save_success()
342+
self.parent.save_success(status_text=ROTATE_FILE_SUCCESS.format(os.path.basename(save_filepath)))
349343

350344

351345
class JoinTabManager:
@@ -432,7 +426,7 @@ def save_as(self):
432426
merger.append(fileobj=open(f[PDF_FILEPATH], 'rb'), pages=page_range)
433427
with open(save_filepath, 'wb') as out_pdf:
434428
merger.write(out_pdf)
435-
self.parent.user_data.save_success()
429+
self.parent.save_success(status_text=JOIN_FILE_SUCCESS.format(os.path.basename(save_filepath)))
436430

437431
def move_up(self):
438432
selected_files = self.__selected_files
@@ -462,6 +456,8 @@ def remove_file(self):
462456

463457

464458
class PyPDFBuilderApplication:
459+
'''Main application class. Handles setup and running of all application parts.'''
460+
465461
def __init__(self):
466462
self.builder = pgBuilder()
467463
self.builder.add_from_file(os.path.join(CURRENT_DIR, 'mainwindow.ui'))
@@ -475,10 +471,10 @@ def __init__(self):
475471
'bg': self.builder.get_object('BgFrame'),
476472
'rotate': self.builder.get_object('RotateFrame'),
477473
}
478-
479474
self.mainmenu = self.builder.get_object('MainMenu')
480475
self.mainwindow.config(menu=self.mainmenu)
481-
476+
self.__status_text_variable = self.builder.get_variable('application_status_text')
477+
self.status_text = None
482478
self.builder.connect_callbacks(self)
483479

484480
self.user_data = UserData()
@@ -489,6 +485,14 @@ def __init__(self):
489485
self.bgtab = BgTabManager(self)
490486
self.rotatetab = RotateTabManager(self)
491487

488+
@property
489+
def status_text(self):
490+
return self.__status_text_variable.get()
491+
492+
@status_text.setter
493+
def status_text(self, val):
494+
self.__status_text_variable.set(val)
495+
492496
# boy oh boy if there's anyway to do these callsbacks more elegantly, please let me gain that knowledge!
493497
def select_tab_join(self, *args, **kwargs):
494498
'''Gets called when menu item "View > Join Files" is selected.
@@ -565,6 +569,13 @@ def rotatetab_open_file(self):
565569
def rotatetab_save_as(self):
566570
self.rotatetab.save_as()
567571

572+
def save_success(self, status_text=DEFAULT_STATUS):
573+
'''Gets called when a PDF file was processed successfully. Currently only
574+
increases the `number_of_processed_files`-counter by 1
575+
'''
576+
self.user_data.number_of_processed_files += 1
577+
self.status_text = status_text
578+
568579
def show_settings(self, *args, **kwargs):
569580
'''Shows the settings dialog. The close event is handled by `self.close_settings()`
570581
and all the settings management is handled there. Args and kwargs are included in

settings.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@
66
PDF_PAGES = 3
77

88
ROTATE_DEGREES = {'LEFT': 270, 'RIGHT': 90, 'ONE_EIGHTY': 180}
9+
10+
11+
SPLIT_FILE_SUCCESS = 'Files saved successfully to {}!'
12+
JOIN_FILE_SUCCESS = 'Files joined successfully to {}!'
13+
ROTATE_FILE_SUCCESS = 'Pages in {} rotated successfully!'
14+
BG_FILE_SUCCESS = 'File saved successfully to {}!'
15+
DEFAULT_STATUS = 'PyPDF Builder v1.0'

0 commit comments

Comments
 (0)