Bases: QMainWindow
A small browser window that allows the user to search through all icons from the available version of QtAwesome. You can also copy the name and python code for the currently selected icon.
Source code in client/ayon_ui_qt/vendor/qtmaterialsymbols/browser.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185 | class IconBrowser(QtWidgets.QMainWindow):
"""
A small browser window that allows the user to search through all icons from
the available version of QtAwesome. You can also copy the name and python
code for the currently selected icon.
"""
def __init__(self):
super().__init__()
self.setMinimumSize(630, 420)
self.setWindowTitle("Material Symbols Browser")
# Prepare icons data
instance = get_instance()
font_maps = instance.get_charmap()
icon_names = list(font_maps)
center_widget = QtWidgets.QWidget(self)
# Filtering inputs
header_widget = QtWidgets.QWidget(center_widget)
filter_input = QtWidgets.QLineEdit(header_widget)
filter_input.setPlaceholderText("Filter by name...")
filled_check = QtWidgets.QCheckBox("Fill", header_widget)
filled_check.setToolTip("Filled icons")
copy_btn = QtWidgets.QPushButton("< no selection >", header_widget)
copy_btn.setToolTip("Copy name")
header_layout = QtWidgets.QHBoxLayout(header_widget)
header_layout.setContentsMargins(0, 0, 0, 0)
header_layout.addWidget(filter_input, 4)
header_layout.addWidget(filled_check, 1)
header_layout.addWidget(copy_btn, 0)
# Icons view
icons_view = IconListView(center_widget)
icons_view.setUniformItemSizes(True)
icons_view.setResizeMode(QtWidgets.QListView.Adjust)
icons_view.setViewMode(QtWidgets.QListView.IconMode)
icons_view.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
model = IconModel(QtGui.QColor("#444746"))
model.setStringList(sorted(icon_names))
proxy_model = QtCore.QSortFilterProxyModel()
proxy_model.setSourceModel(model)
proxy_model.setFilterCaseSensitivity(QtCore.Qt.CaseInsensitive)
icons_view.setModel(proxy_model)
center_layout = QtWidgets.QVBoxLayout(center_widget)
center_layout.setContentsMargins(15, 15, 15, 15)
center_layout.setSpacing(5)
center_layout.addWidget(header_widget, 0)
center_layout.addWidget(icons_view, 1)
self.setCentralWidget(center_widget)
filter_timer = QtCore.QTimer(self)
filter_timer.setSingleShot(True)
filter_timer.setInterval(AUTO_SEARCH_TIMEOUT)
filter_input.textChanged.connect(self._on_filter_change)
filter_input.returnPressed.connect(self._on_filter_confirm)
filled_check.stateChanged.connect(self._on_filled_change)
icons_view.doubleClicked.connect(self._copy_icon_name)
icons_view.selectionModel().selectionChanged.connect(
self._on_selection_change
)
copy_btn.clicked.connect(self._copy_icon_name)
filter_timer.timeout.connect(self._update_filter)
QtWidgets.QShortcut(
QtGui.QKeySequence(QtCore.Qt.Key_Return),
self,
self._copy_icon_name,
)
QtWidgets.QShortcut(
QtGui.QKeySequence("Ctrl+F"),
self,
filter_input.setFocus,
)
self._filled_check = filled_check
self._copy_btn = copy_btn
self._filter_input = filter_input
self._icons_view = icons_view
self._model = model
self._proxy_model = proxy_model
self._filter_timer = filter_timer
def showEvent(self, event):
super().showEvent(event)
self._filter_input.setFocus()
self.setStyleSheet(load_stylesheet())
def _update_filter(self):
regex = ""
search_term = self._filter_input.text()
if search_term:
regex = f".*{search_term}.*$"
self._proxy_model.setFilterRegularExpression(regex)
def _on_filled_change(self):
self._model.set_filled(self._filled_check.isChecked())
def _on_selection_change(self, _new_selection, _old_selection):
indexes = self._icons_view.selectedIndexes()
if not indexes:
self._copy_btn.setText("< nothing >")
return
index = indexes[0]
icon_name = index.data()
self._copy_btn.setText(icon_name)
def _on_filter_change(self):
self._filter_timer.start()
def _on_filter_confirm(self):
self._filter_timer.stop()
self._update_filter()
def _copy_icon_name(self):
indexes = self._icons_view.selectedIndexes()
for index in indexes:
clipboard = QtWidgets.QApplication.instance().clipboard()
clipboard.setText(index.data())
break
|