mirror of
https://github.com/wxWidgets/wxWidgets.git
synced 2026-09-28 15:50:17 +08:00
Added wxDllWidget from Vaclav Slavik which allows wx widgets derived
from wxWindow to be loaded from a C++ .dll (or .so) and be used in a wxPython program, without the widget having to be SWIGged first. Various updates for distribs git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12890 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -105,6 +105,14 @@ wxRemotelyScrolledTreeCtrl, wxTreeCompanionWindow,
|
||||
wxThinSplitterWindow, and wxSplitterScrolledWindow, some of which may
|
||||
also be useful by themselves.
|
||||
|
||||
Added wxDllWidget from Vaclav Slavik which allows wx widgets derived
|
||||
from wxWindow to be loaded from a C++ .dll (or .so) and be used in a
|
||||
wxPython program, without the widget having to be SWIGged first. The
|
||||
visible API of the widget is limited to wxWindow methods plus a
|
||||
SendCommand method, but it is still quite powerful. See
|
||||
wxPython/contrib/dllwidget and wxPython/demo/dllwidget for more
|
||||
details.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -166,3 +166,17 @@ include contrib/gizmos/*.c
|
||||
include contrib/gizmos/*.h
|
||||
include contrib/gizmos/contrib/include/wx/gizmos/*.h
|
||||
include contrib/gizmos/contrib/src/gizmos/*.cpp
|
||||
|
||||
include contrib/dllwidget/*.txt
|
||||
include contrib/dllwidget/*.i
|
||||
include contrib/dllwidget/*.py
|
||||
include contrib/dllwidget/*.cpp
|
||||
include contrib/dllwidget/*.c
|
||||
include contrib/dllwidget/*.h
|
||||
|
||||
include demo/dllwidget/*.h
|
||||
include demo/dllwidget/*.cpp
|
||||
include demo/dllwidget/*.py
|
||||
include demo/dllwidget/Makefile
|
||||
include demo/dllwidget/makefile.*
|
||||
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: dllwidget.cpp
|
||||
// Purpose: Dynamically loadable C++ widget for wxPython
|
||||
// Author: Vaclav Slavik
|
||||
// Created: 2001/12/03
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2001 Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "dllwidget.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/defs.h"
|
||||
#include "wx/dynlib.h"
|
||||
#include "wx/sizer.h"
|
||||
|
||||
#include "dllwidget.h"
|
||||
|
||||
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxDllWidget, wxPanel)
|
||||
|
||||
wxDllWidget::wxDllWidget(wxWindow *parent,
|
||||
wxWindowID id,
|
||||
const wxString& dllName, const wxString& className,
|
||||
const wxPoint& pos, const wxSize& size,
|
||||
long style)
|
||||
: wxPanel(parent, id, pos, size, wxTAB_TRAVERSAL | wxNO_BORDER,
|
||||
className + wxT("_container")),
|
||||
m_widget(NULL), m_lib(NULL), m_controlAdded(FALSE)
|
||||
{
|
||||
SetBackgroundColour(wxColour(255, 0, 255));
|
||||
if ( !!className )
|
||||
LoadWidget(dllName, className, style);
|
||||
}
|
||||
|
||||
wxDllWidget::~wxDllWidget()
|
||||
{
|
||||
UnloadWidget();
|
||||
}
|
||||
|
||||
void wxDllWidget::AddChild(wxWindowBase *child)
|
||||
{
|
||||
wxASSERT_MSG( !m_controlAdded, wxT("Couldn't load two widgets into one container!") )
|
||||
|
||||
wxPanel::AddChild(child);
|
||||
|
||||
m_controlAdded = TRUE;
|
||||
wxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
sizer->Add((wxWindow*)child, 1, wxEXPAND);
|
||||
SetSizer(sizer);
|
||||
SetAutoLayout(TRUE);
|
||||
Layout();
|
||||
}
|
||||
|
||||
|
||||
wxString wxDllWidget::GetDllExt()
|
||||
{
|
||||
return wxDllLoader::GetDllExt();
|
||||
}
|
||||
|
||||
|
||||
typedef WXDLLEXPORT bool (*DLL_WidgetFactory_t)(const wxString& className,
|
||||
wxWindow *parent,
|
||||
long style,
|
||||
wxWindow **classInst,
|
||||
wxSendCommandFunc *cmdFunc);
|
||||
|
||||
bool wxDllWidget::LoadWidget(const wxString& dll, const wxString& className,
|
||||
long style)
|
||||
{
|
||||
UnloadWidget();
|
||||
|
||||
// Load the dynamic library
|
||||
m_lib = new wxDynamicLibrary(dll);
|
||||
if ( !m_lib->IsLoaded() )
|
||||
{
|
||||
delete m_lib;
|
||||
m_lib = NULL;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
DLL_WidgetFactory_t factory;
|
||||
factory = (DLL_WidgetFactory_t) m_lib->GetSymbol(wxT("DLL_WidgetFactory"));
|
||||
if ( factory == NULL)
|
||||
{
|
||||
delete m_lib;
|
||||
m_lib = NULL;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ( !factory(className, this, style, &m_widget, &m_cmdFunc) )
|
||||
{
|
||||
delete m_widget;
|
||||
delete m_lib;
|
||||
m_lib = NULL;
|
||||
m_widget = NULL;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void wxDllWidget::UnloadWidget()
|
||||
{
|
||||
if ( m_widget )
|
||||
{
|
||||
DestroyChildren();
|
||||
m_widget = NULL;
|
||||
delete m_lib;
|
||||
m_lib = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int wxDllWidget::SendCommand(int cmd, const wxString& param)
|
||||
{
|
||||
wxASSERT_MSG( m_widget && m_cmdFunc, wxT("Sending command to not loaded widget!"));
|
||||
|
||||
return m_cmdFunc(m_widget, cmd, param);
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: dllwidget.h
|
||||
// Purpose: Dynamically loadable C++ widget for wxPython
|
||||
// Author: Vaclav Slavik
|
||||
// Created: 2001/12/03
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2001 Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface "dllwidget.h"
|
||||
#endif
|
||||
|
||||
#ifndef __DLLWIDGET_H__
|
||||
#define __DLLWIDGET_H__
|
||||
|
||||
#include "wx/panel.h"
|
||||
|
||||
/*
|
||||
|
||||
wxDllWidget can be used to embed a wxWindow implemented in C++ in your
|
||||
wxPython application without the need to write a SWIG interface. Widget's code
|
||||
is stored in shared library or DLL that exports DLL_WidgetFactory symbol
|
||||
and loaded at runtime. All you have to do is to pass the name of DLL and the class
|
||||
to create to wxDllWidget's ctor.
|
||||
|
||||
Runtime-loadable widget must have HandleCommand method (see the example) that is
|
||||
used to communicate with Python app. You call wxDllWidget.SendCommand(cmd,param) from
|
||||
Python and it in turn calls HandleCommand of the loaded widget.
|
||||
|
||||
You must use DECLARE_DLL_WIDGET, BEGIN_WIDGET_LIBRARY, END_WIDGET_LIBRARY and
|
||||
REGISTER_WIDGET macros in your C++ module in order to provide all the meat
|
||||
wxDllWidget needs.
|
||||
|
||||
Example of use:
|
||||
|
||||
#define CMD_MAKEWHITE 1
|
||||
|
||||
class MyWindow : public wxWindow
|
||||
{
|
||||
public:
|
||||
MyWindow(wxWindow *parent, long style)
|
||||
: wxWindow(parent, -1) {}
|
||||
|
||||
int HandleCommand(int cmd, const wxString& param)
|
||||
{
|
||||
if (cmd == CMD_MAKEWHITE)
|
||||
SetBackgroundColour(*wxWHITE);
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
DECLARE_DLL_WIDGET(MyWindow)
|
||||
|
||||
class MyCanvasWindow : public wxScrolledWindow
|
||||
{
|
||||
...
|
||||
};
|
||||
DECLARE_DLL_WIDGET(MyCanvasWindow)
|
||||
|
||||
BEGIN_WIDGET_LIBRARY()
|
||||
REGISTER_WIDGET(MyWindow)
|
||||
REGISTER_WIDGET(MyCanvasWindow)
|
||||
END_WIDGET_LIBRARY()
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
class WXDLLEXPORT wxDynamicLibrary;
|
||||
|
||||
typedef int (*wxSendCommandFunc)(wxWindow *wnd, int cmd, const wxString& param);
|
||||
|
||||
class wxDllWidget : public wxPanel
|
||||
{
|
||||
public:
|
||||
wxDllWidget(wxWindow *parent,
|
||||
wxWindowID id = -1,
|
||||
const wxString& dllName = wxEmptyString,
|
||||
const wxString& className = wxEmptyString,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize,
|
||||
long style = 0);
|
||||
virtual ~wxDllWidget();
|
||||
|
||||
bool Ok() { return m_widget != NULL; }
|
||||
|
||||
virtual int SendCommand(int cmd, const wxString& param = wxEmptyString);
|
||||
virtual wxWindow* GetEmbeddedWindow() { return m_widget; }
|
||||
|
||||
virtual void AddChild(wxWindowBase *child);
|
||||
|
||||
static wxString GetDllExt();
|
||||
|
||||
|
||||
protected:
|
||||
bool LoadWidget(const wxString& dll, const wxString& className, long style);
|
||||
void UnloadWidget();
|
||||
|
||||
protected:
|
||||
wxWindow* m_widget;
|
||||
wxSendCommandFunc m_cmdFunc;
|
||||
wxDynamicLibrary* m_lib;
|
||||
bool m_controlAdded;
|
||||
|
||||
private:
|
||||
DECLARE_ABSTRACT_CLASS(wxDllWidget)
|
||||
};
|
||||
|
||||
|
||||
#define DECLARE_DLL_WIDGET(widget) \
|
||||
static int SendCommandTo##widget(wxWindow *wnd, int cmd, const wxString& param) \
|
||||
{ \
|
||||
return wxStaticCast(wnd, widget)->HandleCommand(cmd, param); \
|
||||
}
|
||||
|
||||
|
||||
#define BEGIN_WIDGET_LIBRARY() \
|
||||
extern "C" WXEXPORT bool DLL_WidgetFactory( \
|
||||
const wxString& className, \
|
||||
wxWindow *parent, \
|
||||
long style, \
|
||||
wxWindow **classInst, \
|
||||
wxSendCommandFunc *cmdFunc) \
|
||||
{ \
|
||||
wxClassInfo::CleanUpClasses(); \
|
||||
wxClassInfo::InitializeClasses();
|
||||
|
||||
|
||||
#define REGISTER_WIDGET(widget) \
|
||||
if ( className == wxT(#widget) ) \
|
||||
{ \
|
||||
*classInst = new widget(parent, style); \
|
||||
*cmdFunc = SendCommandTo##widget; \
|
||||
return TRUE; \
|
||||
}
|
||||
|
||||
|
||||
#define END_WIDGET_LIBRARY() \
|
||||
return FALSE; \
|
||||
}
|
||||
|
||||
#endif // __DLLWIDGET_H__
|
||||
@@ -0,0 +1,6 @@
|
||||
# The SWIG module is named dllwidget_ to avoid name clashes, so
|
||||
# this stub just imports everything in it so the firendly module
|
||||
# name can be used elsewhere.
|
||||
|
||||
from dllwidget_ import *
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,111 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: dllwidget_.i
|
||||
// Purpose: Load wx widgets from external DLLs
|
||||
//
|
||||
// Author: Robin Dunn
|
||||
//
|
||||
// Created: 04-Dec-2001
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2001 by Total Control Software
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
%module dllwidget_
|
||||
|
||||
|
||||
%{
|
||||
#include "export.h"
|
||||
#include "dllwidget.h"
|
||||
%}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
%include typemaps.i
|
||||
%include my_typemaps.i
|
||||
|
||||
%extern wx.i
|
||||
%extern windows.i
|
||||
%extern _defs.i
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
|
||||
wxDllWidget can be used to embed a wxWindow implemented in C++ in your
|
||||
wxPython application without the need to write a SWIG interface. Widget's code
|
||||
is stored in shared library or DLL that exports DLL_WidgetFactory symbol
|
||||
and loaded at runtime. All you have to do is to pass the name of DLL and the class
|
||||
to create to wxDllWidget's ctor.
|
||||
|
||||
Runtime-loadable widget must have HandleCommand method (see the example) that is
|
||||
used to communicate with Python app. You call wxDllWidget.SendCommand(cmd,param) from
|
||||
Python and it in turn calls HandleCommand of the loaded widget.
|
||||
|
||||
You must use DECLARE_DLL_WIDGET, BEGIN_WIDGET_LIBRARY, END_WIDGET_LIBRARY and
|
||||
REGISTER_WIDGET macros in your C++ module in order to provide all the meat
|
||||
wxDllWidget needs.
|
||||
|
||||
Example of use:
|
||||
|
||||
#define CMD_MAKEWHITE 1
|
||||
|
||||
class MyWindow : public wxWindow
|
||||
{
|
||||
public:
|
||||
MyWindow(wxWindow *parent, long style)
|
||||
: wxWindow(parent, -1) {}
|
||||
|
||||
int HandleCommand(int cmd, const wxString& param)
|
||||
{
|
||||
if (cmd == CMD_MAKEWHITE)
|
||||
SetBackgroundColour(*wxWHITE);
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
DECLARE_DLL_WIDGET(MyWindow)
|
||||
|
||||
class MyCanvasWindow : public wxScrolledWindow
|
||||
{
|
||||
...
|
||||
};
|
||||
DECLARE_DLL_WIDGET(MyCanvasWindow)
|
||||
|
||||
BEGIN_WIDGET_LIBRARY()
|
||||
REGISTER_WIDGET(MyWindow)
|
||||
REGISTER_WIDGET(MyCanvasWindow)
|
||||
END_WIDGET_LIBRARY()
|
||||
|
||||
*/
|
||||
|
||||
class wxDllWidget : public wxPanel
|
||||
{
|
||||
public:
|
||||
wxDllWidget(wxWindow *parent,
|
||||
wxWindowID id = -1,
|
||||
const wxString& dllName = wxEmptyString,
|
||||
const wxString& className = wxEmptyString,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize,
|
||||
long style = 0);
|
||||
|
||||
%pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
|
||||
|
||||
bool Ok();
|
||||
|
||||
int SendCommand(int cmd, const wxString& param = wxEmptyString);
|
||||
wxWindow* GetEmbeddedWindow();
|
||||
|
||||
static wxString GetDllExt();
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
%init %{
|
||||
|
||||
wxClassInfo::CleanUpClasses();
|
||||
wxClassInfo::InitializeClasses();
|
||||
|
||||
%}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
@@ -0,0 +1,76 @@
|
||||
# This file was created automatically by SWIG.
|
||||
import dllwidget_c
|
||||
|
||||
from misc import *
|
||||
|
||||
from misc2 import *
|
||||
|
||||
from windows import *
|
||||
|
||||
from gdi import *
|
||||
|
||||
from clip_dnd import *
|
||||
|
||||
from events import *
|
||||
|
||||
from streams import *
|
||||
|
||||
from utils import *
|
||||
|
||||
from mdi import *
|
||||
|
||||
from frames import *
|
||||
|
||||
from stattool import *
|
||||
|
||||
from controls import *
|
||||
|
||||
from controls2 import *
|
||||
|
||||
from windows2 import *
|
||||
|
||||
from cmndlgs import *
|
||||
|
||||
from windows3 import *
|
||||
|
||||
from image import *
|
||||
|
||||
from printfw import *
|
||||
|
||||
from sizers import *
|
||||
|
||||
from filesys import *
|
||||
class wxDllWidgetPtr(wxPanelPtr):
|
||||
def __init__(self,this):
|
||||
self.this = this
|
||||
self.thisown = 0
|
||||
def Ok(self, *_args, **_kwargs):
|
||||
val = apply(dllwidget_c.wxDllWidget_Ok,(self,) + _args, _kwargs)
|
||||
return val
|
||||
def SendCommand(self, *_args, **_kwargs):
|
||||
val = apply(dllwidget_c.wxDllWidget_SendCommand,(self,) + _args, _kwargs)
|
||||
return val
|
||||
def GetEmbeddedWindow(self, *_args, **_kwargs):
|
||||
val = apply(dllwidget_c.wxDllWidget_GetEmbeddedWindow,(self,) + _args, _kwargs)
|
||||
return val
|
||||
def __repr__(self):
|
||||
return "<C wxDllWidget instance at %s>" % (self.this,)
|
||||
class wxDllWidget(wxDllWidgetPtr):
|
||||
def __init__(self,*_args,**_kwargs):
|
||||
self.this = apply(dllwidget_c.new_wxDllWidget,_args,_kwargs)
|
||||
self.thisown = 1
|
||||
self._setOORInfo(self)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-------------- FUNCTION WRAPPERS ------------------
|
||||
|
||||
wxDllWidget_GetDllExt = dllwidget_c.wxDllWidget_GetDllExt
|
||||
|
||||
|
||||
|
||||
#-------------- VARIABLE WRAPPERS ------------------
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
|
||||
CXX = c++
|
||||
CXXFLAGS = `wx-config --cxxflags` -fPIC -I.
|
||||
LDFLAGS = `wx-config --libs`
|
||||
|
||||
|
||||
all: test_prg test_dll.so
|
||||
|
||||
test_prg: dllwidget.o test_prg.o
|
||||
$(CXX) $(LDFLAGS) -o $@ dllwidget.o test_prg.o
|
||||
|
||||
test_dll.so: test_dll.o
|
||||
$(CXX) $(LDFLAGS) -shared -o $@ $<
|
||||
|
||||
%.o : %.cpp
|
||||
$(CXX) -c $(CXXFLAGS) -o $@ $<
|
||||
|
||||
clean:
|
||||
rm -f *.o *.so test_prg
|
||||
@@ -0,0 +1,32 @@
|
||||
|
||||
WXDIR = $(WXWIN)
|
||||
WXUSINGDLL = 1
|
||||
|
||||
PROGRAM = test_dll
|
||||
OBJECTS = test_dll.obj
|
||||
|
||||
!include $(WXDIR)\src\makevc.env
|
||||
|
||||
|
||||
$(PROGRAM).dll : $(OBJECTS)
|
||||
$(link) @<<
|
||||
-out:$(PROGRAM).dll
|
||||
-dll $(LINK_DEBUG_FLAGS) $(WINLINKFLAGS)
|
||||
$(OBJECTS)
|
||||
$(WXLIB)
|
||||
<<
|
||||
|
||||
|
||||
clean:
|
||||
del $(OBJECTS)
|
||||
del $(PROGRAM).dll
|
||||
del $(PROGRAM).exp
|
||||
del $(PROGRAM).lib
|
||||
del $(PROGRAM).pdb
|
||||
|
||||
test:
|
||||
@echo -out:$(PROGRAM).dll
|
||||
@echo -dll $(LINK_DEBUG_FLAGS) $(WINLINKFLAGS)
|
||||
@echo $(OBJECTS)
|
||||
@echo $(WXLIB)
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
|
||||
#include <wx/defs.h>
|
||||
#include <wx/window.h>
|
||||
#include <wx/msgdlg.h>
|
||||
|
||||
#include "../dllwidget.h"
|
||||
|
||||
class TestWindow : public wxWindow
|
||||
{
|
||||
public:
|
||||
TestWindow(wxWindow *parent, long style)
|
||||
: wxWindow(parent, -1)
|
||||
{
|
||||
SetBackgroundColour(wxColour("white"));
|
||||
}
|
||||
|
||||
int HandleCommand(int cmd, const wxString& param)
|
||||
{
|
||||
if (cmd == 1)
|
||||
{
|
||||
SetBackgroundColour(wxColour("red"));
|
||||
Refresh();
|
||||
}
|
||||
|
||||
if (cmd == 2)
|
||||
{
|
||||
SetBackgroundColour(wxColour(param));
|
||||
Refresh();
|
||||
}
|
||||
|
||||
else if (cmd == 3)
|
||||
{
|
||||
wxMessageBox("Message from embedded widget:\n\n" + param);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
private:
|
||||
DECLARE_ABSTRACT_CLASS(TestWindow)
|
||||
};
|
||||
|
||||
IMPLEMENT_ABSTRACT_CLASS(TestWindow, wxWindow)
|
||||
|
||||
|
||||
//DECLARE_DLL_WIDGET(TestWindow)
|
||||
static int SendCommandToTestWindow(wxWindow *wnd, int cmd, const wxString& param)
|
||||
{
|
||||
return wxStaticCast(wnd, TestWindow)->HandleCommand(cmd, param);
|
||||
}
|
||||
|
||||
|
||||
BEGIN_WIDGET_LIBRARY()
|
||||
REGISTER_WIDGET(TestWindow)
|
||||
END_WIDGET_LIBRARY()
|
||||
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.dllwidget import wxDllWidget, wxDllWidget_GetDllExt
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TestFrame(wxFrame):
|
||||
def __init__(self):
|
||||
wxFrame.__init__(self, None, -1, "Test wxDllWidget")
|
||||
|
||||
menu = wxMenu()
|
||||
menu.Append(101, "Send command &1")
|
||||
menu.Append(102, "Send command &2")
|
||||
menu.Append(103, "Send command &3")
|
||||
menu.AppendSeparator()
|
||||
menu.Append(110, "E&xit")
|
||||
|
||||
mb = wxMenuBar()
|
||||
mb.Append(menu, "&Test")
|
||||
self.SetMenuBar(mb)
|
||||
|
||||
EVT_MENU_RANGE(self, 101, 109, self.OnSendCommand)
|
||||
EVT_MENU(self, 110, self.OnExit)
|
||||
|
||||
panel = wxPanel(self, -1)
|
||||
panel.SetFont(wxFont(12, wxSWISS, wxNORMAL, wxBOLD))
|
||||
|
||||
st = wxStaticText(panel, -1,
|
||||
"The widget below was dynamically imported from\n"
|
||||
"test_dll.dll or test_dll.so with no prior knowledge\n"
|
||||
"of it's contents or structure by wxPython.")
|
||||
|
||||
self.dw = dw = wxDllWidget(panel, -1,
|
||||
"test_dll" + wxDllWidget_GetDllExt(),
|
||||
"TestWindow",
|
||||
size=(250, 150))
|
||||
|
||||
# The embedded window is the one exported from the DLL
|
||||
print dw.GetEmbeddedWindow().GetClassName()
|
||||
|
||||
# This shows that we can give it a child from this side of things.
|
||||
# You can also call any wxWindow methods on it too.
|
||||
wxStaticText(dw.GetEmbeddedWindow(), -1,
|
||||
"Loaded from test_dll...", pos=(10,10))
|
||||
|
||||
|
||||
sizer = wxBoxSizer(wxVERTICAL)
|
||||
sizer.Add(wxStaticLine(panel, -1), 0, wxGROW)
|
||||
sizer.Add(st, 0, wxGROW|wxALL, 5)
|
||||
sizer.Add(dw, 1, wxGROW|wxALL, 5)
|
||||
|
||||
panel.SetSizer(sizer)
|
||||
panel.SetAutoLayout(true)
|
||||
sizer.Fit(self)
|
||||
sizer.SetSizeHints(self)
|
||||
|
||||
|
||||
def OnExit(self, evt):
|
||||
self.Close()
|
||||
|
||||
|
||||
def OnSendCommand(self, evt):
|
||||
ID = evt.GetId() - 100 # use the menu ID as the command
|
||||
param = ""
|
||||
if ID == 2:
|
||||
dlg = wxTextEntryDialog(self, "Enter a colour name to pass to the embedded widget:")
|
||||
if dlg.ShowModal() == wxID_OK:
|
||||
param = dlg.GetValue()
|
||||
dlg.Destroy()
|
||||
self.dw.SendCommand(ID, param)
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = wxPySimpleApp()
|
||||
frame = TestFrame()
|
||||
frame.Show(true)
|
||||
app.MainLoop()
|
||||
@@ -79,6 +79,7 @@ Source: "wxPython\oglc.pyd"; DestDir: "{app}\wxPython"; Component
|
||||
Source: "wxPython\stc_c.pyd"; DestDir: "{app}\wxPython"; Components: core
|
||||
Source: "wxPython\xrcc.pyd"; DestDir: "{app}\wxPython"; Components: core
|
||||
Source: "wxPython\gizmosc.pyd"; DestDir: "{app}\wxPython"; Components: core
|
||||
Source: "wxPython\dllwidget.pyd"; DestDir: "{app}\wxPython"; Components: core
|
||||
|
||||
Source: "wxPython\*.py"; DestDir: "{app}\wxPython"; Components: core
|
||||
Source: "wxPython\lib\*.py"; DestDir: "{app}\wxPython\lib"; Components: core
|
||||
@@ -117,6 +118,11 @@ Source: "demo\data\*.wav"; DestDir: "{app}\wxPython\demo\data";
|
||||
Source: "demo\data\*.wdr"; DestDir: "{app}\wxPython\demo\data"; Components: demo
|
||||
Source: "demo\data\*.xrc"; DestDir: "{app}\wxPython\demo\data"; Components: demo
|
||||
|
||||
Source: "demo\dllwidget\*.cpp"; DestDir: "{app}\wxPython\demo\dllwidget"; Components: demo
|
||||
Source: "demo\dllwidget\*.py"; DestDir: "{app}\wxPython\demo\dllwidget"; Components: demo
|
||||
Source: "demo\dllwidget\Makefile"; DestDir: "{app}\wxPython\demo\dllwidget"; Components: demo
|
||||
Source: "demo\dllwidget\makefile.*"; DestDir: "{app}\wxPython\demo\dllwidget"; Components: demo
|
||||
|
||||
Source: "README.txt"; DestDir: "{app}\wxPython\docs"; Flags: isreadme; Components: core
|
||||
Source: "CHANGES.txt"; DestDir: "{app}\wxPython\docs"; Components: core
|
||||
Source: "licence\*.txt"; DestDir: "{app}\wxPython\docs\licence"; Components: core
|
||||
@@ -201,9 +207,6 @@ Type: files; Name: "{app}\wxPython\samples\frogedit\*.pyo";
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
## TODO: For Python 2.2 wxPython should go into
|
||||
# os.path.join(sys.prefix, 'Lib', 'site-packages')
|
||||
|
||||
|
||||
IFS_Template = r"""
|
||||
program Setup;
|
||||
|
||||
+38
-2
@@ -33,11 +33,13 @@ BUILD_OGL = 1 # If true, build the contrib/ogl extension module
|
||||
BUILD_STC = 1 # If true, build the contrib/stc extension module
|
||||
BUILD_XRC = 1 # XML based resource system
|
||||
BUILD_GIZMOS = 1 # Build a module for the gizmos contrib library
|
||||
BUILD_DLLWIDGET = 1# Build a module for the gizmos contrib library
|
||||
|
||||
BUILD_IEWIN = 0 # Internet Explorer wrapper (experimental)
|
||||
|
||||
|
||||
CORE_ONLY = 0 # if true, don't build any of the above
|
||||
|
||||
|
||||
GL_ONLY = 0 # Only used when making the -gl RPM. See the "b" script
|
||||
# for the ugly details
|
||||
|
||||
@@ -113,6 +115,7 @@ if bcpp_compiling:
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
for flag in ['BUILD_GLCANVAS', 'BUILD_OGL', 'BUILD_STC', 'BUILD_XRC',
|
||||
'BUILD_GIZMOS', 'BUILD_DLLWIDGET',
|
||||
'CORE_ONLY', 'USE_SWIG', 'IN_CVS_TREE',
|
||||
'FINAL', 'HYBRID', ]:
|
||||
for x in range(len(sys.argv)):
|
||||
@@ -554,7 +557,7 @@ if not GL_ONLY and BUILD_STC:
|
||||
swig_args + ['-I'+STC_H, '-I'+location],
|
||||
[opj(STC_H, 'stc.h')])
|
||||
|
||||
# copy a project specific py module to the main package dir
|
||||
# copy a contrib project specific py module to the main package dir
|
||||
copy_file(opj(location, 'stc.py'), PKGDIR, update=1, verbose=0)
|
||||
|
||||
# add some include dirs to the standard set
|
||||
@@ -793,6 +796,39 @@ if not GL_ONLY and BUILD_GIZMOS:
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# Define the DLLWIDGET extension module
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
if not GL_ONLY and BUILD_DLLWIDGET:
|
||||
msg('Preparing DLLWIDGET...')
|
||||
location = 'contrib/dllwidget'
|
||||
swig_files = ['dllwidget_.i']
|
||||
|
||||
swig_sources = run_swig(swig_files, location, '', PKGDIR,
|
||||
USE_SWIG, swig_force, swig_args)
|
||||
|
||||
# copy a contrib project specific py module to the main package dir
|
||||
copy_file(opj(location, 'dllwidget.py'), PKGDIR, update=1, verbose=0)
|
||||
|
||||
ext = Extension('dllwidget_c', [
|
||||
'%s/dllwidget.cpp' % location,
|
||||
] + swig_sources,
|
||||
|
||||
include_dirs = includes,
|
||||
define_macros = defines,
|
||||
|
||||
library_dirs = libdirs,
|
||||
libraries = libs,
|
||||
|
||||
extra_compile_args = cflags,
|
||||
extra_link_args = lflags,
|
||||
)
|
||||
|
||||
wxpExtensions.append(ext)
|
||||
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# Do the Setup/Build/Install/Whatever
|
||||
|
||||
Reference in New Issue
Block a user