[PyKDE] Intro + question on where to stick finger
Mike C. Fletcher
mcfletch at rogers.com
Fri Jun 25 21:20:00 BST 2004
Mike C. Fletcher wrote:
...
>>> * drag-and-drop -- as with single-instance operation, when I drag a
>>> file from Konquerer onto my IDE, I want it to open the
>>> file. I assume this will be a fairly trivial task once I figure out
>>> KDE's model for D&D.
>>>
>>
>>
>> That part is still on the todo list.
>
I have a crude implementation of drag-and-drop of files from Konquerer
now. It's not particularly fancy, and I don't have Eric on Win32 to
test there. The biggest concern I have, however, is the parsing of the
text/uri-list data-type, which *appears* to be a \000 seperated list of
uri-escaped strings with \r\n appended to the entries, but that's just
reverse engineered from what Konquerer was giving me when I dropped
files on the app. uri-list is AFAICS the only generic, but
file-specific, data-type being reported by Konquerer.
There's nothing I'm doing to override the drag-and-drop into, for
instance, text-editing windows, so they still have the (less than
particularly useful IMO) response of just embedding the filename in the
text being edited. I would imagine that checking for text/uri-list and
using that for file-drag-and-drop instead of text-drag-and-drop would be
preferable, but it's not actually an issue for me at the moment (I can
just drop onto the main-window).
Probably should check for valid files during dragEnterEvent and only
accept if we really can handle the result. Should also be checking that
we're doing copy, not move. Anyway, code is below if someone else wants
to play with it in the meantime.
Any feedback on making the code fit into Eric would be useful as well.
Have fun all,
Mike
class UserInterface(QMainWindow):
def __init__(self, loc, splash):
...
self.setAcceptDrops(True)
...
def dragEnterEvent( self, event ):
"""
Handler for drag-and-drop entry into the window
"""
if event.provides( 'text/uri-list' ):
event.accept(True)
else:
event.accept(False)
def dropEvent( self, event ):
"""
Handler for drag-and-drop completion on the window
"""
import traceback, urllib
data = event.encodedData( 'text/uri-list' )
files = [ file.replace( '\r\n', '') for file in
data.data().split( '\000' ) if file ]
for file in files:
if file.startswith( 'file:' ):
file = file[5:]
try:
file = urllib.unquote( file )
if os.path.isfile( file ):
self.viewmanager.handlePythonFile( file )
else:
print 'NOT A FILE', file
except Exception, err:
traceback.print_exc()
________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://members.rogers.com/mcfletch/
blog: http://zope.vex.net/~mcfletch/plumbing/
More information about the PyQt
mailing list