Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 63b3abcd43
Fetching contributors…

Cannot retrieve contributors at this time

executable file 77 lines (59 sloc) 1.768 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
#!/usr/bin/env python
# A simple drop target app for testing drag and drop
# Copyright (C) 2008 Gary Sherman
# Licensed under the terms of GNU GPL 2
from PyQt4.QtCore import *
from PyQt4.QtGui import *
#from qgis.core import *
#from qgis.gui import *
import sys
import os
# Import our GUI tree->setRootIndex(model->index(QDir::currentPath()));
from droptarget_ui import Ui_MainWindow
# Import our resources (icons)
import resources

# Environment variable QGISHOME must be set to the 0.9 install directory
# before running this application
qgis_prefix = os.getenv("QGISHOME")

class DropTarget(QMainWindow, Ui_MainWindow):

  def __init__(self):
    
    QMainWindow.__init__(self)

    # Required by Qt4 to initialize the UI
    self.setupUi(self)

    # Set the title for the app
    self.setWindowTitle("Drop Target")

    # enable drop
    self.setAcceptDrops(True)

  def dragEnterEvent(self, event):
    if event.mimeData().hasUrls():
      fmts = event.mimeData().formats()
      for f in fmts:
        print f
      urls = event.mimeData().urls()
      for u in urls:
        print u.toString()
      event.acceptProposedAction()
    

  def dropEvent(self, event):
    urls = event.mimeData().urls()
    for u in urls:
      print u.toString()
      self.textEdit.setPlainText(u.path())
    event.acceptProposedAction();
 

def main(argv):
  # create Qt application
  app = QApplication(argv)

  # Initialize qgis libraries
  #QgsApplication.setPrefixPath(qgis_prefix, True)
  #QgsApplication.initQgis()

  # create main window
  wnd = DropTarget()
  # Move the app window to upper left
  wnd.move(100,100)
  wnd.show()

  # run!
  retval = app.exec_()

  # exit
  #QgsApplication.exitQgis()
  sys.exit(retval)


if __name__ == "__main__":
  main(sys.argv)
Something went wrong with that request. Please try again.