Last active
April 26, 2016 11:55
-
-
Save nrtkbb/eb73c3db642cccb291f4e49d8101dd82 to your computer and use it in GitHub Desktop.
http://flame-blaze.net/archives/3341 を少し改変したやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import sys | |
import subprocess | |
import time | |
from PySide import QtCore, QtGui | |
from PySide.QtUiTools import QUiLoader | |
def load_ui(widget, ui_file): | |
loader = QUiLoader() | |
try: | |
f = QtCore.QFile(ui_file) | |
f.open(QtCore.QFile.ReadOnly) | |
ui = loader.load(f, widget) | |
finally: | |
f.close() | |
return ui | |
class TextEdit(QtGui.QWidget): | |
ui_file = 'textEdit.ui' | |
def __init__(self, parent=None): | |
super(TextEdit, self).__init__(parent) | |
self.ui = load_ui(self, self.ui_file) | |
layout = QtGui.QVBoxLayout() | |
layout.addWidget(self.ui) | |
self.setLayout(layout) | |
self.cursor = self.ui.textEdit.textCursor() | |
self.ui.pushButton.clicked.connect(self.start) | |
def start(self): | |
p = subprocess.Popen(['HELP']) | |
while not p.poll(): | |
time.sleep(1) | |
self.cursor.movePosition(QtGui.QTextCursor.End) | |
self.cursor.insertText(p.stdout()) | |
def main(): | |
app = QtGui.QApplication(sys.argv) | |
# 日本語使用時に入れておくもの | |
QtCore.QTextCodec.setCodecForCStrings(QtCore.QTextCodec.codecForLocale()) | |
window = TextEdit() | |
window.show() | |
return app.exec_() | |
if __name__ == '__main__': | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment