Новичок
Профиль
Группа: Участник
Сообщений: 1
Регистрация: 25.5.2007
Репутация: нет Всего: нет
|
Всем привет. Я тут новенький, так что сильно не пинать. Вот суть вопроса - у меня есть некоторые недельные навыки программирования в PyQt4. Первое время я все делал в одном классе и обращался к функциям этого класса. Но со временем я решил разнести некторые функции по отдельным классам, так как в дальнейшем намереваюсь расширять программу и мне по любому прийдется как-то разносить код по разным частям, чтобы не запутаться, да и так правильнее. И вот что у меня не получается, я не могу из главного меню главного окна по нажатию на пункт меню About Us вызвать окошко в котором бы писалось о программе (название, автор и т.д.). Дизайнил в QtDesigner Вот код файлов по очередности их создания Первый test.py Код | import sys from PyQt4 import QtCore, QtGui from eskiz import Ui_MainWindow from translits import Ui_DialogAboutUs
class StartMyMain(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.uiAbout = Ui_DialogAboutUs() QtCore.QObject.connect(self.ui.actionExit, QtCore.SIGNAL("triggered()"), self.close) QtCore.QObject.connect(self.ui.actionAbout_us_2, QtCore.SIGNAL("triggered()"), self.uiAbout.aboutshow)
if __name__ == "__main__": app = QtGui.QApplication(sys.argv) myapp = StartMyMain() myapp.show() sys.exit(app.exec_())
|
Второй файл eskiz.py Код | # -*- coding: utf-8 -*-
# Form implementation generated from reading ui file '2page.ui' # # Created: Wed Sep 23 11:56:36 2009 # by: PyQt4 UI code generator 4.5.4 # # WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(555, 600) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth()) MainWindow.setSizePolicy(sizePolicy) MainWindow.setMouseTracking(False) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap("images/handyman.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) MainWindow.setWindowIcon(icon) self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.textEdit = QtGui.QTextEdit(self.centralwidget) self.textEdit.setGeometry(QtCore.QRect(100, 130, 411, 131)) self.textEdit.setObjectName("textEdit") self.horizontalLayoutWidget = QtGui.QWidget(self.centralwidget) self.horizontalLayoutWidget.setGeometry(QtCore.QRect(10, 20, 531, 80)) self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget") self.lbatton_1 = QtGui.QHBoxLayout(self.horizontalLayoutWidget) self.lbatton_1.setSpacing(3) self.lbatton_1.setObjectName("lbatton_1") self.tanslit_s_en = QtGui.QPushButton(self.horizontalLayoutWidget) self.tanslit_s_en.setEnabled(True) self.tanslit_s_en.setMaximumSize(QtCore.QSize(200, 65)) self.tanslit_s_en.setBaseSize(QtCore.QSize(100, 0)) self.tanslit_s_en.setCheckable(False) self.tanslit_s_en.setObjectName("tanslit_s_en") self.lbatton_1.addWidget(self.tanslit_s_en) self.translit_s_ru = QtGui.QPushButton(self.horizontalLayoutWidget) self.translit_s_ru.setMaximumSize(QtCore.QSize(200, 65)) self.translit_s_ru.setObjectName("translit_s_ru") self.lbatton_1.addWidget(self.translit_s_ru) self.cheknewwindow = QtGui.QCheckBox(self.horizontalLayoutWidget) self.cheknewwindow.setMaximumSize(QtCore.QSize(70, 16777215)) self.cheknewwindow.setObjectName("cheknewwindow") self.lbatton_1.addWidget(self.cheknewwindow) self.label = QtGui.QLabel(self.centralwidget) self.label.setGeometry(QtCore.QRect(15, 170, 71, 41)) self.label.setObjectName("label") self.label_2 = QtGui.QLabel(self.centralwidget) self.label_2.setGeometry(QtCore.QRect(10, 330, 71, 31)) self.label_2.setObjectName("label_2") self.plainTextEdit = QtGui.QPlainTextEdit(self.centralwidget) self.plainTextEdit.setGeometry(QtCore.QRect(100, 280, 411, 131)) self.plainTextEdit.setObjectName("plainTextEdit") MainWindow.setCentralWidget(self.centralwidget) self.statusbar = QtGui.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.menuBar = QtGui.QMenuBar(MainWindow) self.menuBar.setGeometry(QtCore.QRect(0, 0, 555, 21)) self.menuBar.setObjectName("menuBar") self.menuFile = QtGui.QMenu(self.menuBar) self.menuFile.setObjectName("menuFile") self.menuText = QtGui.QMenu(self.menuBar) self.menuText.setObjectName("menuText") MainWindow.setMenuBar(self.menuBar) self.actionExit = QtGui.QAction(MainWindow) icon1 = QtGui.QIcon() icon1.addPixmap(QtGui.QPixmap("images/exit.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionExit.setIcon(icon1) self.actionExit.setObjectName("actionExit") self.actionAbout_us = QtGui.QAction(MainWindow) icon2 = QtGui.QIcon() icon2.addPixmap(QtGui.QPixmap("images/about-us.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionAbout_us.setIcon(icon2) self.actionAbout_us.setObjectName("actionAbout_us") self.actionTransliteration_string = QtGui.QAction(MainWindow) self.actionTransliteration_string.setObjectName("actionTransliteration_string") self.actionTransliteration_file = QtGui.QAction(MainWindow) self.actionTransliteration_file.setObjectName("actionTransliteration_file") self.actionAbout_us_2 = QtGui.QAction(MainWindow) self.actionAbout_us_2.setIcon(icon2) self.actionAbout_us_2.setObjectName("actionAbout_us_2") self.menuFile.addAction(self.actionAbout_us_2) self.menuFile.addAction(self.actionExit) self.menuText.addAction(self.actionTransliteration_string) self.menuText.addAction(self.actionTransliteration_file) self.menuBar.addAction(self.menuFile.menuAction()) self.menuBar.addAction(self.menuText.menuAction())
self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow): MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "My Handyman", None, QtGui.QApplication.UnicodeUTF8)) self.tanslit_s_en.setText(QtGui.QApplication.translate("MainWindow", "Transliteration (en)", None, QtGui.QApplication.UnicodeUTF8)) self.translit_s_ru.setText(QtGui.QApplication.translate("MainWindow", "Transliteration (ru)", None, QtGui.QApplication.UnicodeUTF8)) self.cheknewwindow.setToolTip(QtGui.QApplication.translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-weight:600;\">Transliteration New Window</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8)) self.cheknewwindow.setText(QtGui.QApplication.translate("MainWindow", "TNW", None, QtGui.QApplication.UnicodeUTF8)) self.label.setText(QtGui.QApplication.translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:14pt; font-weight:600; text-decoration: underline;\">Input</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8)) self.label_2.setText(QtGui.QApplication.translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:14pt; font-weight:600; text-decoration: underline;\">Output</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8)) self.menuFile.setTitle(QtGui.QApplication.translate("MainWindow", "File", None, QtGui.QApplication.UnicodeUTF8)) self.menuText.setTitle(QtGui.QApplication.translate("MainWindow", "Text", None, QtGui.QApplication.UnicodeUTF8)) self.actionExit.setText(QtGui.QApplication.translate("MainWindow", "Exit", None, QtGui.QApplication.UnicodeUTF8)) self.actionAbout_us.setText(QtGui.QApplication.translate("MainWindow", "About us", None, QtGui.QApplication.UnicodeUTF8)) self.actionTransliteration_string.setText(QtGui.QApplication.translate("MainWindow", "Transliteration string", None, QtGui.QApplication.UnicodeUTF8)) self.actionTransliteration_file.setText(QtGui.QApplication.translate("MainWindow", "Transliteration file", None, QtGui.QApplication.UnicodeUTF8)) self.actionAbout_us_2.setText(QtGui.QApplication.translate("MainWindow", "About us", None, QtGui.QApplication.UnicodeUTF8))
|
Третий файл translits.py Код | import sys from PyQt4 import QtCore, QtGui
class Ui_DialogAboutUs(object): def aboutshow(self,DialogAboutUs): DialogAboutUs.setObjectName("DialogAboutUs") DialogAboutUs.resize(240, 320) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap("images/handyman.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) DialogAboutUs.setWindowIcon(icon) self.textBrowser = QtGui.QTextBrowser(DialogAboutUs) self.textBrowser.setGeometry(QtCore.QRect(0, 0, 241, 321)) self.textBrowser.setObjectName("textBrowser")
self.retranslateUi(DialogAboutUs) QtCore.QMetaObject.connectSlotsByName(DialogAboutUs)
def retranslateUi(self, DialogAboutUs): DialogAboutUs.setWindowTitle(QtGui.QApplication.translate("DialogAboutUs", "About Us", None, QtGui.QApplication.UnicodeUTF8)) self.textBrowser.setHtml(QtGui.QApplication.translate("DialogAboutUs", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt; font-weight:600;\">MyHandyMan</span></p>\n" "<p align=\"center\" style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt; font-weight:600;\"></p>\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt;\">Developer: Rudyuk Vitalij Anatol\'evich</span></p>\n" "<p align=\"center\" style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;\"></p>\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt;\">Date: 23.09.2009</span></p>\n" "<p align=\"center\" style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;\"></p>\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt;\">License: GNU Public license</span></p>\n" "<p align=\"center\" style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;\"></p>\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt;\">Build: 0.1 version</span></p>\n" "<p align=\"center\" style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;\"></p>\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt;\">Description: Program for web developers, helps with trifles.</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
|
Все... Буду рад любой помощи и даже критике
|