from
PyQt5.QtWidgets
import
*
from
PyQt5
import
QtCore, QtGui
from
PyQt5.QtGui
import
*
from
PyQt5.QtCore
import
*
import
sys
class
Window(QMainWindow):
number
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
]
desired
=
[
10
,
11
,
8
,
4
]
def
__init__(
self
):
super
().__init__()
self
.setWindowTitle("Sub
Set
Search")
self
.setGeometry(
100
,
100
,
600
,
400
)
self
.UiComponents()
self
.show()
def
UiComponents(
self
):
self
.start
=
False
self
.label_list
=
[]
self
.match
=
[]
self
.list_index
=
0
self
.sub_index
=
0
c
=
0
for
i
in
self
.number:
label
=
QLabel(
str
(i),
self
)
label.setStyleSheet("border :
1px
solid black;
background : white;")
label.setAlignment(Qt.AlignTop)
label.setGeometry(
50
+
c
*
30
,
50
,
20
, i
*
10
+
10
)
self
.label_list.append(label)
c
=
c
+
1
self
.search_button
=
QPushButton("Start Search",
self
)
self
.search_button.setGeometry(
100
,
270
,
100
,
30
)
self
.search_button.clicked.connect(
self
.search_action)
pause_button
=
QPushButton("Pause",
self
)
pause_button.setGeometry(
100
,
320
,
100
,
30
)
pause_button.clicked.connect(
self
.pause_action)
self
.result
=
QLabel("To search : "
+
str
(
self
.desired),
self
)
self
.result.setGeometry(
320
,
280
,
250
,
40
)
self
.result.setStyleSheet("border :
3px
solid black;")
self
.result.setFont(QFont(
'Times'
,
10
))
self
.result.setAlignment(Qt.AlignCenter)
timer
=
QTimer(
self
)
timer.timeout.connect(
self
.showTime)
timer.start(
300
)
def
showTime(
self
):
if
self
.start:
if
self
.list_index >
=
len
(
self
.number):
self
.start
=
False
self
.result.setText("Not Found")
return
if
self
.desired[
self
.sub_index]
=
=
self
.number[
self
.list_index]:
self
.match.append(
self
.list_index)
for
i
in
range
(
len
(
self
.label_list)):
self
.label_list[i].setStyleSheet(
"border :
1px
solid yellow;"
"background
-
color : white;"
)
if
i
in
self
.match:
self
.label_list[i].setStyleSheet(
"border :
2px
solid yellow;"
"background
-
color : yellow;" )
self
.sub_index
+
=
1
self
.list_index
=
0
else
:
self
.label_list[
self
.sub_index
+
self
.list_index].setStyleSheet(
"border :" "
1px
solid black;"
"background
-
color : grey;" )
self
.list_index
+
=
1
if
len
(
self
.match)
=
=
len
(
self
.desired):
self
.start
=
False
self
.result.setText("Found at : "
+
str
(
self
.match))
for
i
in
self
.match:
self
.label_list[i].setStyleSheet(
"border :
2px
solid green;"
"background
-
color : lightgreen;")
def
search_action(
self
):
self
.start
=
True
self
.result.setText("Started searching...")
def
pause_action(
self
):
self
.start
=
False
self
.result.setText("Paused")
App
=
QApplication(sys.argv)
window
=
Window()
sys.exit(App.
exec
())