SIP4 python bindings for TQt
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # This is part of the dragdrop example.
  2. from python_tqt.qt import *
  3. import secret
  4. class DropSite(TQLabel):
  5. def __init__(self, parent=None, name=None):
  6. TQLabel.__init__( self, parent, name )
  7. self.setAcceptDrops(1)
  8. # this is a normal event
  9. def mousePressEvent( self, e ):
  10. if ( self.pixmap() ) :
  11. drobj = TQImageDrag( self.pixmap().convertToImage(), self )
  12. pm = TQPixmap()
  13. pm.convertFromImage(self.pixmap().convertToImage().smoothScale(
  14. self.pixmap().width()/3,self.pixmap().height()/3))
  15. drobj.setPixmap(pm,TQPoint(-5,-7))
  16. else :
  17. drobj = TQTextDrag( self.text(), self )
  18. drobj.dragCopy()
  19. def backgroundColorChange( self, qcolor ):
  20. # Reduce flicker by using repaint() rather than update()
  21. self.repaint()
  22. def dragMoveEvent( self, e ):
  23. # Check if you want the drag at e.pos()...
  24. # Give the user some feedback...
  25. pass
  26. def dragEnterEvent( self, e ):
  27. # Check if you want the drag...
  28. if (secret.canDecode( e ) or
  29. TQTextDrag.canDecode( e ) or
  30. TQImageDrag.canDecode( e ) or
  31. TQUriDrag.canDecode( e )):
  32. e.accept()
  33. # Give the user some feedback...
  34. t = ''
  35. i = 0
  36. while e.format( i ):
  37. if ( t != '' ):
  38. t += "\n"
  39. t += str(e.format( i ))
  40. i += 1
  41. self.emit(PYSIGNAL('message(TQString &)'), (TQString(t),))
  42. self.setEraseColor(TQt.white)
  43. def dragLeaveEvent( self, TQDragLeaveEvent ):
  44. # Give the user some feedback...
  45. self.emit(PYSIGNAL('message(TQString &)'), (TQString(''),))
  46. self.setEraseColor(TQt.lightGray)
  47. def dropEvent( self, e ):
  48. self.setEraseColor(TQt.lightGray)
  49. # Try to decode to the data you understand...
  50. str = TQString()
  51. if ( TQTextDrag.decode( e, str ) ) :
  52. self.setText( str )
  53. self.setMinimumSize( self.minimumSize().expandedTo(self.sizeHint()) )
  54. return
  55. pm = TQPixmap()
  56. if ( TQImageDrag.decode( e, pm ) ) :
  57. self.setPixmap( pm )
  58. self.setMinimumSize(self.minimumSize().expandedTo(self.sizeHint()))
  59. return
  60. # TQStrList strings
  61. #strings = TQStrList()
  62. strings = []
  63. if ( TQUriDrag.decode( e, strings ) ) :
  64. m = TQString("Full URLs:\n")
  65. for u in strings:
  66. m = m + " " + u + '\n'
  67. # TQStringList files
  68. files = []
  69. if ( TQUriDrag.decodeLocalFiles( e, files ) ) :
  70. m += "Files:\n"
  71. # for (TQStringList.Iterator i=files.begin() i!=files.end() ++i)
  72. for i in files:
  73. m = m + " " + i + '\n'
  74. self.setText( m )
  75. self.setMinimumSize(self.minimumSize().expandedTo(self.sizeHint()))
  76. return
  77. str = secret.decode( e )
  78. if str:
  79. self.setText( str )
  80. self.setMinimumSize(self.minimumSize().expandedTo(self.sizeHint()))
  81. return