-
Notifications
You must be signed in to change notification settings - Fork 0
/
kiselect.py
63 lines (52 loc) · 2.18 KB
/
kiselect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# KiSelect.py
import pcbnew
import wx
class SelectDialog(pcbnew.ActionPlugin):
def defaults( self ):
"""Support for ActionPlugins, though it doesn't work in 4.0.6 nightly and later"""
self.name = "Select..."
self.category = "Select"
self.description = "Find any text on the board."
def Run(self):
_pcbnew_frame = \
filter(lambda w: w.GetTitle().startswith('Pcbnew'),
wx.GetTopLevelWindows()
)[0]
_pcbnew_manager = wx.aui.AuiManager.GetManager(_pcbnew_frame)
try:
dlg = wx.TextEntryDialog(_pcbnew_frame, "Enter text to select", defaultValue="")
result = dlg.ShowModal()
except Exception as e:
self._message.SetLabel("ERROR "+str(e))
result = None
return
if result != wx.ID_OK:
return
self.SearchByText(dlg.GetValue())
def get_text_objects(self,layer=None):
"""Gets all the text objects, those on the main board and those within
modules. If specified, the text objects are filtered to return only
those text objects on the indicated layer."""
Texts = []
for drawing in pcbnew.GetBoard().GetDrawings():
if isinstance(drawing,pcbnew.TEXTE_PCB):
Texts.append(drawing)
for module in pcbnew.GetBoard().GetModules():
Texts.append(module.Value())
Texts.append(module.Reference())
for gi in module.GraphicalItems():
if isinstance(gi,pcbnew.TEXTE_MODULE):
Texts.append(gi)
if layer is not None:
Texts = filter(lambda x:x.IsOnLayer(layer),Texts)
return Texts
def SearchByText(self,searchtext,matchcase=False):
if not matchcase:
searchtext = searchtext.lower()
for textobject in self.get_text_objects():
text = textobject.GetShownText()
if not matchcase:
text = text.lower()
if text.find(searchtext) != -1:
textobject.SetSelected()
SelectDialog().register()