Exemple #1
0
    def setModelData(self, editor, model, index):
        if index.column() == 0:
            sindex = self.table.table.model().mapToSource(index)
            cindex = editor.currentIndex()
            relation = index.model().sourceModel().relations[sindex.row()]
            predicate = relation[0]
            direct = relation[2]
            if direct:
                subject = self.table.resource
                object = relation[1]
            else:
                subject = relation[1]
                object = self.table.resource

            newPredicate = self.sortedProps[cindex][0]
            if newPredicate.uri().toString() != predicate.uri().toString():
                self.table.setCursor(Qt.WaitCursor)
                subject.addProperty(newPredicate.uri(),
                                    Nepomuk.Variant(object.resourceUri()))
                subject.removeProperty(predicate.uri(),
                                       Nepomuk.Variant(object.resourceUri()))
                self.table.unsetCursor()
            #don't do that since the model gets already updated through signal emission
            #index.model().sourceModel().relations[index.row()] = (newPredicate, object, direct)
        else:
            QItemDelegate.setModelData(self, editor, model, index)
Exemple #2
0
def getFileResource(path):
    absolutePath = os.path.abspath(path)
    name = os.path.basename(path)
    url = "file://" + absolutePath
    file = Nepomuk.Resource(QUrl(url))

    #    print file.isValid()
    if len(file.resourceUri().toString()) == 0:
        file.setProperty(NIE.url, Nepomuk.Variant(QUrl(url)))
        file.setProperty(NFO.fileName, Nepomuk.Variant(name))
        file.setLabel(name)

    return file
Exemple #3
0
    def save(self):

        super(ContactEditor, self).save()

        self.resource.setProperty(
            NCO.nameGiven, Nepomuk.Variant(unicode(self.ui.firstname.text())))
        self.resource.setProperty(
            NCO.nameFamily, Nepomuk.Variant(unicode(self.ui.lastname.text())))
        self.resource.setProperty(NCO.emailAddress,
                                  Nepomuk.Variant(self.ui.email.text()))
        self.resource.setProperty(NCO.phoneNumber,
                                  Nepomuk.Variant(self.ui.phone.text()))

        self.ui.updateFields()
Exemple #4
0
def findRelations(uri):

    resource = Nepomuk.Resource(uri)
    relations = dict()
    props = resource.properties()

    for prop in props:
        if props[prop].isResourceList():
            relations[prop.toString()] = set(props[prop].toResourceList())
        elif props[prop].isResource():
            relations[prop.toString()] = set([props[prop].toResource()])

    props = resourceTypesProperties(resource)
    for property in props:
        irel = Nepomuk.ResourceManager.instance().allResourcesWithProperty(
            property.uri(), Nepomuk.Variant(resource))
        if len(irel) > 0 and relations.has_key(property.uri().toString()):
            relations[property.uri().toString()] = relations[
                property.uri().toString()].union(irel)
        elif len(irel) > 0:
            relations[property.uri().toString()] = set(irel)

    #TODO: the dict should directly contain property objects, and compare them properly
    #see how to give the dict a good hash function for properties (based on the comparison of their uri)

    newrelations = dict()
    for key in relations.keys():
        prop = Nepomuk.Types.Property(QUrl(key))
        newrelations[prop] = relations[key]

    return newrelations
Exemple #5
0
def findInverseRelationsTemp(uri):
    resource = Nepomuk.Resource(uri)
    relations = dict()

    props = resourceTypesProperties(resource)
    for property in props:
        #skip the RDF.type() property, otherwise for classes we get all their instances
        if property.uri() == Soprano.Vocabulary.RDF.type():
            continue

        irel = Nepomuk.ResourceManager.instance().allResourcesWithProperty(
            property.uri(), Nepomuk.Variant(resource))
        if len(irel) > 0 and relations.has_key(property.uri().toString()):
            relations[property.uri().toString()] = relations[
                property.uri().toString()].union(irel)
        elif len(irel) > 0:
            relations[property.uri().toString()] = set(irel)

    #TODO: the dict should directly contain property objects, and compare them properly
    #see how to give the dict a good hash function for properties (based on the comparison of their uri)

    newrelations = dict()
    for key in relations.keys():
        prop = Nepomuk.Types.Property(QUrl(key))
        newrelations[prop] = relations[key]

    return newrelations
 def processAction(self, key, propvalue):
     if key == COPY_TO_CLIPBOARD:
         clipboard = QApplication.clipboard()
         clipboard.setText(propvalue[1].toString())
     elif key == ADD_PROPERTY:
         elt = (Soprano.Vocabulary.RDFS.comment(), Nepomuk.Variant(""))
         self.table.model().sourceModel().addProperty(elt)
Exemple #7
0
 def save(self):
     
     super(WebsiteEditor, self).save()
     
     self.resource.setProperty(NIE.url, Nepomuk.Variant(QUrl(unicode(self.ui.url.text()))))
     
     self.ui.updateFields()
    def setModelData(self, editor, model, index):
        if index.column() == 0:
            sindex = self.table.table.model().mapToSource(index)
            cindex = editor.currentIndex()
            predicateUrl = index.model().sourceModel().data[sindex.row()][0]
            value = index.model().sourceModel().data[sindex.row()][1]
            
            newPredicate = self.sortedProps[cindex][0]
            if newPredicate.uri() != predicateUrl:
                self.table.setCursor(Qt.WaitCursor)
                self.table.resource.addProperty(newPredicate.uri(), Nepomuk.Variant(value))
                self.table.resource.removeProperty(predicateUrl, Nepomuk.Variant(value))
                self.table.unsetCursor()
            #here we need to update the model since it won't get updated by signal emission
            index.model().sourceModel().data[sindex.row()] = (newPredicate.uri(), value)
            
        elif index.column() == 1:
            sindex = self.table.table.model().mapToSource(index)
            predicateUrl = index.model().sourceModel().data[sindex.row()][0]
            value = index.model().sourceModel().data[sindex.row()][1]

            #TODO: fix that (class comparison won't work since QSpinBox.__class__ is a pyqtWrapperType
            if str(editor.__class__) in ("<class 'PyQt4.QtGui.QSpinBox'>", "<class 'PyQt4.QtGui.QDoubleSpinBox'>"):
                newValue = editor.value()
                
            elif str(editor.__class__) == "<class 'PyQt4.QtGui.QDateEdit'>":
                newValue = editor.date()
            
            elif str(editor.__class__) == "<class 'PyQt4.QtGui.QDateTimeEdit'>":
                newValue = editor.dateTime()
            
            elif str(editor.__class__) == "<class 'PyQt4.QtGui.QLineEdit'>":
                newValue = editor.text()

            
            self.table.setCursor(Qt.WaitCursor)
            self.table.resource.addProperty(predicateUrl, Nepomuk.Variant(newValue))
            self.table.resource.removeProperty(predicateUrl, Nepomuk.Variant(value))
            self.table.unsetCursor()
            #here we need to update the model since it won't get updated by signal emission
            index.model().sourceModel().data[sindex.row()] = (predicateUrl, Nepomuk.Variant(newValue))
    def updateRangeLiteral(self):
        #save the resource to create it if it doesn't exist yet
        if not self.resource:
            self.save()

        idx = self.ui.literalBox.currentIndex()
        data = self.ui.literalBox.itemData(idx)
        literalTypeUri = QUrl(data.toString())
        self.mainWindow.setCursor(Qt.WaitCursor)
        self.resource.setProperty(Soprano.Vocabulary.RDFS.range(),
                                  Nepomuk.Variant(literalTypeUri))
        self.ui.updateFields()
        self.mainWindow.unsetCursor()
Exemple #10
0
    def save(self):

        #TODO: validate that name trimmed is not empty
        super(TaskEditor, self).save()

        priority = TMO.TMO_Instance_Priority_Medium
        if self.ui.lowPriority.isChecked():
            priority = TMO.TMO_Instance_Priority_Low
        elif self.ui.highPriority.isChecked():
            priority = TMO.TMO_Instance_Priority_High

        state = TMO.TMO_Instance_TaskState_New
        if self.ui.stateRunning.isChecked():
            state = TMO.TMO_Instance_TaskState_Running
        elif self.ui.stateCompleted.isChecked():
            state = TMO.TMO_Instance_TaskState_Completed

        dueDate = None
        if self.ui.dateBox.isChecked():
            dueDate = self.ui.dueDate.date()

        self.resource.setLabel(self.ui.label.text())
        self.resource.setProperty(TMO.priority, Nepomuk.Variant(priority))
        self.resource.setProperty(TMO.taskState, Nepomuk.Variant(state))
        if dueDate:
            self.resource.setProperty(TMO.dueDate, Nepomuk.Variant(dueDate))
        else:
            self.resource.removeProperty(TMO.dueDate)

        if self.superTask is not None:
            self.resource.removeProperty(TMO.superTask)
            self.resource.setProperty(TMO.superTask,
                                      Nepomuk.Variant(self.superTask))
            self.mainWindow.emit(SIGNAL('taskHierarchyUpdated'))
        else:
            #TODO: distinguish between the old and the new task attributes
            self.resource.removeProperty(TMO.superTask)
            self.mainWindow.emit(SIGNAL('taskHierarchyUpdated'))
Exemple #11
0
def findRelateds(uri):

    resource = Nepomuk.Resource(uri)
    related = set(resource.isRelateds())
    relatedInverse = set(resource.isRelatedOf())

    pimoRelated = resource.property(PIMO.isRelated)
    urls = pimoRelated.toUrlList()
    for elt in urls:
        related.add(Nepomuk.Resource(elt))

    pimoRelatedInverse = Nepomuk.ResourceManager.instance(
    ).allResourcesWithProperty(PIMO.isRelated, Nepomuk.Variant(resource))
    relations = related.union(relatedInverse).union(pimoRelatedInverse)

    return relations
Exemple #12
0
def scrap():

    labelTerm = Nepomuk.Query.ComparisonTerm(
        Nepomuk.Types.Property(Soprano.Vocabulary.NAO.prefLabel()),
        Nepomuk.Query.LiteralTerm(Soprano.LiteralValue("Alex")),
        Nepomuk.Query.ComparisonTerm.Contains)
    labelTerm.setVariableName("label")
    #query = Nepomuk.Query.Query(labelTerm)

    nepomukType = Nepomuk.Types.Class(NCO.Contact)
    typeTerm = Nepomuk.Query.ResourceTypeTerm(nepomukType)
    query = Nepomuk.Query.Query(typeTerm)

    data = findResources(query.toSparqlQuery())
    for elt in data:
        elt.addProperty(Soprano.Vocabulary.RDF.type(),
                        Nepomuk.Variant(NCO.PersonContact))
Exemple #13
0
    def updateRangeType(self):
        #save the resource to create it if it doesn't exist yet
        if not self.resource:
            self.save()

        rangeUrl = QUrl(
            self.resource.property(Soprano.Vocabulary.RDFS.range()).toString())

        #TODO: only one type should be possible (check)
        dialog = TypeChooserDialog(mainWindow=self.mainWindow,
                                   typesUris=[rangeUrl])
        if dialog.exec_():
            chosenTypes = dialog.chosenTypes()

            if len(chosenTypes) == 1:
                self.setCursor(Qt.WaitCursor)
                range = chosenTypes[0]
                self.resource.setProperty(Soprano.Vocabulary.RDFS.range(),
                                          Nepomuk.Variant(range.resourceUri()))
                self.ui.updateFields()
                self.unsetCursor()
Exemple #14
0
    def updateDomain(self):
        #save the resource to create it if it doesn't exist yet
        if not self.resource:
            self.save()

        domainUrl = QUrl(
            self.resource.property(
                Soprano.Vocabulary.RDFS.domain()).toString())

        dialog = TypeChooserDialog(mainWindow=self.mainWindow,
                                   typesUris=[domainUrl])
        if dialog.exec_():
            chosenTypes = dialog.chosenTypes()

            if len(chosenTypes) == 1:

                self.setCursor(Qt.WaitCursor)
                domain = chosenTypes[0]
                self.resource.setProperty(
                    Soprano.Vocabulary.RDFS.domain(),
                    Nepomuk.Variant(domain.resourceUri()))
                self.ui.updateFields()
                self.unsetCursor()
Exemple #15
0
    def save(self):
        self.setCursor(Qt.WaitCursor)
        if self.resource is None:
            self.resource = self.mainWindow.createResource(self.ui.resourceLabel(), self.nepomukType)
        
        else:
            #TODO: remove an editor when the edited resource was deleted externally
            if len(self.resource.types()) == 0:
                self.resource = self.mainWindow.createResource(self.ui.resourceLabel(), self.nepomukType)      
        

        self.ui.relationsTable.setResource(self.resource)
        self.ui.propsTable.setResource(self.resource)
        
        if hasattr(self.ui, "typePropertiesTable"):
            self.ui.typePropertiesTable.setResource(self.resource)
        
        
#        #save generic properties
        self.resource.setLabel(unicode(self.ui.resourceLabel()))
        
        desc = unicode(self.ui.description.toHtml())
        
        self.resource.setDescription(desc)
        if hasattr(self.ui, "url"):
            self.resource.setProperty(NIE.url, Nepomuk.Variant(QUrl(unicode(self.ui.url.text()))))
        
        #TODO: catch Except and print warning
        #reply = QMessageBox.warning(self, i18n("Warning", ), i18n("An error ocurred when saving the resource. You should copy and paste this resource's contents to a distinct editor. Please report a bug."))

        #update the fields only if we are not in a sbuclass, otherwise, the fields get updated
        #before their actual value are saved (see the contacteditor for instance)
        if self.__class__ == getClass("ginkgo.editors.resourceeditor.ResourceEditor"):
            self.ui.updateFields()
        
        self.unsetCursor()
Exemple #16
0
 def processAction(self, key, selectedResources):
     super(SuggestionsTable, self).processAction(key, selectedResources)
     if key == CREATE_RELATION:
         for resource in selectedResources:
             self.resource.addProperty(Soprano.Vocabulary.NAO.isRelated(), Nepomuk.Variant(resource))
             self.removeResource(resource.resourceUri())