def _get_contacts_group(self, contacts_group): '''Возвращает объект MDLabel - "Контактов нет", если контакты в группе отсутствуют или объект со списком добавленных в группу контактов.''' if not contacts_group.__len__(): return MDLabel(text=self.data.string_lang_not_contacts, font_style='Headline', halign='center', theme_text_color='Custom', text_color=self.data.text_color) else: for contact_name in contacts_group: info_contacts = { contact_name: self.info_contacts[contact_name] } if not self._contacts_list_in_group: contacts_list = ContactsList() self._contacts_list_in_group = Lists( dict_items=info_contacts, flag='three_list_custom_icon', right_icons=self.data.right_icons[:1], events_callback=self._event_contact_item) contacts_list.add_widget(self._contacts_list_in_group) else: self._contacts_list_in_group.three_list_custom_icon( info_contacts) self._contacts_list_in_group = None return contacts_list
def show_contacts(self, info_contacts): ''' :type info_contacts: dict; :param info_contacts: { 'Name contact': ['Number contact\nMail contact', 'path/to/avatar'] }; ''' if not self._contacts_items: # Создаем список контактов. self._contacts_list = ContactsList() self._contacts_items = Lists( dict_items=info_contacts, flag='three_list_custom_icon', right_icons=self.data.right_icons, events_callback=self._event_contact_item) button_add_contact = Builder.template( 'ButtonAdd', disabled=False, events_callback=self.show_form_create_contact) self._contacts_list.add_widget(self._contacts_items) self._contacts_list.add_widget(button_add_contact) self.add_screens('contact_list', self.manager_tab_contacts, self._contacts_list) else: # Добавляет контакт к существующему списку # и выводит список на экран. self._add_contact_item(info_contacts) self.manager_tab_contacts.current = 'contact_list'
def select_game_locale(self, *args): def select_game_locale(name_locale): for locale in self.dict_language.keys(): if name_locale == self.dict_language[locale]: self.lang_games = locale self.config.set('Games', 'language', self.lang_games) self.config.write() self.translation_game.switch_lang(name_locale) self.snake_words_with_color = [{ word: get_random_color(alpha=1.0) for word in words } for words in [ s.split(' ') for s in self.translation_game._( 'snake_rounds').split(' | ') ]] dict_info_locales = {} for locale in self.dict_language.keys(): dict_info_locales[self.dict_language[locale]] = \ ['locale', locale == self.lang_games] if not self.window_game_language: self.window_game_language = card(Lists( dict_items=dict_info_locales, events_callback=select_game_locale, flag='one_select_check'), size=(.85, .55)) self.window_game_language.open()
def select_locale(self, *args): '''Выводит окно со списком имеющихся языковых локализаций для установки языка приложения.''' def select_locale(name_locale): '''Устанавливает выбранную локализацию.''' for locale in self.dict_language.keys(): if name_locale == self.dict_language[locale]: self.lang = locale self.config.set('General', 'language', self.lang) self.config.write() dict_info_locales = {} for locale in self.dict_language.keys(): dict_info_locales[self.dict_language[locale]] = \ ['locale', locale == self.lang] if not self.window_language: self.window_language = card( Lists( dict_items=dict_info_locales, events_callback=select_locale, flag='one_select_check' ), size=(.85, .55) ) self.window_language.open()
def show_plugins(self, *args): '''Выводит на экран список установленных плагинов.''' dict_info_plugins = self._get_info_plugins() if not dict_info_plugins.__len__(): dialog(text=self.translation._(u'Нет установленных плагинов!'), title=self.title) return self._list_plugins = Lists(dict_items=dict_info_plugins, events_callback=self._action_plugin, flag='two_list_icon_check') card(self._list_plugins)
def options_popup(self, options_instance): def on_select(value): options_instance.value = value dialog.dismiss() options_list = [] for options in options_instance.options: options_list.append(options) options_list = Lists(list_items=options_list, flag='single_list', events_callback=on_select) dialog = card(options_list)
def _show_names_groups(self, name_contact): '''Выводит на экран окно со списком групп.''' def get_choice_group(name_group): groups_list.dismiss() self._add_contact_in_group(name_contact, name_group) if not self.info_groups.__len__(): Snackbar.make(self.data.string_lang_list_groups_empty) return groups_list = \ [[name_group, 'accounts'] for name_group in self.info_groups.keys()] groups_list = Lists(list_items=groups_list, events_callback=get_choice_group, flag='single_list_icon') groups_list = card(groups_list, self.data.string_lang_add_in_group)
def show_plugins(self): '''Выводит на экран список установленных плагинов.''' dict_info_plugins = self._get_info_plugins() if not dict_info_plugins.__len__(): dialog( text=self.data.self.data.string_lang_not_install_plugin, title=self.title ) return self._list_plugins = Lists( dict_items=dict_info_plugins, events_callback=self._action_plugin, flag='two_list_icon_check' ) card(self._list_plugins)
def show_plugins(self): '''Выводит на экран список установленных плагинов.''' if not self.window_user_plugins: dict_info_plugins = self._get_info_plugins() if not dict_info_plugins.__len__(): dialog(text=self._app.translation._( 'Нет установленных плагинов!'), title=self._app.title) return self._list_plugins = Lists(dict_items=dict_info_plugins, events_callback=self._action_plugin, flag='two_list_icon_check') self.window_user_plugins = card(self._list_plugins, size=(.85, .55)) self.window_user_plugins.open()
def select_locale(self, *args): def select_locale(name_locale): for locale in self.dict_language.keys(): if name_locale == self.dict_language[locale]: self.lang = locale self.config.set('General', 'language', self.lang) self.config.write() dict_info_locales = {} for locale in self.dict_language.keys(): dict_info_locales[self.dict_language[locale]] = \ ['locale', locale == self.lang] if not self.window_language: self.window_language = card(Lists(dict_items=dict_info_locales, events_callback=select_locale, flag='one_select_check'), size=(.85, .55)) self.window_language.open()
def show_choose_from_contacts(self, *args): def select_contact(name_contact): for contact in self.dict_contacts.keys(): if name_contact == self.dict_contacts[contact]: self.window_contacts.dismiss() self.cont = name_contact text_cont = name_contact print(text_cont) self.window_contacts.dismiss() dict_info_contacts = {} for contact in self.dict_contacts.keys(): dict_info_contacts[self.dict_contacts[contact]] = \ ['contact', contact == self.cont] if not self.window_contacts: self.window_contacts = card(Lists(dict_items=dict_info_contacts, events_callback=select_contact, flag='one_select_check'), size=(.85, .55)) self.window_contacts.open()
def select_locale(self, *args): '''Выводит окно со списком имеющихся языковых локализаций для установки языка приложения.''' def select_locale(name_locale): '''Устанавливает выбранную локализацию.''' for locale in self.dict_language.keys(): if name_locale == self.dict_language[locale]: self.lang = locale self.config.set('General', 'language', self.lang) self.config.write() dict_info_locales = {} for locale in self.dict_language.keys(): dict_info_locales[self.dict_language[locale]] = \ ['locale', locale == self.lang] if not self.window_language: self.window_language = card(Lists(dict_items=dict_info_locales, events_callback=select_locale, flag='one_select_check'), size=(.85, .55)) self.window_language.open()
class ShowContacts(object): _contacts_items = None def show_contacts(self, info_contacts): ''' :type info_contacts: dict; :param info_contacts: { 'Name contact': ['Number contact\nMail contact', 'path/to/avatar'] }; ''' if not self._contacts_items: # Создаем список контактов. self._contacts_list = ContactsList() self._contacts_items = Lists( dict_items=info_contacts, flag='three_list_custom_icon', right_icons=self.data.right_icons, events_callback=self._event_contact_item) button_add_contact = Builder.template( 'ButtonAdd', disabled=False, events_callback=self.show_form_create_contact) self._contacts_list.add_widget(self._contacts_items) self._contacts_list.add_widget(button_add_contact) self.add_screens('contact_list', self.manager_tab_contacts, self._contacts_list) else: # Добавляет контакт к существующему списку # и выводит список на экран. self._add_contact_item(info_contacts) self.manager_tab_contacts.current = 'contact_list' def _event_contact_item(self, *args): '''События пункта списка контактов.''' def end_call(): self.screen.current = 'root_screen' instanse_button = args[0] if type(instanse_button) == RightButton: name_contact, name_event = instanse_button.id.split(', ') if name_event == 'call': self.screen.current = 'call_contact' data_contact = self.info_contacts[name_contact] call_screen = self.screen.current_screen.children[0] call_screen.name_contact = name_contact call_screen.number_contact = data_contact[0].split('\n')[0] call_screen.avatar = data_contact[1] call_screen.callback = end_call elif name_event == 'groups': self._show_names_groups(name_contact) else: name_contact, name_event = args def _show_names_groups(self, name_contact): '''Выводит на экран окно со списком групп.''' def get_choice_group(name_group): groups_list.dismiss() self._add_contact_in_group(name_contact, name_group) if not self.info_groups.__len__(): Snackbar.make(self.data.string_lang_list_groups_empty) return groups_list = \ [[name_group, 'accounts'] for name_group in self.info_groups.keys()] groups_list = Lists(list_items=groups_list, events_callback=get_choice_group, flag='single_list_icon') groups_list = card(groups_list, self.data.string_lang_add_in_group) def _add_contact_item(self, info_contacts): self._contacts_items.three_list_custom_icon(info_contacts)
class CreateGroup(object): _new_group = None _contacts_list_in_group = None def create_group(self): def callback(group_name): dialog_group.dismiss() if group_name: if group_name in self.info_groups: Snackbar.make( self.data.string_lang_group_exists.format(group_name)) return self.info_groups[group_name] = [] self._save_data('groups.ini', self.info_groups) self._show_group(group_name) dialog_group = input_dialog(title=self.title, hint_text=self.data.string_lang_name_group, text_button_ok='OK', events_callback=callback) def _show_group(self, groups_data): if self.manager_tab_groups.has_screen('groups') and \ not isinstance(groups_data, str): if self.old_info_groups != groups_data: self._check_new_add_contact_in_groups(groups_data) return else: # Выводим на экран список групп, если он был ранее создан. self.manager_tab_groups.current = 'groups' return if not self._new_group: self._new_group = NewGroup() if isinstance(groups_data, str): groups_data = {groups_data: []} for group_name in groups_data.keys(): self._create_accordion_item(group_name, groups_data) if not self.manager_tab_groups.current or \ self.manager_tab_groups.current == 'empty_groups_list': self.add_screens('groups', self.manager_tab_groups, self._new_group) def _create_accordion_item(self, group_name, groups_data): group_item = MDAccordionItem(id=group_name, title=group_name, icon='accounts', background_color=self.data.alpha, title_theme_color='Primary') scroll = ScrollView(id=group_name) contacts_group = self._get_contacts_group(groups_data[group_name]) scroll.add_widget(contacts_group) group_item.add_widget(scroll) self._new_group.ids.group.add_widget(group_item) def _add_contact_in_group(self, name_contact, group_name): '''Добавляет контакт в группу.''' if name_contact not in self.info_groups[group_name]: self.info_groups[group_name].append(name_contact) self._save_data('groups.ini', self.info_groups) self.info_contacts, self.info_groups = self._read_data() Snackbar.make( self.data.string_lang_add_contact_in_group.format( name_contact, group_name)) def _get_contacts_group(self, contacts_group): '''Возвращает объект MDLabel - "Контактов нет", если контакты в группе отсутствуют или объект со списком добавленных в группу контактов.''' if not contacts_group.__len__(): return MDLabel(text=self.data.string_lang_not_contacts, font_style='Headline', halign='center', theme_text_color='Custom', text_color=self.data.text_color) else: for contact_name in contacts_group: info_contacts = { contact_name: self.info_contacts[contact_name] } if not self._contacts_list_in_group: contacts_list = ContactsList() self._contacts_list_in_group = Lists( dict_items=info_contacts, flag='three_list_custom_icon', right_icons=self.data.right_icons[:1], events_callback=self._event_contact_item) contacts_list.add_widget(self._contacts_list_in_group) else: self._contacts_list_in_group.three_list_custom_icon( info_contacts) self._contacts_list_in_group = None return contacts_list def _check_new_add_contact_in_groups(self, groups_data): '''Проверяет и добавляет в группу новые контакты, если таковые были включены в какую-лиюо группу во вкладке "Контакты".''' def add_contact_list_in_groups(): scroll_in_accordion_item = accordion_item.ids.container.children[0] label_not_contacts = scroll_in_accordion_item.children[0] scroll_in_accordion_item.remove_widget(label_not_contacts) contacts_group = self._get_contacts_group(groups_data[group_name]) scroll_in_accordion_item.add_widget(contacts_group) for accordion_item in self._new_group.ids.group.children: for group_name in groups_data.keys(): contacts_name_in_group = groups_data[group_name] if group_name == accordion_item.id: for contact_name in contacts_name_in_group: if group_name in self.old_info_groups: if contact_name not in self.old_info_groups[ group_name]: accordion_content = \ accordion_item.ids.container.children[0].children[0] if type(accordion_content) == ContactsList: contacts_list_in_group = \ accordion_content.children[0] info_contacts = \ {contact_name: self.info_contacts[contact_name]} contacts_list_in_group.three_list_custom_icon( info_contacts) else: add_contact_list_in_groups() else: add_contact_list_in_groups() self.old_info_groups = groups_data