Add search function
Add the possibility to search in the content Display only line where a match was found Highlight match
This commit is contained in:
parent
03c0ad0635
commit
28585c1089
@ -13,6 +13,9 @@
|
|||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Form</string>
|
<string>Form</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="styleSheet">
|
||||||
|
<string notr="true">font: 11pt "UbuntuMono NF";</string>
|
||||||
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QSplitter" name="splitter">
|
<widget class="QSplitter" name="splitter">
|
||||||
@ -22,7 +25,7 @@
|
|||||||
<widget class="QWidget" name="layoutWidget">
|
<widget class="QWidget" name="layoutWidget">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="lineEdit">
|
<widget class="QLineEdit" name="search_line_edit">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Search</string>
|
<string>Search</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>1214</width>
|
<width>1214</width>
|
||||||
<height>896</height>
|
<height>888</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@ -15,7 +15,7 @@
|
|||||||
</property>
|
</property>
|
||||||
<property name="styleSheet">
|
<property name="styleSheet">
|
||||||
<string notr="true">background-color: rgb(42, 42, 42);
|
<string notr="true">background-color: rgb(42, 42, 42);
|
||||||
font: 12pt "UbuntuMono NF";
|
font: 11pt "UbuntuMono NF";
|
||||||
selection-background-color: rgb(105, 105, 105);
|
selection-background-color: rgb(105, 105, 105);
|
||||||
color: rgb(230, 230, 230);</string>
|
color: rgb(230, 230, 230);</string>
|
||||||
</property>
|
</property>
|
||||||
@ -48,24 +48,27 @@ background-color: rgb(105, 105, 105);</string>
|
|||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="handleWidth">
|
<property name="handleWidth">
|
||||||
<number>4</number>
|
<number>2</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="layoutWidget">
|
<widget class="QWidget" name="layoutWidget">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<property name="spacing">
|
<property name="spacing">
|
||||||
<number>4</number>
|
<number>2</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="lineEdit">
|
<widget class="QLineEdit" name="search_line_edit">
|
||||||
<property name="styleSheet">
|
<property name="styleSheet">
|
||||||
<string notr="true">background-color: rgb(42, 42, 42);</string>
|
<string notr="true">background-color: rgb(42, 42, 42);</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Search</string>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
<property name="frame">
|
<property name="frame">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>Search...</string>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
@ -80,19 +83,13 @@ background-color: rgb(105, 105, 105);</string>
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QPlainTextEdit" name="detail_plain_text_edit">
|
<widget class="QTextEdit" name="detail_text_edit">
|
||||||
<property name="styleSheet">
|
<property name="styleSheet">
|
||||||
<string notr="true">background-color: rgb(42, 42, 42);</string>
|
<string notr="true">background-color: rgb(42, 42, 42);</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="frameShape">
|
<property name="frameShape">
|
||||||
<enum>QFrame::NoFrame</enum>
|
<enum>QFrame::NoFrame</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="undoRedoEnabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="lineWrapMode">
|
|
||||||
<enum>QPlainTextEdit::NoWrap</enum>
|
|
||||||
</property>
|
|
||||||
<property name="readOnly">
|
<property name="readOnly">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
from PySide6.QtWidgets import QWidget
|
from PySide6.QtWidgets import QWidget
|
||||||
|
from PySide6.QtCore import QSize
|
||||||
|
from PySide6.QtGui import QTextCharFormat, QTextCursor, QColor
|
||||||
from ui_main_window import Ui_MainWindow
|
from ui_main_window import Ui_MainWindow
|
||||||
from file_cmds import FileCmds
|
from file_cmds import FileCmds
|
||||||
from PySide6.QtCore import QSize
|
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(QWidget, Ui_MainWindow):
|
class MainWindow(QWidget, Ui_MainWindow):
|
||||||
@ -19,6 +20,7 @@ class MainWindow(QWidget, Ui_MainWindow):
|
|||||||
|
|
||||||
def setupConnections(self):
|
def setupConnections(self):
|
||||||
self.tracks_list_widget.itemSelectionChanged.connect(self.popuplate_content)
|
self.tracks_list_widget.itemSelectionChanged.connect(self.popuplate_content)
|
||||||
|
self.search_line_edit.textChanged.connect(self.search)
|
||||||
|
|
||||||
|
|
||||||
def dragEnterEvent(self, event):
|
def dragEnterEvent(self, event):
|
||||||
@ -54,5 +56,50 @@ class MainWindow(QWidget, Ui_MainWindow):
|
|||||||
def popuplate_content(self):
|
def popuplate_content(self):
|
||||||
item_selected = self.tracks_list_widget.selectedItems()
|
item_selected = self.tracks_list_widget.selectedItems()
|
||||||
if item_selected:
|
if item_selected:
|
||||||
text = self.file_cmds.tabs_content[item_selected[0].text()]
|
self.content = self.file_cmds.tabs_content[item_selected[0].text()]
|
||||||
self.detail_plain_text_edit.setPlainText(text)
|
self.detail_text_edit.setPlainText(self.content)
|
||||||
|
self.search()
|
||||||
|
|
||||||
|
|
||||||
|
def search(self):
|
||||||
|
to_search = self.search_line_edit.text()
|
||||||
|
|
||||||
|
if not to_search:
|
||||||
|
self.detail_text_edit.setPlainText(self.content)
|
||||||
|
return
|
||||||
|
|
||||||
|
content_list = self.content.split("\n")
|
||||||
|
|
||||||
|
searched_content = []
|
||||||
|
|
||||||
|
for line in content_list:
|
||||||
|
if to_search.lower() in line.lower():
|
||||||
|
searched_content.append(line)
|
||||||
|
# elif line == "" and not searched_content[-1] == "":
|
||||||
|
elif line == "":
|
||||||
|
if searched_content and not searched_content[-1] == "":
|
||||||
|
searched_content.append(line)
|
||||||
|
|
||||||
|
searched_content = "\n".join(searched_content)
|
||||||
|
self.detail_text_edit.setPlainText(searched_content)
|
||||||
|
|
||||||
|
def add_selection():
|
||||||
|
sel = self.detail_text_edit.ExtraSelection()
|
||||||
|
sel.cursor = cursor
|
||||||
|
sel.format = fmt
|
||||||
|
selections.append(sel)
|
||||||
|
|
||||||
|
selections = []
|
||||||
|
doc = self.detail_text_edit.document()
|
||||||
|
fmt = QTextCharFormat()
|
||||||
|
fmt.setBackground(QColor(0,128,0))
|
||||||
|
cursor = QTextCursor()
|
||||||
|
while True:
|
||||||
|
cursor = doc.find(to_search, cursor)
|
||||||
|
if cursor.isNull() or cursor.atEnd():
|
||||||
|
if cursor.atEnd():
|
||||||
|
if cursor.selectedText() == to_search:
|
||||||
|
add_selection()
|
||||||
|
break
|
||||||
|
add_selection()
|
||||||
|
self.detail_text_edit.setExtraSelections(selections)
|
@ -16,16 +16,16 @@ from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
|
|||||||
QImage, QKeySequence, QLinearGradient, QPainter,
|
QImage, QKeySequence, QLinearGradient, QPainter,
|
||||||
QPalette, QPixmap, QRadialGradient, QTransform)
|
QPalette, QPixmap, QRadialGradient, QTransform)
|
||||||
from PySide6.QtWidgets import (QApplication, QFrame, QLineEdit, QListWidget,
|
from PySide6.QtWidgets import (QApplication, QFrame, QLineEdit, QListWidget,
|
||||||
QListWidgetItem, QPlainTextEdit, QSizePolicy, QSplitter,
|
QListWidgetItem, QSizePolicy, QSplitter, QTextEdit,
|
||||||
QVBoxLayout, QWidget)
|
QVBoxLayout, QWidget)
|
||||||
|
|
||||||
class Ui_MainWindow(object):
|
class Ui_MainWindow(object):
|
||||||
def setupUi(self, MainWindow):
|
def setupUi(self, MainWindow):
|
||||||
if not MainWindow.objectName():
|
if not MainWindow.objectName():
|
||||||
MainWindow.setObjectName(u"MainWindow")
|
MainWindow.setObjectName(u"MainWindow")
|
||||||
MainWindow.resize(1214, 896)
|
MainWindow.resize(1214, 888)
|
||||||
MainWindow.setStyleSheet(u"background-color: rgb(42, 42, 42);\n"
|
MainWindow.setStyleSheet(u"background-color: rgb(42, 42, 42);\n"
|
||||||
"font: 12pt \"UbuntuMono NF\";\n"
|
"font: 11pt \"UbuntuMono NF\";\n"
|
||||||
"selection-background-color: rgb(105, 105, 105);\n"
|
"selection-background-color: rgb(105, 105, 105);\n"
|
||||||
"color: rgb(230, 230, 230);")
|
"color: rgb(230, 230, 230);")
|
||||||
self.verticalLayout_2 = QVBoxLayout(MainWindow)
|
self.verticalLayout_2 = QVBoxLayout(MainWindow)
|
||||||
@ -38,19 +38,19 @@ class Ui_MainWindow(object):
|
|||||||
"background-color: rgb(105, 105, 105);")
|
"background-color: rgb(105, 105, 105);")
|
||||||
self.splitter.setFrameShadow(QFrame.Plain)
|
self.splitter.setFrameShadow(QFrame.Plain)
|
||||||
self.splitter.setOrientation(Qt.Horizontal)
|
self.splitter.setOrientation(Qt.Horizontal)
|
||||||
self.splitter.setHandleWidth(4)
|
self.splitter.setHandleWidth(2)
|
||||||
self.layoutWidget = QWidget(self.splitter)
|
self.layoutWidget = QWidget(self.splitter)
|
||||||
self.layoutWidget.setObjectName(u"layoutWidget")
|
self.layoutWidget.setObjectName(u"layoutWidget")
|
||||||
self.verticalLayout = QVBoxLayout(self.layoutWidget)
|
self.verticalLayout = QVBoxLayout(self.layoutWidget)
|
||||||
self.verticalLayout.setSpacing(4)
|
self.verticalLayout.setSpacing(2)
|
||||||
self.verticalLayout.setObjectName(u"verticalLayout")
|
self.verticalLayout.setObjectName(u"verticalLayout")
|
||||||
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
|
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
|
||||||
self.lineEdit = QLineEdit(self.layoutWidget)
|
self.search_line_edit = QLineEdit(self.layoutWidget)
|
||||||
self.lineEdit.setObjectName(u"lineEdit")
|
self.search_line_edit.setObjectName(u"search_line_edit")
|
||||||
self.lineEdit.setStyleSheet(u"background-color: rgb(42, 42, 42);")
|
self.search_line_edit.setStyleSheet(u"background-color: rgb(42, 42, 42);")
|
||||||
self.lineEdit.setFrame(False)
|
self.search_line_edit.setFrame(False)
|
||||||
|
|
||||||
self.verticalLayout.addWidget(self.lineEdit)
|
self.verticalLayout.addWidget(self.search_line_edit)
|
||||||
|
|
||||||
self.tracks_list_widget = QListWidget(self.layoutWidget)
|
self.tracks_list_widget = QListWidget(self.layoutWidget)
|
||||||
self.tracks_list_widget.setObjectName(u"tracks_list_widget")
|
self.tracks_list_widget.setObjectName(u"tracks_list_widget")
|
||||||
@ -60,14 +60,12 @@ class Ui_MainWindow(object):
|
|||||||
self.verticalLayout.addWidget(self.tracks_list_widget)
|
self.verticalLayout.addWidget(self.tracks_list_widget)
|
||||||
|
|
||||||
self.splitter.addWidget(self.layoutWidget)
|
self.splitter.addWidget(self.layoutWidget)
|
||||||
self.detail_plain_text_edit = QPlainTextEdit(self.splitter)
|
self.detail_text_edit = QTextEdit(self.splitter)
|
||||||
self.detail_plain_text_edit.setObjectName(u"detail_plain_text_edit")
|
self.detail_text_edit.setObjectName(u"detail_text_edit")
|
||||||
self.detail_plain_text_edit.setStyleSheet(u"background-color: rgb(42, 42, 42);")
|
self.detail_text_edit.setStyleSheet(u"background-color: rgb(42, 42, 42);")
|
||||||
self.detail_plain_text_edit.setFrameShape(QFrame.NoFrame)
|
self.detail_text_edit.setFrameShape(QFrame.NoFrame)
|
||||||
self.detail_plain_text_edit.setUndoRedoEnabled(False)
|
self.detail_text_edit.setReadOnly(True)
|
||||||
self.detail_plain_text_edit.setLineWrapMode(QPlainTextEdit.NoWrap)
|
self.splitter.addWidget(self.detail_text_edit)
|
||||||
self.detail_plain_text_edit.setReadOnly(True)
|
|
||||||
self.splitter.addWidget(self.detail_plain_text_edit)
|
|
||||||
|
|
||||||
self.verticalLayout_2.addWidget(self.splitter)
|
self.verticalLayout_2.addWidget(self.splitter)
|
||||||
|
|
||||||
@ -79,6 +77,7 @@ class Ui_MainWindow(object):
|
|||||||
|
|
||||||
def retranslateUi(self, MainWindow):
|
def retranslateUi(self, MainWindow):
|
||||||
MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"Form", None))
|
MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"Form", None))
|
||||||
self.lineEdit.setText(QCoreApplication.translate("MainWindow", u"Search", None))
|
self.search_line_edit.setText("")
|
||||||
|
self.search_line_edit.setPlaceholderText(QCoreApplication.translate("MainWindow", u"Search...", None))
|
||||||
# retranslateUi
|
# retranslateUi
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user