[PyQt] Help with Login Dialog / QThread issues

Eric Frederich eric.frederich at gmail.com
Mon Aug 8 14:58:40 BST 2011


I'm just a little confused on what connections to make.
I'm sure I could get something working but I'd be going about it the wrong way.

Forget my original post.

This is what I want.
I want a login dialog with username, password and group.
I want that dialog to stay up until the login is successful or user hits cancel.
I have a QThread subclass for logging in.
It emits either "success" or "fail", and with fail it provides some
text feedback.
When the login thread starts a progress bar should start animating.

This is where I am completely lost as far as connections go.
The QDialogButtonBox has accepted, rejected.
The QDialog has accepted, rejected.
My login thread has success, and fail.
There are clicked() signals as well.

Its not complicated, but I'm new to Qt and PyQt.
I think I need someone to spell it out for me.

Thanks,
~Eric

On Sat, Aug 6, 2011 at 1:14 PM, Baz Walter <bazwal at ftml.net> wrote:
> On 05/08/11 17:46, Eric Frederich wrote:
>>
>> Any takers?
>>
>> On Thu, Jul 7, 2011 at 12:38 PM, Eric Frederich
>> <eric.frederich at gmail.com>  wrote:
>>>
>>> Hello,
>>>
>>> I am trying to create a login dialog for my application.
>>> Logging in can take a couple of seconds so I wanted to show a progress
>>> bar during the login process.
>>> I think that for my QProgressBar to animate during this time, I need
>>> to log in on a different thread.  Is this true?
>>>
>>> So, below I have what I think is a working example.
>>> Is there a better way to call QDialog's accept slot when the login
>>> thread is finished than how I am doing it via functools.partial?
>>> It seems a bit hacky.
>>>
>>>
>>>
>>>
>>> from functools import partial
>>>
>>> class LoginThread(QThread):
>>>    def __init__(self, username, password, parent=None):
>>>        super(LoginThread, self).__init__(parent)
>>>        self.username = username
>>>        self.password = password
>>>    def run(self):
>>>        LOGIN(
>>>            self.username,
>>>            self.password,
>>>        )
>>>
>>> class LoginDialog(QDialog, Ui_LoginDialog):
>>>
>>>    def __init__(self, *args, **kwargs):
>>>        super(LoginDialog, self).__init__(*args, **kwargs)
>>>        self.setupUi(self)
>>>        self.progressbar.hide()
>>>
>>>    def accept(self):
>>>        self.progressbar.setMinimum(0)
>>>        self.progressbar.setMaximum(0)
>>>        self.progressbar.show()
>>>        self.lt = LoginThread(
>>>            str(self.username_edit.text()),
>>>            str(self.password_edit.text())
>>>        )
>>>        self.connect(self.lt, SIGNAL('finished()'),
>>> partial(QDialog.accept, self))
>>>        self.lt.start()
>
> it's hard to tell from the limited code you've posted why you need to
> override accept(). why not just create a handler for the clicked() signal of
> the ok button (or whatever it is) and then connect the thread's finished()
> signal directly to the dialog's accept() slot?
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>


More information about the PyQt mailing list