Example #1
0
    @cached_property
    def get_database(self):
        return self.get_resource('database/resturant_database.db')

    @cached_property
    def cancel_icon(self):
        return QIcon(self.get_resource('icons/cross-button.png'))

    @cached_property
    def logout_icon(self):
        return QIcon(self.get_resource('icons/control-power.png'))

    @cached_property
    def about_logo(self):
        return QPixmap(self.get_resource('icons/restaurant128.png'))

    @cached_property
    def window_icon(self):
        return QIcon(self.get_resource('icons/restaurant64.png'))


if __name__ == '__main__':
    
    appctxt = MyApplicationContext()     # 1. Instantiate ApplicationContext

    window = LoginWindow(appctxt)
    window.show()

    exit_code = appctxt.app.exec_()      # 2. Invoke appctxt.app.exec_()
    sys.exit(exit_code)
class AdminWindow(QMainWindow, Ui_MainWindow):

    """
    Ui_MainWindow:  Class containing widgets and their respective settings
    context:        This is the overall application context, containing
                    resources used through out the app.

    Seriously aren't the variable names and function names intuitive enough?
    """

    def __init__(self, context, *args, **kwargs):
        super(AdminWindow, self).__init__(*args, **kwargs)
        
        self.context = context
        self.setupUi(self)      # create widgets from Ui_MainWindow
        self.setWindowIcon(self.context.window_icon)
        self.load_tables()      # create tables from database

        self.actionAbout.setIcon(self.context.about_icon)
        self.actionAbout.triggered.connect(self.show_about)
        
        self.actionLog_Out.setIcon(self.context.logout_icon)
        self.actionLog_Out.triggered.connect(self.logout)

        self.add_product_button.clicked.connect(self.add_product)
        
        self.delete_product_button.clicked.connect(lambda: self.product_model.removeRow(
            self.product_table_view.currentIndex().row()))

        self.add_user_button.clicked.connect(self.add_user)

        self.delete_user_button.clicked.connect(
            lambda: self.users_model.removeRow(
                self.user_table_view.currentIndex().row()
        ))

    def show_about(self):
        dlg = AboutDialog(self.context, self)
        dlg.exec_()

    def load_tables(self):
        self.connect_database()
        self.load_products_table()
        self.load_users_table()
        self.load_orders_table()

    def connect_database(self):
        # connection to database and open connection
        db = QSqlDatabase.addDatabase('QSQLITE')
        db.setDatabaseName(self.context.get_database)
        db.open()

    def load_products_table(self):
        # The model used by the view
        self.product_model = QSqlTableModel()
        self.product_model.setTable('products')
        self.product_model.setEditStrategy(QSqlTableModel.OnFieldChange)
        self.product_model.select()

        # Use the product model as the model. MV programming
        self.product_table_view.setModel(self.product_model)

    def load_users_table(self):
        self.users_model = QSqlTableModel()
        self.users_model.setTable('users')
        self.users_model.setEditStrategy(QSqlTableModel.OnFieldChange)

        self.users_model.select()

        self.user_table_view.setModel(self.users_model)

    def load_orders_table(self):
        self.orders_model = QSqlTableModel()
        self.orders_model.setTable('orders')

        self.orders_model.select()

        self.orders_table_view.setModel(self.orders_model)

    def logout(self):
        # Go to login window
        self.loginwindow = LoginWindow(context=self.context)
        self.loginwindow.show()
        self.hide()

    def add_product(self):
        self.product_model.insertRows(self.product_model.rowCount(), 1)

    def add_user(self):
        self.users_model.insertRows(self.users_model.rowCount(), 1)
 def logout(self):
     # Go to login window
     self.loginwindow = LoginWindow(context=self.context)
     self.loginwindow.show()
     self.hide()
class SalesWindow(QMainWindow, Ui_MainWindow):
    """
    username:   current user login, whose name transactions
                will be carried on with

    context:    The Application context that controls the whole
                app and contains all resources
    """

    products_in_checkout = set()

    def __init__(self, username, context, *args, **kwargs):
        super(SalesWindow, self).__init__(*args, **kwargs)

        self.username = username
        self.context = context
        self.setupUi(self)
        self.setWindowIcon(self.context.window_icon)
        self.get_product_list()

        self.username_label.setText(self.username.title())
        self.actionLog_Out.setIcon(self.context.logout_icon)
        self.actionAbout.setIcon(self.context.about_icon)
        self.actionAbout.triggered.connect(self.show_about)

        self.actionLog_Out.triggered.connect(self.logout)
        self.closing_sales_button.clicked.connect(self.select_duration)
        self.populate_combobox()

        self.items_combobox.currentTextChanged.connect(self.add_to_checkout)
        self.done_button.clicked.connect(self.checkout)

    def show_about(self):
        dlg = AboutDialog(self.context, self)
        dlg.exec_()

    def logout(self):
        self.loginwindow = LoginWindow(self.context)
        self.loginwindow.show()
        self.hide()

    def checkout(self):
        dlg = CheckoutConfirmationDialog(self)

        if dlg.exec_():
            self.perform_transaction()
            self.clear_screen()
            print('Success')
        else:
            print('Cancel')

    def select_duration(self):
        """Creates a dialog containg two datetime edit widgets"""

        dlg = ClosingSalesDialog(self.context, self.username, self)

        if dlg.exec_():
            print('Success!')
        else:
            print("Cancel!")

    def connect_database(self):
        db = QSqlDatabase.addDatabase('QSQLITE')
        db.setDatabaseName(self.context.get_database)
        db.open()

    def populate_combobox(self):
        self.connect_database()
        model = QSqlTableModel()
        model.setTable('products')
        column = model.fieldIndex('name')
        model.select()
        self.items_combobox.setModel(model)
        self.items_combobox.setModelColumn(column)

    def add_to_checkout(self, currenttext):
        # check if product already in checkout
        for product in self.product_list:
            if product.name == currenttext:
                break

        self.process_product(product)

    def process_product(self, product):
        if not product.in_checkout:
            product.in_checkout = True
            self.products_in_checkout.add(product)
            self.add_create_product_layout(product)

    def add_create_product_layout(self, product):
        item = ProductFrame(product, self.context, self)
        item.no_label.setText(str(0))
        self.checkout_layout.addWidget(item)

    def calculate_total(self):
        self.total_label.setText(
            str(sum(product.subtotal
                    for product in self.products_in_checkout)))

    def update_database(self, product):
        now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")

        with DBHandler(self.context.get_database) as cursor:
            update_SQL = """
                    UPDATE products SET 
                    quantity_in_stock = quantity_in_stock - ?
                    """

            insert_SQL = """
                            INSERT INTO orders VALUES (?, ?, ?, ?, ?, ?)
                        """

            cursor.execute(update_SQL, [product.quantity])
            cursor.execute(insert_SQL, [
                None, self.username, now, product.name, product.quantity,
                product.subtotal
            ])

            print('Success')

    def perform_transaction(self):
        for product in self.products_in_checkout:
            self.update_database(product)
            product.in_checkout = False
            product.quantity = 0

    def clear_screen(self):

        for i in reversed(range(self.checkout_layout.count())):
            self.checkout_layout.itemAt(i).widget().setParent(None)

        for product in self.products_in_checkout:
            reset(product)

        self.products_in_checkout.clear()
        self.total_label.setText(str('0'))

    def get_product_list(self):
        with DBHandler(self.context.get_database) as cursor:
            cursor.execute("SELECT * FROM products")
            results = cursor.fetchall()

            # Genexpr to get all items from database
            self.product_list = [
                self._Product(*value) for _, value in enumerate(results)
            ]

    class _Product:
        """
            This is a private class that holds attributes of
            each product.
            """
        def __init__(self, name, price, remaining_stock):
            self.name = name
            self.quantity = 0
            self.price = price
            self.remaining_stock = remaining_stock
            self.in_checkout = False

        @property
        def subtotal(self):
            return self.price * self.quantity

        def __str__(self):
            return str(self.name)
 def logout(self):
     self.loginwindow = LoginWindow(self.context)
     self.loginwindow.show()
     self.hide()
Example #6
0
import sys
from PyQt5.QtWidgets import QApplication
from loginwindow import LoginWindow

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = LoginWindow()
    window.show()
    sys.exit(app.exec_())
Example #7
0
import sys, socket
from PyQt4 import QtCore, QtGui

from account import Account
from mainwindow import MainWindow
from loginwindow import LoginWindow

if __name__ == '__main__':
    try:
        # Prevent hanging for remote connections
        socket.setdefaulttimeout(10)

        app = QtGui.QApplication(sys.argv)
        app.connect(app, QtCore.SIGNAL('lastWindowClosed()'), app, QtCore.SLOT('quit()'))

        account = Account()

        mainWindow = MainWindow(app, QtCore.QSettings('iiMonitor', 'Undefined Fire'), account)
        mainWindow.setWindowIcon(QtGui.QIcon('rc/tray-yr.png'))
        mainWindow.show()

        loginWindow = LoginWindow(app, mainWindow.settings, account, mainWindow)
        mainWindow.setLoginWindow(loginWindow)
        loginWindow.setWindowIcon(QtGui.QIcon('rc/tray-yr.png'))
        loginWindow.login()
    except:
        print 'Something went wrong'
        sys.exit(1)

    sys.exit(app.exec_())
Example #8
0
os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1"

api = API()
db = Database()

if __name__ == '__main__':
    app = QApplication(sys.argv)

    data = api.whoami(db.readDatabase()['userdata']['api_token'])
    print(data)

    try:
        if data == None:
            raise ApiException('Error could not connect to api')
        if data.get('error'):
            login = LoginWindow()
            trayIcon = SystemTrayIcon(QIcon(Config.icon))
            #Maybe move this inside the SystemTray class, keep the main clean yo
            trayIcon.StartWorking.setEnabled(False)
            trayIcon.dashboard.setEnabled(False)
            trayIcon.settings.setEnabled(False)
            trayIcon.timer.setEnabled(False)
            trayIcon.show()
            #lol.button.clicked.connect(run)#self.button.clicked
            if login.exec_() == QDialog.Accepted:
                ex = TimerWindow()
                trayIcon.ex = ex
                trayIcon.StartWorking.setEnabled(True)
                trayIcon.dashboard.setEnabled(True)
                trayIcon.settings.setEnabled(True)
                trayIcon.timer.setEnabled(True)
Example #9
0
 def login(self):
     """Run login dialog and get the api_conn set up"""
     login = LoginWindow(self)
     login.exec_()
     self.connected = True
Example #10
0
 def login(self):
     """Run login dialog and get the api_conn set up"""
     login = LoginWindow(self)
     login.exec_()
     self.connected = True