Merged wxPython 2.4.x to the 2.5 branch (Finally!!!)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19793 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2003-03-25 06:35:27 +00:00
parent 9b4e3f352b
commit 1e4a197e4c
586 changed files with 62691 additions and 17740 deletions

View File

@@ -1 +1 @@
ver = '2.3.3pre8'
ver = '2.5.0p1'

View File

@@ -2,3 +2,4 @@
# Stuff these names into the wx namespace so wxPyConstructObject can find them
wx.wxCalendarEventPtr = wxCalendarEventPtr
wx.wxCalendarCtrlPtr = wxCalendarCtrlPtr

View File

@@ -298,6 +298,7 @@ enum {
wxRA_SPECIFY_ROWS,
wxRA_SPECIFY_COLS,
wxRB_GROUP,
wxRB_SINGLE,
wxGA_PROGRESSBAR,
wxGA_HORIZONTAL,
wxGA_VERTICAL,
@@ -532,6 +533,17 @@ enum {
wxMOUSE_BTN_MIDDLE,
wxMOUSE_BTN_RIGHT,
// It looks like wxTabCtrl may rise from the dead. Uncomment these if
// it gets an implementation for all platforms...
// wxTC_RIGHTJUSTIFY,
// wxTC_FIXEDWIDTH,
// wxTC_TOP,
// wxTC_LEFT,
// wxTC_RIGHT,
// wxTC_BOTTOM,
// wxTC_MULTILINE,
// wxTC_OWNERDRAW,
};
@@ -921,12 +933,6 @@ enum wxHitTest
#define FALSE 0
#define false 0
#define TRUE 1
#define true 1
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------

View File

@@ -1,6 +1,6 @@
#----------------------------------------------------------------------------
# Name: _extra.py
# Purpose: This file is appended to the shadow class file generated
# Purpose: This file is appended to the shadow class file generated
# by SWIG. We add some unSWIGable things here.
#
# Author: Robin Dunn
@@ -131,6 +131,12 @@ def EVT_WINDOW_CREATE(win, func):
def EVT_WINDOW_DESTROY(win, func):
win.Connect(-1, -1, wxEVT_DESTROY, func)
def EVT_WINDOW_CREATE_ID(win, id, func):
win.Connect(id, -1, wxEVT_CREATE, func)
def EVT_WINDOW_DESTROY_ID(win, id, func):
win.Connect(id, -1, wxEVT_DESTROY, func)
def EVT_SET_CURSOR(win, func):
win.Connect(-1, -1, wxEVT_SET_CURSOR, func)
@@ -263,7 +269,7 @@ def EVT_COMMAND_SCROLL(win, id, func):
win.Connect(id, -1, wxEVT_SCROLL_PAGEDOWN, func)
win.Connect(id, -1, wxEVT_SCROLL_THUMBTRACK,func)
win.Connect(id, -1, wxEVT_SCROLL_THUMBRELEASE,func)
win.Connect(-1, -1, wxEVT_SCROLL_ENDSCROLL, func)
win.Connect(id, -1, wxEVT_SCROLL_ENDSCROLL, func)
def EVT_COMMAND_SCROLL_TOP(win, id, func):
win.Connect(id, -1, wxEVT_SCROLL_TOP, func)
@@ -587,17 +593,50 @@ wxColor = wxColour
wxNamedColor = wxNamedColour
wxPen = wxPyPen
wxScrollbar = wxScrollBar
wxPoint2D = wxPoint2DDouble
wxPyAssertionError = wxc.wxPyAssertionError
# backwards compatibility
wxNoRefBitmap = wxBitmap
wxPyDefaultPosition = wxDefaultPosition
wxPyDefaultSize = wxDefaultSize
NULL = None
wxNoRefBitmap = wxBitmap
wxPyDefaultPosition = wxDefaultPosition
wxPyDefaultSize = wxDefaultSize
NULL = None
wxSystemSettings_GetSystemColour = wxSystemSettings_GetColour
wxSystemSettings_GetSystemFont = wxSystemSettings_GetFont
wxSystemSettings_GetSystemMetric = wxSystemSettings_GetMetric
# workarounds for bad wxRTTI names
__wxPyPtrTypeMap['wxGauge95'] = 'wxGauge'
def NewId():
import warnings
warnings.warn("Use wxNewId instead", DeprecationWarning, 2)
return wxNewId()
def RegisterId(ID):
import warnings
warnings.warn("Use wxRegisterId instead", DeprecationWarning, 2)
return wxRegisterId(ID)
# Use Python's bool constants if available, make aliases if not
try:
True
except NameError:
True = 1==1
False = 1==0
# Backwards compaatible
TRUE = true = True
FALSE = false = False
#----------------------------------------------------------------------
# wxGTK sets the locale when initialized. Doing this at the Python
# level should set it up to match what GTK is doing at the C level.
@@ -608,7 +647,11 @@ if wxPlatform == "__WXGTK__":
except:
pass
if wxPlatform == "__WXMSW__":
import os
localedir = os.path.join(os.path.split(__file__)[0], "locale")
wxLocale_AddCatalogLookupPathPrefix(localedir)
del os
#----------------------------------------------------------------------
# wxWindows version numbers. wxPython version is in __version__.
@@ -660,6 +703,18 @@ def wxPyTypeCast(obj, typeStr):
theObj.thisown = obj.thisown
return theObj
#----------------------------------------------------------------------------
# An isinstance for Pythons < 2.2 that can check a sequence of class objects
# like the one in 2.2 can.
def wxPy_isinstance(obj, klasses):
import types
if sys.version[:3] < "2.2" and type(klasses) in [types.TupleType, types.ListType]:
for klass in klasses:
if isinstance(obj, klass): return True
return False
else:
return isinstance(obj, klasses)
#----------------------------------------------------------------------------
_wxCallAfterId = None
@@ -685,6 +740,9 @@ def wxCallAfter(callable, *args, **kw):
evt.kw = kw
wxPostEvent(app, evt)
# an alias
wxRunLater = wxCallAfter
#----------------------------------------------------------------------
class wxPyDeadObjectError(AttributeError):
@@ -744,7 +802,7 @@ class wxPyOnDemandOutputWindow:
self.text = wxTextCtrl(self.frame, -1, "",
style = wxTE_MULTILINE|wxTE_READONLY)
self.frame.SetSize(wxSize(450, 300))
self.frame.Show(true)
self.frame.Show(True)
EVT_CLOSE(self.frame, self.OnCloseWindow)
self.text.AppendText(str)
@@ -765,12 +823,17 @@ class wxApp(wxPyApp):
error = 'wxApp.error'
outputWindowClass = wxPyOnDemandOutputWindow
def __init__(self, redirect=_defRedirect, filename=None):
def __init__(self, redirect=_defRedirect, filename=None, useBestVisual=False):
wxPyApp.__init__(self)
self.stdioWin = None
self.saveStdio = (sys.stdout, sys.stderr)
# This has to be done before OnInit
self.SetUseBestVisual(useBestVisual)
if redirect:
self.RedirectStdio(filename)
# this initializes wxWindows and then calls our OnInit
_wxStart(self.OnInit)
@@ -797,7 +860,7 @@ class wxApp(wxPyApp):
if filename:
sys.stdout = sys.stderr = open(filename, 'a')
else:
self.stdioWin = self.outputWindowClass() # wxPyOnDemandOutputWindow
self.stdioWin = self.outputWindowClass()
sys.stdout = sys.stderr = self.stdioWin
@@ -805,6 +868,21 @@ class wxApp(wxPyApp):
sys.stdout, sys.stderr = self.saveStdio
# change from wxPyApp_ to wxApp_
wxApp_GetMacDefaultEncodingIsPC = wxc.wxPyApp_GetMacDefaultEncodingIsPC
wxApp_GetMacSupportPCMenuShortcuts = wxc.wxPyApp_GetMacSupportPCMenuShortcuts
wxApp_GetMacAboutMenuItemId = wxc.wxPyApp_GetMacAboutMenuItemId
wxApp_GetMacPreferencesMenuItemId = wxc.wxPyApp_GetMacPreferencesMenuItemId
wxApp_GetMacExitMenuItemId = wxc.wxPyApp_GetMacExitMenuItemId
wxApp_GetMacHelpMenuTitleName = wxc.wxPyApp_GetMacHelpMenuTitleName
wxApp_SetMacDefaultEncodingIsPC = wxc.wxPyApp_SetMacDefaultEncodingIsPC
wxApp_SetMacSupportPCMenuShortcuts = wxc.wxPyApp_SetMacSupportPCMenuShortcuts
wxApp_SetMacAboutMenuItemId = wxc.wxPyApp_SetMacAboutMenuItemId
wxApp_SetMacPreferencesMenuItemId = wxc.wxPyApp_SetMacPreferencesMenuItemId
wxApp_SetMacExitMenuItemId = wxc.wxPyApp_SetMacExitMenuItemId
wxApp_SetMacHelpMenuTitleName = wxc.wxPyApp_SetMacHelpMenuTitleName
#----------------------------------------------------------------------------
class wxPySimpleApp(wxApp):
@@ -812,7 +890,7 @@ class wxPySimpleApp(wxApp):
wxApp.__init__(self, flag)
def OnInit(self):
wxInitAllImageHandlers()
return true
return True
class wxPyWidgetTester(wxApp):
@@ -823,11 +901,11 @@ class wxPyWidgetTester(wxApp):
def OnInit(self):
self.frame = wxFrame(None, -1, "Widget Tester", pos=(0,0), size=self.size)
self.SetTopWindow(self.frame)
return true
return True
def SetWidget(self, widgetClass, *args):
w = apply(widgetClass, (self.frame,) + args)
self.frame.Show(true)
self.frame.Show(True)
#----------------------------------------------------------------------------
# DO NOT hold any other references to this object. This is how we

View File

@@ -1,3 +1,4 @@
# Stuff these names into the wx namespace so wxPyConstructObject can find them
import wx
wx.wxHelpEventPtr = wxHelpEventPtr
wx.wxContextHelpButtonPtr = wxContextHelpButtonPtr

View File

@@ -11,4 +11,5 @@ wx.wxHtmlContainerCellPtr = wxHtmlContainerCellPtr
wx.wxHtmlWidgetCellPtr = wxHtmlWidgetCellPtr
wx.wxHtmlWindowPtr = wxHtmlWindowPtr
wx.wxHtmlLinkInfoPtr = wxHtmlLinkInfoPtr
wx.wxHtmlFilterPtr = wxHtmlFilterPtr

View File

@@ -1,3 +1,7 @@
# Stuff these names into the wx namespace so wxPyConstructObject can find them
import wx
wx.wxWizardEventPtr = wxWizardEventPtr
wx.wxWizardPagePtr = wxWizardPagePtr
wx.wxPyWizardPagePtr = wxPyWizardPagePtr
wx.wxWizardPageSimplePtr = wxWizardPageSimplePtr
wx.wxWizardPtr = wxWizardPtr

View File

@@ -111,10 +111,13 @@ public:
wxDataFormat GetPreferredFormat(Direction dir = wxDataObject::Get);
size_t GetFormatCount(Direction dir = wxDataObject::Get);
// TODO: Fix these two to be usable from wxPython.
void GetAllFormats(wxDataFormat *formats,
Direction dir = wxDataObject::Get);
size_t GetDataSize(const wxDataFormat& format);
bool GetDataHere(const wxDataFormat& format, void *buf);
size_t GetDataSize(const wxDataFormat& format);
bool SetData(const wxDataFormat& format,
size_t len, const void * buf);
bool IsSupportedFormat(const wxDataFormat& format);
@@ -288,7 +291,7 @@ wxBitmap wxPyBitmapDataObject::GetBitmap() {
void wxPyBitmapDataObject::SetBitmap(const wxBitmap& bitmap) {
wxPyBeginBlockThreads();
if (m_myInst.findCallback("SetBitmap")) {
PyObject* bo = wxPyConstructObject((void*)&bitmap, "wxBitmap");
PyObject* bo = wxPyConstructObject((void*)&bitmap, wxT("wxBitmap"));
m_myInst.callCallback(Py_BuildValue("(O)", bo));
Py_DECREF(bo);
}
@@ -452,15 +455,17 @@ bool wxIsDragResultOk(wxDragResult res);
class wxPyDropSource : public wxDropSource {
public:
#ifdef __WXMSW__
wxPyDropSource(wxWindow *win = NULL,
const wxCursor &cursorCopy = wxNullCursor,
const wxCursor &cursorMove = wxNullCursor,
const wxCursor &cursorStop = wxNullCursor)
: wxDropSource(win, cursorCopy, cursorMove, cursorStop) {}
wxPyDropSource(wxWindow *win = NULL,
const wxCursor &copy = wxNullCursor,
const wxCursor &move = wxNullCursor,
const wxCursor &none = wxNullCursor)
: wxDropSource(win, copy, move, none) {}
#else
wxPyDropSource(wxWindow *win = NULL,
const wxIcon &go = wxNullIcon)
: wxDropSource(win, go) {}
const wxIcon& copy = wxNullIcon,
const wxIcon& move = wxNullIcon,
const wxIcon& none = wxNullIcon)
: wxDropSource(win, copy, move, none) {}
#endif
~wxPyDropSource() { }
@@ -476,13 +481,15 @@ IMP_PYCALLBACK_BOOL_DR(wxPyDropSource, wxDropSource, GiveFeedback);
%name(wxDropSource) class wxPyDropSource {
public:
#ifdef __WXMSW__
wxPyDropSource(wxWindow *win = NULL,
const wxCursor &cursorCopy = wxNullCursor,
const wxCursor &cursorMove = wxNullCursor,
const wxCursor &cursorStop = wxNullCursor);
wxPyDropSource(wxWindow *win = NULL,
const wxCursor &copy = wxNullCursor,
const wxCursor &move = wxNullCursor,
const wxCursor &none = wxNullCursor);
#else
wxPyDropSource(wxWindow *win = NULL,
const wxIcon &go = wxNullIcon);
const wxIcon& copy = wxNullIcon,
const wxIcon& move = wxNullIcon,
const wxIcon& none = wxNullIcon);
#endif
void _setCallbackInfo(PyObject* self, PyObject* _class, int incref);

View File

@@ -338,6 +338,7 @@ public:
%pragma(python) addtomethod = "wxPreCheckBox:val._setOORInfo(val)"
bool GetValue();
bool IsChecked();
void SetValue(const bool state);
};
@@ -1003,18 +1004,15 @@ public:
int FindString(const wxString& string);
wxString GetString(int n);
#ifdef __WXGTK__
%name(GetItemLabel)wxString GetLabel( int item );
%name(SetItemLabel)void SetLabel( int item, const wxString& label );
#else
void SetString(int n, const wxString& label);
%pragma(python) addtoclass = "
GetItemLabel = GetString
SetItemLabel = SetString
"
#ifndef __WXGTK__
int GetColumnCount();
int GetRowCount();
int GetNextItem(int item, wxDirection dir, long style);
#endif
int GetSelection();

View File

@@ -498,7 +498,6 @@ public:
return val
"
// Sets information about the item
bool SetItem(wxListItem& info) ;
@@ -560,6 +559,10 @@ public:
// view, otherwise the large icon view.
int GetItemSpacing(bool isSmall) const;
#ifndef __WXMSW__
void SetItemSpacing( int spacing, bool isSmall = FALSE );
#endif
// Gets the number of selected items in the list control
int GetSelectedItemCount() const;
@@ -624,6 +627,8 @@ public:
// End label editing, optionally cancelling the edit
bool EndEditLabel(bool cancel);
#else
void EditLabel(long item);
#endif
// Ensures this item is visible
@@ -700,6 +705,14 @@ public:
'''get the currently focused item or -1 if none'''
return self.GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED)
def GetFirstSelected(self, *args):
'''return first selected item, or -1 when none'''
return self.GetNextSelected(-1)
def GetNextSelected(self, item):
'''return subsequent selected items, or -1 when no more'''
return self.GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED)
def IsSelected(self, idx):
'''return TRUE if the item is selected'''
return self.GetItemState(idx, wxLIST_STATE_SELECTED) != 0
@@ -717,10 +730,14 @@ public:
'''Append an item to the list control. The entry parameter should be a
sequence with an item for each column'''
if len(entry):
if wx.wxUSE_UNICODE:
cvtfunc = unicode
else:
cvtfunc = str
pos = self.GetItemCount()
self.InsertStringItem(pos, str(entry[0]))
self.InsertStringItem(pos, cvtfunc(entry[0]))
for i in range(1, len(entry)):
self.SetStringItem(pos, i, str(entry[i]))
self.SetStringItem(pos, i, cvtfunc(entry[i]))
return pos
"
@@ -1091,8 +1108,8 @@ public:
bool found;
wxPyBeginBlockThreads();
if ((found = m_myInst.findCallback("OnCompareItems"))) {
PyObject *o1 = wxPyConstructObject((void*)&item1, "wxTreeItemId");
PyObject *o2 = wxPyConstructObject((void*)&item2, "wxTreeItemId");
PyObject *o1 = wxPyConstructObject((void*)&item1, wxT("wxTreeItemId"));
PyObject *o2 = wxPyConstructObject((void*)&item2, wxT("wxTreeItemId"));
rval = m_myInst.callCallback(Py_BuildValue("(OO)",o1,o2));
Py_DECREF(o1);
Py_DECREF(o2);
@@ -1205,6 +1222,16 @@ public:
}
// get the item's text colour
wxColour GetItemTextColour(const wxTreeItemId& item) const;
// get the item's background colour
wxColour GetItemBackgroundColour(const wxTreeItemId& item) const;
// get the item's font
wxFont GetItemFont(const wxTreeItemId& item) const;
bool IsVisible(const wxTreeItemId& item);
bool ItemHasChildren(const wxTreeItemId& item);
bool IsExpanded(const wxTreeItemId& item);
@@ -1212,7 +1239,7 @@ public:
wxTreeItemId GetRootItem();
wxTreeItemId GetSelection();
%name(GetItemParent) wxTreeItemId GetParent(const wxTreeItemId& item);
wxTreeItemId GetItemParent(const wxTreeItemId& item);
//size_t GetSelections(wxArrayTreeItemIds& selection);
%addmethods {
PyObject* GetSelections() {
@@ -1223,7 +1250,7 @@ public:
num = self->GetSelections(array);
for (x=0; x < num; x++) {
wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
PyObject* item = wxPyConstructObject((void*)tii, "wxTreeItemId", TRUE);
PyObject* item = wxPyConstructObject((void*)tii, wxT("wxTreeItemId"), TRUE);
PyList_Append(rval, item);
}
wxPyEndBlockThreads();
@@ -1283,12 +1310,11 @@ public:
void SelectItem(const wxTreeItemId& item);
void EnsureVisible(const wxTreeItemId& item);
void ScrollTo(const wxTreeItemId& item);
#ifdef __WXMSW__
wxTextCtrl* EditLabel(const wxTreeItemId& item);
wxTextCtrl* GetEditControl();
void EndEditLabel(const wxTreeItemId& item, int discardChanges = FALSE);
#else
void EditLabel(const wxTreeItemId& item);
#ifdef __WXMSW__
void EndEditLabel(const wxTreeItemId& item, int discardChanges = FALSE);
#endif
void SortChildren(const wxTreeItemId& item);
@@ -1314,7 +1340,7 @@ public:
if (self->GetBoundingRect(item, rect, textOnly)) {
wxPyBeginBlockThreads();
wxRect* r = new wxRect(rect);
PyObject* val = wxPyConstructObject((void*)r, "wxRect");
PyObject* val = wxPyConstructObject((void*)r, wxT("wxRect"));
wxPyEndBlockThreads();
return val;
}

350
wxPython/src/drawlist.cpp Normal file
View File

@@ -0,0 +1,350 @@
/////////////////////////////////////////////////////////////////////////////
// Name: drawlist.cpp
// Purpose: Helper functions for optimized list drawing on a wxDC
//
// Author: Robin Dunn Chris Barker
//
// Created:
// RCS-ID: $Id$
// Copyright: (c) 2003 by Total Control Software
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#undef DEBUG
#include <Python.h>
#include "helpers.h"
//----------------------------------------------------------------------
PyObject* wxPyDrawXXXList(wxDC& dc, wxPyDrawListOp_t doDraw,
PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes) {
wxPyBeginBlockThreads(); // _DrawXXXList
bool isFastSeq = PyList_Check(pyCoords) || PyTuple_Check(pyCoords);
bool isFastPens = PyList_Check(pyPens) || PyTuple_Check(pyPens);
bool isFastBrushes = PyList_Check(pyBrushes) || PyTuple_Check(pyBrushes);
int numObjs = 0;
int numPens = 0;
int numBrushes = 0;
wxPen* pen;
wxBrush* brush;
PyObject* obj;
PyObject* coords;
int x1, x2, x3, x4;
int i = 0;
PyObject* retval;
if (!PySequence_Check(pyCoords)) {
goto err0;
}
if (!PySequence_Check(pyPens)) {
goto err1;
}
if (!PySequence_Check(pyBrushes)) {
goto err2;
}
numObjs = PySequence_Length(pyCoords);
numPens = PySequence_Length(pyPens);
numBrushes = PySequence_Length(pyBrushes);
for (i = 0; i < numObjs; i++) {
// Use a new pen?
if (i < numPens) {
if (isFastPens) {
obj = PySequence_Fast_GET_ITEM(pyPens, i);
}
else {
obj = PySequence_GetItem(pyPens, i);
}
if (SWIG_GetPtrObj(obj, (void **) &pen, "_wxPen_p")) {
if (!isFastPens)
Py_DECREF(obj);
goto err1;
}
dc.SetPen(*pen);
if (!isFastPens)
Py_DECREF(obj);
}
// Use a new brush?
if (i < numBrushes) {
if (isFastBrushes) {
obj = PySequence_Fast_GET_ITEM(pyBrushes, i);
}
else {
obj = PySequence_GetItem(pyBrushes, i);
}
if (SWIG_GetPtrObj(obj, (void **) &brush, "_wxBrush_p")) {
if (!isFastBrushes)
Py_DECREF(obj);
goto err2;
}
dc.SetBrush(*brush);
if (!isFastBrushes)
Py_DECREF(obj);
}
// Get the Coordinates
if (isFastSeq) {
coords = PySequence_Fast_GET_ITEM(pyCoords, i);
}
else {
coords = PySequence_GetItem(pyCoords, i);
}
// call the drawOp
bool success = doDraw(dc, coords);
if (!isFastSeq)
Py_DECREF(coords);
if (! success) {
retval = NULL;
goto exit;
}
} // end of main for loop
Py_INCREF(Py_None);
retval = Py_None;
goto exit;
err0:
PyErr_SetString(PyExc_TypeError, "Expected a sequence of coordinates");
retval = NULL;
goto exit;
err1:
PyErr_SetString(PyExc_TypeError, "Expected a sequence of wxPens");
retval = NULL;
goto exit;
err2:
PyErr_SetString(PyExc_TypeError, "Expected a sequence of wxBrushes");
retval = NULL;
goto exit;
exit:
wxPyEndBlockThreads();
return retval;
}
bool wxPyDrawXXXPoint(wxDC& dc, PyObject* coords) {
int x, y;
if (! wxPy2int_seq_helper(coords, &x, &y)) {
PyErr_SetString(PyExc_TypeError, "Expected a sequence of (x,y) sequences.");
return FALSE;
}
dc.DrawPoint(x, y);
return TRUE;
}
bool wxPyDrawXXXLine(wxDC& dc, PyObject* coords) {
int x1, y1, x2, y2;
if (! wxPy4int_seq_helper(coords, &x1, &y1, &x2, &y2)) {
PyErr_SetString(PyExc_TypeError, "Expected a sequence of (x1,y1, x1,y2) sequences.");
return FALSE;
}
dc.DrawLine(x1,y1, x2,y2);
return TRUE;
}
bool wxPyDrawXXXRectangle(wxDC& dc, PyObject* coords) {
int x, y, w, h;
if (! wxPy4int_seq_helper(coords, &x, &y, &w, &h)) {
PyErr_SetString(PyExc_TypeError, "Expected a sequence of (x,y, w,h) sequences.");
return FALSE;
}
dc.DrawRectangle(x, y, w, h);
return TRUE;
}
bool wxPyDrawXXXEllipse(wxDC& dc, PyObject* coords) {
int x, y, w, h;
if (! wxPy4int_seq_helper(coords, &x, &y, &w, &h)) {
PyErr_SetString(PyExc_TypeError, "Expected a sequence of (x,y, w,h) sequences.");
return FALSE;
}
dc.DrawEllipse(x, y, w, h);
return TRUE;
}
bool wxPyDrawXXXPolygon(wxDC& dc, PyObject* coords) {
wxPoint* points;
int numPoints;
points = wxPoint_LIST_helper(coords, &numPoints);
if (! points) {
PyErr_SetString(PyExc_TypeError, "Expected a sequence of sequences of (x,y) sequences.");
return FALSE;
}
dc.DrawPolygon(numPoints, points);
return TRUE;
}
//----------------------------------------------------------------------
PyObject* wxPyDrawTextList(wxDC& dc, PyObject* textList, PyObject* pyPoints, PyObject* foregroundList, PyObject* backgroundList) {
wxPyBeginBlockThreads();
bool isFastSeq = PyList_Check(pyPoints) || PyTuple_Check(pyPoints);
bool isFastText = PyList_Check(textList) || PyTuple_Check(textList);
bool isFastForeground = PyList_Check(foregroundList) || PyTuple_Check(foregroundList);
bool isFastBackground = PyList_Check(backgroundList) || PyTuple_Check(backgroundList);
int numText = 0;
int numPoints = 0;
int numForeground = 0;
int numBackground = 0;
PyObject* obj;
int x1, y1;
int i = 0;
wxColor* color;
PyObject* retval;
wxString string;
if (!PySequence_Check(pyPoints)) {
goto err0;
}
if (!PySequence_Check(textList)) {
goto err1;
}
if (!PySequence_Check(foregroundList)) {
goto err2;
}
if (!PySequence_Check(backgroundList)) {
goto err3;
}
numPoints = PySequence_Length(pyPoints);
numText = PySequence_Length(textList);
numForeground = PySequence_Length(foregroundList);
numBackground = PySequence_Length(backgroundList);
for (i = 0; i < numPoints; i++) {
// Use a new string ?
if (i < numText) {
if ( isFastText ) {
obj = PySequence_Fast_GET_ITEM(textList, i);
}
else {
obj = PySequence_GetItem(textList, i);
}
if (! PyString_Check(obj) ) {
Py_DECREF(obj);
goto err1;
}
string = Py2wxString(obj);
if ( !isFastText )
Py_DECREF(obj);
}
if (i < numForeground) {
// Use a new foreground ?
if ( isFastForeground ) {
obj = PySequence_Fast_GET_ITEM(foregroundList, i);
}
else {
obj = PySequence_GetItem(foregroundList, i);
}
if (SWIG_GetPtrObj(obj, (void **) &color, "_wxColour_p")) {
if (!isFastForeground)
Py_DECREF(obj);
goto err2;
}
dc.SetTextForeground(*color);
if ( !isFastForeground )
Py_DECREF(obj);
}
if (i < numBackground) {
// Use a new background ?
if ( isFastBackground ) {
obj = PySequence_Fast_GET_ITEM(backgroundList, i);
}
else {
obj = PySequence_GetItem(backgroundList, i);
}
if (SWIG_GetPtrObj(obj, (void **) &color, "_wxColour_p")) {
if (!isFastBackground)
Py_DECREF(obj);
goto err3;
}
dc.SetTextBackground(*color);
if ( !isFastBackground )
Py_DECREF(obj);
}
// Get the point coordinates
if (isFastSeq) {
obj = PySequence_Fast_GET_ITEM(pyPoints, i);
}
else {
obj = PySequence_GetItem(pyPoints, i);
}
if (! wxPy2int_seq_helper(obj, &x1, &y1)) {
if (! isFastSeq)
Py_DECREF(obj);
goto err0;
}
if (PyErr_Occurred()) {
retval = NULL;
if (!isFastSeq)
Py_DECREF(obj);
goto exit;
}
// Now draw the text
dc.DrawText(string, x1, y1);
if (!isFastText)
Py_DECREF(obj);
}
Py_INCREF(Py_None);
retval = Py_None;
goto exit;
err0:
PyErr_SetString(PyExc_TypeError, "Expected a sequence of (x,y) sequences.");
retval = NULL;
goto exit;
err1:
PyErr_SetString(PyExc_TypeError, "Expected a sequence of strings");
retval = NULL;
goto exit;
err2:
PyErr_SetString(PyExc_TypeError, "Expected a sequence of wxColours for foregrounds");
retval = NULL;
goto exit;
err3:
PyErr_SetString(PyExc_TypeError, "Expected a sequence of wxColours for backgrounds");
retval = NULL;
goto exit;
exit:
wxPyEndBlockThreads();
return retval;
}
//----------------------------------------------------------------------

View File

@@ -225,9 +225,9 @@ public:
bool MetaDown();
bool AltDown();
bool ShiftDown();
long KeyCode();
long GetKeyCode();
%pragma(python) addtoclass = "KeyCode = GetKeyCode"
bool HasModifiers();
// get the raw key code (platform-dependent)
@@ -407,7 +407,7 @@ public:
for (int i=0; i<count; i++) {
#if wxUSE_UNICODE
PyList_SetItem(list, i, PyUnicode_FromUnicode(files[i], files[i].Len()));
PyList_SetItem(list, i, PyUnicode_FromWideChar(files[i], files[i].Len()));
#else
PyList_SetItem(list, i, PyString_FromString((const char*)files[i]));
#endif

View File

@@ -33,7 +33,6 @@
%import streams.i
%pragma(python) code = "import wx"
%pragma(python) code = "import string"
//---------------------------------------------------------------------------
@@ -141,6 +140,12 @@ public:
static void AddHandler(wxFileSystemHandler *handler);
static void CleanUpHandlers();
// // Returns the native path for a file URL
// static wxFileName URLToFileName(const wxString& url);
// // Returns the file URL for a native path
// static wxString FileNameToURL(const wxFileName& filename);
};
//---------------------------------------------------------------------------
@@ -209,9 +214,9 @@ void __wxMemoryFSHandler_AddFile_Data(const wxString& filename,
%pragma(python) code = "
import types
def wxMemoryFSHandler_AddFile(filename, a, b=''):
if isinstance(a, wxImage):
if wx.wxPy_isinstance(a, (wxImage, wxImagePtr)):
__wxMemoryFSHandler_AddFile_wxImage(filename, a, b)
elif isinstance(a, wxBitmap):
elif wx.wxPy_isinstance(a, (wxBitmap, wxBitmapPtr)):
__wxMemoryFSHandler_AddFile_wxBitmap(filename, a, b)
elif type(a) == types.StringType:
#__wxMemoryFSHandler_AddFile_wxString(filename, a)

View File

@@ -131,6 +131,15 @@ enum wxFontEncoding
wxFONTENCODING_UTF7, // UTF-7 Unicode encoding
wxFONTENCODING_UTF8, // UTF-8 Unicode encoding
// Far Eastern encodings
// Chinese
wxFONTENCODING_GB2312 = wxFONTENCODING_CP936, // Simplified Chinese
wxFONTENCODING_BIG5 = wxFONTENCODING_CP950, // Traditional Chinese
// Japanese (see http://zsigri.tripod.com/fontboard/cjk/jis.html)
wxFONTENCODING_SHIFT_JIS = wxFONTENCODING_CP932, // Shift JIS
wxFONTENCODING_EUC_JP, // Extended Unix Codepage for Japanese
wxFONTENCODING_UNICODE, // Unicode - currently used only by
// wxEncodingConverter class
@@ -147,26 +156,11 @@ enum wxFontEncoding
// ToString() and restore them using FromString())
struct wxNativeFontInfo
{
#ifdef __WXGTK__
// init the elements from an XLFD, return TRUE if ok
bool FromXFontName(const wxString& xFontName);
// return false if we were never initialized with a valid XLFD
bool IsDefault() const;
// generate an XLFD using the fontElements
wxString GetXFontName() const;
// set the XFLD
void SetXFontName(const wxString& xFontName);
#endif
wxNativeFontInfo() { Init(); }
wxNativeFontInfo();
// reset to the default state
void Init();
#ifndef __WXGTK__
// accessors and modifiers for the font elements
int GetPointSize() const;
wxFontStyle GetStyle() const;
@@ -183,7 +177,6 @@ struct wxNativeFontInfo
void SetFaceName(wxString facename);
void SetFamily(wxFontFamily family);
void SetEncoding(wxFontEncoding encoding);
#endif
// it is important to be able to serialize wxNativeFontInfo objects to be
// able to store them (in config file, for example)
@@ -204,6 +197,34 @@ struct wxNativeFontInfo
};
%{
// Fix some link errors... Remove this when these methods get real implementations...
#if defined(__WXGTK__) || defined(__WXX11__)
#if wxUSE_PANGO
void wxNativeFontInfo::SetPointSize(int pointsize)
{ wxFAIL_MSG( _T("not implemented") ); }
void wxNativeFontInfo::SetStyle(wxFontStyle style)
{ wxFAIL_MSG( _T("not implemented") ); }
void wxNativeFontInfo::SetWeight(wxFontWeight weight)
{ wxFAIL_MSG( _T("not implemented") ); }
void wxNativeFontInfo::SetUnderlined(bool WXUNUSED(underlined))
{ wxFAIL_MSG( _T("not implemented") ); }
void wxNativeFontInfo::SetFaceName(wxString facename)
{ wxFAIL_MSG( _T("not implemented") ); }
void wxNativeFontInfo::SetFamily(wxFontFamily family)
{ wxFAIL_MSG( _T("not implemented") ); }
void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding)
{ wxFAIL_MSG( _T("not implemented") ); }
#endif
#endif
%}
//---------------------------------------------------------------------------
// wxFontMapper manages user-definable correspondence between logical font
// names and the fonts present on the machine.
@@ -307,6 +328,13 @@ public:
wxFontEncoding encoding=wxFONTENCODING_DEFAULT);
%name(wxFontFromNativeInfo)wxFont(const wxNativeFontInfo& info);
%addmethods {
%new wxFont* wxFontFromNativeInfoString(const wxString& info) {
wxNativeFontInfo nfi;
nfi.FromString(info);
return new wxFont(nfi);
}
}
~wxFont();
@@ -340,6 +368,9 @@ public:
wxString GetStyleString() const;
wxString GetWeightString() const;
void SetNoAntiAliasing( bool no = TRUE );
bool GetNoAntiAliasing();
static wxFontEncoding GetDefaultEncoding();
static void SetDefaultEncoding(wxFontEncoding encoding);
@@ -412,7 +443,9 @@ public:
enum wxLanguage
{
// user's default/preffered language as got from OS:
wxLANGUAGE_DEFAULT,
// unknown language, if wxLocale::GetSystemLanguage fails:
wxLANGUAGE_UNKNOWN,
wxLANGUAGE_ABKHAZIAN,
@@ -691,16 +724,28 @@ public:
wxLocale(int language = wxLANGUAGE_DEFAULT,
int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING);
// the same as a function (returns TRUE on success)
bool Init(const wxString& szName,
const wxString& szShort = wxPyEmptyString,
const wxString& szLocale = wxPyEmptyString,
bool bLoadDefault = TRUE,
bool bConvertEncoding = FALSE);
// restores old locale
~wxLocale();
%name(Init1)bool Init(const wxString& szName,
const wxString& szShort = wxPyEmptyString,
const wxString& szLocale = wxPyEmptyString,
bool bLoadDefault = TRUE,
bool bConvertEncoding = FALSE);
%name(Init2) bool Init(int language = wxLANGUAGE_DEFAULT,
int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING);
%pragma(python) addtoclass = "
def Init(self, *_args, **_kwargs):
if type(_args[0]) in [type(''), type(u'')]:
val = apply(self.Init1, _args, _kwargs)
else:
val = apply(self.Init2, _args, _kwargs)
return val
"
// Try to get user's (or OS's) prefered language setting.
// Return wxLANGUAGE_UNKNOWN if language-guessing algorithm failed
static int GetSystemLanguage();

View File

@@ -145,11 +145,9 @@ public:
wxMenuBar *GetMenuBar();
// call this to simulate a menu command
bool Command(int id);
// process menu command: returns TRUE if processed
bool ProcessCommand(int id);
%pragma(python) addtoclass = "Command = ProcessCommand"
// create the main status bar
wxStatusBar* CreateStatusBar(int number = 1,

View File

@@ -34,6 +34,7 @@
%import misc.i
%import fonts.i
%pragma(python) code = "import wx"
//---------------------------------------------------------------------------
%{
@@ -67,6 +68,11 @@ public:
bool LoadFile(const wxString& name, wxBitmapType type=wxBITMAP_TYPE_ANY);
bool SaveFile(const wxString& name, wxBitmapType type, wxPalette* palette = NULL);
void SetMask(wxMask* mask);
%pragma(python) addtoclass = "
def SetMaskColour(self, colour):
mask = wxMaskColour(self, colour)
self.SetMask(mask)
"
#ifdef __WXMSW__
void SetPalette(wxPalette& palette);
#endif
@@ -95,14 +101,6 @@ public:
void SetQuality(int q);
#endif
%pragma(python) addtoclass = "
def __del__(self,gdic=gdic):
try:
if self.thisown == 1 :
gdic.delete_wxBitmap(self)
except:
pass
"
};
@@ -231,14 +229,6 @@ public:
#endif
void CopyFromBitmap(const wxBitmap& bmp);
%pragma(python) addtoclass = "
def __del__(self,gdic=gdic):
try:
if self.thisown == 1 :
gdic.delete_wxIcon(self)
except:
pass
"
};
@@ -337,6 +327,17 @@ public:
}
%}
%new wxCursor* wxCursorFromImage(const wxImage& image);
%{
wxCursor* wxCursorFromImage(const wxImage& image) {
#ifndef __WXMAC__
return new wxCursor(image);
#else
return NULL;
#endif
}
%}
//----------------------------------------------------------------------
class wxColour : public wxObject {
@@ -351,15 +352,45 @@ public:
%addmethods {
PyObject* Get() {
PyObject* rv = PyTuple_New(3);
PyTuple_SetItem(rv, 0, PyInt_FromLong(self->Red()));
PyTuple_SetItem(rv, 1, PyInt_FromLong(self->Green()));
PyTuple_SetItem(rv, 2, PyInt_FromLong(self->Blue()));
int red = -1;
int green = -1;
int blue = -1;
if (self->Ok()) {
red = self->Red();
green = self->Green();
blue = self->Blue();
}
PyTuple_SetItem(rv, 0, PyInt_FromLong(red));
PyTuple_SetItem(rv, 1, PyInt_FromLong(green));
PyTuple_SetItem(rv, 2, PyInt_FromLong(blue));
return rv;
}
bool __eq__(PyObject* obj) {
wxColour tmp;
wxColour* ptr = &tmp;
if (obj == Py_None) return FALSE;
wxPyBLOCK_THREADS(bool success = wxColour_helper(obj, &ptr); PyErr_Clear());
if (! success) return FALSE;
return *self == *ptr;
}
bool __ne__(PyObject* obj) {
wxColour tmp;
wxColour* ptr = &tmp;
if (obj == Py_None) return TRUE;
wxPyBLOCK_THREADS(bool success = wxColour_helper(obj, &ptr); PyErr_Clear());
if (! success) return TRUE;
return *self != *ptr;
}
}
%pragma(python) addtoclass = "asTuple = Get"
%pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
%pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
%pragma(python) addtoclass = "asTuple = Get
def __str__(self): return str(self.asTuple())
def __repr__(self): return 'wxColour:' + str(self.asTuple())
def __nonzero__(self): return self.Ok()
def __getinitargs__(self): return ()
def __getstate__(self): return self.asTuple()
def __setstate__(self, state): self.Set(*state)
"
};
@@ -388,15 +419,15 @@ public:
if ( !cName2.Replace(wxT("GRAY"), wxT("GREY")) )
cName2.clear();
wxNode *node = self->First();
wxNode *node = self->GetFirst();
while ( node ) {
const wxChar *key = node->GetKeyString();
if ( cName == key || cName2 == key ) {
wxColour* c = (wxColour *)node->Data();
wxColour* c = (wxColour *)node->GetData();
c->Set(red, green, blue);
return;
}
node = node->Next();
node = node->GetNext();
}
// otherwise append the new colour
@@ -535,34 +566,34 @@ public:
//----------------------------------------------------------------------
class wxDC : public wxObject {
public:
// wxDC(); **** abstract base class, can't instantiate.
~wxDC();
void BeginDrawing();
// %name(BlitXY)
bool Blit(long xdest, long ydest,
long width, long height,
wxDC *source, long xsrc, long ysrc,
bool Blit(wxCoord xdest, wxCoord ydest,
wxCoord width, wxCoord height,
wxDC *source, wxCoord xsrc, wxCoord ysrc,
int logicalFunc = wxCOPY, int useMask = FALSE);
// bool Blit(const wxPoint& destPt, const wxSize& sz,
// wxDC *source, const wxPoint& srcPt,
// int logicalFunc = wxCOPY, int useMask = FALSE);
void Clear();
void CrossHair(long x, long y);
void CrossHair(wxCoord x, wxCoord y);
void DestroyClippingRegion();
long DeviceToLogicalX(long x);
long DeviceToLogicalXRel(long x);
long DeviceToLogicalY(long y);
long DeviceToLogicalYRel(long y);
void DrawArc(long x1, long y1, long x2, long y2, long xc, long yc);
void DrawCircle(long x, long y, long radius);
void DrawEllipse(long x, long y, long width, long height);
void DrawEllipticArc(long x, long y, long width, long height, long start, long end);
void DrawIcon(const wxIcon& icon, long x, long y);
wxCoord DeviceToLogicalX(wxCoord x);
wxCoord DeviceToLogicalXRel(wxCoord x);
wxCoord DeviceToLogicalY(wxCoord y);
wxCoord DeviceToLogicalYRel(wxCoord y);
void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord xc, wxCoord yc);
void DrawCircle(wxCoord x, wxCoord y, wxCoord radius);
void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord width, wxCoord height, wxCoord start, wxCoord end);
void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y);
void DrawLabel(const wxString& text, const wxRect& rect,
int alignment = wxALIGN_LEFT | wxALIGN_TOP,
@@ -580,27 +611,27 @@ public:
}
}
void DrawLine(long x1, long y1, long x2, long y2);
void DrawLines(int PCOUNT, wxPoint* points, long xoffset=0, long yoffset=0);
void DrawPolygon(int PCOUNT, wxPoint* points, long xoffset=0, long yoffset=0,
void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
void DrawLines(int PCOUNT, wxPoint* points, wxCoord xoffset=0, wxCoord yoffset=0);
void DrawPolygon(int PCOUNT, wxPoint* points, wxCoord xoffset=0, wxCoord yoffset=0,
int fill_style=wxODDEVEN_RULE);
void DrawPoint(long x, long y);
void DrawRectangle(long x, long y, long width, long height);
void DrawPoint(wxCoord x, wxCoord y);
void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
%name(DrawRectangleRect)void DrawRectangle(const wxRect& rect);
void DrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle);
void DrawRoundedRectangle(long x, long y, long width, long height, long radius=20);
void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, wxCoord radius=20);
void DrawSpline(int PCOUNT, wxPoint* points);
void DrawText(const wxString& text, long x, long y);
void DrawText(const wxString& text, wxCoord x, wxCoord y);
void EndDoc();
void EndDrawing();
void EndPage();
bool FloodFill(long x, long y, const wxColour& colour, int style=wxFLOOD_SURFACE);
bool FloodFill(wxCoord x, wxCoord y, const wxColour& colour, int style=wxFLOOD_SURFACE);
wxBrush GetBackground();
wxBrush GetBrush();
long GetCharHeight();
long GetCharWidth();
void GetClippingBox(long *OUTPUT, long *OUTPUT,
long *OUTPUT, long *OUTPUT);
wxCoord GetCharHeight();
wxCoord GetCharWidth();
void GetClippingBox(wxCoord *OUTPUT, wxCoord *OUTPUT,
wxCoord *OUTPUT, wxCoord *OUTPUT);
wxFont GetFont();
int GetLogicalFunction();
void GetLogicalScale(double *OUTPUT, double *OUTPUT);
@@ -608,7 +639,7 @@ public:
bool GetOptimization();
wxPen GetPen();
%addmethods {
%new wxColour* GetPixel(long x, long y) {
%new wxColour* GetPixel(wxCoord x, wxCoord y) {
wxColour* wc = new wxColour();
self->GetPixel(x, y, wc);
return wc;
@@ -618,25 +649,27 @@ public:
wxSize GetSize();
wxSize GetSizeMM();
wxColour GetTextBackground();
void GetTextExtent(const wxString& string, long *OUTPUT, long *OUTPUT);
void GetTextExtent(const wxString& string, wxCoord *OUTPUT, wxCoord *OUTPUT);
%name(GetFullTextExtent)void GetTextExtent(const wxString& string,
long *OUTPUT, long *OUTPUT, long *OUTPUT, long* OUTPUT,
wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord* OUTPUT,
const wxFont* font = NULL);
void GetMultiLineTextExtent(const wxString& text, wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord *OUTPUT,
wxFont *font = NULL);
wxColour GetTextForeground();
void GetUserScale(double *OUTPUT, double *OUTPUT);
long LogicalToDeviceX(long x);
long LogicalToDeviceXRel(long x);
long LogicalToDeviceY(long y);
long LogicalToDeviceYRel(long y);
long MaxX();
long MaxY();
long MinX();
long MinY();
wxCoord LogicalToDeviceX(wxCoord x);
wxCoord LogicalToDeviceXRel(wxCoord x);
wxCoord LogicalToDeviceY(wxCoord y);
wxCoord LogicalToDeviceYRel(wxCoord y);
wxCoord MaxX();
wxCoord MaxY();
wxCoord MinX();
wxCoord MinY();
bool Ok();
void SetDeviceOrigin(long x, long y);
void SetDeviceOrigin(wxCoord x, wxCoord y);
void SetBackground(const wxBrush& brush);
void SetBackgroundMode(int mode);
void SetClippingRegion(long x, long y, long width, long height);
void SetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
%name(SetClippingRegionAsRegion) void SetClippingRegion(const wxRegion& region);
%name(SetClippingRect) void SetClippingRegion(const wxRect& rect);
void SetPalette(const wxPalette& colourMap);
@@ -655,7 +688,7 @@ public:
void DrawBitmap(const wxBitmap& bitmap, long x, long y,
void DrawBitmap(const wxBitmap& bitmap, wxCoord x, wxCoord y,
int useMask = FALSE);
bool CanDrawBitmap();
@@ -681,192 +714,39 @@ public:
#endif
%addmethods {
// NOTE: These methods are VERY SIMILAR in implentation. It would be
// nice to factor out common code and or turn them into a set of
// template-like macros.
%addmethods { // See drawlist.cpp for impplementaion of these...
// Draw a point for every set of coordinants in pyPoints, optionally
// setting a new pen for each
PyObject* _DrawPointList(PyObject* pyPoints, PyObject* pyPens) {
wxPyBeginBlockThreads();
bool isFastSeq = PyList_Check(pyPoints) || PyTuple_Check(pyPoints);
bool isFastPens = PyList_Check(pyPens) || PyTuple_Check(pyPens);
int numObjs = 0;
int numPens = 0;
wxPen* pen;
PyObject* obj;
int x1, y1;
int i = 0;
PyObject* retval;
if (!PySequence_Check(pyPoints)) {
goto err0;
}
if (!PySequence_Check(pyPens)) {
goto err1;
}
numObjs = PySequence_Length(pyPoints);
numPens = PySequence_Length(pyPens);
for (i = 0; i < numObjs; i++) {
// Use a new pen?
if (i < numPens) {
if (isFastPens) {
obj = PySequence_Fast_GET_ITEM(pyPens, i);
}
else {
obj = PySequence_GetItem(pyPens, i);
}
if (SWIG_GetPtrObj(obj, (void **) &pen, "_wxPen_p")) {
if (!isFastPens)
Py_DECREF(obj);
goto err1;
}
self->SetPen(*pen);
if (!isFastPens)
Py_DECREF(obj);
}
// Get the point coordinants
if (isFastSeq) {
obj = PySequence_Fast_GET_ITEM(pyPoints, i);
}
else {
obj = PySequence_GetItem(pyPoints, i);
}
if (! _2int_seq_helper(obj, &x1, &y1)) {
if (!isFastPens)
Py_DECREF(obj);
goto err0;
}
if (PyErr_Occurred()) {
retval = NULL;
if (!isFastPens)
Py_DECREF(obj);
goto exit;
}
// Now draw the point
self->DrawPoint(x1, y1);
if (!isFastSeq)
Py_DECREF(obj);
}
Py_INCREF(Py_None);
retval = Py_None;
goto exit;
err1:
PyErr_SetString(PyExc_TypeError, "Expected a sequence of wxPens");
retval = NULL;
goto exit;
err0:
PyErr_SetString(PyExc_TypeError, "Expected a sequence of (x,y) sequences.");
retval = NULL;
goto exit;
exit:
wxPyEndBlockThreads();
return retval;
PyObject* _DrawPointList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes)
{
return wxPyDrawXXXList(*self, wxPyDrawXXXPoint, pyCoords, pyPens, pyBrushes);
}
PyObject* _DrawLineList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes)
{
return wxPyDrawXXXList(*self, wxPyDrawXXXLine, pyCoords, pyPens, pyBrushes);
}
// Draw a line for every set of coordinants in pyLines, optionally
// setting a new pen for each
PyObject* _DrawLineList(PyObject* pyLines, PyObject* pyPens) {
wxPyBeginBlockThreads();
PyObject* _DrawRectangleList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes)
{
return wxPyDrawXXXList(*self, wxPyDrawXXXRectangle, pyCoords, pyPens, pyBrushes);
}
bool isFastSeq = PyList_Check(pyLines) || PyTuple_Check(pyLines);
bool isFastPens = PyList_Check(pyPens) || PyTuple_Check(pyPens);
int numObjs = 0;
int numPens = 0;
wxPen* pen;
PyObject* obj;
int x1, y1, x2, y2;
int i = 0;
PyObject* retval;
PyObject* _DrawEllipseList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes)
{
return wxPyDrawXXXList(*self, wxPyDrawXXXEllipse, pyCoords, pyPens, pyBrushes);
}
if (!PySequence_Check(pyLines)) {
goto err0;
}
if (!PySequence_Check(pyPens)) {
goto err1;
}
numObjs = PySequence_Length(pyLines);
numPens = PySequence_Length(pyPens);
PyObject* _DrawPolygonList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes)
{
return wxPyDrawXXXList(*self, wxPyDrawXXXPolygon, pyCoords, pyPens, pyBrushes);
}
for (i = 0; i < numObjs; i++) {
// Use a new pen?
if (i < numPens) {
if (isFastPens) {
obj = PySequence_Fast_GET_ITEM(pyPens, i);
}
else {
obj = PySequence_GetItem(pyPens, i);
}
if (SWIG_GetPtrObj(obj, (void **) &pen, "_wxPen_p")) {
if (!isFastPens)
Py_DECREF(obj);
goto err1;
}
self->SetPen(*pen);
if (!isFastPens)
Py_DECREF(obj);
}
// Get the line coordinants
if (isFastSeq) {
obj = PySequence_Fast_GET_ITEM(pyLines, i);
}
else {
obj = PySequence_GetItem(pyLines, i);
}
if (! _4int_seq_helper(obj, &x1, &y1, &x2, &y2)) {
if (!isFastPens)
Py_DECREF(obj);
goto err0;
}
if (PyErr_Occurred()) {
retval = NULL;
if (!isFastPens)
Py_DECREF(obj);
goto exit;
}
// Now draw the line
self->DrawLine(x1, y1, x2, y2);
if (!isFastSeq)
Py_DECREF(obj);
}
Py_INCREF(Py_None);
retval = Py_None;
goto exit;
err1:
PyErr_SetString(PyExc_TypeError, "Expected a sequence of wxPens");
retval = NULL;
goto exit;
err0:
PyErr_SetString(PyExc_TypeError, "Expected a sequence of (x1,y1, x2,y2) sequences.");
retval = NULL;
goto exit;
exit:
wxPyEndBlockThreads();
return retval;
PyObject* _DrawTextList(PyObject* textList, PyObject* pyPoints,
PyObject* foregroundList, PyObject* backgroundList) {
return wxPyDrawTextList(*self, textList, pyPoints, foregroundList, backgroundList);
}
}
%pragma(python) addtoclass = "
def DrawPointList(self, points, pens=None):
if pens is None:
@@ -875,7 +755,8 @@ public:
pens = [pens]
elif len(pens) != len(points):
raise ValueError('points and pens must have same length')
return self._DrawPointList(points, pens)
return self._DrawPointList(points, pens, [])
def DrawLineList(self, lines, pens=None):
if pens is None:
@@ -884,7 +765,83 @@ public:
pens = [pens]
elif len(pens) != len(lines):
raise ValueError('lines and pens must have same length')
return self._DrawLineList(lines, pens)
return self._DrawLineList(lines, pens, [])
def DrawRectangleList(self, rectangles, pens=None, brushes=None):
if pens is None:
pens = []
elif isinstance(pens, wxPenPtr):
pens = [pens]
elif len(pens) != len(rectangles):
raise ValueError('rectangles and pens must have same length')
if brushes is None:
brushes = []
elif isinstance(brushes, wxBrushPtr):
brushes = [brushes]
elif len(brushes) != len(rectangles):
raise ValueError('rectangles and brushes must have same length')
return self._DrawRectangleList(rectangles, pens, brushes)
def DrawEllipseList(self, ellipses, pens=None, brushes=None):
if pens is None:
pens = []
elif isinstance(pens, wxPenPtr):
pens = [pens]
elif len(pens) != len(ellipses):
raise ValueError('ellipses and pens must have same length')
if brushes is None:
brushes = []
elif isinstance(brushes, wxBrushPtr):
brushes = [brushes]
elif len(brushes) != len(ellipses):
raise ValueError('ellipses and brushes must have same length')
return self._DrawEllipseList(ellipses, pens, brushes)
def DrawPolygonList(self, polygons, pens=None, brushes=None):
## Note: This does not currently support fill style or offset
## you can always use the non-List version if need be.
## I really would like to support fill-style, however,
## but wxODDEVEN_RULE does not appear to be defined at the Python level
## [It's in wx.py... --Robin]
if pens is None:
pens = []
elif isinstance(pens, wxPenPtr):
pens = [pens]
elif len(pens) != len(polygons):
raise ValueError('polygons and pens must have same length')
if brushes is None:
brushes = []
elif isinstance(brushes, wxBrushPtr):
brushes = [brushes]
elif len(brushes) != len(polygons):
raise ValueError('polygons and brushes must have same length')
return self._DrawPolygonList(polygons, pens, brushes)
def DrawTextList(self, textList, coords, foregrounds = None, backgrounds = None, fonts = None):
## NOTE: this does not currently support changing the font
## Make sure you set Background mode to wxSolid (DC.SetBackgroundMode)
## If you want backgounds to do anything.
if type(textList) == type(''):
textList = [textList]
elif len(textList) != len(coords):
raise ValueError('textlist and coords must have same length')
if foregrounds is None:
foregrounds = []
elif isinstance(foregrounds, wxColourPtr):
foregrounds = [foregrounds]
elif len(foregrounds) != len(coords):
raise ValueError('foregrounds and coords must have same length')
if backgrounds is None:
backgrounds = []
elif isinstance(backgrounds, wxColourPtr):
backgrounds = [backgrounds]
elif len(backgrounds) != len(coords):
raise ValueError('backgrounds and coords must have same length')
return self._DrawTextList(textList, coords, foregrounds, backgrounds)
"
@@ -1082,7 +1039,7 @@ enum wxRegionContain {
class wxRegion : public wxGDIObject {
public:
wxRegion(long x=0, long y=0, long width=0, long height=0);
wxRegion(wxCoord x=0, wxCoord y=0, wxCoord width=0, wxCoord height=0);
#ifndef __WXMAC__
%name(wxRegionFromPoints)wxRegion(int PCOUNT, wxPoint* points, int fillStyle = wxWINDING_RULE);
#endif
@@ -1093,28 +1050,28 @@ public:
bool Offset(wxCoord x, wxCoord y);
#endif
wxRegionContain Contains(long x, long y);
wxRegionContain Contains(wxCoord x, wxCoord y);
%name(ContainsPoint)wxRegionContain Contains(const wxPoint& pt);
%name(ContainsRect)wxRegionContain Contains(const wxRect& rect);
%name(ContainsRectDim)wxRegionContain Contains(long x, long y, long w, long h);
%name(ContainsRectDim)wxRegionContain Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
wxRect GetBox();
bool Intersect(long x, long y, long width, long height);
bool Intersect(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
%name(IntersectRect)bool Intersect(const wxRect& rect);
%name(IntersectRegion)bool Intersect(const wxRegion& region);
bool IsEmpty();
bool Union(long x, long y, long width, long height);
bool Union(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
%name(UnionRect)bool Union(const wxRect& rect);
%name(UnionRegion)bool Union(const wxRegion& region);
bool Subtract(long x, long y, long width, long height);
bool Subtract(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
%name(SubtractRect)bool Subtract(const wxRect& rect);
%name(SubtractRegion)bool Subtract(const wxRegion& region);
bool Xor(long x, long y, long width, long height);
bool Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
%name(XorRect)bool Xor(const wxRect& rect);
%name(XorRegion)bool Xor(const wxRegion& region);
};
@@ -1126,12 +1083,12 @@ public:
wxRegionIterator(const wxRegion& region);
~wxRegionIterator();
long GetX();
long GetY();
long GetW();
long GetWidth();
long GetH();
long GetHeight();
wxCoord GetX();
wxCoord GetY();
wxCoord GetW();
wxCoord GetWidth();
wxCoord GetH();
wxCoord GetHeight();
wxRect GetRect();
bool HaveRects();
void Reset();

View File

@@ -1,4 +1,4 @@
/////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// Name: grid.i
// Purpose: SWIG definitions for the new wxGrid and related classes
//
@@ -70,7 +70,7 @@ PyObject* wxPyMake_##TYPE(TYPE* source) { \
/* Otherwise make a new wrapper for it the old fashioned way and \
give it the OOR treatment */ \
if (! target) { \
target = wxPyConstructObject(source, #TYPE, FALSE); \
target = wxPyConstructObject(source, wxT(#TYPE), FALSE); \
if (target) \
source->SetClientObject(new wxPyOORClientData(target)); \
} \
@@ -571,7 +571,7 @@ public:
PyObject* go = wxPyMake_wxObject(&grid);
PyObject* dco = wxPyMake_wxObject(&dc);
PyObject* ao = wxPyMake_wxGridCellAttr(&attr);
PyObject* ro = wxPyConstructObject((void*)&rect, "wxRect", 0);
PyObject* ro = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOOOiii)", go, ao, dco, ro,
row, col, isSelected));
@@ -747,6 +747,9 @@ public:
wxControl* GetControl();
void SetControl(wxControl* control);
wxGridCellAttr* GetCellAttr();
void SetCellAttr(wxGridCellAttr* attr);
void SetParameters(const wxString& params);
void IncRef();
void DecRef();
@@ -768,6 +771,7 @@ public:
virtual void HandleReturn(wxKeyEvent& event);
virtual void Destroy();
virtual wxString GetValue();
};
@@ -816,7 +820,7 @@ public:
}
wxGridCellEditor*Clone() const {
wxGridCellEditor* Clone() const {
wxGridCellEditor* rval = NULL;
wxPyBeginBlockThreads();
if (wxPyCBH_findCallback(m_myInst, "Clone")) {
@@ -856,7 +860,7 @@ public:
wxPyBeginBlockThreads();
if ((found = wxPyCBH_findCallback(m_myInst, "PaintBackground)"))) {
PyObject* ao = wxPyMake_wxGridCellAttr(attr);
PyObject* ro = wxPyConstructObject((void*)&rectCell, "wxRect", 0);
PyObject* ro = wxPyConstructObject((void*)&rectCell, wxT("wxRect"), 0);
wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", ro, ao));
@@ -880,6 +884,7 @@ public:
DEC_PYCALLBACK__(StartingClick);
DEC_PYCALLBACK__(Destroy);
DEC_PYCALLBACK__STRING(SetParameters);
DEC_PYCALLBACK_STRING__const(GetValue);
PYPRIVATE;
};
@@ -893,6 +898,7 @@ IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, StartingKey, wxKeyEven
IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, HandleReturn, wxKeyEvent);
IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, StartingClick);
IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, Destroy);
IMP_PYCALLBACK_STRING__const(wxPyGridCellEditor, wxGridCellEditor, GetValue);
%}
@@ -914,6 +920,7 @@ public:
void base_HandleReturn(wxKeyEvent& event);
void base_Destroy();
void base_SetParameters(const wxString& params);
wxString base_GetValue();
};
//---------------------------------------------------------------------------
@@ -1403,8 +1410,17 @@ public:
return *self != other;
}
}
%pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
%pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
%pragma(python) addtoclass = "
def __str__(self): return str(self.asTuple())
def __repr__(self): return 'wxGridCellCoords'+str(self.asTuple())
def __len__(self): return len(self.asTuple())
def __getitem__(self, index): return self.asTuple()[index]
def __setitem__(self, index, val):
if index == 0: self.SetRow(val)
elif index == 1: self.SetCol(val)
else: raise IndexError
"
};
// Typemap to allow conversion of sequence objects to wxGridCellCoords...
@@ -1440,6 +1456,36 @@ bool wxGridCellCoords_helper(PyObject* source, wxGridCellCoords** obj) {
}
%}
// Typemap to convert an array of cells coords to a list of tuples...
%typemap(python, out) wxGridCellCoordsArray {
$target = wxGridCellCoordsArray_helper($source);
}
%typemap(python, ret) wxGridCellCoordsArray {
delete $source;
}
// ...and the helper function for the above typemap.
%{
PyObject* wxGridCellCoordsArray_helper(const wxGridCellCoordsArray* source)
{
PyObject* list = PyList_New(0);
size_t idx;
for (idx = 0; idx < source->GetCount(); idx += 1) {
wxGridCellCoords& coord = source->Item(idx);
PyObject* tup = PyTuple_New(2);
PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(coord.GetRow()));
PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(coord.GetCol()));
PyList_Append(list, tup);
Py_DECREF(tup);
}
return list;
}
%}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// The grid itself
@@ -1509,7 +1555,8 @@ public:
//
void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
int horizontalAlignment = wxLEFT,
int verticalAlignment = wxTOP );
int verticalAlignment = wxTOP,
int textOrientation = wxHORIZONTAL );
// // Split a string containing newline chararcters into an array of
// // strings and return the number of lines
@@ -1614,6 +1661,7 @@ public:
wxFont GetLabelFont();
void GetRowLabelAlignment( int *OUTPUT, int *OUTPUT );
void GetColLabelAlignment( int *OUTPUT, int *OUTPUT );
int GetColLabelTextOrientation();
wxString GetRowLabelValue( int row );
wxString GetColLabelValue( int col );
wxColour GetGridLineColour();
@@ -1628,6 +1676,7 @@ public:
void SetLabelFont( const wxFont& );
void SetRowLabelAlignment( int horiz, int vert );
void SetColLabelAlignment( int horiz, int vert );
void SetColLabelTextOrientation( int textOrientation );
void SetRowLabelValue( int row, const wxString& );
void SetColLabelValue( int col, const wxString& );
void SetGridLineColour( const wxColour& );
@@ -1700,6 +1749,13 @@ public:
// and also set the grid size to just fit its contents
void AutoSize();
// autosize row height depending on label text
void AutoSizeRowLabelSize( int row );
// autosize column width depending on label text
void AutoSizeColLabelSize( int col );
// column won't be resized to be lesser width - this must be called during
// the grid creation because it won't resize the column if it's already
// narrower than the minimal width
@@ -1763,12 +1819,15 @@ public:
bool IsInSelection( int row, int col );
// TODO: ??? bool IsInSelection( const wxGridCellCoords& coords )
// TODO: These need typemaps
// wxGridCellCoordsArray GetSelectedCells() const;
// wxGridCellCoordsArray GetSelectionBlockTopLeft() const;
// wxGridCellCoordsArray GetSelectionBlockBottomRight() const;
// wxArrayInt GetSelectedRows() const;
// wxArrayInt GetSelectedCols() const;
const wxGridCellCoordsArray GetSelectedCells() const;
const wxGridCellCoordsArray GetSelectionBlockTopLeft() const;
const wxGridCellCoordsArray GetSelectionBlockBottomRight() const;
const wxArrayInt GetSelectedRows() const;
const wxArrayInt GetSelectedCols() const;
void DeselectRow( int row );
void DeselectCol( int col );
void DeselectCell( int row, int col );
// This function returns the rectangle that encloses the block of cells

View File

@@ -46,6 +46,7 @@ void WXDLLEXPORT wxEntryCleanup();
wxPyApp* wxPythonApp = NULL; // Global instance of application object
bool wxPyDoCleanup = FALSE;
bool wxPyDoingCleanup = FALSE;
#ifdef WXP_WITH_THREAD
@@ -67,6 +68,11 @@ wxMutex* wxPyTMutex = NULL;
#endif
static PyObject* wxPython_dict = NULL;
static PyObject* wxPyPtrTypeMap = NULL;
static PyObject* wxPyAssertionError = NULL;
#ifdef __WXMSW__ // If building for win32...
//----------------------------------------------------------------------
// This gets run when the DLL is loaded. We just need to save a handle.
@@ -90,16 +96,19 @@ BOOL WINAPI DllMain(
// Classes for implementing the wxp main application shell.
//----------------------------------------------------------------------
IMPLEMENT_ABSTRACT_CLASS(wxPyApp, wxApp);
wxPyApp::wxPyApp() {
SetUseBestVisual(TRUE);
m_assertMode = wxPYAPP_ASSERT_EXCEPTION;
}
wxPyApp::~wxPyApp() {
}
// This one isn't acutally called... See __wxStart()
// This one isn't acutally called... We fake it with __wxStart()
bool wxPyApp::OnInit() {
return FALSE;
}
@@ -126,6 +135,200 @@ int wxPyApp::MainLoop() {
}
bool wxPyApp::OnInitGui() {
bool rval=TRUE;
wxApp::OnInitGui(); // in this case always call the base class version
// wxPyBeginBlockThreads(); *** only called from within __wxStart so we already have the GIL
if (wxPyCBH_findCallback(m_myInst, "OnInitGui"))
rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()"));
// wxPyEndBlockThreads(); ***
return rval;
}
int wxPyApp::OnExit() {
int rval=0;
wxPyBeginBlockThreads();
if (wxPyCBH_findCallback(m_myInst, "OnExit"))
rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()"));
wxPyEndBlockThreads();
wxApp::OnExit(); // in this case always call the base class version
return rval;
}
#ifdef __WXDEBUG__
void wxPyApp::OnAssert(const wxChar *file,
int line,
const wxChar *cond,
const wxChar *msg) {
// If the OnAssert is overloaded in the Python class then call it...
bool found;
wxPyBeginBlockThreads();
if ((found = wxPyCBH_findCallback(m_myInst, "OnAssert"))) {
PyObject* fso = wx2PyString(file);
PyObject* cso = wx2PyString(file);
PyObject* mso;
if (msg != NULL)
mso = wx2PyString(file);
else {
mso = Py_None; Py_INCREF(Py_None);
}
wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OiOO)", fso, line, cso, mso));
Py_DECREF(fso);
Py_DECREF(cso);
Py_DECREF(mso);
}
wxPyEndBlockThreads();
// ...otherwise do our own thing with it
if (! found) {
// ignore it?
if (m_assertMode & wxPYAPP_ASSERT_SUPPRESS)
return;
// turn it into a Python exception?
if (m_assertMode & wxPYAPP_ASSERT_EXCEPTION) {
wxString buf;
buf.Alloc(4096);
buf.Printf(wxT("C++ assertion \"%s\" failed in %s(%d)"), cond, file, line);
if (msg != NULL) {
buf += wxT(": ");
buf += msg;
}
// set the exception
wxPyBeginBlockThreads();
PyObject* s = wx2PyString(buf);
PyErr_SetObject(wxPyAssertionError, s);
Py_DECREF(s);
wxPyEndBlockThreads();
// Now when control returns to whatever API wrapper was called from
// Python it should detect that an exception is set and will return
// NULL, signalling the exception to Python.
}
// Send it to the normal log destination, but only if
// not _DIALOG because it will call this too
if ( (m_assertMode & wxPYAPP_ASSERT_LOG) && !(m_assertMode & wxPYAPP_ASSERT_DIALOG)) {
wxString buf;
buf.Alloc(4096);
buf.Printf(wxT("%s(%d): assert \"%s\" failed"),
file, line, cond);
if (msg != NULL) {
buf += wxT(": ");
buf += msg;
}
wxLogDebug(buf);
}
// do the normal wx assert dialog?
if (m_assertMode & wxPYAPP_ASSERT_DIALOG)
wxApp::OnAssert(file, line, cond, msg);
}
}
#endif
/*static*/
bool wxPyApp::GetMacDefaultEncodingIsPC() {
#ifdef __WXMAC__
return s_macDefaultEncodingIsPC;
#else
return 0;
#endif
}
/*static*/
bool wxPyApp::GetMacSupportPCMenuShortcuts() {
#ifdef __WXMAC__
return s_macSupportPCMenuShortcuts;
#else
return 0;
#endif
}
/*static*/
long wxPyApp::GetMacAboutMenuItemId() {
#ifdef __WXMAC__
return s_macAboutMenuItemId;
#else
return 0;
#endif
}
/*static*/
long wxPyApp::GetMacPreferencesMenuItemId() {
#ifdef __WXMAC__
return s_macPreferencesMenuItemId;
#else
return 0;
#endif
}
/*static*/
long wxPyApp::GetMacExitMenuItemId() {
#ifdef __WXMAC__
return s_macExitMenuItemId;
#else
return 0;
#endif
}
/*static*/
wxString wxPyApp::GetMacHelpMenuTitleName() {
#ifdef __WXMAC__
return s_macHelpMenuTitleName;
#else
return wxEmptyString;
#endif
}
/*static*/
void wxPyApp::SetMacDefaultEncodingIsPC(bool val) {
#ifdef __WXMAC__
s_macDefaultEncodingIsPC = val;
#endif
}
/*static*/
void wxPyApp::SetMacSupportPCMenuShortcuts(bool val) {
#ifdef __WXMAC__
s_macSupportPCMenuShortcuts = val;
#endif
}
/*static*/
void wxPyApp::SetMacAboutMenuItemId(long val) {
#ifdef __WXMAC__
s_macAboutMenuItemId = val;
#endif
}
/*static*/
void wxPyApp::SetMacPreferencesMenuItemId(long val) {
#ifdef __WXMAC__
s_macPreferencesMenuItemId = val;
#endif
}
/*static*/
void wxPyApp::SetMacExitMenuItemId(long val) {
#ifdef __WXMAC__
s_macExitMenuItemId = val;
#endif
}
/*static*/
void wxPyApp::SetMacHelpMenuTitleName(const wxString& val) {
#ifdef __WXMAC__
s_macHelpMenuTitleName = val;
#endif
}
//---------------------------------------------------------------------
//----------------------------------------------------------------------
@@ -170,7 +373,7 @@ static wxChar* wxPyCopyWString(const wxChar *src)
// This is where we pick up the first part of the wxEntry functionality...
// The rest is in __wxStart and __wxCleanup. This function is called when
// wxcmodule is imported. (Before there is a wxApp object.)
void __wxPreStart()
void __wxPreStart(PyObject* moduleDict)
{
#ifdef __WXMSW__
@@ -185,6 +388,11 @@ void __wxPreStart()
wxApp::CheckBuildOptions(wxBuildOptions());
wxPyAssertionError = PyErr_NewException("wxPython.wxc.wxPyAssertionError",
PyExc_AssertionError, NULL);
PyDict_SetItemString(moduleDict, "wxPyAssertionError", wxPyAssertionError);
// Bail out if there is already a wxApp created. This means that the
// toolkit has already been initialized, as in embedding wxPython in
// a C++ wxWindows app, so we don't need to call wxEntryStart.
@@ -202,12 +410,7 @@ void __wxPreStart()
int x;
for(x=0; x<argc; x++) {
PyObject *item = PyList_GetItem(sysargv, x);
#if wxUSE_UNICODE
if (PyUnicode_Check(item))
argv[x] = wxPyCopyCString(PyUnicode_AS_UNICODE(item));
else
#endif
argv[x] = wxPyCopyCString(PyString_AsString(item));
argv[x] = wxPyCopyCString(Py2wxString(item));
}
argv[argc] = NULL;
}
@@ -238,12 +441,7 @@ PyObject* __wxStart(PyObject* /* self */, PyObject* args)
int x;
for(x=0; x<argc; x++) {
PyObject *pyArg = PyList_GetItem(sysargv, x);
#if wxUSE_UNICODE
if (PyUnicode_Check(pyArg))
argv[x] = wxPyCopyWString(PyUnicode_AS_UNICODE(pyArg));
else
#endif
argv[x] = wxPyCopyWString(PyString_AsString(pyArg));
argv[x] = wxPyCopyWString(Py2wxString(pyArg));
}
argv[argc] = NULL;
}
@@ -256,30 +454,40 @@ PyObject* __wxStart(PyObject* /* self */, PyObject* args)
// Call the Python App's OnInit function
arglist = PyTuple_New(0);
result = PyEval_CallObject(onInitFunc, arglist);
Py_DECREF(arglist);
if (!result) { // an exception was raised.
return NULL;
}
if (! PyInt_Check(result)) {
PyObject* pyint = PyNumber_Int(result);
if (! pyint) {
PyErr_SetString(PyExc_TypeError, "OnInit should return a boolean value");
return NULL;
goto error;
}
bResult = PyInt_AS_LONG(result);
bResult = PyInt_AS_LONG(pyint);
if (! bResult) {
PyErr_SetString(PyExc_SystemExit, "OnInit returned FALSE, exiting...");
return NULL;
goto error;
}
#ifdef __WXGTK__
wxTheApp->m_initialized = (wxTopLevelWindows.GetCount() > 0);
#endif
Py_DECREF(result);
Py_DECREF(pyint);
Py_INCREF(Py_None);
return Py_None;
error:
Py_XDECREF(result);
Py_XDECREF(pyint);
return NULL;
}
void __wxCleanup() {
wxPyDoingCleanup = TRUE;
if (wxPyDoCleanup)
wxEntryCleanup();
#ifdef WXP_WITH_THREAD
@@ -293,9 +501,6 @@ void __wxCleanup() {
static PyObject* wxPython_dict = NULL;
static PyObject* wxPyPtrTypeMap = NULL;
PyObject* __wxSetDictionary(PyObject* /* self */, PyObject* args)
{
@@ -346,15 +551,20 @@ PyObject* __wxSetDictionary(PyObject* /* self */, PyObject* args)
//---------------------------------------------------------------------------
void wxPyClientData_dtor(wxPyClientData* self) {
wxPyBeginBlockThreads();
Py_DECREF(self->m_obj);
wxPyEndBlockThreads();
if (! wxPyDoingCleanup) { // Don't do it during cleanup as Python
// may have already garbage collected the object...
wxPyBeginBlockThreads();
Py_DECREF(self->m_obj);
wxPyEndBlockThreads();
}
}
void wxPyUserData_dtor(wxPyUserData* self) {
wxPyBeginBlockThreads();
Py_DECREF(self->m_obj);
wxPyEndBlockThreads();
if (! wxPyDoingCleanup) {
wxPyBeginBlockThreads();
Py_DECREF(self->m_obj);
wxPyEndBlockThreads();
}
}
@@ -377,6 +587,8 @@ void wxPyOORClientData_dtor(wxPyOORClientData* self) {
Py_INCREF(deadObjectClass);
}
// TODO: If wxPyDOingCleanup, should we skip the code below?
// Clear the instance's dictionary, put the name of the old class into the
// instance, and then reset the class to be the dead class.
if (self->m_obj->ob_refcnt > 1) { // but only if there is more than one reference
@@ -412,14 +624,26 @@ void wxPyPtrTypeMap_Add(const char* commonName, const char* ptrName) {
PyObject* wxPyClassExists(const wxString& className) {
PyObject* item;
wxString name(className);
char buff[64]; // should always be big enough...
if (!className)
return NULL;
char buff[64]; // should always be big enough...
sprintf(buff, "%sPtr", className.mbc_str());
// Try the name as-is first
sprintf(buff, "%sPtr", (const char*)name.mbc_str());
PyObject* classobj = PyDict_GetItemString(wxPython_dict, buff);
// if not found see if there is a mapped name for it
if ( ! classobj) {
if ((item = PyDict_GetItemString(wxPyPtrTypeMap, (char*)(const char*)name.mbc_str())) != NULL) {
name = wxString(PyString_AsString(item), *wxConvCurrent);
sprintf(buff, "%sPtr", (const char*)name.mbc_str());
classobj = PyDict_GetItemString(wxPython_dict, buff);
}
}
return classobj; // returns NULL if not found
}
@@ -445,8 +669,8 @@ PyObject* wxPyMake_wxObject(wxObject* source, bool checkEvtHandler) {
if (! target) {
// Otherwise make it the old fashioned way by making a
// new shadow object and putting this pointer in it.
wxClassInfo* info = source->GetClassInfo();
wxChar* name = (wxChar*)info->GetClassName();
wxClassInfo* info = source->GetClassInfo();
wxString name = info->GetClassName();
PyObject* klass = wxPyClassExists(name);
while (info && !klass) {
name = (wxChar*)info->GetBaseClassName1();
@@ -691,13 +915,15 @@ PyObject* wxPyInputStream::read(int size) {
// check if we have a real wxInputStream to work with
if (!m_wxis) {
wxPyBeginBlockThreads();
PyErr_SetString(PyExc_IOError, "no valid C-wxInputStream");
wxPyEndBlockThreads();
return NULL;
}
if (size < 0) {
// read until EOF
while (! m_wxis->Eof()) {
// read while bytes are available on the stream
while ( m_wxis->CanRead() ) {
m_wxis->Read(buf.GetAppendBuf(BUFSIZE), BUFSIZE);
buf.UngetAppendBuf(m_wxis->LastRead());
}
@@ -708,13 +934,16 @@ PyObject* wxPyInputStream::read(int size) {
}
// error check
if (m_wxis->LastError() == wxSTREAM_READ_ERROR) {
wxPyBeginBlockThreads();
wxStreamError err = m_wxis->GetLastError();
if (err != wxSTREAM_NO_ERROR && err != wxSTREAM_EOF) {
PyErr_SetString(PyExc_IOError,"IOError in wxInputStream");
}
else {
// We use only strings for the streams, not unicode
obj = PyString_FromStringAndSize(buf, buf.GetDataLen());
}
wxPyEndBlockThreads();
return obj;
}
@@ -727,24 +956,29 @@ PyObject* wxPyInputStream::readline(int size) {
// check if we have a real wxInputStream to work with
if (!m_wxis) {
wxPyBeginBlockThreads();
PyErr_SetString(PyExc_IOError,"no valid C-wxInputStream");
wxPyEndBlockThreads();
return NULL;
}
// read until \n or byte limit reached
for (i=ch=0; (ch != '\n') && (!m_wxis->Eof()) && ((size < 0) || (i < size)); i++) {
for (i=ch=0; (ch != '\n') && (m_wxis->CanRead()) && ((size < 0) || (i < size)); i++) {
ch = m_wxis->GetC();
buf.AppendByte(ch);
}
// errorcheck
if (m_wxis->LastError() == wxSTREAM_READ_ERROR) {
wxPyBeginBlockThreads();
wxStreamError err = m_wxis->GetLastError();
if (err != wxSTREAM_NO_ERROR && err != wxSTREAM_EOF) {
PyErr_SetString(PyExc_IOError,"IOError in wxInputStream");
}
else {
// We use only strings for the streams, not unicode
obj = PyString_FromStringAndSize((char*)buf.GetData(), buf.GetDataLen());
}
wxPyEndBlockThreads();
return obj;
}
@@ -754,33 +988,45 @@ PyObject* wxPyInputStream::readlines(int sizehint) {
// check if we have a real wxInputStream to work with
if (!m_wxis) {
PyErr_SetString(PyExc_IOError,"no valid C-wxInputStream below");
wxPyBeginBlockThreads();
PyErr_SetString(PyExc_IOError,"no valid C-wxInputStream");
wxPyEndBlockThreads();
return NULL;
}
// init list
wxPyBeginBlockThreads();
pylist = PyList_New(0);
if (!pylist) {
wxPyBeginBlockThreads();
PyErr_NoMemory();
wxPyEndBlockThreads();
return NULL;
}
// read sizehint bytes or until EOF
int i;
for (i=0; (!m_wxis->Eof()) && ((sizehint < 0) || (i < sizehint));) {
for (i=0; (m_wxis->CanRead()) && ((sizehint < 0) || (i < sizehint));) {
PyObject* s = this->readline();
if (s == NULL) {
wxPyBeginBlockThreads();
Py_DECREF(pylist);
wxPyEndBlockThreads();
return NULL;
}
wxPyBeginBlockThreads();
PyList_Append(pylist, s);
i += PyString_Size(s);
wxPyEndBlockThreads();
}
// error check
if (m_wxis->LastError() == wxSTREAM_READ_ERROR) {
wxStreamError err = m_wxis->GetLastError();
if (err != wxSTREAM_NO_ERROR && err != wxSTREAM_EOF) {
wxPyBeginBlockThreads();
Py_DECREF(pylist);
PyErr_SetString(PyExc_IOError,"IOError in wxInputStream");
wxPyEndBlockThreads();
return NULL;
}
@@ -889,7 +1135,6 @@ size_t wxPyCBInputStream::OnSysRead(void *buffer, size_t bufsize) {
else
m_lasterror = wxSTREAM_READ_ERROR;
wxPyEndBlockThreads();
m_lastcount = o;
return o;
}
@@ -956,9 +1201,9 @@ void wxPyCallback::EventThunker(wxEvent& event) {
wxPyBeginBlockThreads();
wxString className = event.GetClassInfo()->GetClassName();
if (className == "wxPyEvent")
if (className == wxT("wxPyEvent"))
arg = ((wxPyEvent*)&event)->GetSelf();
else if (className == "wxPyCommandEvent")
else if (className == wxT("wxPyCommandEvent"))
arg = ((wxPyCommandEvent*)&event)->GetSelf();
else {
arg = wxPyConstructObject((void*)&event, className);
@@ -1287,19 +1532,20 @@ void wxPyTimer::Notify() {
//---------------------------------------------------------------------------
// Convert a wxList to a Python List
PyObject* wxPy_ConvertList(wxListBase* list, const char* className) {
PyObject* wxPy_ConvertList(wxListBase* listbase, const char* className) {
wxList* list = (wxList*)listbase; // this is probably bad...
PyObject* pyList;
PyObject* pyObj;
wxObject* wxObj;
wxNode* node = list->First();
wxNode* node = list->GetFirst();
wxPyBeginBlockThreads();
pyList = PyList_New(0);
while (node) {
wxObj = node->Data();
wxObj = node->GetData();
pyObj = wxPyMake_wxObject(wxObj); //wxPyConstructObject(wxObj, className);
PyList_Append(pyList, pyObj);
node = node->Next();
node = node->GetNext();
}
wxPyEndBlockThreads();
return pyList;
@@ -1315,10 +1561,14 @@ long wxPyGetWinHandle(wxWindow* win) {
// Find and return the actual X-Window.
#ifdef __WXGTK__
if (win->m_wxwindow) {
#ifdef __WXGTK20__
return (long) GDK_WINDOW_XWINDOW(GTK_PIZZA(win->m_wxwindow)->bin_window);
#else
GdkWindowPrivate* bwin = (GdkWindowPrivate*)GTK_PIZZA(win->m_wxwindow)->bin_window;
if (bwin) {
return (long)bwin->xwindow;
}
#endif
}
#endif
return 0;
@@ -1344,7 +1594,12 @@ wxString* wxString_in_helper(PyObject* source) {
}
#if wxUSE_UNICODE
if (PyUnicode_Check(source)) {
target = new wxString(PyUnicode_AS_UNICODE(source));
target = new wxString();
size_t len = PyUnicode_GET_SIZE(source);
if (len) {
PyUnicode_AsWideChar((PyUnicodeObject*)source, target->GetWriteBuf(len), len);
target->UngetWriteBuf();
}
} else {
// It is a string, get pointers to it and transform to unicode
char* tmpPtr; int tmpSize;
@@ -1386,7 +1641,11 @@ wxString Py2wxString(PyObject* source)
#if wxUSE_UNICODE
if (PyUnicode_Check(source)) {
target = PyUnicode_AS_UNICODE(source);
size_t len = PyUnicode_GET_SIZE(source);
if (len) {
PyUnicode_AsWideChar((PyUnicodeObject*)source, target.GetWriteBuf(len), len);
target.UngetWriteBuf();
}
} else {
// It is a string, get pointers to it and transform to unicode
char* tmpPtr; int tmpSize;
@@ -1419,7 +1678,7 @@ PyObject* wx2PyString(const wxString& src)
{
PyObject* str;
#if wxUSE_UNICODE
str = PyUnicode_FromUnicode(src.c_str(), src.Len());
str = PyUnicode_FromWideChar(src.c_str(), src.Len());
#else
str = PyString_FromStringAndSize(src.c_str(), src.Len());
#endif
@@ -1624,7 +1883,7 @@ error2:
if (!isFast)
Py_DECREF(o);
error1:
delete temp;
delete [] temp;
error0:
PyErr_SetString(PyExc_TypeError, "Expected a sequence of length-2 sequences or wxPoints.");
return NULL;
@@ -1765,7 +2024,7 @@ wxPen** wxPen_LIST_helper(PyObject* source) {
}
bool _2int_seq_helper(PyObject* source, int* i1, int* i2) {
bool wxPy2int_seq_helper(PyObject* source, int* i1, int* i2) {
bool isFast = PyList_Check(source) || PyTuple_Check(source);
PyObject *o1, *o2;
@@ -1792,7 +2051,7 @@ bool _2int_seq_helper(PyObject* source, int* i1, int* i2) {
}
bool _4int_seq_helper(PyObject* source, int* i1, int* i2, int* i3, int* i4) {
bool wxPy4int_seq_helper(PyObject* source, int* i1, int* i2, int* i3, int* i4) {
bool isFast = PyList_Check(source) || PyTuple_Check(source);
PyObject *o1, *o2, *o3, *o4;
@@ -1859,6 +2118,7 @@ bool wxSize_helper(PyObject* source, wxSize** obj) {
return FALSE;
}
bool wxPoint_helper(PyObject* source, wxPoint** obj) {
// If source is an object instance then it may already be the right type
@@ -1974,9 +2234,9 @@ bool wxColour_helper(PyObject* source, wxColour** obj) {
*obj = ptr;
return TRUE;
}
// otherwise a string is expected
else if (PyString_Check(source)) {
wxString spec(PyString_AS_STRING(source), *wxConvCurrent);
// otherwise check for a string
else if (PyString_Check(source) || PyUnicode_Check(source)) {
wxString spec = Py2wxString(source);
if (spec.GetChar(0) == '#' && spec.Length() == 7) { // It's #RRGGBB
long red, green, blue;
red = green = blue = 0;
@@ -1992,15 +2252,63 @@ bool wxColour_helper(PyObject* source, wxColour** obj) {
return TRUE;
}
}
// last chance: 3-tuple of integers is expected
else if (PySequence_Check(source) && PyObject_Length(source) == 3) {
PyObject* o1 = PySequence_GetItem(source, 0);
PyObject* o2 = PySequence_GetItem(source, 1);
PyObject* o3 = PySequence_GetItem(source, 2);
if (!PyNumber_Check(o1) || !PyNumber_Check(o2) || !PyNumber_Check(o3)) {
Py_DECREF(o1);
Py_DECREF(o2);
Py_DECREF(o3);
goto error;
}
**obj = wxColour(PyInt_AsLong(o1), PyInt_AsLong(o2), PyInt_AsLong(o3));
Py_DECREF(o1);
Py_DECREF(o2);
Py_DECREF(o3);
return TRUE;
}
error:
PyErr_SetString(PyExc_TypeError,
"Expected a wxColour object or a string containing a colour "
"name or '#RRGGBB'.");
"Expected a wxColour object or a string containing a colour name or '#RRGGBB'.");
return FALSE;
}
bool wxPoint2DDouble_helper(PyObject* source, wxPoint2DDouble** obj) {
// If source is an object instance then it may already be the right type
if (PyInstance_Check(source)) {
wxPoint2DDouble* ptr;
if (SWIG_GetPtrObj(source, (void **)&ptr, "_wxPoint2DDouble_p"))
goto error;
*obj = ptr;
return TRUE;
}
// otherwise a length-2 sequence of floats is expected
if (PySequence_Check(source) && PySequence_Length(source) == 2) {
PyObject* o1 = PySequence_GetItem(source, 0);
PyObject* o2 = PySequence_GetItem(source, 1);
// This should really check for integers, not numbers -- but that would break code.
if (!PyNumber_Check(o1) || !PyNumber_Check(o2)) {
Py_DECREF(o1);
Py_DECREF(o2);
goto error;
}
**obj = wxPoint2DDouble(PyFloat_AsDouble(o1), PyFloat_AsDouble(o2));
Py_DECREF(o1);
Py_DECREF(o2);
return TRUE;
}
error:
PyErr_SetString(PyExc_TypeError, "Expected a 2-tuple of floats or a wxPoint2DDouble object.");
return FALSE;
}
//----------------------------------------------------------------------
PyObject* wxArrayString2PyList_helper(const wxArrayString& arr) {
@@ -2008,7 +2316,7 @@ PyObject* wxArrayString2PyList_helper(const wxArrayString& arr) {
PyObject* list = PyList_New(0);
for (size_t i=0; i < arr.GetCount(); i++) {
#if wxUSE_UNICODE
PyObject* str = PyUnicode_FromUnicode(arr[i].c_str(), arr[i].Len());
PyObject* str = PyUnicode_FromWideChar(arr[i].c_str(), arr[i].Len());
#else
PyObject* str = PyString_FromStringAndSize(arr[i].c_str(), arr[i].Len());
#endif

View File

@@ -14,27 +14,13 @@
#define __wxp_helpers__
#include <wx/wx.h>
#include <wx/geometry.h>
//---------------------------------------------------------------------------
typedef unsigned char byte;
class wxPyApp: public wxApp
{
public:
wxPyApp();
~wxPyApp();
bool OnInit();
int MainLoop();
};
extern wxPyApp *wxPythonApp;
//----------------------------------------------------------------------
void __wxPreStart();
void __wxPreStart(PyObject*);
PyObject* __wxStart(PyObject*, PyObject* args);
void __wxCleanup();
@@ -80,6 +66,8 @@ void wxPyEndAllowThreads(PyThreadState* state);
void wxPyBeginBlockThreads();
void wxPyEndBlockThreads();
#define wxPyBLOCK_THREADS(stmt) wxPyBeginBlockThreads(); stmt; wxPyEndBlockThreads()
//----------------------------------------------------------------------
// These are helpers used by the typemaps
@@ -101,6 +89,9 @@ bool wxRealPoint_helper(PyObject* source, wxRealPoint** obj);
bool wxRect_helper(PyObject* source, wxRect** obj);
bool wxColour_helper(PyObject* source, wxColour** obj);
bool wxPoint2DDouble_helper(PyObject* source, wxPoint2DDouble** obj);
//----------------------------------------------------------------------
// Other helpful stuff
@@ -109,8 +100,8 @@ bool wxColour_helper(PyObject* source, wxColour** obj);
(PyList_Check(o) ? PyList_GET_ITEM(o, i) : PyTuple_GET_ITEM(o, i))
#endif
bool _2int_seq_helper(PyObject* source, int* i1, int* i2);
bool _4int_seq_helper(PyObject* source, int* i1, int* i2, int* i3, int* i4);
bool wxPy2int_seq_helper(PyObject* source, int* i1, int* i2);
bool wxPy4int_seq_helper(PyObject* source, int* i1, int* i2, int* i3, int* i4);
PyObject* wxArrayString2PyList_helper(const wxArrayString& arr);
@@ -120,6 +111,21 @@ PyObject* wxArrayInt2PyList_helper(const wxArrayInt& arr);
#define DECLARE_DEF_STRING(name) static const wxString wxPy##name(wx##name)
#define DECLARE_DEF_STRING2(name,val) static const wxString wxPy##name(val)
//----------------------------------------------------------------------
// functions used by the DrawXXXList enhancements added to wxDC
typedef bool (*wxPyDrawListOp_t)(wxDC& dc, PyObject* coords);
PyObject* wxPyDrawXXXList(wxDC& dc, wxPyDrawListOp_t doDraw,
PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes);
bool wxPyDrawXXXPoint(wxDC& dc, PyObject* coords);
bool wxPyDrawXXXLine(wxDC& dc, PyObject* coords);
bool wxPyDrawXXXRectangle(wxDC& dc, PyObject* coords);
bool wxPyDrawXXXEllipse(wxDC& dc, PyObject* coords);
bool wxPyDrawXXXPolygon(wxDC& dc, PyObject* coords);
PyObject* wxPyDrawTextList(wxDC& dc, PyObject* textList, PyObject* pyPoints,
PyObject* foregroundList, PyObject* backgroundList);
//----------------------------------------------------------------------
#ifndef SWIGCODE
@@ -270,6 +276,7 @@ struct wxPyCoreAPI {
bool (*p_wxRealPoint_helper)(PyObject* source, wxRealPoint** obj);
bool (*p_wxRect_helper)(PyObject* source, wxRect** obj);
bool (*p_wxColour_helper)(PyObject* source, wxColour** obj);
bool (*p_wxPoint2DDouble_helper)(PyObject* source, wxPoint2DDouble** obj);
void (*p_wxPyCBH_setCallbackInfo)(wxPyCallbackHelper& cbh, PyObject* self, PyObject* klass, int incref);
bool (*p_wxPyCBH_findCallback)(const wxPyCallbackHelper& cbh, const char* name);
@@ -404,19 +411,78 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh);
//---------------------------------------------------------------------------
// This is used in C++ classes that need to be able to make callback to
// "overloaded" python methods
#define PYPRIVATE \
void _setCallbackInfo(PyObject* self, PyObject* _class, int incref=1) { \
wxPyCBH_setCallbackInfo(m_myInst, self, _class, incref); \
} \
private: wxPyCallbackHelper m_myInst
//---------------------------------------------------------------------------
enum {
wxPYAPP_ASSERT_SUPPRESS = 1,
wxPYAPP_ASSERT_EXCEPTION = 2,
wxPYAPP_ASSERT_DIALOG = 4,
wxPYAPP_ASSERT_LOG = 8
};
class wxPyApp: public wxApp
{
DECLARE_ABSTRACT_CLASS(wxPyApp);
public:
wxPyApp();
~wxPyApp();
bool OnInit();
int MainLoop();
int GetAssertMode() { return m_assertMode; }
void SetAssertMode(int mode) { m_assertMode = mode; }
virtual bool OnInitGui();
virtual int OnExit();
#ifdef __WXDEBUG__
virtual void OnAssert(const wxChar *file,
int line,
const wxChar *cond,
const wxChar *msg);
#endif
// virtual int FilterEvent(wxEvent& event); // This one too????
static bool GetMacDefaultEncodingIsPC();
static bool GetMacSupportPCMenuShortcuts();
static long GetMacAboutMenuItemId();
static long GetMacPreferencesMenuItemId();
static long GetMacExitMenuItemId();
static wxString GetMacHelpMenuTitleName();
static void SetMacDefaultEncodingIsPC(bool val);
static void SetMacSupportPCMenuShortcuts(bool val);
static void SetMacAboutMenuItemId(long val);
static void SetMacPreferencesMenuItemId(long val);
static void SetMacExitMenuItemId(long val);
static void SetMacHelpMenuTitleName(const wxString& val);
PYPRIVATE;
int m_assertMode;
};
extern wxPyApp *wxPythonApp;
//----------------------------------------------------------------------
// These macros are used to implement the virtual methods that should
// redirect to a Python method if one exists. The names designate the
// return type, if any, as well as any parameter types.
//---------------------------------------------------------------------------
#define PYPRIVATE \
void _setCallbackInfo(PyObject* self, PyObject* _class, int incref=1) { \
wxPyCBH_setCallbackInfo(m_myInst, self, _class, incref); \
} \
private: wxPyCallbackHelper m_myInst
//---------------------------------------------------------------------------
#define DEC_PYCALLBACK__(CBNAME) \
void CBNAME(); \
void base_##CBNAME();
@@ -425,10 +491,10 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh);
#define IMP_PYCALLBACK__(CLASS, PCLASS, CBNAME) \
void CLASS::CBNAME() { \
bool found; \
wxPyBeginBlockThreads(); \
wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
wxPyEndBlockThreads(); \
wxPyEndBlockThreads(); \
if (! found) \
PCLASS::CBNAME(); \
} \
@@ -1173,6 +1239,34 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh);
//---------------------------------------------------------------------------
#define DEC_PYCALLBACK_STRING__const(CBNAME) \
wxString CBNAME() const; \
wxString base_##CBNAME() const;
#define IMP_PYCALLBACK_STRING__const(CLASS, PCLASS, CBNAME) \
wxString CLASS::CBNAME() const { \
wxString rval; \
bool found; \
wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
PyObject* ro; \
ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
if (ro) { \
rval = Py2wxString(ro); \
Py_DECREF(ro); \
} \
} \
wxPyEndBlockThreads(); \
if (! found) \
rval = PCLASS::CBNAME(); \
return rval; \
} \
wxString CLASS::base_##CBNAME() const { \
return PCLASS::CBNAME(); \
}
//---------------------------------------------------------------------------
#define DEC_PYCALLBACK_STRING__pure(CBNAME) \
wxString CBNAME();
@@ -1203,7 +1297,7 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh);
bool rval=FALSE; \
wxPyBeginBlockThreads(); \
if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
PyObject* obj = wxPyConstructObject((void*)&a, "wxHtmlTag", 0); \
PyObject* obj = wxPyConstructObject((void*)&a, wxT("wxHtmlTag"), 0); \
rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
Py_DECREF(obj); \
} \
@@ -1222,7 +1316,7 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh);
bool found; \
wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
PyObject* obj = wxPyConstructObject((void*)cell, "wxHtmlCell", 0); \
PyObject* obj = wxPyConstructObject((void*)cell, wxT("wxHtmlCell"), 0); \
wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(Oii)",obj,x,y)); \
Py_DECREF(obj); \
} \
@@ -1246,8 +1340,8 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh);
bool found; \
wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
PyObject* obj = wxPyConstructObject((void*)cell, "wxHtmlCell", 0); \
PyObject* o2 = wxPyConstructObject((void*)&e, "wxMouseEvent", 0); \
PyObject* obj = wxPyConstructObject((void*)cell, wxT("wxHtmlCell"), 0); \
PyObject* o2 = wxPyConstructObject((void*)&e, wxT("wxMouseEvent"), 0); \
wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(OiiO)",obj,x,y,o2)); \
Py_DECREF(obj); \
Py_DECREF(o2); \
@@ -1582,7 +1676,7 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh);
bool found; \
wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
PyObject* obj = wxPyConstructObject((void*)&a, #Type, 0); \
PyObject* obj = wxPyConstructObject((void*)&a, wxT(#Type), 0); \
wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
Py_DECREF(obj); \
} \
@@ -1607,7 +1701,7 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh);
bool found; \
wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
PyObject* obj = wxPyConstructObject((void*)&a, #Type, 0); \
PyObject* obj = wxPyConstructObject((void*)&a, wxT(#Type), 0); \
wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
Py_DECREF(obj); \
} \
@@ -1632,7 +1726,7 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh);
bool found; \
wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
PyObject* obj = wxPyConstructObject((void*)&a, #Type, 0); \
PyObject* obj = wxPyConstructObject((void*)&a, wxT(#Type), 0); \
rv = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
Py_DECREF(obj); \
} \
@@ -1656,7 +1750,7 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh);
bool rv=FALSE; \
wxPyBeginBlockThreads(); \
if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
PyObject* obj = wxPyConstructObject((void*)&a, #Type, 0); \
PyObject* obj = wxPyConstructObject((void*)&a, wxT(#Type), 0); \
rv = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
Py_DECREF(obj); \
} \
@@ -1766,7 +1860,7 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh);
wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
PyObject* ro; \
PyObject* obj = wxPyConstructObject((void*)&e, "wxMouseEvent", 0); \
PyObject* obj = wxPyConstructObject((void*)&e, wxT("wxMouseEvent"), 0); \
ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(O)",obj)); \
if (ro) { \
rval = PyInt_AsLong(ro); \
@@ -1851,6 +1945,29 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh);
//---------------------------------------------------------------------------
#define DEC_PYCALLBACK_OBJECT_STRING_pure(CBNAME) \
wxObject* CBNAME(const wxString& a);
#define IMP_PYCALLBACK_OBJECT_STRING_pure(CLASS, PCLASS, CBNAME) \
wxObject* CLASS::CBNAME(const wxString& a) { \
wxObject* rv = NULL; \
wxPyBeginBlockThreads(); \
if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
PyObject* so = wx2PyString(a); \
PyObject* ro; \
ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(O)", so)); \
if (ro) { \
SWIG_GetPtrObj(ro, (void **)&rv, "_wxObject_p"); \
Py_DECREF(ro); \
} \
Py_DECREF(so); \
} \
wxPyEndBlockThreads(); \
return rv; \
}
//---------------------------------------------------------------------------
#define DEC_PYCALLBACK_BOOL_NODE_pure(CBNAME) \
bool CBNAME(wxXmlNode* a);
@@ -1860,7 +1977,7 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh);
bool rv=FALSE; \
wxPyBeginBlockThreads(); \
if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
PyObject* obj = wxPyConstructObject((void*)a, "wxXmlNode", 0); \
PyObject* obj = wxPyConstructObject((void*)a, wxT("wxXmlNode"), 0); \
rv = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
Py_DECREF(obj); \
} \

View File

@@ -21,6 +21,7 @@
#include <wx/fs_zip.h>
#include <wx/fs_inet.h>
#include <wx/wfstream.h>
#include <wx/filesys.h>
#include "printfw.h"
%}
@@ -37,8 +38,10 @@
%extern controls.i
%extern controls2.i
%extern printfw.i
%extern utils.i
%extern filesys.i
%extern streams.i
%pragma(python) code = "import wx"
@@ -158,7 +161,9 @@ public:
void InitParser(const wxString& source);
void DoneParser();
void DoParsing(int begin_pos, int end_pos);
void StopParsing();
// wxObject* GetProduct();
void AddTagHandler(wxHtmlTagHandler *handler);
wxString* GetSource();
void PushTagHandler(wxHtmlTagHandler* handler, wxString tags);
@@ -415,6 +420,7 @@ public:
%name(SetWidthFloatFromTag)void SetWidthFloat(const wxHtmlTag& tag);
void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP);
void SetBackgroundColour(const wxColour& clr);
wxColour GetBackgroundColour();
void SetBorder(const wxColour& clr1, const wxColour& clr2);
wxHtmlCell* GetFirstCell();
};
@@ -442,9 +448,75 @@ public:
};
//---------------------------------------------------------------------------
// wxHtmlFilter
//---------------------------------------------------------------------------
%{ // here's the C++ version
class wxPyHtmlFilter : public wxHtmlFilter {
DECLARE_ABSTRACT_CLASS(wxPyHtmlFilter);
public:
wxPyHtmlFilter() : wxHtmlFilter() {}
// returns TRUE if this filter is able to open&read given file
virtual bool CanRead(const wxFSFile& file) const {
bool rval = FALSE;
bool found;
wxPyBeginBlockThreads();
if ((found = wxPyCBH_findCallback(m_myInst, "CanRead"))) {
PyObject* obj = wxPyMake_wxObject((wxFSFile*)&file); // cast away const
rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj));
Py_DECREF(obj);
}
wxPyEndBlockThreads();
return rval;
}
// Reads given file and returns HTML document.
// Returns empty string if opening failed
virtual wxString ReadFile(const wxFSFile& file) const {
wxString rval;
bool found;
wxPyBeginBlockThreads();
if ((found = wxPyCBH_findCallback(m_myInst, "ReadFile"))) {
PyObject* obj = wxPyMake_wxObject((wxFSFile*)&file); // cast away const
PyObject* ro;
ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(O)", obj));
Py_DECREF(obj);
if (ro) {
rval = Py2wxString(ro);
Py_DECREF(ro);
}
}
wxPyEndBlockThreads();
return rval;
}
PYPRIVATE;
};
IMPLEMENT_ABSTRACT_CLASS(wxPyHtmlFilter, wxHtmlFilter);
%}
// And now the version seen by SWIG
%name(wxHtmlFilter) class wxPyHtmlFilter : public wxObject {
public:
wxPyHtmlFilter();
void _setCallbackInfo(PyObject* self, PyObject* _class);
%pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxHtmlFilter)"
};
// TODO: wxHtmlFilterHTML
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// wxHtmlWindow
//---------------------------------------------------------------------------
%{
@@ -455,7 +527,7 @@ public:
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxHW_SCROLLBAR_AUTO,
const wxString& name = "htmlWindow")
const wxString& name = wxPyHtmlWindowNameStr)
: wxHtmlWindow(parent, id, pos, size, style, name) {};
wxPyHtmlWindow() : wxHtmlWindow() {};
@@ -478,7 +550,6 @@ public:
DEC_PYCALLBACK__STRING(OnSetTitle);
DEC_PYCALLBACK__CELLINTINT(OnCellMouseHover);
DEC_PYCALLBACK__CELLINTINTME(OnCellClicked);
// DEC_PYCALLBACK_BOOL_STRING(OnOpeningURL);
PYPRIVATE;
};
@@ -486,14 +557,13 @@ IMPLEMENT_ABSTRACT_CLASS( wxPyHtmlWindow, wxHtmlWindow );
IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnSetTitle);
IMP_PYCALLBACK__CELLINTINT(wxPyHtmlWindow, wxHtmlWindow, OnCellMouseHover);
IMP_PYCALLBACK__CELLINTINTME(wxPyHtmlWindow, wxHtmlWindow, OnCellClicked);
// IMP_PYCALLBACK_BOOL_STRING(wxPyHtmlWindow, wxHtmlWindow, OnOpeningURL);
void wxPyHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link) {
bool found;
wxPyBeginBlockThreads();
if ((found = wxPyCBH_findCallback(m_myInst, "OnLinkClicked"))) {
PyObject* obj = wxPyConstructObject((void*)&link, "wxHtmlLinkInfo", 0);
PyObject* obj = wxPyConstructObject((void*)&link, wxT("wxHtmlLinkInfo"), 0);
wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj));
Py_DECREF(obj);
}
@@ -564,18 +634,45 @@ public:
%pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
%pragma(python) addtomethod = "wxPreHtmlWindow:val._setOORInfo(val)"
// Set HTML page and display it. !! source is HTML document itself,
// it is NOT address/filename of HTML document. If you want to
// specify document location, use LoadPage() istead
// Return value : FALSE if an error occured, TRUE otherwise
bool SetPage(const wxString& source);
// Load HTML page from given location. Location can be either
// a) /usr/wxGTK2/docs/html/wx.htm
// b) http://www.somewhere.uk/document.htm
// c) ftp://ftp.somesite.cz/pub/something.htm
// In case there is no prefix (http:,ftp:), the method
// will try to find it itself (1. local file, then http or ftp)
// After the page is loaded, the method calls SetPage() to display it.
// Note : you can also use path relative to previously loaded page
// Return value : same as SetPage
bool LoadPage(const wxString& location);
// Append to current page
bool AppendToPage(const wxString& source);
// Returns full location of opened page
wxString GetOpenedPage();
// Returns anchor within opened page
wxString GetOpenedAnchor();
// Returns <TITLE> of opened page or empty string otherwise
wxString GetOpenedPageTitle();
// Sets frame in which page title will be displayed. Format is format of
// frame title, e.g. "HtmlHelp : %s". It must contain exactly one %s
void SetRelatedFrame(wxFrame* frame, const wxString& format);
wxFrame* GetRelatedFrame();
// After(!) calling SetRelatedFrame, this sets statusbar slot where messages
// will be displayed. Default is -1 = no messages.
void SetRelatedStatusBar(int bar);
//void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
// Sets fonts to be used when displaying HTML page.
%addmethods {
void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes) {
int* temp = int_LIST_helper(sizes);
@@ -587,20 +684,39 @@ public:
}
void SetTitle(const wxString& title);
// Sets space between text and window borders.
void SetBorders(int b);
// Saves custom settings into cfg config. it will use the path 'path'
// if given, otherwise it will save info into currently selected path.
// saved values : things set by SetFonts, SetBorders.
void ReadCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
void WriteCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
// Goes to previous/next page (in browsing history)
// Returns TRUE if successful, FALSE otherwise
bool HistoryBack();
bool HistoryForward();
bool HistoryCanBack();
bool HistoryCanForward();
// Resets History
void HistoryClear();
// Returns pointer to conteiners/cells structure.
wxHtmlContainerCell* GetInternalRepresentation();
// Returns a pointer to the parser.
wxHtmlWinParser* GetParser();
bool ScrollToAnchor(const wxString& anchor);
bool HasAnchor(const wxString& anchor);
//Adds input filter
static void AddFilter(wxPyHtmlFilter *filter);
void base_OnLinkClicked(const wxHtmlLinkInfo& link);
void base_OnSetTitle(const wxString& title);
void base_OnCellMouseHover(wxHtmlCell *cell, wxCoord x, wxCoord y);
@@ -609,12 +725,6 @@ public:
const wxMouseEvent& event);
};
// Static methods are mapped to stand-alone functions
%inline %{
void wxHtmlWindow_AddFilter(wxHtmlFilter *filter) {
wxHtmlWindow::AddFilter(filter);
}
%}
//---------------------------------------------------------------------------
@@ -702,6 +812,7 @@ public:
wxPyPtrTypeMap_Add("wxHtmlTagHandler", "wxPyHtmlTagHandler");
wxPyPtrTypeMap_Add("wxHtmlWinTagHandler", "wxPyHtmlWinTagHandler");
wxPyPtrTypeMap_Add("wxHtmlWindow", "wxPyHtmlWindow");
wxPyPtrTypeMap_Add("wxHtmlFilter", "wxPyHtmlFilter");
%}
//----------------------------------------------------------------------

View File

@@ -179,6 +179,21 @@ public:
return PyString_FromStringAndSize((char*)data, len);
}
void SetDataBuffer(PyObject* data) {
unsigned char* buffer;
int size;
if (!PyArg_Parse(data, "w#", &buffer, &size))
return;
if (size != self->GetWidth() * self->GetHeight() * 3) {
PyErr_SetString(PyExc_TypeError, "Incorrect buffer size");
return;
}
self->SetData(buffer);
}
void SetData(PyObject* data) {
unsigned char* dataPtr;

View File

@@ -17,6 +17,7 @@
#include <wx/resource.h>
#include <wx/tooltip.h>
#include <wx/busyinfo.h>
#include <wx/geometry.h>
%}
//----------------------------------------------------------------------
@@ -79,22 +80,38 @@ public:
return tup;
}
int __cmp__(const wxSize* sz) {
if (! sz) return 1;
if (*self == *sz) return 0;
return -1;
bool __eq__(PyObject* obj) {
wxSize tmp;
wxSize* ptr = &tmp;
if (obj == Py_None) return FALSE;
wxPyBLOCK_THREADS(bool success = wxSize_helper(obj, &ptr); PyErr_Clear());
if (! success) return FALSE;
return *self == *ptr;
}
bool __ne__(PyObject* obj) {
wxSize tmp;
wxSize* ptr = &tmp;
if (obj == Py_None) return TRUE;
wxPyBLOCK_THREADS(bool success = wxSize_helper(obj, &ptr); PyErr_Clear());
if (! success) return TRUE;
return *self != *ptr;
}
}
%pragma(python) addtoclass = "
def __str__(self): return str(self.asTuple())
def __repr__(self): return str(self.asTuple())
def __repr__(self): return 'wxSize'+str(self.asTuple())
def __len__(self): return len(self.asTuple())
def __getitem__(self, index): return self.asTuple()[index]
def __setitem__(self, index, val):
if index == 0: self.width = val
elif index == 1: self.height = val
else: raise IndexError
def __nonzero__(self): return self.asTuple() != (0,0)
def __getinitargs__(self): return ()
def __getstate__(self): return self.asTuple()
def __setstate__(self, state): self.Set(*state)
"
};
@@ -122,31 +139,46 @@ public:
return tup;
}
wxRealPoint __add__(const wxRealPoint* p) {
if (! p) return *self;
return *self + *p;
wxRealPoint __add__(const wxRealPoint& p) {
return *self + p;
}
wxRealPoint __sub__(const wxRealPoint* p) {
if (! p) return *self;
return *self - *p;
wxRealPoint __sub__(const wxRealPoint& p) {
return *self - p;
}
int __cmp__(const wxRealPoint* p) {
if (! p) return 1;
if (*self == *p) return 0;
return -1;
bool __eq__(PyObject* obj) {
wxRealPoint tmp;
wxRealPoint* ptr = &tmp;
if (obj == Py_None) return FALSE;
wxPyBLOCK_THREADS(bool success = wxRealPoint_helper(obj, &ptr); PyErr_Clear());
if (! success) return FALSE;
return *self == *ptr;
}
bool __ne__(PyObject* obj) {
wxRealPoint tmp;
wxRealPoint* ptr = &tmp;
if (obj == Py_None) return TRUE;
wxPyBLOCK_THREADS(bool success = wxRealPoint_helper(obj, &ptr); PyErr_Clear());
if (! success) return TRUE;
return *self != *ptr;
}
}
%pragma(python) addtoclass = "
def __str__(self): return str(self.asTuple())
def __repr__(self): return str(self.asTuple())
def __repr__(self): return 'wxRealPoint'+str(self.asTuple())
def __len__(self): return len(self.asTuple())
def __getitem__(self, index): return self.asTuple()[index]
def __setitem__(self, index, val):
if index == 0: self.width = val
elif index == 1: self.height = val
else: raise IndexError
def __nonzero__(self): return self.asTuple() != (0.0, 0.0)
def __getinitargs__(self): return ()
def __getstate__(self): return self.asTuple()
def __setstate__(self, state): self.Set(*state)
"
};
@@ -172,31 +204,46 @@ public:
return tup;
}
wxPoint __add__(const wxPoint* p) {
if (! p) return *self;
return *self + *p;
wxPoint __add__(const wxPoint& p) {
return *self + p;
}
wxPoint __sub__(const wxPoint* p) {
if (! p) return *self;
return *self - *p;
wxPoint __sub__(const wxPoint& p) {
return *self - p;
}
int __cmp__(const wxPoint* p) {
if (! p) return 1;
if (*self == *p) return 0;
return -1;
bool __eq__(PyObject* obj) {
wxPoint tmp;
wxPoint* ptr = &tmp;
if (obj == Py_None) return FALSE;
wxPyBLOCK_THREADS(bool success = wxPoint_helper(obj, &ptr); PyErr_Clear());
if (! success) return FALSE;
return *self == *ptr;
}
bool __ne__(PyObject* obj) {
wxPoint tmp;
wxPoint* ptr = &tmp;
if (obj == Py_None) return TRUE;
wxPyBLOCK_THREADS(bool success = wxPoint_helper(obj, &ptr); PyErr_Clear());
if (! success) return TRUE;
return *self != *ptr;
}
}
%pragma(python) addtoclass = "
def __str__(self): return str(self.asTuple())
def __repr__(self): return str(self.asTuple())
def __repr__(self): return 'wxPoint'+str(self.asTuple())
def __len__(self): return len(self.asTuple())
def __getitem__(self, index): return self.asTuple()[index]
def __setitem__(self, index, val):
if index == 0: self.x = val
elif index == 1: self.y = val
else: raise IndexError
def __nonzero__(self): return self.asTuple() != (0,0)
def __getinitargs__(self): return ()
def __getstate__(self): return self.asTuple()
def __setstate__(self, state): self.Set(*state)
"
};
@@ -204,7 +251,7 @@ public:
class wxRect {
public:
wxRect(int x=0, int y=0, int w=0, int h=0);
wxRect(int x=0, int y=0, int width=0, int height=0);
// TODO: do this one too... wxRect(const wxPoint& pos, const wxSize& size);
~wxRect();
@@ -233,12 +280,24 @@ public:
void SetTop(int top);
void SetBottom(int bottom);
void Deflate(int dx, int dy);
void Inflate(int dx, int dy);
bool Inside(int cx, int cy);
%name(InsideXY)bool Inside(int cx, int cy);
bool Inside(const wxPoint& pt);
bool Intersects(const wxRect& rect);
%name(OffsetXY) void Offset(int dx, int dy);
void Offset(const wxPoint& pt);
int x, y, width, height;
%addmethods {
void Set(int x=0, int y=0, int width=0, int height=0) {
self->x = x;
self->y = y;
self->width = width;
self->height = height;
}
PyObject* asTuple() {
wxPyBeginBlockThreads();
PyObject* tup = PyTuple_New(4);
@@ -250,21 +309,32 @@ public:
return tup;
}
wxRect __add__(const wxRect* rect) {
if (! rect) return *self;
return *self + *rect;
wxRect __add__(const wxRect& rect) {
return *self + rect;
}
int __cmp__(const wxRect* rect) {
if (! rect) return 1;
if (*self == *rect) return 0;
return -1;
bool __eq__(PyObject* obj) {
wxRect tmp;
wxRect* ptr = &tmp;
if (obj == Py_None) return FALSE;
wxPyBLOCK_THREADS(bool success = wxRect_helper(obj, &ptr); PyErr_Clear());
if (! success) return FALSE;
return *self == *ptr;
}
bool __ne__(PyObject* obj) {
wxRect tmp;
wxRect* ptr = &tmp;
if (obj == Py_None) return TRUE;
wxPyBLOCK_THREADS(bool success = wxRect_helper(obj, &ptr); PyErr_Clear());
if (! success) return TRUE;
return *self != *ptr;
}
}
%pragma(python) addtoclass = "
def __str__(self): return str(self.asTuple())
def __repr__(self): return str(self.asTuple())
def __repr__(self): return 'wxRect'+str(self.asTuple())
def __len__(self): return len(self.asTuple())
def __getitem__(self, index): return self.asTuple()[index]
def __setitem__(self, index, val):
@@ -273,6 +343,10 @@ public:
elif index == 2: self.width = val
elif index == 3: self.height = val
else: raise IndexError
def __nonzero__(self): return self.asTuple() != (0,0,0,0)
def __getinitargs__(self): return ()
def __getstate__(self): return self.asTuple()
def __setstate__(self, state): self.Set(*state)
# override the __getattr__ made by SWIG
def __getattr__(self, name):
@@ -328,7 +402,7 @@ public:
if (dest != wxRect(0,0,0,0)) {
wxPyBeginBlockThreads();
wxRect* newRect = new wxRect(dest);
obj = wxPyConstructObject((void*)newRect, "wxRect");
obj = wxPyConstructObject((void*)newRect, wxT("wxRect"));
PyObject* one = PyInt_FromLong(1);
PyObject_SetAttrString(obj, "thisown", one);
Py_DECREF(one);
@@ -341,13 +415,116 @@ public:
%}
//---------------------------------------------------------------------------
// wxPoint2Ds represent a point or a vector in a 2d coordinate system
class wxPoint2DDouble
{
public:
double m_x;
double m_y;
%name(x)double m_x;
%name(y)double m_y;
wxPoint2DDouble( double x=0 , double y=0 );
%name(wxPoint2DDoubleCopy)wxPoint2DDouble( const wxPoint2DDouble &pt );
%name(wxPoint2DDoubleFromPoint)wxPoint2DDouble( const wxPoint &pt );
// two different conversions to integers, floor and rounding
void GetFloor( int* OUTPUT , int* OUTPUT ) const;
void GetRounded( int* OUTPUT , int* OUTPUT ) const;
double GetVectorLength() const;
double GetVectorAngle() const ;
void SetVectorLength( double length );
void SetVectorAngle( double degrees );
// LinkError: void SetPolarCoordinates( double angle , double length );
// LinkError: void Normalize();
%pragma(python) addtoclass = "
def SetPolarCoordinates(self, angle, length):
self.SetVectorLength(length)
self.SetVectorAngle(angle)
def Normalize(self):
self.SetVectorLength(1.0)
"
double GetDistance( const wxPoint2DDouble &pt ) const;
double GetDistanceSquare( const wxPoint2DDouble &pt ) const;
double GetDotProduct( const wxPoint2DDouble &vec ) const;
double GetCrossProduct( const wxPoint2DDouble &vec ) const;
%addmethods {
void Set( double x=0 , double y=0 ) {
self->m_x = x;
self->m_y = y;
}
// the reflection of this point
wxPoint2DDouble __neg__() { return -(*self); }
wxPoint2DDouble& __iadd__(const wxPoint2DDouble& pt) { return (*self) += pt; }
wxPoint2DDouble& __isub__(const wxPoint2DDouble& pt) { return (*self) -= pt; }
wxPoint2DDouble& __imul__(const wxPoint2DDouble& pt) { return (*self) *= pt; }
wxPoint2DDouble& __idiv__(const wxPoint2DDouble& pt) { return (*self) /= pt; }
// TODO:
//wxPoint2DDouble& operator*=(double n);
//wxPoint2DDouble& operator*=(int n);
//wxPoint2DDouble& operator/=(double n);
//wxPoint2DDouble& operator/=(int n);
bool __eq__(PyObject* obj) {
wxPoint2DDouble tmp;
wxPoint2DDouble* ptr = &tmp;
if (obj == Py_None) return FALSE;
wxPyBLOCK_THREADS(bool success = wxPoint2DDouble_helper(obj, &ptr); PyErr_Clear());
if (! success) return FALSE;
return *self == *ptr;
}
bool __ne__(PyObject* obj) {
wxPoint2DDouble tmp;
wxPoint2DDouble* ptr = &tmp;
if (obj == Py_None) return TRUE;
wxPyBLOCK_THREADS(bool success = wxPoint2DDouble_helper(obj, &ptr); PyErr_Clear());
if (! success) return TRUE;
return *self != *ptr;
}
PyObject* asTuple() {
wxPyBeginBlockThreads();
PyObject* tup = PyTuple_New(2);
PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->m_x));
PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->m_y));
wxPyEndBlockThreads();
return tup;
}
}
%pragma(python) addtoclass = "
def __str__(self): return str(self.asTuple())
def __repr__(self): return 'wxPoint2DDouble'+str(self.asTuple())
def __len__(self): return len(self.asTuple())
def __getitem__(self, index): return self.asTuple()[index]
def __setitem__(self, index, val):
if index == 0: self.m_x = val
elif index == 1: self.m_yt = val
else: raise IndexError
def __nonzero__(self): return self.asTuple() != (0.0, 0.0)
def __getinitargs__(self): return ()
def __getstate__(self): return self.asTuple()
def __setstate__(self, state): self.Set(*state)
"
};
//---------------------------------------------------------------------------
// Miscellaneous functions
long wxNewId();
void wxRegisterId(long id);
%name(NewId) long wxNewId();
%name(RegisterId) void wxRegisterId(long id);
long wxGetCurrentId();
void wxBell();
@@ -381,14 +558,16 @@ bool wxYield();
bool wxYieldIfNeeded();
void wxEnableTopLevelWindows(bool enable);
%inline %{
#ifdef wxUSE_RESOURCES
inline %{
wxString wxGetResource(const wxString& section, const wxString& entry,
const wxString& file = wxPyEmptyString) {
wxChar * retval;
wxChar* retval;
wxGetResource(section, entry, &retval, file);
return retval;
}
%}
#endif
wxString wxStripMenuCodes(const wxString& in);

View File

@@ -183,6 +183,7 @@ wxWindow* wxGetTopLevelParent(wxWindow *win);
//---------------------------------------------------------------------------
// Resource System
#ifdef wxUSE_WX_RESOURCES
bool wxResourceAddIdentifier(char* name, int value);
void wxResourceClear(void);
wxBitmap wxResourceCreateBitmap(char* resource);
@@ -192,6 +193,7 @@ int wxResourceGetIdentifier(char* name);
bool wxResourceParseData(char* resource, wxResourceTable *table = NULL);
bool wxResourceParseFile(char* filename, wxResourceTable *table = NULL);
bool wxResourceParseString(char* resource, wxResourceTable *table = NULL);
#endif
//---------------------------------------------------------------------------
// System Settings
@@ -407,7 +409,7 @@ public:
//----------------------------------------------------------------------
bool wxSafeYield(wxWindow* win=NULL);
bool wxSafeYield(wxWindow* win=NULL, bool onlyIfNeeded=FALSE);
void wxPostEvent(wxEvtHandler *dest, wxEvent& event);
void wxWakeUpIdle();
@@ -509,8 +511,10 @@ public:
bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
bool fullScreen = FALSE, wxRect* rect = NULL);
%name(BeginDrag2) bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
wxWindow* fullScreenRect);
%name(BeginDragBounded) bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
wxWindow* boundingWindow);
%pragma(python) addtoclass = "BeginDrag2 = BeginDragBounded"
bool EndDrag();
bool Move(const wxPoint& pt);
@@ -629,6 +633,10 @@ public:
static unsigned long GetTraceMask();
static bool IsAllowedTraceMask(const wxString& mask);
static void SetLogLevel(unsigned long logLevel);
static unsigned long GetLogLevel();
// static void TimeStamp(wxString *str);
%addmethods {
wxString TimeStamp() {
@@ -695,6 +703,7 @@ void wxLogError(const wxString& msg);
void wxLogWarning(const wxString& msg);
void wxLogMessage(const wxString& msg);
void wxLogInfo(const wxString& msg);
void wxLogDebug(const wxString& msg);
void wxLogVerbose(const wxString& msg);
void wxLogStatus(const wxString& msg);
%name(wxLogStatusFrame)void wxLogStatus(wxFrame *pFrame, const wxString& msg);
@@ -1108,10 +1117,10 @@ class wxFileTypeInfo
public:
// ctors
// a normal item
wxFileTypeInfo(const char* mimeType,
const char* openCmd,
const char* printCmd,
const char* desc);
wxFileTypeInfo(const wxString& mimeType,
const wxString& openCmd,
const wxString& printCmd,
const wxString& desc);
// the array elements correspond to the parameters of the ctor above in
@@ -1205,7 +1214,7 @@ public:
wxString str;
if (self->GetMimeType(&str)) {
#if wxUSE_UNICODE
return PyUnicode_FromUnicode(str.c_str(), str.Len());
return PyUnicode_FromWideChar(str.c_str(), str.Len());
#else
return PyString_FromStringAndSize(str.c_str(), str.Len());
#endif
@@ -1255,9 +1264,9 @@ public:
wxPyBeginBlockThreads();
PyObject* tuple = PyTuple_New(3);
PyTuple_SetItem(tuple, 0, wxPyConstructObject(new wxIcon(icon),
"wxIcon", TRUE));
wxT("wxIcon"), TRUE));
#if wxUSE_UNICODE
PyTuple_SetItem(tuple, 1, PyUnicode_FromUnicode(iconFile.c_str(), iconFile.Len()));
PyTuple_SetItem(tuple, 1, PyUnicode_FromWideChar(iconFile.c_str(), iconFile.Len()));
#else
PyTuple_SetItem(tuple, 1, PyString_FromStringAndSize(iconFile.c_str(), iconFile.Len()));
#endif
@@ -1276,7 +1285,7 @@ public:
wxString str;
if (self->GetDescription(&str)) {
#if wxUSE_UNICODE
return PyUnicode_FromUnicode(str.c_str(), str.Len());
return PyUnicode_FromWideChar(str.c_str(), str.Len());
#else
return PyString_FromStringAndSize(str.c_str(), str.Len());
#endif
@@ -1293,7 +1302,7 @@ public:
wxString str;
if (self->GetOpenCommand(&str, wxFileType::MessageParameters(filename, mimetype))) {
#if wxUSE_UNICODE
return PyUnicode_FromUnicode(str.c_str(), str.Len());
return PyUnicode_FromWideChar(str.c_str(), str.Len());
#else
return PyString_FromStringAndSize(str.c_str(), str.Len());
#endif
@@ -1310,7 +1319,7 @@ public:
wxString str;
if (self->GetPrintCommand(&str, wxFileType::MessageParameters(filename, mimetype))) {
#if wxUSE_UNICODE
return PyUnicode_FromUnicode(str.c_str(), str.Len());
return PyUnicode_FromWideChar(str.c_str(), str.Len());
#else
return PyString_FromStringAndSize(str.c_str(), str.Len());
#endif
@@ -1525,7 +1534,7 @@ public:
wxBitmap rval = wxNullBitmap;
wxPyBeginBlockThreads();
if ((wxPyCBH_findCallback(m_myInst, "CreateBitmap"))) {
PyObject* so = wxPyConstructObject((void*)&size, "wxSize", 0);
PyObject* so = wxPyConstructObject((void*)&size, wxT("wxSize"), 0);
PyObject* ro;
wxBitmap* ptr;
PyObject* s1, *s2;
@@ -1580,8 +1589,6 @@ public:
const wxString& client = wxPyART_OTHER,
const wxSize& size = wxDefaultSize);
// Destroy caches & all providers
static void CleanUpProviders();
};
@@ -1691,7 +1698,7 @@ public:
// #define ADD_STRING(dict, str) \
// wxString tmp##str(str); \
// PyDict_SetItemString(dict, #str, \
// PyUnicode_FromUnicode(tmp##str.c_str(), tmp##str.Len()))
// PyUnicode_FromWideChar(tmp##str.c_str(), tmp##str.Len()))
// #else
// #define ADD_STRING(dict, str) \
// PyDict_SetItemString(d, #str, PyString_FromString(str))

View File

@@ -168,7 +168,7 @@ $function
%typemap(python, out) wxString {
#if wxUSE_UNICODE
$target = PyUnicode_FromUnicode($source->c_str(), $source->Len());
$target = PyUnicode_FromWideChar($source->c_str(), $source->Len());
#else
$target = PyString_FromStringAndSize($source->c_str(), $source->Len());
#endif
@@ -180,7 +180,7 @@ $function
%typemap(python, out) wxString* {
#if wxUSE_UNICODE
$target = PyUnicode_FromUnicode($source->c_str(), $source->Len());
$target = PyUnicode_FromWideChar($source->c_str(), $source->Len());
#else
$target = PyString_FromStringAndSize($source->c_str(), $source->Len());
#endif
@@ -244,6 +244,12 @@ $function
return NULL;
}
%typemap(python,in) wxPoint2DDouble& (wxPoint2DDouble temp) {
$target = &temp;
if (! wxPoint2DDouble_helper($source, &$target))
return NULL;
}
//---------------------------------------------------------------------------
// Typemap to convert strings to wxColour. Two string formats are accepted,
// either a colour name, or a hex colour spec like "#RRGGBB"
@@ -268,11 +274,10 @@ $function
PyObject* item = PySequence_GetItem($source, i);
#if wxUSE_UNICODE
PyObject* str = PyObject_Unicode(item);
$target->Add(PyUnicode_AsUnicode(str));
#else
PyObject* str = PyObject_Str(item);
$target->Add(PyString_AsString(str));
#endif
$target->Add(Py2wxString(str));
Py_DECREF(item);
Py_DECREF(str);
}
@@ -308,6 +313,29 @@ $function
}
// Typemaps to convert an array of ints to a list
%typemap(python, out) wxArrayInt& {
$target = PyList_New(0);
size_t idx;
for (idx = 0; idx < $source->GetCount(); idx += 1) {
PyObject* val = PyInt_FromLong($source->Item(idx));
PyList_Append($target, val);
Py_DECREF(val);
}
}
%typemap(python, out) wxArrayInt {
$target = PyList_New(0);
size_t idx;
for (idx = 0; idx < $source->GetCount(); idx += 1) {
PyObject* val = PyInt_FromLong($source->Item(idx));
PyList_Append($target, val);
Py_DECREF(val);
}
delete $source;
}
//---------------------------------------------------------------------------
// Map T_OUTPUTs for floats to return ints.
@@ -360,6 +388,11 @@ $function
%typemap(python,ignore) byte *OUTPUT = byte *T_OUTPUT;
%typemap(python,argout) byte *OUTPUT = byte *T_OUTPUT;
%typemap(python,ignore) wxCoord *OUTPUT = int *OUTPUT;
%typemap(python,argout) wxCoord *OUTPUT = int *OUTPUT;
//---------------------------------------------------------------------------
// Typemaps to convert return values that are base class pointers
// to the real derived type, if possible. See wxPyMake_wxObject in
@@ -369,6 +402,8 @@ $function
%typemap(python, out) wxMenu* { $target = wxPyMake_wxObject($source); }
%typemap(python, out) wxValidator* { $target = wxPyMake_wxObject($source); }
%typemap(python, out) wxApp* { $target = wxPyMake_wxObject($source); }
%typemap(python, out) wxPyApp* { $target = wxPyMake_wxObject($source); }
%typemap(python, out) wxDC* { $target = wxPyMake_wxObject($source); }
%typemap(python, out) wxFSFile* { $target = wxPyMake_wxObject($source); }
%typemap(python, out) wxFileSystem* { $target = wxPyMake_wxObject($source); }

View File

@@ -50,6 +50,19 @@ public:
void write(wxString data);
void writelines(wxStringPtrList);
*/
// wxInputStream methods that may come in handy...
char Peek() { if (m_wxis) return m_wxis->Peek(); else return -1; }
char GetC() { if (m_wxis) return m_wxis->GetC(); else return -1; }
size_t LastRead() { if (m_wxis) return m_wxis->LastRead(); else return 0; }
bool CanRead() { if (m_wxis) return m_wxis->CanRead(); else return FALSE; }
bool Eof() { if (m_wxis) return m_wxis->Eof(); else return FALSE; }
bool Ungetch(char c) { if (m_wxis) return m_wxis->Ungetch(c); else return FALSE; }
unsigned long SeekI(unsigned long pos, wxSeekMode mode)
{ if (m_wxis) return m_wxis->SeekI(pos, mode); else return 0; }
unsigned long TellI() { if (m_wxis) return m_wxis->TellI(); else return 0; }
};

View File

@@ -30,7 +30,6 @@
%import controls.i
%pragma(python) code = "import wx"
%pragma(python) code = "import string"
//---------------------------------------------------------------------------
@@ -39,16 +38,20 @@ class wxSizerItem : public wxObject {
public:
// No need to ever create one directly in Python...
//wxSizerItem( int width, int height, int option, int flag, int border, wxObject* userData);
//wxSizerItem( wxWindow *window, int option, int flag, int border, wxObject* userData );
//wxSizerItem( wxSizer *sizer, int option, int flag, int border, wxObject* userData );
//wxSizerItem( int width, int height, int proportion, int flag, int border, wxObject* userData);
//wxSizerItem( wxWindow *window, int proportion, int flag, int border, wxObject* userData );
//wxSizerItem( wxSizer *sizer, int proportion, int flag, int border, wxObject* userData );
void DeleteWindows();
void DetachSizer();
wxPoint GetPosition();
wxSize GetSize();
wxSize CalcMin();
void SetDimension( wxPoint pos, wxSize size );
wxSize GetMinSize();
void SetInitSize( int x, int y );
%name(SetRatioWH) void SetRatio( int width, int height );
%name(SetRatioSize) void SetRatio( wxSize size );
void SetRatio( float ratio );
@@ -58,18 +61,26 @@ public:
bool IsSizer();
bool IsSpacer();
void SetProportion( int proportion );
int GetProportion();
%pragma(python) addtoclass = "SetOption = SetProportion"
%pragma(python) addtoclass = "GetOption = GetProportion"
void SetFlag( int flag );
int GetFlag();
void SetBorder( int border );
int GetBorder();
wxWindow *GetWindow();
void SetWindow( wxWindow *window );
wxSizer *GetSizer();
void SetSizer( wxSizer *sizer );
int GetOption();
int GetFlag();
int GetBorder();
const wxSize& GetSpacer();
void SetSpacer( const wxSize &size );
void SetInitSize( int x, int y );
void SetOption( int option );
void SetFlag( int flag );
void SetBorder( int border );
void Show( bool show );
bool IsShown();
wxPoint GetPosition();
// wxObject* GetUserData();
%addmethods {
@@ -104,103 +115,127 @@ public:
%addmethods {
void Destroy() { delete self; }
void AddWindow(wxWindow *window, int option=0, int flag=0, int border=0,
void AddWindow(wxWindow *window, int proportion=0, int flag=0, int border=0,
PyObject* userData=NULL) {
wxPyUserData* data = NULL;
if (userData) data = new wxPyUserData(userData);
self->Add(window, option, flag, border, data);
self->Add(window, proportion, flag, border, data);
}
void AddSizer(wxSizer *sizer, int option=0, int flag=0, int border=0,
void AddSizer(wxSizer *sizer, int proportion=0, int flag=0, int border=0,
PyObject* userData=NULL) {
wxPyUserData* data = NULL;
if (userData) data = new wxPyUserData(userData);
self->Add(sizer, option, flag, border, data);
self->Add(sizer, proportion, flag, border, data);
}
void AddSpacer(int width, int height, int option=0, int flag=0,
void AddSpacer(int width, int height, int proportion=0, int flag=0,
int border=0, PyObject* userData=NULL) {
wxPyUserData* data = NULL;
if (userData) data = new wxPyUserData(userData);
self->Add(width, height, option, flag, border, data);
self->Add(width, height, proportion, flag, border, data);
}
void InsertWindow(int before, wxWindow *window, int option=0, int flag=0,
void InsertWindow(int before, wxWindow *window, int proportion=0, int flag=0,
int border=0, PyObject* userData=NULL) {
wxPyUserData* data = NULL;
if (userData) data = new wxPyUserData(userData);
self->Insert(before, window, option, flag, border, data);
self->Insert(before, window, proportion, flag, border, data);
}
void InsertSizer(int before, wxSizer *sizer, int option=0, int flag=0,
void InsertSizer(int before, wxSizer *sizer, int proportion=0, int flag=0,
int border=0, PyObject* userData=NULL) {
wxPyUserData* data = NULL;
if (userData) data = new wxPyUserData(userData);
self->Insert(before, sizer, option, flag, border, data);
self->Insert(before, sizer, proportion, flag, border, data);
}
void InsertSpacer(int before, int width, int height, int option=0, int flag=0,
void InsertSpacer(int before, int width, int height, int proportion=0, int flag=0,
int border=0, PyObject* userData=NULL) {
wxPyUserData* data = NULL;
if (userData) data = new wxPyUserData(userData);
self->Insert(before, width, height, option, flag, border, data);
self->Insert(before, width, height, proportion, flag, border, data);
}
void PrependWindow(wxWindow *window, int option=0, int flag=0, int border=0,
void PrependWindow(wxWindow *window, int proportion=0, int flag=0, int border=0,
PyObject* userData=NULL) {
wxPyUserData* data = NULL;
if (userData) data = new wxPyUserData(userData);
self->Prepend(window, option, flag, border, data);
self->Prepend(window, proportion, flag, border, data);
}
void PrependSizer(wxSizer *sizer, int option=0, int flag=0, int border=0,
void PrependSizer(wxSizer *sizer, int proportion=0, int flag=0, int border=0,
PyObject* userData=NULL) {
wxPyUserData* data = NULL;
if (userData) data = new wxPyUserData(userData);
self->Prepend(sizer, option, flag, border, data);
self->Prepend(sizer, proportion, flag, border, data);
}
void PrependSpacer(int width, int height, int option=0, int flag=0,
void PrependSpacer(int width, int height, int proportion=0, int flag=0,
int border=0, PyObject* userData=NULL) {
wxPyUserData* data = NULL;
if (userData) data = new wxPyUserData(userData);
self->Prepend(width, height, option, flag, border, data);
self->Prepend(width, height, proportion, flag, border, data);
}
// TODO: AddItem, InsertItem, PrependItem
}
%name(RemoveWindow)bool Remove( wxWindow *window );
%name(RemoveWindow)bool Remove( wxWindow *window ); // TODO: This is DEPRECATED. Should all be removed?
%name(RemoveSizer)bool Remove( wxSizer *sizer );
%name(RemovePos)bool Remove( int pos );
%name(DetachWindow)bool Detach( wxWindow *window );
%name(DetachSizer)bool Detach( wxSizer *sizer );
%name(DetachPos)bool Detach( int pos );
%pragma(python) addtoclass = "
def Add(self, *args, **kw):
if type(args[0]) == type(1):
apply(self.AddSpacer, args, kw)
elif string.find(args[0].this, 'Sizer') != -1:
elif isinstance(args[0], wxSizerPtr):
apply(self.AddSizer, args, kw)
else:
elif isinstance(args[0], wxWindowPtr):
apply(self.AddWindow, args, kw)
else:
raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
def Insert(self, *args, **kw):
if type(args[1]) == type(1):
apply(self.InsertSpacer, args, kw)
elif string.find(args[1].this, 'Sizer') != -1:
elif isinstance(args[1], wxSizerPtr):
apply(self.InsertSizer, args, kw)
else:
elif isinstance(args[1], wxWindowPtr):
apply(self.InsertWindow, args, kw)
else:
raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
def Prepend(self, *args, **kw):
if type(args[0]) == type(1):
apply(self.PrependSpacer, args, kw)
elif string.find(args[0].this, 'Sizer') != -1:
elif isinstance(args[0], wxSizerPtr):
apply(self.PrependSizer, args, kw)
else:
elif isinstance(args[0], wxWindowPtr):
apply(self.PrependWindow, args, kw)
else:
raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
def Remove(self, *args, **kw):
if type(args[0]) == type(1):
apply(self.RemovePos, args, kw)
elif string.find(args[0].this, 'Sizer') != -1:
apply(self.RemoveSizer, args, kw)
return apply(self.RemovePos, args, kw)
elif isinstance(args[0], wxSizerPtr):
return apply(self.RemoveSizer, args, kw)
elif isinstance(args[0], wxWindowPtr):
return apply(self.RemoveWindow, args, kw)
else:
apply(self.RemoveWindow, args, kw)
raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
def Detach(self, *args, **kw):
if type(args[0]) == type(1):
return apply(self.DetachPos, args, kw)
elif isinstance(args[0], wxSizerPtr):
return apply(self.DetachSizer, args, kw)
elif isinstance(args[0], wxWindowPtr):
return apply(self.DetachWindow, args, kw)
else:
raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
def AddMany(self, widgets):
for childinfo in widgets:
@@ -209,22 +244,38 @@ public:
apply(self.Add, childinfo)
"
void Clear( bool delete_windows = false );
void DeleteWindows();
void SetDimension( int x, int y, int width, int height );
void SetMinSize(wxSize size);
%name(SetItemMinSizeWindow) void SetItemMinSize(wxWindow* window, int width, int height);
%name(SetItemMinSizeSizer) void SetItemMinSize(wxSizer* sizer, int width, int height);
%name(SetItemMinSizePos) void SetItemMinSize(int pos, int width, int height);
%name(SetItemMinSizeWindow) void SetItemMinSize(wxWindow* window, wxSize size);
%name(SetItemMinSizeSizer) void SetItemMinSize(wxSizer* sizer, wxSize size);
%name(SetItemMinSizePos) void SetItemMinSize(int pos, wxSize size);
%name(SetItemMinSizeWindowWH) void SetItemMinSize(wxWindow* window, int width, int height);
%name(SetItemMinSizeSizerWH) void SetItemMinSize(wxSizer* sizer, int width, int height);
%name(SetItemMinSizePosWH) void SetItemMinSize(int pos, int width, int height);
%pragma(python) addtoclass = "
def SetItemMinSize(self, *args):
if type(args[0]) == type(1):
apply(self.SetItemMinSizePos, args)
elif string.find(args[0].this, 'Sizer') != -1:
elif isinstance(args[0], wxSizerPtr):
apply(self.SetItemMinSizeSizer, args)
else:
elif isinstance(args[0], wxWindowPtr):
apply(self.SetItemMinSizeWindow, args)
else:
raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
def SetItemMinSizeWH(self, *args):
if type(args[0]) == type(1):
apply(self.SetItemMinSizePosWH, args)
elif isinstance(args[0], wxSizerPtr):
apply(self.SetItemMinSizeSizerWH, args)
elif isinstance(args[0], wxWindowPtr):
apply(self.SetItemMinSizeWindowWH, args)
else:
raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
"
wxSize GetSize();
@@ -251,17 +302,64 @@ public:
void SetSizeHints( wxWindow *window );
void SetVirtualSizeHints( wxWindow *window );
void Clear( bool delete_windows=FALSE );
void DeleteWindows();
// wxList& GetChildren();
%addmethods {
PyObject* GetChildren() {
wxList& list = self->GetChildren();
wxSizerItemList& list = self->GetChildren();
return wxPy_ConvertList(&list, "wxSizerItem");
}
}
void SetDimension( int x, int y, int width, int height );
// Manage whether individual windows or sub-sizers are considered
// in the layout calculations or not.
%name(ShowWindow)void Show( wxWindow *window, bool show = TRUE );
%name(ShowSizer)void Show( wxSizer *sizer, bool show = TRUE );
%name(ShowPos)void Show( size_t index, bool show = TRUE );
%name(HideWindow)void Hide( wxWindow *window );
%name(HideSizer)void Hide( wxSizer *sizer );
%name(HidePos)void Hide( size_t index );
%name(IsShownWindow)bool IsShown( wxWindow *window );
%name(IsShownSizer)bool IsShown( wxSizer *sizer );
%name(IsShownPos)bool IsShown( size_t index );
%pragma(python) addtoclass = "
def Show(self, *args):
if type(args[0]) == type(1):
apply(self.ShowPos, args)
elif isinstance(args[0], wxSizerPtr):
apply(self.ShowSizer, args)
elif isinstance(args[0], wxWindowPtr):
apply(self.ShowWindow, args)
else:
raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
def Hide(self, *args):
if type(args[0]) == type(1):
apply(self.HidePos, args)
elif isinstance(args[0], wxSizerPtr):
apply(self.HideSizer, args)
elif isinstance(args[0], wxWindowPtr):
apply(self.HideWindow, args)
else:
raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
def IsShown(self, *args):
if type(args[0]) == type(1):
return apply(self.IsShownPos, args)
elif isinstance(args[0], wxSizerPtr):
return apply(self.IsShownSizer, args)
elif isinstance(args[0], wxWindowPtr):
return apply(self.IsShownWindow, args)
else:
raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
"
// Recursively call wxWindow::Show () on all sizer items.
void ShowItems (bool show);
};
@@ -303,6 +401,7 @@ public:
wxBoxSizer(int orient = wxHORIZONTAL);
%pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
int GetOrientation();
void SetOrientation(int orient);
void RecalcSizes();
wxSize CalcMin();
};
@@ -352,6 +451,19 @@ public:
//---------------------------------------------------------------------------
enum wxFlexSizerGrowMode
{
// don't resize the cells in non-flexible direction at all
wxFLEX_GROWMODE_NONE,
// uniformly resize only the specified ones (default)
wxFLEX_GROWMODE_SPECIFIED,
// uniformly resize all cells
wxFLEX_GROWMODE_ALL
};
class wxFlexGridSizer: public wxGridSizer
{
public:
@@ -361,11 +473,22 @@ public:
void RecalcSizes();
wxSize CalcMin();
void AddGrowableRow( size_t idx );
void AddGrowableRow( size_t idx, int proportion = 0 );
void RemoveGrowableRow( size_t idx );
void AddGrowableCol( size_t idx );
void AddGrowableCol( size_t idx, int proportion = 0 );
void RemoveGrowableCol( size_t idx );
// the sizer cells may grow in both directions, not grow at all or only
// grow in one direction but not the other
// the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default)
void SetFlexibleDirection(int direction);
int GetFlexibleDirection();
// note that the grow mode only applies to the direction which is not
// flexible
void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode);
wxFlexSizerGrowMode GetNonFlexibleGrowMode();
};
//---------------------------------------------------------------------------

View File

@@ -196,7 +196,7 @@ public:
// Insert the new tool at the given position, if pos == GetToolsCount(), it
// is equivalent to DoAddTool()
wxToolBarToolBase *InsertTool(size_t pos,
wxToolBarToolBase *DoInsertTool(size_t pos,
int id,
const wxString& label,
const wxBitmap& bitmap,
@@ -270,7 +270,7 @@ public:
# 2.3.3. They are renamed to have 'Label' in the name so as to be
# able to keep backwards compatibility with using the above
# methods. Eventually these should migrate to be the methods used
# primarily and loose the 'Label' in the name...
# primarily and lose the 'Label' in the name...
def AddLabelTool(self, id, label, bitmap,
bmpDisabled = wxNullBitmap,

View File

@@ -28,7 +28,6 @@
%import _defs.i
%pragma(python) code = "import wx"
%pragma(python) code = "import string"
//----------------------------------------------------------------------
// typemaps for wxInputStream
@@ -61,7 +60,7 @@
if ($source) {
_ptr = new wxPyInputStream($source);
}
$target = wxPyConstructObject(_ptr, "wxInputStream", TRUE);
$target = wxPyConstructObject(_ptr, wxT("wxInputStream"), TRUE);
}
//----------------------------------------------------------------------
@@ -88,6 +87,12 @@
// $target=0;
// }
enum wxSeekMode
{
wxFromStart,
wxFromCurrent,
wxFromEnd
};
@@ -118,6 +123,16 @@ public:
void write(wxString data);
void writelines(wxStringPtrList);
*/
char Peek();
char GetC();
size_t LastRead();
bool CanRead();
bool Eof();
bool Ungetch(char c);
long SeekI(long pos, wxSeekMode mode = wxFromStart);
long TellI();
}

View File

@@ -35,7 +35,7 @@
// Import some definitions of other classes, etc.
%import _defs.i
%pragma(python) code = "import string"
%pragma(python) code = "import wx"
//---------------------------------------------------------------------------
@@ -46,7 +46,7 @@
if (ret) {
PyTuple_SET_ITEM(ret, 0, PyInt_FromLong(flag));
#if wxUSE_UNICODE
PyTuple_SET_ITEM(ret, 1, PyUnicode_FromUnicode(str.c_str(), str.Len()));
PyTuple_SET_ITEM(ret, 1, PyUnicode_FromWideChar(str.c_str(), str.Len()));
#else
PyTuple_SET_ITEM(ret, 1, PyString_FromStringAndSize(str.c_str(), str.Len()));
#endif
@@ -449,6 +449,10 @@ public:
// return the wxDateTime object for the current time
static inline wxDateTime Now();
// return the wxDateTime object for the current time with millisecond
// precision (if available on this platform)
static wxDateTime UNow();
// return the wxDateTime object for today midnight: i.e. as Now() but
// with time set to 0
static inline wxDateTime Today();
@@ -528,8 +532,8 @@ public:
// calendar calculations
// set to the given week day in the same week as this one
wxDateTime& SetToWeekDayInSameWeek(WeekDay weekday);
wxDateTime GetWeekDayInSameWeek(WeekDay weekday);
wxDateTime& SetToWeekDayInSameWeek(WeekDay weekday, WeekFlags flags = Monday_First);
wxDateTime GetWeekDayInSameWeek(WeekDay weekday, WeekFlags flags = Monday_First);
// set to the next week day following this one
wxDateTime& SetToNextWeekDay(WeekDay weekday);
@@ -563,8 +567,8 @@ public:
// sets the date to the given day of the given week in the year,
// returns TRUE on success and FALSE if given date doesn't exist (e.g.
// numWeek is > 53)
bool SetToTheWeek(wxDateTime_t numWeek, WeekDay weekday = Mon);
wxDateTime GetWeek(wxDateTime_t numWeek, WeekDay weekday = Mon);
bool SetToTheWeek(wxDateTime_t numWeek, WeekDay weekday = Mon, WeekFlags flags = Monday_First);
wxDateTime GetWeek(wxDateTime_t numWeek, WeekDay weekday = Mon, WeekFlags flags = Monday_First);
// sets the date to the last day of the given (or current) month or the
// given (or current) year
@@ -758,17 +762,17 @@ public:
%pragma(python) addtoclass = "
def __add__(self, other):
if string.find(other.this, 'wxTimeSpan') != -1:
if isinstance(other, wxTimeSpanPtr):
return self.__add__TS(other)
if string.find(other.this, 'wxDateSpan') != -1:
if isinstance(other, wxDateSpanPtr):
return self.__add__DS(other)
raise TypeError, 'Invalid r.h.s. type for __add__'
def __sub__(self, other):
if string.find(other.this, 'wxDateTime') != -1:
if isinstance(other, wxDateTimePtr):
return self.__sub__DT(other)
if string.find(other.this, 'wxTimeSpan') != -1:
if isinstance(other, wxTimeSpanPtr):
return self.__sub__TS(other)
if string.find(other.this, 'wxDateSpan') != -1:
if isinstance(other, wxDateSpanPtr):
return self.__sub__DS(other)
raise TypeError, 'Invalid r.h.s. type for __sub__'
"

View File

@@ -216,12 +216,17 @@ public:
void DragAcceptFiles(bool accept);
#endif
void Enable(bool enable);
void Disable();
// Find child window by ID or name
%name(FindWindowById) wxWindow* FindWindow(long id);
%name(FindWindowByName) wxWindow* FindWindow(const wxString& name);
void Fit();
// set virtual size to satisfy children
void FitInside();
wxColour GetBackgroundColour();
wxBorder GetBorder() const;
@@ -291,7 +296,9 @@ public:
bool IsShown();
bool IsTopLevel();
void Layout();
#ifdef wxUSE_WX_RESOURCES
bool LoadFromResource(wxWindow* parent, const wxString& resourceName, const wxResourceTable* resourceTable = NULL);
#endif
void Lower();
void MakeModal(bool flag=TRUE);
%name(MoveXY)void Move(int x, int y, int flags = wxSIZE_USE_EXISTING);
@@ -365,6 +372,8 @@ public:
wxSize GetVirtualSize() const;
%name(GetVirtualSizeTuple)void GetVirtualSize( int *OUTPUT, int *OUTPUT ) const;
wxSize GetBestVirtualSize();
%name(SetClientSizeWH)void SetClientSize(int width, int height);
void SetClientSize(const wxSize& size);
//void SetPalette(wxPalette* palette);
@@ -410,6 +419,13 @@ public:
wxSize GetBestSize();
wxSize GetMaxSize();
// There are times (and windows) where 'Best' size and 'Min' size
// are vastly out of sync. This should be remedied somehow, but in
// the meantime, this method will return the larger of BestSize
// (the window's smallest legible size), and any user specified
// MinSize hint.
wxSize GetAdjustedBestSize();
void SetCaret(wxCaret *caret);
wxCaret *GetCaret();
%pragma(python) addtoclass = "# replaces broken shadow method
@@ -761,6 +777,7 @@ public:
wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
wxMenu *Remove(size_t pos);
void EnableTop(size_t pos, bool enable);
bool IsEnabledTop(size_t pos);
void SetLabelTop(size_t pos, const wxString& label);
wxString GetLabelTop(size_t pos);
int FindMenu(const wxString& title);

View File

@@ -65,7 +65,7 @@ enum {
class wxNotebookEvent : public wxNotifyEvent {
public:
wxNotebookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
int nSel = -1, int nOldSel = -1);
int sel = -1, int oldSel = -1);
int GetSelection();
int GetOldSelection();
@@ -96,36 +96,36 @@ public:
%pragma(python) addtomethod = "wxPreNotebook:val._setOORInfo(val)"
int GetPageCount();
int SetSelection(int nPage);
void AdvanceSelection(bool bForward = TRUE);
int SetSelection(int page);
void AdvanceSelection(bool forward = TRUE);
int GetSelection();
bool SetPageText(int nPage, const wxString& strText);
wxString GetPageText(int nPage) const;
bool SetPageText(int page, const wxString& text);
wxString GetPageText(int page) const;
void SetImageList(wxImageList* imageList);
void AssignImageList(wxImageList *imageList) ;
%pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
wxImageList* GetImageList();
int GetPageImage(int nPage);
bool SetPageImage(int nPage, int nImage);
int GetPageImage(int page);
bool SetPageImage(int page, int image);
int GetRowCount();
void SetPageSize(const wxSize& size);
void SetPadding(const wxSize& padding);
bool DeletePage(int nPage);
bool RemovePage(int nPage);
bool DeletePage(int page);
bool RemovePage(int page);
bool DeleteAllPages();
bool AddPage(/*wxNotebookPage*/ wxWindow *pPage,
const wxString& strText,
int bSelect = FALSE,
bool AddPage(/*wxNotebookPage*/ wxWindow *page,
const wxString& text,
int select = FALSE,
int imageId = -1);
bool InsertPage(int nPage,
/*wxNotebookPage*/ wxWindow *pPage,
const wxString& strText,
bool bSelect = FALSE,
bool InsertPage(int page,
/*wxNotebookPage*/ wxWindow *page,
const wxString& text,
bool select = FALSE,
int imageId = -1);
/*wxNotebookPage*/ wxWindow *GetPage(int nPage);
/*wxNotebookPage*/ wxWindow *GetPage(int page);
%addmethods {
void ResizeChildren() {

View File

@@ -6,7 +6,7 @@
name="Controls"
type="win32"
/>
<description>wxPython: GUI library for Python</description>
<description>Python Interpreter</description>
<dependency>
<dependentAssembly>
<assemblyIdentity

View File

@@ -43,7 +43,8 @@ enum {
wxEVT_WIZARD_PAGE_CHANGED,
wxEVT_WIZARD_PAGE_CHANGING,
wxEVT_WIZARD_CANCEL,
wxEVT_WIZARD_HELP
wxEVT_WIZARD_HELP,
wxEVT_WIZARD_FINISHED
};
@@ -61,6 +62,9 @@ def EVT_WIZARD_CANCEL(win, id, func):
def EVT_WIZARD_HELP(win, id, func):
win.Connect(id, -1, wxEVT_WIZARD_HELP, func)
def EVT_WIZARD_FINISHED(win, id, func):
win.Connect(id, -1, wxEVT_WIZARD_FINISHED, func)
"
//----------------------------------------------------------------------
@@ -361,6 +365,9 @@ public:
// page first and return FALSE without changing the page if
// TransferDataFromWindow() returns FALSE - otherwise, returns TRUE
bool ShowPage(wxWizardPage *page, bool goingForward = TRUE);
bool HasNextPage(wxWizardPage* page);
bool HasPrevPage(wxWizardPage* page);
};

View File

@@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wxp.i
// Name: wx.i
// Purpose: SWIG interface file for a python wxWindows module
//
// Author: Robin Dunn
@@ -65,6 +65,14 @@ wxSize wxDefaultSize;
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
enum {
wxPYAPP_ASSERT_SUPPRESS = 1,
wxPYAPP_ASSERT_EXCEPTION = 2,
wxPYAPP_ASSERT_DIALOG = 4,
wxPYAPP_ASSERT_LOG = 8
};
class wxPyApp : public wxEvtHandler {
public:
%addmethods {
@@ -76,6 +84,11 @@ public:
~wxPyApp();
void _setCallbackInfo(PyObject* self, PyObject* _class);
%pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyApp)"
%pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
wxString GetAppName();
#ifdef __WXMSW__
bool GetAuto3D();
@@ -105,6 +118,24 @@ public:
void SetTopWindow(wxWindow* window);
void SetVendorName(const wxString& name);
void SetUseBestVisual(bool flag);
int GetAssertMode();
void SetAssertMode(int mode);
static bool GetMacDefaultEncodingIsPC();
static bool GetMacSupportPCMenuShortcuts();
static long GetMacAboutMenuItemId();
static long GetMacPreferencesMenuItemId();
static long GetMacExitMenuItemId();
static wxString GetMacHelpMenuTitleName();
static void SetMacDefaultEncodingIsPC(bool val);
static void SetMacSupportPCMenuShortcuts(bool val);
static void SetMacAboutMenuItemId(long val);
static void SetMacPreferencesMenuItemId(long val);
static void SetMacExitMenuItemId(long val);
static void SetMacHelpMenuTitleName(const wxString& val);
};
%inline %{
@@ -192,6 +223,7 @@ static wxPyCoreAPI API = {
wxRealPoint_helper,
wxRect_helper,
wxColour_helper,
wxPoint2DDouble_helper,
wxPyCBH_setCallbackInfo,
wxPyCBH_findCallback,
@@ -226,7 +258,7 @@ static wxPyCoreAPI API = {
Py_XDECREF(v);
__wxPreStart(); // initialize the GUI toolkit, if needed.
__wxPreStart(d); // initialize the GUI toolkit, if needed.
// Since these modules are all linked together, initialize them now
@@ -261,7 +293,7 @@ static wxPyCoreAPI API = {
PyDict_SetItemString(d,"wxVERSION_NUMBER", PyInt_FromLong((long)wxVERSION_NUMBER ));
#if wxUSE_UNICODE
wxString tempStr(wxVERSION_STRING);
PyDict_SetItemString(d,"wxVERSION_STRING", PyUnicode_FromUnicode(tempStr.c_str(), tempStr.Len()));
PyDict_SetItemString(d,"wxVERSION_STRING", PyUnicode_FromWideChar(tempStr.c_str(), tempStr.Len()));
#else
PyDict_SetItemString(d,"wxVERSION_STRING", PyString_FromString(wxVERSION_STRING));
#endif
@@ -275,3 +307,4 @@ static wxPyCoreAPI API = {
%pragma(python) include="_extras.py";

View File

@@ -71,6 +71,7 @@ static void wxPyCoreAPI_IMPORT() {
#define wxRealPoint_helper(a,b) (wxPyCoreAPIPtr->p_wxRealPoint_helper(a,b))
#define wxRect_helper(a,b) (wxPyCoreAPIPtr->p_wxRect_helper(a,b))
#define wxColour_helper(a,b) (wxPyCoreAPIPtr->p_wxColour_helper(a,b))
#define wxPoint2DDouble_helper(a,b) (wxPyCoreAPIPtr->p_wxPoint2DDouble_helper(a,b))
#define wxPyCBH_setCallbackInfo(a, b, c, d) (wxPyCoreAPIPtr->p_wxPyCBH_setCallbackInfo(a,b,c,d))
#define wxPyCBH_findCallback(a, b) (wxPyCoreAPIPtr->p_wxPyCBH_findCallback(a, b))

View File

@@ -1,5 +1,5 @@
aa_wxpicon ICON "wxp.ico"
#include "wx/msw/wx.rc"
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "wxc.pyd.manifest"