class DropdownInput(Gtk.Alignment): __gsignals__ = { 'dropdown-changed': (GObject.SIGNAL_RUN_FIRST, None, ()), "popup": (GObject.SIGNAL_RUN_FIRST, None, ()) } def __init__(self, values): super(DropdownInput, self).__init__() self._combo = KanoComboBox(items=values) KanoComboBox.apply_styling_to_screen() self._combo.connect("selected", self._emit_value_changed) # Propagate the dropdown widget popup signal self._combo.connect("popup", self._emit_popup) self.add(self._combo) def get_selected_text(self): return self._combo.get_selected_item_text() def _emit_value_changed(self, widget): self.emit('dropdown-changed') def _emit_popup(self, widget): self.emit('popup') def get_focusable_widget(self): ''' :returns: tuple (bool, widget) The first argument is whether there is a widget that should be focused on, the second is the widget in question ''' return (True, self._combo)
def _create_language_combo(self): language_combo = KanoComboBox(max_display_items=7) language_combo.connect('changed', self._on_language_changed) language_combo.set_items(SUPPORTED_LOCALES.list_languages()) return language_combo
def __init__(self, values): super(DropdownInput, self).__init__() self._combo = KanoComboBox(items=values) KanoComboBox.apply_styling_to_screen() self._combo.connect("selected", self._emit_value_changed) # Propagate the dropdown widget popup signal self._combo.connect("popup", self._emit_popup) self.add(self._combo)
def _create_birthday_widget(self, day=None, month=None, year=None): KanoComboBox.apply_styling_to_screen() current_year = datetime.datetime.now().year years = [str(i) for i in range(current_year, 1900, -1)] self._year_dropdown = self._create_dropdown(years, "Year") self._year_dropdown.connect("changed", self._update_day_dropdown) months = [] for i in range(1, 13): months.append(calendar.month_name[i]) self._month_dropdown = self._create_dropdown(months, "Month", width=60) self._month_dropdown.connect("changed", self._update_day_dropdown) # When the month gets changed, the day gets changed. # At start, shows days 1-31 days = [str(i) for i in range(1, 32)] self._day_dropdown = self._create_dropdown(days, "Day") self._day_dropdown.connect("changed", self.validate) hbox = Gtk.Box() hbox.pack_start(self._year_dropdown, False, False, 10) hbox.pack_start(self._month_dropdown, False, False, 10) hbox.pack_start(self._day_dropdown, False, False, 10) hbox.set_margin_left(20) hbox.set_margin_right(10) # validation label_box = Gtk.Box() label_box.set_margin_left(30) birthday_label = Gtk.Label(_("Birthday")) birthday_label.get_style_context().add_class("get_data_label") label_box.pack_start(birthday_label, False, False, 0) self._birthday_status = Gtk.Label() self._birthday_status.get_style_context().add_class("validation_label") label_box.pack_start(self._birthday_status, False, False, 0) # Container for the validation and title labels self.pack_start(label_box, False, False, 0) # Container for the dropdowns self.pack_start(hbox, False, False, 0)
def _create_birthday_widget(self, day=None, month=None, year=None): KanoComboBox.apply_styling_to_screen() current_year = datetime.datetime.now().year years = [str(i) for i in range(current_year, 1900, -1)] self._year_dropdown = self._create_dropdown(years, _("Year")) self._year_dropdown.connect('changed', self._update_day_dropdown) months = [] for i in range(1, 13): months.append(calendar.month_name[i]) self._month_dropdown = self._create_dropdown(months, _("Month"), width=60) self._month_dropdown.connect('changed', self._update_day_dropdown) # When the month gets changed, the day gets changed. # At start, shows days 1-31 days = [str(i) for i in range(1, 32)] self._day_dropdown = self._create_dropdown(days, _("Day")) self._day_dropdown.connect('changed', self.validate) hbox = Gtk.Box() hbox.pack_start(self._year_dropdown, False, False, 10) hbox.pack_start(self._month_dropdown, False, False, 10) hbox.pack_start(self._day_dropdown, False, False, 10) hbox.set_margin_left(20) hbox.set_margin_right(10) # validation label_box = Gtk.Box() label_box.set_margin_left(30) birthday_label = Gtk.Label(_("Birthday")) birthday_label.get_style_context().add_class('get_data_label') label_box.pack_start(birthday_label, False, False, 0) self._birthday_status = Gtk.Label() self._birthday_status.get_style_context().add_class('validation_label') label_box.pack_start(self._birthday_status, False, False, 0) # Container for the validation and title labels self.pack_start(label_box, False, False, 0) # Container for the dropdowns self.pack_start(hbox, False, False, 0)
def __init__(self, screen_number=None, screen_name=None, socket_id=0, onescreen=False): # Check for internet, if screen is 12 means no internet if screen_number == 12 or screen_name == 'no-internet': common.has_internet = False else: common.has_internet = is_internet() # Set combobox styling to the screen # Is done here so we don't attach the styling multiple times when # switching screens apply_styling_to_screen(self.CSS_PATH) apply_common_to_screen() KanoComboBox.apply_styling_to_screen() ScrolledWindow.apply_styling_to_screen(wide=True) # Set window base_class.__init__(self, _("Settings"), self.width, self.height, socket_id) self.set_decorated(True) self.top_bar = TopBar(_("Settings")) self.top_bar.set_close_callback(self.close_window) self.prev_handler = None self.set_icon_name('kano-settings') if self._base_name == "Window": self.set_titlebar(self.top_bar) self._onescreen = onescreen self.connect('delete-event', Gtk.main_quit) # In case we are called from kano-world-launcher, terminate splash os.system('kano-stop-splash') # Init to Home Screen HomeScreen(self, screen_number=screen_number, screen_name=screen_name)
def __init__(self, video, main=None): super(AddToPlaylistPopup, self).__init__(main) self.video = video self._combo = KanoComboBox(max_display_items=7) self._combo.connect('changed', self._enable_add) self.grid.attach(self._combo, 0, 1, 1, 1) self._add_button = Button('ADD') self._add_button.get_style_context().add_class('green') self._add_button.set_sensitive(False) self._add_button.connect('clicked', self._add, self._combo) self.grid.attach(self._add_button, 1, 1, 1, 1) button = Button('CREATE NEW') button.get_style_context().add_class('orange_linktext') button.connect('clicked', self._new) self.grid.attach(button, 0, 2, 1, 1) self.refresh()
def _create_dropdown(self, item_list, default_text=None, width=-1): if default_text: dropdown = KanoComboBox(default_text=default_text, max_display_items=7) else: dropdown = KanoComboBox(max_display_items=7) dropdown.set_size_request(width, -1) for i in item_list: dropdown.append(i) return dropdown
class SetDisplay(Template): def __init__(self, win): # Show the Display brand and model self.model = get_model() info_message = ' (Changing this requires a reboot)' # And the current display resolution try: current_resolution = get_status()['resolution'] info_message += '\n\nCurrent resolution: {}'.format(current_resolution) except: pass Template.__init__( self, "Display", self.model + info_message, "APPLY CHANGES" ) self.win = win self.win.set_main_widget(self) self.win.top_bar.enable_prev() self.win.change_prev_callback(self.win.go_to_home) self.kano_button.connect("button-release-event", self.apply_changes) self.kano_button.connect("key-release-event", self.apply_changes) horizontal_container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=40) horizontal_container.set_valign(Gtk.Align.CENTER) # HDMI mode combo box self.mode_combo = KanoComboBox(max_display_items=7) self.mode_combo.connect("changed", self.on_mode_changed) # Fill list of modes modes = list_supported_modes() self.mode_combo.append("auto") if modes: for v in modes: self.mode_combo.append(v) horizontal_container.pack_start(self.mode_combo, False, False, 0) self.mode_combo.props.valign = Gtk.Align.CENTER # Select the current setting in the dropdown list saved_group, saved_mode = read_hdmi_mode() active_item = find_matching_mode(modes, saved_group, saved_mode) self.mode_combo.set_selected_item_index(active_item) self.init_item = active_item self.mode_index = active_item # Overscan button overscan_button = OrangeButton("Overscan") horizontal_container.pack_end(overscan_button, False, False, 0) overscan_button.connect("button-release-event", self.go_to_overscan) self.box.pack_start(horizontal_container, False, False, 0) # Create Flip 180 checkbox flip_button = Gtk.CheckButton("Flip Screen") flip_button.set_can_focus(False) flip_button.props.valign = Gtk.Align.CENTER flip_button.set_active(get_config_value("display_rotate") == 2) flip_button.connect("clicked", self.flip) self.box.pack_start(flip_button, False, False, 0) self.kano_button.set_sensitive(False) # Add apply changes button under the main settings content self.win.show_all() def apply_changes(self, button, event): # If enter key is pressed or mouse button is clicked if not hasattr(event, 'keyval') or event.keyval == Gdk.KEY_Return: # Check if we have done any change if self.init_item != self.mode_index: # Set HDMI mode # Get mode:group string # Of the form "auto" or "cea:1" or "dmt:1" etc. parse_mode = self.mode.split(" ")[0] self.set_hdmi_mode_from_str(parse_mode) # Track the user's screen resolution track_data("screen-mode-changed", { "mode": parse_mode }) common.need_reboot = True self.win.go_to_home() def on_mode_changed(self, combo): # Get the selected mode self.mode = combo.get_selected_item_text() self.mode_index = combo.get_selected_item_index() self.kano_button.set_sensitive(True) def set_hdmi_mode_from_str(self, mode): if mode == "auto": set_hdmi_mode() set_config_comment('kano_screen_used', 'xxx') return group, number = mode.split(":") set_hdmi_mode(group, number) set_config_comment('kano_screen_used', self.model) def go_to_overscan(self, widget, event): self.win.clear_win() # Check if overscan values are all the same overscan_values = get_overscan_status() if overscan_values['top'] != overscan_values['bottom'] or \ overscan_values['top'] != overscan_values['left'] or \ overscan_values['top'] != overscan_values['right']: SetAdvancedOverscan(self.win, overscan_values) else: SetSimpleOverscan(self.win, overscan_values) def flip(self, button): set_flip(button.get_active()) self.kano_button.set_sensitive(True) common.need_reboot = True
class AddToPlaylistPopup(PlaylistPopup): """ A popup for selecting a playlist """ def __init__(self, video, main=None): super(AddToPlaylistPopup, self).__init__(main) self.video = video self._combo = KanoComboBox(max_display_items=7) self._combo.connect('changed', self._enable_add) self.grid.attach(self._combo, 0, 1, 1, 1) self._add_button = Button('ADD') self._add_button.get_style_context().add_class('green') self._add_button.set_sensitive(False) self._add_button.connect('clicked', self._add, self._combo) self.grid.attach(self._add_button, 1, 1, 1, 1) button = Button('CREATE NEW') button.get_style_context().add_class('orange_linktext') button.connect('clicked', self._new) self.grid.attach(button, 0, 2, 1, 1) self.refresh() def _enable_add(self, _): self._add_button.set_sensitive(True) def _add(self, _, combo): playlist_name = combo.get_selected_item_text() playlistCollection.collection[playlist_name].add(self.video) self._return = playlist_name self.destroy() def _new(self, _): popup = AddPlaylistPopup(self._main_win) res = popup.run() if res: self._combo.append(res) self._combo.set_selected_item_index(0) self._combo.set_sensitive(True) def refresh(self): self._combo.remove_all() for name, _ in playlistCollection.collection.iteritems(): if name != 'Kano': self._combo.append(name) if len(playlistCollection.collection) is 1: self._combo.set_sensitive(False)
class SetDisplay(Template): def __init__(self, win): # Show the Display brand and model self.model = get_edid_name() info_message = _("\nScreen Model: {}".format(self.model)) # And the current display resolution try: current_resolution = get_status()['resolution'] info_message += _("\nCurrent Resolution: {}").format(_(current_resolution)) except: pass Template.__init__( self, _("Display"), info_message, _("APPLY CHANGES") ) self.win = win self.win.set_main_widget(self) self.win.top_bar.enable_prev() self.win.change_prev_callback(self.win.go_to_home) self.kano_button.connect('button-release-event', self.apply_changes) self.kano_button.connect('key-release-event', self.apply_changes) horizontal_container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=40) horizontal_container.set_valign(Gtk.Align.CENTER) # HDMI mode combo box self.mode_combo = KanoComboBox(max_display_items=7) self.mode_combo.connect('changed', self.on_mode_changed) # Fill list of modes modes = list_supported_modes() self.mode_combo.append('auto') mode_string = '{hdmi_group}:{hdmi_mode} {width}x{height} {refresh_rate}Hz {aspect_ratio}' if modes: for mode in modes: self.mode_combo.append(mode_string.format( hdmi_group=mode['group'], hdmi_mode=mode['mode'], width=mode['width'], height=mode['height'], refresh_rate=mode['rate'], aspect_ratio=mode['aspect_ratio'] )) horizontal_container.pack_start(self.mode_combo, False, False, 0) self.mode_combo.props.valign = Gtk.Align.CENTER # Select the current setting in the dropdown list saved_group, saved_mode = read_hdmi_mode() active_item = find_matching_mode(modes, saved_group, saved_mode) self.mode_combo.set_selected_item_index(active_item) self.init_item = active_item self.mode_index = active_item # Overscan button overscan_button = OrangeButton(_("Overscan")) horizontal_container.pack_end(overscan_button, False, False, 0) overscan_button.connect('button-release-event', self.go_to_overscan) self.box.pack_start(horizontal_container, False, False, 0) # Create Flip 180 checkbox flip_button = Gtk.CheckButton(_("Flip Screen")) flip_button.set_can_focus(False) flip_button.props.valign = Gtk.Align.CENTER self.flip_preference_start = (get_screen_value('display_rotate') == 2) self.flip_preference_end = self.flip_preference_start flip_button.set_active(self.flip_preference_start) flip_button.connect('clicked', self.on_flip_screen_clicked) self.box.pack_start(flip_button, False, False, 0) self.kano_button.set_sensitive(False) # Add apply changes button under the main settings content self.win.show_all() def apply_changes(self, button, event): # If enter key is pressed or mouse button is clicked if not hasattr(event, 'keyval') or event.keyval == Gdk.KEY_Return: # Check if there was a change to the Flip Screen state. if self.flip_preference_start != self.flip_preference_end: set_flip(self.flip_preference_end) end_config_transaction() common.need_reboot = True # Check if there was resolution change. if self.init_item != self.mode_index: # Set HDMI mode # Get mode:group string # Of the form "auto" or "cea:1" or "dmt:1" etc. parse_mode = self.mode.split(" ")[0] self.set_hdmi_mode_from_str(parse_mode) # Track the user's screen resolution track_data('screen-mode-changed', { 'mode': parse_mode }) end_config_transaction() common.need_reboot = True self.win.go_to_home() def on_mode_changed(self, combo): # Get the selected mode self.mode = combo.get_selected_item_text() self.mode_index = combo.get_selected_item_index() self.kano_button.set_sensitive(True) def set_hdmi_mode_from_str(self, mode): if mode == 'auto': if get_edid_name(): set_hdmi_mode() else: set_unflashed_sk_resolution() return group, number = mode.split(":") set_hdmi_mode(group, number) def go_to_overscan(self, widget, event): self.win.clear_win() # Check if overscan values are all the same overscan_values = get_overscan_status() if overscan_values['top'] != overscan_values['bottom'] or \ overscan_values['top'] != overscan_values['left'] or \ overscan_values['top'] != overscan_values['right']: SetAdvancedOverscan(self.win, overscan_values) else: SetSimpleOverscan(self.win, overscan_values) def on_flip_screen_clicked(self, button): self.flip_preference_end = button.get_active() self.kano_button.set_sensitive(True)
def _create_region_combo(self): region_combo = KanoComboBox(max_display_items=7) region_combo.connect('changed', self._on_region_changed) return region_combo
def __init__(self, win): # Show the Display brand and model self.model = get_edid_name() info_message = _("\nScreen Model: {}".format(self.model)) # And the current display resolution try: current_resolution = get_status()['resolution'] info_message += _("\nCurrent Resolution: {}").format(_(current_resolution)) except: pass Template.__init__( self, _("Display"), info_message, _("APPLY CHANGES") ) self.win = win self.win.set_main_widget(self) self.win.top_bar.enable_prev() self.win.change_prev_callback(self.win.go_to_home) self.kano_button.connect('button-release-event', self.apply_changes) self.kano_button.connect('key-release-event', self.apply_changes) horizontal_container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=40) horizontal_container.set_valign(Gtk.Align.CENTER) # HDMI mode combo box self.mode_combo = KanoComboBox(max_display_items=7) self.mode_combo.connect('changed', self.on_mode_changed) # Fill list of modes modes = list_supported_modes() self.mode_combo.append('auto') mode_string = '{hdmi_group}:{hdmi_mode} {width}x{height} {refresh_rate}Hz {aspect_ratio}' if modes: for mode in modes: self.mode_combo.append(mode_string.format( hdmi_group=mode['group'], hdmi_mode=mode['mode'], width=mode['width'], height=mode['height'], refresh_rate=mode['rate'], aspect_ratio=mode['aspect_ratio'] )) horizontal_container.pack_start(self.mode_combo, False, False, 0) self.mode_combo.props.valign = Gtk.Align.CENTER # Select the current setting in the dropdown list saved_group, saved_mode = read_hdmi_mode() active_item = find_matching_mode(modes, saved_group, saved_mode) self.mode_combo.set_selected_item_index(active_item) self.init_item = active_item self.mode_index = active_item # Overscan button overscan_button = OrangeButton(_("Overscan")) horizontal_container.pack_end(overscan_button, False, False, 0) overscan_button.connect('button-release-event', self.go_to_overscan) self.box.pack_start(horizontal_container, False, False, 0) # Create Flip 180 checkbox flip_button = Gtk.CheckButton(_("Flip Screen")) flip_button.set_can_focus(False) flip_button.props.valign = Gtk.Align.CENTER self.flip_preference_start = (get_screen_value('display_rotate') == 2) self.flip_preference_end = self.flip_preference_start flip_button.set_active(self.flip_preference_start) flip_button.connect('clicked', self.on_flip_screen_clicked) self.box.pack_start(flip_button, False, False, 0) self.kano_button.set_sensitive(False) # Add apply changes button under the main settings content self.win.show_all()
def __init__(self, win): Template.__init__( self, _("Keyboard"), _("Where do you live? So I can set your keyboard."), _("APPLY CHANGES") ) self.win = win self.win.set_main_widget(self) self.read_config() kano_keyboard = detect_kano_keyboard() self.win.top_bar.enable_prev() if kano_keyboard: self.win.change_prev_callback(self.go_to_kano_screen) else: self.win.change_prev_callback(self.win.go_to_home) self.kano_button.connect('button-release-event', self.apply_changes) # Make sure continue button is enabled self.kano_button.set_sensitive(False) # Create Continents Combo box self.continents_combo = KanoComboBox(max_display_items=7) for c in self.continents: self.continents_combo.append(c) self.continents_combo.connect('changed', self.on_continent_changed) # Create Countries Combo box self.countries_combo = KanoComboBox(max_display_items=7) self.countries_combo.connect('changed', self.on_country_changed) self.countries_combo.props.valign = Gtk.Align.CENTER # Create Advance mode checkbox advance_button = Gtk.CheckButton(_("Advanced options")) advance_button.set_can_focus(False) advance_button.props.valign = Gtk.Align.CENTER advance_button.connect('clicked', self.on_advance_mode) advance_button.set_active(False) # Create Variants Combo box self.variants_combo = KanoComboBox(max_display_items=7) self.variants_combo.connect('changed', self.on_variants_changed) self.variants_combo.props.valign = Gtk.Align.CENTER # Set up default values in dropdown lists self.set_defaults('continent') self.fill_countries_combo(self.continents_combo.get_selected_item_text()) self.set_defaults('country') self.on_country_changed(self.countries_combo) self.set_defaults('variant') # Ceate various dropdown boxes so we can resize the dropdown lists appropriately # We create two boxes side by side, and then stack the country dropdow lists in one, and one by itself in the other # dropdown_box_countries dropdown_box_keys # | | | # |-------continents-------| Advance option | # | | | # | | | # |-------countries -------|--------variants--------| # | | | dropdown_box_countries = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=20) dropdown_box_countries.set_size_request(230, 30) dropdown_box_countries.props.valign = Gtk.Align.CENTER dropdown_box_keys = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=20) dropdown_box_keys.set_size_request(230, 30) dropdown_box_countries.pack_start(self.continents_combo, False, False, 0) dropdown_box_countries.pack_start(self.countries_combo, False, False, 0) dropdown_box_keys.pack_start(advance_button, False, False, 0) dropdown_box_keys.pack_start(self.variants_combo, False, False, 0) dropdown_container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=20) dropdown_container.pack_start(dropdown_box_countries, False, False, 0) dropdown_container.pack_start(dropdown_box_keys, False, False, 0) self.box.pack_start(dropdown_container, False, False, 0) # show all elements except the advanced mode self.refresh_window()
class SetKeyboard(Template): selected_layout = None selected_continent_index = 1 selected_country = None selected_country_index = 21 selected_variant = None selected_variant_index = 0 selected_continent_hr = 'America' selected_country_hr = 'USA' selected_variant_hr = 'generic' variants_combo = None continents = keyboard_layouts.get_continents() kano_keyboard = True def __init__(self, win): Template.__init__( self, _("Keyboard"), _("Where do you live? So I can set your keyboard."), _("APPLY CHANGES") ) self.win = win self.win.set_main_widget(self) self.read_config() kano_keyboard = detect_kano_keyboard() self.win.top_bar.enable_prev() if kano_keyboard: self.win.change_prev_callback(self.go_to_kano_screen) else: self.win.change_prev_callback(self.win.go_to_home) self.kano_button.connect('button-release-event', self.apply_changes) # Make sure continue button is enabled self.kano_button.set_sensitive(False) # Create Continents Combo box self.continents_combo = KanoComboBox(max_display_items=7) for c in self.continents: self.continents_combo.append(c) self.continents_combo.connect('changed', self.on_continent_changed) # Create Countries Combo box self.countries_combo = KanoComboBox(max_display_items=7) self.countries_combo.connect('changed', self.on_country_changed) self.countries_combo.props.valign = Gtk.Align.CENTER # Create Advance mode checkbox advance_button = Gtk.CheckButton(_("Advanced options")) advance_button.set_can_focus(False) advance_button.props.valign = Gtk.Align.CENTER advance_button.connect('clicked', self.on_advance_mode) advance_button.set_active(False) # Create Variants Combo box self.variants_combo = KanoComboBox(max_display_items=7) self.variants_combo.connect('changed', self.on_variants_changed) self.variants_combo.props.valign = Gtk.Align.CENTER # Set up default values in dropdown lists self.set_defaults('continent') self.fill_countries_combo(self.continents_combo.get_selected_item_text()) self.set_defaults('country') self.on_country_changed(self.countries_combo) self.set_defaults('variant') # Ceate various dropdown boxes so we can resize the dropdown lists appropriately # We create two boxes side by side, and then stack the country dropdow lists in one, and one by itself in the other # dropdown_box_countries dropdown_box_keys # | | | # |-------continents-------| Advance option | # | | | # | | | # |-------countries -------|--------variants--------| # | | | dropdown_box_countries = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=20) dropdown_box_countries.set_size_request(230, 30) dropdown_box_countries.props.valign = Gtk.Align.CENTER dropdown_box_keys = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=20) dropdown_box_keys.set_size_request(230, 30) dropdown_box_countries.pack_start(self.continents_combo, False, False, 0) dropdown_box_countries.pack_start(self.countries_combo, False, False, 0) dropdown_box_keys.pack_start(advance_button, False, False, 0) dropdown_box_keys.pack_start(self.variants_combo, False, False, 0) dropdown_container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=20) dropdown_container.pack_start(dropdown_box_countries, False, False, 0) dropdown_container.pack_start(dropdown_box_keys, False, False, 0) self.box.pack_start(dropdown_container, False, False, 0) # show all elements except the advanced mode self.refresh_window() def go_to_kano_screen(self, widget=None, event=None): self.win.clear_win() SetKanoKeyboard(self.win) def refresh_window(self): self.win.show_all() self.variants_combo.hide() def apply_changes(self, button, event): # If enter key is pressed or mouse button is clicked if not hasattr(event, 'keyval') or event.keyval == 65293: def lengthy_process(): if keyboard_config.is_changed(self.selected_country, self.selected_variant): # Apply the keyboard changes keyboard_config.set_keyboard(self.selected_country, self.selected_variant) # A reboot is needed to apply the new keyboard to QT5 apps common.need_reboot = True # The callback runs a GUI task, so wrap it! GObject.idle_add(self.work_finished_cb) # Save the changes in the config file self.update_config() # An then apply the new saved changes thread = threading.Thread(target=lengthy_process) thread.start() kano_keyboard = detect_kano_keyboard() # Go back a screen if kano_keyboard: self.go_to_kano_screen() else: self.win.go_to_home() self.win.show_all() def read_config(self): self.selected_continent_index = get_setting('Keyboard-continent-index') self.selected_country_index = get_setting('Keyboard-country-index') self.selected_variant_index = get_setting('Keyboard-variant-index') self.selected_continent_hr = get_setting('Keyboard-continent-human') self.selected_country_hr = get_setting('Keyboard-country-human') self.selected_variant_hr = get_setting('Keyboard-variant-human') def update_config(self): keyboard_config.update_settings_keyboard_conf( self.selected_continent_index, self.selected_country_index, self.selected_variant_index, self.selected_continent_hr, self.selected_country_hr, self.selected_variant_hr ) # setting = "variant", "continent" or "country" def set_defaults(self, setting): # Set the default info on the dropdown lists # 'Keyboard-continent':continents_combo, 'Keyboard-country', 'Keyboard-variant']: active_item = get_setting('Keyboard-' + setting + '-index') if setting == 'continent': self.continents_combo.set_selected_item_index(int(active_item)) elif setting == 'country': self.countries_combo.set_selected_item_index(int(active_item)) elif setting == 'variant': self.variants_combo.set_selected_item_index(int(active_item)) else: logger.error("Bad argument in set_defaults - should be 'continent', 'country' or 'variant'") return def set_variants_to_generic(self): self.variants_combo.set_selected_item_index(0) def set_variants_to_mac_layout(self): # If the country is the United States, select the generic setting if self.selected_country_hr.upper() == 'UNITED STATES': self.set_variants_to_generic() return # Otherwise, try and find a Macintosh variant layout = keyboard_layouts.layouts[self.selected_continent_hr] index = keyboard_config.find_macintosh_index(self.selected_country_hr, layout) # If the macintosh variant exists, set it if index: self.variants_combo.set_selected_item_index(index) # if not found, select generic else: self.set_variants_to_generic() def on_continent_changed(self, combo): # making sure the continent has been set continent_text = combo.get_selected_item_text() continent_index = combo.get_selected_item_index() if not continent_text or continent_index == -1: return self.selected_continent_hr = continent_text self.selected_continent_index = continent_index self.kano_button.set_sensitive(False) self.fill_countries_combo(self.selected_continent_hr) # Use the first country as the default value for country combo self.countries_combo.set_selected_item_index(0) self.on_country_changed(self.countries_combo) def on_country_changed(self, combo): # making sure the country has been set country_text = combo.get_selected_item_text() country_index = combo.get_selected_item_index() if not country_text or country_index == -1: return # Remove entries from variants combo box self.variants_combo.remove_all() self.selected_country_hr = country_text self.selected_country_index = country_index # Refresh variants combo box self.selected_country = keyboard_config.find_country_code(country_text, self.selected_layout) variants = keyboard_config.find_keyboard_variants(self.selected_country) self.variants_combo.append('generic') if variants is not None: for v in variants: self.variants_combo.append(v[0]) # if kano keyboard is connected, change to Mac layout kano_keyboard = detect_kano_keyboard() if kano_keyboard: self.set_variants_to_mac_layout() else: self.set_variants_to_generic() self.on_variants_changed(self.variants_combo) def on_variants_changed(self, combo): # making sure the variant has been set variant_text = combo.get_selected_item_text() variant_index = combo.get_selected_item_index() if not variant_text or variant_index == -1: return self.kano_button.set_sensitive(True) if variant_text == 'generic': self.selected_variant = self.selected_variant_hr = variant_text self.selected_variant_index = 0 return # Select the variant code variants = keyboard_config.find_keyboard_variants(self.selected_country) if variants is not None: for v in variants: if v[0] == variant_text: self.selected_variant = v[1] self.selected_variant_index = variant_index self.selected_variant_hr = variant_text def on_advance_mode(self, button): if int(button.get_active()): self.variants_combo.show() else: self.variants_combo.hide() def work_finished_cb(self): # Finished updating keyboard pass def fill_countries_combo(self, continent): continent = continent.lower() self.selected_layout = keyboard_layouts.get_countries_for_continent( continent ) self.selected_continent_hr = continent # Remove entries from countries and variants combo box self.countries_combo.remove_all() self.variants_combo.remove_all() # Get a sorted list of the countries from the dict layout sorted_countries = keyboard_layouts.sorted_countries( self.selected_layout ) # Refresh countries combo box for country in sorted_countries: self.countries_combo.append(country)
class SetDisplay(Template): def __init__(self, win): # Show the Display brand and model self.model = get_edid_name() info_message = _("\nScreen Model: {}".format(self.model)) # And the current display resolution try: current_resolution = get_status()['resolution'] info_message += _("\nCurrent Resolution: {}").format(_(current_resolution)) except: pass Template.__init__( self, _("Display"), info_message, _("APPLY CHANGES") ) self.win = win self.win.set_main_widget(self) self.win.top_bar.enable_prev() self.win.change_prev_callback(self.win.go_to_home) self.kano_button.connect('button-release-event', self.apply_changes) self.kano_button.connect('key-release-event', self.apply_changes) horizontal_container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=40) horizontal_container.set_valign(Gtk.Align.CENTER) # HDMI mode combo box self.mode_combo = KanoComboBox(max_display_items=7) self.mode_combo.connect('changed', self.on_mode_changed) # Fill list of modes modes = list_supported_modes() self.mode_combo.append('auto') mode_string = '{hdmi_group}:{hdmi_mode} {width}x{height} {refresh_rate}Hz {aspect_ratio}' if modes: for mode in modes: self.mode_combo.append(mode_string.format( hdmi_group=mode['group'], hdmi_mode=mode['mode'], width=mode['width'], height=mode['height'], refresh_rate=mode['rate'], aspect_ratio=mode['aspect_ratio'] )) horizontal_container.pack_start(self.mode_combo, False, False, 0) self.mode_combo.props.valign = Gtk.Align.CENTER # Select the current setting in the dropdown list saved_group, saved_mode = read_hdmi_mode() active_item = find_matching_mode(modes, saved_group, saved_mode) self.mode_combo.set_selected_item_index(active_item) self.init_item = active_item self.mode_index = active_item # Overscan button overscan_button = OrangeButton(_("Overscan")) horizontal_container.pack_end(overscan_button, False, False, 0) overscan_button.connect('button-release-event', self.go_to_overscan) self.box.pack_start(horizontal_container, False, False, 0) # Create Flip 180 checkbox flip_button = Gtk.CheckButton(_("Flip Screen")) flip_button.set_can_focus(False) flip_button.props.valign = Gtk.Align.CENTER flip_button.set_active(get_screen_value('display_rotate') == 2) flip_button.connect('clicked', self.flip) self.box.pack_start(flip_button, False, False, 0) self.kano_button.set_sensitive(False) # Add apply changes button under the main settings content self.win.show_all() def apply_changes(self, button, event): # If enter key is pressed or mouse button is clicked if not hasattr(event, 'keyval') or event.keyval == Gdk.KEY_Return: # Check if we have done any change if self.init_item != self.mode_index: # Set HDMI mode # Get mode:group string # Of the form "auto" or "cea:1" or "dmt:1" etc. parse_mode = self.mode.split(" ")[0] self.set_hdmi_mode_from_str(parse_mode) # Track the user's screen resolution track_data('screen-mode-changed', { 'mode': parse_mode }) end_config_transaction() common.need_reboot = True self.win.go_to_home() def on_mode_changed(self, combo): # Get the selected mode self.mode = combo.get_selected_item_text() self.mode_index = combo.get_selected_item_index() self.kano_button.set_sensitive(True) def set_hdmi_mode_from_str(self, mode): if mode == 'auto': set_hdmi_mode() return group, number = mode.split(":") set_hdmi_mode(group, number) def go_to_overscan(self, widget, event): self.win.clear_win() # Check if overscan values are all the same overscan_values = get_overscan_status() if overscan_values['top'] != overscan_values['bottom'] or \ overscan_values['top'] != overscan_values['left'] or \ overscan_values['top'] != overscan_values['right']: SetAdvancedOverscan(self.win, overscan_values) else: SetSimpleOverscan(self.win, overscan_values) def flip(self, button): set_flip(button.get_active()) self.kano_button.set_sensitive(True) end_config_transaction() common.need_reboot = True
def __init__(self, win): # Show the Display brand and model self.model = get_edid_name() info_message = _("\nScreen Model: {}".format(self.model)) # And the current display resolution try: current_resolution = get_status()['resolution'] info_message += _("\nCurrent Resolution: {}").format(_(current_resolution)) except: pass Template.__init__( self, _("Display"), info_message, _("APPLY CHANGES") ) self.win = win self.win.set_main_widget(self) self.win.top_bar.enable_prev() self.win.change_prev_callback(self.win.go_to_home) self.kano_button.connect('button-release-event', self.apply_changes) self.kano_button.connect('key-release-event', self.apply_changes) horizontal_container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=40) horizontal_container.set_valign(Gtk.Align.CENTER) # HDMI mode combo box self.mode_combo = KanoComboBox(max_display_items=7) self.mode_combo.connect('changed', self.on_mode_changed) # Fill list of modes modes = list_supported_modes() self.mode_combo.append('auto') mode_string = '{hdmi_group}:{hdmi_mode} {width}x{height} {refresh_rate}Hz {aspect_ratio}' if modes: for mode in modes: self.mode_combo.append(mode_string.format( hdmi_group=mode['group'], hdmi_mode=mode['mode'], width=mode['width'], height=mode['height'], refresh_rate=mode['rate'], aspect_ratio=mode['aspect_ratio'] )) horizontal_container.pack_start(self.mode_combo, False, False, 0) self.mode_combo.props.valign = Gtk.Align.CENTER # Select the current setting in the dropdown list saved_group, saved_mode = read_hdmi_mode() active_item = find_matching_mode(modes, saved_group, saved_mode) self.mode_combo.set_selected_item_index(active_item) self.init_item = active_item self.mode_index = active_item # Overscan button overscan_button = OrangeButton(_("Overscan")) horizontal_container.pack_end(overscan_button, False, False, 0) overscan_button.connect('button-release-event', self.go_to_overscan) self.box.pack_start(horizontal_container, False, False, 0) # Create Flip 180 checkbox flip_button = Gtk.CheckButton(_("Flip Screen")) flip_button.set_can_focus(False) flip_button.props.valign = Gtk.Align.CENTER flip_button.set_active(get_screen_value('display_rotate') == 2) flip_button.connect('clicked', self.flip) self.box.pack_start(flip_button, False, False, 0) self.kano_button.set_sensitive(False) # Add apply changes button under the main settings content self.win.show_all()
def __init__(self, win): # Show the Display brand and model self.model = get_model() info_message = ' (Changing this requires a reboot)' # And the current display resolution try: current_resolution = get_status()['resolution'] info_message += '\n\nCurrent resolution: {}'.format(current_resolution) except: pass Template.__init__( self, "Display", self.model + info_message, "APPLY CHANGES" ) self.win = win self.win.set_main_widget(self) self.win.top_bar.enable_prev() self.win.change_prev_callback(self.win.go_to_home) self.kano_button.connect("button-release-event", self.apply_changes) self.kano_button.connect("key-release-event", self.apply_changes) horizontal_container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=40) horizontal_container.set_valign(Gtk.Align.CENTER) # HDMI mode combo box self.mode_combo = KanoComboBox(max_display_items=7) self.mode_combo.connect("changed", self.on_mode_changed) # Fill list of modes modes = list_supported_modes() self.mode_combo.append("auto") if modes: for v in modes: self.mode_combo.append(v) horizontal_container.pack_start(self.mode_combo, False, False, 0) self.mode_combo.props.valign = Gtk.Align.CENTER # Select the current setting in the dropdown list saved_group, saved_mode = read_hdmi_mode() active_item = find_matching_mode(modes, saved_group, saved_mode) self.mode_combo.set_selected_item_index(active_item) self.init_item = active_item self.mode_index = active_item # Overscan button overscan_button = OrangeButton("Overscan") horizontal_container.pack_end(overscan_button, False, False, 0) overscan_button.connect("button-release-event", self.go_to_overscan) self.box.pack_start(horizontal_container, False, False, 0) # Create Flip 180 checkbox flip_button = Gtk.CheckButton("Flip Screen") flip_button.set_can_focus(False) flip_button.props.valign = Gtk.Align.CENTER flip_button.set_active(get_config_value("display_rotate") == 2) flip_button.connect("clicked", self.flip) self.box.pack_start(flip_button, False, False, 0) self.kano_button.set_sensitive(False) # Add apply changes button under the main settings content self.win.show_all()