← Back to team overview

kicad-developers team mailing list archive

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 | 40 ++++++++++++++++++++++++++++++++++++----
3 files changed, 42 insertions(+), 4 deletions(-)


 --------------060205010608070002020901 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 | 40 ++++++++++++++++++++++++++++++++++++----
3 files changed, 42 insertions(+), 4 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:22:12.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 */
{
@@ -662,11 +673,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 +843,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 - 2; 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)
 --------------060205010608070002020901--