Footprint Wizard not updated when script edited

Bug #1648102 reported by Fredrik Jonsson
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
KiCad
Fix Released
Undecided
jean-pierre charras

Bug Description

After posting the question on the forum I was recommended to report it on the bugtracker instead.

I am writing a Python script to generate footprints using the footprint wizard. The script works, and it is indeed a powerful tool. However, the scripts seems to be loaded only loaded once when KiCad is started. If I make any modification to the script after KiCAD is launched, the function in the Footprint Wizard do not change. This makes it very time consuming to debug the script since I have to restart KiCad every time I edit the script.

Is there a way to force KiCAD to reload the scripts each time they are launched? Preferably I would also be able to set custom footprint wizard path so I don't have to mix my own scripts with the installation, but I have not managed to find information how this can be done.

I am running version 4.0.2-stable, release build
wxWidgets 3.0.2 Unicode and Boost 1.57.0
Platform: Windows 7 (build 7601, Service Pack1), 64-bit edition

Eldar Khayrullin (eldar)
tags: added: footprint pcbnew python wizard
tags: added: script
Revision history for this message
xzcvczx (xzcvczx) wrote :

based on a quick google i am not even sure if this is possible as python is only being loaded once, you might be able to try the sugggestions in this stackoverflow link

http://stackoverflow.com/questions/1517038/python-refresh-reload

Revision history for this message
Fredrik Jonsson (fredrik-jonsson) wrote :

Thanks for the suggestion!
While it didn't not solve the problem, using reload() made it possible to create a workaround.

By placing the wizard implementation in a separate module and creating a wrapper function that reloads this module, the implementation can be edited without the need to restart KiCad. While this may be highly inefficient, I think this is acceptable since the reload is only used during development of the wizard. Once the wizard is working the wrapper may still be kept but with the reload() function commented out.

I attach the wrapper code below. The wrapper is sent as an argument to the __init__ function, so the wrapper can be stored and accessed in the wizard implementation.

The workaround is not perfect however, the parameter list is not updated since these are stored in the wrapper.

A solution to the problem would be to compare the time-stamps of the .py and .pyc files and reload the modules if .py is newer. This would better be placed within KiCad module loader itself. But this may not be a bug but should be added to the feature wish-list for future releases.

FootprintWizardWrapper.py
-------------------------
import HelpfulFootprintWizardPlugin as HFPW
import sys
sys.path.append('''C:/proj/modules/KiCAD/scripts''')
import wizard_implementation

class WizardWrapper(HFPW.HelpfulFootprintWizardPlugin):
 def GetWizard(self):
  reload(wizard_implementation)
  return wizard_implementation.WizardImplementation(self)

 # Wrapper functions
 def GetName(self):
  return self.GetWizard().GetName()

 def GetDescription(self):
  return self.GetWizard().GetDescription()

 def GenerateParameterList(self):
  self.GetWizard().GenerateParameterList()

 def CheckParameters(self):
  self.GetWizard().CheckParameters()

 def GetValue(self):
  return self.GetWizard().GetValue()

 def BuildThisFootprint(self):
  self.GetWizard().BuildThisFootprint()

WizardWrapper().register()

WizardImplementation.py
-----------------------
import pcbnew
import HelpfulFootprintWizardPlugin as HFPW

class WizardImplementation:
 def __init__(self, wizard_wrapper):
  self.ww = wizard_wrapper

 def GetName(self):
  return "My Wizard"

 def GenerateParameterList(self):
  self.ww.AddParam("Pads", "test", self.ww.uNatural, 17)
etc.

Revision history for this message
Nick Østergaard (nickoe) wrote :

I think this is addressed in the master branch, i.e. the nightlies. Could you test it?

Revision history for this message
Fredrik Jonsson (fredrik-jonsson) wrote :

Finally found time to test, have tried on Nightly Build (2017-01-24 revision 0b6147e)-makepkg, release build.

The new feature showing trace and which modules have problem loading is very helpful. However, the scripts do not reload automatically on my computer. Pressing the "Update Python Modules" cause KiCad to freeze completely. I can post trace-log if needed.

Revision history for this message
jean-pierre charras (jp-charras) wrote :

Python scripts are updated only on request.
There are other scripts than footprint wizards, and only devs usually modify these scripts.
So I prefer update these scripts only on request, not silently, in the corresponding editors (not only in the footprint wizard manager frame).

Updating python scripts does not freeze Pcbnew on my computer (W7 32 bits and Linux Ubuntu 64 bits).
A log trace from gdb can be useful.
However it is useful only if Kicad is compiled in debug mode.

Revision history for this message
Fredrik Jonsson (fredrik-jonsson) wrote :

Tried on Ubuntu, it crash also here. Get the following message in the terminal: (kicad:59766):Gdk-CRITICAL **: IA__gdk_window_process_updates: assertion 'GDK_IS_WINDOW (window)' failed

Revision history for this message
jean-pierre charras (jp-charras) wrote :

Got it:
It happens (at least on Windows) only if wxPython is enabled, and only in release mode (not in debug mode).
It am trying to fix it.

Revision history for this message
jean-pierre charras (jp-charras) wrote :

The crash should be fixed now.

Changed in kicad:
status: New → Fix Committed
assignee: nobody → jean-pierre charras (jp-charras)
Revision history for this message
Fredrik Jonsson (fredrik-jonsson) wrote :

Great!
Tried on both Ubuntu and Windows, works without problem!

Changed in kicad:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.