def test_unique_font_family_name(qtbot): """ Test that each font used by qtawesome has a unique name. If this test fails, this probably means that you need to rename the family name of some fonts. Please see PR #98 for more details on why it is necessary and on how to do this. Regression test for Issue #107 """ resource = qta._instance() assert isinstance(resource, IconicFont) # Check that the fonts were loaded successfully. fontnames = resource.fontname.values() assert fontnames # Check that qtawesome does not load fonts with duplicate family names. duplicates = [fontname for fontname, count in collections.Counter(fontnames).items() if count > 1] assert not duplicates
def __init__(self, parent=None, dialog=False, title='QtAwesome Icon Browser', btnOkName='OK', btnCopyName='Copy Name', color="gray"): super().__init__(parent) self.dialog = dialog self.selected = "" self.color = color self.setMinimumSize(400, 600) self.setWindowTitle(title) if dialog: self.setWindowModality(QtCore.Qt.WindowModal) qtawesome._instance() fontMaps = qtawesome._resource['iconic'].charmap iconNames = [] for fontCollection, fontData in fontMaps.items(): for iconName in fontData: iconNames.append('%s.%s' % (fontCollection, iconName)) self._filterTimer = QtCore.QTimer(self) self._filterTimer.setSingleShot(True) self._filterTimer.setInterval(AUTO_SEARCH_TIMEOUT) self._filterTimer.timeout.connect(self._updateFilter) model = IconModel(self.color) model.setStringList(sorted(iconNames)) self._proxyModel = QtCore.QSortFilterProxyModel() self._proxyModel.setSourceModel(model) self._proxyModel.setFilterCaseSensitivity(QtCore.Qt.CaseInsensitive) self._listView = IconListView(self) self._listView.setUniformItemSizes(True) self._listView.setViewMode(QtWidgets.QListView.IconMode) self._listView.setModel(self._proxyModel) self._listView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) if dialog: self._listView.doubleClicked.connect(self._selectIconText) else: self._listView.doubleClicked.connect(self._copyIconText) self._listView.selectionModel().selectionChanged.connect( self._updateNameField) self._lineEdit = QtWidgets.QLineEdit(self) self._lineEdit.setAlignment(QtCore.Qt.AlignCenter) self._lineEdit.textChanged.connect(self._triggerDelayedUpdate) self._lineEdit.returnPressed.connect(self._triggerImmediateUpdate) self._comboBox = QtWidgets.QComboBox(self) self._comboBox.setMinimumWidth(75) self._comboBox.currentIndexChanged.connect( self._triggerImmediateUpdate) self._comboBox.addItems([ALL_COLLECTIONS] + sorted(fontMaps.keys())) lyt = QtWidgets.QHBoxLayout() lyt.setContentsMargins(0, 0, 0, 0) lyt.addWidget(self._comboBox) lyt.addWidget(self._lineEdit) self._combo_style = QtWidgets.QComboBox(self) self._combo_style.addItems([ qtawesome.styles.DEFAULT_DARK_PALETTE, qtawesome.styles.DEFAULT_LIGHT_PALETTE ]) self._combo_style.currentTextChanged.connect(self._updateStyle) lyt.addWidget(self._combo_style) searchBarFrame = QtWidgets.QFrame(self) searchBarFrame.setLayout(lyt) self._nameField = QtWidgets.QLineEdit(self) self._nameField.setAlignment(QtCore.Qt.AlignCenter) self._nameField.setReadOnly(True) if self.dialog: self._copyButton = QtWidgets.QPushButton(btnOkName, self) self._copyButton.clicked.connect(self._selectIconText) else: self._copyButton = QtWidgets.QPushButton(btnCopyName, self) self._copyButton.clicked.connect(self._copyIconText) lyt = QtWidgets.QVBoxLayout() lyt.addWidget(searchBarFrame) lyt.addWidget(self._listView) lyt.addWidget(self._nameField) lyt.addWidget(self._copyButton) self.setLayout(lyt) self.setTabOrder(self._comboBox, self._lineEdit) self.setTabOrder(self._lineEdit, self._combo_style) self.setTabOrder(self._combo_style, self._listView) self.setTabOrder(self._listView, self._nameField) self.setTabOrder(self._nameField, self._copyButton) self.setTabOrder(self._copyButton, self._comboBox) QtWidgets.QShortcut( QtGui.QKeySequence(QtCore.Qt.Key_Return), self, self._copyIconText, ) QtWidgets.QShortcut( QtGui.QKeySequence("Ctrl+F"), self, self._lineEdit.setFocus, ) self._lineEdit.setFocus() geo = self.geometry() # QApplication.desktop() has been removed in Qt 6. # Instead, QGuiApplication.screenAt(QPoint) is supported # in Qt 5.10 or later. try: screen = QtGui.QGuiApplication.screenAt(QtGui.QCursor.pos()) centerPoint = screen.geometry().center() except AttributeError: desktop = QtWidgets.QApplication.desktop() screen = desktop.screenNumber(desktop.cursor().pos()) centerPoint = desktop.screenGeometry(screen).center() geo.moveCenter(centerPoint) self.setGeometry(geo)
def __init__(self): super(IconBrowser, self).__init__() self.setMinimumSize(400, 300) self.setWindowTitle('QtAwesome Icon Browser') qtawesome._instance() fontMaps = qtawesome._resource['iconic'].charmap iconNames = [] for fontCollection, fontData in fontMaps.items(): for iconName in fontData: iconNames.append('%s.%s' % (fontCollection, iconName)) self._filterTimer = QtCore.QTimer(self) self._filterTimer.setSingleShot(True) self._filterTimer.setInterval(AUTO_SEARCH_TIMEOUT) self._filterTimer.timeout.connect(self._updateFilter) model = IconModel(self.palette().color(QtGui.QPalette.Text)) model.setStringList(sorted(iconNames)) self._proxyModel = QtCore.QSortFilterProxyModel() self._proxyModel.setSourceModel(model) self._proxyModel.setFilterCaseSensitivity(QtCore.Qt.CaseInsensitive) self._listView = IconListView(self) self._listView.setUniformItemSizes(True) self._listView.setViewMode(QtWidgets.QListView.IconMode) self._listView.setModel(self._proxyModel) self._listView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self._listView.doubleClicked.connect(self._copyIconText) self._lineEdit = QtWidgets.QLineEdit(self) self._lineEdit.setAlignment(QtCore.Qt.AlignCenter) self._lineEdit.textChanged.connect(self._triggerDelayedUpdate) self._lineEdit.returnPressed.connect(self._triggerImmediateUpdate) self._comboBox = QtWidgets.QComboBox(self) self._comboBox.setMinimumWidth(75) self._comboBox.currentIndexChanged.connect( self._triggerImmediateUpdate) self._comboBox.addItems([ALL_COLLECTIONS] + sorted(fontMaps.keys())) lyt = QtWidgets.QHBoxLayout() lyt.setContentsMargins(0, 0, 0, 0) lyt.addWidget(self._comboBox) lyt.addWidget(self._lineEdit) searchBarFrame = QtWidgets.QFrame(self) searchBarFrame.setLayout(lyt) self._copyButton = QtWidgets.QPushButton('Copy Name', self) self._copyButton.clicked.connect(self._copyIconText) lyt = QtWidgets.QVBoxLayout() lyt.addWidget(searchBarFrame) lyt.addWidget(self._listView) lyt.addWidget(self._copyButton) frame = QtWidgets.QFrame(self) frame.setLayout(lyt) self.setCentralWidget(frame) QtWidgets.QShortcut( QtGui.QKeySequence(QtCore.Qt.Key_Return), self, self._copyIconText, ) self._lineEdit.setFocus() geo = self.geometry() desktop = QtWidgets.QApplication.desktop() screen = desktop.screenNumber(desktop.cursor().pos()) centerPoint = desktop.screenGeometry(screen).center() geo.moveCenter(centerPoint) self.setGeometry(geo)