diff --git a/.gitignore b/.gitignore index 7d5bd24..e4a3f68 100644 --- a/.gitignore +++ b/.gitignore @@ -129,4 +129,12 @@ dmypy.json # Test output /tests/output/test_output.pdf -report.html \ No newline at end of file +report.html + +# PyCharm files +.idea/* + +# Extra files +.DS_Store +tests/.DS_Store +tests/data/.DS_Store diff --git a/pdf_merger/src/app.py b/pdf_merger/src/app.py index 0c81fb9..bf1fbd4 100644 --- a/pdf_merger/src/app.py +++ b/pdf_merger/src/app.py @@ -9,8 +9,9 @@ from PyQt5.QtWidgets import QHBoxLayout, QWidget, QMainWindow, QTabWidget, QApplication from pdf_merger.src.services import ImageMergerService, PdfMergerService -from pdf_merger.src.views import AppLayoutConfig, ViewAggregator -from pdf_merger.src.views.labels import Labels +from pdf_merger.src.ui.views.view_aggregator import ViewAggregator +from pdf_merger.src.ui.components.app_layout_config import AppLayoutConfig +from pdf_merger.src.ui.constants import LabelsConstants class AppConfigModule(Module): @@ -22,7 +23,7 @@ class ViewAggregatorContainerModule(Module): def configure(self, binder: Binder) -> None: binder.bind(PdfMergerService, to=PdfMergerService(PdfFileMerger(), [], ""), scope=injector.singleton) binder.bind(ImageMergerService, to=ImageMergerService(img2pdf, [], ""), scope=injector.singleton) - binder.bind(Labels, to=Labels()) + binder.bind(LabelsConstants, to=LabelsConstants()) binder.bind(ViewAggregator, to=ViewAggregator, scope=injector.singleton) @@ -45,8 +46,8 @@ def initialize(self): self.setGeometry(self.config.left, self.config.top, self.config.width, self.config.height) self.tabs = QTabWidget() - self.tabs.addTab(self.viewAggregator.imageToPDFMergeView.get_widget(), Labels.IMAGE_TO_PDF_TAB_TITLE) - self.tabs.addTab(self.viewAggregator.pdfCollectionMergeView.get_widget(), Labels.MERGE_PDF_TAB_TITLE) + self.tabs.addTab(self.viewAggregator.imageToPDFMergeView.get_widget(), LabelsConstants.IMAGE_TO_PDF_TAB_TITLE) + self.tabs.addTab(self.viewAggregator.pdfCollectionMergeView.get_widget(), LabelsConstants.MERGE_PDF_TAB_TITLE) self.tabsLayout = QHBoxLayout() self.tabsLayout.addWidget(self.tabs) diff --git a/pdf_merger/src/services/abstract_merger_service.py b/pdf_merger/src/services/abstract_file_merger_service.py similarity index 100% rename from pdf_merger/src/services/abstract_merger_service.py rename to pdf_merger/src/services/abstract_file_merger_service.py diff --git a/pdf_merger/src/services/image_merger_service.py b/pdf_merger/src/services/image_merger_service.py index 325232d..ab55855 100644 --- a/pdf_merger/src/services/image_merger_service.py +++ b/pdf_merger/src/services/image_merger_service.py @@ -3,7 +3,7 @@ from PyQt5.QtCore import QUrl import pathlib import img2pdf -from pdf_merger.src.services.abstract_merger_service import AbstractFileMergerService +from pdf_merger.src.services.abstract_file_merger_service import AbstractFileMergerService ''' Operations related to merging Images to PDF diff --git a/pdf_merger/src/services/pdf_merger_service.py b/pdf_merger/src/services/pdf_merger_service.py index 2870769..2e16e44 100644 --- a/pdf_merger/src/services/pdf_merger_service.py +++ b/pdf_merger/src/services/pdf_merger_service.py @@ -2,7 +2,7 @@ import pathlib from PyPDF2 import PdfFileMerger -from pdf_merger.src.services.abstract_merger_service import AbstractFileMergerService +from pdf_merger.src.services.abstract_file_merger_service import AbstractFileMergerService ''' Deals with operations related to PDF merging and creation diff --git a/pdf_merger/src/ui/__init__.py b/pdf_merger/src/ui/__init__.py new file mode 100644 index 0000000..5c94c0d --- /dev/null +++ b/pdf_merger/src/ui/__init__.py @@ -0,0 +1,10 @@ +# __init__.py + +from .constants import UILayoutConstants, LabelsConstants + +__all__ = [ + 'UILayoutConstants', + 'LabelsConstants' +] + +VERSION = '1.0.0' diff --git a/pdf_merger/src/ui/components/__init__.py b/pdf_merger/src/ui/components/__init__.py new file mode 100644 index 0000000..b3a2e93 --- /dev/null +++ b/pdf_merger/src/ui/components/__init__.py @@ -0,0 +1,15 @@ +# __init__.py + +from .app_layout_config import AppLayoutConfig +from .popup_factory import PopupFactory +from .button_factory import ButtonFactory +from .drag_drop_area import DragAndDropArea + +__all__ = [ + 'AppLayoutConfig', + 'PopupFactory', + 'ButtonFactory', + 'DragAndDropArea' +] + +VERSION = '1.0.0' diff --git a/pdf_merger/src/views/app_layout_config.py b/pdf_merger/src/ui/components/app_layout_config.py similarity index 72% rename from pdf_merger/src/views/app_layout_config.py rename to pdf_merger/src/ui/components/app_layout_config.py index 2c4a4e6..59d0078 100644 --- a/pdf_merger/src/views/app_layout_config.py +++ b/pdf_merger/src/ui/components/app_layout_config.py @@ -1,12 +1,11 @@ # Author: Ayush Kaushik -from pdf_merger.src.views.labels import Labels -from pdf_merger.src.views.ui_layout_constants import UILayoutConstants +from pdf_merger.src.ui.constants import LabelsConstants, UILayoutConstants class AppLayoutConfig: def __init__(self, - title: str = Labels.APP_NAME, + title: str = LabelsConstants.APP_NAME, left: int = UILayoutConstants.MARGIN, top: int = UILayoutConstants.MARGIN, height: int = UILayoutConstants.WINDOW_HEIGHT, diff --git a/pdf_merger/src/views/button_factory.py b/pdf_merger/src/ui/components/button_factory.py similarity index 100% rename from pdf_merger/src/views/button_factory.py rename to pdf_merger/src/ui/components/button_factory.py diff --git a/pdf_merger/src/views/drag_drop_area.py b/pdf_merger/src/ui/components/drag_drop_area.py similarity index 92% rename from pdf_merger/src/views/drag_drop_area.py rename to pdf_merger/src/ui/components/drag_drop_area.py index f78d5ae..307405a 100644 --- a/pdf_merger/src/views/drag_drop_area.py +++ b/pdf_merger/src/ui/components/drag_drop_area.py @@ -4,8 +4,8 @@ from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QAbstractItemView, QListWidget from pdf_merger.src.exceptions import InvalidExtensionError -from pdf_merger.src.views.popup_factory import PopupFactory -from pdf_merger.src.services.abstract_merger_service import AbstractFileMergerService +from pdf_merger.src.ui.components.popup_factory import PopupFactory +from pdf_merger.src.services.abstract_file_merger_service import AbstractFileMergerService ''' List Widget Box which accepts multiple files diff --git a/pdf_merger/src/views/popup_factory.py b/pdf_merger/src/ui/components/popup_factory.py similarity index 100% rename from pdf_merger/src/views/popup_factory.py rename to pdf_merger/src/ui/components/popup_factory.py diff --git a/pdf_merger/src/views/labels.py b/pdf_merger/src/ui/constants.py similarity index 66% rename from pdf_merger/src/views/labels.py rename to pdf_merger/src/ui/constants.py index 55078d7..ca417ba 100644 --- a/pdf_merger/src/views/labels.py +++ b/pdf_merger/src/ui/constants.py @@ -1,6 +1,14 @@ # Author: Ayush Kaushik -class Labels: +class UILayoutConstants: + WINDOW_WIDTH = 800 + WINDOW_HEIGHT = 600 + BUTTON_WIDTH = 80 + BUTTON_HEIGHT = 30 + MARGIN = 10 + + +class LabelsConstants: APP_NAME = "PDF Merger" APP_WINDOW_HEIGHT = 500 APP_WINDOW_WIDTH = 400 diff --git a/pdf_merger/src/ui/views/__init__.py b/pdf_merger/src/ui/views/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pdf_merger/src/views/file_collection_merge_view.py b/pdf_merger/src/ui/views/file_collection_merge_view.py similarity index 79% rename from pdf_merger/src/views/file_collection_merge_view.py rename to pdf_merger/src/ui/views/file_collection_merge_view.py index 5fcc024..ae31ac9 100644 --- a/pdf_merger/src/views/file_collection_merge_view.py +++ b/pdf_merger/src/ui/views/file_collection_merge_view.py @@ -2,13 +2,13 @@ from PyQt5.QtWidgets import QWidget, QFileDialog, QVBoxLayout, QLineEdit, QHBoxLayout, QLabel -from pdf_merger.src.views.app_layout_config import AppLayoutConfig -from pdf_merger.src.views.button_factory import ButtonFactory -from pdf_merger.src.views.drag_drop_area import DragAndDropArea -from pdf_merger.src.views.labels import Labels -from pdf_merger.src.views.popup_factory import PopupFactory +from pdf_merger.src.ui.components.app_layout_config import AppLayoutConfig +from pdf_merger.src.ui.components.button_factory import ButtonFactory +from pdf_merger.src.ui.components.drag_drop_area import DragAndDropArea +from pdf_merger.src.ui.constants import LabelsConstants +from pdf_merger.src.ui.components.popup_factory import PopupFactory -from pdf_merger.src.services.abstract_merger_service import AbstractFileMergerService +from pdf_merger.src.services.abstract_file_merger_service import AbstractFileMergerService ''' Includes the complete view for Merging files into single PDF @@ -20,7 +20,7 @@ def __init__( self, service: AbstractFileMergerService, config: AppLayoutConfig, - labels: Labels + labels: LabelsConstants ): super().__init__() self.fileMergerService = service @@ -61,9 +61,9 @@ def initialize_layout(self): self.textbox.setReadOnly(True) # Button to open dialog to select location to place merged file - self.saveButton = ButtonFactory.create("Save To", self.get_output_file_path) - self.deleteButton = ButtonFactory.create("Reset Files", self.reset_widget) - self.mergeButton = ButtonFactory.create("Merge Files", self.merge_files) + self.saveButton = ButtonFactory.create(self.labels.SAVE_TO, self.get_output_file_path) + self.deleteButton = ButtonFactory.create(self.labels.RESET, self.reset_widget) + self.mergeButton = ButtonFactory.create(self.labels.MERGE, self.merge_files) # PDF drag and drop area self.dragAndDropView = DragAndDropArea(self.fileMergerService) diff --git a/pdf_merger/src/views/view_aggregator.py b/pdf_merger/src/ui/views/view_aggregator.py similarity index 66% rename from pdf_merger/src/views/view_aggregator.py rename to pdf_merger/src/ui/views/view_aggregator.py index 066a298..aa3d66f 100644 --- a/pdf_merger/src/views/view_aggregator.py +++ b/pdf_merger/src/ui/views/view_aggregator.py @@ -1,13 +1,14 @@ # Author: Ayush Kaushik -from pdf_merger.src.views import AppLayoutConfig, Labels -from pdf_merger.src.views.file_collection_merge_view import FileCollectionMergeView +from pdf_merger.src.ui.constants import LabelsConstants +from pdf_merger.src.ui.components.app_layout_config import AppLayoutConfig +from pdf_merger.src.ui.views.file_collection_merge_view import FileCollectionMergeView from pdf_merger.src.services.image_merger_service import ImageMergerService from pdf_merger.src.services.pdf_merger_service import PdfMergerService from injector import inject ''' - Collects all the views to be passed into the main application + Collects all the ui to be passed into the main application ''' @@ -18,7 +19,7 @@ def __init__( pdf_service: PdfMergerService, image_service: ImageMergerService, widget_layout_config: AppLayoutConfig, - labels: Labels + labels: LabelsConstants ): self.imageToPDFMergeView = FileCollectionMergeView(pdf_service, widget_layout_config, labels) self.pdfCollectionMergeView = FileCollectionMergeView(image_service, widget_layout_config, labels) diff --git a/pdf_merger/src/views/__init__.py b/pdf_merger/src/views/__init__.py deleted file mode 100644 index bee23b6..0000000 --- a/pdf_merger/src/views/__init__.py +++ /dev/null @@ -1,23 +0,0 @@ -# __init__.py - -from pdf_merger.src.views.app_layout_config import AppLayoutConfig -from .button_factory import ButtonFactory -from .drag_drop_area import DragAndDropArea -from .labels import Labels -from pdf_merger.src.views.file_collection_merge_view import FileCollectionMergeView -from .popup_factory import PopupFactory -from .ui_layout_constants import UILayoutConstants -from .view_aggregator import ViewAggregator - -__all__ = [ - 'AppLayoutConfig', - 'ButtonFactory', - 'DragAndDropArea', - 'Labels', - 'FileCollectionMergeView', - 'PopupFactory', - 'UILayoutConstants', - 'ViewAggregator' -] - -VERSION = '1.0.0' diff --git a/pdf_merger/src/views/ui_layout_constants.py b/pdf_merger/src/views/ui_layout_constants.py deleted file mode 100644 index c698f67..0000000 --- a/pdf_merger/src/views/ui_layout_constants.py +++ /dev/null @@ -1,8 +0,0 @@ -# Author: Ayush Kaushik - -class UILayoutConstants: - WINDOW_WIDTH = 800 - WINDOW_HEIGHT = 600 - BUTTON_WIDTH = 80 - BUTTON_HEIGHT = 30 - MARGIN = 10 diff --git a/tests/test_app_layout_config.py b/tests/test_app_layout_config.py index 83b7f5a..9034a2c 100644 --- a/tests/test_app_layout_config.py +++ b/tests/test_app_layout_config.py @@ -1,12 +1,12 @@ import unittest -from pdf_merger.src.views import AppLayoutConfig -from pdf_merger.src.views.labels import Labels +from pdf_merger.src.ui.components import AppLayoutConfig +from pdf_merger.src.ui.constants import LabelsConstants class TestAppLayoutConfig(unittest.TestCase): def test_constructor_defaults(self): config = AppLayoutConfig() - self.assertEqual(config.title, Labels.APP_NAME) + self.assertEqual(config.title, LabelsConstants.APP_NAME) self.assertEqual(config.left, 10) self.assertEqual(config.top, 10) self.assertEqual(config.width, 800)