def setupScene(self): self.information(0) self.error(0) if self.data: attr = self.stringAttrs[self.imageAttr] titleAttr = self.allAttrs[self.titleAttr] instances = [inst for inst in self.data if numpy.isfinite(inst[attr])] widget = ThumbnailWidget() layout = widget.layout() size = QSizeF(self.imageSize, self.imageSize) self.scene.addItem(widget) for i, inst in enumerate(instances): url = self.urlFromValue(inst[attr]) title = str(inst[titleAttr]) thumbnail = GraphicsThumbnailWidget( QPixmap(), title=title, parent=widget ) thumbnail.setThumbnailSize(size) thumbnail.setToolTip(url.toString()) thumbnail.instance = inst layout.addItem(thumbnail, i / 5, i % 5) if url.isValid(): future = self.loader.get(url) @future.add_done_callback def set_pixmap(future, thumb=thumbnail): if future.cancelled(): return assert future.done() if future.exception(): # Should be some generic error image. pixmap = QPixmap() thumb.setToolTip(thumb.toolTip() + "\n" + str(future.exception())) else: pixmap = QPixmap.fromImage(future.result()) thumb.setPixmap(pixmap) self._updateStatus(future) else: future = None self.items.append(_ImageItem(i, thumbnail, url, future)) widget.show() widget.geometryChanged.connect(self._updateSceneRect) self.info.setText("Retrieving...\n") self.thumbnailWidget = widget self.sceneLayout = layout if self.sceneLayout: self._updateGeometryConstraints()
def set_mark_mode(self, mode=None): if mode is not None: self.mark_mode = mode for i, (_, widget, _) in enumerate(self.mark_criteria): if widget: if i == self.mark_mode: widget.show() else: widget.hide() self.searchStringTimer.stop() self.update_marks()
self.is_preprocessed = '' self.is_pos_tagged = '' self.ngram_range = '' def commit(self): if self.corpus is not None: matched = self.corpus[self.output_mask] output_mask = set(self.output_mask) unmatched_mask = [ i for i in range(len(self.corpus)) if i not in output_mask ] unmatched = self.corpus[unmatched_mask] self.Outputs.matching_docs.send(matched) self.Outputs.other_docs.send(unmatched) else: self.Outputs.matching_docs.send(None) self.Outputs.other_docs.send(None) if __name__ == '__main__': from orangecontrib.text.tag import pos_tagger app = QApplication([]) widget = OWCorpusViewer() widget.show() corpus = Corpus.from_file('book-excerpts') corpus = corpus[:3] corpus = pos_tagger.tag_corpus(corpus) corpus.ngram_range = (1, 2) widget.set_data(corpus) app.exec()
def setupScene(self): self.information(0) self.error(0) if self.data: attr = self.stringAttrs[self.imageAttr] titleAttr = self.allAttrs[self.titleAttr] instances = [ inst for inst in self.data if numpy.isfinite(inst[attr]) ] widget = ThumbnailWidget() layout = widget.layout() self.scene.addItem(widget) for i, inst in enumerate(instances): url = self.urlFromValue(inst[attr]) title = str(inst[titleAttr]) thumbnail = GraphicsThumbnailWidget(QPixmap(), title=title, parent=widget) thumbnail.setToolTip(url.toString()) thumbnail.instance = inst layout.addItem(thumbnail, i / 5, i % 5) if url.isValid(): future = self.loader.get(url) watcher = _FutureWatcher(parent=thumbnail) # watcher = FutureWatcher(future, parent=thumbnail) def set_pixmap(thumb=thumbnail, future=future): if future.cancelled(): return if future.exception(): # Should be some generic error image. pixmap = QPixmap() thumb.setToolTip(thumb.toolTip() + "\n" + str(future.exception())) else: pixmap = QPixmap.fromImage(future.result()) thumb.setPixmap(pixmap) if not pixmap.isNull(): thumb.setThumbnailSize(self.pixmapSize(pixmap)) self._updateStatus(future) watcher.finished.connect(set_pixmap, Qt.QueuedConnection) watcher.setFuture(future) else: future = None self.items.append(_ImageItem(i, thumbnail, url, future)) widget.show() widget.geometryChanged.connect(self._updateSceneRect) self.info.setText("Retrieving...\n") self.thumbnailWidget = widget self.sceneLayout = layout if self.sceneLayout: width = (self.sceneView.width() - self.sceneView.verticalScrollBar().width()) self.thumbnailWidget.reflow(width) self.thumbnailWidget.setPreferredWidth(width) self.sceneLayout.activate()
if result is not None and len(result.dictionary) == 0: self.Warning.no_token_left() result = None self.send(Output.PP_CORPUS, result) self.progressBarFinished(None) def set_minimal_width(self): max_width = 250 for widget in self.stages: if widget.enabled: max_width = max(max_width, widget.sizeHint().width()) self.scroll.setMinimumWidth(max_width + 20) @pyqtSlot() def settings_invalidated(self): self.set_minimal_width() self.commit() def send_report(self): self.report_items('Preprocessor', self.preprocessor.report()) if __name__ == '__main__': app = QApplication([]) widget = OWPreprocess() widget.show() corpus = Corpus.from_file('bookexcerpts') widget.set_data(corpus) app.exec() widget.saveSettings()
def setupScene(self): self.information(0) self.error(0) if self.data: attr = self.stringAttrs[self.imageAttr] titleAttr = self.allAttrs[self.titleAttr] instances = [inst for inst in self.data if numpy.isfinite(inst[attr])] widget = ThumbnailWidget() layout = widget.layout() self.scene.addItem(widget) for i, inst in enumerate(instances): url = self.urlFromValue(inst[attr]) title = str(inst[titleAttr]) thumbnail = GraphicsThumbnailWidget( QPixmap(), title=title, parent=widget ) thumbnail.setToolTip(url.toString()) thumbnail.instance = inst layout.addItem(thumbnail, i / 5, i % 5) if url.isValid(): future = self.loader.get(url) watcher = _FutureWatcher(parent=thumbnail) # watcher = FutureWatcher(future, parent=thumbnail) def set_pixmap(thumb=thumbnail, future=future): if future.cancelled(): return if future.exception(): # Should be some generic error image. pixmap = QPixmap() thumb.setToolTip(thumb.toolTip() + "\n" + str(future.exception())) else: pixmap = QPixmap.fromImage(future.result()) thumb.setPixmap(pixmap) if not pixmap.isNull(): thumb.setThumbnailSize(self.pixmapSize(pixmap)) self._updateStatus(future) watcher.finished.connect(set_pixmap, Qt.QueuedConnection) watcher.setFuture(future) else: future = None self.items.append(_ImageItem(i, thumbnail, url, future)) widget.show() widget.geometryChanged.connect(self._updateSceneRect) self.info.setText("Retrieving...\n") self.thumbnailWidget = widget self.sceneLayout = layout if self.sceneLayout: width = (self.sceneView.width() - self.sceneView.verticalScrollBar().width()) self.thumbnailWidget.reflow(width) self.thumbnailWidget.setPreferredWidth(width) self.sceneLayout.activate()