added last configuration load feature

This commit is contained in:
DYefremov
2020-01-09 13:14:49 +03:00
parent 2e3ec1c99d
commit 9082d5c96e
4 changed files with 109 additions and 12 deletions

View File

@@ -196,6 +196,14 @@ class Settings:
def language(self, value):
self._settings["language"] = value
@property
def load_last_config(self):
return self._settings.get("load_last_config", False)
@load_last_config.setter
def load_last_config(self, value):
self._settings["load_last_config"] = value
@property
def host(self):
return self._cp_settings.get("host", self.get_default("host"))

View File

@@ -290,9 +290,15 @@ class Application(Gtk.Application):
def do_startup(self):
Gtk.Application.do_startup(self)
self.init_profiles()
self.init_drag_and_drop()
self.init_colors()
if self._settings.load_last_config:
config = self._settings.get("last_config") or {}
self.init_profiles(config.get("last_profile", None))
last_bouquet = config.get("last_bouquet", None)
self.open_data(callback=lambda: self.open_bouquet(last_bouquet))
else:
self.init_profiles()
gen = self.init_http_api()
GLib.idle_add(lambda: next(gen, False), priority=GLib.PRIORITY_LOW)
@@ -303,7 +309,11 @@ class Application(Gtk.Application):
def do_shutdown(self):
""" Performs shutdown tasks """
self._settings.save() # storing current config
if self._settings.load_last_config:
self._settings.add("last_config", {"last_profile": self._settings.current_profile,
"last_bouquet": self._current_bq_name})
self._settings.save() # storing current settings
if self._player:
self._player.release()
Gtk.Application.do_shutdown(self)
@@ -318,9 +328,11 @@ class Application(Gtk.Application):
self.activate()
return 0
def init_profiles(self):
def init_profiles(self, profile=None):
self.update_profiles()
self._profile_combo_box.set_active_id(self._settings.default_profile)
self._profile_combo_box.set_active_id(profile if profile else self._settings.default_profile)
if profile:
self.set_profile(profile)
def init_drag_and_drop(self):
""" Enable drag-and-drop """
@@ -855,12 +867,12 @@ class Application(Gtk.Application):
return
self.open_data(response)
def open_data(self, data_path=None):
def open_data(self, data_path=None, callback=None):
""" Opening data and fill views. """
gen = self.update_data(data_path)
gen = self.update_data(data_path, callback)
GLib.idle_add(lambda: next(gen, False), priority=GLib.PRIORITY_DEFAULT_IDLE)
def update_data(self, data_path):
def update_data(self, data_path, callback=None):
self._wait_dialog.show()
yield True
@@ -892,6 +904,8 @@ class Application(Gtk.Application):
yield from self.append_data(bouquets, services)
finally:
self._wait_dialog.hide()
if callback:
callback()
yield True
def append_data(self, bouquets, services):
@@ -956,6 +970,17 @@ class Application(Gtk.Application):
if extra_services:
self._extra_bouquets[bq_id] = extra_services
@run_idle
def open_bouquet(self, name):
""" Find and open bouquet by name """
for r in self._bouquets_model:
for i in r.iterchildren():
if i[Column.BQ_NAME] == name:
self._bouquets_view.expand_row(self._bouquets_model.get_path(r.iter), Column.BQ_NAME)
self._bouquets_view.set_cursor(i.path)
self._bouquets_view.row_activated(i.path, self._bouquets_view.get_column(Column.BQ_NAME))
break
def append_services(self, services):
for srv in services:
# adding channels to dict with fav_id as keys
@@ -1202,13 +1227,16 @@ class Application(Gtk.Application):
active = self._profile_combo_box.get_active_text()
if active in self._settings.profiles:
self.set_profile(active)
gen = self.init_http_api()
GLib.idle_add(lambda: next(gen, False), priority=GLib.PRIORITY_LOW)
self.open_data()
def set_profile(self, active):
self._settings.current_profile = active
self._s_type = self._settings.setting_type
self._profile_combo_box.set_tooltip_text(self._profile_combo_box.get_tooltip_text() + self._settings.host)
self.update_profile_label()
gen = self.init_http_api()
GLib.idle_add(lambda: next(gen, False), priority=GLib.PRIORITY_LOW)
self.open_data()
def update_profiles(self):
self._profile_combo_box.remove_all()

View File

@@ -1291,7 +1291,7 @@ Author: Dmitriy Yefremov
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkFrame" id="lang_frame">
<object class="GtkFrame" id="load_startup_frame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">5</property>
@@ -1356,6 +1356,64 @@ Author: Dmitriy Yefremov
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="load_on_startup_frame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="label_xalign">0</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkBox" id="load_on_startup_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<child>
<object class="GtkLabel" id="load_on_startup_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="label" translatable="yes">Load the last open configuration at program startup</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="load_on_startup_switch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="valign">center</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<child type="label_item">
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="program_frame">
<property name="visible">True</property>

View File

@@ -95,6 +95,7 @@ class SettingsDialog:
self._set_color_switch = builder.get_object("set_color_switch")
self._new_color_button = builder.get_object("new_color_button")
self._extra_color_button = builder.get_object("extra_color_button")
self._load_on_startup_switch = builder.get_object("load_on_startup_switch")
# HTTP API
self._support_http_api_switch = builder.get_object("support_http_api_switch")
self._enable_y_dl_switch = builder.get_object("enable_y_dl_switch")
@@ -198,6 +199,7 @@ class SettingsDialog:
self._before_save_switch.set_active(self._settings.backup_before_save)
self._before_downloading_switch.set_active(self._settings.backup_before_downloading)
self.set_fav_click_mode(self._settings.fav_click_mode)
self._load_on_startup_switch.set_active(self._settings.load_last_config)
if self._s_type is SettingsType.ENIGMA_2:
self._support_ver5_switch.set_active(self._settings.v5_support)
@@ -244,6 +246,7 @@ class SettingsDialog:
self._ext_settings.backup_before_downloading = self._before_downloading_switch.get_active()
self._ext_settings.fav_click_mode = self.get_fav_click_mode()
self._ext_settings.language = self._lang_combo_box.get_active_id()
self._ext_settings.load_last_config = self._load_on_startup_switch.get_active()
if self._s_type is SettingsType.ENIGMA_2:
self._ext_settings.use_colors = self._set_color_switch.get_active()