Skip to content

Commit 37c041e

Browse files
OwLouvain: Display number of cluster in UI
1 parent b20aa02 commit 37c041e

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Orange/widgets/unsupervised/owlouvainclustering.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from AnyQt.QtCore import (
1313
Qt, QObject, QTimer, pyqtSignal as Signal, pyqtSlot as Slot
1414
)
15-
from AnyQt.QtWidgets import QSlider, QCheckBox, QWidget
15+
from AnyQt.QtWidgets import QSlider, QCheckBox, QWidget, QLabel
1616

1717
from Orange.clustering.louvain import table_to_knn_graph, Louvain
1818
from Orange.data import Table, DiscreteVariable
@@ -98,6 +98,10 @@ def __init__(self):
9898
self.__commit_timer = QTimer(self, singleShot=True)
9999
self.__commit_timer.timeout.connect(self.commit)
100100

101+
# Set up UI
102+
info_box = gui.vBox(self.controlArea, "Info")
103+
self.info_label = gui.widgetLabel(info_box, "No data on input.") # type: QLabel
104+
101105
pca_box = gui.vBox(self.controlArea, "PCA Preprocessing")
102106
self.apply_pca_cbx = gui.checkBox(
103107
pca_box, self, "apply_pca", label="Apply PCA preprocessing",
@@ -248,6 +252,7 @@ def commit(self):
248252
run_on_graph, graph, resolution=self.resolution, state=state
249253
)
250254

255+
self.info_label.setText("Running...")
251256
self.__set_state_busy()
252257
self.__start_task(task, state)
253258

@@ -282,6 +287,7 @@ def __on_done(self, future):
282287
result = future.result()
283288
except Exception as err: # pylint: disable=broad-except
284289
self.Error.general_error(str(err), exc_info=True)
290+
self.info_label.setText("An error occurred during clustering.")
285291
else:
286292
self.__set_results(result)
287293

@@ -346,6 +352,11 @@ def __set_results(self, results):
346352
assert results.resolution == self.resolution
347353
assert self.partition is results.partition
348354
self.partition = results.partition
355+
356+
# Display the number of found clusters in the UI
357+
num_clusters = len(np.unique(self.partition))
358+
self.info_label.setText("%d clusters found." % num_clusters)
359+
349360
self._send_data()
350361

351362
def _send_data(self):
@@ -406,6 +417,8 @@ def set_data(self, data):
406417
self.k_neighbors_spin.setMaximum(min(_MAX_K_NEIGBOURS, len(data) - 1))
407418
self.k_neighbors_spin.setValue(min(_DEFAULT_K_NEIGHBORS, len(data) - 1))
408419

420+
self.info_label.setText("Clustering not yet run.")
421+
409422
self.commit()
410423

411424
def clear(self):
@@ -416,6 +429,7 @@ def clear(self):
416429
self.partition = None
417430
self.Error.clear()
418431
self.Information.modified.clear()
432+
self.info_label.setText("No data on input.")
419433

420434
def onDeleteWidget(self):
421435
self.__cancel_task(wait=True)

0 commit comments

Comments
 (0)