maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   [Solved] python QT4 subprocess.call to run shell script? (https://talk.maemo.org/showthread.php?t=70344)

AlMehdi 2011-02-25 15:44

[Solved] python QT4 subprocess.call to run shell script?
 
1 Attachment(s)
I am a total noob when i comes to Python. But i wanted to give it a try as i need a GUI. I understand bash shell scripting a lot better so i want to use that in my "program" even though i know it would be better to do it all in python.

So where am i going wrong?

(attaching the complete file below)

Code:

        self.retranslateUi(dialog)
        QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL(_fromUtf8("clicked()")), dialog.open)
        QtCore.QObject.connect(self.pushButton_2, QtCore.SIGNAL(_fromUtf8("clicked()")), dialog.open)
        QtCore.QObject.connect(self.pushButton_3, QtCore.SIGNAL(_fromUtf8("clicked()")), dialog.open)
        QtCore.QObject.connect(self.pushButton_4, QtCore.SIGNAL(_fromUtf8("clicked()")), dialog.close)
        QtCore.QMetaObject.connectSlotsByName(dialog)
        dialog.setTabOrder(self.pushButton, self.pushButton_3)
        dialog.setTabOrder(self.pushButton_3, self.pushButton_2)
        dialog.setTabOrder(self.pushButton_2, self.pushButton_4)

        def self(dialog):
                f = ("/home/daniel/Hämtningar/n900/awoken-extras/test.sh");
                import subprocess
                subprocess.call("/bin/sh " + f, shell=True);
                print "open(self) started"


AlMehdi 2011-02-25 19:49

Re: python QT4 subprocess.call to run shell script?
 
***bump***

attila77 2011-02-25 19:53

Re: python QT4 subprocess.call to run shell script?
 
subprocess.call(["/bin/sh", f])

AlMehdi 2011-02-25 19:57

Re: python QT4 subprocess.call to run shell script?
 
Quote:

Originally Posted by attila77 (Post 955477)
subprocess.call(["/bin/sh", f])

Thanks, but i already figurred that one out.

Right now i am trying with this two:
Code:

        def open(dialog):
                f = ("/home/daniel/Hämtningar/n900/awoken-extras/test.sh");
                import subprocess
                subprocess.call("/bin/sh " + f, shell=True);

        def dialog(pushButton_2):
                f = ("/home/daniel/Hämtningar/n900/awoken-extras/test.sh");
                from subprocess import Popen
                Popen('/bin/sh ' + f);

I somehow can't "connect" the button click event with the subprocess. When i run it nothing happens. So i think i am doing the "def" string wrong.

AlMehdi 2011-02-26 10:29

Re: python QT4 subprocess.call to run shell script?
 
When i do this i get an error.

Code:

        self.retranslateUi(dialog)
        QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL(_fromUtf8("clicked()")), self.open)
        def open(self):
                f = ("/home/daniel/Hämtningar/n900/awoken-extras/test.sh");
                import subprocess
                subprocess.call(["/bin/sh " + f]);

The error:
Code:

Traceback (most recent call last):
  File "awoken.py", line 82, in <module>
    ui.setupUi(dialog)
  File "awoken.py", line 43, in setupUi
    QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL(_fromUtf8("clicked()")), self.open)


AlMehdi 2011-02-26 15:55

Re: python QT4 subprocess.call to run shell script?
 
1 Attachment(s)
Solved! I got some help from my friend Wellef and sorted it out. I will attach the file in case someone els finds it useful.

This is how it should look:
Code:

        self.retranslateUi(MainWindow)
        QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL(_fromUtf8("clicked()")), self.change)
        QtCore.QObject.connect(self.pushButton_3, QtCore.SIGNAL(_fromUtf8("clicked()")), self.backup)
        QtCore.QObject.connect(self.pushButton_2, QtCore.SIGNAL(_fromUtf8("clicked()")), self.reset)
        QtCore.QObject.connect(self.pushButton_4, QtCore.SIGNAL(_fromUtf8("clicked()")), MainWindow.close)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def change(self):
        os.system("/home/daniel/Hämtningar/n900/awoken-extras/test.sh");

    def backup(self):
        os.system("/home/daniel/Hämtningar/n900/awoken-extras/test.sh");

    def reset(self):
        os.system("/home/daniel/Hämtningar/n900/awoken-extras/test.sh");



All times are GMT. The time now is 20:41.

vBulletin® Version 3.8.8