def item_activated(self, index): try: char_code = int(self.model().data(index, Qt.UserRole)) except (TypeError, ValueError): pass else: self.char_selected.emit(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, chr(charcode))
def context_menu(self, pos): index = self.indexAt(pos) if index.isValid(): char_code, ok = self.model().data(index, Qt.UserRole).toInt() if ok: m = QMenu(self) m.addAction(QIcon(I('edit-copy.png')), _('Copy %s to clipboard') % 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')) % 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 context_menu(self, pos): index = self.indexAt(pos) if index.isValid(): char_code, ok = self.model().data(index, Qt.UserRole).toInt() if ok: m = QMenu(self) m.addAction(QIcon(I('edit-copy.png')), _('Copy %s to clipboard') % 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')) % 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 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") % 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")) % 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(chr(char_code))
def item_activated(self, index): char_code, ok = self.model().data(index, Qt.UserRole).toInt() if ok: self.char_selected.emit(chr(char_code))