# Path: boris/dialog.py
# def MessageDialog(title, text, buttons):
# def error_message_box(task, error_type, error_file_name,
#                       error_lineno):  # do NOT use this function directly, use error_message function
# def error_message(task: str, exc_info: tuple) -> None:
#     def __init__(self, parent=None):
#     def __init__(self):
#     def browse(self):
#     def ok(self):
#     def __init__(self, label_caption, elements_list):
#     def __init__(self, text, codes_list):
#     def getCode(self):
#     def pbOK_clicked(self):
#     def __init__(self, text, observations_list):
#     def get_selected_observations(self):
#     def __init__(self, time_format):
#     def __init__(self):
#     def rb_changed(self):
#     def pbOK_clicked(self):
#     def pbCancel_clicked(self):
#     def __init__(self):
#     def click(self, msg):
#     def __init__(self):
#     def click(self, msg):
#     def __init__(self):
#     def __init__(self):
#     def save_results(self):
#     def __init__(self):
#     def save_results(self):
#     def __init__(self):
#     def __init__(self):
#     def tw_cellDoubleClicked(self, r, c):
# def choose_obs_subj_behav_category(pj: dict,
#                                    selected_observations: list,
#                                    maxTime=0,
#                                    flagShowIncludeModifiers: bool = True,
#                                    flagShowExcludeBehaviorsWoEvents: bool = True,
#                                    by_category: bool = False,
#                                    show_time: bool = False,
#                                    timeFormat: str = HHMMSS):
# class Info_widget(QWidget):
# class Video_overlay_dialog(QDialog):
# class Input_dialog(QDialog):
# class DuplicateBehaviorCode(QDialog):
# class ChooseObservationsToImport(QDialog):
# class Ask_time(QDialog):
# class EditSelectedEvents(QDialog):
# class FindInEvents(QWidget):
# class FindReplaceEvents(QWidget):
# class explore_project_dialog(QDialog):
# class Results_dialog(QDialog):
# class ResultsWidget(QWidget):
# class View_data_head(QDialog):
# class View_explore_project_results(QWidget):
# 
# Path: boris/project_functions.py
# def check_observation_exhaustivity(events: list, ethogram: list, state_events_list: list = []):
#     def interval_len(interval):
#     def interval_number(interval):
# def behavior_category(ethogram: dict) -> dict:
# def check_coded_behaviors(pj: dict) -> set:
# def check_if_media_available(observation: dict, project_file_name: str) -> bool:
# def check_state_events_obs(obsId: str, ethogram: dict, observation: dict, time_format: str = HHMMSS) -> tuple:
# def check_project_integrity(pj: dict,
#                             time_format: str,
#                             project_file_name: str,
#                             media_file_available: bool = True) -> str:
# def create_subtitles(pj: dict, selected_observations: list, parameters: dict, export_dir: str) -> tuple:
#     def subject_color(subject):
# def export_observations_list(pj: dict, selected_observations: list, file_name: str, output_format: str) -> bool:
# def remove_media_files_path(pj):
# def media_full_path(media_file: str, project_file_name: str) -> str:
# def observed_interval(observation: dict):
# def observation_total_length(observation: dict):
# def observation_length(pj, selected_observations: list) -> tuple:
# def events_start_stop(ethogram, events):
# def extract_observed_subjects(pj: dict, selected_observations: list) -> list:
# def open_project_json(projectFileName: str) -> tuple:
# def event_type(code: str, ethogram: dict) -> str:
# def fix_unpaired_state_events(obsId, ethogram, observation, fix_at_time):
# 
# Path: boris/param_panel.py
# class Param_panel(QDialog, Ui_Dialog):
#     def __init__(self, parent=None):
#     def rb_time(self, button):
#     def subjects_button_clicked(self, command):
#     def behaviors_button_clicked(self, command):
#     def ok(self):
#     def behavior_item_clicked(self, item):
#     def extract_observed_behaviors(self, selected_observations, selected_subjects):
#     def cb_changed(self):


import sys
import logging
import boris.utilities as utilities
from boris import dialog
from boris import project_functions
from boris.config import *
from boris import param_panel
from PyQt5.QtWidgets import (QFileDialog, QTableWidgetItem, QApplication, QMessageBox, QListWidgetItem)
from PyQt5.QtCore import (Qt)
from PyQt5.QtGui import (QColor, QFont)

                            item.setText(str(project[ETHOGRAM][i][field]))

                            if field not in ETHOGRAM_EDITABLE_FIELDS:
                                item.setFlags(Qt.ItemIsEnabled)
                                item.setBackground(QColor(230, 230, 230))

                        self.twBehaviors.setItem(self.twBehaviors.rowCount() - 1, behavioursFields[field], item)

                self.twBehaviors.resizeColumnsToContents()

            else:
                QMessageBox.warning(self, programName, "No behaviors configuration found in project")

    except Exception:
        dialog.error_message(sys._getframe().f_code.co_name, sys.exc_info())


def import_subjects_from_project(self):
    """
    import subjects from another project
    """

    try:
        fn = QFileDialog().getOpenFileName(self, "Import subjects from project file", "",
                                           ("Project files (*.boris *.boris.gz);;"
                                            "All files (*)"))
        file_name = fn[0] if type(fn) is tuple else fn

        if file_name:

# Path: boris/dialog.py
# def MessageDialog(title, text, buttons):
# def error_message_box(task, error_type, error_file_name,
#                       error_lineno):  # do NOT use this function directly, use error_message function
# def error_message(task: str, exc_info: tuple) -> None:
#     def __init__(self, parent=None):
#     def __init__(self):
#     def browse(self):
#     def ok(self):
#     def __init__(self, label_caption, elements_list):
#     def __init__(self, text, codes_list):
#     def getCode(self):
#     def pbOK_clicked(self):
#     def __init__(self, text, observations_list):
#     def get_selected_observations(self):
#     def __init__(self, time_format):
#     def __init__(self):
#     def rb_changed(self):
#     def pbOK_clicked(self):
#     def pbCancel_clicked(self):
#     def __init__(self):
#     def click(self, msg):
#     def __init__(self):
#     def click(self, msg):
#     def __init__(self):
#     def __init__(self):
#     def save_results(self):
#     def __init__(self):
#     def save_results(self):
#     def __init__(self):
#     def __init__(self):
#     def tw_cellDoubleClicked(self, r, c):
# def choose_obs_subj_behav_category(pj: dict,
#                                    selected_observations: list,
#                                    maxTime=0,
#                                    flagShowIncludeModifiers: bool = True,
#                                    flagShowExcludeBehaviorsWoEvents: bool = True,
#                                    by_category: bool = False,
#                                    show_time: bool = False,
#                                    timeFormat: str = HHMMSS):
# class Info_widget(QWidget):
# class Video_overlay_dialog(QDialog):
# class Input_dialog(QDialog):
# class DuplicateBehaviorCode(QDialog):
# class ChooseObservationsToImport(QDialog):
# class Ask_time(QDialog):
# class EditSelectedEvents(QDialog):
# class FindInEvents(QWidget):
# class FindReplaceEvents(QWidget):
# class explore_project_dialog(QDialog):
# class Results_dialog(QDialog):
# class ResultsWidget(QWidget):
# class View_data_head(QDialog):
# class View_explore_project_results(QWidget):
# 
# Path: boris/project_functions.py
# def check_observation_exhaustivity(events: list, ethogram: list, state_events_list: list = []):
#     def interval_len(interval):
#     def interval_number(interval):
# def behavior_category(ethogram: dict) -> dict:
# def check_coded_behaviors(pj: dict) -> set:
# def check_if_media_available(observation: dict, project_file_name: str) -> bool:
# def check_state_events_obs(obsId: str, ethogram: dict, observation: dict, time_format: str = HHMMSS) -> tuple:
# def check_project_integrity(pj: dict,
#                             time_format: str,
#                             project_file_name: str,
#                             media_file_available: bool = True) -> str:
# def create_subtitles(pj: dict, selected_observations: list, parameters: dict, export_dir: str) -> tuple:
#     def subject_color(subject):
# def export_observations_list(pj: dict, selected_observations: list, file_name: str, output_format: str) -> bool:
# def remove_media_files_path(pj):
# def media_full_path(media_file: str, project_file_name: str) -> str:
# def observed_interval(observation: dict):
# def observation_total_length(observation: dict):
# def observation_length(pj, selected_observations: list) -> tuple:
# def events_start_stop(ethogram, events):
# def extract_observed_subjects(pj: dict, selected_observations: list) -> list:
# def open_project_json(projectFileName: str) -> tuple:
# def event_type(code: str, ethogram: dict) -> str:
# def fix_unpaired_state_events(obsId, ethogram, observation, fix_at_time):
# 
# Path: boris/param_panel.py
# class Param_panel(QDialog, Ui_Dialog):
#     def __init__(self, parent=None):
#     def rb_time(self, button):
#     def subjects_button_clicked(self, command):
#     def behaviors_button_clicked(self, command):
#     def ok(self):
#     def behavior_item_clicked(self, item):
#     def extract_observed_behaviors(self, selected_observations, selected_subjects):
#     def cb_changed(self):


# Path: boris/project_import.py
import sys
import logging
import boris.utilities as utilities
from boris import dialog
from boris import project_functions
from boris.config import *
from boris import param_panel
from PyQt5.QtWidgets import (QFileDialog, QTableWidgetItem, QApplication, QMessageBox, QListWidgetItem)
from PyQt5.QtCore import (Qt)
from PyQt5.QtGui import (QColor, QFont)


                            item.setText(str(project[ETHOGRAM][i][field]))

                            if field not in ETHOGRAM_EDITABLE_FIELDS:
                                item.setFlags(Qt.ItemIsEnabled)
                                item.setBackground(QColor(230, 230, 230))

                        self.twBehaviors.setItem(self.twBehaviors.rowCount() - 1, behavioursFields[field], item)

                self.twBehaviors.resizeColumnsToContents()

            else:
                QMessageBox.warning(self, programName, "No behaviors configuration found in project")

    except Exception:
        dialog.error_message(sys._getframe().f_code.co_name, sys.exc_info())


def import_subjects_from_project(self):
    """
    import subjects from another project
    """

    try:
        fn = QFileDialog().getOpenFileName(self, "Import subjects from project file", "",
                                           ("Project files (*.boris *.boris.gz);;"
                                            "All files (*)"))
        file_name = fn[0] if type(fn) is tuple else fn

        if file_name:

            _, _, project, _ = project_functions.open_project_json(file_name)