# Path: src/plugins/util/custom_qt_items.py
# class CheckableComboBox(QtGui.QComboBox):
#     def __init__(self):
#         super(CheckableComboBox, self).__init__()
#         self.view().pressed.connect(self.handleItemPressed)
#         self.setModel(QtGui.QStandardItemModel(self))
# 
#     def handleItemPressed(self, index):
#         item = self.model().itemFromIndex(index)
#         if item.checkState() == QtCore.Qt.Checked:
#             item.setCheckState(QtCore.Qt.Unchecked)
#         else:
#             item.setCheckState(QtCore.Qt.Checked)
# 
# class PlayerDialog(QDialog):
#   def __init__(self, project, filename, parent=None, scaling=True):
#     super(PlayerDialog, self).__init__(parent)
#     self.project = project
#     self.setup_ui()
#     self.setWindowTitle(os.path.basename(filename))
# 
#     self.scale = scaling
#     self.fp = np.load(filename, mmap_mode='r')
#     if isinstance(scaling, bool) and scaling:
#         self.global_min = np.min(self.fp)
#         self.global_max = np.max(self.fp)
#     if isinstance(scaling, tuple):
#         self.global_min = scaling[0]
#         self.global_max = scaling[1]
#     self.slider.setMaximum(len(self.fp)-1)
#     self.show_frame(0)
# 
#   def show_frame(self, frame_num):
#     frame = self.fp[frame_num]
#     self.label_frame.setText(str(frame_num) + ' / ' + str(len(self.fp)-1))
#     if hasattr(self, 'global_min') and hasattr(self, 'global_max'):
#         self.view.show(frame, self.global_min, self.global_max)
#     else:
#         self.view.show(frame)
# 
#   def setup_ui(self):
#     vbox = QVBoxLayout()
#     self.view = MyGraphicsView(self.project)
#     vbox.addWidget(self.view)
#     hbox = QHBoxLayout()
#     self.slider = QSlider(Qt.Horizontal)
#     self.slider.valueChanged.connect(self.slider_moved)
#     hbox.addWidget(self.slider)
#     self.label_frame = QLabel('- / -')
#     hbox.addWidget(self.label_frame)
#     vbox.addLayout(hbox)
#     self.setLayout(vbox)
# 
#   def slider_moved(self, value):
#     self.show_frame(value)
# 
# Path: src/plugins/util/file_io.py
# def load_reference_frame(filename, offset=0):
#   if filename.endswith('.npy'):
#     frame = load_reference_frame_npy(filename, offset)
#   else:
#     raise UnknownFileFormatError()
#   return frame


import ast
import functools
import os
import pickle
import uuid
import qtutil
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from . import constants
from . import file_io
from .custom_qt_items import CheckableComboBox, PlayerDialog
from .file_io import load_reference_frame

    if len(indices) == 0:
        return
    if len(indices) > 1:
        ui_list.setCurrentIndex(ui_list.model().index(indices[0], 0))
        theQIndexObjects = [ui_list.model().createIndex(rowIndex, 0) for rowIndex in
                            indices]
        for Qindex in theQIndexObjects:
            ui_list.selectionModel().select(Qindex, QItemSelectionModel.Select)
    elif len(indices) == 1:
        ui_list.setCurrentIndex(ui_list.model().index(indices[0], 0))

def refresh_video_list_via_combo_box(widget, list_display_type, trigger_item=None):
    if trigger_item != 0:
        widget.toolbutton.model().item(0, 0).setCheckState(Qt.Unchecked)

    last_manips_to_display = []
    for i in range(widget.toolbutton.count()):
        if widget.toolbutton.model().item(i, 0).checkState() != 0:
            last_manips_to_display = last_manips_to_display + [widget.toolbutton.itemText(i)]
    refresh_list(widget.project, widget.video_list, [0], list_display_type, last_manips_to_display)

def get_project_file_from_key_item(project, key, item):
    file = [files for files in project.files if os.path.normpath(files[key]) == os.path.normpath(item)]
    if not file:
        return
    assert (len(file) == 1)
    return file[0]

def add_combo_dropdown(widget, items):

# Path: src/plugins/util/custom_qt_items.py
# class CheckableComboBox(QtGui.QComboBox):
#     def __init__(self):
#         super(CheckableComboBox, self).__init__()
#         self.view().pressed.connect(self.handleItemPressed)
#         self.setModel(QtGui.QStandardItemModel(self))
# 
#     def handleItemPressed(self, index):
#         item = self.model().itemFromIndex(index)
#         if item.checkState() == QtCore.Qt.Checked:
#             item.setCheckState(QtCore.Qt.Unchecked)
#         else:
#             item.setCheckState(QtCore.Qt.Checked)
# 
# class PlayerDialog(QDialog):
#   def __init__(self, project, filename, parent=None, scaling=True):
#     super(PlayerDialog, self).__init__(parent)
#     self.project = project
#     self.setup_ui()
#     self.setWindowTitle(os.path.basename(filename))
# 
#     self.scale = scaling
#     self.fp = np.load(filename, mmap_mode='r')
#     if isinstance(scaling, bool) and scaling:
#         self.global_min = np.min(self.fp)
#         self.global_max = np.max(self.fp)
#     if isinstance(scaling, tuple):
#         self.global_min = scaling[0]
#         self.global_max = scaling[1]
#     self.slider.setMaximum(len(self.fp)-1)
#     self.show_frame(0)
# 
#   def show_frame(self, frame_num):
#     frame = self.fp[frame_num]
#     self.label_frame.setText(str(frame_num) + ' / ' + str(len(self.fp)-1))
#     if hasattr(self, 'global_min') and hasattr(self, 'global_max'):
#         self.view.show(frame, self.global_min, self.global_max)
#     else:
#         self.view.show(frame)
# 
#   def setup_ui(self):
#     vbox = QVBoxLayout()
#     self.view = MyGraphicsView(self.project)
#     vbox.addWidget(self.view)
#     hbox = QHBoxLayout()
#     self.slider = QSlider(Qt.Horizontal)
#     self.slider.valueChanged.connect(self.slider_moved)
#     hbox.addWidget(self.slider)
#     self.label_frame = QLabel('- / -')
#     hbox.addWidget(self.label_frame)
#     vbox.addLayout(hbox)
#     self.setLayout(vbox)
# 
#   def slider_moved(self, value):
#     self.show_frame(value)
# 
# Path: src/plugins/util/file_io.py
# def load_reference_frame(filename, offset=0):
#   if filename.endswith('.npy'):
#     frame = load_reference_frame_npy(filename, offset)
#   else:
#     raise UnknownFileFormatError()
#   return frame


# Path: src/plugins/util/project_functions.py
import ast
import functools
import os
import pickle
import uuid
import qtutil
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from . import constants
from . import file_io
from .custom_qt_items import CheckableComboBox, PlayerDialog
from .file_io import load_reference_frame


    if len(indices) == 0:
        return
    if len(indices) > 1:
        ui_list.setCurrentIndex(ui_list.model().index(indices[0], 0))
        theQIndexObjects = [ui_list.model().createIndex(rowIndex, 0) for rowIndex in
                            indices]
        for Qindex in theQIndexObjects:
            ui_list.selectionModel().select(Qindex, QItemSelectionModel.Select)
    elif len(indices) == 1:
        ui_list.setCurrentIndex(ui_list.model().index(indices[0], 0))

def refresh_video_list_via_combo_box(widget, list_display_type, trigger_item=None):
    if trigger_item != 0:
        widget.toolbutton.model().item(0, 0).setCheckState(Qt.Unchecked)

    last_manips_to_display = []
    for i in range(widget.toolbutton.count()):
        if widget.toolbutton.model().item(i, 0).checkState() != 0:
            last_manips_to_display = last_manips_to_display + [widget.toolbutton.itemText(i)]
    refresh_list(widget.project, widget.video_list, [0], list_display_type, last_manips_to_display)

def get_project_file_from_key_item(project, key, item):
    file = [files for files in project.files if os.path.normpath(files[key]) == os.path.normpath(item)]
    if not file:
        return
    assert (len(file) == 1)
    return file[0]

def add_combo_dropdown(widget, items):

    widget.ComboBox = CheckableComboBox()