我有一个3选项卡面板的应用程序。我目前正在向wx发送AppendText。TextCtrl在同一面板wx.CallAfter(self.running_log1.AppendText, line)
,但也要发送AppendText到wx。TextCtrl在另一个选项卡面板,RunningPane2, wx.CallAfter(RunningPane2.running_log2.AppendText, line)
,我不能得到工作。我该如何做到这一点,或者我可以完全取消RunningPane2类,并从RunningPane1面板创建self.running_log2 = wx.TextCtrl
?
class MainWindow(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(900, 700))
self.tabbed = wx.Notebook(self, -1, style=(wx.NB_TOP))
self.running1 = RunningPane1(self.tabbed, run_params)
self.running2 = RunningPane2(self.tabbed, run_params)
self.submissions = SubmissionPane(self.tabbed, self.running1, self.running2, run_params)
self.tabbed.AddPage(self.submissions, "Submit Job")
self.tabbed.AddPage(self.running1, "Running Jobs 1")
self.tabbed.AddPage(self.running2, "Running Jobs 2")
self.Show()
#---
class SubmissionPane(wx.Panel):
def __init__(self, parent, running_pane1, running_pane2, run_params):
wx.Panel.__init__(self, parent)
...............
class RunningPane1(wx.Panel):
def __init__(self, parent, run_params):
wx.Panel.__init__(self, parent, -1)
self.running_log1 = wx.TextCtrl(self, -1, pos=(5, 5), size=(875,605),
style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)
def StartWork(self, indir1, the_queue_pane, runningMode, showBox1, tvtitle):
..............
wx.CallAfter(self.running_log1.AppendText, line)
wx.CallAfter(RunningPane2.running_log2.AppendText, line)
..............
#---
class RunningPane2(wx.Panel):
def __init__(self, parent, run_params):
wx.Panel.__init__(self, parent, -1)
self.running_log2 = wx.TextCtrl(self, -1, pos=(5, 5), size=(875,605),
style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)
self.Show()
这样行不通:RunningPane2.running_log2
.
您应该获得running_log2
的实例,您可以将MainWindow
实例传递给RunningPanel
,然后您可以从中获得running_log2
。
class MainWindow(wx.Frame):
def __init__(self, parent, id, title):
...........
self.running1 = RunningPane1(self.tabbed, self, run_params)
class RunningPane1(wx.Panel):
def __init__(self, parent, frame, run_params):
wx.Panel.__init__(self, parent, -1)
..............
self.frame = frame
def StartWork(self, indir1, the_queue_pane, runningMode, showBox1, tvtitle):
..............
wx.CallAfter(self.running_log1.AppendText, line)
wx.CallAfter(self.frame.running2.running_log2.AppendText, line)