117 lines
3.7 KiB
Python
117 lines
3.7 KiB
Python
from PySide6.QtWidgets import QWidget
|
|
from PySide6.QtCore import QSize
|
|
from PySide6.QtGui import QTextCharFormat, QTextCursor, QColor, QTextBlockFormat
|
|
from ui_main_window import Ui_MainWindow
|
|
from file_cmds import FileCmds
|
|
|
|
|
|
class MainWindow(QWidget, Ui_MainWindow):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.setupUi(self)
|
|
self.window_title = "mediaInfoSama"
|
|
self.setWindowTitle(self.window_title)
|
|
self.setAcceptDrops(True)
|
|
self.setupConnections()
|
|
|
|
self.splitter.setStretchFactor(0, False)
|
|
self.splitter.setStretchFactor(1, True)
|
|
|
|
self.detail_text_edit.setFont("UbuntuMono NF")
|
|
self.detail_text_edit.zoomIn(2)
|
|
|
|
|
|
def setupConnections(self):
|
|
self.tracks_list_widget.itemSelectionChanged.connect(self.popuplate_content)
|
|
self.search_line_edit.textChanged.connect(self.search)
|
|
|
|
|
|
def dragEnterEvent(self, event):
|
|
event.accept()
|
|
|
|
|
|
def dragMoveEvent(self, event):
|
|
event.accept()
|
|
|
|
|
|
def dropEvent(self, event):
|
|
self.file_path = event.mimeData().urls()[0].toLocalFile()
|
|
self.file_cmds = FileCmds(self.file_path)
|
|
|
|
if self.file_cmds.file_exist() == False:
|
|
return
|
|
|
|
self.setWindowTitle(f"{self.file_path} - {self.window_title}")
|
|
self.populate_tabs()
|
|
self.tracks_list_widget.item(0).setSelected(True)
|
|
|
|
|
|
def populate_tabs(self):
|
|
self.tracks_list_widget.clear()
|
|
self.tracks_list_widget.addItems(self.file_cmds.tabs_list)
|
|
|
|
for i in range(self.tracks_list_widget.count()):
|
|
item = self.tracks_list_widget.item(i)
|
|
height = self.tracks_list_widget.sizeHintForRow(0)
|
|
item.setSizeHint(QSize(0, height+5))
|
|
|
|
|
|
def popuplate_content(self):
|
|
item_selected = self.tracks_list_widget.selectedItems()
|
|
if item_selected:
|
|
self.content = self.file_cmds.tabs_content[item_selected[0].text()]
|
|
self.detail_text_edit.setPlainText(self.content)
|
|
self.search()
|
|
self.wrap_line_indent()
|
|
|
|
|
|
def wrap_line_indent(self):
|
|
cursor = QTextCursor(self.detail_text_edit.document())
|
|
cursor.select(QTextCursor.Document)
|
|
fmt = QTextBlockFormat()
|
|
fmt.setLeftMargin(100)
|
|
fmt.setTextIndent(-100)
|
|
cursor.mergeBlockFormat(fmt)
|
|
|
|
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) |