python - Displaying a popup window from action toolbar on a compiled PyQt4 Qt Designer -
so, tried build app , struggling on how connect action dialog window. searched found solution window wasn't built qt designer. designed qt designer , compiled .ui .py format.
this first window:
# -*- coding: utf-8 -*- # form implementation generated reading ui file 'home.ui' # # created by: pyqt4 ui code generator 4.11.4 # # warning! changes made in file lost! pyqt4 import qtcore, qtgui howto import ui_howtodialog 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_homewindow(object): def setupui(self, homewindow): homewindow.setobjectname(_fromutf8("homewindow")) homewindow.resize(1106, 259) font = qtgui.qfont() font.setfamily(_fromutf8("consolas")) homewindow.setfont(font) icon = qtgui.qicon() icon.addpixmap(qtgui.qpixmap(_fromutf8(":/resources/plottwist.png")), qtgui.qicon.normal, qtgui.qicon.off) homewindow.setwindowicon(icon) homewindow.setlayoutdirection(qtcore.qt.lefttoright) self.centralwidget = qtgui.qwidget(homewindow) self.centralwidget.setobjectname(_fromutf8("centralwidget")) self.horizontallayout = qtgui.qhboxlayout(self.centralwidget) self.horizontallayout.setobjectname(_fromutf8("horizontallayout")) self.homebrowser = qtgui.qtextbrowser(self.centralwidget) font = qtgui.qfont() font.setfamily(_fromutf8("consolas")) self.homebrowser.setfont(font) self.homebrowser.setobjectname(_fromutf8("homebrowser")) self.horizontallayout.addwidget(self.homebrowser) homewindow.setcentralwidget(self.centralwidget) self.statusbar = qtgui.qstatusbar(homewindow) self.statusbar.setobjectname(_fromutf8("statusbar")) homewindow.setstatusbar(self.statusbar) self.hometoolbar = qtgui.qtoolbar(homewindow) font = qtgui.qfont() font.setfamily(_fromutf8("consolas")) font.setpointsize(10) self.hometoolbar.setfont(font) self.hometoolbar.setcursor(qtgui.qcursor(qtcore.qt.pointinghandcursor)) self.hometoolbar.setlayoutdirection(qtcore.qt.lefttoright) self.hometoolbar.settoolbuttonstyle(qtcore.qt.toolbuttontextundericon) self.hometoolbar.setobjectname(_fromutf8("hometoolbar")) homewindow.addtoolbar(qtcore.qt.lefttoolbararea, self.hometoolbar) self.actionopendataset = qtgui.qaction(homewindow) icon1 = qtgui.qicon() icon1.addpixmap(qtgui.qpixmap(_fromutf8(":/resources/dataset.png")), qtgui.qicon.normal, qtgui.qicon.off) self.actionopendataset.seticon(icon1) self.actionopendataset.setobjectname(_fromutf8("actionopendataset")) self.actionhowto = qtgui.qaction(homewindow) self.actionhowto.triggered.connect(self.showhowto) icon2 = qtgui.qicon() icon2.addpixmap(qtgui.qpixmap(_fromutf8(":/resources/howto.png")), qtgui.qicon.normal, qtgui.qicon.off) self.actionhowto.seticon(icon2) self.actionhowto.setobjectname(_fromutf8("actionhowto")) self.actionabout = qtgui.qaction(homewindow) icon3 = qtgui.qicon() icon3.addpixmap(qtgui.qpixmap(_fromutf8(":/resources/about.png")), qtgui.qicon.normal, qtgui.qicon.off) self.actionabout.seticon(icon3) self.actionabout.setobjectname(_fromutf8("actionabout")) self.hometoolbar.addaction(self.actionopendataset) self.hometoolbar.addaction(self.actionhowto) self.hometoolbar.addaction(self.actionabout) self.retranslateui(homewindow) qtcore.qmetaobject.connectslotsbyname(homewindow) def retranslateui(self, homewindow): homewindow.setwindowtitle(_translate("homewindow", "plot twist", none)) self.homebrowser.sethtml(_translate("homewindow", "<!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:\'consolas\'; font-size:7.5pt; font-weight:400; font-style:normal;\">\n" "<p align=\"justify\" 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;\">data visualization important sounds, can visualize data app inserting dataset want. more detailed instructions, go how icon.</span></p>\n" "<p align=\"justify\" 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:14pt; font-weight:600;\"><br /></p>\n" "<p align=\"justify\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:12pt; font-weight:600;\">with plot twist, can:</span></p>\n" "<p align=\"justify\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:12pt; font-weight:600;\">- inside dataset</span></p>\n" "<p align=\"justify\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:12pt; font-weight:600;\">- visualize choosing possible diagrams of columns</span></p>\n" "<p align=\"justify\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:12pt; font-weight:600;\">- find out specific calculation of column</span></p></body></html>", none)) self.hometoolbar.setwindowtitle(_translate("homewindow", "toolbar", none)) self.actionopendataset.settext(_translate("homewindow", "open dataset", none)) self.actionopendataset.setstatustip(_translate("homewindow", "open dataset visualize it.", none)) self.actionopendataset.setshortcut(_translate("homewindow", "ctrl+o", none)) self.actionhowto.settext(_translate("homewindow", "how to", none)) self.actionhowto.settooltip(_translate("homewindow", "how this?", none)) self.actionhowto.setstatustip(_translate("homewindow", "instructions on how app works.", none)) self.actionhowto.setshortcut(_translate("homewindow", "f1", none)) self.actionabout.settext(_translate("homewindow", "about", none)) self.actionabout.settooltip(_translate("homewindow", "about", none)) self.actionabout.setstatustip(_translate("homewindow", "description , message creator.", none)) self.actionabout.setshortcut(_translate("homewindow", "f2", none)) def showhowto(self): howtodialog = qtgui.qdialog() hui = ui_howtodialog() hui.setupui(howtodialog) howtodialog.show() sys.exit(app.exec_()) import resources_rc if __name__ == "__main__": import sys app = qtgui.qapplication(sys.argv) homewindow = qtgui.qmainwindow() ui = ui_homewindow() ui.setupui(homewindow) homewindow.show() sys.exit(app.exec_())
and dialog tried pop up. it's supposed show howto dialog when icon on toolbar triggered.
# -*- coding: utf-8 -*- # form implementation generated reading ui file 'howto.ui' # # created by: pyqt4 ui code generator 4.11.4 # # warning! changes made in file lost! 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_howtodialog(object): def setupui(self, howtodialog): howtodialog.setobjectname(_fromutf8("howtodialog")) howtodialog.resize(585, 242) font = qtgui.qfont() font.setfamily(_fromutf8("consolas")) howtodialog.setfont(font) howtodialog.setacceptdrops(false) icon = qtgui.qicon() icon.addpixmap(qtgui.qpixmap(_fromutf8(":/resources/howto.png")), qtgui.qicon.normal, qtgui.qicon.off) howtodialog.setwindowicon(icon) self.horizontallayout = qtgui.qhboxlayout(howtodialog) self.horizontallayout.setobjectname(_fromutf8("horizontallayout")) self.howtobrowser = qtgui.qtextbrowser(howtodialog) self.howtobrowser.setobjectname(_fromutf8("howtobrowser")) self.horizontallayout.addwidget(self.howtobrowser) self.retranslateui(howtodialog) qtcore.qmetaobject.connectslotsbyname(howtodialog) def retranslateui(self, howtodialog): howtodialog.setwindowtitle(_translate("howtodialog", "how this?", none)) self.howtobrowser.sethtml(_translate("howtodialog", "<!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:\'consolas\'; font-size:7.5pt; font-weight:400; font-style:normal;\">\n" "<p align=\"justify\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:12pt;\">how insert dataset:</span></p>\n" "<p align=\"justify\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:12pt;\">1. click </span><span style=\" font-size:12pt; font-weight:600;\">open dataset </span><span style=\" font-size:12pt;\">icon.</span></p>\n" "<p align=\"justify\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:12pt;\">2. click </span><span style=\" font-size:12pt; font-weight:600;\">browse </span><span style=\" font-size:12pt;\">and select dataset.</span></p>\n" "<p align=\"justify\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:12pt;\">3. note dataset has .csv file.</span></p>\n" "<p align=\"justify\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:12pt;\">4. click </span><span style=\" font-size:12pt; font-weight:600;\">insert file </span><span style=\" font-size:12pt;\">button.</span></p>\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:12pt;\">5. dataset visualization window appear, , can start visualize it.</span></p>\n" "<p align=\"justify\" 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:12pt;\"><br /></p>\n" "<p align=\"justify\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:12pt;\">happy visualizing :)</span></p></body></html>", none)) import resources_rc if __name__ == "__main__": import sys app = qtgui.qapplication(sys.argv) howtodialog = qtgui.qdialog() ui = ui_howtodialog() ui.setupui(howtodialog) howtodialog.show() sys.exit(app.exec_())
as can see, function define show second window:
def showhowto(self): howtodialog = qtgui.qdialog() hui = ui_howtodialog() hui.setupui(howtodialog) howtodialog.show() sys.exit(app.exec_())
and have connected action toolbar self.actionhowto.triggered.connect(self.showhowto)
.
when run it, displays qcoreapplication::exec: event loop running
. can tell me what's wrong , solution? before!
i had similar trouble when starting pyqt. should create class dialog window so:
#!python3 '''docs''' import sys pyqt4.qtgui import * _apps.pyui import dialogui class dialogapp(qdialog, dialogui.ui_dialogapp): """dialog class""" def __init__(self, parent=none): super(self.__class__, self).__init__(parent) self.setupui(self) def main(self): app = qapplication(sys.argv) form = dialogapp() form.show() app.exec_() if __name__ == '__main__': main()
the main included easy testing... next part in main window slot connected action:
def opendialog(self): self.dialog= dialogapp(self) self.dialog.show()
the part need careful parent dialog, if none
parent in example dialog separate tab on task bar , can instantiated many times click action
, assuming dialog modeless. if pass mainwindow
(self
) dialog, recommended in cases concerning dialog windows, main parent, default dialog centered on main when appears.
edit:
also need , can have 1 qapplication
active, windows shown , underlying methods , functions go through initial qapplication
, far know.
Comments
Post a Comment