def getDirectories(self, node): res = VecNode() if node.absolute() != "/": children = node.children() for child in children: if child.isDir() or child.hasChildren(): res.append(child) else: res = node.children() return res
def setListContext(self, query, nodelist, targetmodel): self.listmode = True self.nodes = VecNode() for node in nodelist: self.nodes.append(node) self.model = targetmodel try: self.filters.compile(query) return True except: box = QMessageBox(QMessageBox.Critical, self.tr("Error"), self.tr("Error compiling query"), \ QMessageBox.NoButton, self.__parent) box.setDetailedText(QString.fromUtf8(query)) box.exec_() return False
def setListContext(self, query, nodelist, targetmodel): self.listmode = True self.nodes = VecNode() for node in nodelist: self.nodes.append(node) self.model = targetmodel try: self.filters.compile(query) return True except: box = QMessageBox( QMessageBox.Critical, self.tr("Error"), self.tr("Error compiling query"), QMessageBox.NoButton, self.__parent, ) box.setDetailedText(QString.fromUtf8(query)) box.exec_() return False
class SearchThread(QThread, EventHandler): def __init__(self, parent=None): EventHandler.__init__(self) QThread.__init__(self) self.__parent = parent self.nodes = [] self.filters = Filter("search") self.filters.connection(self) self.model = None self.listmode = False def setListContext(self, query, nodelist, targetmodel): self.listmode = True self.nodes = VecNode() for node in nodelist: self.nodes.append(node) self.model = targetmodel try: self.filters.compile(query) return True except: box = QMessageBox(QMessageBox.Critical, self.tr("Error"), self.tr("Error compiling query"), \ QMessageBox.NoButton, self.__parent) box.setDetailedText(QString.fromUtf8(query)) box.exec_() return False def setContext(self, query, rootnode, targetmodel): self.listmode = False self.rootnode = rootnode self.model = targetmodel try: self.filters.compile(query) return True except Exception as e: print e box = QMessageBox(QMessageBox.Critical, self.tr("Error"), self.tr("Error compiling query"), \ QMessageBox.NoButton, self.__parent) box.setDetailedText(QString.fromUtf8(query)) box.exec_() return False def Event(self, e): if e != None: if e.value != None: if e.type == Filter.EndOfProcessing: self.emit(SIGNAL("finished")) if e.type == Filter.TotalNodesToProcess: self.total = e.value.value() if e.type == Filter.ProcessedNodes: self.processed += 1 if e.type == Filter.NodeMatched: self.match += 1 val = e.value.value() self.model.emit(SIGNAL("appendList"), val) self.emit(SIGNAL("match")) pc = self.processed * 100 / self.total try: if pc > self.percent: self.percent = pc self.emit(SIGNAL("count"), self.percent) except: self.percent = 0 def run(self): self.emit(SIGNAL("started")) self.match = 0 self.processed = 0 self.total = 0 self.percent = 0 try: if not self.listmode: self.filters.process(self.rootnode, True) else: self.filters.process(self.nodes) except: pass def stopSearch(self): e = event() e.thisown = False e.type = Filter.StopProcessing self.filters.Event(e)
class SearchThread(QThread, EventHandler): def __init__(self, parent=None): EventHandler.__init__(self) QThread.__init__(self) self.__parent = parent self.nodes = [] self.filters = Filter("search") self.filters.connection(self) self.model = None self.listmode = False def setListContext(self, query, nodelist, targetmodel): self.listmode = True self.nodes = VecNode() for node in nodelist: self.nodes.append(node) self.model = targetmodel try: self.filters.compile(query) return True except: box = QMessageBox( QMessageBox.Critical, self.tr("Error"), self.tr("Error compiling query"), QMessageBox.NoButton, self.__parent, ) box.setDetailedText(QString.fromUtf8(query)) box.exec_() return False def setContext(self, query, rootnode, targetmodel): self.listmode = False self.rootnode = rootnode self.model = targetmodel try: self.filters.compile(query) return True except Exception as e: print e box = QMessageBox( QMessageBox.Critical, self.tr("Error"), self.tr("Error compiling query"), QMessageBox.NoButton, self.__parent, ) box.setDetailedText(QString.fromUtf8(query)) box.exec_() return False def Event(self, e): if e != None: if e.value != None: if e.type == Filter.EndOfProcessing: self.emit(SIGNAL("finished")) if e.type == Filter.TotalNodesToProcess: self.total = e.value.value() if e.type == Filter.ProcessedNodes: self.processed += 1 if e.type == Filter.NodeMatched: self.match += 1 val = e.value.value() self.model.emit(SIGNAL("appendList"), val) self.emit(SIGNAL("match")) pc = self.processed * 100 / self.total try: if pc > self.percent: self.percent = pc self.emit(SIGNAL("count"), self.percent) except: self.percent = 0 def run(self): self.emit(SIGNAL("started")) self.match = 0 self.processed = 0 self.total = 0 self.percent = 0 try: if not self.listmode: self.filters.process(self.rootnode, True) else: self.filters.process(self.nodes) except: pass def stopSearch(self): e = event() e.thisown = False e.type = Filter.StopProcessing self.filters.Event(e)