kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #00269
PATCH: Icon composition for project editor
-
To:
kicad-devel@xxxxxxxxxxxxxxx
-
From:
Florian Delizy <fdy@...>
-
Date:
Mon, 07 May 2007 16:37:53 +0200
-
User-agent:
Icedove 1.5.0.10 (X11/20070328)
(resend, with bugfix, I sent this one a bit early ...)
This patch allow new set of icons to be created from python and to be
set on each file.
int kicad.TreeWindow.AddState( bitmap )
kicad.TreeItemData.SetState( int )
the bitmap is superposed on existing icons, and a new set of icon is
created.
This will be useful for instance to create a SVN binding changing icons
regarding the subversion state (like tortoise SVN)
---
kicad/kicad.cpp | 2 ++
kicad/kicad.h | 4 ++++
kicad/treeprj.cpp | 41 ++++++++++++++++++++++++++++++++++++-----
3 files changed, 42 insertions(+), 5 deletions(-)
--------------020002000005060107030005 Content-Type: text/x-patch;
name="kicad-file-icon-composition.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="kicad-file-icon-composition.patch"
Subject: PATCH: Icon composition for project editor
This patch allow new set of icons to be created from python and to be set on each file.
int kicad.TreeWindow.AddState( bitmap )
kicad.TreeItemData.SetState( int )
the bitmap is superposed on existing icons, and a new set of icon is created.
This will be useful for instance to create a SVN binding changing icons regarding the subversion state (like tortoise SVN)
---
kicad/kicad.cpp | 2 ++
kicad/kicad.h | 4 ++++
kicad/treeprj.cpp | 41 ++++++++++++++++++++++++++++++++++++-----
3 files changed, 42 insertions(+), 5 deletions(-)
Index: kicad-dev/kicad/kicad.cpp
===================================================================
--- kicad-dev.orig/kicad/kicad.cpp 2007-05-07 14:02:42.000000000 +0200
+++ kicad-dev/kicad/kicad.cpp 2007-05-07 14:05:01.000000000 +0200
@@ -130,6 +130,7 @@
.def( "GetId", &TreePrjItemData::GetIdPy )
.def( "GetMenu", &TreePrjItemData::GetMenuPy )
// Item control
+ .def( "SetState", &TreePrjItemData::SetState )
.def( "Rename", &TreePrjItemData::RenamePy )
.def( "Move", &TreePrjItemData::Move )
.def( "Delete", &TreePrjItemData::Delete )
@@ -162,6 +163,7 @@
.def( "GetFilters", &WinEDA_PrjFrame::GetFilters, return_value_policy < copy_const_reference >() )
.def( "GetCurrentMenu", &WinEDA_PrjFrame::GetCurrentMenu )
// Project tree control
+ .def( "AddState", &WinEDA_PrjFrame::AddStatePy )
.def( "GetTreeCtrl", &WinEDA_PrjFrame::GetTreeCtrl )
.def( "GetItemData", &WinEDA_PrjFrame::GetItemData, return_value_policy < reference_existing_object >() )
.def( "FindItemData", &WinEDA_PrjFrame::FindItemData, return_value_policy < reference_existing_object >() )
Index: kicad-dev/kicad/kicad.h
===================================================================
--- kicad-dev.orig/kicad/kicad.h 2007-05-07 13:37:53.000000000 +0200
+++ kicad-dev/kicad/kicad.h 2007-05-07 14:06:22.000000000 +0200
@@ -118,6 +118,7 @@
wxString m_FileName;
wxTreeCtrl * m_Parent;
wxMenu m_fileMenu;
+ int m_State;
public:
@@ -127,6 +128,7 @@
, m_FileName( src.m_FileName )
, m_Parent( src.m_Parent )
{
+ SetState( src.m_State );
}
TreePrjItemData(enum TreeFileType type, const wxString & data, wxTreeCtrl * parent);
@@ -143,6 +145,7 @@
void Activate();
const wxMenu * GetMenu() { return &m_fileMenu; }
+ void SetState( int state );
#ifdef KICAD_PYTHON
boost::python::object GetFileNamePy() const;
@@ -228,6 +231,7 @@
TreePrjItemData * FindItemData( const boost::python::str & name );
boost::python::object GetCurrentMenu();
+ int AddStatePy( boost::python::object & bitmap );
#endif
Index: kicad-dev/kicad/treeprj.cpp
===================================================================
--- kicad-dev.orig/kicad/treeprj.cpp 2007-05-07 13:38:44.000000000 +0200
+++ kicad-dev/kicad/treeprj.cpp 2007-05-07 16:36:22.000000000 +0200
@@ -55,6 +55,17 @@
}
#endif
+void TreePrjItemData::SetState( int state )
+// Set the state used in the icon list
+{
+ wxImageList* imglist = m_Parent->GetImageList();
+ if ( !imglist || state < 0 || state >= imglist->GetImageCount() / ( TREE_MAX - 2 ) ) return;
+ m_State = state;
+ int imgid = m_Type - 1 + state * ( TREE_MAX - 1 );
+ m_Parent->SetItemImage( GetId(), imgid );
+ m_Parent->SetItemImage( GetId(), imgid, wxTreeItemIcon_Selected );
+}
+
wxString TreePrjItemData::GetDir() const
/* Get the directory containing the file */
{
@@ -365,7 +376,6 @@
TreePrjItemData * data = dynamic_cast< TreePrjItemData *>( m_TreeProject->GetItemData( child ) );
if ( data )
{
- std::cout << " ( " << data->GetFileName().fn_str() << ")" << std::endl;
if ( data->GetFileName() == filename ) return data;
if ( m_TreeProject->ItemHasChildren( child ) ) reserve->push_back( child );
}
@@ -662,11 +672,10 @@
wxString file = wxFileNameFromPath( name );
cellule = m_TreeProject->AppendItem( root, file );
- m_TreeProject->SetItemData( cellule, new TreePrjItemData( (enum TreeFileType) type, name, m_TreeProject ) );
+ TreePrjItemData * data = new TreePrjItemData( (enum TreeFileType) type, name, m_TreeProject );
+ m_TreeProject->SetItemData( cellule, data );
m_TreeProject->SetItemFont( cellule, *g_StdFont );
- m_TreeProject->SetItemImage( cellule, type - 1);
- m_TreeProject->SetItemImage( cellule, type - 1, wxTreeItemIcon_Selected );
-
+ data->SetState(0);
#ifdef KICAD_PYTHON
PyHandler::GetInstance()->TriggerEvent( wxT("kicad::TreeAddFile"), PyHandler::Convert( name ) );
#endif
@@ -833,6 +842,28 @@
PyHandler::GetInstance()->TriggerEvent( wxT("kicad::RunScript"), PyHandler::Convert( FullFileName ) );
PyHandler::GetInstance()->RunScript( FullFileName );
}
+
+int WinEDA_PrjFrame::AddStatePy( object & bitmap )
+// Add a state to the image list ...
+{
+ wxBitmap * image;
+ bool success = wxPyConvertSwigPtr( bitmap.ptr(), (void**)&image, _T("wxBitmap"));
+ if ( !success ) return -1;
+
+ wxImageList * list = m_TreeProject->GetImageList();
+ int ret = list->GetImageCount() / ( TREE_MAX - 2 );
+
+ for ( int i = 0; i < TREE_MAX - 1; i ++ )
+ {
+ wxBitmap composed ( list->GetBitmap( i ) );
+ wxMemoryDC dc;
+ dc.SelectObject( composed );
+ dc.DrawBitmap( *image, 0, 0, true );
+ list->Add( composed );
+ }
+ return ret;
+}
+
#endif
void WinEDA_PrjFrame::OnRenameAsk(wxTreeEvent & event)
--------------020002000005060107030005--