Commit 0171f349 authored by magho's avatar magho

added the ability to stop timer in cart

parent 1b27ecf5
......@@ -51,6 +51,8 @@ class Cart(GenericFrame, TimedFrame):
## Help text
self.help_text = """Press <Return> to remove selected item.
Double click item to remove item.
Press <Space> to stop timeout.
Press <Escape> to clear cart.
TODO: Scan RFID card to buy Cart.
"""
......@@ -110,10 +112,19 @@ TODO: Scan RFID card to buy Cart.
# Install a custom eventFilter to capture enterPressed anywhere
def eventFilter(self, obj, event):
if event.type() == QtCore.QEvent.ShortcutOverride:
self.restart_timer()
if event.text().isalnum():
self.parent.show_frame('Search')
return False # ?
if (event.key() == QtCore.Qt.Key_Space):
# <Space> stops timeout so people can have as much time as they
# need
self.stop_timer()
return True
else:
if(self.timeout_timer.isActive()):
# Only restart the timer on activity if it's already
# running
self.restart_timer()
if event.text().isalnum():
self.parent.show_frame('Search')
return False
elif event.type() == QtCore.QEvent.KeyPress:
if event.key() == QtCore.Qt.Key_Return:
......@@ -124,7 +135,11 @@ TODO: Scan RFID card to buy Cart.
self.clear_cart('Guide')
return True
else:
self.restart_timer()
# Only restart the timer on activity if it's already
# running
if(self.timeout_timer.isActive()):
self.restart_timer()
return True
# Pass event to QWidget
return super(Cart, self).eventFilter(obj, event)
......@@ -229,7 +244,7 @@ TODO: Scan RFID card to buy Cart.
row = row_positions
# Merge the initial cells
self.cart.setSpan(row, 0, 1, 2)
self.cart.setSpan(row, 0, 1, 4)
title_table_item = QtWidgets.QTableWidgetItem("TOTAL:")
title_table_item.setFlags(QtCore.Qt.ItemIsEnabled)
......
......@@ -83,7 +83,6 @@ class Search(GenericFrame, TimedFrame):
## Help text
self.help_text = """\
Type search text and press <Return> to look up components.
Another <Return> clears search.
Press <Escape> to quit search.
......@@ -135,6 +134,10 @@ Double click an item to add it to the cart."""
else:
self.return_pressed()
return True # ?
if (event.key() == QtCore.Qt.Key_Escape):
self.stop_search()
self.leave_search()
return True
if event.type() == QtCore.QEvent.ShortcutOverride:
if event.text().isalnum():
......@@ -180,12 +183,20 @@ Double click an item to add it to the cart."""
@QtCore.pyqtSlot()
def timeout(self):
# Stop any ongoing search
self.stop_search()
self.leave_search()
def stop_search(self):
# Stop any ongoing search thread
if (self.search_querier and self.search_querier.isRunning()):
self.search_should_stop = True
self.search_querier.wait(3000)
self.search_should_stop = False
#Clear it and go to guide
self.clear_search()
def leave_search(self):
self.stop_timer()
if self.parent.cart_has_items():
self.parent.show_frame('Cart')
......@@ -310,13 +321,7 @@ Double click an item to add it to the cart."""
return text
def search(self):
# Stop any ongoing search thread
if (self.search_querier and self.search_querier.isRunning()):
self.search_should_stop = True
self.search_querier.wait(3000)
self.search_should_stop = False
self.clear_search()
self.stop_search()
# Get query string
query_string = self.get_entry_text()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment