Commit bce30485 authored by magho's avatar magho

added images and warnings

parent 7e9e995c
import sys
import math
from PyQt5 import QtCore, QtGui, QtWidgets
from frames.FrameBase import GenericFrame, TimedFrame
from frames.FrameBase import GenericFrame, TimedFrame, TimerMessageBox
import api_communication as API
......@@ -144,8 +144,13 @@ TODO: Scan RFID card to buy Cart.
if (row < self.cart.rowCount() - 1):
self.remove_row(row)
def add_item_from_location(self, loc):
item = API.AJAX_search_component_pos(loc['rom'], loc['seksjon'], loc['hylle'], loc['rad'], loc['kolonne'], loc['dybde'])
def add_item_from_location(self, location):
item = API.AJAX_search_component_pos(location['rom'],
location['seksjon'],
location['hylle'],
location['rad'],
location['kolonne'],
location['dybde'])
print(item)
if item != None and 'error' not in item.keys():
# Add lager choice
......@@ -159,6 +164,20 @@ TODO: Scan RFID card to buy Cart.
self.add_item(item)
self.parent.show_frame('Cart')
elif item == None:
# Send warning no item found
none_message = "API failed to return an item for location {0}.".format(location)
warning = TimerMessageBox(message=none_message, parent=self)
warning.setIcon(QtWidgets.QMessageBox.Critical)
warning.exec_()
return
elif 'error' in item.keys():
# Warn about API error
api_message = "API returned error '{0}' for location '{1}.".format(item['error'], location)
warning = TimerMessageBox(message=api_message, parent=self)
warning.setIcon(QtWidgets.QMessageBox.Critical)
warning.exec_()
return
def has_items(self):
return self.cart.rowCount() >= 2
......
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5 import QtCore, QtGui, QtWidgets, QtSvg
class GenericFrame(QtWidgets.QWidget):
def __init__(self, **kwargs):
......@@ -17,9 +17,20 @@ class GenericFrame(QtWidgets.QWidget):
self.user_font = QtGui.QFont()
self.user_font.setPointSize(30)
# Title. NOTE: Must be added to layout by derived class
# Title Bar. NOTE: Title text must be added to layout by derived class
self.title = QtWidgets.QLabel("", font=self.title_font)
self.layout.addWidget(self.title)
self.title_bar = QtWidgets.QHBoxLayout()
self.title_bar.addWidget(self.title)
self.title_bar.addStretch()
self.banner = QtSvg.QSvgWidget('./omegav_text.svg')
banner_height = 30
self.banner.setMaximumHeight(banner_height)
self.banner.setMaximumWidth(banner_height*7.7788)
self.title_bar.addWidget(self.banner)
self.layout.addLayout(self.title_bar)
# This function should be redefined by those frames that need special
......@@ -57,3 +68,26 @@ class TimedFrame(QtWidgets.QWidget):
def stop_timer(self):
self.timeout_timer.stop()
class TimerMessageBox(QtWidgets.QMessageBox):
def __init__(self, timeout=10, message="Empty message", parent=None):
super(TimerMessageBox, self).__init__(parent)
self.message = message
self.setWindowTitle("Message")
self.time_to_wait = timeout
self.setText("{0} [Closing automatically in {1} seconds.]".format(self.message, timeout))
self.setStandardButtons(QtWidgets.QMessageBox.Ok)
self.timer = QtCore.QTimer(self)
self.timer.setInterval(1000)
self.timer.timeout.connect(self.changeContent)
self.timer.start()
def changeContent(self):
self.setText("{0} [Closing automatically in {1} seconds.]".format(self.message, self.time_to_wait))
self.time_to_wait -= 1
if self.time_to_wait <= 0:
self.close()
def closeEvent(self, event):
self.timer.stop()
event.accept()
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5 import QtCore, QtGui, QtWidgets, QtSvg
from frames.FrameBase import GenericFrame
class Guide(GenericFrame):
......@@ -18,6 +18,18 @@ class Guide(GenericFrame):
## Title
self.title.setText("Guide Page")
# OV Logo Layout
self.logo_layout = QtWidgets.QHBoxLayout()
self.logo_svg = QtSvg.QSvgWidget('./omegav_logo.svg')
self.logo_svg.setMaximumHeight(400)
self.logo_svg.setMaximumWidth(400)
self.logo_layout.addStretch()
self.logo_layout.addWidget(self.logo_svg)
self.logo_layout.addStretch()
self.layout.addLayout(self.logo_layout)
self.layout.addStretch()
## Help text
......
import sys
import math
from PyQt5 import QtCore, QtGui, QtWidgets
from frames.FrameBase import GenericFrame, TimedFrame
from frames.FrameBase import GenericFrame, TimedFrame, TimerMessageBox
import api_communication as API
......@@ -294,15 +294,35 @@ Double click an item to add it to the cart."""
for index in lager.keys():
if index != 'count' and lager[index]['type'] == 'Fremlager' and lager[index]['rom'] == 'OV':
lager_choice = index
# If a fremlager is found, we break so that lager_choice
# doesn't get overridden by a baklager
break
elif index != 'count' and lager[index]['type'] == 'Baklager' and lager[index]['rom'] == 'GM':
lager_choice = index
if lager_choice == None:
# Display critical warning
missing_message = "No valid storage position was found for this item. Please contact a workshop board member."
warning = TimerMessageBox(message=baklager_message, parent=self)
warning.setIcon(QtWidgets.QMessageBox.Critical)
warning.exec_()
return
if lager_choice != None:
item['lager_choice'] = lager_choice
else:
print("TODO: display warning")
# Display warning
if lager[lager_choice]['type'] == 'Baklager':
# Display baklager warning
# TODO: Allow customers to buy from baklager?
baklager_message = "This item is only available at a Baklager. Please contact a board member to buy this item."
warning = TimerMessageBox(message=baklager_message, parent=self)
warning.setIcon(QtWidgets.QMessageBox.Critical)
warning.exec_()
return
# Add lager_choice
item['lager_choice'] = lager_choice
# Add item
self.parent.frames['Cart'].add_item(item)
self.parent.show_frame('Cart')
self.stop_timer()
......
This diff is collapsed.
This diff is collapsed.
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