-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearching_page.py
46 lines (38 loc) · 1.37 KB
/
searching_page.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
import sys
from search_page import Ui_Form
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5 import QtCore, QtGui, QtWidgets
class MySearchWidget(QMainWindow, Ui_Form):
def __init__(self, text=""):
super().__init__()
# self.text = self.get_text()
self.text = text
self.setupUi(self)
self.lineEdit.setText("поиск")
self.lineEdit.setPlaceholderText("что каво зачем")
self.lineEdit.setStyleSheet("QLineEdit {color:red}")
self.setWindowTitle("Поисковая страница")
# self.textEdit.print()
self.pushButton.clicked.connect(self.run)
# Обратите внимание: имя элемента такое же как в QTDesigner
def get_text(self):
try:
from test01 import MainWindow
text = MainWindow.textEdit.toPlainText()
return text
except Exception:
return ""
def run(self):
a = self.text.lower().split("\n")
b = self.lineEdit.text()
numbers = []
for i in range(len(a)):
if b in a[i]:
numbers.append(i + 1)
if numbers:
self.lineEdit.setText(f"FIND: '{b}' in lines: {numbers}")
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MySearchWidget()
ex.show()
sys.exit(app.exec_())