From 5e21c2ef54d66fa0ca6fec45637917bfaf0da5bc Mon Sep 17 00:00:00 2001 From: bionel Date: Mon, 18 Sep 2017 21:28:45 +0300 Subject: step 1: prepare functions for seachByField --- src/frontend/gui/sisyphus-gui.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/frontend/gui/sisyphus-gui.py b/src/frontend/gui/sisyphus-gui.py index 49a153c..7e7a703 100755 --- a/src/frontend/gui/sisyphus-gui.py +++ b/src/frontend/gui/sisyphus-gui.py @@ -11,7 +11,10 @@ class Sisyphus(QtWidgets.QMainWindow): self.centerOnScreen() self.show() self.progress.hide() - self.loadDatabase("'%%'") + + Sisyphus.SFIELD = "name" # forced to 'name' until ui implementation + #print(Sisyphus.SFIELD) + self.loadDatabase(Sisyphus.SFIELD,"'%%'") self.input.textEdited.connect(self.filterDatabase) @@ -41,7 +44,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 +58,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 a.%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 +72,8 @@ class Sisyphus(QtWidgets.QMainWindow): def filterDatabase(self): search = self.input.text() - queryTerm = "'%" + search + "%'" - self.loadDatabase(queryTerm) + searchTerm = "'%" + search + "%'" + self.loadDatabase(Sisyphus.SFIELD,searchTerm) def packageInstall(self): indexes = self.database.selectionModel().selectedRows(1) -- cgit v1.2.3 From b956214563f29208bff368eab4a477cd46fd9aa4 Mon Sep 17 00:00:00 2001 From: bionel Date: Tue, 19 Sep 2017 22:53:55 +0300 Subject: implement search by field --- src/frontend/gui/sisyphus-gui.py | 24 +++++-- src/frontend/gui/ui/sisyphus-gui.ui | 134 +++++++++++++++--------------------- 2 files changed, 74 insertions(+), 84 deletions(-) (limited to 'src') diff --git a/src/frontend/gui/sisyphus-gui.py b/src/frontend/gui/sisyphus-gui.py index 7e7a703..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 * @@ -12,9 +13,17 @@ class Sisyphus(QtWidgets.QMainWindow): self.show() self.progress.hide() - Sisyphus.SFIELD = "name" # forced to 'name' until ui implementation - #print(Sisyphus.SFIELD) - self.loadDatabase(Sisyphus.SFIELD,"'%%'") + 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) @@ -35,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() @@ -58,7 +70,7 @@ class Sisyphus(QtWidgets.QMainWindow): ON a.category = i.category AND a.name = i.name AND a.slot = i.slot - WHERE a.%s LIKE %s + WHERE %s LIKE %s ''' % (searchField, searchTerm)) rows = cursor.fetchall() model = QtGui.QStandardItemModel(len(rows), 5) @@ -73,7 +85,7 @@ class Sisyphus(QtWidgets.QMainWindow): def filterDatabase(self): search = self.input.text() searchTerm = "'%" + search + "%'" - self.loadDatabase(Sisyphus.SFIELD,searchTerm) + self.loadDatabase(Sisyphus.SEARCHFIELD,searchTerm) def packageInstall(self): indexes = self.database.selectionModel().selectedRows(1) diff --git a/src/frontend/gui/ui/sisyphus-gui.ui b/src/frontend/gui/ui/sisyphus-gui.ui index 8dcedb8..3364640 100644 --- a/src/frontend/gui/ui/sisyphus-gui.ui +++ b/src/frontend/gui/ui/sisyphus-gui.ui @@ -71,43 +71,7 @@ 25 - - - - <html><head/><body><p align="center">Write package name and press Enter</p></body></html> - - - true - - - - - - - - 16777215 - 25 - - - - <html><head/><body><p align="center">Uninstall package</p></body></html> - - - - - - - ../icon/uninstall.png../icon/uninstall.png - - - - 16 - 16 - - - - - + QFrame::Panel @@ -145,35 +109,10 @@ false - - - Category - - - - - Name - - - - - Available Version - - - - - Installed Version - - - - - Description - - - - + + 16777215 @@ -181,14 +120,11 @@ - <html><head/><body><p align="center">Install package</p></body></html> - - - + <html><head/><body><p align="center">Upgrade system</p></body></html> - ../icon/install.png../icon/install.png + ../icon/upgrade.png../icon/upgrade.png @@ -198,8 +134,8 @@ - - + + 16777215 @@ -207,11 +143,14 @@ - <html><head/><body><p align="center">Exit Sisyphus</p></body></html> + <html><head/><body><p align="center">Install package</p></body></html> + + + - ../icon/exit.png../icon/exit.png + ../icon/install.png../icon/install.png @@ -221,8 +160,8 @@ - - + + 16777215 @@ -230,11 +169,14 @@ - <html><head/><body><p align="center">Upgrade system</p></body></html> + <html><head/><body><p align="center">Uninstall package</p></body></html> + + + - ../icon/upgrade.png../icon/upgrade.png + ../icon/uninstall.png../icon/uninstall.png @@ -244,7 +186,7 @@ - + @@ -270,6 +212,42 @@ + + + + + 16777215 + 25 + + + + <html><head/><body><p align="center">Exit Sisyphus</p></body></html> + + + + ../icon/exit.png../icon/exit.png + + + + 16 + 16 + + + + + + + + <html><head/><body><p align="center">Write package name and press Enter</p></body></html> + + + true + + + + + + -- cgit v1.2.3