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 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
|
#-----------------------------------------------------------------------------
# Name: PythonControllers.py
# Purpose:
#
# Author: Riaan Booysen
#
# Created: 2002/02/09
# RCS-ID: $Id: PythonControllers.py,v 1.14 2004/08/16 13:28:13 riaan Exp $
# Copyright: (c) 2002 - 2004
# Licence: GPL
#-----------------------------------------------------------------------------
print 'importing Models.PythonControllers'
import os, sys, time, imp, marshal, stat
from wxPython.wx import *
import Preferences, Utils
from Preferences import keyDefs
import PaletteStore
import Controllers
from Controllers import SourceController, EditorController, addTool
import EditorHelper, EditorModels, PythonEditorModels
from Views import EditorViews, AppViews, SourceViews, PySourceView, OGLViews, ProfileView
from ModRunner import ProcessModuleRunner
import ErrorStack
import methodparse, sourceconst
# TODO: Profile, Cyclops and other file runners should use the command-line
# TODO: parameters whenever possible
class ModuleController(SourceController):
Model = PythonEditorModels.ModuleModel
DefaultViews = [PySourceView.PythonSourceView, EditorViews.ExploreView]
AdditionalViews = [EditorViews.HierarchyView, EditorViews.ModuleDocView,
EditorViews.ToDoView, OGLViews.UMLView,
PySourceView.PythonDisView] + SourceController.AdditionalViews
activeApp = None
runAppBmp = 'Images/Debug/RunApp.png'
runBmp = 'Images/Debug/Run.png'
compileBmp = 'Images/Debug/Compile.png'
debugBmp = 'Images/Debug/Debug.png'
profileBmp = 'Images/Debug/Profile.png'
def actions(self, model):
actions = [
('-', None, '', ''),
('Import module into Shell', self.OnImportInShell, '-', ''),
('Reload module in Shell', self.OnReloadInShell, '-', ''),
('-', None, '', ''),
('Set command-line parameters', self.OnSetRunParams, '-', ''),
('Toggle use input stream', self.OnToggleUseInputStream, '-', ''),
('Run application', self.OnRunApp, self.runAppBmp, 'RunApp'),
('Run module', self.OnRun, self.runBmp, 'RunMod'),
('Debug application', self.OnDebugApp, self.debugBmp, 'Debug'),
('Debug module', self.OnDebug, '-', ''),
('Step in', self.OnDebugStepIn, '-', 'DebugStep'),
('Step over', self.OnDebugStepOver, '-', 'DebugOver'),
('Step out', self.OnDebugStepOut, '-', 'DebugOut'),
('-', None, '-', ''),
('Profile', self.OnProfile, self.profileBmp, ''),
('Check source', self.OnCheckSource, self.compileBmp, 'CheckSource'),
('Cyclops', self.OnCyclops, '-', ''),
('-', None, '', ''),
('Reindent whole file', self.OnReindent, '-', ''),
('-', None, '', '')]
if hasattr(model, 'app') and model.app:
actions.append(('Switch to app', self.OnSwitchApp, '-', 'SwitchToApp'))
else:
actions.extend(
[('Add to an open application', self.OnAddToOpenApp, '-', ''),
('Associate with an open application', self.OnAssosiateWithOpenApp, '-', '')])
try:
imp.find_module('pychecker')
except ImportError:
pass
else:
actions.extend([
('Run PyChecker', self.OnRunPyChecker, '-', ''),
('Configure PyChecker', self.OnConfigPyChecker, '-', '')])
return SourceController.actions(self, model) + actions
def createModel(self, source, filename, main, saved, modelParent=None):
return self.Model(source, filename, self.editor, saved, modelParent)
def createNewModel(self, modelParent=None):
if modelParent:
name = self.editor.getValidName(self.Model, modelParent.absModulesPaths())
else:
name = self.editor.getValidName(self.Model)
model = self.createModel('', name, '', false, modelParent)
model.transport = self.newFileTransport('', name)
self.activeApp = modelParent
return model, name
def afterAddModulePage(self, model):
if self.activeApp and Preferences.autoAddToApplication:
self.activeApp.addModule(model.filename, '')
model.new()
def OnProfile(self, event):
model = self.getModel()
if self.checkUnsaved(model): return
statFile, modtime, profDir = model.profile()
if modtime is not None:
curmodtime = os.stat(statFile)[stat.ST_MTIME]
if curmodtime == modtime:
wxLogError('Stats file date unchanged, check for errors in script.')
return
elif not os.path.exists(statFile):
wxLogError('Stats file not found, check for errors in script.')
return
self.editor.setStatus('Loading stats...')
stats = marshal.load(open(statFile, 'rb'))
resName = 'Profile stats: %s'%time.strftime('%H:%M:%S', time.gmtime(time.time()))
if not model.views.has_key(resName):
resultView = self.editor.addNewView(resName,
ProfileView.ProfileStatsView)
else:
resultView = model.views[resName]
resultView.tabName = resName
resultView.stats = stats
resultView.profDir = profDir
self.editor.setStatus('Refreshing view...')
resultView.refresh()
resultView.focus()
self.editor.setStatus('Profiling complete.')
def OnCheckSource(self, event):
model = self.getModel()
self.editor.setStatus('Compiling...')
if model.compile():
self.editor.setStatus('There were errors', 'Warning')
else:
self.editor.setStatus('Compiled successfully')
if Preferences.runPyLintOnCheckSource:
self.editor.setStatus('Running lint...')
warnings = model.runLint()
if warnings and self.editor.erroutFrm:
self.editor.erroutFrm.updateCtrls(warnings, [], 'Warning',
os.path.dirname(model.assertLocalFile()))
self.editor.erroutFrm.display(len(warnings))
self.editor.setStatus('Lint completed')
def OnSetRunParams(self, event):
model = self.getModel()
dlg = wxTextEntryDialog(self.editor, 'Parameters:',
'Command-line parameters', model.lastRunParams)
try:
if dlg.ShowModal() == wxID_OK:
model.lastRunParams = dlg.GetValue()
# update running debuggers debugging this module
debugger = self.editor.debugger
if debugger and debugger.filename == model.localFilename():
if model.lastRunParams:
params = methodparse.safesplitfields(model.lastRunParams, ' ')
else:
params = []
self.editor.debugger.setParams(params)
finally:
dlg.Destroy()
def OnRun(self, event):
self.OnRunApp(event, self.getModel())
def OnRunApp(self, event=None, runModel=None):
model = self.getModel()
if self.checkUnsaved(model): return
wxBeginBusyCursor()
try:
if runModel is None:
if model.app:
runModel = model.app
else:
runModel = model
runModel.run(runModel.lastRunParams, self.execStart, self.execFinish)
finally:
wxEndBusyCursor()
## def execFinish1(self, runner):
## model = self.getModel()
## editor = model.editor
## if editor.erroutFrm:
## if editor.palette.IsShown():
## editor.palette.restore()
## editor.restore()
##
## runner.init(editor.erroutFrm)
## errs = runner.recheck()
##
## editor.erroutFrm.processFinished(runner.pid)
##
## if errs:
## editor.statusBar.setHint('Finished execution, there were errors', 'Warning')
## else:
## editor.statusBar.setHint('Finished execution.')
def execStart(self, pid, program, script):
model = self.getModel()
editor = model.editor
if editor.erroutFrm:
editor.erroutFrm.processStarted(program, pid, script)
def execFinish(self, runner):
model = self.getModel()
editor = model.editor
if editor.erroutFrm:
if editor.palette.IsShown():
editor.palette.restore()
editor.restore()
runner.init(editor.erroutFrm)
errs = runner.recheck()
editor.erroutFrm.processFinished(runner.pid)
if errs:
editor.statusBar.setHint('Finished execution, there were errors',
'Warning')
else:
editor.statusBar.setHint('Finished execution.')
def OnDebug(self, event):
self.OnDebugApp(event, self.getModel())
def OnDebugApp(self, event=None, debugModel=None):
model = self.getModel()
if self.checkUnsaved(model): return
if debugModel is None:
if model.app:
debugModel = model.app
else:
debugModel = model
if debugModel.lastRunParams:
params = methodparse.safesplitfields(debugModel.lastRunParams, ' ')
else:
params = None
debugModel.debug(params, cont_if_running=1)
def OnDebugStepIn(self, event):
if self.editor.debugger:
self.editor.debugger.OnStep(event)
def OnDebugStepOver(self, event):
if self.editor.debugger:
self.editor.debugger.OnOver(event)
def OnDebugStepOut(self, event):
if self.editor.debugger:
self.editor.debugger.OnOut(event)
def OnSwitchApp(self, event):
model = self.getModel()
if model and isinstance(model, PythonEditorModels.ModuleModel) and model.app:
# does this ensure correct app is reconnected?
appmodel, controller = self.editor.openOrGotoModule(model.app.filename)
if appmodel.prevSwitch and appmodel.prevSwitch.model:
appmodel.prevSwitch.focus()
appmodel.prevSwitch = None
else:
appmodel.views['Application'].focus()
def OnRunPyChecker(self, event):
model = self.getModel()
if model:
if self.checkUnsaved(model): return
filename = model.assertLocalFile()
cwd = os.path.abspath(os.getcwd())
newCwd = os.path.dirname(filename)
os.chdir(newCwd)
oldErr = sys.stderr
oldSysPath = sys.path[:]
try:
sys.path.append(Preferences.pyPath)
cmd = '"%s" "%s" %s'%(sys.executable,
os.path.join(Preferences.pyPath, 'ExternalLib',
'pychecker_custom.py'), os.path.basename(filename))
ProcessModuleRunner(self.editor.erroutFrm, newCwd).run(cmd,
ErrorStack.PyCheckerErrorParser, 'PyChecker', 'Warning',
true)
finally:
sys.path = oldSysPath
sys.stderr = oldErr
os.chdir(cwd)
def OnConfigPyChecker(self, event):
model = self.getModel()
if model:
home = os.environ.get('HOME')
if home:
appDir = home
appConfig = home+'/.pycheckrc'
else:
filename = model.assertLocalFile()
appDir = os.path.dirname(filename)
appConfig = appDir+'/.pycheckrc'
if not os.path.exists(appConfig):
dlg = wxMessageDialog(self.editor, 'The PyChecker configuration file '
'can not be found. Copy the default file here?',
'Config file not found', wxYES_NO | wxICON_QUESTION)
try:
if dlg.ShowModal() == wxID_YES:
from pychecker import Config
open(appConfig, 'w').write(Config.outputRc(Config.Config()))
else:
return
finally:
dlg.Destroy()
from Explorers.PrefsExplorer import SourceBasedPrefColNode
SourceBasedPrefColNode('PyChecker', ('*',), appConfig, -1, None).open(self.editor)
def OnCyclops(self, event):
model = self.getModel()
if model:
if self.checkUnsaved(model): return
self.editor.setStatus('Running Cyclopse on %s ...'%model.filename)
wxBeginBusyCursor()
try:
report = model.cyclops()
finally:
wxEndBusyCursor()
resName = 'Cyclops report: %s'%time.strftime('%H:%M:%S', time.gmtime(time.time()))
if not model.views.has_key(resName):
resultView = self.editor.addNewView(resName, EditorViews.CyclopsView)
else:
resultView = model.views[resName]
resultView.tabName = resName
resultView.report = report
resultView.refresh()
resultView.focus()
def OnReindent(self, event):
model = self.getModel()
if model:
model.reindent()
def OnTabNanny(self, event):
model = self.getModel()
if model:
model.tabnanny()
def chooseOpenApp(self, model, msg, capt):
openApps = self.editor.getAppModules()
if not openApps:
wxMessageBox('No open applications.', style=wxICON_ERROR)
return
chooseApps = {}
for app in openApps:
chooseApps[os.path.basename(app.filename)] = app
dlg = wxSingleChoiceDialog(self.editor, msg, capt, chooseApps.keys())
try:
if dlg.ShowModal() == wxID_OK:
return chooseApps[dlg.GetStringSelection()]
else:
return None
finally:
dlg.Destroy()
def OnAddToOpenApp(self, event):
model = self.getModel()
if model:
app = self.chooseOpenApp(model,
'Select application to add the current file to',
'Add to Application')
if app:
if model.savedAs: src = None
else: src = model.getDataAsLines()
app.addModule(model.filename, '', src)
model.app = app
self.editor.setupToolBar()
def OnAssosiateWithOpenApp(self, event):
model = self.getModel()
if model:
app = self.chooseOpenApp(model,
'Select application to associate the current file with',
'Associate with Application')
if app:
model.app = app
self.editor.setupToolBar()
def OnSave(self, event):
SourceController.OnSave(self, event)
if Preferences.checkSourceOnSave:
self.OnCheckSource(event)
def OnSaveAs(self, event):
SourceController.OnSaveAs(self, event)
if Preferences.checkSourceOnSave:
self.OnCheckSource(event)
def OnImportInShell(self, event):
model = self.getModel()
if model:
msg, status = model.importInShell()
self.editor.setStatus(msg, status)
def OnReloadInShell(self, event):
model = self.getModel()
if model:
msg, status = model.reloadInShell()
self.editor.setStatus(msg, status)
def OnToggleUseInputStream(self, event):
model = self.getModel()
if model:
model.useInputStream = not model.useInputStream
if model.useInputStream:
self.editor.erroutFrm.displayInput(true)
wxLogMessage('Using input stream for running')
else:
wxLogMessage('Not using input stream for running')
def ToolsOnAttachToDebugger(editor):
from Debugger.RemoteDialog import create
rmtDlg = create(editor)
rmtDlg.ShowModal()
rmtDlg.Destroy()
class BaseAppController(ModuleController):
DefaultViews = [AppViews.AppView] + ModuleController.DefaultViews
AdditionalViews = [AppViews.AppModuleDocView, AppViews.AppToDoView,
EditorViews.ToDoView,
OGLViews.ImportsView, EditorViews.CVSConflictsView,
AppViews.AppREADME_TIFView, AppViews.AppCHANGES_TIFView,
AppViews.AppTODO_TIFView, AppViews.AppBUGS_TIFView]
saveAllBmp = 'Images/Editor/SaveAll.png'
def actions(self, model):
return ModuleController.actions(self, model) + [
('Save modified modules', self.OnSaveAll, self.saveAllBmp, ''),
('Compare apps', self.OnCmpApps, '-', ''),
('View crash log as traceback', self.OnCrashLog, '-', '')]
def createModel(self, source, filename, main, saved, modelParent=None):
return self.Model(source, filename, main, self.editor, saved,
self.editor.modules)
def createNewModel(self, modelParent=None):
appName = self.editor.getValidName(self.Model)
main = appName[7:-3]
appModel = self.createModel('', appName, main, false)
appModel.transport = self.newFileTransport(main, appName)
return appModel, appName
def OnSaveAll(self, event):
model = self.getModel()
if model:
for modulePage in self.editor.modules.values():
mod = modulePage.model
if mod != model:
if hasattr(mod, 'app') and mod.app == model and \
(mod.modified or len(mod.viewsModified)):
if len(mod.viewsModified):
mod.refreshFromViews()
modulePage.saveOrSaveAs()
else:
appModPage = modulePage
appModPage.saveOrSaveAs()
def OnCmpApps(self, event):
model = self.getModel()
if model:
fn = self.editor.openFileDlg()
if fn:
filename = model.assertLocalFile(fn)
tbName = 'App. Compare : '+filename
if not model.views.has_key(tbName):
from Views.AppViews import AppCompareView
resultView = self.editor.addNewView(tbName, AppCompareView)
else:
resultView = model.views[tbName]
resultView.tabName = tbName
resultView.compareTo = filename
resultView.refresh()
resultView.focus()
def OnCrashLog(self, event):
model = self.getModel()
if model:
wxBeginBusyCursor()
try:
model.crashLog()
finally:
wxEndBusyCursor()
class PyAppController(BaseAppController):
Model = PythonEditorModels.PyAppModel
def afterAddModulePage(self, model):
model.new()
class PackageController(ModuleController):
Model = PythonEditorModels.PackageModel
DefaultViews = [EditorViews.PackageView] + ModuleController.DefaultViews
AdditionalViews = ModuleController.AdditionalViews + [OGLViews.ImportsView]
def createModel(self, source, filename, main, saved, modelParent=None):
return self.Model(source, filename, self.editor, saved)
def createNewModel(self, modelParent=None):
name = '__init__.py'
filename, success = self.editor.saveAsDlg(name)
if success:
model = self.createModel(sourceconst.defPackageSrc, filename, '', false)
model.transport = self.newFileTransport(name, filename)
model.save()
return model, filename
else:
return None, None
def new(self):
pass
def afterAddModulePage(self, model):
pass
class PythonExtensionController(EditorController):
Model = PythonEditorModels.PythonExtensionFileModel
DefaultViews = [EditorViews.ExplorePythonExtensionView]
AdditionalViews = []
def createModel(self, source, filename, main, saved, modelParent=None):
return self.Model(source, filename, self.editor, saved)
def createNewModel(self, modelParent=None):
raise 'Cannot create a new Python Extension, use distutils to build it'
def new(self):
pass
class SetupController(ModuleController):
Model = PythonEditorModels.SetupModuleModel
DefaultViews = ModuleController.DefaultViews + [EditorViews.DistUtilManifestView]
def actions(self, model):
actions = [
('-', None, '', ''),
('setup.py with parameters', self.OnSetupParams, '-', ''),
('setup.py build', self.OnSetupBuild, '-', ''),
('setup.py clean', self.OnSetupClean, '-', ''),
('setup.py install', self.OnSetupInstall, '-', ''),
('setup.py sdist', self.OnSetupSDist, '-', ''),
('setup.py bdist', self.OnSetupBDist, '-', '')]
if wxPlatform == '__WXGTK__':
actions.append(('setup.py bdist_rpm', self.OnSetupBDist_RPM, '-', ''))
else:
actions.append(('setup.py bdist_wininst', self.OnSetupBDist_WinInst, '-', ''))
try:
imp.find_module('py2exe')
except ImportError:
pass
else:
actions.append(('setup.py py2exe', self.OnSetupPy2Exe, '-', ''))
return ModuleController.actions(self, model) + actions
def createNewModel(self, modelParent=None):
name = 'setup.py'
model = self.createModel(sourceconst.defSetup_py, name, '', false)
model.transport = self.newFileTransport('', name)
model.new()
return model, name
def runDistUtilsCmd(self, cmd):
model = self.getModel()
if not model.savedAs:
wxLogError('Cannot run distutils on an unsaved module')
return
cwd = os.path.abspath(os.getcwd())
filename = model.assertLocalFile()
filedir = os.path.dirname(filename)
os.chdir(filedir)
try:
ProcessModuleRunner(self.editor.erroutFrm, filedir).run(\
'"%s" setup.py %s'%(`Preferences.getPythonInterpreterPath()`[1:-1], cmd),
caption='Running distutil command...')
finally:
os.chdir(cwd)
def OnSetupBuild(self, event):
self.runDistUtilsCmd('build')
def OnSetupClean(self, event):
self.runDistUtilsCmd('clean')
def OnSetupInstall(self, event):
self.runDistUtilsCmd('install')
def OnSetupSDist(self, event):
self.runDistUtilsCmd('sdist')
def OnSetupBDist(self, event):
self.runDistUtilsCmd('bdist')
def OnSetupBDist_WinInst(self, event):
self.runDistUtilsCmd('bdist_wininst')
def OnSetupBDist_RPM(self, event):
self.runDistUtilsCmd('bdist_rpm')
def OnSetupParams(self, event):
dlg = wxTextEntryDialog(self.editor, 'Edit setup.py arguments',
'Distutils setup', '')
try:
if dlg.ShowModal() == wxID_OK:
self.runDistUtilsCmd(dlg.GetValue())
finally:
dlg.Destroy()
def OnSetupPy2Exe(self, event):
self.runDistUtilsCmd('py2exe')
#-------------------------------------------------------------------------------
Preferences.paletteTitle = Preferences.paletteTitle +' - Python IDE'
Controllers.headerStartChar['.py'] = '#'
Controllers.identifyHeader['.py'] = PythonEditorModels.identifyHeader
Controllers.identifySource['.py'] = PythonEditorModels.identifySource
Controllers.appModelIdReg.append(PythonEditorModels.PyAppModel.modelIdentifier)
Controllers.modelControllerReg.update({
PythonEditorModels.PyAppModel: PyAppController,
PythonEditorModels.ModuleModel: ModuleController,
PythonEditorModels.PackageModel: PackageController,
PythonEditorModels.SetupModuleModel: SetupController,
PythonEditorModels.PythonExtensionFileModel: PythonExtensionController,
})
Controllers.fullnameTypes.update({
'__init__.py': (PythonEditorModels.PackageModel, '', '.py'),
'setup.py': (PythonEditorModels.SetupModuleModel, '', '.py'),
})
PaletteStore.newControllers.update({'PythonApp': PyAppController,
'Module': ModuleController,
'Package': PackageController,
'Setup': SetupController,
})
PaletteStore.paletteLists['New'].extend(['PythonApp', 'Module', 'Package', 'Setup'])
# Python extensions to the Explorer
# Register Packages as a File Explorer sub type
from Explorers import ExplorerNodes, FileExplorer
def isPackage(filename):
return os.path.exists(os.path.join(filename, PythonEditorModels.PackageModel.pckgIdnt))
FileExplorer.FileSysNode.subExplorerReg['folder'].append(
(FileExplorer.FileSysNode, isPackage, PythonEditorModels.PackageModel.imgIdx),
)
class SysPathNode(ExplorerNodes.ExplorerNode):
protocol = 'sys.path'
def __init__(self, clipboard, parent, bookmarks):
ExplorerNodes.ExplorerNode.__init__(self, 'sys.path', '', clipboard,
EditorHelper.imgPathFolder, parent)
self.bookmarks = bookmarks
self.bold = true
self.vetoSort = true
def isFolderish(self):
return true
def createChildNode(self, shpth, pth):
return FileExplorer.FileSysNode(shpth, pth, self.clipboard,
EditorHelper.imgPathFolder, self, self.bookmarks)
def refresh(self):
self.entries = []
pythonDir = os.path.dirname(sys.executable)
for pth in sys.path:
pth = os.path.abspath(pth)
shortPath = pth
if pth:
if pth[0:len(pythonDir)] == pythonDir:
shortPath = pth[len(pythonDir):]
if not shortPath:
shortPath = '<Python root>'
self.entries.append( (shortPath, pth) )
def openList(self):
self.refresh()
res = []
for short, entry in self.entries:
res.append(self.createChildNode(short, entry))
return res
ExplorerNodes.register(SysPathNode, clipboard='file', controller='file', root=True)
# Hook debugger attaching to Tools menu
EditorHelper.editorToolsReg.append( ('Attach to debugger', ToolsOnAttachToDebugger,
'Images/Shared/Debugger.png') )
|