UI/BrowserModel.py

changeset 3358
57af7e9fda48
parent 3357
2390df6f42ba
child 3440
ddcce63ab5cc
equal deleted inserted replaced
3357:2390df6f42ba 3358:57af7e9fda48
5 5
6 """ 6 """
7 Module implementing the browser model. 7 Module implementing the browser model.
8 """ 8 """
9 9
10 import sys
11 import os 10 import os
12 import fnmatch 11 import fnmatch
12 import json
13 13
14 from PyQt4.QtCore import QDir, QModelIndex, QAbstractItemModel, \ 14 from PyQt4.QtCore import QDir, QModelIndex, QAbstractItemModel, \
15 QFileSystemWatcher, Qt 15 QFileSystemWatcher, Qt, QProcess
16 from PyQt4.QtGui import QImageReader, QApplication, QFont 16 from PyQt4.QtGui import QImageReader, QApplication, QFont
17 17
18 import UI.PixmapCache 18 import UI.PixmapCache
19 import Preferences 19 import Preferences
20 import Utilities 20 import Utilities
556 Public method to populate a sys.path item's subtree. 556 Public method to populate a sys.path item's subtree.
557 557
558 @param parentItem reference to the sys.path item to be populated 558 @param parentItem reference to the sys.path item to be populated
559 @param repopulate flag indicating a repopulation (boolean) 559 @param repopulate flag indicating a repopulation (boolean)
560 """ 560 """
561 # TODO: make this dynamic depending on interpreter 561 if self.__sysPathInterpreter:
562 if len(sys.path) > 0: 562 script = "import sys, json; print(json.dumps(sys.path))"
563 if repopulate: 563 proc = QProcess()
564 self.beginInsertRows( 564 proc.start(self.__sysPathInterpreter, ["-c", script])
565 self.createIndex(parentItem.row(), 0, parentItem), 565 finished = proc.waitForFinished(3000)
566 0, len(sys.path) - 1) 566 if finished:
567 for p in sys.path: 567 procOutput = str(proc.readAllStandardOutput(),
568 if p: 568 Preferences.getSystem("IOEncoding"),
569 node = BrowserDirectoryItem(parentItem, p) 569 'replace')
570 self._addItem(node, parentItem) 570 syspath = [p for p in json.loads(procOutput) if p]
571 if repopulate: 571 if len(syspath) > 0:
572 self.endInsertRows() 572 if repopulate:
573 self.beginInsertRows(
574 self.createIndex(parentItem.row(), 0, parentItem),
575 0, len(syspath) - 1)
576 for p in syspath:
577 if os.path.isdir(p):
578 node = BrowserDirectoryItem(parentItem, p)
579 else:
580 node = BrowserFileItem(parentItem, p)
581 self._addItem(node, parentItem)
582 if repopulate:
583 self.endInsertRows()
584 else:
585 proc.kill()
573 586
574 def populateFileItem(self, parentItem, repopulate=False): 587 def populateFileItem(self, parentItem, repopulate=False):
575 """ 588 """
576 Public method to populate a file item's subtree. 589 Public method to populate a file item's subtree.
577 590

eric ide

mercurial