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 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
|
#-----------------------------------------------------------------------------
# Name: AppViews.py
# Purpose: Views for application management
#
# Author: Riaan Booysen
#
# Created:
# RCS-ID: $Id: AppViews.py,v 1.33 2004/08/16 13:35:57 riaan Exp $
# Copyright: (c) 1999 - 2004 Riaan Booysen
# Licence: GPL
#-----------------------------------------------------------------------------
print 'importing Views.AppViews'
""" View classes for the AppModel """
import os
import time
try:
from cmp import cmp
except ImportError:
from filecmp import cmp
from wxPython.wx import *
from EditorViews import ListCtrlView, ModuleDocView, wxwAppModuleTemplate, \
ToDoView, CloseableViewMix, FindResultsAdderMixin
import SourceViews
import Search, Utils
class AppFindResults(ListCtrlView, CloseableViewMix):
gotoLineBmp = 'Images/Editor/GotoLine.png'
viewName = 'Application Find Results'
def __init__(self, parent, model):
CloseableViewMix.__init__(self, 'find results')
ListCtrlView.__init__(self, parent, model, wxLC_REPORT,
( ('Goto match', self.OnGoto, self.gotoLineBmp, ''),
('Rerun query', self.OnRerun, '-', ''),
) +
self.closingActionItems, 0)
self.InsertColumn(0, 'Module', width = 100)
self.InsertColumn(1, 'Line no', wxLIST_FORMAT_CENTRE, 40)
self.InsertColumn(2, 'Col', wxLIST_FORMAT_CENTRE, 40)
self.InsertColumn(3, 'Text', width = 550)
self.results = {}
self.listResultIdxs = []
self.tabName = 'Results'
self.findPattern = ''
self.active = true
self.model = model
def refreshCtrl(self):
ListCtrlView.refreshCtrl(self)
i = 0
self.listResultIdxs = []
for mod in self.results.keys():
for result in self.results[mod]:
self.listResultIdxs.append((mod, result))
i = self.addReportItems(i, (os.path.basename(mod), `result[0]`,
`result[1]`, result[2].strip()) )
self.model.editor.statusBar.setHint('%d matches of "%s".'%(i, self.findPattern))
self.pastelise()
def OnGoto(self, event):
if self.selected >= 0:
modName = self.listResultIdxs[self.selected][0]
model, cntrl = self.model.openModule(modName)
srcView = model.views['Source']
srcView.focus()
foundInfo = self.listResultIdxs[self.selected][1]
srcView.lastSearchPattern = self.findPattern
srcView.lastSearchResults = self.results[modName]
try:
srcView.lastMatchPosition = self.results[modName].index(foundInfo)
except:
srcView.lastMatchPosition = 0
print 'foundInfo not found'
srcView.selectSection(foundInfo[0], foundInfo[1], self.findPattern)
def OnRerun(self, event):
self.rerun(None)
# XXX Add 'Get description from module info' option
class AppView(ListCtrlView, FindResultsAdderMixin):
openBmp = 'Images/Editor/OpenFromApp.png'
addModBmp = 'Images/Editor/AddToApp.png'
remModBmp = 'Images/Editor/RemoveFromApp.png'
findBmp = 'Images/Shared/Find.png'
viewName = 'Application'
def __init__(self, parent, model):
ListCtrlView.__init__(self, parent, model, wxLC_REPORT,
(('Open', self.OnOpen, self.openBmp, ''),
('-', None, '', ''),
('Add', self.OnAdd, self.addModBmp, 'Insert'),
('Edit', self.OnEdit, '-', ''),
('Remove', self.OnRemove, self.remModBmp, 'Delete'),
('-', None, '', ''),
('Find', self.OnFind, self.findBmp, 'Find'),
('-', None, '-', ''),
('Make module main module', self.OnMakeMain, '-', ''),
), 0)
self.InsertColumn(0, 'Module', width = 150)
self.InsertColumn(1, 'Type', width = 50)
# self.InsertColumn(2, 'Autocreate', wxLIST_FORMAT_CENTRE, 50)
self.InsertColumn(2, 'Description', width = 150)
self.InsertColumn(3, 'Relative path', width = 220)
self.sortOnColumns = [0, 1, 3]
self.SetImageList(model.editor.modelImageList, wxIMAGE_LIST_SMALL)
self.lastSearchPattern = ''
self.active = true
self.canExplore = true
self.model = model
# EVT_LIST_BEGIN_DRAG(self, self.GetId(), self.OnDrag)
# def OnDrag(self, event):
# print 'drag', event.GetString()
# print 'drag', dir(event.__class__.__bases__[0])
def explore(self):
modSort = self.model.modules.keys()
modSort.sort()
return modSort
def refreshCtrl(self):
ListCtrlView.refreshCtrl(self)
i = 0
modSort = self.model.modules.keys()
modSort.sort()
for mod in modSort:
# XXX Show a broken icon as default
imgIdx = -1
modTpe = 'Unknown'
if self.model.moduleModels.has_key(mod):
imgIdx = self.model.moduleModels[mod].imgIdx
modTpe = self.model.moduleModels[mod].modelIdentifier
else:
self.model.idModel(mod)
if self.model.moduleModels.has_key(mod):
imgIdx = self.model.moduleModels[mod].imgIdx
modTpe = self.model.moduleModels[mod].modelIdentifier
appMod = self.model.modules[mod]
if appMod[0]:
modTpe = '*%s*'%modTpe
i = self.addReportItems(i, (mod, modTpe, appMod[1], appMod[2]), imgIdx)
self.pastelise()
def OnOpen(self, event):
if self.selected >= 0:
# XXX maybe this should be done in the browsing framework
self.model.openModule(self.GetItemText(self.selected))
self.model.prevSwitch = self
def OnAdd(self, event):
self.model.viewAddModule()
def OnEdit(self, event):
name = self.GetItemText(self.selected)
dlg = wxTextEntryDialog(self, 'Set the description of the module',
'Edit item', self.model.modules[name][1])
try:
if dlg.ShowModal() == wxID_OK:
answer = dlg.GetValue()
self.model.editModule(name, name, self.model.modules[name][0],
answer)
self.model.update()
self.model.notify()
finally:
dlg.Destroy()
def OnRemove(self, event):
if self.selected >= 0:
if not self.model.modules[self.GetItemText(self.selected)][0]:
self.model.removeModule(self.GetItemText(self.selected))
else:
wxMessageBox('Cannot remove the main frame of an application',
'Module remove error')
def OnImports(self, events):
wxBeginBusyCursor()
try:
self.model.showImportsView()
finally:
wxEndBusyCursor()
if self.model.views.has_key('Imports'):
self.model.views['Imports'].focus()
self.model.update()
self.model.notify()
def OnOpenAll(self, event):
modules = self.model.modules.keys()
modules.sort()
for mod in modules:
try:
self.model.editor.openOrGotoModule(\
self.model.modules[mod][2])
except: pass
def OnFind(self, event):
import FindReplaceDlg
FindReplaceDlg.find(self, self.model.editor.finder, self)
def OnMakeMain(self, event):
if self.selected >= 0:
self.model.changeMainFrameModule(self.GetItemText(self.selected))
class AppModuleDocView(ModuleDocView):
viewName = 'Application Documentation'
def OnLinkClicked(self, linkinfo):
url = linkinfo.GetHref()
if url[0] == '#':
self.base_OnLinkClicked(linkinfo)
else:
mod = os.path.splitext(url)[0]
newMod, cntrl = self.model.openModule(mod)
view = newMod.editor.addNewView(ModuleDocView.viewName, ModuleDocView)
view.refreshCtrl()
view.focus()
def genModuleListSect(self):
modLst = []
modNames = self.model.modules.keys()
modNames.sort()
for amod in modNames:
desc = self.model.modules[amod][1].strip()
modLst.append('<tr><td width="25%%"><a href="%s.html">%s</a></td><td>%s</td></tr>' %(amod, amod, desc))
return '<table BORDER=0 CELLSPACING=0 CELLPADDING=0>'+'<BR>'.join(modLst)+'</table>', modNames
def genModuleSect(self, page):
classList, classNames = self.genClassListSect()
funcList, funcNames = self.genFuncListSect()
module = self.model.getModule()
modBody = wxwAppModuleTemplate % { \
'ModuleSynopsis': module.getModuleDoc(),
'Module': self.model.moduleName,
'ModuleList': self.genModuleListSect()[0],
'ClassList': classList,
'FunctionList': funcList,
}
return self.genFunctionsSect(\
self.genClassesSect(page + modBody, classNames), funcNames)
# return self.genClassesSect(page + modBody, classNames)
class AppCompareView(ListCtrlView, CloseableViewMix):
gotoLineBmp = 'Images/Editor/GotoLine.png'
viewName = 'App. Compare'
def __init__(self, parent, model):
CloseableViewMix.__init__(self, 'compare results')
ListCtrlView.__init__(self, parent, model, wxLC_REPORT,
( ('Do diff', self.OnGoto, self.gotoLineBmp, ''), ) +\
self.closingActionItems, 0)
self.InsertColumn(0, 'Module', width = 100)
self.InsertColumn(1, 'Differs from', width = 450)
self.InsertColumn(2, 'Result', width = 75)
self.results = {}
self.listResultIdxs = []
self.tabName = 'App. Compare'
self.active = true
self.model = model
self.compareTo = ''
def refreshCtrl(self):
ListCtrlView.refreshCtrl(self)
from Models.PythonEditorModels import BaseAppModel
otherApp = BaseAppModel('', self.compareTo, '', self.model.editor, true, {})
from Explorers.Explorer import openEx
otherApp.transport = openEx(self.compareTo)
otherApp.load()
otherApp.readModules()
filename, otherFilename = self.model.assertLocalFile(), otherApp.assertLocalFile()
i = 0
# Compare apps
if not cmp(filename, otherFilename):
i = self.addReportItems(i,
(os.path.splitext(os.path.basename(filename))[0], otherFilename,
'changed'))
# Find changed modules and modules not occuring in other module
for module in self.model.modules.keys():
if otherApp.modules.has_key(module):
otherFile = otherApp.assertLocalFile(otherApp.moduleFilename(module))
filename = self.model.assertLocalFile(self.model.moduleFilename(module))
try:
if not cmp(filename, otherFile):
i = self.addReportItems(i, (module, otherFile, 'changed') )
except OSError:
pass
else:
i = self.addReportItems(i, (module, '', 'deleted') )
# Find modules only occuring in other module
for module in otherApp.modules.keys():
if not self.model.modules.has_key(module):
#otherFile = otherApp.moduleFilename(module)
i = self.addReportItems(i, (module, '', 'added') )
self.pastelise()
def OnGoto(self, event):
if self.selected >= 0:
module = self.GetItemText(self.selected)
model, controller = self.model.openModule(module)
otherModule = self.GetItem(self.selected, 1).GetText()
if otherModule:
controller.OnDiffModules(filename=otherModule)
class AppToDoView(ListCtrlView):
viewName = 'Application Todo'
viewName = 'Application Todo'
gotoLineBmp = 'Images/Editor/GotoLine.png'
def __init__(self, parent, model):
ListCtrlView.__init__(self, parent, model, wxLC_REPORT,
(('Goto file', self.OnGoto, self.gotoLineBmp, ''),), 0)
self.sortOnColumns = [0, 1]
self.InsertColumn(0, 'Name')
self.InsertColumn(1, '#Todos')
self.InsertColumn(2, 'Filepath')
self.SetColumnWidth(0, 75)
self.SetColumnWidth(1, 25)
self.SetColumnWidth(2, 350)
self.todos = []
self.active = true
def refreshCtrl(self):
ListCtrlView.refreshCtrl(self)
todos = []
prog = 0
from Models.PythonEditorModels import ModuleModel
absModPaths = self.model.absModulesPaths()
progStep = 100.0/len(absModPaths)
for module in absModPaths:
#module = 'file://'+absModPath
self.model.editor.statusBar.progress.SetValue(int(prog*progStep))
prog += 1
self.model.editor.setStatus('Parsing '+module+'...')
#module = self.modules[moduleName]
#filename = self.normaliseModuleRelativeToApp(module[2])
if module[:7] != 'file://':
print '%s skipped, only local files supported for Imports View'
continue
else:
fn = module[7:]
try: f = open(fn)
except IOError:
print "couldn't load %s" % module
continue
else:
data = f.read()
f.close()
name = os.path.splitext(os.path.basename(module))[0]
model = ModuleModel(data, name, self.model.editor, 1)
m = model.getModule()
if m.todos:
todos.append( (name, len(m.todos), module) )
self.model.editor.statusBar.progress.SetValue(0)
self.model.editor.setStatus('Finished parsing')
i = 0
for name, numTodos, path in todos:
self.addReportItems(i, (name, numTodos, path))
i += 1
self.pastelise()
self.todos = todos
def OnGoto(self, event):
if self.selected >= 0:
name, numTodos, path = self.todos[self.selected]
mod, ctrlr = self.model.editor.openOrGotoModule(path)
if mod.views.has_key('Todo'):
view = mod.views['Todo']
else:
view = mod.editor.addNewView(ToDoView.viewName, ToDoView)
view.refreshCtrl()
view.focus()
## srcView = self.model.views['Source']
## # XXX Implement an interface for views to talk
## srcView.focus()
## module = self.model.getModule()
## srcView.gotoLine(int(module.todos[self.selected][0]) -1)
class TextInfoFileView(SourceViews.EditorStyledTextCtrl):
viewName = 'TextInfo'
def __init__(self, parent, model):
SourceViews.EditorStyledTextCtrl.__init__(self, parent, -1,
model, (), 0)
self.active = true
SourceViews.EVT_STC_UPDATEUI(self, self.GetId(), self.OnUpdateUI)
self.model.loadTextInfo(self.viewName)
def OnUpdateUI(self, event):
# don't update if not fully initialised
if hasattr(self, 'pageIdx'):
self.updateViewState()
def getModelData(self):
return self.model.textInfos[self.viewName]
def setModelData(self, data):
self.model.textInfos[self.viewName] = data
if self.viewName not in self.model.unsavedTextInfos:
self.model.unsavedTextInfos.append(self.viewName)
class AppREADME_TIFView(TextInfoFileView):
viewName = 'Readme.txt'
class AppTODO_TIFView(TextInfoFileView):
viewName = 'Todo.txt'
class AppBUGS_TIFView(TextInfoFileView):
viewName = 'Bugs.txt'
class AppCHANGES_TIFView(TextInfoFileView):
viewName = 'Changes.txt'
|