From 636e060c99c499169095a526614e9e3eb789b2ab Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 28 Dec 2016 10:26:01 +0100 Subject: [PATCH] A few enhancements from a larger patch, not yet committed, for footprint wizards --- .../dialogs/dialog_footprint_wizard_list.cpp | 25 ++++++++++++---- pcbnew/swig/python_scripting.cpp | 30 ++++++++++++++++++- pcbnew/swig/python_scripting.h | 26 ++++++++++++++++ pcbnew/swig/units.i | 26 ++++++++++++---- scripting/kicadplugins.i | 23 +++++++++----- 5 files changed, 110 insertions(+), 20 deletions(-) diff --git a/pcbnew/dialogs/dialog_footprint_wizard_list.cpp b/pcbnew/dialogs/dialog_footprint_wizard_list.cpp index 8c49d6b089..ef43ba266d 100644 --- a/pcbnew/dialogs/dialog_footprint_wizard_list.cpp +++ b/pcbnew/dialogs/dialog_footprint_wizard_list.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012-2014 Miguel Angel Ajo - * Copyright (C) 1992-2014 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -33,9 +33,14 @@ #include #include #include +#include + +enum FPGeneratorRowNames +{ + FP_GEN_ROW_NAME = 0, + FP_GEN_ROW_DESCR, +}; -#define ROW_NAME 0 -#define ROW_DESCR 1 #define FPWIZARTDLIST_HEIGHT_KEY wxT( "FpWizardListHeight" ) #define FPWIZARTDLIST_WIDTH_KEY wxT( "FpWizardListWidth" ) @@ -64,11 +69,21 @@ DIALOG_FOOTPRINT_WIZARD_LIST::DIALOG_FOOTPRINT_WIZARD_LIST( wxWindow* aParent ) wxString description = wizard->GetDescription(); wxString image = wizard->GetImage(); - m_footprintGeneratorsGrid->SetCellValue( i, ROW_NAME, name ); - m_footprintGeneratorsGrid->SetCellValue( i, ROW_DESCR, description ); + m_footprintGeneratorsGrid->SetCellValue( i, FP_GEN_ROW_NAME, name ); + m_footprintGeneratorsGrid->SetCellValue( i, FP_GEN_ROW_DESCR, description ); } + m_footprintGeneratorsGrid->AutoSizeColumns(); + + // Auto-expand the description column + int width = m_footprintGeneratorsGrid->GetClientSize().GetWidth() - + m_footprintGeneratorsGrid->GetRowLabelSize() - + m_footprintGeneratorsGrid->GetColSize( FP_GEN_ROW_NAME ); + + if ( width > m_footprintGeneratorsGrid->GetColMinimalAcceptableWidth() ) + m_footprintGeneratorsGrid->SetColSize( FP_GEN_ROW_DESCR, width ); + // Select the first row m_footprintGeneratorsGrid->ClearSelection(); m_footprintGeneratorsGrid->SelectRow( 0, false ); diff --git a/pcbnew/swig/python_scripting.cpp b/pcbnew/swig/python_scripting.cpp index 059ceef6b8..814191b713 100644 --- a/pcbnew/swig/python_scripting.cpp +++ b/pcbnew/swig/python_scripting.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012 NBEE Embedded Systems, Miguel Angel Ajo - * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -37,6 +37,8 @@ #include #include +#include + /* init functions defined by swig */ extern "C" void init_kicad( void ); @@ -359,3 +361,29 @@ wxString PyErrStringWithTraceback() return err; } + +/** + * Find the Python scripting path + */ +wxString PyScriptingPath() +{ + wxString path; + + //TODO should this be a user configurable variable eg KISCRIPT ? +#if defined( __WXMAC__ ) + path = GetOSXKicadDataDir() + wxT( "/scripting" ); +#else + path = Pgm().GetExecutablePath() + wxT( "../share/kicad/scripting" ); +#endif + + wxFileName scriptPath( path ); + + scriptPath.MakeAbsolute(); + + return scriptPath.GetFullPath(); +} + +wxString PyPluginsPath() +{ + return PyScriptingPath() + wxFileName::GetPathSeparator() + "plugins"; +} diff --git a/pcbnew/swig/python_scripting.h b/pcbnew/swig/python_scripting.h index ca25de435d..d14146f678 100644 --- a/pcbnew/swig/python_scripting.h +++ b/pcbnew/swig/python_scripting.h @@ -1,3 +1,26 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + #ifndef __PYTHON_SCRIPTING_H #define __PYTHON_SCRIPTING_H @@ -59,4 +82,7 @@ public: wxArrayString PyArrayStringToWx( PyObject* arr ); wxString PyErrStringWithTraceback(); +wxString PyScriptingPath(); +wxString PyPluginsPath(); + #endif // __PYTHON_SCRIPTING_H diff --git a/pcbnew/swig/units.i b/pcbnew/swig/units.i index bae5edcbe7..441eacac81 100644 --- a/pcbnew/swig/units.i +++ b/pcbnew/swig/units.i @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012 NBEE Embedded Systems, Miguel Angel Ajo - * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -55,11 +55,25 @@ elif type(mils) in [wxPoint,wxSize]: return tuple(map(FromMils,mils)) - def wxSizeMM(mmx,mmy): return wxSize(FromMM(mmx),FromMM(mmy)) - def wxSizeMils(mmx,mmy): return wxSize(FromMils(mmx),FromMils(mmy)) + def PutOnGridMM(value, gridSizeMM): + thresh = FromMM(gridSizeMM) + return round(value/thresh)*thresh - def wxPointMM(mmx,mmy): return wxPoint(FromMM(mmx),FromMM(mmy)) - def wxPointMils(mmx,mmy): return wxPoint(FromMils(mmx),FromMils(mmy)) + def PutOnGridMils(value, gridSizeMils): + thresh = FromMils(gridSizeMils) + return round(value/thresh)*thresh + + def wxSizeMM(mmx,mmy): + return wxSize(FromMM(mmx),FromMM(mmy)) + + def wxSizeMils(mmx,mmy): + return wxSize(FromMils(mmx),FromMils(mmy)) + + def wxPointMM(mmx,mmy): + return wxPoint(FromMM(mmx),FromMM(mmy)) + + def wxPointMils(mmx,mmy): + return wxPoint(FromMils(mmx),FromMils(mmy)) def wxRectMM(x,y,wx,wy): x = int(FromMM(x)) @@ -72,6 +86,6 @@ x = int(FromMils(x)) y = int(FromMils(y)) wx = int(FromMils(wx)) - wy = int (FromMils(wy)) + wy = int(FromMils(wy)) return wxRect(x,y,wx,wy) %} diff --git a/scripting/kicadplugins.i b/scripting/kicadplugins.i index 918896d15d..754e9ba778 100644 --- a/scripting/kicadplugins.i +++ b/scripting/kicadplugins.i @@ -119,19 +119,23 @@ def LoadPlugins(bundlepath=None): if bundlepath: plugin_directories.append(bundlepath) plugin_directories.append(os.path.join(bundlepath, 'plugins')) + plugin_directories.append(os.path.join(bundlepath, 'plugins', 'wizards')) if kicad_path: plugin_directories.append(os.path.join(kicad_path, 'scripting')) plugin_directories.append(os.path.join(kicad_path, 'scripting', 'plugins')) + plugin_directories.append(os.path.join(kicad_path, 'scripting', 'plugins', 'wizards')) if config_path: plugin_directories.append(os.path.join(config_path, 'scripting')) plugin_directories.append(os.path.join(config_path, 'scripting', 'plugins')) + plugin_directories.append(os.path.join(config_path, 'scripting', 'plugins', 'wizards')) if sys.platform.startswith('linux'): plugin_directories.append(os.environ['HOME']+'/.kicad_plugins/') plugin_directories.append(os.environ['HOME']+'/.kicad/scripting/') plugin_directories.append(os.environ['HOME']+'/.kicad/scripting/plugins/') + plugin_directories.append(os.environ['HOME']+'/.kicad/scripting/plugins/wizards') for plugins_dir in plugin_directories: if not os.path.isdir(plugins_dir): @@ -146,15 +150,18 @@ def LoadPlugins(bundlepath=None): if module == '__init__.py' or module[-3:] != '.py': continue - mod = __import__(module[:-3], locals(), globals()) + try: # If there is an error loading the script, skip it + mod = __import__(module[:-3], locals(), globals()) - module_filename = plugins_dir+"/"+module - mtime = os.path.getmtime(module_filename) - if hasattr(mod,'register'): - KICAD_PLUGINS[module]={"filename":module_filename, - "modification_time":mtime, - "object":mod.register(), - "module":mod} + module_filename = plugins_dir+"/"+module + mtime = os.path.getmtime(module_filename) + if hasattr(mod,'register'): + KICAD_PLUGINS[module]={"filename":module_filename, + "modification_time":mtime, + "object":mod.register(), + "module":mod} + except: + pass