python-lottie  0.6.11+deved4e6c7
A framework to work with lottie files and telegram animated stickers (tgs)
search_widget.py
Go to the documentation of this file.
1 from PyQt5.QtGui import QIcon
2 from PyQt5.QtCore import Qt, QTimer
3 from PyQt5.QtCore import pyqtSignal as Signal
4 from PyQt5.QtCore import pyqtSlot as Slot
5 from PyQt5.QtWidgets import *
6 
7 
8 class SearchWidget(QWidget):
9  frame_changed = Signal(int)
10 
11  def __init__(self, target):
12  super().__init__()
13  self.targettarget = target
14 
15  layout_slider = QHBoxLayout()
16  layout_slider.setContentsMargins(0, 0, 0, 0)
17  self.setLayout(layout_slider)
18 
19  self.line_findline_find = QLineEdit()
20  self.line_findline_find.setPlaceholderText("Find")
21  self.line_findline_find.returnPressed.connect(self.find_nextfind_next)
22  layout_slider.addWidget(self.line_findline_find)
23 
24  self.line_replaceline_replace = QLineEdit()
25  self.line_replaceline_replace.setPlaceholderText("Replace")
26  self.line_replaceline_replace.returnPressed.connect(self.replacereplace)
27  layout_slider.addWidget(self.line_replaceline_replace)
28 
29  self.button_nextbutton_next = QPushButton()
30  self.button_nextbutton_next.setIcon(QIcon.fromTheme("go-down-search"))
31  self.button_nextbutton_next.clicked.connect(self.find_nextfind_next)
32  self.button_nextbutton_next.setToolTip("Next")
33  layout_slider.addWidget(self.button_nextbutton_next)
34 
35  self.button_prevbutton_prev = QPushButton()
36  self.button_prevbutton_prev.setIcon(QIcon.fromTheme("go-up-search"))
37  self.button_prevbutton_prev.clicked.connect(self.find_prevfind_prev)
38  self.button_nextbutton_next.setToolTip("Previous")
39  layout_slider.addWidget(self.button_prevbutton_prev)
40 
41  self.button_replbutton_repl = QPushButton()
42  self.button_replbutton_repl.setText("Replace")
43  self.button_replbutton_repl.clicked.connect(self.replacereplace)
44  layout_slider.addWidget(self.button_replbutton_repl)
45 
46  self.button_casebutton_case = QPushButton()
47  self.button_casebutton_case.setCheckable(True)
48  self.button_casebutton_case.setIcon(QIcon.fromTheme("format-text-superscript"))
49  self.button_casebutton_case.setToolTip("Case Sensitive")
50  layout_slider.addWidget(self.button_casebutton_case)
51 
52  self.combo_modecombo_mode = QComboBox()
53  self.combo_modecombo_mode.addItem("Text")
54  self.combo_modecombo_mode.addItem("RegExp")
55  layout_slider.addWidget(self.combo_modecombo_mode)
56 
57  self.button_selectionbutton_selection = QPushButton()
58  self.button_selectionbutton_selection.setCheckable(True)
59  self.button_selectionbutton_selection.setIcon(QIcon.fromTheme("edit-select-all"))
60  self.button_selectionbutton_selection.setToolTip("Only in selection")
61  layout_slider.addWidget(self.button_selectionbutton_selection)
62 
63  self.set_replace_enabledset_replace_enabled(False)
64 
65  def start_search(self, replace):
66  if self.targettarget.hasSelectedText():
67  st = self.targettarget.selectedText()
68  if "\n" in st:
69  self.button_selectionbutton_selection.setChecked(True)
70  else:
71  self.button_selectionbutton_selection.setChecked(False)
72  self.line_findline_find.setText(st)
73  self.line_findline_find.selectAll()
74  self.line_findline_find.setFocus(True)
75  self.set_replace_enabledset_replace_enabled(replace)
76 
77  def set_replace_enabled(self, show):
78  #self.button_selection.setChecked(show != self.button_selection.isVisible())
79  #self.button_selection.setVisible(show)
80  self.line_replaceline_replace.setVisible(show)
81  self.button_replbutton_repl.setVisible(show)
82 
83  def find(self, forward):
84  func = self.targettarget.findFirst if not self.button_selectionbutton_selection.isChecked() else self.targettarget.findFirstInSelection
85  func(
86  self.line_findline_find.text(),
87  self.combo_modecombo_mode.currentIndex() != 0,
88  self.button_casebutton_case.isChecked(),
89  False,
90  True,
91  forward,
92  True
93  )
94 
95  def find_next(self):
96  return self.findfind(True)
97 
98  def find_prev(self):
99  return self.findfind(False)
100 
101  def replace(self):
102  self.targettarget.replace(self.line_replaceline_replace.text())
103  self.find_nextfind_next()