Commit d4392266 authored by Roman Alifanov's avatar Roman Alifanov

settings: add future tracking and fix empty string in map

parent 6728dc0b
...@@ -43,6 +43,7 @@ class BaseSetting: ...@@ -43,6 +43,7 @@ class BaseSetting:
self._executor = get_executor() self._executor = get_executor()
self._timer_id = None self._timer_id = None
self._destroyed = False self._destroyed = False
self._pending_futures = []
self.search_target = setting_data.get("search_target", None) self.search_target = setting_data.get("search_target", None)
...@@ -140,9 +141,10 @@ class BaseSetting: ...@@ -140,9 +141,10 @@ class BaseSetting:
if "choice" in self.type or "list_dual" in self.type: if "choice" in self.type or "list_dual" in self.type:
map_data = {} map_data = {}
for var in range_value: for var in range_value:
key = var if not var:
display_name = var[0].upper() + var[1:] if var else "" continue
map_data[key] = display_name display_name = var[0].upper() + var[1:]
map_data[var] = display_name
return map_data return map_data
if self.type == "number": if self.type == "number":
...@@ -202,7 +204,7 @@ class BaseSetting: ...@@ -202,7 +204,7 @@ class BaseSetting:
self._map_loading = False self._map_loading = False
self._set_busy(False) self._set_busy(False)
self._executor.submit(_load, on_success=_on_success, on_error=_on_error, on_done=_on_done) self._submit_task(_load, on_success=_on_success, on_error=_on_error, on_done=_on_done)
def _notify_map_updated(self): def _notify_map_updated(self):
if self.widget and self._widget_ready: if self.widget and self._widget_ready:
...@@ -242,7 +244,7 @@ class BaseSetting: ...@@ -242,7 +244,7 @@ class BaseSetting:
self._value_loading = False self._value_loading = False
self._set_busy(False) self._set_busy(False)
self._executor.submit(_load, on_success=_on_success, on_error=_on_error, on_done=_on_done) self._submit_task(_load, on_success=_on_success, on_error=_on_error, on_done=_on_done)
def _get_backend_value(self, force=False): def _get_backend_value(self, force=False):
if self._current_value is None or force: if self._current_value is None or force:
...@@ -270,7 +272,7 @@ class BaseSetting: ...@@ -270,7 +272,7 @@ class BaseSetting:
return return
self._set_busy(False) self._set_busy(False)
self._executor.submit(_save, on_error=_on_error, on_done=_on_done) self._submit_task(_save, on_error=_on_error, on_done=_on_done)
def _get_backend_range(self): def _get_backend_range(self):
if not self._map_ready: if not self._map_ready:
...@@ -291,11 +293,25 @@ class BaseSetting: ...@@ -291,11 +293,25 @@ class BaseSetting:
self._timer_id = GLib.timeout_add(int(interval * 1000), _poll) self._timer_id = GLib.timeout_add(int(interval * 1000), _poll)
def _submit_task(self, func, on_success=None, on_error=None, on_done=None):
def _wrapped_done():
if future in self._pending_futures:
self._pending_futures.remove(future)
if on_done:
on_done()
future = self._executor.submit(func, on_success=on_success, on_error=on_error, on_done=_wrapped_done)
self._pending_futures.append(future)
return future
def destroy(self): def destroy(self):
self._destroyed = True self._destroyed = True
if self._timer_id is not None: if self._timer_id is not None:
GLib.source_remove(self._timer_id) GLib.source_remove(self._timer_id)
self._timer_id = None self._timer_id = None
for future in self._pending_futures:
future.cancel()
self._pending_futures.clear()
def _update_widget(self): def _update_widget(self):
if self.widget and self._widget_ready: if self.widget and self._widget_ready:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment