О передаче электронной почты с использованием интерфейса PyQt4.QtGui

Я пытался сделать интерфейс QtGui для передачи электронной почты. Мне удалось создать структуру интерфейса для электронной почты, но у меня возникли проблемы с добавлением и связыванием событий и слотов.

Я много пробовал и использовал много онлайн сайтов, но это все еще не работает. У меня есть демонстрация послезавтра, и я застрял с этой проблемой. Пожалуйста, направьте меня, связав событие и слот с любым QToolBar или QAction. После этого я продолжу себя. Ваша помощь будет много значить для меня. Спасибо!!!

Вот код, который я написал для вашего удобства:

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'Mail.ui'
#
# Created: Fri Apr 25 10:18:44 2014
#      by: PyQt4 UI code generator 4.10.4
#
# WARNING! All changes made in this file will be lost!
import PyQt4
from PyQt4 import QtCore, QtGui

try:
    fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(fromUtf8("MainWindow"))
        MainWindow.resize(800, 600)

        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(fromUtf8("E:/e-mail.jpg")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        MainWindow.setWindowIcon(icon)

        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(fromUtf8("centralwidget"))
        self.horizontalLayout = QtGui.QHBoxLayout(self.centralwidget)
        self.horizontalLayout.setObjectName(fromUtf8("horizontalLayout"))

        self.tabWidget = QtGui.QTabWidget(self.centralwidget)
        self.tabWidget.setObjectName(fromUtf8("tabWidget"))

        self.tab_2 = QtGui.QWidget()
        self.tab_2.setObjectName(fromUtf8("tab_2"))
        self.verticalLayout = QtGui.QVBoxLayout(self.tab_2)
        self.verticalLayout.setObjectName(fromUtf8("verticalLayout"))

        self.gridLayout = QtGui.QGridLayout()
        self.gridLayout.setObjectName(fromUtf8("gridLayout"))

        self.label = QtGui.QLabel(self.tab_2)
        self.label.setObjectName(fromUtf8("label"))
        self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
        self.label_2 = QtGui.QLabel(self.tab_2)
        self.label_2.setObjectName(fromUtf8("label_2"))
        self.gridLayout.addWidget(self.label_2, 2, 0, 1, 1)
        self.label_3 = QtGui.QLabel(self.tab_2)
        self.label_3.setObjectName(fromUtf8("label_3"))
        self.gridLayout.addWidget(self.label_3, 1, 0, 1, 1)

        self.Sender = QtGui.QComboBox(self.tab_2)
        self.Sender.setObjectName(fromUtf8("Sender"))
        self.gridLayout.addWidget(self.Sender, 0, 1, 1, 1)
        spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
        self.gridLayout.addItem(spacerItem, 0, 2, 1, 1)

        self.Receiver = QtGui.QLineEdit(self.tab_2)
        self.Receiver.setObjectName(fromUtf8("Receiver"))
        self.gridLayout.addWidget(self.Receiver, 1, 1, 1, 2)

        self.Subject = QtGui.QLineEdit(self.tab_2)
        self.Subject.setObjectName(fromUtf8("Subject"))
        self.gridLayout.addWidget(self.Subject, 2, 1, 1, 2)
        self.verticalLayout.addLayout(self.gridLayout)

        self.Body = QtGui.QPlainTextEdit(self.tab_2)
        self.Body.setObjectName(fromUtf8("Body"))
        self.verticalLayout.addWidget(self.Body)
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap(fromUtf8(":/what/new/prefix1/submitarticle.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.tabWidget.addTab(self.tab_2, icon1, fromUtf8(""))

        self.tab = QtGui.QWidget()
        self.tab.setObjectName(fromUtf8("tab"))
        self.verticalLayout_2 = QtGui.QVBoxLayout(self.tab)
        self.verticalLayout_2.setObjectName(fromUtf8("verticalLayout_2"))
        self.horizontalLayout_2 = QtGui.QHBoxLayout()
        self.horizontalLayout_2.setObjectName(fromUtf8("horizontalLayout_2"))

        self.AddFolder = QtGui.QToolButton(self.tab)
        icon2 = QtGui.QIcon()
        icon2.addPixmap(QtGui.QPixmap(fromUtf8("imakges.jpg")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.AddFolder.setIcon(icon2)
        self.AddFolder.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
        self.AddFolder.setObjectName(fromUtf8("AddFolder"))
        self.horizontalLayout_2.addWidget(self.AddFolder)

        self.AddFiles = QtGui.QToolButton(self.tab)
        icon3 = QtGui.QIcon()
        icon3.addPixmap(QtGui.QPixmap(fromUtf8("mail_attachment.gif")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.AddFiles.setIcon(icon3)
        self.AddFiles.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
        self.AddFiles.setObjectName(fromUtf8("AddFiles"))
        self.horizontalLayout_2.addWidget(self.AddFiles)

        self.AddFiles.connect(QtCore.QObject,"AddFiles","openFile")

        self.removeFiles = QtGui.QToolButton(self.tab)
        icon4 = QtGui.QIcon()
        icon4.addPixmap(QtGui.QPixmap(fromUtf8("folder_remove.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.removeFiles.setIcon(icon4)
        self.removeFiles.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
        self.removeFiles.setObjectName(fromUtf8("removeFiles"))
        self.horizontalLayout_2.addWidget(self.removeFiles)

        #self.removeFiles.destroy()

        spacerItem1 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
        self.horizontalLayout_2.addItem(spacerItem1)
        self.verticalLayout_2.addLayout(self.horizontalLayout_2)
        self.treeWidget = QtGui.QTreeWidget(self.tab)
        self.treeWidget.setObjectName(fromUtf8("treeWidget"))
        self.verticalLayout_2.addWidget(self.treeWidget)
        icon5 = QtGui.QIcon()
        icon5.addPixmap(QtGui.QPixmap(fromUtf8(":/what/new/prefix1/mail_attachment.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.tabWidget.addTab(self.tab, icon5, fromUtf8(""))
        self.horizontalLayout.addWidget(self.tabWidget)
        MainWindow.setCentralWidget(self.centralwidget)

        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
        self.menubar.setObjectName(fromUtf8("menubar"))
        MainWindow.setMenuBar(self.menubar)

        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName(fromUtf8("statusbar"))
        MainWindow.setStatusBar(self.statusbar)

        self.toolBar = QtGui.QToolBar(MainWindow)
        self.toolBar.setAutoFillBackground(True)
        self.toolBar.setObjectName(fromUtf8("toolBar"))
        MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar)

        self.actionCompose = QtGui.QAction(MainWindow)
        icon6 = QtGui.QIcon()
        icon6.addPixmap(QtGui.QPixmap(fromUtf8("email_compose.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionCompose.setIcon(icon6)
        self.actionCompose.setObjectName(fromUtf8("actionCompose"))

        self.actionSend = QtGui.QAction(MainWindow)
        icon7 = QtGui.QIcon()
        icon7.addPixmap(QtGui.QPixmap(fromUtf8
(":/what/new/prefix1/email_send_sending_emails_mail_letter_forward.png")),          QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionSend.setIcon(icon7)
        self.actionSend.setObjectName(fromUtf8("actionSend"))

        self.actionCancel = QtGui.QAction(MainWindow)
        #self.actionCancel.destroyed

        icon8 = QtGui.QIcon()
        icon8.addPixmap(QtGui.QPixmap(fromUtf8("jnm.jpg")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionCancel.setIcon(icon8)
        self.actionCancel.setObjectName(fromUtf8("actionCancel"))
        self.toolBar.addAction(self.actionCompose)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.actionSend)     
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.actionCancel)

        #print type(self)

        self.retranslateUi(MainWindow)
        self.tabWidget.setCurrentIndex(0)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
# For Tooltips and labels add folder, add files remove files, File and Size
    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(_translate("MainWindow", "JDK Mail", None))
        self.label.setText(_translate("MainWindow", "From:", None))
        self.label_2.setText(_translate("MainWindow", "Subject:", None))
        self.label_3.setText(_translate("MainWindow", "To:", None))
        self.Sender.setToolTip(_translate("MainWindow", "Enter your e-mail address", None))
        self.Receiver.setToolTip(_translate("MainWindow", "Enter receiver's e-mail Address", None))
        self.Subject.setToolTip(_translate("MainWindow", "Subject of mail", None))
        self.Body.setToolTip(_translate("MainWindow", "Main content of the mail\n"
"", None))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("MainWindow", "Message", None))
        self.tabWidget.setTabToolTip(self.tabWidget.indexOf(self.tab_2), _translate("MainWindow", "Send message only", None))
        self.AddFolder.setText(_translate("MainWindow", "Add Folder", None))
        self.AddFolder.setToolTip(_translate("MainWindow", "Add Folders to send", None))
        self.AddFiles.setText(_translate("MainWindow", "Add Files", None))#.clicked.connect(self.openFile)
        #self.AddFiles.clicked.connect(self.openFile)
        self.AddFiles.setToolTip(_translate("MainWindow", "Add Files to send", None))
        self.removeFiles.setText(_translate("MainWindow", "Remove files", None))
        self.removeFiles.setToolTip(_translate("MainWindow", "Remove files not required to send", None))
        self.treeWidget.headerItem().setText(0, _translate("MainWindow", "File", None))
        self.treeWidget.headerItem().setText(1, _translate("MainWindow", "Size", None))

        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("MainWindow", "Files", None))
        self.tabWidget.setTabToolTip(self.tabWidget.indexOf(self.tab), _translate("MainWindow", "Attach more files to send", None))

        self.toolBar.setWindowTitle(_translate("MainWindow", "JDKMail", None))
        self.toolBar.setWhatsThis(_translate("MainWindow", "Interface to send the mail", None))
        self.actionCompose.setText(_translate("MainWindow", "Compose", None))
        self.actionCompose.setToolTip(_translate("MainWindow", "Compose a new e-mail", None))
        self.actionSend.setText(_translate("MainWindow", "Send", None))
        self.actionSend.setToolTip(_translate("MainWindow", "Send mail", None))
        self.actionCancel.setText(_translate("MainWindow", "Cancel", None))
        self.actionCancel.setToolTip(_translate("MainWindow", "Cancel the e-mail transfer", None))

#To open File
    def openFile():
        fname=QtGui.QFileDialog.getOpenFileName()
        print fname


#import Mail_rc
#For program execution
if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    MainWindow = QtGui.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

0 ответов

Другие вопросы по тегам