Ich kämpfe seit Tagen mit einem Problem: Ich versuche einen Dialog zu erzeugen, der nicht immer in Front des Haupt-Frames steht. Wenn ich auf das Hauptframe klicke, möchte ich, dass der Dialog in den Hintergrund entschwindet. Ich kriege das einfach nicht hin.
Hier das Codebeispiel:
Code: Alles auswählen
import wx
class MyDialog1(wx.Dialog):
def __init__(self, parent, id):
sty = wx.DEFAULT_DIALOG_STYLE | wx.DIALOG_NO_PARENT
wx.Dialog.__init__(self, parent, id, "MyDialog parent",
wx.Point(30,120), wx.Size(180, 100), style=sty)
class MyDialog2(wx.Dialog):
def __init__(self, parent, id):
sty = wx.DEFAULT_DIALOG_STYLE | wx.DIALOG_NO_PARENT
wx.Dialog.__init__(self, None, id, "MyDialog None",
wx.Point(230,120), wx.Size(180, 100), style=sty)
class MyPanel(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id, wx.DefaultPosition,
wx.DefaultSize)
b1 = wx.Button(self, 1001, "Open dialog window with parent",
wx.Point(8, 8))
b1.Bind(wx.EVT_BUTTON, self.OnClick1)
b2 = wx.Button(self, 1002, "Open dialog window with None parent",
wx.Point(8, 38))
b2.Bind(wx.EVT_BUTTON, self.OnClick2)
def OnClick1(self, event):
self.dlg1 = MyDialog1(self, -1)
self.dlg1.Show(True)
def OnClick2(self, event):
self.dlg2 = MyDialog2(self, -1)
self.dlg2.Show(True)
class MyFrame(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, "MyFrame",
wx.Point(20, 20), wx.Size(300, 150))
self.pa = MyPanel(self,-1)
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1)
frame.Show(True)
self.SetTopWindow(frame)
return True
def main():
app = MyApp(0)
app.MainLoop()
if __name__ == '__main__':
main()
Das Style-Flag "wx.DIALOG_NO_PARENT" scheint keinen Einfluss zu haben. Dialog 1 hat ja wohl trotzdem ein Parent.
Ich arbeite unter Windows XP SP2. Python hat die Version 2.3.4, wxPython die Version 2.6.1.0.
Für Tipps irgendwelcher Art bin ich dankbar.
amarganth