示例#1
0
    def closeEvent(self, event):

        self.hide()

        from Gunshot_Detection_WINDOW_ADVANCE_SETTING import AdvanceSettingWindow
        self.dialog = AdvanceSettingWindow(self)
        self.dialog.exec_()
    def closeEvent(self, event):

        # closing Dummy Recording Box here.
        self.hide()

        # opening the Advance setting Dialog here.
        from Gunshot_Detection_WINDOW_ADVANCE_SETTING import AdvanceSettingWindow
        self.dialog = AdvanceSettingWindow(self)
        self.dialog.exec_()
示例#3
0
    def on_click_advanceButton(self):

        # saving the last known postion of the main window so that another window can appear on the same position.
        self.settings = QSettings(" ", " ")
        self.settings.setValue("geometry", self.saveGeometry())
        self.settings.setValue("windowState", self.saveState())

        # showing the blur image over the background.
        self.label_blur_img.show()

        # Showing dialog box on the burron click event.
        self.dialog = AdvanceSettingWindow(self)
        self.dialog.exec_()

        self.label_blur_img.hide()
示例#4
0
    def on_click_train(self):

        # saving the last known postion of the main window so that another window can appear on the same position.
        self.settings = QSettings(" ", " ")
        self.settings.setValue("geometry", self.saveGeometry())
        self.settings.setValue("windowState", self.saveState())

        # Poping up the training window.
        #----------------------------------------------------------------------
        self.dialog = TrainWindow()
        self.dialog.show()

        # hiding up the main window.
        #----------------------------------------------------------------------
        self.hide()
class dummyRecordingClass(QDialog):
    def __init__(self, parent=None):

        # To prevent GUI lockup in long run.
        #----------------------------------------------------------------------
        QApplication.processEvents()

        QDialog.__init__(self, parent)
        #super(AdvanceSettingWindow, self).__init__(parent)
        self.setFixedSize(500, 400)
        self.setWindowTitle(' Dummy Recording.')
        self.setWindowIcon(QIcon('assets/icon.png'))

        # Background Image.
        #----------------------------------------------------------------------
        if (os.path.exists('assets/main_background.jpg') == True):
            # Background Image.
            self.Label_bg = QLabel(self)
            self.Label_bg.resize(1000, 500)
            self.Label_bg.move(-255, -50)
            movie = QMovie("assets/main_background.jpg")
            self.Label_bg.setMovie(movie)
            movie.start()
        else:
            # Background Color.
            color = QColor('#3484A9')
            self.setAutoFillBackground(True)
            p = self.palette()
            p.setColor(self.backgroundRole(), color)
            self.setPalette(p)

        # Sub Background part with transparency
        #----------------------------------------------------------------------
        self.Label_sbg = QLabel(self)
        self.Label_sbg.setText('')
        self.Label_sbg.resize(470, 325)
        self.Label_sbg.move(15, 60)
        self.Label_sbg.setStyleSheet(
            "background-color:#70000000; border-radius:10px")

        # setting title text image here {'set notification for'}.
        #----------------------------------------------------------------------
        self.Label_title_ani = QLabel(self)
        self.Label_title_ani.resize(500, 55)
        self.Label_title_ani.move(28, 10)

        movie = QMovie("assets/dummy_text.png")
        self.Label_title_ani.setMovie(movie)
        movie.start()

        # Sub Background part with transparency
        #----------------------------------------------------------------------
        self.Label_sbg = QLabel(self)
        self.Label_sbg.setText('')
        self.Label_sbg.resize(450, 220)
        self.Label_sbg.move(25, 83)
        self.Label_sbg.setStyleSheet(
            "background-color:#50000000; border: 10px solid #000000")

        # Sub Background part with transparency
        #----------------------------------------------------------------------
        self.Label_sbg = QLabel(self)
        self.Label_sbg.setText('')
        self.Label_sbg.resize(400, 180)
        self.Label_sbg.move(50, 103)
        self.Label_sbg.setStyleSheet(
            "background-color:#3484A9;  border: 5px solid #000000")

        # Sub Background part with transparency
        #----------------------------------------------------------------------
        self.Label_sbg = QLabel(self)
        self.Label_sbg.setText('')
        self.Label_sbg.resize(400, 110)
        self.Label_sbg.move(50, 103)
        self.Label_sbg.setStyleSheet("background-color:#20000000")

        # setting text here
        #----------------------------------------------------------------------
        self.Label_sbg = QLabel(self)
        self.Label_sbg.setText(
            "           Enter the value in the input box and click \n on the 'RECORD' button to start collecting dummy data.\n\n \t          ( Enter in minutes only)"
        )
        self.Label_sbg.resize(360, 80)
        self.Label_sbg.move(70, 120)
        self.Label_sbg.setStyleSheet(
            "background:transparent; font-weight:bold; font-size:13px; font-family:Arial, Helvetica, sans-serif"
        )

        # Blocking the the any other window.
        ##############################################################################
        self.setWindowModality(Qt.ApplicationModal)

        #        # disabling minimize button.
        #        self.setWindowFlag(Qt.WindowMinimizeButtonHint, False)
        #
        #        self.settings = QSettings(" ", " ")
        #        self.restoreGeometry(self.settings.value("geometry", ""))
        #        self.restoreState(self.settings.value("windowState", ""))

        #        # displays the position of the window. (x, y, w, h) and extracting the values.
        #        # after extracting the value setting the position to the center of the parent.
        #        ##############################################################################
        #        x = self.frameGeometry()
        #        x = str(x)
        #        val = re.findall(r'\d+', x)
        #        val = [int(val[1]), int(val[2])]
        #        print(val)
        #        self.move(val[0]+260 , val[1]+100)

        self.Button_Message_Signal_Recording()

        self.initUI()

        # calling stylesheet here.
        #----------------------------------------------------------------------
        from Gunshot_Recognition_CSS import styleSheetDummy
        self.setStyleSheet(styleSheetDummy)

# ------------------------------------------------------------------------------------------------------------------------------------------#
########################################################  close event   #####################################################################
# ------------------------------------------------------------------------------------------------------------------------------------------#

    def closeEvent(self, event):

        # closing Dummy Recording Box here.
        self.hide()

        # opening the Advance setting Dialog here.
        from Gunshot_Detection_WINDOW_ADVANCE_SETTING import AdvanceSettingWindow
        self.dialog = AdvanceSettingWindow(self)
        self.dialog.exec_()

# ------------------------------------------------------------------------------------------------------------------------------------------#
########################################################  init FUNCTION   ###################################################################
# ------------------------------------------------------------------------------------------------------------------------------------------#

    def initUI(self):
        self.ButtonDummyRecord()
        self.dummyRecordLabel()

        # self.show     ---> background window will not movable.
        self.show()  # ---> background window will be movable.

        # defining the blur image over the background.
        #----------------------------------------------------------------------
        self.label_blur_img = QLabel(self)
        color = QColor(0, 0, 0, 200)  # rgba color code here.
        pixmap = QPixmap(1000, 500)
        pixmap.fill(color)
        #        pixmap = QPixmap('assets/pg_bg1.png')
        self.label_blur_img.setPixmap(pixmap)
        self.label_blur_img.resize(1000, 500)

# ------------------------------------------------------------------------------------------------------------------------------------------#
#################################################  TEXT BOX FOR TIME INPUT IN MIN   #########################################################
# ------------------------------------------------------------------------------------------------------------------------------------------#

    def dummyRecordLabel(self):
        self.textbox_dummy = QLineEdit(self)
        self.textbox_dummy.setStyleSheet(
            "color:#000000; background-color:#ffffff; border-radius:0px; padding-left:0px; font-size:15px; font-weight:bold; border-style: solid; border-width: 2px; border-color:#000000"
        )
        self.textbox_dummy.setPlaceholderText("Minutes")
        self.textbox_dummy.setAlignment(Qt.AlignCenter)
        self.textbox_dummy.move(205, 230)
        self.textbox_dummy.resize(80, 30)

# ------------------------------------------------------------------------------------------------------------------------------------------#
######################################################  THREAD FOR RECORDING   ##############################################################
# ------------------------------------------------------------------------------------------------------------------------------------------#
# Here we want to show the message box of 'please wait' while in the background the the recording takes place.
# After completion of the recording a message box will appear that take back to advance setting dialog box.

# defining global timeLength.

    timeLength = 1

    def rec(self):
        global timeLength

        # calling recording function here.
        dummyRecording(timeLength)

        # closing the progress bar here.
        self.dialog_record_progress_bar.close()

        # send signal for click the button here to pop up the message.
        self.button_rec.click()

    def thread_dummyRecording(self):

        # starting the thread just after 1 sec to handle any in process error.
        thread_rec = Timer(1, self.rec)
        thread_rec.daemon = True  # daemon thread     --> when main program exit the associated thread also exit or die.
        thread_rec.start(
        )  # non-daemon thread --> even if main program exit the thread runs on background / block main program.

        #Thread(target = self.rec, daemon = True).start()
        #Thread(target = self.messageWait).start()

# ------------------------------------------------------------------------------------------------------------------------------------------#
######################################################  DUMMY RECORD BUTTON   ###############################################################
# ------------------------------------------------------------------------------------------------------------------------------------------#

    def ButtonDummyRecord(self):
        self.button_dummy = QPushButton('RECORD', self)
        self.button_dummy.setToolTip(
            'Click to start recording (enter value in minutes).              ')
        self.button_dummy.setObjectName("enabledDummy")
        self.button_dummy.resize(120, 40)
        self.button_dummy.move(185, 325)
        self.button_dummy.clicked.connect(self.on_click_dummyRecording)

    def on_click_dummyRecording(self):

        # Defining global timeLength variable.
        global timeLength

        self.label_blur_img.show()

        # saving the input time from the textbox to the timeLength variable.
        timeLength = self.textbox_dummy.text()
        timeLength = str(timeLength)

        # regular expression for matching digit of length uptp 5.
        # r"[1-9]{1}([0-9]{1,4})*|[0]{1}([1-9]{1,4})+"

        if (re.fullmatch(r"[1-9]{1}|[1-9]{1}[0-9]{1}", timeLength)):
            x = '  Recording time is set for ' + timeLength + ' minute.      \t\n  Do you really want to continue ? \t'

            msgBox = QMessageBox.warning(self, 'Dummy Recording.', x,
                                         QMessageBox.Yes, QMessageBox.No)
            self.setWindowIcon(QIcon('assets/icon.png'))

            if (msgBox == QMessageBox.Yes):

                # Minimize & Maximizing every dialog box and windows here.
                #######################################################################

                self.hide()
                #AdvanceSettingWindow.close(self)

                # recording thread function.
                self.thread_dummyRecording()

                # showing the progress bar here by passing the "timeLength".
                #--------------------------------------------------------------
                self.dialog_record_progress_bar = RecordingProgressBar(
                    timeLength, self)
                self.dialog_record_progress_bar.exec_()

            else:
                pass

        else:
            x = 'Enter the correct value.\t\t\t  \n\n1)  Only integers are allowed. \n2)  Recording upto 139 min. \n3)  ZERO is not allowed. \n4)  Dont include ZERO in the beginning.'
            QMessageBox.critical(self, 'Time Length', x, QMessageBox.Ok)
            self.setWindowIcon(QIcon('assets/icon.png'))

        self.label_blur_img.hide()

    # Here i have created the hidden button in the dummy recording window so, when we come back from the training
    # the message 'successfully' trained will appear and for that we have auto-click event in above do_training_loop.
    def Button_Message_Signal_Recording(self):
        self.button_rec = QPushButton('', self)
        self.button_rec.setStyleSheet("background: transparent")
        self.button_rec.resize(0, 0)
        self.button_rec.move(0, 0)
        self.button_rec.clicked.connect(self.send_signal_recording)
        #self.button_xxx.animateClick()
        #self.button_xxx.click()

    def send_signal_recording(self):

        x = " Dummy Data Recording done successfully, Click 'OK' to go back. \t"
        QMessageBox.information(self, 'Recording Successful.', x,
                                QMessageBox.Ok)
        self.setWindowIcon(QIcon('assets/icon.png'))
示例#6
0
class SetNotificationWindow(QDialog):
    def __init__(self, parent=None):

        # to prevent GUI lockup in long run.
        #----------------------------------------------------------------------
        QApplication.processEvents()

        QDialog.__init__(self, parent)
        #super(AdvanceSettingWindow, self).__init__(parent)
        self.setFixedSize(500, 400)
        self.setWindowTitle(' Set Notification')
        self.setWindowIcon(QIcon('assets/icon.png'))

        # Background Image.
        #----------------------------------------------------------------------
        if (os.path.exists('assets/main_background.jpg') == True):
            # Background Image.
            self.Label_bg = QLabel(self)
            self.Label_bg.resize(1000, 500)
            self.Label_bg.move(-255, -50)
            movie = QMovie("assets/main_background.jpg")
            self.Label_bg.setMovie(movie)
            movie.start()
        else:
            # Background Color.
            color = QColor('#3484A9')
            self.setAutoFillBackground(True)
            p = self.palette()
            p.setColor(self.backgroundRole(), color)
            self.setPalette(p)

        # Sub Background part with transparency
        #----------------------------------------------------------------------
        self.Label_sbg = QLabel(self)
        self.Label_sbg.setText('')
        self.Label_sbg.resize(450, 265)
        self.Label_sbg.move(25, 60)
        self.Label_sbg.setStyleSheet(
            "background-color:#50000000; border-radius:10px")

        # setting '?' text.
        #----------------------------------------------------------------------
        self.setWhatsThis(
            "This dialog allows to set the notification for certain class \nand notification can be received to the registered phone \nnumber and email address."
        )

        # setting title text image here {'set notification for'}.
        #----------------------------------------------------------------------
        self.Label_title_ani = QLabel(self)
        self.Label_title_ani.resize(420, 55)
        self.Label_title_ani.move(120, 5)

        movie = QMovie("assets/notiTitle.png")
        self.Label_title_ani.setMovie(movie)
        movie.start()

        self.initUI()

        # calling stylesheet here.
        #----------------------------------------------------------------------
        from Gunshot_Recognition_CSS import styleSheetNotification
        self.setStyleSheet(styleSheetNotification)

# ------------------------------------------------------------------------------------------------------------------------------------------#
##################################################  init FUNCTION OF CLASS   ################################################################
# ------------------------------------------------------------------------------------------------------------------------------------------#

    def initUI(self):
        self.InputBoxNotification()
        self.ButtonSetNotification()
        self.setNotification()

        # self.show     ---> background window will not movable.
        # self.show()   ---> background window will be movable.

# ------------------------------------------------------------------------------------------------------------------------------------------#
########################################################  close event   #####################################################################
# ------------------------------------------------------------------------------------------------------------------------------------------#

    def closeEvent(self, event):

        self.hide()

        from Gunshot_Detection_WINDOW_ADVANCE_SETTING import AdvanceSettingWindow
        self.dialog = AdvanceSettingWindow(self)
        self.dialog.exec_()

#        QMainWindow.closeEvent(self, event)

# ------------------------------------------------------------------------------------------------------------------------------------------#
########################################    Displaying the current class, email_Id and phone_number    #########################################
# ------------------------------------------------------------------------------------------------------------------------------------------#

# Displaying current notification set for

    def InputBoxNotification(self):

        ss = "color:#000000; font-size:15px; font-weight:bold"

        # setting text for the option.
        self.Label_text1 = QLabel(self)
        self.Label_text1.setText(' Class Name        :')
        self.Label_text1.resize(160, 30)
        self.Label_text1.move(50, 108)
        self.Label_text1.setStyleSheet(ss)

        self.Label_text1 = QLabel(self)
        self.Label_text1.setText(' Email ID              :')
        self.Label_text1.resize(160, 30)
        self.Label_text1.move(50, 195)
        self.Label_text1.setStyleSheet(ss)

        self.Label_text1 = QLabel(self)
        self.Label_text1.setText(' Phone Number  :')
        self.Label_text1.resize(160, 30)
        self.Label_text1.move(50, 280)
        self.Label_text1.setStyleSheet(ss)

        styleSheet = "background-color:#000000; color:#808080; border-radius:10px; padding-left:0px; font-size:15px; font-weight:bold"

        from Gunshot_Detection_DATA_SAVING import DisplayDataNotification
        data = DisplayDataNotification()

        x = data[0]
        y = data[1]
        z = data[2]

        width = 400
        height = 25

        x_axis = 50

        self.Label_className = QLabel(self)
        self.Label_className.setText(x)
        self.Label_className.setStyleSheet(styleSheet)
        self.Label_className.move(x_axis, 79)
        self.Label_className.resize(width, height)
        self.Label_className.setWhatsThis(x)
        self.Label_className.setAlignment(Qt.AlignCenter)

        self.Label_email = QLabel(self)
        self.Label_email.setText(y)
        self.Label_email.setStyleSheet(styleSheet)
        self.Label_email.move(x_axis, 167)
        self.Label_email.resize(width, height)
        self.Label_email.setWhatsThis(y)
        self.Label_email.setAlignment(Qt.AlignCenter)

        self.Label_phone = QLabel(self)
        self.Label_phone.setText(z)
        self.Label_phone.setStyleSheet(styleSheet)
        self.Label_phone.move(x_axis, 252)
        self.Label_phone.resize(width, height)
        self.Label_phone.setWhatsThis(z)
        self.Label_phone.setAlignment(Qt.AlignCenter)

# ------------------------------------------------------------------------------------------------------------------------------------------#
##############################   Defining the imput box for email_ID & Phone Number and ComboBox selection here    ###################################################
# ------------------------------------------------------------------------------------------------------------------------------------------#

# Defining input box for class name, email Id, phone Number.
#--------------------------------------------------------------------------

    def setNotification(self):

        styleSheet = "color:#0E86B2; background-color:#000000; border-radius:0px; font-size:15px; font-weight:bold"
        width = 250
        height = 25

        # Defining the text box input for the EMAIL ID.
        #----------------------------------------------------------------------
        self.textbox_email = QLineEdit(self)
        self.textbox_email.setStyleSheet(styleSheet)
        self.textbox_email.move(200, 198)
        self.textbox_email.resize(width, height)
        self.textbox_email.setAlignment(Qt.AlignCenter)

        # Defining the text box input for the PHONE NUMBER.
        #----------------------------------------------------------------------
        self.textbox_phone = QLineEdit(self)
        self.textbox_phone.setStyleSheet(styleSheet)
        self.textbox_phone.move(200, 283)
        self.textbox_phone.resize(width, height)
        self.textbox_phone.setAlignment(Qt.AlignCenter)

        # Initially the ComboBox text is NONE so diabling the input box.
        #----------------------------------------------------------------------
        self.textbox_phone.setDisabled(True)
        self.textbox_phone.setPlaceholderText("Currently Not Available.")
        self.textbox_email.setDisabled(True)
        self.textbox_email.setPlaceholderText("Currently Not available.")

        # Defining the drop box and class Name selection is taken from the 'audio/classes.csv'.
        #----------------------------------------------------------------------
        self.comboBox = QComboBox(self)
        self.comboBox.addItem("NONE")
        self.comboBox.move(200, 110)
        self.comboBox.resize(width, height)
        self.comboBox.setStyleSheet(
            "color:#0E86B2; background-color:#000000; border-radius:0px; padding-left:20px; font-size:15px; font-weight:bold"
        )

        # Now adding the element from the CSV file.
        #----------------------------------------------------------------------
        with open('audio/classes.csv', 'r') as f:
            reader = csv.reader(f)
            next(reader, None)  # skipping header
            for row in reader:
                print(row)
                self.comboBox.addItem(row[1])

        self.comboBox.activated[str].connect(self.on_select_ComboBox)

    # taking input from QComboBox.
    #--------------------------------------------------------------------------
    def on_select_ComboBox(self, text):
        self.comboBox_text = text

        if (text == 'NONE'):
            # Disabling the email and phone textbox input.
            #------------------------------------------------------------------
            self.textbox_phone.setDisabled(True)
            self.textbox_phone.setPlaceholderText("Currently Not Available.")
            self.textbox_email.setDisabled(True)
            self.textbox_email.setPlaceholderText("Currently Not available.")

        else:
            # Enabling the email and phone textbox input.
            #------------------------------------------------------------------
            self.textbox_phone.setDisabled(False)
            self.textbox_phone.setPlaceholderText("Enter the Phone Number.")
            self.textbox_email.setDisabled(False)
            self.textbox_email.setPlaceholderText("Enter the Email ID.")

# ------------------------------------------------------------------------------------------------------------------------------------------#
##################################################  SET BUTTON FUNCTIONALITY   ##############################################################
# ------------------------------------------------------------------------------------------------------------------------------------------#

# Button to set class name, phone number, email id for notification.
#--------------------------------------------------------------------------

    def ButtonSetNotification(self):
        self.button_noti = QPushButton('SET', self)
        self.button_noti.setToolTip(
            'Enter the value and click to set the notification.\t          ')
        self.button_noti.setObjectName("enabledNoti")
        self.button_noti.resize(120, 40)
        self.button_noti.move(185, 340)
        self.button_noti.clicked.connect(self.on_click_notification)

        # setting the question masrk (what is this).
        #----------------------------------------------------------------------
        self.button_noti.setWhatsThis("set button")

    # This click event is used for going back to the main window.
    #--------------------------------------------------------------------------
    def on_click_notification(self):

        # showinging the blur image over the background.
        #----------------------------------------------------------------------
        self.label_blur_img = QLabel(self)
        color = QColor(0, 0, 0, 200)  # rgba color code here.
        pixmap = QPixmap(1000, 500)
        pixmap.fill(color)
        #        pixmap = QPixmap('assets/pg_bg1.png')
        self.label_blur_img.setPixmap(pixmap)
        self.label_blur_img.resize(1000, 500)
        self.label_blur_img.show()

        # initially we have nothing selected so, we get error when we click on 'SET button'.
        # so handling this by putting in the try excpet block.
        #----------------------------------------------------------------------
        try:
            self.Class = self.comboBox_text
        except:
            self.Class = 'NONE'

        self.Email = self.textbox_email.text()
        self.Phone = self.textbox_phone.text()

        self.Email = str(self.Email)
        self.Phone = str(self.Phone)

        i = 0

        # Class Name from the the drop down menu
        #----------------------------------------------------------------------
        className = self.Class

        # 1) If class Name in the drop down is selectes as None then, we are not sending any notification.
        # and we are setting everything as NULL.
        #----------------------------------------------------------------------
        if (className == 'NONE'):

            self.Class = 'NULL'
            self.Email = 'NULL'
            self.Phone = 'NULL'

            print('Data collected succesfully |', self.Class, self.Email,
                  self.Phone)

            # here writing data into the csv.
            #----------------------------------------------------------------------
            print('Writing data into the CSV.')
            from Gunshot_Detection_DATA_SAVING import saving_data_notification
            saving_data_notification(self.Class, self.Email, self.Phone)

            # poping up the message for diabling the notification.
            #--------------------------------------------------------------
            x = 'Success !'
            y = 'Notification successfully disabled \t'
            QMessageBox.information(self, x, y, QMessageBox.Ok)
            self.setWindowIcon(QIcon('assets/icon.png'))

            # closing the dialog.
            self.close()

        # 2) Display class name and send notification only to email ID.
        #----------------------------------------------------------------------
        elif (self.Class != 'NONE' and self.Email != '' and self.Phone == ''):

            self.Phone = 'NULL'

            # Regular expression for emial id.
            #------------------------------------------------------------------
            if (re.fullmatch(
                    r"([a-zA-Z0-9.^~&*%$#!_-]+)@([a-zA-Z0-9]+).([a-zA-Z]{2,3}|[0-9]{1,3})",
                    self.Email)):
                i = i + 1

            if (i == 1):

                print('Data collected succesfully |', self.Class, self.Email,
                      self.Phone)

                # here writing data into the csv.
                #--------------------------------------------------------------
                print('Writing data into the CSV.')
                from Gunshot_Detection_DATA_SAVING import saving_data_notification
                saving_data_notification(self.Class, self.Email, self.Phone)

                i = 0

                # poping up the message for the successfully written the data in to the csv.
                #--------------------------------------------------------------
                x = 'Data Added Successfully'
                y = 'Notification avtivated for ' + self.Class + '  \nfor the EMAIL ID : ' + self.Email + '\t'
                QMessageBox.information(self, x, y, QMessageBox.Ok)
                self.setWindowIcon(QIcon('assets/icon.png'))

                # closing the dialog.
                self.close()

            else:
                # displaying message if wrong value is given for threshold frequency.
                #----------------------------------------------------------------------
                x = ' Enter data in the correct format as given.\t'
                x = x + '\n\n 1) Email ID     :  [email protected]'
                x = x + '\n 2) Phone No  :  xxxxxxxxxx (upto 10)'

                QMessageBox.critical(self, 'Wrong format', x, QMessageBox.Ok)
                self.setWindowIcon(QIcon('assets/icon.png'))

                i = 0

        # 3) Display class name and send notification only to Mobile.
        #----------------------------------------------------------------------
        elif (self.Class != 'NONE' and self.Email == '' and self.Phone != ''):

            self.Email = 'NULL'

            # Regular expression for phone number.
            #------------------------------------------------------------------
            if (re.fullmatch(r"[0-9]{10}", self.Phone)):
                i = i + 1

            if (i == 1):

                print('Data collected succesfully |', self.Class, self.Email,
                      self.Phone)

                # here writing data into the csv.
                #--------------------------------------------------------------
                print('Writing data into the CSV.')
                from Gunshot_Detection_DATA_SAVING import saving_data_notification
                saving_data_notification(self.Class, self.Email, self.Phone)

                i = 0

                # poping up the message for the successfully written the data in to the csv.
                #--------------------------------------------------------------
                x = 'Data Added Successfully'
                y = 'Notification avtivated for ' + self.Class + '  \nfor the PHONE NUMBER : ' + self.Phone + '  \t'
                QMessageBox.information(self, x, y, QMessageBox.Ok)
                self.setWindowIcon(QIcon('assets/icon.png'))

                # closing the dialog.
                self.close()

            else:
                # displaying message if wrong value is given for threshold frequency.
                #----------------------------------------------------------------------
                x = ' Enter data in the correct format as given.\t'
                x = x + '\n\n 1) Email ID     :  [email protected]'
                x = x + '\n 2) Phone No  :  xxxxxxxxxx (upto 10)'

                QMessageBox.critical(self, 'Wrong format', x, QMessageBox.Ok)
                self.setWindowIcon(QIcon('assets/icon.png'))

                i = 0

        # 4) Display class name and send notification both Mobile and Email ID.
        #----------------------------------------------------------------------
        else:

            # Regular expression for emial id.
            #------------------------------------------------------------------
            if (re.fullmatch(
                    r"([a-zA-Z0-9.^~&*%$#!_-]+)@([a-zA-Z0-9]+).([a-zA-Z]{2,3}|[0-9]{1,3})",
                    self.Email)):
                i = i + 1

            # Regular esxpression for Phone number.
            #------------------------------------------------------------------
            if (re.fullmatch(r"[0-9]{10}", self.Phone)):
                i = i + 1

            if (i == 2):

                print('Data collected succesfully |', self.Class, self.Email,
                      self.Phone)

                # here writing data into the csv.
                #--------------------------------------------------------------
                print('Writing data into the CSV.')
                from Gunshot_Detection_DATA_SAVING import saving_data_notification
                saving_data_notification(self.Class, self.Email, self.Phone)

                i = 0

                # poping up the message for the successfully written the data in to the csv.
                #--------------------------------------------------------------
                x = 'Data Added Successfully'
                y = 'Sending Notification for class : \'' + self.Class + '\' on \t\t\n\n 1) Email   : \t' + self.Email + ' \n 2) Phone  :\t' + self.Phone
                QMessageBox.information(self, x, y, QMessageBox.Ok)
                self.setWindowIcon(QIcon('assets/icon.png'))

                # closing the dialog.
                self.close()

            else:
                # displaying message if wrong value is given for threshold frequency.
                #----------------------------------------------------------------------
                x = ' Enter data in the correct format as given.\t'
                x = x + '\n\n 1) Email ID     :  [email protected]'
                x = x + '\n 2) Phone No  :  xxxxxxxxxx (upto 10)'

                QMessageBox.critical(self, 'Wrong format', x, QMessageBox.Ok)
                self.setWindowIcon(QIcon('assets/icon.png'))

                i = 0

        self.label_blur_img.hide()


######################################################################################################################################
######################################################################################################################################
######################################################################################################################################

#def run():
#    if __name__ =='__main__':
#
#        QApplication.processEvents()
#        my_app = QCoreApplication.instance()
#        if my_app is None:
#            my_app = QApplication(sys.argv)
#        window = SetNotificationWindow()
#        window.show()
#
#        sys.exit(my_app.exec_())
#
#try:
#    run()
#except:
#    print('\nSERVICE SHUTDOWN\n')
示例#7
0
class MainWindow(QMainWindow):

    # ----------------------------------------------------------------------------------------------------------------------------------------- #
    ######################################################   MAIN FUNCTION   ####################################################################
    # ----------------------------------------------------------------------------------------------------------------------------------------- #

    def __init__(self):

        QMainWindow.__init__(self)
        #        super(MainWindow, self).__init__()

        #        QApplication.processEvents()
        #        QCoreApplication.processEvents()

        self.setFixedSize(1000, 500)
        self.setWindowTitle(" Sound Classification v3.0 ")
        self.setWindowIcon(QIcon("assets/icon.png"))

        # disable the windows title bar.
        #----------------------------------------------------------------------
        #self.setWindowFlags(Qt.FramelessWindowHint)
        #self.setWindowFlags(Qt.CustomizeWindowHint)

        #--------------------------------------------------------------------------------------------
        # This part is for the window postion.
        # At First geometry will be null, so by default the window appear on the center of the screen.
        # Next, when training window get closed the last postion will be saved and in that position
        # this window will appear.
        #--------------------------------------------------------------------------------------------

        self.settings = QSettings(" ", " ")
        if not self.settings.value("geometry") == None:
            self.restoreGeometry(self.settings.value("geometry"))
        if not self.settings.value("windowState") == None:
            self.restoreState(self.settings.value("windowState"))

        # if background image is not available then takin color as background.
        #----------------------------------------------------------------------
        if (os.path.exists('assets/main_background.jpg') == True):
            # Setting background Image.
            oImage = QImage("assets/main_background.jpg")
            sImage = oImage.scaled(QSize(1000, 500))
            palette = QPalette()
            palette.setBrush(10, QBrush(sImage))
            self.setPalette(palette)
        else:
            # Background Color.
            color = QColor("#3484A9")
            self.setAutoFillBackground(True)
            p = self.palette()
            p.setColor(self.backgroundRole(), color)
            self.setPalette(p)

        # defining all labels here.
        #----------------------------------------------------------------------
        self.Label_sbg_title = QLabel(self)
        self.Label_sbg_l = QLabel(self)
        self.Label_sbg_l1 = QLabel(self)
        self.Label_sbg_l2 = QLabel(self)
        self.Label_sbg_l3 = QLabel(self)
        self.Label_sbg_l4 = QLabel(self)
        self.Label_sbg_l11 = QLabel(self)
        self.Label_sbg_l21 = QLabel(self)
        self.Label_sbg_l31 = QLabel(self)
        self.Label_sbg_l41 = QLabel(self)
        self.Label_sbg_x = QLabel(self)
        self.Label_sbg_r = QLabel(self)
        self.Label_sbg_r1 = QLabel(self)
        self.Label_sbg_r2 = QLabel(self)
        self.Label_copyright = QLabel(self)

        self.Label_predict1 = QLabel(self)
        self.Label_accu1 = QLabel(self)
        self.Label_date = QLabel(self)
        self.Label_avg_freq = QLabel(self)
        self.Label_predict11 = QLabel(self)
        self.Label_predict12 = QLabel(self)
        self.Label_predict13 = QLabel(self)
        self.Label_predict14 = QLabel(self)
        self.Label_predict15 = QLabel(self)
        self.button_advance = QPushButton("Go To Advance Settings", self)
        self.button_train = QPushButton("TRAINING", self)
        self.button_stop = QPushButton("STOP", self)
        self.button_start = QPushButton("START", self)

        # setting title text image here 'SOUND CLASSIFICATION'.
        #----------------------------------------------------------------------
        if (os.path.exists('assets/title.png') == True):
            self.Label_title_ani = QLabel(self)
            self.Label_title_ani.resize(900, 150)
            self.Label_title_ani.move(100, 1)
            movie = QMovie("assets/title.png")
            self.Label_title_ani.setMovie(movie)
            movie.start()
        else:
            self.Label_title_ani = QLabel(self)
            self.Label_title_ani.setText("SOUND CLASSIFICATION")
            self.Label_title_ani.setStyleSheet(
                "color:#000000; font-weight:bold; font-size:50px")
            self.Label_title_ani.resize(900, 150)
            self.Label_title_ani.move(170, 1)

        # Defining blur label here.
        #----------------------------------------------------------------------
        self.label_blur_img = QLabel(self)

        # Running the display time here.
        #----------------------------------------------------------------------
        self.threadTimeDisplay()

        # calling init function here.
        #----------------------------------------------------------------------
        self.initUI()

        # calling stylesheet here.
        #----------------------------------------------------------------------
        from Gunshot_Recognition_CSS import styleSheetMain
        self.setStyleSheet(styleSheetMain)

# ----------------------------------------------------------------------------------------------------------------------------------------- #
#############################################  CLOSE EVENT FOR MAIN WINDOW   ################################################################
# ----------------------------------------------------------------------------------------------------------------------------------------- #

    def closeEvent(self, event):

        # When service is active then poping up the message to stop the service first.
        #-----------------------------------------------------------------------------
        global stop

        self.label_blur_img.show()
        if (stop == False):
            msgBox = QMessageBox.warning(
                self, "Warning !",
                "STOP the service first before closing the application.\t",
                QMessageBox.Ok)
            self.setWindowIcon(QIcon("assets/icon.png"))

            if msgBox == QMessageBox.Ok:
                event.ignore()
            else:
                event.ignore()
        else:
            # closing the app and ending the child loop here.
            #----------------------------------------------------------------------
            global main_advance_setting_close
            main_advance_setting_close = 2

        self.label_blur_img.hide()

# ----------------------------------------------------------------------------------------------------------------------------------------- #
######################################### init FUNCTION TO DECLARE EVERYTHING  ##############################################################
# ----------------------------------------------------------------------------------------------------------------------------------------- #

    def initUI(self):
        self.styleSheetDisplay()
        self.constantLabel()
        self.copyrightLabel()
        self.inactive()
        self.prediction_inactive()
        self.date_n_time()
        self.ButtonStart()
        self.ButtonStop()
        self.ButtonTrainWindow()
        self.AdvanceButton()

        self.show()

        # checking that model is empty or not and calling it at last so that other features of main window
        # will be active like button etc.
        self.calling_empty_class()

    def styleSheetDisplay(self):

        # prediction label on leftt side.
        #----------------------------------------------------------------------
        self.Label_predict1.setObjectName("predictionLabels")
        self.Label_predict1.resize(270, 30)
        self.Label_predict1.move(190, 170)

        self.Label_avg_freq.setObjectName("predictionLabels_X")
        self.Label_avg_freq.resize(270, 30)
        self.Label_avg_freq.move(190, 305)

        self.Label_accu1.setObjectName("predictionLabels")
        self.Label_accu1.resize(270, 30)
        self.Label_accu1.move(190, 215)

        # prediction label on right side.
        #----------------------------------------------------------------------
        self.Label_predict11.setObjectName("prediction5")
        self.Label_predict11.resize(350, 30)
        self.Label_predict11.move(580, 235)

        self.Label_predict12.setObjectName("prediction5")
        self.Label_predict12.resize(350, 30)
        self.Label_predict12.move(580, 275)

        self.Label_predict13.setObjectName("prediction5")
        self.Label_predict13.resize(350, 30)
        self.Label_predict13.move(580, 315)

        self.Label_predict14.setObjectName("prediction5")
        self.Label_predict14.resize(350, 30)
        self.Label_predict14.move(580, 355)

        self.Label_predict15.setObjectName("prediction5")
        self.Label_predict15.resize(350, 30)
        self.Label_predict15.move(580, 395)

        # date and time.
        #----------------------------------------------------------------------
        self.Label_date.setObjectName("DateTime")
        self.Label_date.resize(275, 30)
        self.Label_date.move(190, 260)

# ----------------------------------------------------------------------------------------------------------------------------------------- #
###########################################     FUNCTION THAT CHECKS FOR CLASS     ##########################################################
# ----------------------------------------------------------------------------------------------------------------------------------------- #

# If the classes.csv is empty then window will appear before the main window else if there is any class then
# only main window will appear.

# here we are checking that window will appear or not.
#--------------------------------------------------------------------------

    def calling_empty_class(self):

        # defining the blur image over the background.
        #----------------------------------------------------------------------
        color = QColor(0, 0, 0, 200)  # rgba color code here.
        pixmap = QPixmap(1000, 500)
        pixmap.fill(color)
        #        pixmap = QPixmap("assets/pg_bg1.png")
        self.label_blur_img.setPixmap(pixmap)
        self.label_blur_img.resize(1000, 500)

        # opening the csv file and checking if there is any class available or not.
        #--------------------------------------------------------------------------
        with open("audio/classes.csv", 'r') as file:
            reader = csv.reader(file)
            for row in reader:
                row
            Id = row[0]
            print(Id)

        # starting the thread that checks for if the CheckClassAvailability window is closed or not.
        #-------------------------------------------------------------------------------------------
        self.closeMain = Timer(0, self.CloseThreadMainWindowSub)
        self.closeMain.daemon = True
        self.closeMain.start()

        self.dialog_cca = CheckingClassAvailability(self)

        if (Id == "class_id" or Id == '' or Id == ' '):
            try:
                self.label_blur_img.show()
                self.dialog_cca.show()
                print("no class available ")
            except Exception as e:
                print(e)

        else:
            try:
                self.label_blur_img.hide()
                self.dialog_cca.hide()
                print("showing only maindow. new data available")
            except Exception as e:
                print(e)

    # checking and closing the main window here.
    #--------------------------------------------------------------------------
    def CloseThreadMainWindowSub(self):

        global main_advance_setting_close

        while (True):
            time.sleep(0.5)

            QApplication.processEvents()
            QCoreApplication.processEvents()

            #            print('Child Thread Running', main_advance_setting_close, Gunshot_Recognition_IF_NO_CLASS.close_main_window)

            # EMPTY MODEL : closing the main window through the IF_NO_CLASS window
            # if no data is available.
            #----------------------------------------------------------------------
            if (Gunshot_Recognition_IF_NO_CLASS.close_main_window == 1):
                Gunshot_Recognition_IF_NO_CLASS.close_main_window = 0
                self.close()
                print(
                    "Closing the Main window ( data is not available )-----------"
                )
                break

            # AFTER TRAINING : hiding the main window just after the training get completed
            # after the first training when no data is available.
            #------------------------------------------------------------------------------
            elif (Gunshot_Recognition_IF_NO_CLASS.close_main_window == 2):
                Gunshot_Recognition_IF_NO_CLASS.close_main_window = 0
                self.label_blur_img.hide()
                self.label_blur_img.hide()
                self.label_blur_img.hide()
                self.label_blur_img.hide()
                self.label_blur_img.hide()
                print(
                    "cloing the blur background.---------------------------------"
                )

            # DATA CLEANED : hiding the main window when we clean the data from the
            # model and then poping up the main main window.
            #----------------------------------------------------------------------
            elif (main_advance_setting_close == 1):
                main_advance_setting_close = 0
                self.hide()
                print(
                    "Hiding the window after main data cleaned.------------------"
                )

            # DATA AVAILABLE : when we have data in the model and then we close the
            # app in that case we are ending the child loop.
            #----------------------------------------------------------------------
            elif (main_advance_setting_close == 2):
                print(
                    "Closing the Main window ( data is available ).--------------"
                )
                self.close()
                break

            else:
                pass

        print("Child Thread Running Ended.")

# ----------------------------------------------------------------------------------------------------------------------------------------- #
###########################################   FUNCTION TO DISPLAY DATE AND TIME   ##########################################################
# ----------------------------------------------------------------------------------------------------------------------------------------- #

# This function is called in the main loop function to print the date and time.
#------------------------------------------------------------------------------

    def date_n_time(self):
        self.datetime = QDateTime.currentDateTime().toString(
            "HH:mm:ss | ddd | dd-MM-yyyy")

        self.Label_date.setText(self.datetime)
#        self.Label_date.resize(275, 30)
#        self.Label_date.move(190, 260)
#        self.Label_date.setObjectName("DateTime")

    def loopTime(self):
        while (True):
            self.date_n_time()
            time.sleep(1)

            # ending the thread when main window get closed.
            #------------------------------------------------------------------
            global main_advance_setting_close
            if (main_advance_setting_close == 2):
                break

            QApplication.processEvents()
            QCoreApplication.processEvents()

        print("Running Time display Thread Ended.")

    def threadTimeDisplay(self):
        self.threadTime = Timer(1, self.loopTime)
        self.threadTime.daemon = True
        self.threadTime.start()

# ----------------------------------------------------------------------------------------------------------------------------------------- #
##################################################  DEFINING THE CONSTANT LABEL HERE  #######################################################
# ----------------------------------------------------------------------------------------------------------------------------------------- #

    def constantLabel(self):

        # Sub Background part with transparency for title bar
        #----------------------------------------------------------------------
        self.Label_sbg_title.setText(" ")
        self.Label_sbg_title.resize(960, 110)
        self.Label_sbg_title.move(20, 20)
        self.Label_sbg_title.setObjectName("Title")

        #######################################################################
        # Sub Background part with transparency for LEFT SIDE.
        #----------------------------------------------------------------------

        self.Label_sbg_l.setText(" ")
        self.Label_sbg_l.resize(470, 315)
        self.Label_sbg_l.move(20, 150)
        self.Label_sbg_l.setObjectName("sbg_l")

        height = 40
        width = 430
        x_axis = 40
        y_axis = 165

        self.Label_sbg_l1.setText(" ")
        self.Label_sbg_l1.resize(width, height)
        self.Label_sbg_l1.move(x_axis, y_axis)
        self.Label_sbg_l1.setObjectName("sbg_lx")

        self.Label_sbg_l2.setText(" ")
        self.Label_sbg_l2.resize(width, height)
        self.Label_sbg_l2.move(x_axis, y_axis + 45)
        self.Label_sbg_l2.setObjectName("sbg_lx")

        self.Label_sbg_l3.setText(" ")
        self.Label_sbg_l3.resize(width, height)
        self.Label_sbg_l3.move(x_axis, y_axis + 90)
        self.Label_sbg_l3.setObjectName("sbg_lx")

        self.Label_sbg_l4.setText(" ")
        self.Label_sbg_l4.resize(width, height)
        self.Label_sbg_l4.move(x_axis, y_axis + 135)
        self.Label_sbg_l4.setObjectName("sbg_lx")

        width = 140

        self.Label_sbg_l11.setText(" SOUND CLASS  :")
        self.Label_sbg_l11.resize(width, height)
        self.Label_sbg_l11.move(x_axis, y_axis)
        self.Label_sbg_l11.setObjectName("sbg_lxx")

        self.Label_sbg_l21.setText(" PROBABILITY   :")
        self.Label_sbg_l21.resize(width, height)
        self.Label_sbg_l21.move(x_axis, y_axis + 45)
        self.Label_sbg_l21.setObjectName("sbg_lxx")

        self.Label_sbg_l31.setText(" DATE & TIME     :")
        self.Label_sbg_l31.resize(width, height)
        self.Label_sbg_l31.move(x_axis, y_axis + 90)
        self.Label_sbg_l31.setObjectName("sbg_lxx")

        self.Label_sbg_l41.setText(" FREQUENCY      :")
        self.Label_sbg_l41.resize(width, height)
        self.Label_sbg_l41.move(x_axis, y_axis + 135)
        self.Label_sbg_l41.setObjectName("sbg_lxx")

        height = 105
        width = 464
        x_axis = 23
        y_axis = 360

        self.Label_sbg_x.setText('')
        self.Label_sbg_x.resize(width, height)
        self.Label_sbg_x.move(x_axis, y_axis)
        self.Label_sbg_x.setObjectName("x_bottom")

        #######################################################################
        # Sub Background part with transparency for RIGHT SIDE.
        #----------------------------------------------------------------------

        self.Label_sbg_r.setText(" ")
        self.Label_sbg_r.resize(470, 315)
        self.Label_sbg_r.move(510, 150)
        self.Label_sbg_r.setObjectName("sbg_r")

        x_axis = 530
        y_axis = 165

        self.Label_sbg_r1.setText(" NEXT TOP 5 ")
        self.Label_sbg_r1.resize(430, 40)
        self.Label_sbg_r1.move(x_axis, y_axis)
        self.Label_sbg_r1.setAlignment(Qt.AlignCenter)
        self.Label_sbg_r1.setObjectName("sbg_r1")

        self.Label_sbg_r2.setText(" ")
        self.Label_sbg_r2.resize(430, 240)
        self.Label_sbg_r2.move(x_axis, y_axis + 45)
        self.Label_sbg_r2.setAlignment(Qt.AlignCenter)
        self.Label_sbg_r2.setObjectName("sbg_r2")

# ----------------------------------------------------------------------------------------------------------------------------------------- #
#########################################  RECOGNITION OF LEFT SIDE DISPLAYED HERE  #########################################################
# ----------------------------------------------------------------------------------------------------------------------------------------- #

# Label start showing when we click on the start button.
#--------------------------------------------------------------------------

    def active(self):

        x = activeRecog()
        #x[0][1] = x[0][1]
        x[0][1] = x[0][1] + " %"
        x[0][0] = x[0][0].upper()

        #self.Label_predict1.setText('')
        self.Label_predict1.setText(x[0][0])
        #        self.Label_predict1.resize(270, 30)
        #        self.Label_predict1.move(190, 170)
        #        self.Label_predict1.setObjectName("predictionLabels")

        self.Label_accu1.setText(x[0][1])
#        self.Label_accu1.resize(270, 30)
#        self.Label_accu1.move(190, 215)
#        self.Label_accu1.setObjectName("predictionLabels_X")

# Label start showing when serice is in active or we click on stop button.
# Further initial state of app also define this.
#--------------------------------------------------------------------------

    def inactive(self):

        self.Label_predict1.setText("Service is not active")
        #        self.Label_predict1.resize(270, 30)
        #        self.Label_predict1.move(190, 170)
        #        self.Label_predict1.setObjectName("predictionLabels")

        self.Label_accu1.setText("NULL")
        #        self.Label_accu1.resize(270, 30)
        #        self.Label_accu1.move(190, 215)
        #        self.Label_accu1.setObjectName("predictionLabels")

        # frequency value printing.
        #----------------------------------------------------------------------
        self.Label_avg_freq.setText("NULL")
#        self.Label_avg_freq.resize(270, 30)
#        self.Label_avg_freq.move(190, 305)
#        self.Label_avg_freq.setObjectName("predictionLabels_X")

# Label start showing when it found nothing but service is still active.
#--------------------------------------------------------------------------

    def listening(self):

        self.Label_predict1.setText("Listening . . .")
        #        self.Label_predict1.resize(270, 30)
        #        self.Label_predict1.move(190, 170)
        #        self.Label_predict1.setObjectName("predictionLabels")

        self.Label_accu1.setText("NULL")
#        self.Label_accu1.resize(270, 30)
#        self.Label_accu1.move(190, 215)
#        self.Label_accu1.setObjectName("predictionLabels_X")

# ----------------------------------------------------------------------------------------------------------------------------------------- #
############################################### TOP FIVE PREDICTION OF THE RIGHT SIDE DISPLAY ###############################################
# ----------------------------------------------------------------------------------------------------------------------------------------- #

    def prediction_active(self):

        x = activeRecog()

        if (len(x[1][0]) < 5):
            x[1][0] = x[1][0] + "\t"

        if (len(x[2][0]) < 5):
            x[2][0] = x[2][0] + "\t"

        if (len(x[3][0]) < 5):
            x[3][0] = x[3][0] + "\t"

        if (len(x[4][0]) < 5):
            x[4][0] = x[4][0] + "\t"

        if (len(x[5][0]) < 5):
            x[5][0] = x[5][0] + "\t"

        value1 = "1)  " + x[1][0].upper() + "\t   : " + x[1][1] + " %"
        self.Label_predict11.setText(value1)
        #        self.Label_predict11.resize(350, 30)
        #        self.Label_predict11.move(580, 235)
        #        self.Label_predict11.setObjectName("prediction5")

        value2 = "2)  " + x[2][0].upper() + "\t   : " + x[2][1] + " %"
        self.Label_predict12.setText(value2)
        #        self.Label_predict12.resize(350, 30)
        #        self.Label_predict12.move(580, 275)
        #        self.Label_predict12.setObjectName("prediction5")

        value3 = "3)  " + x[3][0].upper() + "\t   : " + x[3][1] + " %"
        self.Label_predict13.setText(value3)
        #        self.Label_predict13.resize(350, 30)
        #        self.Label_predict13.move(580, 315)
        #        self.Label_predict13.setObjectName("prediction5")

        value4 = "4)  " + x[4][0].upper() + "\t   : " + x[4][1] + " %"
        self.Label_predict14.setText(value4)
        #        self.Label_predict14.resize(350, 30)
        #        self.Label_predict14.move(580, 355)
        #        self.Label_predict14.setObjectName("prediction5")

        value5 = "5)  " + x[5][0].upper() + "\t   : " + x[5][1] + " %"
        self.Label_predict15.setText(value5)
#        self.Label_predict15.resize(350, 30)
#        self.Label_predict15.move(580, 395)
#        self.Label_predict15.setObjectName("prediction5")

    def prediction_inactive(self):

        value = "1) Service is not active "
        self.Label_predict11.setText(value)
        #        self.Label_predict11.resize(270, 30)
        #        self.Label_predict11.move(580, 235)
        #        self.Label_predict11.setObjectName("prediction5")

        value = "2) Service is not active "
        self.Label_predict12.setText(value)
        #        self.Label_predict12.resize(270, 30)
        #        self.Label_predict12.move(580, 275)
        #        self.Label_predict12.setObjectName("prediction5")

        value = "3) Service is not active "
        self.Label_predict13.setText(value)
        #        self.Label_predict13.resize(270, 30)
        #        self.Label_predict13.move(580, 315)
        #        self.Label_predict13.setObjectName("prediction5")

        value = "4) Service is not active "
        self.Label_predict14.setText(value)
        #        self.Label_predict14.resize(270, 30)
        #        self.Label_predict14.move(580, 355)
        #        self.Label_predict14.setObjectName("prediction5")

        value = "5) Service is not active "
        self.Label_predict15.setText(value)
#        self.Label_predict15.resize(270, 30)
#        self.Label_predict15.move(580, 395)
#        self.Label_predict15.setObjectName("prediction5")

    def prediction_listening(self):

        value = "1) Please wait. "
        self.Label_predict11.setText(value)
        #        self.Label_predict11.resize(270, 30)
        #        self.Label_predict11.move(580, 235)
        #        self.Label_predict11.setObjectName("prediction5")

        value = "2) Please wait. "
        self.Label_predict12.setText(value)
        #        self.Label_predict12.resize(270, 30)
        #        self.Label_predict12.move(580, 275)
        #        self.Label_predict12.setObjectName("prediction5")

        value = "3) Please wait. "
        self.Label_predict13.setText(value)
        #        self.Label_predict13.resize(270, 30)
        #        self.Label_predict13.move(580, 315)
        #        self.Label_predict13.setObjectName("prediction5")

        value = "4) Please wait. "
        self.Label_predict14.setText(value)
        #        self.Label_predict14.resize(270, 30)
        #        self.Label_predict14.move(580, 355)
        #        self.Label_predict14.setObjectName("prediction5")

        value = "5) Please wait. "
        self.Label_predict15.setText(value)
#        self.Label_predict15.resize(270, 30)
#        self.Label_predict15.move(580, 395)
#        self.Label_predict15.setObjectName("prediction5")

#-----------------------------------------------------------------------------------------------------------------------------------------#
########################################### METHOD FOR FREQUENCY & COPYRIGHT DISPLAYING   #################################################
#-----------------------------------------------------------------------------------------------------------------------------------------#

# Displaying the frequency of incoming sound sample.
#--------------------------------------------------------------------------

    def avg_frequency_display(self):

        f = frequency_value()
        f = str(f)
        print("frequency  : ", f)
        self.Label_avg_freq.setText(f)

    # Displaying the copyright text.
    #--------------------------------------------------------------------------
    def copyrightLabel(self):

        self.Label_copyright.setText("All Rights Reserved © NCTC 2018.")
        self.Label_copyright.resize(1000, 20)
        self.Label_copyright.move(0, 478)
        self.Label_copyright.setObjectName("copyright")

# ----------------------------------------------------------------------------------------------------------------------------------------- #
######################################################   START BUTTON   ####################################################################
# ----------------------------------------------------------------------------------------------------------------------------------------- #

    def ButtonStart(self):

        self.button_start.resize(120, 40)
        self.button_start.move(41, 375)
        self.button_start.setObjectName("enabled")
        self.button_start.setProperty('Test', True)
        self.button_start.setToolTip("Start the service.  ")

        # click event for starting the recognition part when start button is clicked.
        # ---------------------------------------------------------------------------
        self.button_start.clicked.connect(
            lambda: self.on_click_start(self.button_start))

        # Changing the color and enabling /disabling the button when start button is clicked.
        #------------------------------------------------------------------------------------
        self.button_start.clicked.connect(
            lambda: self.on_click_start_rest(self.button_stop))
        self.button_start.clicked.connect(
            lambda: self.on_click_start_rest(self.button_train))
        self.button_start.clicked.connect(
            lambda: self.on_click_start_rest(self.button_advance))

    def on_click_start(self, widget):

        print("\nSERVICE STARTED\n")
        global stop
        stop = False

        # On clicking the start button disabling the START button to prevent further clicking.
        self.button_start.setObjectName("disabled")
        self.button_start.setToolTip("Service is already active   ")
        self.button_start.setEnabled(False)

        # Update the style
        widget.setStyle(widget.style())

        self.Mythread()

        #print('start Thread is alive', self.thread.is_alive())

    def on_click_start_rest(self, widget):

        # When start button is enabled then disabling the TRAIN button.
        self.button_train.setObjectName("disabled")
        self.button_train.setToolTip("Stop the service first.   ")
        self.button_train.setEnabled(False)

        # Disabling the advance setting button when app is active.
        self.button_advance.setObjectName("Advance_disabled")
        self.button_advance.setToolTip(
            "Stop the service first to access advance setting.         ")
        self.button_advance.setEnabled(False)

        # On clicking the start button enabling the STOP button to stop the service.
        self.button_stop.setObjectName("enabled")
        self.button_stop.setToolTip("Click to stop the service.   ")
        self.button_stop.setEnabled(True)

        # Update the style
        widget.setStyle(widget.style())

# ----------------------------------------------------------------------------------------------------------------------------------------- #
######################################################   STOP BUTTON   ######################################################################
# ----------------------------------------------------------------------------------------------------------------------------------------- #

    def ButtonStop(self):

        self.button_stop.resize(120, 40)
        self.button_stop.move(194, 375)
        self.button_stop.setObjectName("disabled")
        self.button_stop.setProperty('Test', True)
        self.button_stop.setToolTip("Service is already inactive.  ")
        self.button_stop.setEnabled(False)

        # click event for stopping the recognition part when stop button is clicked.
        # ---------------------------------------------------------------------------
        self.button_stop.clicked.connect(
            lambda: self.on_click_stop(self.button_stop))

        # Changing the color and enabling /disabling the button when stop button is clicked.
        #------------------------------------------------------------------------------------
        self.button_stop.clicked.connect(
            lambda: self.on_click_stop_rest(self.button_start))
        self.button_stop.clicked.connect(
            lambda: self.on_click_stop_rest(self.button_train))
        self.button_stop.clicked.connect(
            lambda: self.on_click_stop_rest(self.button_advance))

    def on_click_stop(self, widget):

        global stop
        stop = True

        # On clicking the stop button disabling the STOP button to prevent further clicking.
        self.button_stop.setObjectName("disabled")
        self.button_stop.setToolTip("Service is already inactive.   ")
        self.button_stop.setEnabled(False)

        # Update the style
        widget.setStyle(widget.style())

        print("\nSERVICE STOPPED\n")

        time.sleep(1)

        self.inactive()
        self.prediction_inactive()
        print("stop Thread is alive", self.thread_pred.is_alive())

    def on_click_stop_rest(self, widget):

        # Enaabling the advance setting button when app is inactive.
        self.button_advance.setObjectName("Advance_enabled")
        self.button_advance.setEnabled(True)

        # On clicking the stop button enabling the START button to start the service.
        self.button_start.setObjectName("enabled")
        self.button_start.setToolTip("Click here to start the service.   ")
        self.button_start.setEnabled(True)

        # On clicking the stop button enabling the TRAIN button to goto training window.
        self.button_train.setObjectName("enabled")
        self.button_train.setToolTip("Click here to open training window.   ")
        self.button_train.setEnabled(True)

        # Update the style
        widget.setStyle(widget.style())

# ----------------------------------------------------------------------------------------------------------------------------------------- #
###################################################   TRAINING  BUTTON   ####################################################################
# ----------------------------------------------------------------------------------------------------------------------------------------- #

    def ButtonTrainWindow(self):

        self.button_train.resize(125, 40)
        self.button_train.move(345, 375)
        self.button_train.setObjectName("enabled")
        self.button_train.setProperty('Test', True)
        self.button_train.setToolTip("Click here to open training window.   ")
        self.button_train.clicked.connect(self.on_click_train)

    def on_click_train(self):

        # saving the last known postion of the main window so that another window can appear on the same position.
        self.settings = QSettings(" ", " ")
        self.settings.setValue("geometry", self.saveGeometry())
        self.settings.setValue("windowState", self.saveState())

        # Poping up the training window.
        #----------------------------------------------------------------------
        self.dialog = TrainWindow()
        self.dialog.show()

        # hiding up the main window.
        #----------------------------------------------------------------------
        self.hide()

# ------------------------------------------------------------------------------------------------------------------------------------------#
##############################################  ADVANCE SETTING BUTTON   ####################################################################
# ------------------------------------------------------------------------------------------------------------------------------------------#

# Advance setting button.

    def AdvanceButton(self):

        self.button_advance.resize(300, 27)
        self.button_advance.move(105, 435)
        self.button_advance.setProperty('Test', True)
        self.button_advance.setObjectName("Advance_enabled")
        self.button_advance.setToolTip(
            "Click here to open advance setting window.   ")
        self.button_advance.clicked.connect(self.on_click_advanceButton)

    def on_click_advanceButton(self):

        # saving the last known postion of the main window so that another window can appear on the same position.
        self.settings = QSettings(" ", " ")
        self.settings.setValue("geometry", self.saveGeometry())
        self.settings.setValue("windowState", self.saveState())

        # showing the blur image over the background.
        self.label_blur_img.show()

        # Showing dialog box on the burron click event.
        self.dialog = AdvanceSettingWindow(self)
        self.dialog.exec_()

        self.label_blur_img.hide()

# ------------------------------------------------------------------------------------------------------------------------------------------#
################################################  THREAD FOR THE LOOP   #####################################################################
# ------------------------------------------------------------------------------------------------------------------------------------------#

# This thread is going to be get executed when click event for start button happen.

    def Mythread(self):

        # 0 means thread start executing after 0 second of button click event.
        self.thread_pred = Timer(0, self.loop)
        self.thread_pred.start()

# ------------------------------------------------------------------------------------------------------------------------------------------#
#############################################  MAIN LOOP TO DO RECOGNITION   ################################################################
# ------------------------------------------------------------------------------------------------------------------------------------------#

    def loop(self):

        global stop

        try:
            while (True):

                QApplication.processEvents()
                QCoreApplication.processEvents()

                #                time.sleep(0.5)

                print("Recognition is in progress.")

                now = datetime.datetime.now()
                Ctime = now.strftime("%I:%M:%S : %p")
                Cdate = str(datetime.datetime.now().date())

                if (stop == True):
                    break

                Recording()

                if (stop == True):
                    break

                x = activeRecog()

                self.avg_frequency_display()

                if (stop == True):
                    break

                if (int(float(x[0][1])) >= 50):
                    print(x[0][0], '  ', int(float(x[0][1])), end="%  ")

                    self.active()
                    self.prediction_active()

                    # calling function that Opens the CSV file to read the latest data that user
                    # saved for notification user generally saved the class, email, phone number.
                    #-------------------------------------------------------------------------------
                    data = DisplayDataNotification()

                    if (x[0][0] == data[0]):

                        send_email(data[0], data[1],
                                   x[0][1])  # data[class, email, phone]
                        send_sms(data[0], data[2],
                                 x[0][1])  # x[0][1] = probability

                        # Here updating the CSV file (sound_evidence.csv)
                        # -----------------------------------------------------------------------------
                        saving_data_file(x[0][0], x[0][1])

                else:
                    self.listening()
                    self.prediction_listening()
                    print('Found Nothing,', end=" ")

                print("Completed\n")

                # writting the data into the csv file.
                #--------------------------------------------------------------
                if (int(float(x[0][1]) >= 90)):
                    updateCSV(x[0][0], x[0][1], Ctime, Cdate, "null")

        except Exception as e:
            print("ERROR : ", e)