]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/dllwidget/test_prog.py
Added wxDllWidget from Vaclav Slavik which allows wx widgets derived
[wxWidgets.git] / wxPython / demo / dllwidget / test_prog.py
1 #!/usr/bin/env python
2
3 from wxPython.wx import *
4 from wxPython.dllwidget import wxDllWidget, wxDllWidget_GetDllExt
5
6 #----------------------------------------------------------------------
7
8 class TestFrame(wxFrame):
9 def __init__(self):
10 wxFrame.__init__(self, None, -1, "Test wxDllWidget")
11
12 menu = wxMenu()
13 menu.Append(101, "Send command &1")
14 menu.Append(102, "Send command &2")
15 menu.Append(103, "Send command &3")
16 menu.AppendSeparator()
17 menu.Append(110, "E&xit")
18
19 mb = wxMenuBar()
20 mb.Append(menu, "&Test")
21 self.SetMenuBar(mb)
22
23 EVT_MENU_RANGE(self, 101, 109, self.OnSendCommand)
24 EVT_MENU(self, 110, self.OnExit)
25
26 panel = wxPanel(self, -1)
27 panel.SetFont(wxFont(12, wxSWISS, wxNORMAL, wxBOLD))
28
29 st = wxStaticText(panel, -1,
30 "The widget below was dynamically imported from\n"
31 "test_dll.dll or test_dll.so with no prior knowledge\n"
32 "of it's contents or structure by wxPython.")
33
34 self.dw = dw = wxDllWidget(panel, -1,
35 "test_dll" + wxDllWidget_GetDllExt(),
36 "TestWindow",
37 size=(250, 150))
38
39 # The embedded window is the one exported from the DLL
40 print dw.GetEmbeddedWindow().GetClassName()
41
42 # This shows that we can give it a child from this side of things.
43 # You can also call any wxWindow methods on it too.
44 wxStaticText(dw.GetEmbeddedWindow(), -1,
45 "Loaded from test_dll...", pos=(10,10))
46
47
48 sizer = wxBoxSizer(wxVERTICAL)
49 sizer.Add(wxStaticLine(panel, -1), 0, wxGROW)
50 sizer.Add(st, 0, wxGROW|wxALL, 5)
51 sizer.Add(dw, 1, wxGROW|wxALL, 5)
52
53 panel.SetSizer(sizer)
54 panel.SetAutoLayout(true)
55 sizer.Fit(self)
56 sizer.SetSizeHints(self)
57
58
59 def OnExit(self, evt):
60 self.Close()
61
62
63 def OnSendCommand(self, evt):
64 ID = evt.GetId() - 100 # use the menu ID as the command
65 param = ""
66 if ID == 2:
67 dlg = wxTextEntryDialog(self, "Enter a colour name to pass to the embedded widget:")
68 if dlg.ShowModal() == wxID_OK:
69 param = dlg.GetValue()
70 dlg.Destroy()
71 self.dw.SendCommand(ID, param)
72
73
74
75 #----------------------------------------------------------------------
76
77
78 if __name__ == "__main__":
79 app = wxPySimpleApp()
80 frame = TestFrame()
81 frame.Show(true)
82 app.MainLoop()