salve a tutti!
il mio programmino esegue un comando di sistema, e quindi dovrei fare in modo che l'output venga rediretto su una TextCtrl per essere visibile.
ho fatto alcune prove seguendo varie guide, ma senza successo.
ad esempio:
codice:
import subprocess
import wx
import sys
from wx._controls import Button
class Form(wx.Frame):
txtUrl = None
lblWait = None
def __init__(self):
wx.Frame.__init__(self, None, title = "Python", size = (410, 400), style = wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER)
btnGo = Button(self, label = "GO", pos = (5, 40))
btnGo.Bind(wx.EVT_BUTTON, self.comando)
self.txtResult = wx.TextCtrl(self, pos = (5, 100), size = (400, 300), style = wx.TE_MULTILINE | wx.TE_READONLY | wx.HSCROLL)
redir = RedirectText(self.txtResult)
sys.stdout = redir
def comando(self, strUrl):
subprocess.call(["ls", "-lR", "/home/casa/.netbeans"])
class RedirectText(object):
def __init__(self, aWxTextCtrl):
self.out = aWxTextCtrl
def write(self, string):
wx.CallAfter(self.out.WriteText, string)
esegue il comando, ma l'output rimane sul terminale e non viene inviato alla gui.
sapete dirmi dove sbaglio??