Commit 23bd69b3 authored by siguhe's avatar siguhe

Merge branch 'master' of https://git.omegav.no/ov/neokomp

parents b15810de e420aac6
import os
import sys
import math
from PyQt5 import QtCore, QtGui, QtWidgets
......@@ -18,13 +19,24 @@ class NeoKomp(QtWidgets.QMainWindow):
Top level class for NeoKomp
It Sets up each store frame
"""
def __init__(self, parent=None):
def __init__(self, config_path=None, parent=None):
super().__init__(parent)
self.parent = parent
with open ("apikey.key", "r") as myfile:
if config_path != None:
config_file_path = "%s/" % config_path
else:
config_file_path = ""
# Read in parameters
with open ("%sapikey.key" % config_file_path, "r") as myfile:
self.API_key = myfile.readline().rstrip("\n\r")
# Read in device <-> seksjon mapping as a dict
# device_mapping.txt must contain lines with <BLE Address> <Seksjon>
with open('%sdevice_mapping.txt' % config_file_path) as f:
self.device_mapping = dict(x.rstrip().split(None, 1) for x in f)
# Window Title
self.setWindowTitle("NeoKomp")
......@@ -47,10 +59,6 @@ class NeoKomp(QtWidgets.QMainWindow):
# Initial state
self.central_widget.setCurrentWidget(self.frames['Guide'])
# Read in device <-> seksjon mapping as a dict
# device_mapping.txt must contain lines with <BLE Address> <Seksjon>
with open('device_mapping.txt') as f:
self.device_mapping = dict(x.rstrip().split(None, 1) for x in f)
# Make RFID manager
self.rfid_manager = rfid.RFIDManager(self)
......
......@@ -19,31 +19,19 @@ class Balance(GenericFrame, TimedFrame):
self.installEventFilter(self)
def init_layout(self):
title_font = QtGui.QFont()
title_font.setPointSize(20)
self.title = QtWidgets.QLabel("Balance")
self.title.setFont(title_font)
self.layout.addWidget(self.title)
#Title
self.title.setText("Balance")
self.layout.addStretch()
name_font = QtGui.QFont()
name_font.setPointSize(30)
self.user_name = QtWidgets.QLabel("")
self.user_name.setFont(name_font)
self.user_balance = QtWidgets.QLabel("")
self.user_balance.setFont(name_font)
self.user_name = QtWidgets.QLabel("", font=self.user_font)
self.user_balance = QtWidgets.QLabel("", font=self.user_font)
self.layout.addWidget(self.user_name)
self.layout.addWidget(self.user_balance)
self.layout.addStretch()
## Timeout indicator
timeout_indicator_font = QtGui.QFont()
timeout_indicator_font.setPointSize(14)
self.timeout_indicator = QtWidgets.QLabel("")
self.timeout_indicator.setFont(timeout_indicator_font)
self.layout.addWidget(self.timeout_indicator)
## Help text
......@@ -51,7 +39,7 @@ class Balance(GenericFrame, TimedFrame):
Press <Return> to return to Main screen.
Start typing to search for a component."""
self.help_label = QtWidgets.QLabel(self.help_text)
self.help_label = QtWidgets.QLabel(self.help_text, font=self.help_font)
self.layout.addWidget(self.help_label)
# Navigation buttons
......
......@@ -29,11 +29,7 @@ class Cart(GenericFrame, TimedFrame):
def layout_init(self):
## Title
title_font = QtGui.QFont()
title_font.setPointSize(20)
self.title = QtWidgets.QLabel("Shopping Cart")
self.title.setFont(title_font)
self.layout.addWidget(self.title)
self.title.setText("Shopping Cart")
## Make cart
self.cart = QtWidgets.QTableWidget(0, len(self.headers))
......@@ -56,14 +52,10 @@ Press <Escape> to clear cart.
TODO: Scan RFID card to buy Cart.
"""
self.help_label = QtWidgets.QLabel(self.help_text)
self.help_label = QtWidgets.QLabel(self.help_text, font=self.help_font)
self.layout.addWidget(self.help_label)
## Timeout indicator
timeout_indicator_font = QtGui.QFont()
timeout_indicator_font.setPointSize(14)
self.timeout_indicator = QtWidgets.QLabel("")
self.timeout_indicator.setFont(timeout_indicator_font)
# Timeout indicator
self.layout.addWidget(self.timeout_indicator)
## Navigation buttons
......@@ -109,7 +101,6 @@ TODO: Scan RFID card to buy Cart.
else:
self.timeout_indicator.setText("")
# Install a custom eventFilter to capture enterPressed anywhere
def eventFilter(self, obj, event):
if event.type() == QtCore.QEvent.ShortcutOverride:
if (event.key() == QtCore.Qt.Key_Space):
......@@ -293,7 +284,7 @@ TODO: Scan RFID card to buy Cart.
if self.has_items():
self.restart_timer()
else:
self.clear_cart()
self.clear_cart('Guide')
return
self.cart.resizeColumnsToContents()
......@@ -309,8 +300,8 @@ TODO: Scan RFID card to buy Cart.
# Re-add total
self.add_total()
self.cart.resizeColumnsToContents()
self.update_total()
self.cart.resizeColumnsToContents()
# Nothing to see here, go to guide
self.parent.show_frame(next_frame)
......@@ -322,7 +313,10 @@ TODO: Scan RFID card to buy Cart.
items = []
for row in range(row_count - 1):
items.append(self.cart.item(row, 0).data(QtCore.Qt.UserRole))
item = self.cart.item(row, 0).data(QtCore.Qt.UserRole)
count = self.cart.item(row, 3).text()
item['cart_count'] = count
items.append(item)
if len(items) == 0:
self.parent.show_balance(rfid)
......
......@@ -9,6 +9,19 @@ class GenericFrame(QtWidgets.QWidget):
## General vertical layout
self.layout = QtWidgets.QVBoxLayout(self)
# Fonts
self.title_font = QtGui.QFont()
self.title_font.setPointSize(20)
self.help_font = QtGui.QFont()
self.help_font.setPointSize(10)
self.user_font = QtGui.QFont()
self.user_font.setPointSize(30)
# Title. NOTE: Must be added to layout by derived class
self.title = QtWidgets.QLabel("", font=self.title_font)
self.layout.addWidget(self.title)
# This function should be redefined by those frames that need special
# actions on focus
def focus(self):
......@@ -30,6 +43,11 @@ class TimedFrame(QtWidgets.QWidget):
self.timeout_timer.setSingleShot(True)
self.timeout_timer.timeout.connect(self.timeout)
## Timeout indicator. NOTE: Must be added to layout by derived class
self.timeout_indicator_font = QtGui.QFont()
self.timeout_indicator_font.setPointSize(14)
self.timeout_indicator = QtWidgets.QLabel("", font=self.timeout_indicator_font)
self.parent.indicator_timer.timeout.connect(self.update_timeout_indicator)
def restart_timer(self):
......
......@@ -16,11 +16,7 @@ class Guide(GenericFrame):
def init_layout(self):
## Title
title_font = QtGui.QFont()
title_font.setPointSize(20)
self.title = QtWidgets.QLabel("How-To")
self.title.setFont(title_font)
self.layout.addWidget(self.title)
self.title.setText("Guide Page")
self.layout.addStretch()
......@@ -35,8 +31,7 @@ Start typing to search for a component, which can be added to your cart.
TODO: Scan a bar code to add the item to your cart.
Select a component via a section module to add the item to your cart."""
self.help_label = QtWidgets.QLabel(font=title_font)
self.help_label.setText(self.help_text)
self.help_label = QtWidgets.QLabel(self.help_text, font=self.title_font)
self.layout.addWidget(self.help_label)
self.layout.addStretch()
......@@ -59,8 +54,6 @@ Select a component via a section module to add the item to your cart."""
self.layout.addLayout(self.navigation_buttons)
# Install a custom eventFilter to focus switch to search when starting to write
def eventFilter(self, obj, event):
if event.type() == QtCore.QEvent.ShortcutOverride:
......
......@@ -18,26 +18,22 @@ class Receipt(GenericFrame, TimedFrame):
self.installEventFilter(self)
def init_layout(self):
title_font = QtGui.QFont()
title_font.setPointSize(20)
self.title = QtWidgets.QLabel("Receipt", font=title_font)
self.layout.addWidget(self.title)
self.title.setText("Receipt")
## TODO: Add image?
self.layout.addStretch(1)
## Purchase information
receipt_font = QtGui.QFont()
receipt_font.setPointSize(50)
self.purchase_info = QtWidgets.QHBoxLayout()
self.purchase_heads = QtWidgets.QVBoxLayout()
self.purchase_tails = QtWidgets.QVBoxLayout()
self.head1 = QtWidgets.QLabel("", font=title_font)
self.head2 = QtWidgets.QLabel("", font=title_font)
self.head3 = QtWidgets.QLabel("", font=title_font)
self.tail1 = QtWidgets.QLabel("", font=title_font)
self.tail2 = QtWidgets.QLabel("", font=title_font)
self.tail3 = QtWidgets.QLabel("", font=title_font)
self.head1 = QtWidgets.QLabel("", font=self.user_font)
self.head2 = QtWidgets.QLabel("", font=self.user_font)
self.head3 = QtWidgets.QLabel("", font=self.user_font)
self.tail1 = QtWidgets.QLabel("", font=self.user_font)
self.tail2 = QtWidgets.QLabel("", font=self.user_font)
self.tail3 = QtWidgets.QLabel("", font=self.user_font)
self.purchase_heads.addWidget(self.head1)
self.purchase_heads.addWidget(self.head2)
......@@ -47,15 +43,17 @@ class Receipt(GenericFrame, TimedFrame):
self.purchase_tails.addWidget(self.tail3)
self.purchase_info.addStretch(1)
self.purchase_info.addLayout(self.purchase_heads)
self.purchase_info.addLayout(self.purchase_tails)
self.purchase_info.addStretch(1)
self.layout.addLayout(self.purchase_info)
self.layout.addStretch(1)
self.timeout_indicator = QtWidgets.QLabel("")
# Timeout indicator label
self.layout.addWidget(self.timeout_indicator)
## Help text
......@@ -63,7 +61,7 @@ class Receipt(GenericFrame, TimedFrame):
Press <Return> to return to Main screen.\n\
Start typing to search for a component.\n\
TODO: Scan RFID card to show Balance."
self.help_label = QtWidgets.QLabel(self.help_text)
self.help_label = QtWidgets.QLabel(self.help_text, font=self.help_font)
self.layout.addWidget(self.help_label)
# Navigation buttons
......@@ -130,9 +128,16 @@ TODO: Scan RFID card to show Balance."
price = int(item['pris'])
if price < 0:
price = 0
except:
except ValueError:
price = 0
total += price
try:
count = int(item['cart_count'])
if count < 1:
count = 1
except ValueError:
count = 1
total += (price * count)
print("Price for all items: " + str(total))
......@@ -156,15 +161,26 @@ TODO: Scan RFID card to show Balance."
bought = []
failed = []
# Loop through and order each item in turn
# For each item, check that it was bought
for item in items:
try:
count = int(item['cart_count'])
if count < 1:
count = 1
except ValueError:
count = 1
lager = item['lager'][item['lager_choice']]
buy_success = API.API_buy(rfid, lager['rom'], lager['seksjon'], lager['hylle'], lager['rad'], lager['kolonne'], lager['dybde'], self.parent.API_key, None)
if buy_success:
bought.append(item)
else:
failed.append(item)
for x in range(count):
buy_success = API.API_buy(rfid, lager['rom'], lager['seksjon'], lager['hylle'], lager['rad'], lager['kolonne'], lager['dybde'], self.parent.API_key, None)
if buy_success:
bought.append(item)
else:
failed.append(item)
if len(failed):
print("Failed to buy:")
......
......@@ -39,11 +39,8 @@ class Search(GenericFrame, TimedFrame):
self.locations_layout = None
def layout_init(self):
title_font = QtGui.QFont()
title_font.setPointSize(20)
self.title = QtWidgets.QLabel("Search Page")
self.title.setFont(title_font)
self.layout.addWidget(self.title)
#Title
self.title.setText("Search Page")
# Make search bar
self.search_bar = QtWidgets.QHBoxLayout()
......@@ -52,8 +49,10 @@ class Search(GenericFrame, TimedFrame):
self.search_entry.setPlaceholderText('f.ex raspberry')
self.search_entry.setFocusPolicy(QtCore.Qt.StrongFocus)
self.search_entry.returnPressed.connect(self.search)
self.search_indicator = QtWidgets.QLabel("")
self.search_indicator.setMinimumWidth(200)
self.search_bar.addWidget(self.search_promt)
self.search_bar.addWidget(self.search_entry)
self.search_bar.addWidget(self.search_indicator)
......@@ -80,7 +79,7 @@ class Search(GenericFrame, TimedFrame):
self.bottom_right_layout = QtWidgets.QVBoxLayout()
self.bottom_layout.addLayout(self.bottom_right_layout)
## Help text
# Help text
self.help_text = """\
Type search text and press <Return> to look up components.
......@@ -91,19 +90,15 @@ Press <Return> on a selected component to add it to the cart.
Double click an item to add it to the cart."""
self.help_label = QtWidgets.QLabel(self.help_text)
self.help_label = QtWidgets.QLabel(self.help_text, font=self.help_font)
self.bottom_left_layout.addWidget(self.help_label)
## Timeout indicator
timeout_indicator_font = QtGui.QFont()
timeout_indicator_font.setPointSize(14)
self.timeout_indicator = QtWidgets.QLabel("")
self.timeout_indicator.setFont(timeout_indicator_font)
# Timeout indicator label
self.bottom_left_layout.addWidget(self.timeout_indicator)
self.layout.addStretch()
## Navigation buttons
# Navigation buttons
self.navigation_buttons = QtWidgets.QHBoxLayout()
self.goto_guide_button = QtWidgets.QPushButton("Go to Guide", self)
......@@ -130,10 +125,10 @@ Double click an item to add it to the cart."""
if event.type() == QtCore.QEvent.KeyPress:
if (event.key() == QtCore.Qt.Key_Return):
if self.search_entry.hasFocus():
return False # ?
return False
else:
self.return_pressed()
return True # ?
return True
if (event.key() == QtCore.Qt.Key_Escape):
self.stop_search()
self.leave_search()
......
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
import NeoKomp
def main():
app = QtWidgets.QApplication([])
neokomp = NeoKomp.NeoKomp()
if (len(sys.argv) > 1):
neokomp = NeoKomp.NeoKomp(config_path=sys.argv[1])
else:
neokomp = NeoKomp.NeoKomp()
neokomp.setWindowTitle("NeoKomp")
neokomp.show()
app.exec_()
......
Subproject commit f9b92018f16c113a66dc9fcadb49f7f04147f8af
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