]>
Commit | Line | Data |
---|---|---|
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 | if dw.Ok(): | |
40 | # The embedded window is the one exported from the DLL | |
41 | print dw.GetWidgetWindow().GetClassName() | |
42 | ||
43 | # This shows that we can give it a child from this side of things. | |
44 | # You can also call any wxWindow methods on it too. | |
45 | wxStaticText(dw.GetWidgetWindow(), -1, | |
46 | "Loaded from test_dll...", pos=(10,10)) | |
47 | else: | |
48 | wxStaticText(dw, -1, "ERROR!!!!", pos=(20,20)) | |
49 | ||
50 | sizer = wxBoxSizer(wxVERTICAL) | |
51 | sizer.Add(wxStaticLine(panel, -1), 0, wxGROW) | |
52 | sizer.Add(st, 0, wxGROW|wxALL, 5) | |
53 | sizer.Add(dw, 1, wxGROW|wxALL, 5) | |
54 | ||
55 | panel.SetSizer(sizer) | |
56 | panel.SetAutoLayout(true) | |
57 | sizer.Fit(self) | |
58 | sizer.SetSizeHints(self) | |
59 | ||
60 | ||
61 | def OnExit(self, evt): | |
62 | self.Close() | |
63 | ||
64 | ||
65 | def OnSendCommand(self, evt): | |
66 | ID = evt.GetId() - 100 # use the menu ID as the command | |
67 | param = "" | |
68 | if ID == 2: | |
69 | dlg = wxTextEntryDialog(self, "Enter a colour name to pass to the embedded widget:") | |
70 | if dlg.ShowModal() == wxID_OK: | |
71 | param = dlg.GetValue() | |
72 | dlg.Destroy() | |
73 | self.dw.SendCommand(ID, param) | |
74 | ||
75 | ||
76 | ||
77 | #---------------------------------------------------------------------- | |
78 | ||
79 | ||
80 | if __name__ == "__main__": | |
81 | app = wxPySimpleApp() | |
82 | frame = TestFrame() | |
83 | frame.Show(true) | |
84 | app.MainLoop() |