def executeInlineQuery(self): cursor = self.ui.description.textCursor() selection = cursor.selectedText() #Note: If the selection obtained from an editor spans a line break, the text will contain a #Unicode U+2029 paragraph separator character instead of a newline \n character. #Use QString::replace() to replace these characters with newlines. sparqlViewTabIndex = -1 for index in range(self.ui.relationsWidget.count()): tab = self.ui.relationsWidget.widget(index) if tab.__class__ == getClass("ginkgo.views.sparqlview.SparqlResultsTable"): sparqlViewTabIndex = index break if sparqlViewTabIndex < 0: self.sparqlView = SparqlResultsTable(mainWindow=self.mainWindow, sparql=selection) self.ui.relationsWidget.addTab(self.sparqlView , i18n("Query results")) self.ui.relationsWidget.setCurrentWidget(self.sparqlView) else: self.sparqlView.setSparql(selection) self.sparqlView.installModels() self.ui.relationsWidget.setCurrentIndex(sparqlViewTabIndex)
class ResourceEditor(QWidget): def __init__(self, mainWindow=False, resource=None, nepomukType=None): super(ResourceEditor, self).__init__() self.mainWindow = mainWindow self.defaultIcon = ":/nepomuk-large" self.resource = resource self.nepomukType = nepomukType # print self.__class__ # print ResourceEditor.__class__ if self.__class__ == getClass("ginkgo.editors.resourceeditor.ResourceEditor"): self.ui = ResourceEditorUi(self) def resourceIcon(self): if self.resource: return self.mainWindow.resourceIcon(self.resource, 64) elif self.nepomukType: return self.mainWindow.typeIcon(self.nepomukType, 64) else: return KIcon(self.defaultIcon) def selectIcon(self): path = QFileInfo("~/").path() fname = QFileDialog.getOpenFileName(self, i18n("Select Icon - Ginkgo"), path, i18n("Images (*.png *.jpg *.jpeg *.bmp)")) if fname and len(fname) > 0 and os.path.exists(fname): #save the resource to create it if it doesn't exist yet if not self.resource: self.save() self.resource.setSymbols([fname]) self.ui.iconButton.setIcon(KIcon(fname)) 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() def focus(self): self.ui.label.setFocus(Qt.OtherFocusReason) def focusOnLabelField(self): self.ui.label.setFocus(Qt.OtherFocusReason) self.ui.label.selectAll() def showResourceTypesDialog(self): #save the resource to create it if it doesn't exist yet if not self.resource: self.save() dialog = TypeChooserDialog(mainWindow=self.mainWindow, typesUris=self.resource.types()) if dialog.exec_(): chosenTypes = dialog.chosenTypes() types = [] for type in chosenTypes: types.append(type.resourceUri()) self.resource.setTypes(types) self.ui.updateFields() def executeInlineQuery(self): cursor = self.ui.description.textCursor() selection = cursor.selectedText() #Note: If the selection obtained from an editor spans a line break, the text will contain a #Unicode U+2029 paragraph separator character instead of a newline \n character. #Use QString::replace() to replace these characters with newlines. sparqlViewTabIndex = -1 for index in range(self.ui.relationsWidget.count()): tab = self.ui.relationsWidget.widget(index) if tab.__class__ == getClass("ginkgo.views.sparqlview.SparqlResultsTable"): sparqlViewTabIndex = index break if sparqlViewTabIndex < 0: self.sparqlView = SparqlResultsTable(mainWindow=self.mainWindow, sparql=selection) self.ui.relationsWidget.addTab(self.sparqlView , i18n("Query results")) self.ui.relationsWidget.setCurrentWidget(self.sparqlView) else: self.sparqlView.setSparql(selection) self.sparqlView.installModels() self.ui.relationsWidget.setCurrentIndex(sparqlViewTabIndex) def suggestRelations(self): suggestionViewTabIndex = -1 text = u"%s" % self.ui.description.toPlainText() title = u"%s" % self.ui.label.text() for index in range(self.ui.relationsWidget.count()): tab = self.ui.relationsWidget.widget(index) if tab.__class__ == getClass("ginkgo.views.suggestionview.SuggestionsTable"): suggestionViewTabIndex = index break if suggestionViewTabIndex < 0: self.suggestionView = SuggestionsTable(mainWindow=self.mainWindow, editor=self.ui.description, resource=self.resource, title=title, text=text) self.ui.relationsWidget.addTab(self.suggestionView , i18n("Suggestions")) self.ui.relationsWidget.setCurrentWidget(self.suggestionView) self.suggestionView.runAnalyzis() else: self.suggestionView.setText(text) self.suggestionView.installModels() self.ui.relationsWidget.setCurrentIndex(suggestionViewTabIndex) self.suggestionView.runAnalyzis()