From d93dd450dc4fc9d98f576b207f34d536deb04bac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20Wieczorek?= Date: Fri, 18 Dec 2020 19:53:04 +0100 Subject: [PATCH] Add import paths to audio files. Add error dialog. Add checking extension of audio file(.mp3). --- Dockerfile | 24 +++++++ main.py | 4 +- src/gui/ui/preview_dialog.ui | 110 +++++++++++++++++------------ src/python/classes/mainwindow.py | 42 +++++++++++ src/python/ui/preview_dialog_ui.py | 73 +++++++++++-------- 5 files changed, 175 insertions(+), 78 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a19796a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM alpine:3.9 AS build +WORKDIR /opt/app/MagicPodcast +# Install Python and external dependencies, including headers and GCC +RUN apk add --no-cache python3 python3-dev py3-pip libffi libffi-dev musl-dev gcc +# Install Pipenv +RUN pip3 install pipenv +# Create a virtual environment and activate it +RUN python3 -m venv /opt/venv +ENV PATH="/opt/venv/bin:$PATH" VIRTUAL_ENV="/opt/venv" +# Install dependencies into the virtual environment with Pipenv +COPY Pipfile Pipfile.lock /opt/app/MagicPodcast +RUN pipenv install --deploy +FROM alpine:3.9 +WORKDIR /opt/app/MagicPodcast +# Install Python and external runtime dependencies only +RUN apk add --no-cache python3 libffi +# Copy the virtual environment from the previous image +COPY --from=build /opt/venv /opt/venv +# Activate the virtual environment +ENV PATH="/opt/venv/bin:$PATH" VIRTUAL_ENV="/opt/venv" +# Copy your application +COPY . /opt/app/MagicPodcast + + diff --git a/main.py b/main.py index 325567f..88cd0bc 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,10 @@ from src.python.classes.mainwindow import MainWindow -from PyQt5 import QtWidgets +from PyQt5.QtWidgets import QApplication import sys if __name__=='__main__': - app = QtWidgets.QApplication(sys.argv) + app = QApplication(sys.argv) w = MainWindow() w.show() sys.exit(app.exec_()) diff --git a/src/gui/ui/preview_dialog.ui b/src/gui/ui/preview_dialog.ui index a2dcacb..d1a1f29 100644 --- a/src/gui/ui/preview_dialog.ui +++ b/src/gui/ui/preview_dialog.ui @@ -18,67 +18,85 @@ - - - - - - Qt::Horizontal - - - QSlider::TicksBothSides - - - 1 - - - - - + - - - Początek fragmentu + + + + + + Qt::Horizontal - - - - - - Koniec fragemntu + + + Qt::Horizontal + + + QSlider::TicksBothSides + + + 1 - - - - - - - - - - start + + + Qt::Horizontal - - - stop - - + + + + + Początek fragmentu + + + + + + + + + + Koniec fragemntu + + + + + + + - - - zakończ - - + + + + + start + + + + + + + stop + + + + + + + zakończ + + + + diff --git a/src/python/classes/mainwindow.py b/src/python/classes/mainwindow.py index 3c0fe2e..a3601d7 100644 --- a/src/python/classes/mainwindow.py +++ b/src/python/classes/mainwindow.py @@ -6,6 +6,48 @@ class MainWindow(QMainWindow, Ui_MainWindow): def __init__(self, parent=None): super(MainWindow, self).__init__(parent=parent) self.setupUi(self) + self.setup_logic() + + def setup_logic(self): + self.push_button_audio1.clicked.connect(lambda: self.open_audio_import(audio_number=1)) + self.push_button_audio2.clicked.connect(lambda: self.open_audio_import(audio_number=2)) def setup_detail(self): pass + + def create_custom_dialog(self, title: str, msg: str): + dialog = QDialog() + dialog.setWindowTitle(title) + label = QLabel() + label.setText(msg) + buttons = QDialogButtonBox.Ok + button_box = QDialogButtonBox(buttons) + button_box.accepted.connect(dialog.accept) + layout = QVBoxLayout() + layout.addWidget(label) + layout.addWidget(button_box) + dialog.setLayout(layout) + return dialog + + def open_audio_import(self, audio_number: int): + dialog = QFileDialog() + dialog.setOption(dialog.DontUseNativeDialog, True) + dialog.setFileMode(QFileDialog.ExistingFile) + + file, _ = dialog.getOpenFileName(self, "QFileDialog.getOpenFileName()", "", "All Files (*);;mp3 (*.mp3);;wav (*.wav)", options=dialog.options()) + + if not file.endswith('.mp3'): + print(F"[!] Plik {file} nie jest plikiem mp3.") + dialog = self.create_custom_dialog(title='Error', msg=F"[!] Plik {file} nie jest plikiem mp3.") + dialog.exec_() + + else: + if audio_number == 1: + self.line_edit_audio1.setText(file) + + elif audio_number == 2: + self.line_edit_audio2.setText(file) + + print(F"[*] Zaimportowano ścieżkę {audio_number} pliku: '{file}'.") + + diff --git a/src/python/ui/preview_dialog_ui.py b/src/python/ui/preview_dialog_ui.py index 455d566..a763647 100644 --- a/src/python/ui/preview_dialog_ui.py +++ b/src/python/ui/preview_dialog_ui.py @@ -18,42 +18,55 @@ class Ui_dialog(object): dialog.resize(782, 356) self.verticalLayout = QtWidgets.QVBoxLayout(dialog) self.verticalLayout.setObjectName("verticalLayout") - self.graphicsView = QtWidgets.QGraphicsView(dialog) - self.graphicsView.setObjectName("graphicsView") - self.verticalLayout.addWidget(self.graphicsView) + self.vertical_layout = QtWidgets.QVBoxLayout() + self.vertical_layout.setObjectName("vertical_layout") + self.graphics_view = QtWidgets.QGraphicsView(dialog) + self.graphics_view.setObjectName("graphics_view") + self.vertical_layout.addWidget(self.graphics_view) + self.line = QtWidgets.QFrame(dialog) + self.line.setFrameShape(QtWidgets.QFrame.HLine) + self.line.setFrameShadow(QtWidgets.QFrame.Sunken) + self.line.setObjectName("line") + self.vertical_layout.addWidget(self.line) self.range_silder = QtWidgets.QSlider(dialog) self.range_silder.setOrientation(QtCore.Qt.Horizontal) self.range_silder.setTickPosition(QtWidgets.QSlider.TicksBothSides) self.range_silder.setTickInterval(1) self.range_silder.setObjectName("range_silder") - self.verticalLayout.addWidget(self.range_silder) - self.horizontalLayout_2 = QtWidgets.QHBoxLayout() - self.horizontalLayout_2.setObjectName("horizontalLayout_2") + self.vertical_layout.addWidget(self.range_silder) + self.line_2 = QtWidgets.QFrame(dialog) + self.line_2.setFrameShape(QtWidgets.QFrame.HLine) + self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken) + self.line_2.setObjectName("line_2") + self.vertical_layout.addWidget(self.line_2) + self.horizontal_layout_2 = QtWidgets.QHBoxLayout() + self.horizontal_layout_2.setObjectName("horizontal_layout_2") self.label = QtWidgets.QLabel(dialog) self.label.setObjectName("label") - self.horizontalLayout_2.addWidget(self.label) - self.lineEdit = QtWidgets.QLineEdit(dialog) - self.lineEdit.setObjectName("lineEdit") - self.horizontalLayout_2.addWidget(self.lineEdit) + self.horizontal_layout_2.addWidget(self.label) + self.line_edit = QtWidgets.QLineEdit(dialog) + self.line_edit.setObjectName("line_edit") + self.horizontal_layout_2.addWidget(self.line_edit) self.label_2 = QtWidgets.QLabel(dialog) self.label_2.setObjectName("label_2") - self.horizontalLayout_2.addWidget(self.label_2) - self.lineEdit_2 = QtWidgets.QLineEdit(dialog) - self.lineEdit_2.setObjectName("lineEdit_2") - self.horizontalLayout_2.addWidget(self.lineEdit_2) - self.verticalLayout.addLayout(self.horizontalLayout_2) - self.horizontalLayout = QtWidgets.QHBoxLayout() - self.horizontalLayout.setObjectName("horizontalLayout") - self.pushButton = QtWidgets.QPushButton(dialog) - self.pushButton.setObjectName("pushButton") - self.horizontalLayout.addWidget(self.pushButton) - self.pushButton_2 = QtWidgets.QPushButton(dialog) - self.pushButton_2.setObjectName("pushButton_2") - self.horizontalLayout.addWidget(self.pushButton_2) - self.pushButton_3 = QtWidgets.QPushButton(dialog) - self.pushButton_3.setObjectName("pushButton_3") - self.horizontalLayout.addWidget(self.pushButton_3) - self.verticalLayout.addLayout(self.horizontalLayout) + self.horizontal_layout_2.addWidget(self.label_2) + self.line_edit_2 = QtWidgets.QLineEdit(dialog) + self.line_edit_2.setObjectName("line_edit_2") + self.horizontal_layout_2.addWidget(self.line_edit_2) + self.vertical_layout.addLayout(self.horizontal_layout_2) + self.horizontal_layout_3 = QtWidgets.QHBoxLayout() + self.horizontal_layout_3.setObjectName("horizontal_layout_3") + self.push_button = QtWidgets.QPushButton(dialog) + self.push_button.setObjectName("push_button") + self.horizontal_layout_3.addWidget(self.push_button) + self.push_button_2 = QtWidgets.QPushButton(dialog) + self.push_button_2.setObjectName("push_button_2") + self.horizontal_layout_3.addWidget(self.push_button_2) + self.push_button_3 = QtWidgets.QPushButton(dialog) + self.push_button_3.setObjectName("push_button_3") + self.horizontal_layout_3.addWidget(self.push_button_3) + self.vertical_layout.addLayout(self.horizontal_layout_3) + self.verticalLayout.addLayout(self.vertical_layout) self.retranslateUi(dialog) QtCore.QMetaObject.connectSlotsByName(dialog) @@ -63,9 +76,9 @@ class Ui_dialog(object): dialog.setWindowTitle(_translate("dialog", "Dialog")) self.label.setText(_translate("dialog", "Początek fragmentu")) self.label_2.setText(_translate("dialog", "Koniec fragemntu")) - self.pushButton.setText(_translate("dialog", "start")) - self.pushButton_2.setText(_translate("dialog", "stop")) - self.pushButton_3.setText(_translate("dialog", "zakończ")) + self.push_button.setText(_translate("dialog", "start")) + self.push_button_2.setText(_translate("dialog", "stop")) + self.push_button_3.setText(_translate("dialog", "zakończ")) if __name__ == "__main__":