Skip to content

Commit

Permalink
Organized classes
Browse files Browse the repository at this point in the history
- Logical organization of classes
- Renamed some classes
  • Loading branch information
Ayush-Kaushik committed Jun 14, 2024
1 parent cea91bd commit 58927f6
Show file tree
Hide file tree
Showing 18 changed files with 73 additions and 62 deletions.
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,12 @@ dmypy.json

# Test output
/tests/output/test_output.pdf
report.html
report.html

# PyCharm files
.idea/*

# Extra files
.DS_Store
tests/.DS_Store
tests/data/.DS_Store
11 changes: 6 additions & 5 deletions pdf_merger/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)


Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pdf_merger/src/services/image_merger_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pdf_merger/src/services/pdf_merger_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions pdf_merger/src/ui/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# __init__.py

from .constants import UILayoutConstants, LabelsConstants

__all__ = [
'UILayoutConstants',
'LabelsConstants'
]

VERSION = '1.0.0'
15 changes: 15 additions & 0 deletions pdf_merger/src/ui/components/__init__.py
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,7 +20,7 @@ def __init__(
self,
service: AbstractFileMergerService,
config: AppLayoutConfig,
labels: Labels
labels: LabelsConstants
):
super().__init__()
self.fileMergerService = service
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
'''


Expand All @@ -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)
23 changes: 0 additions & 23 deletions pdf_merger/src/views/__init__.py

This file was deleted.

8 changes: 0 additions & 8 deletions pdf_merger/src/views/ui_layout_constants.py

This file was deleted.

6 changes: 3 additions & 3 deletions tests/test_app_layout_config.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 58927f6

Please sign in to comment.