私はanaconda IDEとpython 3.4でguiアプリケーションを開発しました。単純なテストスクリプトを使って、3.4で出力がリアルタイムで表示され、入力を待っていると思っていました。アプリケーションの最終目標は、スクリプトを実行することでした。私は制御できず、2.7でコーディングされていて、スクリプトコマンドを送信していました。私は2.7で動作するようにGUIスクリプトを十分に変換しましたが、qprocessは期待どおりに動作しません。単純なテストスクリプトでは、raw_inputでのハングアップを仮定して、何も表示されません。目的のスクリプトを実行すると、何も表示されず、すべてのメッセージがシャットダウンしたことを示すメッセージが表示されます(タイムアウト機能がチェックできない可能性があります)。残念ながら、私は実際のスクリプトを投稿することはできませんが、私は機能しないこの簡単なテストケースにコードを煮詰めました。私は問題がリアルタイムでスクリプトの出力を読むのではなく、プロセスが入力を正しく待っていないと思う。 2.7でどのように動作させることができますか?qプロセスでGUI内の起動スクリプトが3.4で動作しない2.7 raw_inputでハングしていますか?
mainwindow.ui:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>562</width>
<height>608</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="fileLocation"/>
</item>
<item>
<widget class="QPushButton" name="openFileButton">
<property name="text">
<string>OpenFile</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="startButton">
<property name="text">
<string>Start</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTextBrowser" name="textBrowser"/>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>562</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
main.py:パイソン2.7をコード
from PyQt4 import QtCore, QtGui, uic
class MyMainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
uic.loadUi('mainwindow.ui', self)
self.openFileButton.clicked.connect(self.getFname)
self.process=QtCore.QProcess(self)
self.process.readyRead.connect(self.dataReady)
self.startButton.clicked.connect(self.startScript)
def getFname (self):
self.fileLocation.setText(QtGui.QFileDialog.getOpenFileName(self, "Save File", "", "*.py ;; All files *.*"))
def dataReady(self):
self.textBrowser.append(bytearray(self.process.readAllStandardOutput()).decode('utf-8'))
def startScript(self):
self.process.start('python',[self.fileLocation.text()])
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
main_window = MyMainWindow()
main_window.show()
sys.exit(app.exec_())
test.py:
print "running script 2"
print "Enter an input A,B,C:"
s=raw_input("")
print "you selected:"+s
あなたは働いていた3.4のスクリプトを投稿できますか? –
はい: 'プリント( "スクリプト2を実行している") プリント( "入力Aを入力し、B、C:") S =入力( "") プリント( "もし選択:" + S)' – kaminsknator
缶あなたのpython 2.7でprint( "選択した:" + s) 'print("スクリプトAを実行してください "テスト? –