import numpy as np
import sys
import matplotlib.pyplot as plt
import itertools as iter
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *


class Stroke:
    def __init__(self):
        self.Points = np.empty(7)
        self.ID = 0
        self.BorderingOffStrokes = []
        self.BoundaryPoints = [[0,0,0],[0,0,0]]
        self.Bounds=[]
        self.pictIndex = None
        self.fileName = None
        self.offStrokes = []

class OffStroke:
    def __init__(self):
        self.Points = np.empty(7)
        self.ID = 0
        self.BorderingStrokes = []
        self.BoundaryPoints = [[0,0,0],[0,0,0]]
        self.Bounds = []

class MyListWidget(QListWidget):
    def __init__(self, parent):
        super(MyListWidget, self).__init__( parent)
        self.setAcceptDrops(True)
        self.selectedPict = None
        self.parent = parent
        self.ID = None

    #def decodeMimeData(self, data):
    #    result = {}
    #    value = QVariant()
    #    stream = QDataStream(data)
    #    while not stream.atEnd():
    #        row = stream.readInt32()
    #        col = stream.readInt32()
    #        item = result.setdefault(col, {})
    #        for role in range(stream.readInt32()):
    #            key = Qt.ItemDataRole(stream.readInt32())
    #            stream >> value
    #            item[key] = value.toPyObject()
    #    return result

    def dropEvent(self, event):
        print(event.source().ID)
        if event.source() == self:
            event.setDropAction(Qt.MoveAction)
        
        super(MyListWidget, self).dropEvent(event)
        if event.source() != self:
            try:
                self.parent.updatePictos(self.ID, self.selectedPict)
            except Exception as ex:
                print(ex)
                #raw_input()
                #traceback.print_exc()

        #self.addItem(e.mimeData())
        #print(e.mimeData().text())
        #self.parent.Data.Pictos[self.selectedPict].sIndex.append(int(e.mimeData().text()))
        #print(self.decodeMimeData(e.mimeData().data(format)))

