<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2015-2017:
#   <NAME>, <EMAIL>
#
# This file is part of (AlignakApp).
#
# (AlignakApp) is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# (AlignakApp) is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with (AlignakApp).  If not, see <http://www.gnu.org/licenses/>.

"""
    App Synthesis manage widget for Host Synthesis QWidget.
"""

import json

from logging import getLogger

from alignak_app.core.utils import get_css
from alignak_app.core.action_manager import ActionManager
from alignak_app.synthesis.host_synthesis import HostSynthesis
from alignak_app.widgets.app_widget import AppQWidget

try:
    __import__('PyQt5')
    from PyQt5.QtWidgets import QWidget, QPushButton  # pylint: disable=no-name-in-module
    from PyQt5.QtWidgets import QGridLayout  # pylint: disable=no-name-in-module
    from PyQt5.Qt import QStringListModel  # pylint: disable=no-name-in-module
    from PyQt5.Qt import QCompleter, QLineEdit, QTimer  # pylint: disable=no-name-in-module
    from PyQt5.QtCore import Qt  # pylint: disable=no-name-in-module
except ImportError:  # pragma: no cover
    from PyQt4.Qt import QWidget, QPushButton  # pylint: disable=import-error
    from PyQt4.Qt import QGridLayout  # pylint: disable=import-error
    from PyQt4.Qt import QStringListModel  # pylint: disable=import-error
    from PyQt4.Qt import QCompleter, QLineEdit, QTimer  # pylint: disable=import-error
    from PyQt4.QtCore import Qt  # pylint: disable=import-error


logger = getLogger(__name__)


class Synthesis(QWidget):
    """
        Class who create the Synthesis QWidget.
    """

    first_display = True

    def __init__(self, parent=None):
        super(Synthesis, self).__init__(parent)
        self.setMinimumSize(1000, 600)
        self.setStyleSheet(get_css())
        # Fields
        self.line_search = QLineEdit()
        self.app_backend = None
        self.action_manager = None
        self.host_synthesis = None
        self.app_widget = AppQWidget()
        self.old_checkbox_states = {}

    def initialize(self, app_backend):
        """
        Create the QWidget with its items and layout.

        :param app_backend: app_backend of alignak.
        :type app_backend: alignak_app.core.backend.AppBackend
        """

        logger.info('Create Synthesis View...')

        # App_backend
        self.app_backend = app_backend
        self.action_manager = ActionManager(app_backend)

        # button
        button = QPushButton('Search / Refresh', self)
        button.setObjectName('search')
        button.setMinimumHeight(20)
        button.setToolTip('Type a host name to display its data')
        button.clicked.connect(self.display_host_synthesis)
        self.line_search.returnPressed.connect(button.click)
        self.line_search.cursorPositionChanged.connect(button.click)

        layout = QGridLayout()
        self.setLayout(layout)

        layout.addWidget(self.line_search, 0, 0, 1, 4)
        layout.setAlignment(self.line_search, Qt.AlignTop)
        layout.addWidget(button, 0, 4, 1, 1)
        layout.setAlignment(button, Qt.AlignTop)

        self.app_widget.initialize('Host Synthesis View')
        self.app_widget.add_widget(self)

        refresh_timer = QTimer(self)
        refresh_timer.start(30000)
        refresh_timer.timeout.connect(self.display_host_synthesis)

    def create_line_search(self):
        """
        Add all hosts to QLineEdit and set QCompleter<commit_msg>Sizing the right QWidget to avoid height problem<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2015-2017:
#   <NAME>, <EMAIL>
#
# This file is part of (AlignakApp).
#
# (AlignakApp) is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# (AlignakApp) is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with (AlignakApp).  If not, see <http://www.gnu.org/licenses/>.

"""
    App Synthesis manage widget for Host Synthesis QWidget.
"""

import json

from logging import getLogger

from alignak_app.core.utils import get_css
from alignak_app.core.action_manager import ActionManager
from alignak_app.synthesis.host_synthesis import HostSynthesis
from alignak_app.widgets.app_widget import AppQWidget

try:
    __import__('PyQt5')
    from PyQt5.QtWidgets import QWidget, QPushButton  # pylint: disable=no-name-in-module
    from PyQt5.QtWidgets import QGridLayout  # pylint: disable=no-name-in-module
    from PyQt5.Qt import QStringListModel  # pylint: disable=no-name-in-module
    from PyQt5.Qt import QCompleter, QLineEdit, QTimer  # pylint: disable=no-name-in-module
    from PyQt5.QtCore import Qt  # pylint: disable=no-name-in-module
except ImportError:  # pragma: no cover
    from PyQt4.Qt import QWidget, QPushButton  # pylint: disable=import-error
    from PyQt4.Qt import QGridLayout  # pylint: disable=import-error
    from PyQt4.Qt import QStringListModel  # pylint: disable=import-error
    from PyQt4.Qt import QCompleter, QLineEdit, QTimer  # pylint: disable=import-error
    from PyQt4.QtCore import Qt  # pylint: disable=import-error


logger = getLogger(__name__)


class Synthesis(QWidget):
    """
        Class who create the Synthesis QWidget.
    """

    first_display = True

    def __init__(self, parent=None):
        super(Synthesis, self).__init__(parent)
        self.setStyleSheet(get_css())
        # Fields
        self.line_search = QLineEdit()
        self.app_backend = None
        self.action_manager = None
        self.host_synthesis = None
        self.app_widget = AppQWidget()
        self.old_checkbox_states = {}

    def initialize(self, app_backend):
        """
        Create the QWidget with its items and layout.

        :param app_backend: app_backend of alignak.
        :type app_backend: alignak_app.core.backend.AppBackend
        """

        logger.info('Create Synthesis View...')

        # App_backend
        self.app_backend = app_backend
        self.action_manager = ActionManager(app_backend)

        # button
        button = QPushButton('Search / Refresh', self)
        button.setObjectName('search')
        button.setMinimumHeight(20)
        button.setToolTip('Type a host name to display its data')
        button.clicked.connect(self.display_host_synthesis)
        self.line_search.returnPressed.connect(button.click)
        self.line_search.cursorPositionChanged.connect(button.click)

        layout = QGridLayout()
        self.setLayout(layout)

        layout.addWidget(self.line_search, 0, 0, 1, 4)
        layout.setAlignment(self.line_search, Qt.AlignTop)
        layout.addWidget(button, 0, 4, 1, 1)
        layout.setAlignment(button, Qt.AlignTop)

        self.app_widget.initialize('Host Synthesis View')
        self.app_widget.add_widget(self)
        self.app_widget.setMinimumSize(1200, 700)

        refresh_timer = QTimer(self)
        refresh_timer.start(30000)
        refresh_timer.timeout.connect(self.display_host_synthesis)

    def create_line_search(self):
        """
        Add all hosts to QLineEdit and set QCompleter
{'fraction_non_alphanumeric': 0.08734335839598997, 'fraction_numerical': 0.010776942355889725, 'mean_word_length': 3.2474720596061735, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5505690', 'n_tokens_mistral': 2494, 'n_tokens_neox': 2345, 'n_words': 664}