Commit c237838d authored by jean-pierre charras's avatar jean-pierre charras

python scripting: refinement for UTF8 class (from Miguel Ángel Ajo Pelayo) add...

python scripting: refinement for UTF8 class (from Miguel Ángel Ajo Pelayo) add __str__  method, usefull to print a UTF8 string.
Kicad manager: fix issues in file watcher: changes (adding/removing files)  in project folder not seen by Kicad manager (perhaps due to changes in internal wxWidgets code between 2.9.5 and 3.0).
parent 959b63ba
......@@ -76,6 +76,8 @@ TREEPROJECTFILES::TREEPROJECTFILES( TREE_PROJECT_FRAME* parent ) :
m_ImageList->Add( KiBitmap( post_drill_xpm ) ); // TREE_DRILL
m_ImageList->Add( KiBitmap( svg_file_xpm ) ); // TREE_SVG
m_ImageList->Add( KiBitmap( pagelayout_load_default_xpm ) );// TREE_PAGE_LAYOUT_DESCR
m_ImageList->Add( KiBitmap( module_xpm ) ); // TREE_FOOTPRINT_FILE
m_ImageList->Add( KiBitmap( library_xpm ) ); // TREE_SCHEMATIC_LIBFILE
SetImageList( m_ImageList );
}
......
......@@ -54,7 +54,6 @@ class TREE_PROJECT_FRAME;
//
// When changing this enum please verify (and perhaps update)
// TREE_PROJECT_FRAME::GetFileExt(),
// TREE_PROJECT_FRAME::GetFileExt()
// s_AllowedExtensionsToList[]
enum TreeFileType {
......@@ -74,6 +73,8 @@ enum TreeFileType {
TREE_DRILL, // Excellon drill file (.drl)
TREE_SVG, // SVG file (.svg)
TREE_PAGE_LAYOUT_DESCR, // Page layout and title block descr file (.kicad_wks)
TREE_FOOTPRINT_FILE, // footprint file (.kicad_mod)
TREE_SCHEMATIC_LIBFILE, // schematic library file (.lib)
TREE_MAX
};
......
......@@ -65,9 +65,11 @@ static const wxChar* s_allowedExtensionsToList[] =
wxT( "^.*\\.pro$" ),
wxT( "^.*\\.pdf$" ),
wxT( "^[^$].*\\.brd$" ), // Legacy Pcbnew files
wxT( "^[^$].*\\.kicad_pcb$" ), // S format Pcbnew files
wxT( "^[^$].*\\.kicad_pcb$" ), // S format Pcbnew board files
wxT( "^[^$].*\\.kicad_wks$" ), // S format kicad page layout descr files
wxT( "^[^$].*\\.kicad_mod$" ), // S format kicad footprint files, currently not listed
wxT( "^.*\\.net$" ),
wxT( "^.*\\.lib$" ), // Schematic library file
wxT( "^.*\\.txt$" ),
wxT( "^.*\\.pho$" ), // Gerber file (Old Kicad extension)
wxT( "^.*\\.gbr$" ), // Gerber file
......@@ -75,7 +77,6 @@ static const wxChar* s_allowedExtensionsToList[] =
wxT( "^.*\\.gt[alops]$" ), // Gerber front (or top) layer file
wxT( "^.*\\.g[0-9]{1,2}$" ), // Gerber inner layer file
wxT( "^.*\\.odt$" ),
wxT( "^.*\\.sxw$" ),
wxT( "^.*\\.htm$" ),
wxT( "^.*\\.html$" ),
wxT( "^.*\\.rpt$" ), // Report files
......@@ -196,27 +197,33 @@ void TREE_PROJECT_FRAME::OnCreateNewDirectory( wxCommandEvent& event )
root = m_TreeProject->GetSelection();
}
wxString prj_dir = wxPathOnly( m_Parent->GetProjectFileName() );
// Ask for the new sub directory name
wxString curr_dir = treeData->GetDir();
// Make the current subdir relative to the current path:
if( !curr_dir.IsEmpty() ) // A subdir is selected
{
curr_dir += wxFileName::GetPathSeparator();
curr_dir += wxT( "dummy" );
wxFileName fn( curr_dir );
fn.MakeRelativeTo();
curr_dir = fn.GetPath() + wxFileName::GetPathSeparator();
// Make this subdir name relative to the current path.
// It will be more easy to read by the user, in the next dialog
wxFileName fn;
fn.AssignDir( curr_dir );
fn.MakeRelativeTo( prj_dir );
curr_dir = fn.GetPath();
if( !curr_dir.IsEmpty() )
curr_dir += wxFileName::GetPathSeparator();
}
wxString msg = wxString::Format( _( "Current working directory:\n%s" ), GetChars( wxGetCwd() ) );
wxString msg = wxString::Format( _( "Current project directory:\n%s" ), GetChars( prj_dir ) );
wxString subdir = wxGetTextFromUser( msg, _( "Create New Directory" ), curr_dir );
if( subdir.IsEmpty() )
return;
if( wxMkdir( subdir ) )
wxString full_dirname = prj_dir + wxFileName::GetPathSeparator() + subdir;
if( wxMkdir( full_dirname ) )
{
#ifndef KICAD_USE_FILES_WATCHER
AddItemToTreeProject( subdir, root );
......@@ -287,6 +294,14 @@ wxString TREE_PROJECT_FRAME::GetFileExt( TreeFileType type )
ext = PageLayoutDescrFileExtension;
break;
case TREE_FOOTPRINT_FILE:
ext = KiCadFootprintFileExtension;
break;
case TREE_SCHEMATIC_LIBFILE:
ext = SchematicLibraryFileExtension;
break;
default: // Eliminates unnecessary GCC warning.
break;
}
......@@ -357,7 +372,15 @@ wxString TREE_PROJECT_FRAME::GetFileWildcard( TreeFileType type )
ext = PageLayoutDescrFileWildcard;
break;
default: // Eliminates unnecessary GCC warning.
case TREE_FOOTPRINT_FILE:
ext = KiCadFootprintLibFileWildcard;
break;
case TREE_SCHEMATIC_LIBFILE:
ext = SchematicLibraryFileWildcard;
break;
default: // Eliminates unnecessary GCC warning.
break;
}
......@@ -536,7 +559,7 @@ bool TREE_PROJECT_FRAME::AddItemToTreeProject( const wxString& aName,
{
do // Add name in tree, but do not recurse
{
wxString path = aName + wxCONFIG_PATH_SEPARATOR + dir_filename;
wxString path = aName + wxFileName::GetPathSeparator() + dir_filename;
AddItemToTreeProject( path, cellule, false );
} while( dir.GetNext( &dir_filename ) );
}
......@@ -603,8 +626,8 @@ void TREE_PROJECT_FRAME::ReCreateTreePrj()
{
if( filename != fn.GetFullName() )
{
wxString n = dir.GetName() + wxCONFIG_PATH_SEPARATOR + filename;
AddItemToTreeProject( n, m_root );
wxString name = dir.GetName() + wxFileName::GetPathSeparator() + filename;
AddItemToTreeProject( name, m_root );
}
cont = dir.GetNext( &filename );
......@@ -791,8 +814,8 @@ void TREE_PROJECT_FRAME::OnExpand( wxTreeEvent& Event )
{
do // Add name to tree item, but do not recurse in subdirs:
{
wxString n = fileName + wxCONFIG_PATH_SEPARATOR + dir_filename;
AddItemToTreeProject( n, kid, false );
wxString name = fileName + wxFileName::GetPathSeparator() + dir_filename;
AddItemToTreeProject( name, kid, false );
} while( dir.GetNext( &dir_filename ) );
}
......@@ -830,9 +853,11 @@ TREEPROJECT_ITEM* TREE_PROJECT_FRAME::GetItemIdData( wxTreeItemId aId )
wxTreeItemId TREE_PROJECT_FRAME::findSubdirTreeItem( const wxString& aSubDir )
{
wxString prj_dir = wxPathOnly( m_Parent->GetProjectFileName() );
// If the subdir is the current working directory, return m_root
// in main list:
if( wxGetCwd() == aSubDir )
if( prj_dir == aSubDir )
return m_root;
// The subdir is in the main tree or in a subdir: Locate it
......@@ -905,8 +930,8 @@ void TREE_PROJECT_FRAME::OnFileSystemEvent( wxFileSystemWatcherEvent& event )
return;
}
wxTreeItemId root_id = findSubdirTreeItem( subdir );
if( !root_id.IsOk() )
return;
......@@ -976,12 +1001,15 @@ void TREE_PROJECT_FRAME::FileWatcherReset()
// moreover, under wxWidgets 2.9.4, AddTree does not work properly.
// We can see wxString under a debugger, not a wxFileName
wxString pro_dir = wxPathOnly( m_Parent->GetProjectFileName() );
wxString prj_dir = wxPathOnly( m_Parent->GetProjectFileName() );
wxFileName fn;
fn.AssignDir( prj_dir );
fn.DontFollowLink();
#ifdef __WINDOWS__
m_watcher->AddTree( pro_dir );
m_watcher->AddTree( fn );
#else
m_watcher->Add( pro_dir );
m_watcher->Add( fn );
// Add subdirs
wxTreeItemIdValue cookie;
......@@ -1017,7 +1045,8 @@ void TREE_PROJECT_FRAME::FileWatcherReset()
if( wxFileName::IsDirReadable( path ) ) // linux whines about watching protected dir
{
m_watcher->Add( path );
fn.AssignDir( path );
m_watcher->Add( fn );
// if kid is a subdir, push in list to explore it later
if( itemData->IsPopulated() && m_TreeProject->GetChildrenCount( kid ) )
......
......@@ -132,8 +132,19 @@
%pythoncode
{
/*
* Get the char buffer of the UTF8 string
*/
def GetChars(self):
return self.Cast_to_CChar()
/*
* Convert the UTF8 string to a python string
* Same as GetChars(), but more easy to use in print command
*/
def __str__(self):
return self.GetChars()
}
}
......@@ -65,7 +65,7 @@ footprint = plugin.FootprintLoad( lib_path2, 'footprint' )
fpid = footprint.GetFPID()
fpid.SetLibNickname( UTF8( 'mylib' ) )
name = fpid.Format().GetChars()
name = fpid.Format().GetChars() # example to get the UTF8 char buffer
# Always after a FootprintLoad() the internal name should match the one used to load it.
print( "Internal name should be 'footprint': '%s'" % name )
......@@ -76,10 +76,10 @@ footprint = plugin.FootprintLoad( lib_path1, 'mine' )
fpid = footprint.GetFPID()
fpid.SetLibNickname( UTF8( 'other_mylib' ) )
name = fpid.Format().GetChars()
# Always after a FootprintLoad() the internal name should match the one used to load it.
print( "Internal name should be 'mine': '%s'" % name )
# Example to print an UTF8 string
print( "Internal name should be 'mine': '%s'" % fpid.Format() )
# As of 3-Dec-2013 this test is passed by KICAD_PLUGIN and Wayne is owed an atta boy!
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment