From 958185e26bf85f9e352cebab667836f7150bcf1f Mon Sep 17 00:00:00 2001 From: Dmitriy Yefremov Date: Sat, 18 Nov 2017 20:49:53 +0300 Subject: [PATCH] scroll to for bouquets --- app/ui/main_app_window.py | 34 ++++++++++++++++++++------------ app/ui/main_window.glade | 41 ++++++++------------------------------- 2 files changed, 30 insertions(+), 45 deletions(-) diff --git a/app/ui/main_app_window.py b/app/ui/main_app_window.py index 71be976e..610b9054 100644 --- a/app/ui/main_app_window.py +++ b/app/ui/main_app_window.py @@ -63,6 +63,7 @@ class MainAppWindow: self.__rows_buffer = [] self.__channels = {} self.__bouquets = {} + self.__bouquets_to_del = [] builder = Gtk.Builder() builder.add_from_file("app/ui/main_window.glade") @@ -239,10 +240,8 @@ class MainAppWindow: """ Deleting bouquet """ self.__bouquets.pop(bouquet) self.__fav_model.clear() - # removing bouquet file - bqf = "{}userbouquet.{}.{}".format(self.__options["data_dir_path"], *bouquet.split(":")) - with suppress(FileNotFoundError): - os.remove(bqf) + bouquet_file_name = "{}userbouquet.{}.{}".format(self.__options["data_dir_path"], *bouquet.split(":")) + self.__bouquets_to_del.append(bouquet_file_name) def on_new_bouquet(self, view): """ Creates a new item in the bouquets tree """ @@ -261,23 +260,28 @@ class MainAppWindow: key = "{}:{}".format(bq_name, bq_type) response = show_dialog("input_dialog", self.__main_window, bq_name) - if response == Gtk.ResponseType.CANCEL: return bq = response, bq_type if model.iter_n_children(itr): # parent - model.insert(itr, 0, bq) + ch_itr = model.insert(itr, 0, bq) + self.scroll_to(model.get_path(ch_itr), paths, view) else: - parent_itr = model.iter_parent(itr) - if parent_itr: - index = int(model.get_path(itr)[1]) + 1 - model.insert(parent_itr, index, bq) - else: - model.append(itr, bq) + p_itr = model.iter_parent(itr) + it = model.insert(p_itr, int(model.get_path(itr)[1]) + 1, bq) if p_itr else model.append(itr, bq) + self.scroll_to(model.get_path(it), paths, view) self.__bouquets[key] = [] + def scroll_to(self, path, paths, view): + """ Scrolling to and selecting given path """ + view.expand_row(paths[0], 0) + selection = view.get_selection() + selection.unselect_all() + view.scroll_to_cell(path, None) + selection.select_path(path) + def on_bouquets_edit(self, view): """ Rename bouquets """ if not self.is_bouquet_selected(): @@ -437,6 +441,12 @@ class MainAppWindow: bouquets = [] services_model = self.__services_view.get_model() + # removing bouquet files + for bqf in self.__bouquets_to_del: + with suppress(FileNotFoundError): + os.remove(bqf) + self.__bouquets_to_del.clear() + def parse_bouquets(model, b_path, itr): if model.iter_has_child(itr): num_of_children = model.iter_n_children(itr) diff --git a/app/ui/main_window.glade b/app/ui/main_window.glade index d83ebdb3..171cf38f 100644 --- a/app/ui/main_window.glade +++ b/app/ui/main_window.glade @@ -109,16 +109,6 @@ False mail-send-receive - - True - autosize - Package - - - True - autosize - Service - @@ -677,7 +667,7 @@ - + 250 True True @@ -728,7 +718,6 @@ False - autosize CAS @@ -741,7 +730,6 @@ False - autosize Type @@ -752,9 +740,8 @@ - + True - autosize Service True True @@ -768,9 +755,8 @@ - + True - autosize Package True True @@ -803,7 +789,6 @@ True - autosize Ssid True True @@ -821,7 +806,6 @@ True - autosize Freq True True @@ -839,7 +823,6 @@ True - autosize Rate True True @@ -857,7 +840,6 @@ True - autosize Pol True True @@ -875,7 +857,6 @@ True - autosize FEC True True @@ -893,7 +874,6 @@ True - autosize System True True @@ -927,7 +907,6 @@ False - autosize data_id @@ -940,7 +919,6 @@ False - autosize fav_id @@ -953,7 +931,6 @@ False - autosize transponder @@ -975,11 +952,11 @@ True - True + False - + True True True @@ -1028,12 +1005,11 @@ - True - autosize Num - True - + + 0.20000000298023224 + 0 @@ -1043,7 +1019,6 @@ True - autosize Service True