[PyKDE] QProcess: more guidance needed

Andreas Pakulat apaku at gmx.de
Thu Mar 9 11:34:13 GMT 2006


On 09.03.06 07:40:02, Tina Isaksen wrote:
> >David Boddie wrote:
> >>Have you tried sending "y\n" to the process's stdin, just as you would
> >>type it in a console?
> >>
> >>David
> >> 
> >Not sure I understand what you mean. In a console one types "y[enter]" or 
> >"n[enter]"
> >Actually only 'y' or 'Y' matters. Every other response causes apt-get to 
> >abort.
> >
> >And that's the weird part because even if I send a y or an Y, it will abort. I 
> >also tried to convert it to ascii numbers with no success. But the simple fact 
> >that it aborts must mean that it in fact reads that I send 'something' to 
> >stdin, right?
> 
> I gave up. I just could not get a QProcess write to a process stdin.

I'll see if I can write up a small example to test this. Maybe you just
hit a bug...

> How can I call a Qdialog I have made in Qt3 designer and have it set a variable 
> ('answer') in my main program? The Qdialog only has two buttons called 
> pbUpgradeYes and pbUpgradeNo.

If you created the dialog with one of the dialog templates that designer
offered and you want that dialog to be model, just use

dialog = MyDialog(self)
return = dialog.exec()

(IIRC exec is named a little bit different, but I don't know what is
appended to it).

Then you can check return for beeing either QDialog.Accepted or
QDialog.Rejected and with that set your variable.

If you didn't use one of the templates but you still plan to use a modal
dialog, then you can just connect the click-signal of those 2 buttons to
the slots "accept" and "reject" of QDialog (that's what the dialog
templates do automatically).

If you however don't want to use a modal dialog one option would be to
construct the dialog with a reference to your mainwindow and let it do
the rest. If I'm not totally mistaken you need to subclass your dialog
class in a python module.

> def readOutput(self):
>        outputString = QString(self.upgradeProcess.readStdout())
>        self.mainTextWindow.append(outputString)
>              # Check if upgradeProcess ask to continue
>        if outputString.endsWith("? "):
>            qApp.processEvents()
>                      #### need to call QDialog 'confirmUpgrade' and have it set 
> 'answer' ####
>                      # Determine action to take
>            if answer == "upgradeYes":

Ok, so in this case you need to use a modal dialog. So just make sure
the connections are done (in the dialog) as said above and then replace
the if answer == .. with something like this:

           if confirmUpgrade().exec() == QDialog.Accepted:

And remember to look up how you can execute the dialog in PyQt, it
differes from  the C++-exec()-function, because that is a builtin
function in Python. Phil normally appends "something" to those in PyQt3,
you just have to find out what. Check the examples for this.

Andreas

-- 
You are capable of planning your future.




More information about the PyQt mailing list