55
66import numpy as np
77
8- from AnyQt .QtWidgets import QFrame , QGridLayout , QLabel , QLineEdit , \
8+ from AnyQt .QtWidgets import QLayout , QFrame , QGridLayout , QLabel , QLineEdit , \
99 QSizePolicy , QWidget , QScrollArea
1010from AnyQt .QtCore import Qt , QTimer
1111
1414from Orange .statistics .util import bincount
1515from Orange .preprocess .transformation import Transformation , Lookup
1616from Orange .widgets import gui , widget
17- from Orange .widgets .settings import DomainContextHandler , ContextSetting
17+ from Orange .widgets .settings import DomainContextHandler , ContextSetting , Setting
1818from Orange .widgets .utils .itemmodels import DomainModel
1919from Orange .widgets .utils .localization import pl
2020from Orange .widgets .utils .widgetpreview import WidgetPreview
@@ -233,12 +233,14 @@ class Outputs:
233233 MAX_RULES_AREA_HEIGHT = 360
234234
235235 settingsHandler = DomainContextHandler ()
236- attribute = ContextSetting (None )
237- class_name = ContextSetting ("class" )
238- rules = ContextSetting ({})
239- match_beginning = ContextSetting (False )
240- case_sensitive = ContextSetting (False )
241- regular_expressions = ContextSetting (False )
236+ attribute = ContextSetting (None , schema_only = True )
237+ class_name = Setting ("class" , schema_only = True )
238+ rules = Setting ({}, schema_only = True )
239+ match_beginning = Setting (False , schema_only = True )
240+ case_sensitive = Setting (False , schema_only = True )
241+ regular_expressions = Setting (False , schema_only = True )
242+
243+ settings_version = 2
242244
243245 TRANSFORMERS = {StringVariable : ValueFromStringSubstring ,
244246 DiscreteVariable : ValueFromDiscreteSubstring }
@@ -277,27 +279,28 @@ def __init__(self):
277279 # once the new row's height has been applied
278280 self ._scroll_to_bottom_pending = False
279281
280- gui .lineEdit (
282+ le = gui .lineEdit (
281283 self .controlArea , self , "class_name" ,
282284 orientation = Qt .Horizontal , box = "New Class Name" )
285+ le .setStyleSheet ("QLineEdit { padding-left: 4px; }" )
283286
284- variable_select_box = gui .vBox (self .controlArea , "Match by Substring " )
287+ variable_select_box = gui .vBox (self .controlArea , box = "Source column and patterns " )
285288
286289 combo = gui .comboBox (
287- variable_select_box , self , "attribute" , label = "From column:" ,
288- orientation = Qt .Horizontal , searchable = True ,
290+ variable_select_box , self , "attribute" , searchable = True ,
289291 callback = self .update_rules ,
290292 model = DomainModel (valid_types = (StringVariable , DiscreteVariable )))
291293 # Don't use setSizePolicy keyword argument here: it applies to box,
292294 # not the combo
293295 combo .setSizePolicy (QSizePolicy .MinimumExpanding , QSizePolicy .Preferred )
294296
295297 patternbox = gui .vBox (variable_select_box )
298+ patternbox .layout ().setSpacing (0 )
296299 #: QWidget: the box that contains the remove buttons, line edits and
297300 # count labels. The lines are added and removed dynamically.
298301 self .rules_box = rules_box = QGridLayout ()
299302 rules_box .setSpacing (4 )
300- rules_box .setContentsMargins (4 , 4 , 4 , 4 )
303+ rules_box .setContentsMargins (4 , 4 , 4 , 0 )
301304 self .rules_box .setColumnMinimumWidth (1 , 70 )
302305 self .rules_box .setColumnMinimumWidth (0 , 10 )
303306 self .rules_box .setColumnStretch (0 , 1 )
@@ -342,6 +345,7 @@ def __init__(self):
342345 gui .button (self .buttonsArea , self , "Apply" , callback = self .apply )
343346
344347 self .setSizePolicy (QSizePolicy .Preferred , QSizePolicy .Maximum )
348+ self .layout ().setSizeConstraint (QLayout .SetFixedSize )
345349
346350 @property
347351 def active_rules (self ):
@@ -363,7 +367,6 @@ def rules_to_edits(self):
363367 def set_data (self , data ):
364368 """Input data signal handler."""
365369 self .closeContext ()
366- self .rules = {}
367370 self .data = data
368371 model = self .controls .attribute .model ()
369372 model .set_domain (data .domain if data is not None else None )
@@ -723,6 +726,19 @@ def _count_part():
723726 self .report_items ("Output" , [("Class name" , self .class_name )])
724727 self .report_raw (f"<ol>{ output } </ol>" )
725728
729+ @classmethod
730+ def migrate_settings (cls , settings , version ):
731+ if version < 2 :
732+ contexts = settings .pop ("context_settings" , [])
733+ if contexts :
734+ context = contexts [0 ]
735+ settings .update (
736+ {name : context .values .pop (name )[0 ]
737+ for name in ("class_name" , "rules" , "match_beginning" ,
738+ "case_sensitive" , "regular_expressions" )})
739+ context .values ["__version__" ] = 2
740+ settings ["context_settings" ] = [context ] # selected attribute
741+
726742
727743if __name__ == "__main__" : # pragma: no cover
728744 WidgetPreview (OWCreateClass ).run (Table ("zoo" ))
0 commit comments