sample: python gui python3 compat
This commit is contained in:
parent
52d3bfa54f
commit
48918e93a2
BIN
src/python/samples/recollgui/__pycache__/rclmain.cpython-35.pyc
Normal file
BIN
src/python/samples/recollgui/__pycache__/rclmain.cpython-35.pyc
Normal file
Binary file not shown.
@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import datetime
|
import datetime
|
||||||
@ -67,11 +68,11 @@ class RecollQuery(QtCore.QAbstractTableModel):
|
|||||||
|
|
||||||
def rowCount(self, parent):
|
def rowCount(self, parent):
|
||||||
ret = len(self.docs)
|
ret = len(self.docs)
|
||||||
#print "RecollQuery.rowCount(): ", ret
|
#print("RecollQuery.rowCount(): %d"% ret)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def columnCount(self, parent):
|
def columnCount(self, parent):
|
||||||
#print "RecollQuery.columnCount()"
|
#print("RecollQuery.columnCount()")
|
||||||
if parent.isValid():
|
if parent.isValid():
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
@ -79,7 +80,7 @@ class RecollQuery(QtCore.QAbstractTableModel):
|
|||||||
|
|
||||||
def setquery(self, db, q, sortfield="", ascending=True):
|
def setquery(self, db, q, sortfield="", ascending=True):
|
||||||
"""Parse and execute query on open db"""
|
"""Parse and execute query on open db"""
|
||||||
#print "RecollQuery.setquery():"
|
#print("RecollQuery.setquery():")
|
||||||
# Get query object
|
# Get query object
|
||||||
self.query = db.query()
|
self.query = db.query()
|
||||||
if sortfield:
|
if sortfield:
|
||||||
@ -98,7 +99,7 @@ class RecollQuery(QtCore.QAbstractTableModel):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def sort(self, col, order):
|
def sort(self, col, order):
|
||||||
#print "sort", col, order
|
#print("sort %s %s", (col, order))
|
||||||
self.setquery(self.db, self.qtext, sortfield=self.attrs[col],
|
self.setquery(self.db, self.qtext, sortfield=self.attrs[col],
|
||||||
ascending = order)
|
ascending = order)
|
||||||
|
|
||||||
@ -108,7 +109,7 @@ class RecollQuery(QtCore.QAbstractTableModel):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def data(self, index, role):
|
def data(self, index, role):
|
||||||
#print "RecollQuery.data: row %d, role: " % (index.row(),), role
|
#print("RecollQuery.data: row %d, role: %s" % (index.row(),role))
|
||||||
if not index.isValid():
|
if not index.isValid():
|
||||||
return QtCore.QVariant()
|
return QtCore.QVariant()
|
||||||
|
|
||||||
@ -116,8 +117,8 @@ class RecollQuery(QtCore.QAbstractTableModel):
|
|||||||
return QtCore.QVariant()
|
return QtCore.QVariant()
|
||||||
|
|
||||||
if role == QtCore.Qt.DisplayRole:
|
if role == QtCore.Qt.DisplayRole:
|
||||||
#print "RecollQuery.data: row %d, col %d role: " % \
|
#print("RecollQuery.data: row %d, col %d role: %s" % \
|
||||||
# (index.row(), index.column()), role
|
# (index.row(), index.column() role))
|
||||||
attr = self.attrs[index.column()]
|
attr = self.attrs[index.column()]
|
||||||
value = getattr(self.docs[index.row()], attr)
|
value = getattr(self.docs[index.row()], attr)
|
||||||
if attr == "mtime":
|
if attr == "mtime":
|
||||||
@ -128,14 +129,14 @@ class RecollQuery(QtCore.QAbstractTableModel):
|
|||||||
return QtCore.QVariant()
|
return QtCore.QVariant()
|
||||||
|
|
||||||
def canFetchMore(self, parent):
|
def canFetchMore(self, parent):
|
||||||
#print "RecollQuery.canFetchMore:"
|
#print("RecollQuery.canFetchMore:")
|
||||||
if len(self.docs) < self.totres:
|
if len(self.docs) < self.totres:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def fetchMore(self, parent):
|
def fetchMore(self, parent):
|
||||||
#print "RecollQuery.fetchMore:"
|
#print("RecollQuery.fetchMore:")
|
||||||
self.beginInsertRows(QtCore.QModelIndex(), len(self.docs), \
|
self.beginInsertRows(QtCore.QModelIndex(), len(self.docs), \
|
||||||
len(self.docs) + self.pagelen)
|
len(self.docs) + self.pagelen)
|
||||||
for count in range(self.pagelen):
|
for count in range(self.pagelen):
|
||||||
@ -155,11 +156,11 @@ class RclGui_Main(QMainWindow):
|
|||||||
self.ui.setupUi(self)
|
self.ui.setupUi(self)
|
||||||
self.db = db
|
self.db = db
|
||||||
self.qmodel = RecollQuery()
|
self.qmodel = RecollQuery()
|
||||||
scq = QShortcut(QKeySequence("Ctrl+Q"), self);
|
scq = QShortcut(QKeySequence("Ctrl+Q"), self)
|
||||||
scq.activated.connect(self.onexit)
|
scq.activated.connect(self.onexit)
|
||||||
header = self.ui.resTable.horizontalHeader();
|
header = self.ui.resTable.horizontalHeader()
|
||||||
header.setSortIndicatorShown(True);
|
header.setSortIndicatorShown(True)
|
||||||
header.setSortIndicator(-1, QtCore.Qt.AscendingOrder);
|
header.setSortIndicator(-1, QtCore.Qt.AscendingOrder)
|
||||||
self.ui.resTable.setSortingEnabled(True)
|
self.ui.resTable.setSortingEnabled(True)
|
||||||
self.currentindex = -1
|
self.currentindex = -1
|
||||||
self.currentdoc = None
|
self.currentdoc = None
|
||||||
@ -172,7 +173,7 @@ class RclGui_Main(QMainWindow):
|
|||||||
self.currentindex = index
|
self.currentindex = index
|
||||||
self.currentdoc = doc
|
self.currentdoc = doc
|
||||||
if doc is None:
|
if doc is None:
|
||||||
print "NO DoC"
|
print("NO DoC")
|
||||||
return
|
return
|
||||||
query = self.qmodel.query
|
query = self.qmodel.query
|
||||||
groups = query.getgroups()
|
groups = query.getgroups()
|
||||||
@ -181,7 +182,7 @@ class RclGui_Main(QMainWindow):
|
|||||||
self.ui.resDetail.setText(abs)
|
self.ui.resDetail.setText(abs)
|
||||||
if hasextract:
|
if hasextract:
|
||||||
ipath = doc.get('ipath')
|
ipath = doc.get('ipath')
|
||||||
#print "ipath[%s]" % (ipath,)
|
#print("ipath[%s]" % ipath)
|
||||||
self.ui.previewPB.setEnabled(True)
|
self.ui.previewPB.setEnabled(True)
|
||||||
if ipath:
|
if ipath:
|
||||||
self.ui.savePB.setEnabled(True)
|
self.ui.savePB.setEnabled(True)
|
||||||
@ -190,12 +191,12 @@ class RclGui_Main(QMainWindow):
|
|||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def on_previewPB_clicked(self):
|
def on_previewPB_clicked(self):
|
||||||
print "on_previewPB_clicked(self)"
|
print("on_previewPB_clicked(self)")
|
||||||
newdoc = textextract(self.currentdoc)
|
newdoc = textextract(self.currentdoc)
|
||||||
query = self.qmodel.query;
|
query = self.qmodel.query;
|
||||||
groups = query.getgroups()
|
groups = query.getgroups()
|
||||||
meths = HlMeths(groups)
|
meths = HlMeths(groups)
|
||||||
#print "newdoc.mimetype:", newdoc.mimetype
|
#print("newdoc.mimetype:", newdoc.mimetype)
|
||||||
if newdoc.mimetype == 'text/html':
|
if newdoc.mimetype == 'text/html':
|
||||||
ishtml = True
|
ishtml = True
|
||||||
else:
|
else:
|
||||||
@ -210,7 +211,7 @@ class RclGui_Main(QMainWindow):
|
|||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def on_savePB_clicked(self):
|
def on_savePB_clicked(self):
|
||||||
print "on_savePB_clicked(self)"
|
print("on_savePB_clicked(self)")
|
||||||
doc = self.currentdoc
|
doc = self.currentdoc
|
||||||
ipath = doc.ipath
|
ipath = doc.ipath
|
||||||
if not ipath:
|
if not ipath:
|
||||||
@ -219,9 +220,9 @@ class RclGui_Main(QMainWindow):
|
|||||||
if fn:
|
if fn:
|
||||||
docitems = doc.items()
|
docitems = doc.items()
|
||||||
fn = extractofile(doc, str(fn.toLocal8Bit()))
|
fn = extractofile(doc, str(fn.toLocal8Bit()))
|
||||||
print "Saved as", fn
|
print("Saved as %s" % fn)
|
||||||
else:
|
else:
|
||||||
print >> sys.stderr, "Canceled"
|
print("Canceled", file=sys.stderr)
|
||||||
|
|
||||||
def startQuery(self):
|
def startQuery(self):
|
||||||
self.qmodel.setquery(self.db, self.ui.searchEntry.text())
|
self.qmodel.setquery(self.db, self.ui.searchEntry.text())
|
||||||
@ -232,7 +233,7 @@ class RclGui_Main(QMainWindow):
|
|||||||
|
|
||||||
|
|
||||||
def Usage():
|
def Usage():
|
||||||
print >> sys.stderr, '''Usage: qt.py [<qword1> [<qword2> ...]]'''
|
print('''Usage: qt.py [<qword1> [<qword2> ...]]''', file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
@ -254,7 +255,7 @@ def main(args):
|
|||||||
elif opt == "-i":
|
elif opt == "-i":
|
||||||
extra_dbs.append(val)
|
extra_dbs.append(val)
|
||||||
else:
|
else:
|
||||||
print >> sys.stderr, "Bad opt: ", opt
|
print("Bad opt: %s"% opt, file=sys.stderr)
|
||||||
Usage()
|
Usage()
|
||||||
|
|
||||||
# The query should be in the remaining arg(s)
|
# The query should be in the remaining arg(s)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user