def gen_bouquets(view, bq_view, transient, gen_type, s_type, callback): """ Auto-generate and append list of bouquets """ fav_id_index = Column.SRV_FAV_ID index = Column.SRV_TYPE if gen_type in (BqGenType.PACKAGE, BqGenType.EACH_PACKAGE): index = Column.SRV_PACKAGE elif gen_type in (BqGenType.SAT, BqGenType.EACH_SAT): index = Column.SRV_POS model, paths = view.get_selection().get_selected_rows() bq_type = BqType.BOUQUET.value if s_type is SettingsType.NEUTRINO_MP else BqType.TV.value if gen_type in (BqGenType.SAT, BqGenType.PACKAGE, BqGenType.TYPE): if not is_only_one_item_selected(paths, transient): return service = Service(*model[paths][:Column.SRV_TOOLTIP]) append_bouquets(bq_type, bq_view, callback, fav_id_index, index, model, [ service.package if gen_type is BqGenType.PACKAGE else service.pos if gen_type is BqGenType.SAT else service.service_type ], s_type) else: wait_dialog = WaitDialog(transient) wait_dialog.show() append_bouquets(bq_type, bq_view, callback, fav_id_index, index, model, {row[index] for row in model}, s_type, wait_dialog)
def get_service(self, fav_id, data_id, transponder): freq, rate, pol, fec, system, pos = self.get_transponder_values() return Service( flags_cas=self.get_flags(), transponder_type=self._old_service.transponder_type, coded=CODED_ICON if self._cas_entry.get_text() else None, service=self._name_entry.get_text(), locked=self._old_service.locked, hide=HIDE_ICON if self._hide_check_button.get_active() else None, package=self._package_entry.get_text(), service_type=SERVICE_TYPE.get(self._srv_type_entry.get_text(), SERVICE_TYPE["3"]), picon=self._old_service.picon, picon_id=self._reference_entry.get_text().replace(":", "_") + ".png", ssid="{:04x}".format(int(self._sid_entry.get_text())), freq=freq, rate=rate, pol=pol, fec=fec, system=system, pos=pos, data_id=data_id, fav_id=fav_id, transponder=transponder)
def insert_marker(view, bouquets, selected_bouquet, services, parent_window, m_type=BqServiceType.MARKER): """" Inserts marker into bouquet services list. """ fav_id, text = "1:832:D:0:0:0:0:0:0:0:\n", None if m_type is BqServiceType.MARKER: response = show_dialog(DialogType.INPUT, parent_window) if response == Gtk.ResponseType.CANCEL: return if not response.strip(): show_dialog(DialogType.ERROR, parent_window, "The text of marker is empty, please try again!") return fav_id = "1:64:0:0:0:0:0:0:0:0::{}\n#DESCRIPTION {}\n".format( response, response) text = response s_type = m_type.name model, paths = view.get_selection().get_selected_rows() marker = (None, None, text, None, None, s_type, None, fav_id, None, None, None) itr = model.insert_before(model.get_iter(paths[0]), marker) if paths else model.insert(0, marker) bouquets[selected_bouquet].insert(model.get_path(itr)[0], fav_id) services[fav_id] = Service(None, None, None, text, None, None, None, s_type, *[None] * 9, 0, fav_id, None)
def update_transponder_services(self, transponder, tr_type): for itr in self._transponder_services_iters: srv = self._current_model[itr][:] srv[-9], srv[-8], srv[-7], srv[-6], srv[-5], srv[ -4] = self.get_transponder_values(tr_type) srv[-1] = transponder srv = Service(*srv) self._services[srv.fav_id] = self._services.pop( srv.fav_id)._replace(transponder=transponder) self._current_model.set(itr, {i: v for i, v in enumerate(srv)})
def update_transponder_services(self, transponder): for itr in self._transponder_services_iters: srv = self._current_model[itr][:Column.SRV_TOOLTIP] srv[Column.SRV_FREQ], srv[Column.SRV_RATE], srv[ Column.SRV_POL], srv[Column.SRV_FEC], srv[ Column.SRV_SYSTEM], srv[ Column.SRV_POS] = self.get_transponder_values() srv[Column.SRV_TRANSPONDER] = transponder srv = Service(*srv) self._services[srv.fav_id] = self._services.pop( srv.fav_id)._replace(transponder=transponder) self._current_model.set(itr, {i: v for i, v in enumerate(srv)})
def update_data_elements(self): model, paths = self._services_view.get_selection().get_selected_rows() # Unpacking to search for an iterator for the base model filter_model = model.get_model() self._current_model = get_base_model(model) itr = None if not paths: # If editing from bouquet list and services list in the filter mode fav_model, paths = self._fav_view.get_selection( ).get_selected_rows() fav_id = fav_model[paths][7] for row in self._current_model: if row[-2] == fav_id: itr = row.iter break else: itr = model.get_iter(paths) itr = filter_model.convert_iter_to_child_iter( model.convert_iter_to_child_iter(itr)) if not itr: return srv = Service(*self._current_model[itr][:Column.SRV_TOOLTIP]) self._old_service = srv self._current_itr = itr # Service self._name_entry.set_text(srv.service) self._package_entry.set_text(srv.package) self._sid_entry.set_text(str(int(srv.ssid, 16))) # Transponder if self._s_type is SettingsType.ENIGMA_2: self._tr_type = TrType(srv.transponder_type) self._freq_entry.set_text(srv.freq) self._rate_entry.set_text(srv.rate) self.select_active_text(self._pol_combo_box, srv.pol) self.select_active_text(self._fec_combo_box, srv.fec) self.select_active_text(self._sys_combo_box, srv.system) if self._tr_type is TrType.Terrestrial: self.update_ui_for_terrestrial() elif self._tr_type is TrType.Cable: self.update_ui_for_cable() elif self._tr_type is TrType.ATSC: self.update_ui_for_atsc() else: self.set_sat_positions(srv.pos) if self._s_type is SettingsType.ENIGMA_2: self.init_enigma2_service_data(srv) self.init_enigma2_transponder_data(srv) elif self._s_type is SettingsType.NEUTRINO_MP: self.init_neutrino_data(srv) self.init_neutrino_ui_elements()
def gen_bouquets(view, bq_view, transient, gen_type, s_type, callback): """ Auto-generate and append list of bouquets. """ model, paths = view.get_selection().get_selected_rows() single_types = (BqGenType.SAT, BqGenType.PACKAGE, BqGenType.TYPE) if gen_type in single_types: if not is_only_one_item_selected(paths, transient): return fav_id_index = Column.SRV_FAV_ID index = Column.SRV_TYPE if gen_type in (BqGenType.PACKAGE, BqGenType.EACH_PACKAGE): index = Column.SRV_PACKAGE elif gen_type in (BqGenType.SAT, BqGenType.EACH_SAT): index = Column.SRV_POS # Splitting services [caching] by column value. s_data = defaultdict(list) for row in model: s_data[row[index]].append( BouquetService(None, BqServiceType.DEFAULT, row[fav_id_index], 0)) bq_type = BqType.BOUQUET.value if s_type is SettingsType.NEUTRINO_MP else BqType.TV.value bq_index = 0 if s_type is SettingsType.ENIGMA_2 else 1 bq_root_iter = bq_view.get_model().get_iter(bq_index) srv = Service(*model[paths][:Column.SRV_TOOLTIP]) cond = srv.package if gen_type is BqGenType.PACKAGE else srv.pos if gen_type is BqGenType.SAT else srv.service_type bq_view.expand_row(Gtk.TreePath(bq_index), 0) bq_names = get_bouquets_names(bq_view.get_model()) if gen_type in single_types: if cond in bq_names: show_dialog(DialogType.ERROR, transient, "A bouquet with that name exists!") else: callback(Bouquet(cond, bq_type, s_data.get(cond)), bq_root_iter) else: # We add a bouquet only if the given name is missing [keys - names]! for name in sorted(s_data.keys() - bq_names): callback(Bouquet(name, BqType.TV.value, s_data.get(name)), bq_root_iter)
def gen_bouquets(view, bq_view, transient, gen_type, tv_types, profile, callback): """ Auto-generate and append list of bouquets """ fav_id_index = 18 index = 6 if gen_type in (BqGenType.PACKAGE, BqGenType.EACH_PACKAGE) else 16 if gen_type in ( BqGenType.SAT, BqGenType.EACH_SAT) else 7 model, paths = view.get_selection().get_selected_rows() bq_type = BqType.BOUQUET.value if profile is Profile.NEUTRINO_MP else BqType.TV.value if gen_type in (BqGenType.SAT, BqGenType.PACKAGE, BqGenType.TYPE): if not is_only_one_item_selected(paths, transient): return service = Service(*model[paths][:]) if service.service_type not in tv_types: bq_type = BqType.RADIO.value append_bouquets(bq_type, bq_view, callback, fav_id_index, index, model, [service.package if gen_type is BqGenType.PACKAGE else service.pos if gen_type is BqGenType.SAT else service.service_type], profile) else: wait_dialog = WaitDialog(transient) wait_dialog.show() append_bouquets(bq_type, bq_view, callback, fav_id_index, index, model, {row[index] for row in model}, profile, wait_dialog)
def insert_marker(view, bouquets, selected_bouquet, channels, parent_window): """" Inserts marker into bouquet services list. """ response = show_dialog(DialogType.INPUT, parent_window) if response == Gtk.ResponseType.CANCEL: return if not response.strip(): show_dialog(DialogType.ERROR, parent_window, "The text of marker is empty, please try again!") return # Searching for max num value in all marker services (if empty default = 0) max_num = max(map(lambda num: int(num.data_id, 18), filter(lambda ch: ch.service_type == BqServiceType.MARKER.name, channels.values())), default=0) max_num = '{:x}'.format(max_num + 1) fav_id = "1:64:{}:0:0:0:0:0:0:0::{}\n#DESCRIPTION {}\n".format(max_num, response, response) s_type = BqServiceType.MARKER.name model, paths = view.get_selection().get_selected_rows() marker = (None, None, response, None, None, s_type, None, fav_id, None) itr = model.insert_before(model.get_iter(paths[0]), marker) if paths else model.insert(0, marker) bouquets[selected_bouquet].insert(model.get_path(itr)[0], fav_id) channels[fav_id] = Service(None, None, None, response, None, None, None, s_type, *[None] * 9, max_num, fav_id, None)
def update_transponder_services(self, transponder, sat_pos): for itr in self._transponder_services_iters: srv = self._current_model[itr][:] srv[Column.SRV_FREQ], srv[Column.SRV_RATE], srv[ Column.SRV_POL], srv[Column.SRV_FEC], srv[ Column.SRV_SYSTEM], srv[ Column.SRV_POS] = self.get_transponder_values() srv[Column.SRV_TRANSPONDER] = transponder fav_id = srv[Column.SRV_FAV_ID] old_srv = self._services.pop(fav_id, None) if not old_srv: log("Update transponder services error: No service found for ID {}" .format(srv[Column.SRV_FAV_ID])) continue if self._s_type is SettingsType.NEUTRINO_MP: flags = srv[Column.SRV_CAS_FLAGS].split(":") flags[1] = sat_pos srv[Column.SRV_CAS_FLAGS] = ":".join(flags) self._services[fav_id] = Service(*srv[:Column.SRV_TOOLTIP]) self._current_model.set_row(itr, srv)