import wx
import platform
import sys


class MainWindow(wx.Frame):
    """ This window displays the main Program form. """
    def __init__(self, parent, id, title):
        # Define the main Frame
        wx.Frame.__init__(self, parent, id, title, size = (600,400), pos=(100, 100), style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
        self.SetBackgroundColour(wx.WHITE)

        # Create a MenuBar
        menuBar = wx.MenuBar()
        # Build a Menu Object to go into the Menu Bar
        menu1 = wx.Menu()
        self.menuMain = menu1.Append(-1, "Raise Main")
        self.menuEx1 = menu1.Append(-1, "Raise Extra 1")
        self.menuEx2 = menu1.Append(-1, "Raise Extra 2")
        self.menuExit = menu1.Append(-1, "E&xit")
        #Place the Menu Item in the Menu Bar
        menuBar.Append(menu1, "&File")

        self.SetMenuBar(menuBar)
        #Define Events for the Menu Items
        wx.EVT_MENU(self, self.menuMain.GetId(), self.OnRaise)
        wx.EVT_MENU(self, self.menuEx1.GetId(), self.OnRaise)
        wx.EVT_MENU(self, self.menuEx2.GetId(), self.OnRaise)
        wx.EVT_MENU(self, self.menuExit.GetId(), self.CloseWindow)

        sizer = wx.BoxSizer(wx.HORIZONTAL)


        txt = wx.TextCtrl(self, -1, "", style=wx.TE_MULTILINE)
        sizer.Add(txt, 1, wx.EXPAND | wx.ALL, 4)

        if sys.platform == 'win32':

            sysplat = 'Windows'

            sysver = platform.win32_ver()[0]

        elif sys.platform == 'darwin':

            sysplat = 'Mac OS X'

            sysver = platform.mac_ver()[0]

        else:

            sysplat = sys.platform

            sysver = platform.version()

        str = 'Platform:  %s %s' % (sysplat, sysver)

        if (platform.architecture()[0] == '32bit') or (sys.maxint == 2 ** 31 - 1):

            arc = '32-bit'

        elif platform.architecture()[0] == '64bit':

            arc = '64-bit'

        else:

            arc = 'Unknown architecture'

        str = '%s\nPython:  %s  (%s)\n' % (str, sys.version[:6].strip(), arc)

        if 'unicode' in wx.PlatformInfo:

            str2 = 'unicode'

        else:

            str2 = 'ansi'

        str = '%swxPython:  %s - %s\n' % (str, wx.VERSION_STRING, str2)
        if not hasattr(sys, "frozen"):
            str += 'Running from source\n'
        else:
            str += 'Built using py2app\n'

        txt.AppendText(str)

        self.extraWindow2 = ExtraWindow(self, -1, "Extra Window", "This is Window 2", wx.RED, 40)
        self.extraWindow1 = ExtraWindow(self, -1, "Extra Window", "This is Window 1", wx.BLUE, 20)

        self.SetSizer(sizer)
        self.SetAutoLayout(True)
        self.Layout()
        self.Show(True)

        

    def OnRaise(self, event):
        if event.GetId() == self.menuMain.GetId():
            theWin = self
        elif event.GetId() == self.menuEx1.GetId():
            theWin = self.extraWindow1
        elif event.GetId() == self.menuEx2.GetId():
            theWin = self.extraWindow2
        else:
            return

        if not theWin.IsShown():
            theWin.Show()
        if theWin.IsIconized():
            theWin.Iconize(False)
        theWin.Raise()
        

    def CloseWindow(self, event):
        self.extraWindow1.Close()
        self.extraWindow2.Close()
        self.Close()
      

class ExtraWindow(wx.Frame):
    """ This window displays the main Program form. """
    def __init__(self, parent, id, title, message, winColor, offset):
        # Define the main Frame
        wx.Frame.__init__(self, parent, id, title, size = (600,400), pos = (100 + offset, 100 + offset),
                          style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
        self.SetBackgroundColour(winColor)

        txt = wx.StaticText(self, -1, message)

        self.Show(True)


class MyApp(wx.App):
    def OnInit(self):
        frame = MainWindow(None, -1, "Raise Problem")
        self.SetTopWindow(frame)
        return True


app = MyApp(False)
app.MainLoop()
