<commit_before>from PyQt5.QtWidgets import QDialog, QTabWidget, QVBoxLayout
from PyQt5.QtCore import QObject, pyqtSignal
from sakia.decorators import asyncify
from sakia.gui.widgets.dialogs import dialog_async_exec, QAsyncMessageBox
from .model import UserInformationModel
from .view import UserInformationView
import logging


class UserInformationController(QObject):
    """
    The homescreen view
    """
    identity_loaded = pyqtSignal()

    def __init__(self, parent, view, model):
        """
        Constructor of the homescreen component

        :param sakia.gui.homescreen.view.HomeScreenView: the view
        :param sakia.gui.homescreen.model.HomeScreenModel model: the model
        """
        super().__init__(parent)
        self.view = view
        self.model = model
        self._logger = logging.getLogger('sakia')

    @classmethod
    def create(cls, parent, app, identity):
        view = UserInformationView(parent.view if parent else None)
        model = UserInformationModel(None, app, identity)
        homescreen = cls(parent, view, model)
        model.setParent(homescreen)
        return homescreen

    @classmethod
    def show_identity(cls, parent, app, identity):
        dialog = QDialog()
        dialog.setWindowTitle("Informations")
        user_info = cls.create(parent, app, identity)
        user_info.view.setParent(dialog)
        user_info.refresh()
        dialog.exec()

    @classmethod
    @asyncify
    async def search_and_show_pubkey(cls, parent, app, pubkey):
        dialog = QDialog(parent)
        dialog.setWindowTitle("Informations")
        layout = QVBoxLayout(dialog)
        tabwidget = QTabWidget(dialog)
        layout.addWidget(tabwidget)

        identities = await app.identities_service.lookup(pubkey)
        for i in identities:
            user_info = cls.create(parent, app, i)
            user_info.refresh()
            tabwidget.addTab(user_info.view, i.uid)
        return await dialog_async_exec(dialog)

    @asyncify
    async def refresh(self):
        try:
            if self.model.identity:
                self.view.show_busy()
                await self.model.load_identity(self.model.identity)
                self.view.display_uid(self.model.identity.uid, self.model.identity.member)
                self.view.display_identity_timestamps(self.model.identity.pubkey, self.model.identity.timestamp,
                                                      self.model.identity.membership_timestamp,
                                                      self.model.mstime_remaining(), await self.model.nb_certs())
                self.view.hide_busy()
                self.identity_loaded.emit()
        except RuntimeError as e:
            # object can be deleted by Qt during asynchronous ops
            # we don't care of this error
            if "wrapped C/C++ object" in str(e):
                self._logger.debug(str(e))
                pass
            else:
                raise

    @asyncify
    async def search_identity(self, identity):
        await self.model.load_identity(identity)
        self.refresh()

    def change_identity(self, identity):
        """
        Set identity
        :param sakia.core.registry.Identity identity:
        """
        self.model.identity = identity
        self.refresh()
<commit_msg>Fix issue #619<commit_after>from PyQt5.QtWidgets import QDialog, QTabWidget, QVBoxLayout
from PyQt5.QtCore import QObject, pyqtSignal
from sakia.decorators import asyncify
from sakia.gui.widgets.dialogs import dialog_async_exec, QAsyncMessageBox
from .model import UserInformationModel
from .view import UserInformationView
import logging


class UserInformationController(QObject):
    """
    The homescreen view
    """
    identity_loaded = pyqtSignal()

    def __init__(self, parent, view, model):
        """
        Constructor of the homescreen component

        :param sakia.gui.homescreen.view.HomeScreenView: the view
        :param sakia.gui.homescreen.model.HomeScreenModel model: the model
        """
        super().__init__(parent)
        self.view = view
        self.model = model
        self._logger = logging.getLogger('sakia')

    @classmethod
    def create(cls, parent, app, identity):
        view = UserInformationView(parent.view if parent else None)
        model = UserInformationModel(None, app, identity)
        homescreen = cls(parent, view, model)
        model.setParent(homescreen)
        return homescreen

    @classmethod
    def show_identity(cls, parent, app, identity):
        dialog = QDialog()
        dialog.setWindowTitle("Informations")
        user_info = cls.create(parent, app, identity)
        user_info.view.setParent(dialog)
        dialog.setLayout(QVBoxLayout(dialog))
        dialog.layout().addWidget(user_info.view)
        user_info.refresh()
        dialog.exec()

    @classmethod
    @asyncify
    async def search_and_show_pubkey(cls, parent, app, pubkey):
        dialog = QDialog(parent)
        dialog.setWindowTitle("Informations")
        layout = QVBoxLayout(dialog)
        tabwidget = QTabWidget(dialog)
        layout.addWidget(tabwidget)

        identities = await app.identities_service.lookup(pubkey)
        for i in identities:
            user_info = cls.create(parent, app, i)
            user_info.refresh()
            tabwidget.addTab(user_info.view, i.uid)
        return await dialog_async_exec(dialog)

    @asyncify
    async def refresh(self):
        try:
            if self.model.identity:
                self.view.show_busy()
                await self.model.load_identity(self.model.identity)
                self.view.display_uid(self.model.identity.uid, self.model.identity.member)
                self.view.display_identity_timestamps(self.model.identity.pubkey, self.model.identity.timestamp,
                                                      self.model.identity.membership_timestamp,
                                                      self.model.mstime_remaining(), await self.model.nb_certs())
                self.view.hide_busy()
                self.identity_loaded.emit()
        except RuntimeError as e:
            # object can be deleted by Qt during asynchronous ops
            # we don't care of this error
            if "wrapped C/C++ object" in str(e):
                self._logger.debug(str(e))
                pass
            else:
                raise

    @asyncify
    async def search_identity(self, identity):
        await self.model.load_identity(identity)
        self.refresh()

    def change_identity(self, identity):
        """
        Set identity
        :param sakia.core.registry.Identity identity:
        """
        self.model.identity = identity
        self.refresh()

{'fraction_non_alphanumeric': 0.08608682767817455, 'fraction_numerical': 0.0010371906949177656, 'mean_word_length': 2.200568990042674, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7551185', 'n_tokens_mistral': 1855, 'n_tokens_neox': 1799, 'n_words': 410}