From 630d84f26f30e2cac046baa864f93596e51368b2 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 11 Nov 1998 03:13:19 +0000 Subject: [PATCH] Additions for wxTreeCtrl git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@983 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- utils/wxPython/src/_defs.i | 5 + utils/wxPython/src/controls2.i | 192 +-------------------------- utils/wxPython/src/msw/controls2.cpp | 42 +++++- utils/wxPython/src/msw/controls2.py | 7 +- utils/wxPython/src/msw/wxp.cpp | 6 +- utils/wxPython/src/msw/wxp.py | 6 +- utils/wxPython/tests/test4.py | 79 ++++++++++- 7 files changed, 134 insertions(+), 203 deletions(-) diff --git a/utils/wxPython/src/_defs.i b/utils/wxPython/src/_defs.i index 40404a1256..3c3e479088 100644 --- a/utils/wxPython/src/_defs.i +++ b/utils/wxPython/src/_defs.i @@ -667,6 +667,8 @@ enum wxEventType { wxEVT_COMMAND_TREE_SET_INFO, wxEVT_COMMAND_TREE_ITEM_EXPANDED, wxEVT_COMMAND_TREE_ITEM_EXPANDING, + wxEVT_COMMAND_TREE_ITEM_COLLAPSED, + wxEVT_COMMAND_TREE_ITEM_COLLAPSING, wxEVT_COMMAND_TREE_SEL_CHANGED, wxEVT_COMMAND_TREE_SEL_CHANGING, wxEVT_COMMAND_TREE_KEY_DOWN, @@ -699,6 +701,9 @@ enum wxEventType { ///////////////////////////////////////////////////////////////////////////// // // $Log$ +// Revision 1.7 1998/11/11 03:12:24 RD +// Additions for wxTreeCtrl +// // Revision 1.6 1998/10/20 06:43:53 RD // New wxTreeCtrl wrappers (untested) // some changes in helpers diff --git a/utils/wxPython/src/controls2.i b/utils/wxPython/src/controls2.i index fa7489ddac..7a21fbe916 100644 --- a/utils/wxPython/src/controls2.i +++ b/utils/wxPython/src/controls2.i @@ -189,192 +189,6 @@ public: //---------------------------------------------------------------------- -#ifdef SKIPTHIS - - -enum { - wxTREE_MASK_HANDLE, - wxTREE_MASK_STATE, - wxTREE_MASK_TEXT, - wxTREE_MASK_IMAGE, - wxTREE_MASK_SELECTED_IMAGE, - wxTREE_MASK_CHILDREN, - wxTREE_MASK_DATA, - - wxTREE_STATE_BOLD, - wxTREE_STATE_DROPHILITED, - wxTREE_STATE_EXPANDED, - wxTREE_STATE_EXPANDEDONCE, - wxTREE_STATE_FOCUSED, - wxTREE_STATE_SELECTED, - wxTREE_STATE_CUT, - - wxTREE_HITTEST_ABOVE, - wxTREE_HITTEST_BELOW, - wxTREE_HITTEST_NOWHERE, - wxTREE_HITTEST_ONITEMBUTTON, - wxTREE_HITTEST_ONITEMICON, - wxTREE_HITTEST_ONITEMINDENT, - wxTREE_HITTEST_ONITEMLABEL, - wxTREE_HITTEST_ONITEMRIGHT, - wxTREE_HITTEST_ONITEMSTATEICON, - wxTREE_HITTEST_TOLEFT, - wxTREE_HITTEST_TORIGHT, - wxTREE_HITTEST_ONITEM, -}; - - -enum { - wxTREE_NEXT_CARET, - wxTREE_NEXT_CHILD, - wxTREE_NEXT_DROPHILITE, - wxTREE_NEXT_FIRSTVISIBLE, - wxTREE_NEXT_NEXT, - wxTREE_NEXT_NEXTVISIBLE, - wxTREE_NEXT_PARENT, - wxTREE_NEXT_PREVIOUS, - wxTREE_NEXT_PREVIOUSVISIBLE, - wxTREE_NEXT_ROOT -}; - -enum { - wxTREE_EXPAND_EXPAND, - wxTREE_EXPAND_COLLAPSE, - wxTREE_EXPAND_COLLAPSE_RESET, - wxTREE_EXPAND_TOGGLE -}; - -enum { - wxTREE_INSERT_LAST, - wxTREE_INSERT_FIRST, - wxTREE_INSERT_SORT, -}; - - - - -class wxTreeItem { -public: - long m_mask; - long m_itemId; - long m_state; - long m_stateMask; - wxString m_text; - int m_image; - int m_selectedImage; - int m_children; - long m_data; - - wxTreeItem(); - ~wxTreeItem(); -}; - - - -class wxTreeEvent : public wxCommandEvent { -public: - int m_code; - wxTreeItem m_item; - long m_oldItem; - wxPoint m_pointDrag; -}; - - - - -class wxTreeCtrl : public wxControl { -public: - wxTreeCtrl(wxWindow *parent, wxWindowID id = -1, - const wxPoint& pos = wxPyDefaultPosition, - const wxSize& size = wxPyDefaultSize, - long style = wxTR_HAS_BUTTONS, - const wxValidator& validator = wxPyDefaultValidator, - char* name = "wxTreeCtrl"); - - %pragma(python) addtomethod = "__init__:wxp._StdWindowCallbacks(self)" - - bool DeleteAllItems(); -#ifdef __WXMSW__ - bool DeleteItem(long item); -#else - void DeleteItem(long item); -#endif -#ifdef __WXMSW__ - wxTextCtrl* EditLabel(long item); - bool EnsureVisible(long item); - bool ExpandItem(long item, int action); - long GetChild(long item); -#endif - int GetCount(); -#ifdef __WXMSW__ - wxTextCtrl* GetEditControl(); - long GetFirstVisibleItem(); -#endif - wxImageList* GetImageList(int which = wxIMAGE_LIST_NORMAL); - int GetIndent(); - long GetItemData(long item); - - %addmethods { - %new wxTreeItem* GetItem() { - wxTreeItem* info = new wxTreeItem; - self->GetItem(*info); - return info; - } -#ifdef __WXMSW__ - %new wxRect* GetItemRect(long item, int textOnly = FALSE) { - wxRect* rect = new wxRect; - self->GetItemRect(item, *rect, textOnly); - return rect; - } -#endif - } - -#ifdef __WXMSW__ - int GetItemState(long item, long stateMask); -#endif - wxString GetItemText(long item); -#ifdef __WXMSW__ - long GetNextItem(long item, int code); - long GetNextVisibleItem(long item); -#endif - long GetParent(long item); - long GetRootItem(); - long GetSelection(); - long HitTest(const wxPoint& point, int& OUTPUT); // *** check this - long InsertItem(long parent, wxTreeItem& info, - long insertAfter = wxTREE_INSERT_LAST); - %name(InsertItemString) - long InsertItem(long parent, const wxString& label, - int image = -1, int selImage = -1, - long insertAfter = wxTREE_INSERT_LAST); - bool ItemHasChildren(long item); -#ifdef __WXMSW__ - bool ScrollTo(long item); -#endif - bool SelectItem(long item); - void SetIndent(int indent); - void SetImageList(wxImageList* imageList, int which = wxIMAGE_LIST_NORMAL); - bool SetItem(wxTreeItem& info); -#ifdef __WXMSW__ - bool SetItemImage(long item, int image, int selImage); -#else - void SetItemImage(long item, int image, int selImage); -#endif -#ifdef __WXMSW__ - bool SetItemState(long item, long state, long stateMask); -#endif - void SetItemText(long item, const wxString& text); - bool SetItemData(long item, long data); -#ifdef __WXMSW__ - bool SortChildren(long item); -#endif -}; - -#endif - - -//---------------------------------------------------------------------- - #ifdef __WXMSW__ class wxTreeItemId { public: @@ -396,7 +210,8 @@ public: wxTreeItemData(); ~wxTreeItemData(); - const wxTreeItemId& GetItemId(); + const wxTreeItemId& GetId(); + void SetId(const wxTreeItemId& id); }; @@ -568,6 +383,9 @@ public: ///////////////////////////////////////////////////////////////////////////// // // $Log$ +// Revision 1.7 1998/11/11 03:12:25 RD +// Additions for wxTreeCtrl +// // Revision 1.6 1998/10/20 06:43:55 RD // New wxTreeCtrl wrappers (untested) // some changes in helpers diff --git a/utils/wxPython/src/msw/controls2.cpp b/utils/wxPython/src/msw/controls2.cpp index 26fadf336d..6894a78887 100644 --- a/utils/wxPython/src/msw/controls2.cpp +++ b/utils/wxPython/src/msw/controls2.cpp @@ -2067,8 +2067,8 @@ static PyObject *_wrap_delete_wxTreeItemData(PyObject *self, PyObject *args) { return _resultobj; } -#define wxTreeItemData_GetItemId(_swigobj) (_swigobj->GetItemId()) -static PyObject *_wrap_wxTreeItemData_GetItemId(PyObject *self, PyObject *args) { +#define wxTreeItemData_GetId(_swigobj) (_swigobj->GetId()) +static PyObject *_wrap_wxTreeItemData_GetId(PyObject *self, PyObject *args) { PyObject * _resultobj; wxTreeItemId * _result; wxTreeItemData * _arg0; @@ -2076,21 +2076,50 @@ static PyObject *_wrap_wxTreeItemData_GetItemId(PyObject *self, PyObject *args) char _ptemp[128]; self = self; - if(!PyArg_ParseTuple(args,"s:wxTreeItemData_GetItemId",&_argc0)) + if(!PyArg_ParseTuple(args,"s:wxTreeItemData_GetId",&_argc0)) return NULL; if (_argc0) { if (SWIG_GetPtr(_argc0,(void **) &_arg0,"_wxTreeItemData_p")) { - PyErr_SetString(PyExc_TypeError,"Type error in argument 1 of wxTreeItemData_GetItemId. Expected _wxTreeItemData_p."); + PyErr_SetString(PyExc_TypeError,"Type error in argument 1 of wxTreeItemData_GetId. Expected _wxTreeItemData_p."); return NULL; } } - const wxTreeItemId & _result_ref = wxTreeItemData_GetItemId(_arg0); + const wxTreeItemId & _result_ref = wxTreeItemData_GetId(_arg0); _result = (wxTreeItemId *) &_result_ref; SWIG_MakePtr(_ptemp, (char *) _result,"_wxTreeItemId_p"); _resultobj = Py_BuildValue("s",_ptemp); return _resultobj; } +#define wxTreeItemData_SetId(_swigobj,_swigarg0) (_swigobj->SetId(_swigarg0)) +static PyObject *_wrap_wxTreeItemData_SetId(PyObject *self, PyObject *args) { + PyObject * _resultobj; + wxTreeItemData * _arg0; + wxTreeItemId * _arg1; + char * _argc0 = 0; + char * _argc1 = 0; + + self = self; + if(!PyArg_ParseTuple(args,"ss:wxTreeItemData_SetId",&_argc0,&_argc1)) + return NULL; + if (_argc0) { + if (SWIG_GetPtr(_argc0,(void **) &_arg0,"_wxTreeItemData_p")) { + PyErr_SetString(PyExc_TypeError,"Type error in argument 1 of wxTreeItemData_SetId. Expected _wxTreeItemData_p."); + return NULL; + } + } + if (_argc1) { + if (SWIG_GetPtr(_argc1,(void **) &_arg1,"_wxTreeItemId_p")) { + PyErr_SetString(PyExc_TypeError,"Type error in argument 2 of wxTreeItemData_SetId. Expected _wxTreeItemId_p."); + return NULL; + } + } + wxTreeItemData_SetId(_arg0,*_arg1); + Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + static void *SwigwxTreeEventTowxCommandEvent(void *ptr) { wxTreeEvent *src; wxCommandEvent *dest; @@ -3809,7 +3838,8 @@ static PyMethodDef controls2cMethods[] = { { "wxTreeEvent_GetPoint", _wrap_wxTreeEvent_GetPoint, 1 }, { "wxTreeEvent_GetOldItem", _wrap_wxTreeEvent_GetOldItem, 1 }, { "wxTreeEvent_GetItem", _wrap_wxTreeEvent_GetItem, 1 }, - { "wxTreeItemData_GetItemId", _wrap_wxTreeItemData_GetItemId, 1 }, + { "wxTreeItemData_SetId", _wrap_wxTreeItemData_SetId, 1 }, + { "wxTreeItemData_GetId", _wrap_wxTreeItemData_GetId, 1 }, { "delete_wxTreeItemData", _wrap_delete_wxTreeItemData, 1 }, { "new_wxTreeItemData", _wrap_new_wxTreeItemData, 1 }, { "wxTreeItemId_GetId", _wrap_wxTreeItemId_GetId, 1 }, diff --git a/utils/wxPython/src/msw/controls2.py b/utils/wxPython/src/msw/controls2.py index effb646046..cd0ef14dd3 100644 --- a/utils/wxPython/src/msw/controls2.py +++ b/utils/wxPython/src/msw/controls2.py @@ -348,10 +348,13 @@ class wxTreeItemDataPtr : def __del__(self): if self.thisown == 1 : controls2c.delete_wxTreeItemData(self.this) - def GetItemId(self): - val = controls2c.wxTreeItemData_GetItemId(self.this) + def GetId(self): + val = controls2c.wxTreeItemData_GetId(self.this) val = wxTreeItemIdPtr(val) return val + def SetId(self,arg0): + val = controls2c.wxTreeItemData_SetId(self.this,arg0.this) + return val def __repr__(self): return "" class wxTreeItemData(wxTreeItemDataPtr): diff --git a/utils/wxPython/src/msw/wxp.cpp b/utils/wxPython/src/msw/wxp.cpp index 60663c2506..3a508f0b77 100644 --- a/utils/wxPython/src/msw/wxp.cpp +++ b/utils/wxPython/src/msw/wxp.cpp @@ -33,8 +33,8 @@ * and things like that. * * $Log$ - * Revision 1.4 1998/11/03 09:22:50 RD - * New generated code + * Revision 1.5 1998/11/11 03:12:53 RD + * Additions for wxTreeCtrl * ************************************************************************/ @@ -1700,6 +1700,8 @@ SWIGEXPORT(void,initwxpc)() { PyDict_SetItemString(d,"wxEVT_COMMAND_TREE_SET_INFO", PyInt_FromLong((long) wxEVT_COMMAND_TREE_SET_INFO)); PyDict_SetItemString(d,"wxEVT_COMMAND_TREE_ITEM_EXPANDED", PyInt_FromLong((long) wxEVT_COMMAND_TREE_ITEM_EXPANDED)); PyDict_SetItemString(d,"wxEVT_COMMAND_TREE_ITEM_EXPANDING", PyInt_FromLong((long) wxEVT_COMMAND_TREE_ITEM_EXPANDING)); + PyDict_SetItemString(d,"wxEVT_COMMAND_TREE_ITEM_COLLAPSED", PyInt_FromLong((long) wxEVT_COMMAND_TREE_ITEM_COLLAPSED)); + PyDict_SetItemString(d,"wxEVT_COMMAND_TREE_ITEM_COLLAPSING", PyInt_FromLong((long) wxEVT_COMMAND_TREE_ITEM_COLLAPSING)); PyDict_SetItemString(d,"wxEVT_COMMAND_TREE_SEL_CHANGED", PyInt_FromLong((long) wxEVT_COMMAND_TREE_SEL_CHANGED)); PyDict_SetItemString(d,"wxEVT_COMMAND_TREE_SEL_CHANGING", PyInt_FromLong((long) wxEVT_COMMAND_TREE_SEL_CHANGING)); PyDict_SetItemString(d,"wxEVT_COMMAND_TREE_KEY_DOWN", PyInt_FromLong((long) wxEVT_COMMAND_TREE_KEY_DOWN)); diff --git a/utils/wxPython/src/msw/wxp.py b/utils/wxPython/src/msw/wxp.py index a72df8dd40..6a169c23dc 100644 --- a/utils/wxPython/src/msw/wxp.py +++ b/utils/wxPython/src/msw/wxp.py @@ -596,6 +596,8 @@ wxEVT_COMMAND_TREE_GET_INFO = wxpc.wxEVT_COMMAND_TREE_GET_INFO wxEVT_COMMAND_TREE_SET_INFO = wxpc.wxEVT_COMMAND_TREE_SET_INFO wxEVT_COMMAND_TREE_ITEM_EXPANDED = wxpc.wxEVT_COMMAND_TREE_ITEM_EXPANDED wxEVT_COMMAND_TREE_ITEM_EXPANDING = wxpc.wxEVT_COMMAND_TREE_ITEM_EXPANDING +wxEVT_COMMAND_TREE_ITEM_COLLAPSED = wxpc.wxEVT_COMMAND_TREE_ITEM_COLLAPSED +wxEVT_COMMAND_TREE_ITEM_COLLAPSING = wxpc.wxEVT_COMMAND_TREE_ITEM_COLLAPSING wxEVT_COMMAND_TREE_SEL_CHANGED = wxpc.wxEVT_COMMAND_TREE_SEL_CHANGED wxEVT_COMMAND_TREE_SEL_CHANGING = wxpc.wxEVT_COMMAND_TREE_SEL_CHANGING wxEVT_COMMAND_TREE_KEY_DOWN = wxpc.wxEVT_COMMAND_TREE_KEY_DOWN @@ -1113,8 +1115,8 @@ class wxApp(wxPyApp): #---------------------------------------------------------------------------- # # $Log$ -# Revision 1.4 1998/11/03 09:22:52 RD -# New generated code +# Revision 1.5 1998/11/11 03:12:55 RD +# Additions for wxTreeCtrl # # Revision 1.5 1998/10/20 07:38:02 RD # bug fix diff --git a/utils/wxPython/tests/test4.py b/utils/wxPython/tests/test4.py index 9e4afaaff4..86449c260b 100644 --- a/utils/wxPython/tests/test4.py +++ b/utils/wxPython/tests/test4.py @@ -231,7 +231,7 @@ class ColoredPanel(wxWindow): class TestNotebookWindow(wxFrame): - def __init__(self, parent): + def __init__(self, parent, log): wxFrame.__init__(self, parent, -1, 'Test wxNotebook', wxPyDefaultPosition, wxPyDefaultSize) @@ -239,10 +239,20 @@ class TestNotebookWindow(wxFrame): win = ColoredPanel(nb, wxBLUE) nb.AddPage(win, "Blue") - st = wxStaticText(win, -1, "You can put any type of window here!", wxPoint(10, 10)) + st = wxStaticText(win, -1, + "You can put nearly any type of window here!", + wxPoint(10, 10)) + st.SetForegroundColour(wxWHITE) + st.SetBackgroundColour(wxBLUE) + st = wxStaticText(win, -1, + "Check the next tab for an example...", + wxPoint(10, 30)) st.SetForegroundColour(wxWHITE) st.SetBackgroundColour(wxBLUE) + win = TestTreeCtrlPanel(nb, log) + nb.AddPage(win, "TreeCtrl") + win = ColoredPanel(nb, wxRED) nb.AddPage(win, "Red") @@ -266,7 +276,7 @@ class TestNotebookWindow(wxFrame): nb.SetSelection(0) - self.SetSize(wxSize(300, 300)) # force a redraw so the notebook will draw + self.SetSize(wxSize(350, 300)) # force a redraw so the notebook will draw def OnCloseWindow(self, event): @@ -418,6 +428,56 @@ class TestToolBar(wxFrame): self.log.WriteText("tool %s right-clicked\n" % event.GetId()) +#--------------------------------------------------------------------------- + +class TestTreeCtrlPanel(wxPanel): + def __init__(self, parent, log): + wxPanel.__init__(self, parent, -1) + + self.log = log + tID = 1101 + + self.tree = wxTreeCtrl(self, tID) + root = self.tree.AddRoot("The Root Item") + for x in range(10): + child = self.tree.AppendItem(root, "Item %d" % x) + for y in range(5): + last = self.tree.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y))) + + self.tree.Expand(root) + EVT_TREE_ITEM_EXPANDED (self, tID, self.OnItemExpanded) + EVT_TREE_ITEM_COLLAPSED (self, tID, self.OnItemCollapsed) + EVT_TREE_SEL_CHANGED (self, tID, self.OnSelChanged) + + + def OnSize(self, event): + w,h = self.GetClientSize() + self.tree.SetDimensions(0, 0, w, h) + + + def OnItemExpanded(self, event): + item = event.GetItem() + self.log.WriteText("OnItemExpanded: %s\n" % self.tree.GetItemText(item)) + + def OnItemCollapsed(self, event): + item = event.GetItem() + self.log.WriteText("OnItemCollapsed: %s\n" % self.tree.GetItemText(item)) + + def OnSelChanged(self, event): + item = event.GetItem() + self.log.WriteText("OnSelChanged: %s\n" % self.tree.GetItemText(item)) + + + + +class TestTreeCtrl(wxFrame): + def __init__(self, parent, log): + wxFrame.__init__(self, parent, -1, 'Test TreeCtrl', + wxPyDefaultPosition, wxSize(250, 300)) + + p = TestTreeCtrlPanel(self, log) + + #--------------------------------------------------------------------------- #--------------------------------------------------------------------------- #--------------------------------------------------------------------------- @@ -526,6 +586,10 @@ class AppFrame(wxFrame): menu.Append(mID, '&ToolBar') EVT_MENU(self, mID, self.OnTestToolBar) + mID = NewId() + menu.Append(mID, 'T&ree Control') + EVT_MENU(self, mID, self.OnTestTreeCtrl) + return menu @@ -653,7 +717,7 @@ class AppFrame(wxFrame): def OnTestNotebook(self, event): - win = TestNotebookWindow(self) + win = TestNotebookWindow(self, self) win.Show(true) def OnTestSplitter(self, event): @@ -668,6 +732,10 @@ class AppFrame(wxFrame): win = TestToolBar(self, self) win.Show(true) + def OnTestTreeCtrl(self, event): + win = TestTreeCtrl(self, self) + win.Show(true) + #--------------------------------------------------------------------------- @@ -717,6 +785,9 @@ if __name__ == '__main__': #---------------------------------------------------------------------------- # # $Log$ +# Revision 1.7 1998/11/11 03:13:19 RD +# Additions for wxTreeCtrl +# # Revision 1.6 1998/10/20 06:45:33 RD # New wxTreeCtrl wrappers (untested) # some changes in helpers -- 2.45.2