[PyQt] Problem calling a window
Sandro Dutra
hexodin at gmail.com
Thu Jan 15 17:24:07 GMT 2009
2009/1/15 Sandro Dutra <hexodin at gmail.com>
> Sorry for the delay... it's the time, it's the time...
>
> I used Eric4 and QtDesigner, so the Pro2MainWindow it's only the window
> without the widgets (I only want to test the call), here's the code:
>
> ---Pro2MainWindow Code---
> # -*- coding: utf-8 -*-
>
> """
> Module implementing Pro2MainWindow.
> """
>
> from PyQt4.QtGui import QMainWindow
> from PyQt4.QtCore import pyqtSignature
>
> from Ui_Pro2MainWindow import Ui_Pro2MainWindow
>
> class Pro2MainWindow(QMainWindow, Ui_Pro2MainWindow):
> """
> Class documentation goes here.
> """
> def __init__(self, parent = None):
> """
> Constructor
> """
> QMainWindow.__init__(self, parent)
> self.setupUi(self)
>
> The setupUi, only call the definitions of the ui generated by QtDesigner,
> and here's the complete code for the login screen:
> # -*- coding: utf-8 -*-
>
> """
> Module implementing DialogPro2Login.
> """
>
> from PyQt4.QtGui import QDialog, QMessageBox, QApplication
> from PyQt4.QtCore import pyqtSignature
>
> from Ui_Pro2Login import Ui_DialogPro2Login
> from Pro2MainWindow import Pro2MainWindow
> from db.database import Pro2db
>
> import MySQLdb, sys
>
> class DialogPro2Login(QDialog, Ui_DialogPro2Login):
> """
> Class documentation goes here.
> """
> def __init__(self, parent = None):
> """
> Constructor
> """
> QDialog.__init__(self, parent)
> self.setupUi(self)
>
> @pyqtSignature("")
> def on_pushButton_enter_clicked(self):
> user = self.lineEdit_user.text()
> passw = self.lineEdit_passw.text()
> if user == "" or passw == "":
> QMessageBox.information(self, "ERRO", u"Por favor, entre com
> o usuário e senha.", "OK")
> else:
> try:
> p2db = Pro2db(str(user), str(passw)) ### Here is where I
> want to call the mainwindow ####
> wndMain = Pro2MainWindow()
> wndMain.exec_()
> wndMain.showMaximized()
> self.hide()
> ##############################
> except MySQLdb.Error, error_code:
> if error_code[0] == 1045:
> message = u"Acesso negado para o usuário: %s" %user
> elif error_code[0] == 2003:
> message = u"Não foi possível realizar a conexão."
> else:
> message = u"Erro desconhecido.\nCódigo administrativo:
> %s - %s." %(error_code[0], error_code[1])
> QMessageBox.information(self, "Falha no acesso", u"O
> servidor informa:\n%s" %message, "OK")
>
> @pyqtSignature("")
> def on_pushButton_exit_clicked(self):
> self.close()
>
> If you need more info tell me,
> Thanks for the attention to a so noob problem.
> Sandro Dutra - Brazil.
>
> 2009/1/14 Sergio Jovani <lesergi at gmail.com>
>
> It would be good you post more code, at least, Pro2MainWindow class.
>>
>> 2009/1/14 Sandro Dutra <hexodin at gmail.com>:
>> > I get a AttibuteError in mainWnd.exec_()
>> >
>> > If necessary, I can upload the complete code.
>> >
>> > Thanks in advance.
>> >
>> > 2009/1/13 Sergio Jovani <lesergi at gmail.com>
>> >>
>> >> Hi,
>> >>
>> >> This is a little piece of code, but you can try with:
>> >>
>> >> mainWnd = Pro2MainWindow()
>> >> mainWnd.exec_()
>> >> mainWnd.showMaximized()
>> >> self.hide()
>> >>
>> >> 2009/1/13 Sandro Dutra <hexodin at gmail.com>:
>> >> > I'm writing a solution using Python, Qt and MySQL, I create the login
>> >> > screen
>> >> > and set all the errors...
>> >> >
>> >> > The problem is: When the user do the correct login in MySQL, I want
>> the
>> >> > login screen to close, and the whole application show.
>> >> >
>> >> > The code when the button "Enter" is pressed:
>> >> > ---------------------------
>> >> > def on_pushButton_enter_clicked(self):
>> >> > user = self.lineEdit_user.text()
>> >> > passw = self.lineEdit_passw.text()
>> >> > if user == "" or passw == "":
>> >> > QMessageBox.information(self, "ERRO", u"Por favor,
>> entre
>> >> > com o
>> >> > usuário e senha.", "OK")
>> >> > else:
>> >> > try: ############ If the login is made, the application
>> is
>> >> > launch and the login screen is closed.
>> >> > p2db = Pro2db(str(user), str(passw))
>> >> > mainWnd = Pro2MainWindow()
>> >> > mainWnd.showMaximized()
>> >> > self.close()
>> >> > ###########################################
>> >> > except MySQLdb.Error, error_code:
>> >> > if error_code[0] == 1045:
>> >> > message = u"Acesso negado para o usuário: %s"
>> %user
>> >> > elif error_code[0] == 2003:
>> >> > message = u"Não foi possível realizar a conexão."
>> >> > else:
>> >> > message = u"Erro desconhecido.\nCódigo
>> >> > administrativo:
>> >> > %s - %s." %(error_code[0], error_code[1])
>> >> > QMessageBox.information(self, "Falha no acesso", u"O
>> >> > servidor informa:\n%s" %message, "OK")
>> >> > ---------------------------
>> >> >
>> >> > Anyone can help?
>> >> >
>> >> > Thanks in advance,
>> >> > Sandro Dutra,
>> >> > Brazil.
>> >> >
>> >> > _______________________________________________
>> >> > PyQt mailing list PyQt at riverbankcomputing.com
>> >> > http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>> >> >
>> >
>> >
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090115/d6805f99/attachment-0001.html
More information about the PyQt
mailing list