<commit_before># -*- coding: utf-8 -*-
# Copyright (c) 2012-2014, <NAME>
#
# This module is part of anima-tools and is released under the BSD 2
# License: http://www.opensource.org/licenses/BSD-2-Clause


import sys

from stalker import LocalSession
from anima.ui.utils import logger
from anima.ui.lib import QtCore, QtGui


class AnimaDialogBase(object):
    """A simple class to hold basic common functions for dialogs
    """

    def center_window(self):
        """centers the window to the screen
        """
        desktop = QtGui.QApplication.desktop()
        cursor_pos = QtGui.QCursor.pos()
        desktop_number = desktop.screenNumber(cursor_pos)
        desktop_rect = desktop.screenGeometry(desktop_number)

        size = self.geometry()

        self.move(
            (desktop_rect.width() - size.width()) * 0.5 + desktop_rect.left(),
            (desktop_rect.height() - size.height()) * 0.5 + desktop_rect.top()
        )

    def get_logged_in_user(self):
        """returns the logged in user
        """
        local_session = LocalSession()
        logged_in_user = local_session.logged_in_user
        if not logged_in_user:
            from anima.ui import login_dialog
            dialog = login_dialog.MainDialog(parent=self)
            dialog.exec_()
            logger.debug("dialog.DialogCode: %s" % dialog.DialogCode)
            if dialog.DialogCode == QtGui.QDialog.DialogCode.Accepted:
                local_session = LocalSession()
                logged_in_user = local_session.logged_in_user
            else:
                # close the ui
                #logged_in_user = self.get_logged_in_user()
                logger.debug("no logged in user")
                self.close()

        return logged_in_user


class MultiLineInputDialog(QtGui.QDialog):
    """A simple dialog with a QPlainTextEdit
    """<commit_msg>* **Fix:** Fixed an error based on the difference between PySide and PyQt4 on QDialog return type.<commit_after># -*- coding: utf-8 -*-
# Copyright (c) 2012-2014, <NAME>
#
# This module is part of anima-tools and is released under the BSD 2
# License: http://www.opensource.org/licenses/BSD-2-Clause


import sys

from stalker import LocalSession
from anima.ui.utils import logger
from anima.ui.lib import QtCore, QtGui


class AnimaDialogBase(object):
    """A simple class to hold basic common functions for dialogs
    """

    def center_window(self):
        """centers the window to the screen
        """
        desktop = QtGui.QApplication.desktop()
        cursor_pos = QtGui.QCursor.pos()
        desktop_number = desktop.screenNumber(cursor_pos)
        desktop_rect = desktop.screenGeometry(desktop_number)

        size = self.geometry()

        self.move(
            (desktop_rect.width() - size.width()) * 0.5 + desktop_rect.left(),
            (desktop_rect.height() - size.height()) * 0.5 + desktop_rect.top()
        )

    def get_logged_in_user(self):
        """returns the logged in user
        """
        local_session = LocalSession()
        logged_in_user = local_session.logged_in_user
        if not logged_in_user:
            from anima.ui import login_dialog
            dialog = login_dialog.MainDialog(parent=self)
            dialog.exec_()
            logger.debug("dialog.DialogCode: %s" % dialog.DialogCode)

            try:
                # PySide
                accepted = QtGui.QDialog.DialogCode.Accepted
            except AttributeError:
                # PyQt4
                accepted = QtGui.QDialog.Accepted

            if dialog.DialogCode == accepted:
                local_session = LocalSession()
                logged_in_user = local_session.logged_in_user
            else:
                # close the ui
                #logged_in_user = self.get_logged_in_user()
                logger.debug("no logged in user")
                self.close()

        return logged_in_user


class MultiLineInputDialog(QtGui.QDialog):
    """A simple dialog with a QPlainTextEdit
    """
{'fraction_non_alphanumeric': 0.09534534534534535, 'fraction_numerical': 0.008008008008008008, 'mean_word_length': 2.2207896857373086, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4577444', 'n_tokens_mistral': 1176, 'n_tokens_neox': 1118, 'n_words': 281}