下面的采样代码是针对我目前正在制作的GUI。我有两个问题。第一个问题是当我使用RedirectText类重定向python输出时,只有当循环结束时,输出才会显示在TextCtrl框('tc2')上,以进行特定的迭代。如何在打印文本时通过循环打印文本,而不是打印完成时打印文本?wxpython:将文本动态重定向到文本控制框
我的第二个问题是,我正在使用一个编译的Fortran文件EHSS_updated_atoms.out该文件的输出打印到终端而不是文本控制框。如何从编译好的fortran文件输出到文本控制框?因为它被打印到终端。
import wx
class RedirectText(object):
def __init__(self,aWxTextCtrl):
self.out=aWxTextCtrl
def write(self,string):
self.out.WriteText(string)
def __init__(self, *args, **kwargs):
super(Example, self).__init__(*args, **kwargs)
self.InitUI()
self.Centre()
self.Show()
self.SetSize((800, 600))
self.SetTitle('Hello')
def InitUI(self):
import sys
vbox = wx.BoxSizer(wx.VERTICAL)
hbox5 = wx.BoxSizer(wx.HORIZONTAL)
btn1 = wx.Button(panel, label='Run prog')
hbox5.Add(btn1)
btn2 = wx.Button(panel, label='Stop prog')
hbox5.Add(btn2, flag=wx.LEFT|wx.BOTTOM, border=5)
vbox.Add(hbox5, flag=wx.ALIGN_CENTER|wx.RIGHT, border=10)
self.Bind(wx.EVT_BUTTON, self.prog, btn1)
#self.Bind(wx.EVT_BUTTON, self.cancel_prog, btn2)
hbox3 = wx.BoxSizer(wx.HORIZONTAL)
tc2 = wx.TextCtrl(panel, style=(wx.TE_MULTILINE|wx.TE_READONLY))
hbox3.Add(tc2, proportion=1, flag=wx.EXPAND)
vbox.Add(hbox3, proportion=1, flag=wx.LEFT|wx.RIGHT|wx.EXPAND,border=10)
redir=RedirectText(tc2)
sys.stdout=redir
sys.stderr=redir
panel.SetSizer(vbox)
def prog(self, evt):
import os
import shutil
import subprocess
from mobcal_prep import mobcal
extension = '.pdb'
list_of_files = [file for file in os.listdir('%s' % _selectedDir) if file.lower().endswith(extension)]
prep = mobcal()
for pdb in list_of_files:
print '### Running PDB: %s ###' % pdb
prep.new_mobcal_format(pdb)
subprocess.call(['./EHSS_updated_atoms.out', pdb[:-4]+'_new_mobcal.mfj',pdb[:-4]+'_new_mobcal.out'])
prep.caluclate_average('%s_new_mobcal.out' % pdb[:-4], pdb)
subprocess.call(['rm', pdb[:-4]+'_new_mobcal.out'])
2012-01-03
Harpal