def get_hosts(self, make_cfg): """ Make the new hosts file by the configuration defined by `make_cfg` from function list on the main dialog. :param make_cfg: Module settings in byte word format. :type make_cfg: dict .. seealso:: :attr:`make_cfg` in :class:`~tui.curses_d.CursesDaemon` class. """ for part_id in sorted(make_cfg.keys()): mod_cfg = make_cfg[part_id] if not RetrieveData.chk_mutex(part_id, mod_cfg): return mods = RetrieveData.get_ids(mod_cfg) for mod_id in mods: self.mod_num += 1 hosts, mod_name = RetrieveData.get_host(part_id, mod_id) self.info_trigger.emit(mod_name, self.mod_num) if part_id == 0x02: self.write_localhost_mod(hosts) elif part_id == 0x04: self.write_customized() else: self.write_common_mod(hosts, mod_name)
def on_Selection_changed(self, item): """ Change the current selection of modules to be applied to hosts file. .. note:: This method is the slot responses to the signal argument :attr:`item` from Functionlist widget while the item selection is changed. :param item: Row number of the item listed in Functionlist which is changed by user. :type item: int """ ip_flag = self._ipv_id func_id = self.ui.Functionlist.row(item) if self._funcs[ip_flag][func_id] == 0: self._funcs[ip_flag][func_id] = 1 else: self._funcs[ip_flag][func_id] = 0 mutex = RetrieveData.get_ids(self.choice[ip_flag][func_id][2]) for c_id, c in enumerate(self.choice[ip_flag]): if c[0] == self.choice[ip_flag][func_id][0]: if c[1] in mutex and self._funcs[ip_flag][c_id] == 1: self._funcs[ip_flag][c_id] = 0 self.refresh_func_list()
def select_func(self, pos=None, key_in=None): """ Perform operations if `function selection list` is active, or just draw the `function selection list` with no items selected while it is inactive. .. note:: Whether the `function selection list` is inactive is decided by if :attr:`pos` is `None` or not. .. seealso:: :meth:`~tui.curses_d.CursesDaemon.configure_settings`. :param pos: Index of selected item in `function selection list`. The default value of `pos` is `None`. :type pos: int or None :param key_in: A flag indicating the key pressed by user. The default value of `key_in` is `None`. :type key_in: int or None :return: Index of selected item in `function selection list`. :rtype: int or None """ list_height = 15 ip = self.settings[1][1] # Key Press Operations item_len = len(self.choice[ip]) item_sup, item_inf = self._item_sup, self._item_inf if pos is not None: if item_len > list_height: if pos <= 1: item_sup = 0 item_inf = list_height - 1 elif pos >= item_len - 2: item_sup = item_len - list_height + 1 item_inf = item_len else: item_sup = 0 item_inf = item_len if key_in == curses.KEY_DOWN: pos += 1 if pos >= item_len: pos = 0 if pos not in range(item_sup, item_inf): item_sup += 2 if item_sup == 0 else 1 item_inf += 1 elif key_in == curses.KEY_UP: pos -= 1 if pos < 0: pos = item_len - 1 if pos not in range(item_sup, item_inf): item_inf -= 2 if item_inf == item_len else 1 item_sup -= 1 elif key_in in [10, 32]: self._funcs[ip][pos] = not self._funcs[ip][pos] mutex = RetrieveData.get_ids(self.choice[ip][pos][2]) for c_id, c in enumerate(self.choice[ip]): if c[0] == self.choice[ip][pos][0]: if c[1] in mutex and self._funcs[ip][c_id] == 1: self._funcs[ip][c_id] = 0 self.info(pos, 1) else: item_sup = 0 if item_len > list_height: item_inf = list_height - 1 else: item_inf = item_len self.show_funclist(pos, item_sup, item_inf) return pos