LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-27-2014, 12:34 PM   #1
sharky
Member
 
Registered: Oct 2002
Posts: 569

Rep: Reputation: 84
pyside or pyqt - suprocess is locking the GUI


python 2.7, qt 4.8.3, pyside 1.1.2

Trying to call a process without freezing the GUI.

Currently using subprocess.Popen

Code:
def setup_term(self):
        self.txtProjLog.clear()
        # select proj argument
        cursor = self.txtProjects.textCursor()
        projid = cursor.selectedText()
        QApplication.setOverrideCursor(Qt.WaitCursor)
        QApplication.processEvents()
        # in case no proj selected
        if projid == "":
           QMessageBox.information(self, "Error", "No Project Selected")
           return 
        command = ResDir + '/setproj.sh' + ' ' + projid
        process = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        pilog = process.communicate()[0]
        self.txtProjLog.append(pilog)
        QApplication.restoreOverrideCursor()
The setproj.sh script will set environment variables and open an xterm but the python/pyside GUI is frozen until the xterm started by setproj.sh is closed.
If anyone can tell me how to make subprocess.POpen interactive then please let me know.

Cheers,
 
Old 01-27-2014, 12:43 PM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,236

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Use a QProcess instead.
 
Old 01-27-2014, 02:20 PM   #3
sharky
Member
 
Registered: Oct 2002
Posts: 569

Original Poster
Rep: Reputation: 84
Quote:
Originally Posted by dugan View Post
Use a QProcess instead.
Tried using QProcess and it breaks the setproj.sh script. I have no idea why. It works standalone and it works with subprocess.popen but using QProcess doesn't work.

I added statements in setproj.sh and verified that it was getting invoked but the xterm that setproj.sh invokes never appears when using QProcess.

This is the code I tried.

Code:
    def setup_term(self):
        self.txtProjLog.clear()
        cursor = self.txtProjects.textCursor()
        projid = cursor.selectedText()
        QApplication.setOverrideCursor(Qt.WaitCursor)
        QApplication.processEvents()
        if projid == "":
           QMessageBox.information(self, "Error", "No Project Selected")
           return 
        command = ResDir + '/setproj.sh' + ' ' + projid
        self.runner = QProcess(self)
        self.runner.readyReadStandardError.connect(self.StdInfo)
        self.runner.start(command)

    def StdInfo(self):
        newData = str(self.runner.readAllStandardOutput())
        self.txtProjLog.append(newData)
 
Old 01-28-2014, 02:04 PM   #4
sharky
Member
 
Registered: Oct 2002
Posts: 569

Original Poster
Rep: Reputation: 84
Had to fix another issue related to the way QProcess inputs stdio.

The subprocess was a script that outputs text with html tags. I was directing the output via stdio to a Qtextedit.

example;
Code:
echo "<font>this is info."
echo "this is more info.<\/font>"
Because QProcess inputs stdio one line at a time it was causing the tags to show up in the text widget. The fix was to put html tags on each line of output.

fix;
Code:
echo "<font>this is info.<\/font>"
echo "<font>this is more info.<\/font>"
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] pyqt or pyside exclusive menu options sharky Programming 1 01-25-2014 05:01 PM
[SOLVED] pyQT no GUI appears sharky Programming 2 12-16-2013 07:38 AM
Pyqt vs pyside Garda Programming 1 07-13-2012 05:46 PM
Running GUI commands in console without locking it raphaelmsx Linux - Newbie 3 11-02-2011 01:05 PM
Locking Desktop / GUI Screen iin Linux cf. Windows Hi_This_is_Dev Linux - Desktop 1 09-11-2009 08:56 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration