Skip to content

Commit

Permalink
Use automated summaries
Browse files Browse the repository at this point in the history
  • Loading branch information
janezd committed Mar 6, 2021
1 parent 9e07e90 commit e2d90dc
Show file tree
Hide file tree
Showing 63 changed files with 4 additions and 814 deletions.
9 changes: 0 additions & 9 deletions Orange/widgets/data/owcolor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from Orange.widgets.gui import HorizontalGridDelegate
from Orange.widgets.utils import itemmodels, colorpalettes
from Orange.widgets.utils.widgetpreview import WidgetPreview
from Orange.widgets.utils.state_summary import format_summary_details
from Orange.widgets.report import colored_square as square
from Orange.widgets.widget import Input, Output

Expand Down Expand Up @@ -580,9 +579,6 @@ def __init__(self):
gui.rubber(self.buttonsArea)
gui.auto_apply(self.buttonsArea, self, "auto_apply")

self.info.set_input_summary(self.info.NoInput)
self.info.set_output_summary(self.info.NoOutput)

@staticmethod
def sizeHint(): # pragma: no cover
return QSize(500, 570)
Expand All @@ -594,10 +590,8 @@ def set_data(self, data):
self.cont_descs = []
if data is None:
self.data = self.domain = None
self.info.set_input_summary(self.info.NoInput)
else:
self.data = data
self.info.set_input_summary(len(data), format_summary_details(data))
for var in chain(data.domain.variables, data.domain.metas):
if var.is_discrete:
self.disc_descs.append(DiscAttrDesc(var))
Expand Down Expand Up @@ -738,7 +732,6 @@ def make(variables):

if self.data is None:
self.Outputs.data.send(None)
self.info.set_output_summary(self.info.NoOutput)
return

disc_dict = {desc.var.name: desc for desc in self.disc_descs}
Expand All @@ -748,8 +741,6 @@ def make(variables):
new_domain = Orange.data.Domain(
make(dom.attributes), make(dom.class_vars), make(dom.metas))
new_data = self.data.transform(new_domain)
self.info.set_output_summary(len(new_data),
format_summary_details(new_data))
self.Outputs.data.send(new_data)

def send_report(self):
Expand Down
24 changes: 0 additions & 24 deletions Orange/widgets/data/owconcatenate.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
from Orange.widgets.utils.annotated_data import add_columns
from Orange.widgets.utils.sql import check_sql_input
from Orange.widgets.utils.widgetpreview import WidgetPreview
from Orange.widgets.utils.state_summary import format_summary_details, \
format_multiple_summaries
from Orange.widgets.widget import Input, Output, Msg


Expand Down Expand Up @@ -145,9 +143,6 @@ def __init__(self):
gui.comboBox(ibox, self, "source_column_role", items=self.id_roles,
callback=self._source_changed))

self.info.set_input_summary(self.info.NoInput)
self.info.set_output_summary(self.info.NoOutput)

ibox.layout().addLayout(form)
mleft, mtop, mright, _ = ibox.layout().getContentsMargins()
ibox.layout().setContentsMargins(mleft, mtop, mright, 4)
Expand All @@ -170,25 +165,8 @@ def set_more_data(self, data=None, sig_id=None):
elif sig_id in self.more_data:
del self.more_data[sig_id]

def _set_input_summary(self):
more_data = list(self.more_data.values()) if self.more_data else [None]
n_primary = len(self.primary_data) if self.primary_data else 0
n_more_data = [len(data) if data else 0 for data in more_data]

summary, details, kwargs = self.info.NoInput, "", {}
if self.primary_data or self.more_data:
summary = f"{self.info.format_number(n_primary)}, " \
+ ", ".join(self.info.format_number(i) for i in n_more_data)
details = format_multiple_summaries(
[("Primary data", self.primary_data)]
+ [("", data) for data in more_data]
)
kwargs = {"format": Qt.RichText}
self.info.set_input_summary(summary, details, **kwargs)

def handleNewSignals(self):
self.mergebox.setDisabled(self.primary_data is not None)
self._set_input_summary()
if self.incompatible_types():
self.Error.bow_concatenation()
else:
Expand Down Expand Up @@ -242,10 +220,8 @@ def apply(self):
source_ids = np.array(list(flatten(
[i] * len(table) for i, table in enumerate(tables)))).reshape((-1, 1))
data[:, source_var] = source_ids
self.info.set_output_summary(len(data), format_summary_details(data))
else:
data = None
self.info.set_output_summary(self.info.NoOutput)

self.Outputs.data.send(data)

Expand Down
9 changes: 0 additions & 9 deletions Orange/widgets/data/owcontinuize.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from Orange.widgets.settings import Setting
from Orange.widgets.utils.sql import check_sql_input
from Orange.widgets.utils.widgetpreview import WidgetPreview
from Orange.widgets.utils.state_summary import format_summary_details
from Orange.widgets.widget import Input, Output


Expand Down Expand Up @@ -98,8 +97,6 @@ def __init__(self):
gui.auto_apply(self.buttonsArea, self, "autosend")

self.data = None
self.info.set_input_summary(self.info.NoInput)
self.info.set_output_summary(self.info.NoOutput)

def settings_changed(self):
self.commit()
Expand All @@ -110,12 +107,8 @@ def setData(self, data):
self.data = data
self.enable_normalization()
if data is None:
self.info.set_input_summary(self.info.NoInput)
self.info.set_output_summary(self.info.NoOutput)
self.Outputs.data.send(None)
else:
self.info.set_input_summary(len(data),
format_summary_details(data))
self.unconditional_commit()

def enable_normalization(self):
Expand Down Expand Up @@ -146,8 +139,6 @@ def commit(self):
domain = continuizer(self.data)
data = self.data.transform(domain)
self.Outputs.data.send(data)
self.info.set_output_summary(len(data),
format_summary_details(data))
else:
self.Outputs.data.send(self.data) # None or empty data

Expand Down
11 changes: 0 additions & 11 deletions Orange/widgets/data/owcorrelations.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from Orange.widgets.utils.itemmodels import DomainModel
from Orange.widgets.utils.signals import Input, Output
from Orange.widgets.utils.widgetpreview import WidgetPreview
from Orange.widgets.utils.state_summary import format_summary_details
from Orange.widgets.visualize.utils import VizRankDialogAttrPair
from Orange.widgets.widget import OWWidget, AttributeList, Msg

Expand Down Expand Up @@ -297,9 +296,6 @@ def __init__(self):
button_box = gui.hBox(self.buttonsArea)
button_box.layout().addWidget(self.vizrank.button)

self.info.set_input_summary(self.info.NoInput)
self.info.set_output_summary(self.info.NoOutput)

@staticmethod
def sizeHint():
return QSize(350, 400)
Expand Down Expand Up @@ -366,10 +362,6 @@ def set_data(self, data):
self.Warning.not_enough_vars()
else:
self.cont_data = SklImpute()(cont_data)
self.info.set_input_summary(len(data),
format_summary_details(data))
else:
self.info.set_input_summary(self.info.NoInput)
self.set_feature_model()
self.openContext(self.cont_data)
self.apply()
Expand All @@ -393,9 +385,6 @@ def apply(self):

def commit(self):
self.Outputs.data.send(self.data)
summary = len(self.data) if self.data else self.info.NoOutput
details = format_summary_details(self.data) if self.data else ""
self.info.set_output_summary(summary, details)

if self.data is None or self.cont_data is None:
self.Outputs.features.send(None)
Expand Down
13 changes: 0 additions & 13 deletions Orange/widgets/data/owcreateclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from Orange.widgets.settings import DomainContextHandler, ContextSetting
from Orange.widgets.utils.itemmodels import DomainModel
from Orange.widgets.utils.widgetpreview import WidgetPreview
from Orange.widgets.utils.state_summary import format_summary_details
from Orange.widgets.widget import Msg, Input, Output


Expand Down Expand Up @@ -269,9 +268,6 @@ def __init__(self):

gui.button(self.buttonsArea, self, "Apply", callback=self.apply)

self.info.set_input_summary(self.info.NoInput)
self.info.set_output_summary(self.info.NoOutput)

# TODO: Resizing upon changing the number of rules does not work
self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Maximum)

Expand All @@ -297,16 +293,12 @@ def set_data(self, data):
self.closeContext()
self.rules = {}
self.data = data
summary = len(data) if data else self.info.NoInput
details = format_summary_details(data) if data else ""
self.info.set_input_summary(summary, details)
model = self.controls.attribute.model()
model.set_domain(data and data.domain)
self.Warning.no_nonnumeric_vars(shown=data is not None and not model)
if not model:
self.attribute = None
self.Outputs.data.send(None)
self.info.set_output_summary(self.info.NoOutput)
return
self.attribute = model[0]
self.openContext(data)
Expand Down Expand Up @@ -513,7 +505,6 @@ def apply(self):
self.class_name = self.class_name.strip()
if not self.attribute:
self.Outputs.data.send(None)
self.info.set_output_summary(self.info.NoOutput)
return
domain = self.data.domain
if not self.class_name:
Expand All @@ -522,15 +513,11 @@ def apply(self):
self.Error.class_name_duplicated()
if not self.class_name or self.class_name in domain:
self.Outputs.data.send(None)
self.info.set_output_summary(self.info.NoOutput)
return
new_class = self._create_variable()
new_domain = Domain(
domain.attributes, new_class, domain.metas + domain.class_vars)
new_data = self.data.transform(new_domain)
summary = len(new_data) if new_data is not None else self.info.NoOutput
details = format_summary_details(new_data) if new_data is not None else ""
self.info.set_output_summary(summary, details)
self.Outputs.data.send(new_data)

def _create_variable(self):
Expand Down
27 changes: 0 additions & 27 deletions Orange/widgets/data/owcreateinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
from Orange.widgets import gui
from Orange.widgets.utils.itemmodels import TableModel
from Orange.widgets.settings import Setting
from Orange.widgets.utils.state_summary import format_summary_details, \
format_multiple_summaries
from Orange.widgets.utils.widgetpreview import WidgetPreview
from Orange.widgets.widget import OWWidget, Input, Output, Msg

Expand Down Expand Up @@ -527,8 +525,6 @@ def __init__(self):
gui.rubber(self.buttonsArea)
box = gui.auto_apply(self.buttonsArea, self, "auto_commit")

self._set_input_summary()
self._set_output_summary()
self.settingsAboutToBePacked.connect(self.pack_settings)

def __filter_edit_changed(self):
Expand Down Expand Up @@ -604,7 +600,6 @@ def _initialize_values(self, fun: str, indices: List[QModelIndex] = None):
@Inputs.data
def set_data(self, data: Table):
self.data = data
self._set_input_summary()
self._set_model_data()
self.unconditional_commit()

Expand All @@ -624,35 +619,13 @@ def _set_model_data(self):
@Inputs.reference
def set_reference(self, data: Table):
self.reference = data
self._set_input_summary()

def _set_input_summary(self):
n_data = len(self.data) if self.data else 0
n_refs = len(self.reference) if self.reference else 0
summary, details, kwargs = self.info.NoInput, "", {}

if self.data or self.reference:
summary = f"{self.info.format_number(n_data)}, " \
f"{self.info.format_number(n_refs)}"
data_list = [("Data", self.data), ("Reference", self.reference)]
details = format_multiple_summaries(data_list)
kwargs = {"format": Qt.RichText}
self.info.set_input_summary(summary, details, **kwargs)

def _set_output_summary(self, data: Optional[Table] = None):
if data:
summary, details = len(data), format_summary_details(data)
else:
summary, details = self.info.NoOutput, ""
self.info.set_output_summary(summary, details)

def commit(self):
output_data = None
if self.data:
output_data = self._create_data_from_values()
if self.append_to_data:
output_data = self._append_to_data(output_data)
self._set_output_summary(output_data)
self.Outputs.data.send(output_data)

def _create_data_from_values(self) -> Table:
Expand Down
6 changes: 0 additions & 6 deletions Orange/widgets/data/owcsvimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
from Orange.widgets.utils.settings import (
QSettings_readArray, QSettings_writeArray
)
from Orange.widgets.utils.state_summary import format_summary_details

if typing.TYPE_CHECKING:
# pylint: disable=invalid-name
Expand Down Expand Up @@ -714,8 +713,6 @@ def __init__(self, *args, **kwargs):
self.summary_text.viewport().setAutoFillBackground(False)
box.layout().addWidget(self.summary_text)

self.info.set_output_summary(self.info.NoOutput)

button_box = QDialogButtonBox(
orientation=Qt.Horizontal,
standardButtons=QDialogButtonBox.Cancel | QDialogButtonBox.Retry
Expand Down Expand Up @@ -1221,9 +1218,6 @@ def __handle_result(self, f):
self._update_status_messages(table)

def _update_status_messages(self, data):
summary = len(data) if data else self.info.NoOutput
details = format_summary_details(data) if data else ""
self.info.set_output_summary(summary, details)
if data is None:
return

Expand Down
6 changes: 0 additions & 6 deletions Orange/widgets/data/owdatainfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from Orange.widgets import widget, gui
from Orange.widgets.utils.widgetpreview import WidgetPreview
from Orange.widgets.utils.state_summary import format_summary_details
from Orange.widgets.widget import Input
from Orange.data.table import Table
from Orange.data import StringVariable, DiscreteVariable, ContinuousVariable
Expand Down Expand Up @@ -43,8 +42,6 @@ def __init__(self):
bo = gui.vBox(self.controlArea, box)
gui.label(bo, self, "%%(%s)s" % name)

self.info.set_input_summary(self.info.NoInput)

# ensure the widget has some decent minimum width.
self.targets = "Categorical outcome with 123 values"
self.layout().activate()
Expand All @@ -59,12 +56,9 @@ def __init__(self):
def data(self, data):
if data is None:
self._clear_fields()
self.info.set_input_summary(self.info.NoInput)
else:
self._set_fields(data)
self._set_report(data)
self.info.set_input_summary(data.approx_len(),
format_summary_details(data))

def _clear_fields(self):
self.data_set_name = ""
Expand Down
Loading

0 comments on commit e2d90dc

Please sign in to comment.