def item_activated(self, index): try: char_code = int(self.model().data(index, Qt.ItemDataRole.UserRole)) except (TypeError, ValueError): pass else: self.char_selected.emit(codepoint_to_chr(char_code))
def paint_normal(self, painter, option, charcode): f = option.font f.setPixelSize(option.rect.height() - 8) painter.setFont(f) painter.drawText(option.rect, Qt.AlignHCenter | Qt.AlignBottom | Qt.TextSingleLine, codepoint_to_chr(charcode))
def context_menu(self, pos): index = self.indexAt(pos) if index.isValid(): try: char_code = int(self.model().data(index, Qt.UserRole)) except (TypeError, ValueError): pass else: m = QMenu(self) m.addAction( QIcon(I('edit-copy.png')), _('Copy %s to clipboard') % codepoint_to_chr(char_code), partial(self.copy_to_clipboard, char_code)) m.addAction( QIcon(I('rating.png')), (_('Remove %s from favorites') if self.showing_favorites else _('Add %s to favorites')) % codepoint_to_chr(char_code), partial(self.remove_from_favorites, char_code)) if self.showing_favorites: m.addAction(_('Restore favorites to defaults'), self.restore_defaults) m.exec_(self.mapToGlobal(pos))
def copy_to_clipboard(self, char_code): c = QApplication.clipboard() c.setText(codepoint_to_chr(char_code))