Untitled

 avatar
unknown
plain_text
2 years ago
4.5 kB
15
Indexable
from PyQt5 import QtWidgets, QtGui, QtCore

import sys

global folder_path


class MyApp(QtWidgets.QMainWindow):
    def __init__(self):

        super().__init__()

        self.setWindowTitle("Redacted Torrent Creator")

        # Create a central widget for the main window
        self.central_widget = QtWidgets.QWidget()
        self.setCentralWidget(self.central_widget)

        # Create a grid layout for the central widget
        self.grid_layout = QtWidgets.QGridLayout()
        self.central_widget.setLayout(self.grid_layout)

        # Create a label and line edit for the folder
        self.folder_label = QtWidgets.QLabel("Folder:")
        self.folder_line_edit = QtWidgets.QLineEdit()
        self.folder_browse_button = QtWidgets.QPushButton("Browse...")
        self.folder_browse_button.clicked.connect(self.browse_folder)

        # Add the label, line edit, and button to the grid layout
        self.grid_layout.addWidget(self.folder_label, 0, 0)
        self.grid_layout.addWidget(self.folder_line_edit, 0, 1)
        self.grid_layout.addWidget(self.folder_browse_button, 0, 2)

        # Create a label and line edit for the file
        self.file_label = QtWidgets.QLabel("File:")
        self.file_line_edit = QtWidgets.QLineEdit()
        self.file_browse_button = QtWidgets.QPushButton("Browse...")
        self.file_browse_button.clicked.connect(self.browse_file)

        # Add the label, line edit, and button to the grid layout
        self.grid_layout.addWidget(self.file_label, 1, 0)
        self.grid_layout.addWidget(self.file_line_edit, 1, 1)
        self.grid_layout.addWidget(self.file_browse_button, 1, 2)

        # Create a submit and cancel button
        self.submit_button = QtWidgets.QPushButton("Submit")
        self.cancel_button = QtWidgets.QPushButton("Cancel")
        self.exit_button = QtWidgets.QPushButton("Exit")

        self.submit_button.clicked.connect(self.submit_button_clicked)
        self.exit_button.clicked.connect(QtWidgets.QApplication.quit)

        # Add the buttons to the grid layout
        self.grid_layout.addWidget(self.submit_button, 2, 0)
        self.grid_layout.addWidget(self.cancel_button, 2, 1)
        self.grid_layout.addWidget(
            self.exit_button, self.grid_layout.rowCount()-1, 2)

        # sizes
        self.cancel_button.setFixedSize(70, 25)

        # Create a status bar for the main window
        self.status_bar = QtWidgets.QStatusBar()
        self.status_bar.showMessage(
            "Choose a folder or file to create a torrent.")
        self.setStatusBar(self.status_bar)

        # Create the menu bar
        self.menu_bar = QtWidgets.QMenuBar()
        # Create the File menu and add it to the menu bar
        self.settings_menu = self.menu_bar.addMenu("Settings")
        self.about_menu = self.menu_bar.addMenu("About")
        # Set the menu bar for the main window
        self.setMenuBar(self.menu_bar)

    # para não esconder o status bar
    def event(self, e):
        if e.type() == QtCore.QEvent.StatusTip:
            if e.tip() == '':
                # Set this to whatever you like
                e = QtGui.QStatusTipEvent(
                    'Choose a folder or file to create a torrent.')
        return super().event(e)

    def browse_folder(self):
        global folder_path
        options = QtWidgets.QFileDialog.Options()
        options |= QtWidgets.QFileDialog.ReadOnly
        folder_path = QtWidgets.QFileDialog.getExistingDirectory(
            self, "Select Folder", options=options)
        if folder_path:
            global folder_path
            self.folder_line_edit.setText(folder_path)

            self.folder_path = folder_path
            print(folder_path + 'dddwdadds')
            return folder_path

    def browse_file(self):
        global file_path
        options = QtWidgets.QFileDialog.Options()
        options |= QtWidgets.QFileDialog.ReadOnly
        file_path, _ = QtWidgets.QFileDialog.getOpenFileName(
            self, "Select File", options=options)
        if file_path:
            self.file_line_edit.setText(file_path)
            self.file_path = file_path
            return file_path

    def submit_button_clicked(self):

        QtWidgets.QApplication.quit()


if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    main_window = MyApp()
    main_window.show()

    # Tamanho da window
    main_window.setGeometry(400, 400, 400, 200)
    sys.exit(app.exec_())
    

print(folder_path + 'ddd')
Editor is loading...