Skip to content

Commit

Permalink
add context handler
Browse files Browse the repository at this point in the history
  • Loading branch information
noahnovsak committed Jan 25, 2023
1 parent 583c540 commit e194f30
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion Orange/widgets/unsupervised/owkmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from Orange.preprocess import Normalize
from Orange.preprocess.impute import ReplaceUnknowns
from Orange.widgets import widget, gui
from Orange.widgets.settings import Setting, ContextSetting
from Orange.widgets.settings import Setting, ContextSetting, ContextHandler
from Orange.widgets.utils.annotated_data import \
ANNOTATED_DATA_SIGNAL_NAME, add_columns
from Orange.widgets.utils.concurrent import ThreadExecutor, FutureSetWatcher
Expand Down Expand Up @@ -99,6 +99,18 @@ class NotEnoughData(ValueError):
pass


class TableTypeContextHandler(ContextHandler):
def new_context(self, tabletype):
context = super().new_context()
context.tabletype = tabletype
return context

def match(self, context, tabletype):
if context.tabletype == tabletype:
return self.MATCH
return self.NO_MATCH


class OWKMeans(widget.OWWidget):
name = "k-Means"
description = "k-Means clustering algorithm with silhouette-based " \
Expand Down Expand Up @@ -140,6 +152,7 @@ class Warning(widget.OWWidget.Warning):

resizing_enabled = False

settingsHandler = TableTypeContextHandler()
k = Setting(3)
k_from = Setting(2)
k_to = Setting(8)
Expand Down Expand Up @@ -589,6 +602,7 @@ def send_data(self):
@Inputs.data
@check_sql_input
def set_data(self, data):
self.closeContext()
self.data, old_data = data, self.data
self.selection = None
self.controls.normalize.setDisabled(
Expand All @@ -611,6 +625,7 @@ def set_data(self, data):
self.send_data()
else:
self.invalidate(unconditional=True)
self.openContext(str(type(data)))

def send_report(self):
# False positives (Setting is not recognized as int)
Expand Down

0 comments on commit e194f30

Please sign in to comment.