Exemple #1
0
    def __init__(self, parent, searchview):
        super(QWidget, self).__init__(parent)
        self.setupUi(self)
        self.filters = CustomFiltersTable(self)
        self.searchFiltersLayout.addWidget(self.filters)
        self.browser = parent
        self.vfs = vfs.vfs()
        self.model = searchview.model
        self.searchview = searchview

        self.matched = 0
        self.searchTH = SearchThread(self)

        self.qmode = {0: "$", 1: "/", 2: "~", 3: "\""}
        self.configure()
Exemple #2
0
  def __init__(self, parent, searchview):
    super(QWidget, self).__init__(parent)
    self.setupUi(self)
    self.filters = CustomFiltersTable(self)
    self.searchFiltersLayout.addWidget(self.filters)
    self.browser = parent
    self.vfs = vfs.vfs()
    self.model = searchview.model
    self.searchview = searchview

    self.matched = 0
    self.searchTH = SearchThread(self)

    self.qmode = {0: "$",
                  1: "/",
                  2: "~",
                  3: "\""}
    self.configure()
Exemple #3
0
 def createFilterThread(self):
   self.filterTH = SearchThread(self)
Exemple #4
0
class FilterWidget(Ui_filterWidget, QWidget):
  def __init__(self, parent):
    QWidget.__init__(self, parent)
    self.setupUi(self)
    self.parent = parent
    self.edit = self.filterCombo.lineEdit()    
    self.filterMode = {0: "$",
                       1: "~",
                       2: "/",
                       3: "\""}
    self.query = ""
    self.createFilterThread()
    self.connect(self.filterTH, SIGNAL("match"), self.updateMatchedNodes)
    self.connect(self.filterTH, SIGNAL("finished"), self.searchStoped)
    self.connect(self.filterTH, SIGNAL("started"), self.searchStarted)
    self.connect(self.filterTH, SIGNAL("stoped"), self.searchStoped)
    self.connect(self.clear, SIGNAL("clicked(bool)"), self.resetFilter)
    self.connect(self.stop, SIGNAL("clicked(bool)"), self.stopFilter)
    self.connect(self.edit, SIGNAL("textChanged(QString)"), self.updateQuery)
    self.connect(self.mode, SIGNAL("currentIndexChanged(int)"), self.modeChanged)
    self.redstyle = QString("QWidget {color:red}")
    self.greenstyle = QString("QWidget {color:green}")
    self.blackstyle = QString("QWidget {color:black}")
    self.matched = 0
    self.stop.setEnabled(False)
    self.timer = QTimer(self)
    self.timer.setSingleShot(True)
    self.filtertagwidget = FilterTagWidget(self)
    self.filtertagwidget.hide()
    self.connect(self.timer, SIGNAL("timeout()"), self.quickFilter)

  def createFilterThread(self):
    self.filterTH = SearchThread(self)

  def updateQuery(self, query):
    self.timer.start(1000)
    if self.mode.currentIndex() in xrange(0,4):
      self.query = query
    else:
      f = Filter("completer")
      try:
        q = str(unicode(query).encode('utf-8'))
        f.compile(q)
        self.edit.setStyleSheet(self.greenstyle)
      except RuntimeError:
        self.edit.setStyleSheet(self.redstyle)

  def modeChanged(self, index):
    if index == 5:
      self.verticalLayout.addWidget(self.filtertagwidget)
      self.filtertagwidget.toolbar.refreshTags()
      self.filterCombo.setEnabled(False)
      self.filtertagwidget.show()
    else:
      self.verticalLayout.removeWidget(self.filtertagwidget)
      self.filterCombo.setEnabled(True)
      self.filtertagwidget.hide()
      

  def launchFilter(self, query=None):
    if not query:
      query = self.filterCombo.lineEdit().text()
    else:
      query = query
    nodelist = self.sourceModel().list()
    if len(nodelist) > 0:
      self.parent.filterview.model.clearList()
      q = str(unicode(query).encode('utf-8'))
      r = self.filterTH.setListContext(q, nodelist, self.parent.filterview.model)
      if r:
        self.filterTH.start()

  def quickFilter(self):
    self.timer.stop()
    index = self.mode.currentIndex()
    if index in xrange(0,4):
      self.filterTH.stopSearch()
      if self.query == "":
        self.resetFilter()
      else:
        self.resetFilter()
        q = "name matches " + self.filterMode[index] + self.query + self.filterMode[index]
        self.launchFilter(q)
    else:
      try:
        query = self.filterCombo.lineEdit().text()
        if query != "":
          f = Filter("test")
          q = str(unicode(query).encode('utf-8'))
          f.compile(q)
          self.edit.setStyleSheet(self.greenstyle)
          self.resetFilter()
          self.launchFilter()
        else:
          self.resetFilter()
      except RuntimeError:
        self.edit.setStyleSheet(self.redstyle)

  def stopFilter(self):
    self.filterTH.stopSearch

  def sourceModel(self):
    if self.parent.search.isChecked():
      return self.parent.searchview.model
    else:
      return self.parent.browserview.model

  def resetFilter(self):
    self.edit.setStyleSheet(self.blackstyle)
    self.parent.filterview.model.changeList(self.sourceModel().list())
    count = len(self.sourceModel().list())
    if count > 0:
      self.reslabel.setStyleSheet(self.greenstyle)
      self.countlabel.setStyleSheet(self.greenstyle)
    else:
      self.reslabel.setStyleSheet(self.redstyle)
      self.countlabel.setStyleSheet(self.redstyle)
    self.countlabel.setText(str(count))
    self.reslabel.setText(str(count))
    self.parent.filterview.refreshVisible()

  def updateMatchedNodes(self):
    if self.matched == 0:
      self.reslabel.setStyleSheet(self.greenstyle)
      self.countlabel.setStyleSheet(self.greenstyle)
    self.matched += 1
    self.countlabel.setText(str(self.matched))
    self.parent.filterview.refreshVisible()

  def searchStoped(self):
    QApplication.restoreOverrideCursor()
    self.stop.setEnabled(False)

  def searchStarted(self):
    QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
    self.stop.setEnabled(True)
    self.matched = 0
    self.reslabel.setStyleSheet(self.redstyle)
    self.countlabel.setStyleSheet(self.redstyle)
    self.countlabel.setText(str(self.matched))
    self.reslabel.show()
    self.countlabel.show()
Exemple #5
0
class SearchPanel(Ui_searchPanel, QWidget):
  def __init__(self, parent, searchview):
    super(QWidget, self).__init__(parent)
    self.setupUi(self)
    self.filters = CustomFiltersTable(self)
    self.searchFiltersLayout.addWidget(self.filters)
    self.browser = parent
    self.vfs = vfs.vfs()
    self.model = searchview.model
    self.searchview = searchview

    self.matched = 0
    self.searchTH = SearchThread(self)

    self.qmode = {0: "$",
                  1: "/",
                  2: "~",
                  3: "\""}
    self.configure()

  def configure(self):
    # Quick search
    self.connect(self.quickSearch, SIGNAL("clicked(bool)"), self.quickSearchMode)
    # Thread
    self.connect(self.startButton, SIGNAL("clicked(bool)"), self.startSearch)
    self.connect(self.stopButton, SIGNAL("clicked(bool)"), self.searchTH.stopSearch)
    self.connect(self.searchTH, SIGNAL("count"), self.updateProgressbar)
    self.connect(self.searchTH, SIGNAL("match"), self.updateMatchedNodes)
    self.connect(self.searchTH, SIGNAL("finished"), self.searchStoped)
    self.connect(self.searchTH, SIGNAL("started"), self.searchStarted)
    self.connect(self.searchTH, SIGNAL("stoped"), self.searchStoped)
    # Advanced search 
    self.connect(self.advancedSearch, SIGNAL("clicked(bool)"), self.advancedSearchMode)
    # Typebuttons
    self.connect(self.imageType, SIGNAL("clicked()"), self.buttonClicked)
    self.connect(self.videoType, SIGNAL("clicked()"), self.buttonClicked)
    self.connect(self.soundType, SIGNAL("clicked()"), self.buttonClicked)
    self.connect(self.documentType, SIGNAL("clicked()"), self.buttonClicked)
  
  def buttonClicked(self):
    if not self.buttonsChecked():
      self.quickEdit.setEnabled(True)
      self.quickMode.setEnabled(True)
    else:
      self.quickEdit.setEnabled(False)
      self.quickMode.setEnabled(False)
#    self.refreshQueryEdit()
  
  def buttonsChecked(self):
    self.quickEdit.clear()
    if self.imageType.isChecked() or self.videoType.isChecked() or self.soundType.isChecked() or self.documentType.isChecked():
      self.quickEdit.insert(self.generateButtonsClicked())
      return True
    return False

  def generateButtonsClicked(self):
    r = ""
    count = 0
    if self.imageType.isChecked():
      r += DEFAULT_FILTERS["Images"]
      count += 1
    if self.videoType.isChecked():
      if count != 0:
        r += " or "
      r += DEFAULT_FILTERS["Videos"]
      count += 1
    if self.soundType.isChecked():
      if count != 0:
        r += " or "
      r += DEFAULT_FILTERS["Audios"]
      count += 1
    if self.documentType.isChecked():
      if count != 0:
        r += " or "
      r += DEFAULT_FILTERS["Documents"]
      count += 1
    return r

  def startSearch(self):
    query = self.buildQuery()
    if query != None:
      if self.fromRoot.isChecked():
        rootnode = self.vfs.getnode("/")
      else:
        rootnode = self.browser.navigation.currentNode
      if self.browser.filter.isChecked():
        self.browser.viewpan.setCurrentWidget(self.browser.searchview)
      self.model.clearList()
      self.matchedNodeLabel.setText("0")
      self.matched = 0
      r = self.searchTH.setContext(query, rootnode, self.model)
      if r:
        self.searchTH.start()
    else:
      box = QMessageBox(QMessageBox.Critical, self.tr("Error"), self.tr("Please, specify your query"), \
                          QMessageBox.NoButton, self)
      box.exec_()

  def buildQuery(self):
    if self.quickSearch.isChecked():
      query = ""
      if self.quickEdit.text() != "":
        # Check if buttons are checked
        if not self.quickEdit.isEnabled():
          query += str(unicode(self.quickEdit.text()).encode('utf-8'))
        else:
          if self.quickMode.currentIndex() in xrange(0,4):
            pat = self.qmode[self.quickMode.currentIndex()]
            query += "name matches" + pat + str(unicode(self.quickEdit.text()).encode('utf-8')) + pat
          else:
            query += str(unicode(self.quickEdit.text()).encode('utf-8'))
      else:
        return None
      return query
    else:
      return self.filters.buildAllQueries()
      
  def updateProgressbar(self, count):
    self.searchProgress.setValue(count)

  def updateMatchedNodes(self):
    self.matched += 1
    self.matchedNodeLabel.setText(str(self.matched))
    self.searchview.refreshVisible()

  def searchStarted(self):
    QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
    self.searchProgress.setValue(0)
    self.matchedNodeLabel.setText(QString("0"))
    self.startButton.setEnabled(False)
    self.stopButton.setEnabled(True)

  def searchStoped(self):
    self.startButton.setEnabled(True)
    self.stopButton.setEnabled(False)
    if self.browser.filter.isChecked():
      self.browser.viewpan.setCurrentWidget(self.browser.filterview)
      self.browser.filterwidget.resetFilter()
    QApplication.restoreOverrideCursor()

  def quickSearchMode(self, state):
    if state:
      self.advancedSearch.setChecked(False)
    else:
      self.advancedSearch.setChecked(True)

  def advancedSearchMode(self, state):
    if state:
      self.quickSearch.setChecked(False)
    else:
      self.quickSearch.setChecked(True)
Exemple #6
0
 def createFilterThread(self):
     self.filterTH = SearchThread(self)
Exemple #7
0
class FilterWidget(Ui_filterWidget, QWidget):
    def __init__(self, parent):
        QWidget.__init__(self, parent)
        self.setupUi(self)
        self.parent = parent
        self.edit = self.filterCombo.lineEdit()
        self.filterMode = {0: "$", 1: "~", 2: "/", 3: "\""}
        self.query = ""
        self.createFilterThread()
        self.connect(self.filterTH, SIGNAL("match"), self.updateMatchedNodes)
        self.connect(self.filterTH, SIGNAL("finished"), self.searchStoped)
        self.connect(self.filterTH, SIGNAL("started"), self.searchStarted)
        self.connect(self.filterTH, SIGNAL("stoped"), self.searchStoped)
        self.connect(self.clear, SIGNAL("clicked(bool)"), self.resetFilter)
        self.connect(self.stop, SIGNAL("clicked(bool)"), self.stopFilter)
        self.connect(self.edit, SIGNAL("textChanged(QString)"),
                     self.updateQuery)
        self.connect(self.mode, SIGNAL("currentIndexChanged(int)"),
                     self.modeChanged)
        self.redstyle = QString("QWidget {color:red}")
        self.greenstyle = QString("QWidget {color:green}")
        self.blackstyle = QString("QWidget {color:black}")
        self.matched = 0
        self.stop.setEnabled(False)
        self.timer = QTimer(self)
        self.timer.setSingleShot(True)
        self.filtertagwidget = FilterTagWidget(self)
        self.filtertagwidget.hide()
        self.connect(self.timer, SIGNAL("timeout()"), self.quickFilter)

    def createFilterThread(self):
        self.filterTH = SearchThread(self)

    def updateQuery(self, query):
        self.timer.start(1000)
        if self.mode.currentIndex() in xrange(0, 4):
            self.query = query
        else:
            f = Filter("completer")
            try:
                q = str(unicode(query).encode('utf-8'))
                f.compile(q)
                self.edit.setStyleSheet(self.greenstyle)
            except RuntimeError:
                self.edit.setStyleSheet(self.redstyle)

    def modeChanged(self, index):
        if index == 5:
            self.verticalLayout.addWidget(self.filtertagwidget)
            self.filtertagwidget.toolbar.refreshTags()
            self.filterCombo.setEnabled(False)
            self.filtertagwidget.show()
        else:
            self.verticalLayout.removeWidget(self.filtertagwidget)
            self.filterCombo.setEnabled(True)
            self.filtertagwidget.hide()

    def launchFilter(self, query=None):
        if not query:
            query = self.filterCombo.lineEdit().text()
        else:
            query = query
        nodelist = self.sourceModel().list()
        if len(nodelist) > 0:
            self.parent.filterview.model.clearList()
            q = str(unicode(query).encode('utf-8'))
            r = self.filterTH.setListContext(q, nodelist,
                                             self.parent.filterview.model)
            if r:
                self.filterTH.start()

    def quickFilter(self):
        self.timer.stop()
        index = self.mode.currentIndex()
        if index in xrange(0, 4):
            self.filterTH.stopSearch()
            if self.query == "":
                self.resetFilter()
            else:
                self.resetFilter()
                q = "name matches " + self.filterMode[
                    index] + self.query + self.filterMode[index]
                self.launchFilter(q)
        else:
            try:
                query = self.filterCombo.lineEdit().text()
                if query != "":
                    f = Filter("test")
                    q = str(unicode(query).encode('utf-8'))
                    f.compile(q)
                    self.edit.setStyleSheet(self.greenstyle)
                    self.resetFilter()
                    self.launchFilter()
                else:
                    self.resetFilter()
            except RuntimeError:
                self.edit.setStyleSheet(self.redstyle)

    def stopFilter(self):
        self.filterTH.stopSearch

    def sourceModel(self):
        if self.parent.search.isChecked():
            return self.parent.searchview.model
        else:
            return self.parent.browserview.model

    def resetFilter(self):
        self.edit.setStyleSheet(self.blackstyle)
        self.parent.filterview.model.changeList(self.sourceModel().list())
        count = len(self.sourceModel().list())
        if count > 0:
            self.reslabel.setStyleSheet(self.greenstyle)
            self.countlabel.setStyleSheet(self.greenstyle)
        else:
            self.reslabel.setStyleSheet(self.redstyle)
            self.countlabel.setStyleSheet(self.redstyle)
        self.countlabel.setText(str(count))
        self.reslabel.setText(str(count))
        self.parent.filterview.refreshVisible()

    def updateMatchedNodes(self):
        if self.matched == 0:
            self.reslabel.setStyleSheet(self.greenstyle)
            self.countlabel.setStyleSheet(self.greenstyle)
        self.matched += 1
        self.countlabel.setText(str(self.matched))
        self.parent.filterview.refreshVisible()

    def searchStoped(self):
        QApplication.restoreOverrideCursor()
        self.stop.setEnabled(False)

    def searchStarted(self):
        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
        self.stop.setEnabled(True)
        self.matched = 0
        self.reslabel.setStyleSheet(self.redstyle)
        self.countlabel.setStyleSheet(self.redstyle)
        self.countlabel.setText(str(self.matched))
        self.reslabel.show()
        self.countlabel.show()
Exemple #8
0
class SearchPanel(Ui_searchPanel, QWidget):
    def __init__(self, parent, searchview):
        super(QWidget, self).__init__(parent)
        self.setupUi(self)
        self.filters = CustomFiltersTable(self)
        self.searchFiltersLayout.addWidget(self.filters)
        self.browser = parent
        self.vfs = vfs.vfs()
        self.model = searchview.model
        self.searchview = searchview

        self.matched = 0
        self.searchTH = SearchThread(self)

        self.qmode = {0: "$", 1: "/", 2: "~", 3: "\""}
        self.configure()

    def configure(self):
        # Quick search
        self.connect(self.quickSearch, SIGNAL("clicked(bool)"),
                     self.quickSearchMode)
        # Thread
        self.connect(self.startButton, SIGNAL("clicked(bool)"),
                     self.startSearch)
        self.connect(self.stopButton, SIGNAL("clicked(bool)"),
                     self.searchTH.stopSearch)
        self.connect(self.searchTH, SIGNAL("count"), self.updateProgressbar)
        self.connect(self.searchTH, SIGNAL("match"), self.updateMatchedNodes)
        self.connect(self.searchTH, SIGNAL("finished"), self.searchStoped)
        self.connect(self.searchTH, SIGNAL("started"), self.searchStarted)
        self.connect(self.searchTH, SIGNAL("stoped"), self.searchStoped)
        # Advanced search
        self.connect(self.advancedSearch, SIGNAL("clicked(bool)"),
                     self.advancedSearchMode)
        # Typebuttons
        self.connect(self.imageType, SIGNAL("clicked()"), self.buttonClicked)
        self.connect(self.videoType, SIGNAL("clicked()"), self.buttonClicked)
        self.connect(self.soundType, SIGNAL("clicked()"), self.buttonClicked)
        self.connect(self.documentType, SIGNAL("clicked()"),
                     self.buttonClicked)

    def buttonClicked(self):
        if not self.buttonsChecked():
            self.quickEdit.setEnabled(True)
            self.quickMode.setEnabled(True)
        else:
            self.quickEdit.setEnabled(False)
            self.quickMode.setEnabled(False)
#    self.refreshQueryEdit()

    def buttonsChecked(self):
        self.quickEdit.clear()
        if self.imageType.isChecked() or self.videoType.isChecked(
        ) or self.soundType.isChecked() or self.documentType.isChecked():
            self.quickEdit.insert(self.generateButtonsClicked())
            return True
        return False

    def generateButtonsClicked(self):
        r = ""
        count = 0
        if self.imageType.isChecked():
            r += DEFAULT_FILTERS["Images"]
            count += 1
        if self.videoType.isChecked():
            if count != 0:
                r += " or "
            r += DEFAULT_FILTERS["Videos"]
            count += 1
        if self.soundType.isChecked():
            if count != 0:
                r += " or "
            r += DEFAULT_FILTERS["Audios"]
            count += 1
        if self.documentType.isChecked():
            if count != 0:
                r += " or "
            r += DEFAULT_FILTERS["Documents"]
            count += 1
        return r

    def startSearch(self):
        query = self.buildQuery()
        if query != None:
            if self.fromRoot.isChecked():
                rootnode = self.vfs.getnode("/")
            else:
                rootnode = self.browser.navigation.currentNode
            if self.browser.filter.isChecked():
                self.browser.viewpan.setCurrentWidget(self.browser.searchview)
            self.model.clearList()
            self.matchedNodeLabel.setText("0")
            self.matched = 0
            r = self.searchTH.setContext(query, rootnode, self.model)
            if r:
                self.searchTH.start()
        else:
            box = QMessageBox(QMessageBox.Critical, self.tr("Error"), self.tr("Please, specify your query"), \
                                QMessageBox.NoButton, self)
            box.exec_()

    def buildQuery(self):
        if self.quickSearch.isChecked():
            query = ""
            if self.quickEdit.text() != "":
                # Check if buttons are checked
                if not self.quickEdit.isEnabled():
                    query += str(
                        unicode(self.quickEdit.text()).encode('utf-8'))
                else:
                    if self.quickMode.currentIndex() in xrange(0, 4):
                        pat = self.qmode[self.quickMode.currentIndex()]
                        query += "name matches" + pat + str(
                            unicode(
                                self.quickEdit.text()).encode('utf-8')) + pat
                    else:
                        query += str(
                            unicode(self.quickEdit.text()).encode('utf-8'))
            else:
                return None
            return query
        else:
            return self.filters.buildAllQueries()

    def updateProgressbar(self, count):
        self.searchProgress.setValue(count)

    def updateMatchedNodes(self):
        self.matched += 1
        self.matchedNodeLabel.setText(str(self.matched))
        self.searchview.refreshVisible()

    def searchStarted(self):
        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
        self.searchProgress.setValue(0)
        self.matchedNodeLabel.setText(QString("0"))
        self.startButton.setEnabled(False)
        self.stopButton.setEnabled(True)

    def searchStoped(self):
        self.startButton.setEnabled(True)
        self.stopButton.setEnabled(False)
        if self.browser.filter.isChecked():
            self.browser.viewpan.setCurrentWidget(self.browser.filterview)
            self.browser.filterwidget.resetFilter()
        QApplication.restoreOverrideCursor()

    def quickSearchMode(self, state):
        if state:
            self.advancedSearch.setChecked(False)
        else:
            self.advancedSearch.setChecked(True)

    def advancedSearchMode(self, state):
        if state:
            self.quickSearch.setChecked(False)
        else:
            self.quickSearch.setChecked(True)