Exemple #1
0
class Login(QWidget):
    def __init__(self):
        super().__init__()
        uic.loadUi("ui/login.ui", self)

        username = self.findChild(QLineEdit, 'username')
        password = self.findChild(QLineEdit, 'password')
        login = self.findChild(QPushButton, 'login')
        login.clicked.connect(self.clicked_login)

    def clicked_login(self):
        # get data from user
        txtusername = self.username.text()
        txtpass = self.password.text()

        # get data from userdata.json file
        userdata = jsondata()
        info = userdata.getdata()

        if txtusername == info['username'] and txtpass == info['pass']:
            self.dashboard = Dashboard()
            self.dashboard.location_on_the_screen()
            self.dashboard.show()
            self.close()
        else:
            QMessageBox.about(self, "Error",
                              "Username or password is incorrect.")

    def location_on_the_screen(self):
        qr = self.frameGeometry()
        cp = QDesktopWidget().availableGeometry().center()
        qr.moveCenter(cp)
        self.move(qr.topLeft())
Exemple #2
0
class Settings(QWidget):
    def __init__(self):
        super().__init__()
        uic.loadUi("ui/setting.ui", self)

        # finding chields
        self.setpath = self.findChild(QLineEdit, 'databasepath')
        setpathbtn = self.findChild(QPushButton, 'newpathbtn')
        self.existingpath = self.findChild(QLineEdit, 'existingpath')
        findpathbtn = self.findChild(QPushButton, 'existingpathbtn')
        savesettings = self.findChild(QPushButton, 'save')

        # set signal for this btn
        setpathbtn.clicked.connect(self.setdatabasepath)
        findpathbtn.clicked.connect(self.findexistingpath)
        savesettings.clicked.connect(self.savesettings_func)

    def location_on_the_screen(self):
        qr = self.frameGeometry()
        cp = QDesktopWidget().availableGeometry().center()
        qr.moveCenter(cp)
        self.move(qr.topLeft())

    def setdatabasepath(self):
        folderpath = QFileDialog.getExistingDirectory()
        self.setpath.setText(folderpath)

    def findexistingpath(self):
        folderpath = QFileDialog.getExistingDirectory()
        self.existingpath.setText(folderpath)

    def savesettings_func(self):
        if self.existingpath.text() == '':
            path = self.setpath.text()
            userdata = jsondata()
            userdata.setdatapath(path + '/pdm_database')
            # creating pdm_database folder according to given path
            dirpath = os.path.join(path, 'pdm_database')
            os.mkdir(dirpath)
            dirpath = os.path.join(dirpath, 'images')
            os.mkdir(dirpath)
            # open dashboard
            self.dashboard = Dashboard()
            self.dashboard.location_on_the_screen()
            self.dashboard.show()
            self.close()
        elif self.setpath.text() == '':
            path = self.existingpath.text()
            userdata = jsondata()
            userdata.setdatapath(path)
            self.close()
        elif self.existingpath.text() != '' and self.setpath.text() != '':
            QMessageBox.about(self, "Error",
                              "You must provide only one of them.")
Exemple #3
0
class MyApp(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self):
        QtWidgets.QMainWindow.__init__(self)
        Ui_MainWindow.__init__(self)
        self.__dashboard__ = None
        self.setupUi(self)

        self.btn_exit.clicked.connect(self.Exit)
        self.btn_login.clicked.connect(self.Login)

    def Login(self):
        username = self.txt_username.text()
        password = self.txt_pwd.text()
        if username == "" and password == "":
            QMessageBox.about(
                self, 'Error',
                'Provide a Valid username and password to continue')
        else:
            cursor = connection.cursor()
            sql = "Select * from users where username=%s and pwd=%s"
            cursor.execute(sql, (username, password))
            result = cursor.fetchall()
            if int(len(result)) <= 0:
                QMessageBox.about(
                    self, "Error", "Invalid username and password. "
                    "Provide a valid username and password to continue ")
            else:
                self.__dashboard__ = Dashboard()
                self.__dashboard__.show()
                self.close()

    def Exit(self):
        reply = QMessageBox.question(self, "Exit?", "Would you like to exit?",
                                     QMessageBox.Yes | QMessageBox.No,
                                     QMessageBox.No)
        if reply == QMessageBox.Yes:
            sys.exit()
Exemple #4
0
    Path(TARGET_DIR).mkdir()
if not Path(CACHE_DIR).exists():
    Path(CACHE_DIR).mkdir()

clear_target()
clear_cache()

if not CACHE_DIR.joinpath('log.log').exists():
    CACHE_DIR.joinpath('log.log').open(mode='w')

logging.getLogger('werkzeug').setLevel(logging.ERROR)
logging.basicConfig(
    filename=CACHE_DIR.joinpath('log.log').as_posix(),
    filemode='a',
    level=logging.INFO,
    format='%(asctime)s,%(msecs)d | %(levelname)s — %(message)s',
    datefmt='%H:%M:%S')

# overwrite automated QApplication from ApplicationContext to include flags
# ApplicationContext.app = QApplication(sys.argv)

appctxt = ApplicationContext()  # 1. Instantiate ApplicationContext

main_window = QMainWindow()

db = Dashboard()
db.show()

exit_code = appctxt.app.exec_()  # 2. Invoke appctxt.app.exec_()
sys.exit(exit_code)
Exemple #5
0
from PyQt5 import QtCore, QtGui, QtWidgets
import PyQt5
import sys

from dashboard import Dashboard

if __name__ == '__main__':
    # this declares the event loop
    # every qt application requires this line to get running
    app = QtWidgets.QApplication(sys.argv)

    # add all the components that need to be ran under this comment (usually its the main display)
    # in this case it is the videowidget
    videowidget = Dashboard()
    videowidget.show()

    # start the event loop
    app.exec()