python-lottie  0.6.11+devcecd248
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.target = target
14 
15  layout_slider = QHBoxLayout()
16  layout_slider.setContentsMargins(0, 0, 0, 0)
17  self.setLayout(layout_slider)
18 
19  self.line_find = QLineEdit()
20  self.line_find.setPlaceholderText("Find")
21  self.line_find.returnPressed.connect(self.find_next)
22  layout_slider.addWidget(self.line_find)
23 
24  self.line_replace = QLineEdit()
25  self.line_replace.setPlaceholderText("Replace")
26  self.line_replace.returnPressed.connect(self.replace)
27  layout_slider.addWidget(self.line_replace)
28 
29  self.button_next = QPushButton()
30  self.button_next.setIcon(QIcon.fromTheme("go-down-search"))
31  self.button_next.clicked.connect(self.find_next)
32  self.button_next.setToolTip("Next")
33  layout_slider.addWidget(self.button_next)
34 
35  self.button_prev = QPushButton()
36  self.button_prev.setIcon(QIcon.fromTheme("go-up-search"))
37  self.button_prev.clicked.connect(self.find_prev)
38  self.button_next.setToolTip("Previous")
39  layout_slider.addWidget(self.button_prev)
40 
41  self.button_repl = QPushButton()
42  self.button_repl.setText("Replace")
43  self.button_repl.clicked.connect(self.replace)
44  layout_slider.addWidget(self.button_repl)
45 
46  self.button_case = QPushButton()
47  self.button_case.setCheckable(True)
48  self.button_case.setIcon(QIcon.fromTheme("format-text-superscript"))
49  self.button_case.setToolTip("Case Sensitive")
50  layout_slider.addWidget(self.button_case)
51 
52  self.combo_mode = QComboBox()
53  self.combo_mode.addItem("Text")
54  self.combo_mode.addItem("RegExp")
55  layout_slider.addWidget(self.combo_mode)
56 
57  self.button_selection = QPushButton()
58  self.button_selection.setCheckable(True)
59  self.button_selection.setIcon(QIcon.fromTheme("edit-select-all"))
60  self.button_selection.setToolTip("Only in selection")
61  layout_slider.addWidget(self.button_selection)
62 
63  self.set_replace_enabled(False)
64 
65  def start_search(self, replace):
66  if self.target.hasSelectedText():
67  st = self.target.selectedText()
68  if "\n" in st:
69  self.button_selection.setChecked(True)
70  else:
71  self.button_selection.setChecked(False)
72  self.line_find.setText(st)
73  self.line_find.selectAll()
74  self.line_find.setFocus(True)
75  self.set_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_replace.setVisible(show)
81  self.button_repl.setVisible(show)
82 
83  def find(self, forward):
84  func = self.target.findFirst if not self.button_selection.isChecked() else self.target.findFirstInSelection
85  func(
86  self.line_find.text(),
87  self.combo_mode.currentIndex() != 0,
88  self.button_case.isChecked(),
89  False,
90  True,
91  forward,
92  True
93  )
94 
95  def find_next(self):
96  return self.find(True)
97 
98  def find_prev(self):
99  return self.find(False)
100 
101  def replace(self):
102  self.target.replace(self.line_replace.text())
103  self.find_next()
lottie.gui.search_widget.SearchWidget.combo_mode
combo_mode
Definition: search_widget.py:52
lottie.gui.search_widget.SearchWidget.button_selection
button_selection
Definition: search_widget.py:57
lottie.gui.search_widget.SearchWidget.set_replace_enabled
def set_replace_enabled(self, show)
Definition: search_widget.py:77
lottie.gui.search_widget.SearchWidget.__init__
def __init__(self, target)
Definition: search_widget.py:11
lottie.gui.search_widget.SearchWidget.find_prev
def find_prev(self)
Definition: search_widget.py:98
lottie.gui.search_widget.SearchWidget.find
def find(self, forward)
Definition: search_widget.py:83
lottie.gui.search_widget.SearchWidget.button_next
button_next
Definition: search_widget.py:29
lottie.gui.search_widget.SearchWidget.button_repl
button_repl
Definition: search_widget.py:41
lottie.gui.search_widget.SearchWidget
Definition: search_widget.py:8
lottie.gui.search_widget.SearchWidget.button_prev
button_prev
Definition: search_widget.py:35
lottie.gui.search_widget.SearchWidget.start_search
def start_search(self, replace)
Definition: search_widget.py:65
lottie.gui.search_widget.SearchWidget.replace
def replace(self)
Definition: search_widget.py:101
lottie.gui.search_widget.SearchWidget.button_case
button_case
Definition: search_widget.py:46
lottie.gui.search_widget.SearchWidget.find_next
def find_next(self)
Definition: search_widget.py:95
lottie.gui.search_widget.SearchWidget.line_replace
line_replace
Definition: search_widget.py:24
QtGui
QtWidgets
lottie.gui.search_widget.SearchWidget.line_find
line_find
Definition: search_widget.py:19
lottie.gui.search_widget.SearchWidget.target
target
Definition: search_widget.py:13