Menu

[r175]: / drplugins / bikeplugin.py  Maximize  Restore  History

Download this file

239 lines (204 with data), 10.1 kB

  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
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#Boa:Frame:BikeFrame
import bike
from bike.query.findReferences import CouldntFindDefinitionException
import sys
import os.path
import wx
def create(parent):
return BikeFrame(parent)
[wxID_BIKEFRAME, wxID_BIKEFRAMEEXTRACTMETHODBTN, wxID_BIKEFRAMEFINDDEFBTN,
wxID_BIKEFRAMEFINDREFBTN, wxID_BIKEFRAMERENAMEBTN, wxID_BIKEFRAMERESULTLIST,
wxID_BIKEFRAMERESULTTEXTCTRL, wxID_BIKEFRAMEUNDOBTN,
] = [wx.NewId() for _init_ctrls in range(8)]
class BikeFrame(wx.MiniFrame):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.MiniFrame.__init__(self, id=wxID_BIKEFRAME, name='BikeFrame',
parent=prnt, pos=wx.Point(807, 74), size=wx.Size(353, 497),
style=wx.DEFAULT_FRAME_STYLE, title='Bike Results')
self.SetClientSize(wx.Size(345, 463))
self.Bind(wx.EVT_CLOSE, self.OnBikeClose)
self.findRefBtn = wx.Button(id=wxID_BIKEFRAMEFINDREFBTN,
label='find References', name='findRefBtn', parent=self,
pos=wx.Point(8, 8), size=wx.Size(104, 23), style=0)
self.findRefBtn.Bind(wx.EVT_BUTTON, self.OnFindRef_Click,
id=wxID_BIKEFRAMEFINDREFBTN)
self.undoBtn = wx.Button(id=wxID_BIKEFRAMEUNDOBTN, label='undo',
name='undoBtn', parent=self, pos=wx.Point(120, 40),
size=wx.Size(104, 23), style=0)
self.undoBtn.SetHelpText('undoes the effect of rename and extract')
self.undoBtn.Bind(wx.EVT_BUTTON, self.undoBtn_Click,
id=wxID_BIKEFRAMEUNDOBTN)
self.renameBtn = wx.Button(id=wxID_BIKEFRAMERENAMEBTN, label='rename',
name='renameBtn', parent=self, pos=wx.Point(232, 8),
size=wx.Size(104, 23), style=0)
self.renameBtn.Bind(wx.EVT_BUTTON, self.OnRenameBtn_Click,
id=wxID_BIKEFRAMERENAMEBTN)
self.findDefBtn = wx.Button(id=wxID_BIKEFRAMEFINDDEFBTN,
label='find Definition', name='findDefBtn', parent=self,
pos=wx.Point(120, 8), size=wx.Size(104, 23), style=0)
self.findDefBtn.Bind(wx.EVT_BUTTON, self.OnFindDef_Click,
id=wxID_BIKEFRAMEFINDDEFBTN)
self.resultList = wx.ListCtrl(id=wxID_BIKEFRAMERESULTLIST,
name='resultList', parent=self, pos=wx.Point(8, 80),
size=wx.Size(328, 208), style=wx.NO_BORDER | wx.LC_REPORT)
self.resultList.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnResultList_Click,
id=wxID_BIKEFRAMERESULTLIST)
self.extractMethodBtn = wx.Button(id=wxID_BIKEFRAMEEXTRACTMETHODBTN,
label='extract method', name='extractMethodBtn', parent=self,
pos=wx.Point(8, 40), size=wx.Size(104, 23), style=0)
self.extractMethodBtn.Bind(wx.EVT_BUTTON, self.OnExtractMethodBtn_Click,
id=wxID_BIKEFRAMEEXTRACTMETHODBTN)
self.resultTextCtrl = wx.TextCtrl(id=wxID_BIKEFRAMERESULTTEXTCTRL,
name='resultTextCtrl', parent=self, pos=wx.Point(8, 296),
size=wx.Size(328, 160), style=wx.TE_MULTILINE, value='')
def __init__(self, parent):
self._init_ctrls(parent)
self.DrFrame = parent
self.resultList.InsertColumn(0,"file name")
self.resultList.InsertColumn(1,"line no")
#self.resultList.InsertColumn(2,"col no")
#self.resultList.InsertColumn(3,"col end")
self.resultList.InsertColumn(2,"confidence")
self.bikeCtx = bike.init()
self.bikeCtx.setProgressLogger(self)
def OnFindRef_Click(self, event):
try :
activeDocument = self.DrFrame.GetActiveSTC()
fileName = activeDocument.GetFilename()
startPos,EndPos = activeDocument.GetSelection()
lineNum = activeDocument.LineFromPosition(startPos)
colNum = activeDocument.GetColumn(startPos)
self.resultList.DeleteAllItems()
self.results = []
for ref in self.bikeCtx.findReferencesByCoordinates(fileName,lineNum+1,colNum) :
index=self.resultList.InsertStringItem(sys.maxint,"")
self.resultList.SetStringItem(index,0,ref.filename)
self.resultList.SetStringItem(index,1,str(ref.lineno))
#self.resultList.SetStringItem(index,2,str(ref.colno))
#self.resultList.SetStringItem(index,3,str(ref.colend))
self.resultList.SetStringItem(index,2,str(ref.confidence))
print index
self.results.append(ref)
#['__doc__', '__eq__', '__module__', '__repr__', 'colend', 'colno', 'confidence', 'filename', 'lineno', 'sourcenode']
except CouldntFindDefinitionException :
wx.MessageBox('Could not find Reference','Find References', wx.OK | wx.ICON_ERROR)
except Exception,err:
wx.MessageBox(str(err),'Find References', wx.OK | wx.ICON_ERROR)
#event.Skip()
def OnFindDef_Click(self, event):
try :
activeDocument = self.DrFrame.GetActiveSTC()
fileName = activeDocument.GetFilename()
startPos,EndPos = activeDocument.GetSelection()
lineNum = activeDocument.LineFromPosition(startPos)
colNum = activeDocument.GetColumn(startPos)
self.resultList.DeleteAllItems()
self.results = []
for ref in self.bikeCtx.findDefinitionByCoordinates(fileName,lineNum+1,colNum) :
index=self.resultList.InsertStringItem(sys.maxint,"")
self.resultList.SetStringItem(index,0,ref.filename)
self.resultList.SetStringItem(index,1,str(ref.lineno))
#self.resultList.SetStringItem(index,2,str(ref.colno))
#self.resultList.SetStringItem(index,3,str(ref.colend))
self.resultList.SetStringItem(index,2,str(ref.confidence))
print index
self.results.append(ref)
except CouldntFindDefinitionException :
wx.MessageBox('Could not find Definition','Find Definition', wx.OK | wx.ICON_ERROR)
except Exception,err:
wx.MessageBox(self,str(err),'Find Definition', wx.OK | wx.ICON_ERROR)
#event.Skip()
def OnResultList_Click(self, event):
#wx.BeginBusyCursor()
openFiles = self.DrFrame.GetAlreadyOpen()
idx = -1
i = 0
for fileName in openFiles :
if os.path.abspath(fileName) == os.path.abspath(self.results[event.m_itemIndex].filename) :
idx=i
i+=1
if idx!=-1 :
self.DrFrame.setDocumentTo(idx)
else :
self.DrFrame.OpenFile(self.results[event.m_itemIndex].filename,True)
activeDocument = self.DrFrame.GetActiveSTC()
lineNum = self.results[event.m_itemIndex].lineno-1
colNum = self.results[event.m_itemIndex].colno
colEnd = None
try :
colEnd = self.results[event.m_itemIndex].colend
except :
colEnd = activeDocument.GetLineEndPosition(lineNum)-1
linePos = activeDocument.PositionFromLine(lineNum)
activeDocument.SetSelection(linePos+colNum,linePos+colEnd)
#wx.EndBusyCursor()
event.Skip()
def RenameCallback(self, filename, lineno, colbegin, colend) :
print "rename callback"
return True
def OnRenameBtn_Click(self, event):
activeDocument = self.DrFrame.GetActiveSTC()
fileName = activeDocument.GetFilename()
startPos,EndPos = activeDocument.GetSelection()
lineNum = activeDocument.LineFromPosition(startPos)
colNum = activeDocument.GetColumn(startPos)
dlg = wx.TextEntryDialog(self, 'Rename Method to :','Method Name :','')
try:
if dlg.ShowModal() == wx.ID_OK:
newname = dlg.GetValue()
self.bikeCtx.setRenameMethodPromptCallback(self.RenameCallback)
self.bikeCtx.renameByCoordinates(fileName,lineNum+1,colNum,newname)
self.SaveAndRefresh()
finally:
dlg.Destroy()
#event.Skip()
def SaveAndRefresh(self) :
savedFiles = self.bikeCtx.save()
openFiles = map(os.path.abspath,self.DrFrame.GetAlreadyOpen())
for fileName in savedFiles :
if openFiles.count(os.path.abspath(fileName)) > 0 :
self.DrFrame.OpenFile(fileName,False)
def undoBtn_Click(self, event):
self.bikeCtx.undo()
self.SaveAndRefresh()
#event.Skip()
def OnExtractMethodBtn_Click(self, event):
activeDocument = self.DrFrame.GetActiveSTC()
fileName = activeDocument.GetFilename()
startPos,EndPos = activeDocument.GetSelection()
beginLineNum = activeDocument.LineFromPosition(startPos)
beginColNum = activeDocument.GetColumn(startPos)
endLineNum = activeDocument.LineFromPosition(EndPos)
endColNum = activeDocument.GetColumn(EndPos)
dlg = wx.TextEntryDialog(self, 'Question', 'Caption', 'Default answer')
try:
if dlg.ShowModal() == wx.ID_OK:
methodname = dlg.GetValue()
self.bikeCtx.extractMethod(fileName,beginLineNum,beginColNum,endLineNum,endColNum,methodname)
self.SaveAndRefresh()
finally:
dlg.Destroy()
#event.Skip()
def write(self,text) :
self.resultTextCtrl.AppendText(text)
def OnBikeClose(self, event):
event.Skip()
def Plugin(DrFrame):
idum = DrFrame.GetNewId()
DrFrame.viewmenu.Append(idum,"Bicycle Repair Main")
def BicycleFunction(event):
bikeFrame=BikeFrame(DrFrame)
bikeFrame.Show()
DrFrame.Bind(wx.EVT_MENU,BicycleFunction,id=idum)
def OnHelp(DrFrame):
helpText = '''Bike Repairman 0.01\n
Created by John Janecek
Requires module http://bicyclerepair.sourceforge.net/\n
functionality was ripped off the Boa Constructor and Idle Plugin\n
Boa Constructor runs the methods in a thread not sure if that good idea.\n
Really cool module.
Anyway this plugin will probably destroy your code. Fixes bugs etc
email to nopa90@gmail.com
'''
DrFrame.ShowMessage(helpText, "CodeCompletion Help")