def __init__(self, params, prev_page="timezone", next_page="desktop"): super().__init__(self, params, "keymap", prev_page, next_page) self.prepare_called = False self.keyboard_test_entry = self.ui.get_object("keyboard_test_entry") self.keyboard_widget = self.ui.get_object("keyboard_widget") self.keyboard_layout = {'code': None, 'description': None} self.keyboard_variant = {'code': None, 'description': None} base_xml_path = os.path.join(self.settings.get('data'), "base.xml") self.kbd_names = keyboard_names.KeyboardNames(base_xml_path) # Init keymap treeview self.keymap_treeview = self.ui.get_object("keymap_treeview") self.keymap_treeview.set_model(Gtk.TreeStore(str)) column = Gtk.TreeViewColumn("Layouts") self.keymap_treeview.append_column(column) cell = Gtk.CellRendererText() column.pack_start(cell, False) column.add_attribute(cell, "text", 0) self.keymap_treeview.set_activate_on_single_click(True) self.keymap_treeview.connect("row-activated", self.on_keymap_row_activated)
def store_values(self): if self.keyboard_layout_human is None: # We have not previously stored our layout return selected = self.variant_treeview.get_selection() keyboard_variant_human = "USA" if selected: (ls, iterator) = selected.get_selected() if iterator: keyboard_variant_human = ls.get_value(iterator, 0) lang = self.settings.get("language_code") kbd_names = keyboard_names.KeyboardNames(self.filename) if not kbd_names.has_language(lang): lang = "C" kbd_names.load(lang) country_code = kbd_names.layout_by_human[self.keyboard_layout_human] self.keyboard_layout = country_code self.keyboard_variant = kbd_names.variant_by_human[country_code][keyboard_variant_human] self.settings.set("keyboard_layout", self.keyboard_layout) self.settings.set("keyboard_variant", self.keyboard_variant) # This fixes issue 75: Won't pick/load the keyboard layout after selecting one (sticks to qwerty) if not self.testing and self.prepare_called: self.setkb() return True
def fill_layout_treeview(self): lang = self.settings.get("language_code") keyboard_names._default_filename = self.filename if not keyboard_names.has_language(lang): lang = "C" kbd_names = keyboard_names.KeyboardNames(self.filename) kbd_names.load(lang) sorted_layouts = [] for layout in kbd_names.layout_by_human: sorted_layouts.append(layout) sorted_layouts = misc.sort_list(sorted_layouts, self.settings.get("locale")) # Block signal self.layout_treeview.handler_block_by_func(self.on_keyboardlayout_cursor_changed) # Clear our model liststore = self.layout_treeview.get_model() liststore.clear() # Add layouts (sorted) for layout in sorted_layouts: liststore.append([layout]) # Unblock signal self.layout_treeview.handler_unblock_by_func(self.on_keyboardlayout_cursor_changed)
def initialize(self): self.kbd_names = keyboard_names.KeyboardNames(self.base_xml_path) country_code = self.settings.country_code description = self.kbd_names.get_layout_description(country_code) self.keyboard_layout, self.keyboard_variant = self._reset() self.keyboard_layout['code'] = country_code if description: self.keyboard_layout['description'] = description # specific variant cases country_name = self.settings.country_name language_name = self.settings.language_name
def fill_variant_treeview(self): selected = self.layout_treeview.get_selection() if selected: (ls, iterator) = selected.get_selected() if iterator: keyboard_layout = ls.get_value(iterator, 0) # Store layout selected self.keyboard_layout_human = keyboard_layout lang = self.settings.get("language_code") if not keyboard_names.has_language(lang): lang = "C" kbd_names = keyboard_names.KeyboardNames(self.filename) kbd_names.load(lang) country_code = kbd_names.layout_by_human[self.keyboard_layout_human] self.keyboard_layout = country_code variants = kbd_names.variant_by_human sorted_variants = [] for variant in variants[country_code]: sorted_variants.append(variant) sorted_variants = misc.sort_list(sorted_variants, self.settings.get("locale")) # Block signal self.variant_treeview.handler_block_by_func(self.on_keyboardvariant_cursor_changed) # Clear our model liststore = self.variant_treeview.get_model() liststore.clear() # Add keyboard variants (sorted) for variant in sorted_variants: liststore.append([variant]) # Unblock signal self.variant_treeview.handler_unblock_by_func(self.on_keyboardvariant_cursor_changed) self.variant_treeview.set_cursor(0) else: liststore = self.variant_treeview.get_model() liststore.clear()