hashableQListWidgetItem.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Copyright (c) <2015-Present> Tzutalin
  2. # Copyright (C) 2013 MIT, Computer Science and Artificial Intelligence Laboratory. Bryan Russell, Antonio Torralba,
  3. # William T. Freeman. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
  4. # associated documentation files (the "Software"), to deal in the Software without restriction, including without
  5. # limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
  6. # Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  7. # The above copyright notice and this permission notice shall be included in all copies or substantial portions of
  8. # the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
  9. # NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
  10. # SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  11. # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  12. # THE SOFTWARE.
  13. #!/usr/bin/env python
  14. # -*- coding: utf-8 -*-
  15. import sys
  16. try:
  17. from PyQt5.QtGui import *
  18. from PyQt5.QtCore import *
  19. from PyQt5.QtWidgets import *
  20. except ImportError:
  21. # needed for py3+qt4
  22. # Ref:
  23. # http://pyqt.sourceforge.net/Docs/PyQt4/incompatible_apis.html
  24. # http://stackoverflow.com/questions/21217399/pyqt4-qtcore-qvariant-object-instead-of-a-string
  25. if sys.version_info.major >= 3:
  26. import sip
  27. sip.setapi('QVariant', 2)
  28. from PyQt4.QtGui import *
  29. from PyQt4.QtCore import *
  30. # PyQt5: TypeError: unhashable type: 'QListWidgetItem'
  31. class HashableQListWidgetItem(QListWidgetItem):
  32. def __init__(self, *args):
  33. super(HashableQListWidgetItem, self).__init__(*args)
  34. def __hash__(self):
  35. return hash(id(self))