Commit 23bd69b3 authored by siguhe's avatar siguhe
Browse files

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

parents b15810de e420aac6
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
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)
+5 −17
Original line number Diff line number Diff line
@@ -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
+9 −15
Original line number Diff line number Diff line
@@ -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)
+18 −0
Original line number Diff line number Diff line
@@ -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):
+2 −9
Original line number Diff line number Diff line
@@ -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:
Loading