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

# Copyright (c) 2015-2016:
#   <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 Widget manage creation of a QWidget to make a tempalte for all QWidgets of Alignak-app
"""

import sys

from logging import getLogger
from alignak_app.core.utils import get_image_path, init_config, get_css

try:
    __import__('PyQt5')
    from PyQt5.QtWidgets import QApplication  # pylint: disable=no-name-in-module
    from PyQt5.QtWidgets import QWidget, QStyle, QVBoxLayout  # pylint: disable=no-name-in-module
    from PyQt5.QtWidgets import QLabel, QStyleOption  # pylint: disable=no-name-in-module
    from PyQt5.QtWidgets import QHBoxLayout, QPushButton  # pylint: disable=no-name-in-module
    from PyQt5.Qt import Qt, QIcon, QPixmap, QFrame  # pylint: disable=no-name-in-module
except ImportError:  # pragma: no cover
    from PyQt4.Qt import QApplication  # pylint: disable=import-error
    from PyQt4.Qt import QWidget, QStyle, QVBoxLayout  # pylint: disable=import-error
    from PyQt4.Qt import QLabel, QStyleOption  # pylint: disable=import-error
    from PyQt4.Qt import QHBoxLayout, QPushButton  # pylint: disable=import-error
    from PyQt4.Qt import Qt, QIcon, QPixmap, QFrame  # pylint: disable=import-error


logger = getLogger(__name__)


class AppQWidget(QFrame):
    """
        Class who create a QWidget template.
    """

    def __init__(self, parent=None):
        super(AppQWidget, self).__init__(parent)
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setWindowIcon(QIcon(get_image_path('icon')))
        self.setStyleSheet(get_css())
        self.offset = None

    def initialize(self, title):
        """
        Initialize the QWidget, with its "title"

        :param title: title of the QWidget
        :type title: str
        """

        self.setWindowTitle(title)
        self.setObjectName('app_widget')

        main_layout = QVBoxLayout()
        main_layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(main_layout)

        main_layout.addWidget(self.get_logo_widget(title))

        self.setAttribute(Qt.WA_TransparentForMouseEvents)

    def get_logo_widget(self, title):
        """
        Return the logo QWidget

        :return: logo QWidget
        :rtype: QWidget
        """

        logo_widget = QWidget()
        logo_widget.setFixedHeight(45)
        logo_widget.setObjectName('logo')
        logo_layout = QHBoxLayout()
        logo_widget.setLayout(logo_layout)
        logo_widget.setAttribute(Qt.WA_TransparentForMouseEvents)

        logo_label = QLabel()
        logo_label.setPixmap(QPixmap(get_image_path('alignak')))
        logo_label.setFixedSize(121, 35)
        logo_label.setScaledContents(True)

        logo_layout.addWidget(logo_label, 0)

        title_label = QLabel('<h3>%s</h3>' % title)
        title_label.setObjectName('title')

        logo_layout.addWidget(title_label, 1)
        logo_layout.setAlignment(title_label, Qt.AlignHCenter)

        minimize_btn = QPushButton()
        minimize_btn.setIcon(QIcon(get_image_path('minimize')))
        minimize_btn.setFixedSize(22, 22)
        minimize_btn.clicked.connect(self.minimize)
        if 'Notification' in self.windowTitle():
            minimize_btn.setEnabled(False)
        logo_layout.addWidget(minimize_btn, 2)

        maximize_btn = QPushButton()
        maximize_btn.setIcon(QIcon(get_image_path('maximize')))
        maximize_btn.setFixedSize(22, 22)
        maximize_btn.clicked.connect(self.minimize_maximize)
        if 'Notification' in self.windowTitle():
            maximize_btn.setEnabled(False)
        logo_layout.addWidget(maximize_btn, 3)

        close_btn = QPushButton()
        close_btn.setIcon(QIcon(get_image_path('exit')))
        close_btn.setFixedSize(22, 22)
        close_btn.clicked.connect(self.close)
        logo_layout.addWidget(close_btn, 4)

        return logo_widget

    def minimize(self):
        """
        Minimize QWidget

        """

        if self.windowState() == Qt.WindowMinimized:
            self.setWindowState(Qt.WindowNoState)
        else:
            self.setWindowState(Qt.WindowMinimized)
<commit_msg>Move TransparentEvent to title, add ObjectNames<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2015-2016:
#   <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 Widget manage creation of a QWidget to make a tempalte for all QWidgets of Alignak-app
"""

import sys

from logging import getLogger
from alignak_app.core.utils import get_image_path, init_config, get_css

try:
    __import__('PyQt5')
    from PyQt5.QtWidgets import QApplication  # pylint: disable=no-name-in-module
    from PyQt5.QtWidgets import QWidget, QStyle, QVBoxLayout  # pylint: disable=no-name-in-module
    from PyQt5.QtWidgets import QLabel, QStyleOption  # pylint: disable=no-name-in-module
    from PyQt5.QtWidgets import QHBoxLayout, QPushButton  # pylint: disable=no-name-in-module
    from PyQt5.Qt import Qt, QIcon, QPixmap, QFrame  # pylint: disable=no-name-in-module
except ImportError:  # pragma: no cover
    from PyQt4.Qt import QApplication  # pylint: disable=import-error
    from PyQt4.Qt import QWidget, QStyle, QVBoxLayout  # pylint: disable=import-error
    from PyQt4.Qt import QLabel, QStyleOption  # pylint: disable=import-error
    from PyQt4.Qt import QHBoxLayout, QPushButton  # pylint: disable=import-error
    from PyQt4.Qt import Qt, QIcon, QPixmap, QFrame  # pylint: disable=import-error


logger = getLogger(__name__)


class AppQWidget(QFrame):
    """
        Class who create a QWidget template.
    """

    def __init__(self, parent=None):
        super(AppQWidget, self).__init__(parent)
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setWindowIcon(QIcon(get_image_path('icon')))
        self.setStyleSheet(get_css())
        self.offset = None

    def initialize(self, title):
        """
        Initialize the QWidget, with its "title"

        :param title: title of the QWidget
        :type title: str
        """

        self.setWindowTitle(title)
        self.setObjectName('app_widget')

        main_layout = QVBoxLayout()
        main_layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(main_layout)

        main_layout.addWidget(self.get_logo_widget(title))

        self.setAttribute(Qt.WA_TransparentForMouseEvents)

    def get_logo_widget(self, title):
        """
        Return the logo QWidget

        :return: logo QWidget
        :rtype: QWidget
        """

        logo_widget = QWidget()
        logo_widget.setFixedHeight(45)
        logo_widget.setObjectName('logo')
        logo_layout = QHBoxLayout()
        logo_widget.setLayout(logo_layout)

        logo_label = QLabel()
        logo_label.setPixmap(QPixmap(get_image_path('alignak')))
        logo_label.setFixedSize(121, 35)
        logo_label.setScaledContents(True)

        logo_layout.addWidget(logo_label, 0)

        title_label = QLabel('<h3>%s</h3>' % title)
        title_label.setObjectName('title')
        title_label.setAttribute(Qt.WA_TransparentForMouseEvents)

        logo_layout.addWidget(title_label, 1)
        logo_layout.setAlignment(title_label, Qt.AlignHCenter)

        minimize_btn = QPushButton()
        minimize_btn.setIcon(QIcon(get_image_path('minimize')))
        minimize_btn.setFixedSize(22, 22)
        minimize_btn.setObjectName('app_widget')
        minimize_btn.clicked.connect(self.minimize)
        if 'Notification' in self.windowTitle():
            minimize_btn.setEnabled(False)
        logo_layout.addWidget(minimize_btn, 2)

        maximize_btn = QPushButton()
        maximize_btn.setIcon(QIcon(get_image_path('maximize')))
        maximize_btn.setFixedSize(22, 22)
        maximize_btn.setObjectName('app_widget')
        maximize_btn.clicked.connect(self.minimize_maximize)
        if 'Notification' in self.windowTitle():
            maximize_btn.setEnabled(False)
        logo_layout.addWidget(maximize_btn, 3)

        close_btn = QPushButton()
        close_btn.setIcon(QIcon(get_image_path('exit')))
        close_btn.setFixedSize(22, 22)
        close_btn.setObjectName('app_widget')
        close_btn.clicked.connect(self.close)
        logo_layout.addWidget(close_btn, 4)

        return logo_widget

    def minimize(self):
        """
        Minimize QWidget

        """

        if self.windowState() == Qt.WindowMinimized:
            self.setWindowState(Qt.WindowNoState)
        else:
            self.setWindowState(Qt.WindowMinimized)

{'fraction_non_alphanumeric': 0.09492005666869055, 'fraction_numerical': 0.010321797207043109, 'mean_word_length': 3.1525210084033612, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '105698', 'n_tokens_mistral': 3185, 'n_tokens_neox': 3066, 'n_words': 716}