Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from mysql.connector import (connection)
- from datetime import *
- from RPI1_ui import Ui_Form
- '''Handling of database related stuff'''
- class DatabaseUtility(Ui_Form):
- def __init__(self):
- #DB Connection
- self.cnx = None
- self.cursor = None
- def mysql_connect(self):
- # Database connection
- try:
- self.cnx = connection.MySQLConnection(user='root', password='', host='127.0.0.1', database='spicadb')
- self.cursor = self.cnx.cursor()
- except connection.errors.InterfaceError as e:
- self.lblShowInfo.setText(str(e)) # -> Try to change label
- def get_table(self):
- return self.run_command("SELECT * FROM tblseal")
- def get_columns(self):
- return self.run_command("SHOW COLUMNS FROM tblseal")
- from PyQt5.QtWidgets import QApplication, QWidget, QDialog
- from mysql.connector import (connection)
- from datetime import *
- from bs4 import BeautifulSoup as bs
- import os
- import sys
- import DatabaseHandling
- '''Convert UI file to Python'''
- os.chdir("C:\UsersGianni DeclercqAppDataLocalProgramsPythonPython36-32Scripts")
- os.system("pyuic5.exe H:QtProjects\RPI1.ui -o H:QtProjects\RPI1_ui.py")
- from RPI1_ui import Ui_Form # import after recreation of py file
- from RPI1_Sec import SecondWindow
- '''Main program'''
- class MainWindow(QWidget, Ui_Form):
- def __init__(self):
- super(MainWindow, self).__init__()
- # Initialize variables
- self.dbu = DatabaseHandling.DatabaseUtility()
- self.spica_reference = None
- self.barcode = None
- self.msl = None
- self.package_body = None
- self.window2 = None
- # Get UI elements + resize window
- self.setupUi(self)
- self.resize(800, 480)
- # Define what should happen on button click
- self.btnQuit.clicked.connect(lambda: app.exit())
- self.btnInsert.clicked.connect(lambda: self.get_entry())
- self.btnTable.clicked.connect(lambda: self.new_window())
- # Style buttons
- self.btnQuit.setStyleSheet("background-color: red")
- self.btnInsert.setStyleSheet("background-color: green")
- self.btnTable.setStyleSheet("background-color: orange")
- def get_entry(self):
- try:
- self.spica_reference = self.txtReferentie.text()
- self.barcode = self.txtBarcode.text()
- self.msl = self.txtMsl.text()
- self.package_body = float(self.txtBodyPackage.text())
- except ValueError:
- self.lblShowInfo.setText("Please insert the correct values")
- self.lblShowInfo.setStyleSheet('color: red')
- else:
- self.dbu.mysql_connect()
- if self.dbu.cursor and self.dbu.cnx is not None:
- self.dbu.add_entry(self.spica_reference, self.barcode, self.msl, self.package_body, self.calc_floor_life)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement