From 37c041ecaa986d804f57d86b65fd8a3da3070813 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavlin=20Poli=C4=8Dar?= Date: Sat, 2 Feb 2019 10:07:19 +0100 Subject: [PATCH] OwLouvain: Display number of cluster in UI --- .../widgets/unsupervised/owlouvainclustering.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Orange/widgets/unsupervised/owlouvainclustering.py b/Orange/widgets/unsupervised/owlouvainclustering.py index 8af6dd1165c..ce62c3a98e6 100644 --- a/Orange/widgets/unsupervised/owlouvainclustering.py +++ b/Orange/widgets/unsupervised/owlouvainclustering.py @@ -12,7 +12,7 @@ from AnyQt.QtCore import ( Qt, QObject, QTimer, pyqtSignal as Signal, pyqtSlot as Slot ) -from AnyQt.QtWidgets import QSlider, QCheckBox, QWidget +from AnyQt.QtWidgets import QSlider, QCheckBox, QWidget, QLabel from Orange.clustering.louvain import table_to_knn_graph, Louvain from Orange.data import Table, DiscreteVariable @@ -98,6 +98,10 @@ def __init__(self): self.__commit_timer = QTimer(self, singleShot=True) self.__commit_timer.timeout.connect(self.commit) + # Set up UI + info_box = gui.vBox(self.controlArea, "Info") + self.info_label = gui.widgetLabel(info_box, "No data on input.") # type: QLabel + pca_box = gui.vBox(self.controlArea, "PCA Preprocessing") self.apply_pca_cbx = gui.checkBox( pca_box, self, "apply_pca", label="Apply PCA preprocessing", @@ -248,6 +252,7 @@ def commit(self): run_on_graph, graph, resolution=self.resolution, state=state ) + self.info_label.setText("Running...") self.__set_state_busy() self.__start_task(task, state) @@ -282,6 +287,7 @@ def __on_done(self, future): result = future.result() except Exception as err: # pylint: disable=broad-except self.Error.general_error(str(err), exc_info=True) + self.info_label.setText("An error occurred during clustering.") else: self.__set_results(result) @@ -346,6 +352,11 @@ def __set_results(self, results): assert results.resolution == self.resolution assert self.partition is results.partition self.partition = results.partition + + # Display the number of found clusters in the UI + num_clusters = len(np.unique(self.partition)) + self.info_label.setText("%d clusters found." % num_clusters) + self._send_data() def _send_data(self): @@ -406,6 +417,8 @@ def set_data(self, data): self.k_neighbors_spin.setMaximum(min(_MAX_K_NEIGBOURS, len(data) - 1)) self.k_neighbors_spin.setValue(min(_DEFAULT_K_NEIGHBORS, len(data) - 1)) + self.info_label.setText("Clustering not yet run.") + self.commit() def clear(self): @@ -416,6 +429,7 @@ def clear(self): self.partition = None self.Error.clear() self.Information.modified.clear() + self.info_label.setText("No data on input.") def onDeleteWidget(self): self.__cancel_task(wait=True)