Syntext Forums - Serna Enterprise XML Editor, Serna Free XML Editor
(#1 (permalink))
Old
Junior Member
 
Posts: 26
Join Date: Jul 2009
Default need help to drag-and-drop from QTreeView into ContentMap - 09-16-2009, 06:57 PM

I'm implementing drag-and-drop from QTreeView into the ContentMap in a Python plugin. If I properly understand, classes MimeHandler and MimeCallback should be used. Is there an example of their usage in Python?
Reply With Quote
(#2 (permalink))
Old
apg apg is offline
Administrator
 
Posts: 53
Join Date: Mar 2009
Default 09-17-2009, 02:39 PM

Here's a piece of code which takes text/plain mime type, appends '123' to the text and creates drop buffer for Serna (DocumentFragment). The idea is simple: callback should create appropriate GroveDocumentFragment from the QMimeData.

Code:
from SernaApi import *
from weakref import *
from PyQt4.QtCore import QMimeData
from PyQt4.QtGui import QDropEvent

class TextToFragment(MimeCallback):
    def __init__(self, mt):
        MimeCallback.__init__(self)
        self.fragMimeType_ = mt
    
    def mimeType(self):
        return "text/plain"
    
    def callbackClass(self):
        return MimeCallback.CREATE_FRAGMENT
    
    def execute(self, mh, dropevent):
        frag  = GroveDocumentFragment()
        tnode = GroveText(unicode(mh.mimeData().text() + "123"))
        frag.appendChild(tnode)
        SernaDocFragment.newFragment(mh.mimeData(), \
                self.fragMimeType_).setFragment(frag)
        return True

class MimeCallbacksTest(DocumentPlugin):
    def __init__(self, a1, a2):
        DocumentPlugin.__init__(self, a1, a2)
        self.buildPluginExecutors(True)
        self.mh_ = self.sernaDoc().mimeHandler()

    def postInit(self):
        target_mt = SernaDocFragment.fragMimeType(self.sernaDoc().getDsi())
        self.textToFrag_ = TextToFragment(target_mt)
        self.mh_.registerCallback(self.textToFrag_, 150)
~
Reply With Quote
(#3 (permalink))
Old
Junior Member
 
Posts: 26
Join Date: Jul 2009
Default 09-17-2009, 07:21 PM

Thanks a lot! It works, except in
"SernaDocFragment.newFragment(mh.mimeData(), \
self.fragMimeType_).setFragment(frag)"
it actually should be
"SernaDocFragment.newFragment(mh, \
self.fragMimeType_).setFragment(frag)"
The rest is just perfect! Thanks again for the help.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.1
vBulletin Skin developed by: vBStyles.com