Saturday, May 14, 2022

Tensorflow: Save and Load Model to retrain

 This demo program show how to save a trained model and then load it for retraining. I splitted the original file into 2 which I used in this post "Predictive Model: Customer Subsciption (Continue/Discontinue) with Tensorflow". 


The output:

Orignal Model Accuracy result:


Loaded Model Accuracy result:


The code:

First program:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import os
import pandas as pd
from sklearn.model_selection import train_test_split
from tensorflow.keras.models import Sequential, load_model
from tensorflow.keras.layers import Dense, Flatten
from sklearn.metrics import accuracy_score
from sklearn.metrics import ConfusionMatrixDisplay, classification_report, confusion_matrix
from matplotlib import style
import tensorflow as tf
from tensorflow import keras


style.use('classic')
df = pd.read_csv('cont_subs.csv')
X = pd.get_dummies(df.drop(['cont_subs', 'Customer ID'], axis=1))
y = df['cont_subs'].apply(lambda x: 1 if x=='Yes' else 0)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.15)
X.columns

y_train.head()

model = Sequential()
model.add(Dense(units=64, activation='relu', input_dim=len(X_train.columns)))
model.add(Dense(units=128, activation='relu'))
model.add(Dense(units=128, activation='relu'))
model.add(Dense(units=1, activation='sigmoid'))

checkpoint_path = "training_1/cp.ckpt"
checkpoint_dir = os.path.dirname(checkpoint_path)

# Create a callback that saves the model's weights
cp_callback = tf.keras.callbacks.ModelCheckpoint(filepath=checkpoint_path,
                                                 save_weights_only=True,
                                                 verbose=1)

model.compile(loss='binary_crossentropy', optimizer='sgd', metrics='accuracy')

model.fit(X_train, y_train, epochs=256, batch_size=32, callbacks=[cp_callback])

y_hat = model.predict(X_test)
y_hat = [0 if val < 0.5 else 1 for val in y_hat]

print('Model Accuracy' + str(accuracy_score(y_test, y_hat)))

# Display the model's architecture
model.summary()

cm = confusion_matrix(y_test, y_hat)
disp = ConfusionMatrixDisplay(confusion_matrix = cm)
disp.plot()

model.save('my_model')

 

The Loaded Model Program:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
import pandas as pd
from sklearn.model_selection import train_test_split
from tensorflow.keras.models import Sequential, load_model
from tensorflow.keras.layers import Dense, Flatten
from sklearn.metrics import accuracy_score
from sklearn.metrics import ConfusionMatrixDisplay, classification_report, confusion_matrix
from matplotlib import style
import tensorflow as tf
from tensorflow import keras


style.use('classic')
df = pd.read_csv('cont_subs1.csv')
X = pd.get_dummies(df.drop(['cont_subs', 'Customer ID'], axis=1))
y = df['cont_subs'].apply(lambda x: 1 if x=='Yes' else 0)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.15)
X.columns
y_train.head()

new_model = tf.keras.models.load_model('my_model')

# Check its architecture
new_model.summary()
new_model = Sequential()
new_model.add(Dense(units=64, activation='relu', input_dim=len(X_train.columns)))
new_model.add(Dense(units=128, activation='relu'))
new_model.add(Dense(units=1, activation='sigmoid'))

checkpoint_path = "training_1/cp.ckpt"
checkpoint_dir = os.path.dirname(checkpoint_path)

# Create a callback that saves the model's weights
cp_callback = tf.keras.callbacks.ModelCheckpoint(filepath=checkpoint_path,
                                                 save_weights_only=True,
                                                 verbose=1)

new_model.compile(loss='binary_crossentropy', optimizer='sgd', metrics='accuracy')
new_model.fit(X_train, y_train, epochs=256, batch_size=32, callbacks=[cp_callback])
new_model.evaluate(X_train, y_train, verbose=2)
y_hat = new_model.predict(X_test)
y_hat = [0 if val < 0.5 else 1 for val in y_hat]

#accuracy_score(y_test, y_hat)
print('Loaded Model Accuracy' + str(accuracy_score(y_test, y_hat))) 


model.save('my_model')

new_model.summary()

Thursday, May 12, 2022

Create a Rich Text Document with Image and Printpreview using QTextEdit in PyQt6

This demo program shows how to create a rich text document with an image and print preview the contents.

The Output:




The code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from PyQt6.QtWidgets import QWidget, QPushButton, QApplication, QTextEdit
from PyQt6.QtCore import Qt
from PyQt6 import QtPrintSupport

import sys
class Example(QWidget):

    def __init__(self):
        super().__init__()

        self.initUI()


    def initUI(self):
    
        self.etext = QTextEdit(self)  
        self.etext.setReadOnly(True)        
        self.etext.setGeometry(25, 40, 300, 300)
        redText = "<span style=\" font-size:8pt; font-weight:600; color:#ff0000;\" >"
        redText = redText  + "I want this text red"
        redText = redText  + "</span>"
        self.etext.append(redText)

        blackText = "<p><span style=' font-size:12pt;'>CENTER</span></p>"      
        self.etext.append(blackText)
        self.etext.setAlignment(Qt.AlignmentFlag.AlignCenter)
        
        img = "<p><img src='balloon.png' style='width:50px;height:60px;' ></p>"
        self.etext.append(img)
        self.etext.setAlignment(Qt.AlignmentFlag.AlignRight)
        
        self.redb = QPushButton('Preview', self)       
        self.redb.setGeometry(250, 370, 80, 40)
        self.redb.clicked.connect(self.handlePreview)
        self.setGeometry(200, 100, 350, 430)
        self.setWindowTitle('Post 33')
        self.show()
        
    def handlePreview(self):
        dialog = QtPrintSupport.QPrintPreviewDialog()
        dialog.paintRequested.connect(self.etext.print)
        dialog.exec()  
def main():
    
    app = QApplication(sys.argv)
    ex = Example()
    
    sys.exit(app.exec())
   

if __name__ == '__main__':
    main()        

Wednesday, May 11, 2022

Upgrade 02: PyQt6 Desktop App Template

This demo program add another improvement of the desk top app template(original post here). The newly added feature is a the ability to login, a simple password encryption(sha256) and connecting to sa mysql database. Also added a top layer file that should perform system configuration before the splash screen is shown.

 

Login Info:

  UserName : admin

  Password :  Appl3Tr33.456

The output:

 


The mysql table:

 

1
2
3
4
5
6
7
CREATE TABLE `tbusr` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `username` varchar(256) NOT NULL,
 `userpassword` varchar(2048) NOT NULL,
 PRIMARY KEY (`id`),
 UNIQUE KEY `ind_usr` (`username`)
 ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1

 

The code:

The python code to encrypt the password:

 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import os
import hashlib
import hmac
password = "Appl3Tr33.456"
password = password.encode()
#salt = os.urandom(16)
password_hash = hashlib.pbkdf2_hmac("sha256", password, salt, 100000)

salt = b'4\xa8y\x8e\xca\xfb\x7f\x8e\xd5\x97v\x14\xc7[Z\xd0'
print(salt)
print(password_hash)

popular_app.py:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from imports import *
from splash import SplashScreen
class App(a.QWidget):
    def __init__(self, parent=None):
        super().__init__()
        self.setWindowTitle("")
        self.do_logging()
        self.setFixedSize(0, 0)
        self.hide()
        t.sleep(1)
        self.splash1 = SplashScreen()
        self.splash1.show() 
    def do_logging(self):
        print("Do something here...")
 
        
def main():

    app = a.QApplication(s.argv)
    app.setStyleSheet('''
        #title_label {
            font-size: 50px;
            color: #F0B21A;
        }
        #desc_label {
            font-size: 15px;
            color: #F0B21A;
        }
        #loading_label {
            font-size: 20px;
            color: #F0B21A;
        }
        QFrame {
            background-color: #2F339B;
            color: #c8c8c8;
        }
    ''')
    ex = App()
    s.exit(app.exec())


if __name__ == '__main__':
    main()


login.py:


  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
from imports import *
import mysql.connector as mysql
import hashlib
import hmac
import pandas as pd
from mainw import Window2

TIME_LIMIT = 100
class WindowApp(a.QMainWindow):
    def __init__(self, parent=None):
        super().__init__()
        self.setWindowTitle("Login")
        self.setFixedSize(320, 245)
        self.quit = g.QAction("Quit", self)
        self.quit.triggered.connect(self.closeEvent)
        self.move(400, 200) 
        lblusr =  a.QLabel('UserName', self)
        lblusr.setStyleSheet('QLabel {background-color: transparent; color: black;}')
        lblusr.setGeometry(25, 55, 100, 30) 
        self.txtusr = a.QLineEdit('', self) 
        
        self.txtusr.setGeometry(100, 55, 150, 30)  
        lblpwd =  a.QLabel('Password', self)
        lblpwd.setStyleSheet('QLabel {background-color: transparent; color: black;}')
        lblpwd.setGeometry(25, 100, 100, 30) 
        self.txtpwd = a.QLineEdit('', self) 
        self.txtusr.setPlaceholderText("Enter Username Here")
        self.txtpwd.setPlaceholderText("Enter Password Here")
        self.txtpwd.setGeometry(100, 100, 150, 30) 
        self.txtpwd.setEchoMode(a.QLineEdit.EchoMode.Password)        
        self.pblogin = a.QPushButton('Login', self)
        self.pblogin.setEnabled(False)
        self.pblogin.setGeometry(100, 165, 65, 25)
        self.pblogin.clicked.connect(self.onClick_pb3)  
        self.txtpwd.textChanged.connect(self.on_text_changed)
        self.txtusr.textChanged.connect(self.on_text_changed)
        pbcanc = a.QPushButton('Cancel', self)
        pbcanc.setGeometry(180, 165, 65, 25)
        pbcanc.clicked.connect(self.onClick_pb4)  
        self.statusBar = a.QStatusBar()
        self.setStatusBar(self.statusBar)
        self.statusBar.showMessage("Ready", 5000)        
        #self.show()
        
        self.progressBar = a.QProgressBar()
        self.progressBar.setStyleSheet("""QProgressBar {
            background-color: transparent;
            color: #9B2F6A;
            border-style: none;
            border-radius: 5px;
            text-align: center;
            font-size: 10px;
        }
        QProgressBar::chunk {
            border-radius: 5px;
            background-color: qlineargradient(spread:pad x1:0, x2:1, y1:0.511364, y2:0.523, stop:0 #E1F01A);
        }""")
        self.statusBar.addPermanentWidget(self.progressBar)
        self.progressBar.move(30, 40)
        self.progressBar.setFixedSize(120, 20)
        #self.progressBar.setValue(100)
    def on_text_changed(self):
        self.pblogin.setEnabled(bool(self.txtusr.text()) and bool(self.txtpwd.text()))
        
    def closeEvent(self, event):
        close = a.QMessageBox()
        close.setIcon(a.QMessageBox.Icon.Question)
        close.setWindowTitle('Pls confirm')
        close.setStyleSheet('QLabel {background-color: transparent; color: black;}')
        close.setText("Do you really want to quit?")
        close.setStandardButtons(a.QMessageBox.StandardButton.Yes | a.QMessageBox.StandardButton.Cancel)
        close = close.exec()

        if close == a.QMessageBox.StandardButton.Yes:
            event.accept()
        else:
            event.ignore()
    def onClick_pb3(self):
        db = mysql.connect(
             host = "localhost",
             user = "root",
             passwd = "",
             database = "pop_app"
        )
        cursor = db.cursor()
        t1 = self.txtusr.text()
        t2 = self.txtpwd.text()
        salt = b'4\xa8y\x8e\xca\xfb\x7f\x8e\xd5\x97v\x14\xc7[Z\xd0'
        print(t2)
        t2 = hashlib.pbkdf2_hmac("sha256", t2.encode(), salt, 100000)
        
        t1 = repr(str(t1))
        t2 = repr(str(t2))
        print(t2)
        query = "SELECT * FROM tbusr where username = %s and userpassword  = %s" %(t1, t2)
        cursor.execute(query)
        records = cursor.fetchall()
        df = pd.DataFrame(records) 
        count = 0
        while count < TIME_LIMIT:
            count += 1
            t.sleep(0.01)
            self.progressBar.setValue(count)
        if df.empty:    
            self.statusBar.showMessage("User not found!", 5000)
            self.txtusr.setStyleSheet('QLineEdit {background-color: #ffe6e6; color: black;}')
            self.txtusr.repaint()
            t.sleep(1.5)  
            self.txtusr.setStyleSheet('QLineEdit {background-color: white; color: black;}')
            self.txtusr.repaint()
        else:
            self.statusBar.showMessage("User found!", 5000)
            self.statusBar.repaint()
            t.sleep(2)
            self.showWindow2()
            
            self.hide()
            
        #self.w = Window2()       
        #self.w.show()
        
    def showWindow2(self):
        self.mdiwindow = Window2()
        self.mdiwindow.show()
    def onClick_pb4(self):
        self.quit 
        self.close()    
          
if __name__ == "__main__":       
    app = a.QApplication(s.argv)
    app.setStyleSheet('''        
        QProgressBar {
            background-color: #000000;
            color: #9B2F6A;
            border-style: none;
            border-radius: 4px;
            text-align: center;
            font-size: 10px;
        }
        QProgressBar::chunk {
            border-radius: 4px;
            background-color: qlineargradient(spread:pad x1:0, x2:1, y1:0.511364, y2:0.523, stop:0 #E1F01A);
        }
    ''')
    splash = WindowApp()
    splash.show()
    s.exit(app.exec())

Monday, May 2, 2022

Global Variables Handling across PyQt6 Windows

This demo program shows how to handle global variables across files or PyQt6 windows and execute a function from another file.


The output:




The code:

config.py:

1
2
a = 0
b = "empty"

update.py:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import config

config.a = 10
config.b = "alphabet"

def update(arg1, arg2):
    config.a = arg1
    config.b = arg2
    
def add(arg1, arg2):
    return arg1 + arg2

main.py:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from imports import *
from main1 import WindowApp1
import config
import update



class WindowApp(a.QMainWindow):
    def __init__(self, parent=None):
        super().__init__()
        self.setWindowTitle("Post 31")
        self.setFixedSize(320, 245)
        
        lbla =  a.QLabel('Global a: ', self)        
        lbla.setGeometry(25, 55, 100, 30) 
        
        self.txta = a.QLineEdit(str(config.a), self)        
        self.txta.setGeometry(100, 55, 50, 30) 
        
        self.lbla_r =  a.QLabel(str(config.a), self)        
        self.lbla_r.setGeometry(170, 55, 50, 30)
        
        lblb =  a.QLabel('Global b: ', self)        
        lblb.setGeometry(25, 100, 100, 30) 
        
        self.txtb = a.QLineEdit(config.b, self) 
        self.txtb.setGeometry(100, 100, 50, 30) 
        
        self.lblb_r =  a.QLabel(config.b, self)        
        self.lblb_r.setGeometry(170, 100, 50, 30) 
        
        self.pblogin = a.QPushButton('Login', self)
        self.pblogin.setGeometry(50, 195, 65, 25)
        self.pblogin.clicked.connect(self.onClick_pb3)
        
        pbcanc = a.QPushButton('Update', self)
        pbcanc.setGeometry(125, 195, 65, 25)
        pbcanc.clicked.connect(self.onClick_pb4)
        
        pbcalc = a.QPushButton('Function', self)
        pbcalc.setGeometry(200, 195, 65, 25)
        pbcalc.clicked.connect(self.onClick_pb5)
        
        lblf =  a.QLabel('Function: ', self)        
        lblf.setGeometry(25, 140, 75, 30) 
        
        self.txtfa = a.QLineEdit(self) 
        self.txtfa.setGeometry(100, 140, 40, 30)
        
        lblfp =  a.QLabel('+', self)        
        lblfp.setGeometry(150, 140, 10, 30) 
        
        self.txtfb = a.QLineEdit(self) 
        self.txtfb.setGeometry(165, 140, 40, 30)
        
        self.lblf_r =  a.QLabel( self)        
        self.lblf_r.setGeometry(215, 140, 40, 30)
        
    def onClick_pb3(self):
        self.mdiwindow = WindowApp1()
        self.mdiwindow.show()
        self.hide()
    def onClick_pb4(self): 
          
        a = int(self.txta.text())
        b = self.txtb.text()

        update.update(a,b)
        
        self.lbla_r.setText(str(config.a))
        self.lblb_r.setText(config.b)
 
    def onClick_pb5(self):
        self.lblf_r.setText('= ' + str(update.add(int(self.txtfa.text()),int(self.txtfb.text())))) 

if __name__ == "__main__":       
    app = a.QApplication(s.argv)
 
    splash = WindowApp()
    splash.show()
    s.exit(app.exec())        

main1.py:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from imports import *
import config




class WindowApp1(a.QMainWindow):
    def __init__(self, parent=None):
        super().__init__()
        self.setWindowTitle("Post 31")
        self.setFixedSize(320, 245)
        self.lbla =  a.QLabel('Global a: ', self)        
        self.lbla.setGeometry(25, 55, 100, 30) 
        
        self.lblb =  a.QLabel('Global b: ', self)        
        self.lblb.setGeometry(25, 100, 100, 30)
        
        self.pblogin = a.QPushButton('End', self)
        self.pblogin.setGeometry(100, 165, 65, 25)
        self.pblogin.clicked.connect(self.onClick_pb3)
        pbcanc = a.QPushButton('Print', self)
        pbcanc.setGeometry(180, 165, 65, 25)
        pbcanc.clicked.connect(self.onClick_pb4)
        
        
    def onClick_pb3(self):       
        self.close()
        
    def onClick_pb4(self): 
     
        self.lbla.setText('Global a: ' + str(config.a))
        self.lblb.setText('Global b: ' + config.b)
if __name__ == "__main__":       
    app = a.QApplication(s.argv)
 
    splash = WindowApp1()
    splash.show()
    s.exit(app.exec())          

Sunday, May 1, 2022

Create a Lock Screen in Windows with PyQt6

This demo program shows how to create a lockscreen and detect any movement within the Windows OS. 

The Output: 

 


The Code: 

 


  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import sys
from PyQt6.QtCore import *
from PyQt6.QtGui import *
from PyQt6.QtWidgets import *
import time
from ctypes import *
x_idle = 0
x_idle_toggle = 0
start_tmr = 0
class XScreenSaverInfo(Structure):
    _fields_ = [('window', c_long),
                ('state', c_int),
                ('kind', c_int),
                ('til_or_since',c_ulong),
                ('idle', c_ulong),
                ('eventMask', c_ulong)]

class LASTINPUTINFO(Structure):
    _fields_ = [
        ('cbSize', c_uint),
        ('dwTime', c_uint),
    ]
def get_idle_duration():
    lastInputInfo = LASTINPUTINFO()
    lastInputInfo.cbSize = sizeof(lastInputInfo)
    windll.user32.GetLastInputInfo(byref(lastInputInfo))
    millis = windll.kernel32.GetTickCount() - lastInputInfo.dwTime
    return millis / 1000.0

class inputdialogdemo(QMainWindow):
    def __init__(self, parent = None):
      super(inputdialogdemo, self).__init__(parent)
      fnt = QFont('Open Sans', 16, QFont.Weight.Bold)
      self.lblIdle = QLabel('Idle Time', self)
      self.lblIdle.setFont(fnt)
      self.lblIdle.setGeometry(20, 40, 300, 30)
      pb3 = QPushButton('Show Lockscreen ', self)
      pb3.setGeometry(50, 100, 130, 30)
      
      pb3.clicked.connect(self.onClick_pb3)
      pb5 = QPushButton('Reset Idle', self)
      pb5.setGeometry(200, 100, 130, 30)
      
      pb5.clicked.connect(self.onClick_pb5)
      self.timer = QTimer(self)
      self.timer.timeout.connect(self.showTime)
      self.timer.start(1000) # update every second
      
      self.move(100, 200)
      self.setFixedSize(400, 300)
      self.setWindowTitle('Post 30')
    def exec_idel(self):
      global x_idle_toggle
      global x_idle
      global start_tmr
        
      while x_idle_toggle ==1:
        GetLastInputInfo = int(get_idle_duration())
        print(GetLastInputInfo)
        if GetLastInputInfo == 1:
          start_tmr = 1
          x_idle = 0
          x_idle_toggle = 0
          #self.timer.stop()
          self.buildExamplePopup()
          break
        if GetLastInputInfo == 1:
          start_tmr = 1
          x_idle = 0
          x_idle_toggle = 0
          #self.timer.stop()
          self.buildExamplePopup()
          break
        time.sleep(1)      
    def start_timer(self):
        global x_idle
        x_idle = 0 
        #self.timer = QTimer(self)
        #self.timer.timeout.connect(self.showTime)
        self.lblIdle.setText("Idle Time: " + str(x_idle))
        self.timer.start(1000) # update every second
        
        
    def mousePressEvent(self, QMouseEvent):
        global x_idle
        x_idle = 0     
    def showTime(self):
        global x_idle
        global x_idle_toggle
        global start_tmr
        self.lblIdle.setText("Idle Time: " + str(x_idle))
        if start_tmr == 0:
           x_idle = x_idle + 1
        if x_idle > 10 and x_idle_toggle == 0:
           x_idle_toggle = 1
           x_idle = 0
           self.exec_idel()
    def onClick_pb5(self):
        global x_idle
        x_idle = 0 
        self.lblIdle.setText("Idle Time: " + str(x_idle))
        self.timer.start(1000)
    def onClick_pb3(self):
        global x_idle
        global start_tmr
        start_tmr = 1
        x_idle = 0
        #self.timer.stop()
        self.buildExamplePopup()
    def buildExamplePopup(self):
        name = 'Lock Screen'
        self.exPopup = examplePopup(name)
        
        #self.exPopup.setGeometry(self.pos().x()+50, self.pos().y()+75, 300, 225)
        self.exPopup.move(self.pos().x()+50, self.pos().y()+75)
        self.exPopup.setFixedSize(300, 225)
        self.exPopup.show()
        
class examplePopup(QMainWindow):
    def __init__(self, name):
        super().__init__()
        
        self.name = name
        self.setWindowFlags(Qt.WindowType.Window | Qt.WindowType.CustomizeWindowHint | Qt.WindowType.WindowStaysOnTopHint)
        self.initUI()

    def initUI(self):
        fnt = QFont('Open Sans', 16, QFont.Weight.Bold)
        lblName = QLabel(self.name, self)
        lblName.setFont(fnt)
        lblName.setGeometry(50, 40, 200, 30)
        lblpwd =  QLabel('Password', self)
        lblpwd.setStyleSheet('QLabel {background-color: transparent; color: black;}')
        lblpwd.setGeometry(25, 115, 100, 30) 
        txtpwd = QLineEdit('', self) 

        txtpwd.setPlaceholderText("Enter Password Here")
        txtpwd.setGeometry(110, 115, 150, 30) 
        txtpwd.setEchoMode(QLineEdit.EchoMode.Password)
        
        pb4 = QPushButton('Ok', self)
        pb4.move(90, 175)
        
        pb4.clicked.connect(self.onClick_pb4)
        
    def mousePressEvent(self, QMouseEvent):
        global x_idle
        x_idle = 0 
    def onClick_pb4(self):
        global x_idle
        global start_tmr 

        start_tmr = 0
        
        x_idle = 0 
        
        self.close()
        
        
        	
def main(): 
   app = QApplication(sys.argv)
   ex = inputdialogdemo()
   ex.show()
   sys.exit(app.exec())
	
if __name__ == '__main__':
   main()