simple text editor w/ D&D of hyperlinks
Andrew Dalke
adalke at mindspring.com
Tue Nov 19 04:56:57 EST 2002
Neil Hodgson wrote:
> The Mozilla (1.1) on X URL drag format appears incompatible with most
> editors. On Windows, Scintilla can receive the URL text but not on X where
> it is looking for "STRING", "TEXT", "COMPOUND_TEXT", or "text/uri-list"
> formats. OTOH Classic Netscape uses a widely supported drag format.
Yeah, I noticed that. When I drop a Mozilla URL into XEmacs I only
get the first character.
OTOH, since I'm implementing the app myself, I can special case things
as needed. Here's my code to dump the Mozilla and Konqueror info in
addition to the normal text versions.
import sys
from qt import *
class YEdit(QTextEdit):
def __init__(self, *args):
QTextEdit.__init__(self, *args)
self.setTextFormat(Qt.RichText)
self.setText("<qt>Hello <b>World!</b></qt>")
# self.setAcceptDrops(1)
def contentsDragEnterEvent(self, evt):
if evt.provides("text/uri-list"):
# KDE URL
evt.accept(1)
elif evt.provides("text/x-moz-url"):
# Mozilla URL
evt.accept(1)
else:
QTextEdit.contentsDragEnterEvent(self, evt)
def contentsDropEvent(self, evt):
url = None
if evt.provides("text/uri-list"):
url = str(evt.encodedData("text/plain"))
if url[-1:] == "\0":
url = url[:-1]
print "KDE", repr(url)
evt.acceptAction(1)
elif evt.provides("text/x-moz-url"):
# Mozilla URL
url = str(evt.encodedData("text/plain"))
print "Mozilla", repr(url)
evt.acceptAction(1)
else:
QTextEdit.contentsDropEvent(self, evt)
return
b = self.bold()
self.setBold(0)
self.insert("url=")
self.setBold(1)
self.insert(url)
self.setBold(b)
class AppWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self, None, 'yedit', Qt.WDestructiveClose)
self._edit = YEdit(self, "Blah")
self.setCentralWidget(self._edit)
def main(app):
w = AppWindow()
app.setMainWidget(w)
w.show()
app.exec_loop()
if __name__ == "__main__":
app = QApplication(sys.argv)
main(app)
Andrew
dalke at dalkescientific.com
More information about the Python-list
mailing list