← Back to team overview

kicad-developers team mailing list archive

Will realy next stable release be really full useful?

 

I insisted that Python scripting is just a toy, a lot of features aimed to
return text, returns some mythical pointers that are nonsense.
It will be nice to have global function pcbnew.GetChars(), which will give
something usable from any 'wxChar *' or 'wxString *'.
Asking for improving each encountered case is beyond my strength.
>>> import pcbnew as brd
>>> brd.ColorGetName(0)
<Swig Object of type 'wxChar *' at 0x7fad80105480>
Of course I might deal with ctypes, but I would assume that this is not necessary.
>>> import ctypes as ct
>>> ct.wstring_at(brd.ColorGetName(0).__long__())
u'Black'

BTW. Why received string is not compatible with std name space?:
>>> ct.wstring_at(brd.ColorGetName(16).__long__())
u'Magenta 2'
>>> for attr_name in dir(brd):
...   if 'magenta' in attr_name.lower():
...     print("pcbnew.%s:%i" % (attr_name, getattr(brd, attr_name)))
...
pcbnew.DARKMAGENTA:10
pcbnew.LIGHTMAGENTA:22
pcbnew.MAGENTA:16
pcbnew.PUREMAGENTA:28
I found 30 colors:
>>> n_color = 0
>>> while True:
...   color_ptr = brd.ColorGetName(n_color)
...   if not(color_ptr):
...     break
...   print("\t%2d: '%s'" % (n_color, ct.wstring_at(color_ptr.__long__())))
...   n_color += 1
...
	 0: 'Black'
	 1: 'Gray 1'
	 2: 'Gray 2'
	 3: 'Gray 3'
	 4: 'White'
	 5: 'L.Yellow'
	 6: 'Blue 1'
	 7: 'Green 1'
	 8: 'Cyan 1'
	 9: 'Red 1'
	10: 'Magenta 1'
	11: 'Brown 1'
	12: 'Blue 2'
	13: 'Green 2'
	14: 'Cyan 2'
	15: 'Red 2'
	16: 'Magenta 2'
	17: 'Brown 2'
	18: 'Blue 3'
	19: 'Green 3'
	20: 'Cyan 3'
	21: 'Red 3'
	22: 'Magenta 3'
	23: 'Yellow 3'
	24: 'Blue 4'
	25: 'Green 4'
	26: 'Cyan 4'
	27: 'Red 4'
	28: 'Magenta 4'
	29: 'Yellow 4'
>>> colors = []
>>> for attr_name in dir(brd):
... for color in('black', 'blue', 'brown', 'cyan', 'gray', 'green', 'magenta', 'red', 'yellow', 'white'):
...     if color in attr_name.lower():
...       attr_obj = getattr(brd, attr_name)
...       if type(attr_obj) is int:
...         colors.append((attr_name, attr_obj))
...
>>> for attr_name, num in sorted(colors, key=lambda n: n[1]):
...   print("pcbnew.%s: %2i" % (attr_name.ljust(14), num))
...
pcbnew.BLACK         :  0
pcbnew.DARKDARKGRAY  :  1
pcbnew.DARKGRAY      :  2
pcbnew.LIGHTGRAY     :  3
pcbnew.WHITE         :  4
pcbnew.LIGHTYELLOW   :  5
pcbnew.DARKBLUE      :  6
pcbnew.DARKGREEN     :  7
pcbnew.DARKCYAN      :  8
pcbnew.DARKRED       :  9
pcbnew.DARKMAGENTA   : 10
pcbnew.DARKBROWN     : 11
pcbnew.BLUE          : 12
pcbnew.GREEN         : 13
pcbnew.CYAN          : 14
pcbnew.RED           : 15
pcbnew.MAGENTA       : 16
pcbnew.BROWN         : 17
pcbnew.LIGHTBLUE     : 18
pcbnew.LIGHTGREEN    : 19
pcbnew.LIGHTCYAN     : 20
pcbnew.LIGHTRED      : 21
pcbnew.LIGHTMAGENTA  : 22
pcbnew.YELLOW        : 23
pcbnew.PUREBLUE      : 24
pcbnew.PUREGREEN     : 25
pcbnew.PURECYAN      : 26
pcbnew.PURERED       : 27
pcbnew.PUREMAGENTA   : 28
pcbnew.PUREYELLOW    : 29

--
Best Regards,
LordBlick


Follow ups