Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GeoCoding: Don't override identifier type in set_data #180

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading