summaryrefslogtreecommitdiff
path: root/src/frontend/gui/sisyphus-gui.py
diff options
context:
space:
mode:
authorGhiunhan Mamut (aka V3n3RiX) <venerix@redcorelinux.org>2017-09-20 03:54:57 +0000
committerGhiunhan Mamut (aka V3n3RiX) <venerix@redcorelinux.org>2017-09-20 03:54:57 +0000
commit89ccb97f702ed6bd5ba1e63064d626e5f3359654 (patch)
treea609ec059bb8a0a08175ff79bca10f66f90dfcd7 /src/frontend/gui/sisyphus-gui.py
parent2f3bb730654eec93c427bf43691c0a8a0e8af761 (diff)
parentb956214563f29208bff368eab4a477cd46fd9aa4 (diff)
Merge branch 'implementSearchByField' into 'master'
Implement search by field See merge request redcore/sisyphus!2
Diffstat (limited to 'src/frontend/gui/sisyphus-gui.py')
-rwxr-xr-xsrc/frontend/gui/sisyphus-gui.py29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/frontend/gui/sisyphus-gui.py b/src/frontend/gui/sisyphus-gui.py
index 49a153c..f8be306 100755
--- a/src/frontend/gui/sisyphus-gui.py
+++ b/src/frontend/gui/sisyphus-gui.py
@@ -1,5 +1,6 @@
#!/usr/bin/python3
import sys, subprocess, sqlite3
+from collections import OrderedDict
from PyQt5 import QtCore, QtGui, QtWidgets, uic
from libsisyphus import *
@@ -11,7 +12,18 @@ class Sisyphus(QtWidgets.QMainWindow):
self.centerOnScreen()
self.show()
self.progress.hide()
- self.loadDatabase("'%%'")
+
+ self.SEARCHFIELDS = OrderedDict ([
+ ('Category', 'cat'),
+ ('Name', 'pn'),
+ ('Description', 'descr')
+ ])
+ self.selectfield.addItems(self.SEARCHFIELDS.keys())
+ self.selectfield.setCurrentIndex(1) # defaults to package name
+ self.selectfield.activated.connect(self.setSearchField)
+
+ Sisyphus.SEARCHFIELD = "pn" # defaults to package name
+ self.loadDatabase(Sisyphus.SEARCHFIELD,"'%%'")
self.input.textEdited.connect(self.filterDatabase)
@@ -32,7 +44,10 @@ class Sisyphus(QtWidgets.QMainWindow):
self.orphansThread.orphansFinished.connect(self.finishedOrphans)
self.abort.clicked.connect(self.sisyphusExit)
-
+
+ def setSearchField(self):
+ Sisyphus.SEARCHFIELD = self.SEARCHFIELDS[self.selectfield.currentText()]
+
def updateSystem(self):
sisyphus_pkg_system_update()
@@ -41,7 +56,7 @@ class Sisyphus(QtWidgets.QMainWindow):
self.move((resolution.width() / 2) - (self.frameSize().width() / 2),
(resolution.height() / 2) - (self.frameSize().height() / 2))
- def loadDatabase(self,searchTerm):
+ def loadDatabase(self,searchField,searchTerm):
with sqlite3.connect('/var/lib/sisyphus/db/sisyphus.db') as db:
cursor=db.cursor()
cursor.execute('''SELECT
@@ -55,8 +70,8 @@ class Sisyphus(QtWidgets.QMainWindow):
ON a.category = i.category
AND a.name = i.name
AND a.slot = i.slot
- WHERE a.name LIKE %s
- '''%searchTerm)
+ WHERE %s LIKE %s
+ ''' % (searchField, searchTerm))
rows = cursor.fetchall()
model = QtGui.QStandardItemModel(len(rows), 5)
model.setHorizontalHeaderLabels(['Category', 'Name', 'Available Version', 'Installed Version', 'Description'])
@@ -69,8 +84,8 @@ class Sisyphus(QtWidgets.QMainWindow):
def filterDatabase(self):
search = self.input.text()
- queryTerm = "'%" + search + "%'"
- self.loadDatabase(queryTerm)
+ searchTerm = "'%" + search + "%'"
+ self.loadDatabase(Sisyphus.SEARCHFIELD,searchTerm)
def packageInstall(self):
indexes = self.database.selectionModel().selectedRows(1)