#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# generated by wxGlade 0.9.9pre on Fri Jan  3 20:14:00 2020
#

import wx

# begin wxGlade: dependencies
# end wxGlade

# begin wxGlade: extracode
# end wxGlade


class MyFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyFrame.__init__
        kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.SetSize((400, 300))
        self.SetTitle("frame")

        # Menu Bar
        self.frame_menubar = wx.MenuBar()
        wxglade_tmp_menu = wx.Menu()
        item = wxglade_tmp_menu.Append(wx.ID_ANY, "Show Dialog", "")
        self.Bind(wx.EVT_MENU, self.show_modal, item)
        self.frame_menubar.Append(wxglade_tmp_menu, "Menu")
        self.SetMenuBar(self.frame_menubar)
        # Menu Bar end

        self.panel_1 = wx.Panel(self, wx.ID_ANY)

        sizer_1 = wx.BoxSizer(wx.VERTICAL)

        self.button_1 = wx.Button(self.panel_1, wx.ID_ANY, "Show Dialog (modal)")
        sizer_1.Add(self.button_1, 0, wx.ALL, 4)

        static_text_1 = wx.StaticText(self.panel_1, wx.ID_ANY, "Text from dialog:")
        sizer_1.Add(static_text_1, 0, wx.ALL, 4)

        self.text_ctrl_1 = wx.TextCtrl(self.panel_1, wx.ID_ANY, "", style=wx.TE_READONLY)
        sizer_1.Add(self.text_ctrl_1, 0, wx.ALL | wx.EXPAND, 4)

        self.panel_1.SetSizer(sizer_1)

        self.Layout()

        self.Bind(wx.EVT_BUTTON, self.show_modal, self.button_1)
        # end wxGlade

    def show_modal(self, event):  # wxGlade: MyFrame.<event_handler>
        # event might be a button or menu event; it's not used anyway
        # instantiate dialog and set text control to initial value
        with MyDialog(self) as dlg:
            dlg.text_ctrl_1.SetValue(self.text_ctrl_1.GetValue())
            # show as modal dialog
            if dlg.ShowModal() == wx.ID_OK:
                # user has hit OK -> read text control value
                self.text_ctrl_1.SetValue(dlg.text_ctrl_1.GetValue())

# end of class MyFrame

class MyDialog(wx.Dialog):
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyDialog.__init__
        kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_DIALOG_STYLE
        wx.Dialog.__init__(self, *args, **kwds)
        self.SetTitle("dialog")

        sizer_1 = wx.BoxSizer(wx.VERTICAL)

        static_text_1 = wx.StaticText(self, wx.ID_ANY, "Enter text:")
        sizer_1.Add(static_text_1, 0, wx.ALL, 8)

        self.text_ctrl_1 = wx.TextCtrl(self, wx.ID_ANY, "")
        sizer_1.Add(self.text_ctrl_1, 0, wx.ALL | wx.EXPAND, 8)

        sizer_1.Add((20, 20), 1, wx.EXPAND, 0)

        sizer_2 = wx.StdDialogButtonSizer()
        sizer_1.Add(sizer_2, 0, wx.ALIGN_RIGHT | wx.ALL, 4)

        self.button_OK = wx.Button(self, wx.ID_OK, "")
        self.button_OK.SetDefault()
        sizer_2.AddButton(self.button_OK)

        self.button_CANCEL = wx.Button(self, wx.ID_CANCEL, "")
        sizer_2.AddButton(self.button_CANCEL)

        sizer_2.Realize()

        self.SetSizer(sizer_1)
        sizer_1.Fit(self)

        self.SetAffirmativeId(self.button_OK.GetId())
        self.SetEscapeId(self.button_CANCEL.GetId())

        self.Layout()
        # end wxGlade

# end of class MyDialog

class MyApp(wx.App):
    def OnInit(self):
        self.frame = MyFrame(None, wx.ID_ANY, "")
        self.SetTopWindow(self.frame)
        self.frame.Show()
        return True

# end of class MyApp

if __name__ == "__main__":
    app = MyApp(0)
    app.MainLoop()
