Skip to content

Commit

Permalink
GeoCoding: Don't override identifier type in set_data
Browse files Browse the repository at this point in the history
  • Loading branch information
janezd committed Apr 23, 2024
1 parent cd22075 commit 7a8f826
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions orangecontrib/geo/widgets/owgeocoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Outputs:
autocommit = settings.Setting(True)
is_decoding = settings.ContextSetting(0)
str_attr = settings.ContextSetting(None)
str_type = settings.ContextSetting(next(iter(ID_TYPE)))
str_type = settings.ContextSetting(None)
lat_attr = settings.ContextSetting(None)
lon_attr = settings.ContextSetting(None)
admin = settings.ContextSetting(0)
Expand Down Expand Up @@ -106,13 +106,14 @@ def _radioChanged():
model = DomainModel(parent=self, valid_types=(StringVariable, DiscreteVariable))
self.domainmodels.append(model)

combo = gui.comboBox(
gui.comboBox(
box, self, 'str_attr', label='Region identifier:',
orientation=Qt.Horizontal, callback=self.region_attr_changed,
orientation=Qt.Horizontal, callback=self.on_region_attr_changed,
sendSelectedValue=True, model=model)
gui.comboBox(
box, self, 'str_type', label='Identifier type:', orientation=Qt.Horizontal,
items=tuple(self.ID_TYPE.keys()), callback=lambda: self.commit(), sendSelectedValue=True)
self.str_type_combo = gui.comboBox(
box, self, None, label='Identifier type:', orientation=Qt.Horizontal,
items=tuple(self.ID_TYPE))
self.str_type_combo.textActivated.connect(self.on_region_type_changed)

# Select first mode if any of its combos are changed
for combo in box.findChildren(QComboBox):
Expand Down Expand Up @@ -203,7 +204,15 @@ def save_and_commit():
box.layout().addWidget(view)
self.setMainAreaVisibility(False)

def region_attr_changed(self):
def on_region_attr_changed(self):
self.guess_region_type()
self.commit()

def on_region_type_changed(self, value):
self.str_type = value
self.commit()

def guess_region_type(self):
if self.data is None:
return
if self.str_attr:
Expand All @@ -213,8 +222,8 @@ def region_attr_changed(self):
str_type = next((k for k, v in self.ID_TYPE.items() if v == func), None)
if str_type is not None and str_type != self.str_type:
self.str_type = str_type
self.str_type_combo.setCurrentText(self.str_type)

self.commit()

def commit(self):
output = None
Expand Down Expand Up @@ -330,8 +339,15 @@ def set_data(self, data):

self.lat_attr, self.lon_attr = find_lat_lon(data)

self.str_type = None
self.openContext(data)
self.region_attr_changed()
if self.str_type is None:
self.guess_region_type()
if self.str_type is None:
self.str_type = next(iter(self.ID_TYPE))
self.str_type_combo.setCurrentText(self.str_type)

self.commit()

def clear(self):
self.data = None
Expand Down

0 comments on commit 7a8f826

Please sign in to comment.