Exemplo n.º 1
0
    def mimeData(self, modelIndexes):
        item       = self.itemFromIndex(modelIndexes[0])
        mimeData   = QtGui.QStandardItemModel.mimeData(self, modelIndexes)
        (pkg_id, factory_id, mimetype) = self.get_item_info(item)

        # -- marshall package and factory to the data stream, needed later --
        itemData   = QtCore.QByteArray()
        dataStream = QtCore.QDataStream(itemData, QtCore.QIODevice.WriteOnly)
        dataStream.writeString(pkg_id)
        dataStream.writeString(factory_id)
        mimeData.setData(mimetype, itemData)

        # -- build an url --
        factory = PackageManager()[pkg_id][factory_id]
        if isinstance(factory, DataFactory):
            url = QtCore.QUrl.fromLocalFile(factory.get_pkg_data().repr)
        else:
            query   = ["fac="+factory_id]
            ftname  = type(factory).__name__
            query.append("ft="+ftname)
            query = reduce(lambda x,y:"&".join((x,y)), query)
            url = QtCore.QUrl("oa://local/"+pkg_id+"?"+query)

        mimeData.setUrls([url])
        return mimeData
Exemplo n.º 2
0
    def open_node(self):
        """ Instantiate Node : open a dialog """
        index = self.currentIndex()
        obj   = self.model().data(index, PkgModel.pkgmodelRole)

        if(isinstance(obj, AbstractFactory)):
            widget = obj.instantiate_widget(autonomous=True)
            open_dialog(self, widget, obj.get_id())

        elif(isinstance(obj, Package)):
            # Display URL
            urlstr = obj.get_metainfo('url')
            QtGui.QDesktopServices.openUrl(QtCore.QUrl(urlstr))
Exemplo n.º 3
0
def file_url_to_path(url):
    qurl = QtCore.QUrl(url)
    return str(qurl.toLocalFile())