I have made a test but I probably have missed something as the threading is not working as expected… (see code below)
Sorry ( the frame does not look nice… but it works and for long tasks the main app is still stucked - may be due to the fact that the parent window of the MiniFrame is the mainframe and not the thread ? but wx.Frame seems not to accept the thread as a parent…).
Thanx
Robert
···
#!/usr/bin/env python
-- coding: ISO-8859-1 --
generated by wxGlade 0.4.1 on Sun Dec 31 18:34:03 2006
import wx
from wx import py
import threading
import thread
class MyFrame(wx.Frame):
def init(self, *args, **kwds):
# begin wxGlade: MyFrame.init
kwds[“style”] = wx.DEFAULT_FRAME_STYLE
wx.Frame.init(self, *args,
**kwds)
self.button_1 = wx.Button(self, -1, “button_1”)
self.Bind(wx.EVT_BUTTON , self.OnButton, self.button_1 )
self.tracker = []
self.__set_properties()
self.__do_layout()
# end wxGlade
def __set_properties(self):
# begin wxGlade: MyFrame.__set_properties
self.SetTitle("Test_RFV")
self.SetSize((400, 300))
# end wxGlade
def __do_layout(self):
# begin wxGlade:
MyFrame.__do_layout
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_1.Add(self.button_1, 0, wx.ADJUST_MINSIZE, 0)
self.SetAutoLayout(True)
self.SetSizer(sizer_1)
self.Layout()
# end wxGlade
def OnButton(self, ev):
self.tracker.append(TFrame(self, "This is a wx.MiniFrame", style=wx.DEFAULT_FRAME_STYLE | wx.TINY_CAPTION_HORIZ))
self.tracker[-1].Show(True)
return
end of class MyFrame
class MyMiniFrame(wx.MiniFrame):
def
init(
self, parent, title, pos=wx.DefaultPosition, size=wx.DefaultSize,
style=wx.DEFAULT_FRAME_STYLE
):
wx.MiniFrame.__init__(self, parent, -1, title, pos, size, style)
panel = wx.Panel(self, -1)
self.SetSize((200,200))
self.CenterOnParent(wx.BOTH)
self.myshell = py.shell.Shell(panel, -1, introText="A Mini Shell")
class TFrame(threading.Thread):
“”" Threaded"""
def init(self, parent, title, pos=wx.DefaultPosition,
size=wx.DefaultSize,
style=wx.DEFAULT_FRAME_STYLE):
threading.Thread.init(self)
self.parent=parent
#Thread is open and ready to be called
self.win = MyMiniFrame(parent, “This is a wx.MiniFrame Threaded”,
style=wx.DEFAULT_FRAME_STYLE | wx.TINY_CAPTION_HORIZ)
def run(self):
print "Thread Started"
self.win.Show(True)
return True
def Show(self, val):
self.win.Show(val)
if name == “main”:
testRFVapp = wx.PySimpleApp(0)
wx.InitAllImageHandlers()
Test_RFV = MyFrame(None, -1, “”)
testRFVapp.SetTopWindow(Test_RFV)
Test_RFV.Show()
testRFVapp.MainLoop()
Découvrez une nouvelle façon d’obtenir des réponses à toutes vos questions ! Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses.