def generate_label(self, text): """Generate a simple label.""" label = Label(text) label.set_use_markup(True) label.set_halign(Gtk.Align.START) label.set_valign(Gtk.Align.CENTER) self.wrapper.pack_start(label, True, True, 0)
def generate_widgets(self, config_section): # noqa: C901 # pylint: disable=too-many-branches,too-many-statements """Parse the config dict and generates widget accordingly.""" if not self.options: no_options_label = Label(_("No options available")) no_options_label.set_halign(Gtk.Align.CENTER) no_options_label.set_valign(Gtk.Align.CENTER) self.pack_start(no_options_label, True, True, 0) return # Select config section. if config_section == "game": self.config = self.lutris_config.game_config self.raw_config = self.lutris_config.raw_game_config elif config_section == "runner": self.config = self.lutris_config.runner_config self.raw_config = self.lutris_config.raw_runner_config elif config_section == "system": self.config = self.lutris_config.system_config self.raw_config = self.lutris_config.raw_system_config # Go thru all options. for option in self.options: if "scope" in option: if config_section not in option["scope"]: continue option_key = option["option"] value = self.config.get(option_key) default = option.get("default") if callable(option.get( "choices")) and option["type"] != "choice_with_search": option["choices"] = option["choices"]() if callable(option.get("condition")): option["condition"] = option["condition"]() self.wrapper = Gtk.Box() self.wrapper.set_spacing(12) self.wrapper.set_margin_bottom(6) # Set tooltip's "Default" part default = option.get("default") self.tooltip_default = default if isinstance(default, str) else None # Generate option widget self.option_widget = None self.call_widget_generator(option, option_key, value, default) # Reset button reset_btn = Gtk.Button.new_from_icon_name("edit-clear", Gtk.IconSize.MENU) reset_btn.set_relief(Gtk.ReliefStyle.NONE) reset_btn.set_tooltip_text( _("Reset option to global or default config")) reset_btn.connect( "clicked", self.on_reset_button_clicked, option, self.option_widget, self.wrapper, ) placeholder = Gtk.Box() placeholder.set_size_request(32, 32) if option_key not in self.raw_config: reset_btn.set_visible(False) reset_btn.set_no_show_all(True) placeholder.pack_start(reset_btn, False, False, 0) # Tooltip helptext = option.get("help") if isinstance(self.tooltip_default, str): helptext = helptext + "\n\n" if helptext else "" helptext += _("<b>Default</b>: ") + _(self.tooltip_default) if value != default and option_key not in self.raw_config: helptext = helptext + "\n\n" if helptext else "" helptext += _("<i>(Italic indicates that this option is " "modified in a lower configuration level.)</i>") if helptext: self.wrapper.props.has_tooltip = True self.wrapper.connect("query-tooltip", self.on_query_tooltip, helptext) hbox = Gtk.Box() hbox.set_margin_left(18) hbox.pack_end(placeholder, False, False, 5) # Grey out option if condition unmet if "condition" in option and not option["condition"]: hbox.set_sensitive(False) # Hide if advanced if option.get("advanced"): hbox.get_style_context().add_class("advanced") show_advanced = settings.read_setting("show_advanced_options") if not show_advanced == "True": hbox.set_no_show_all(True) hbox.pack_start(self.wrapper, True, True, 0) self.pack_start(hbox, False, False, 0)
def generate_widgets(self, config_section): """Parse the config dict and generates widget accordingly.""" if not self.options: label = Label("No options available") label.set_halign(Gtk.Align.CENTER) label.set_valign(Gtk.Align.CENTER) self.pack_start(label, True, True, 0) return # Select config section. if config_section == 'game': self.config = self.lutris_config.game_config self.raw_config = self.lutris_config.raw_game_config elif config_section == 'runner': self.config = self.lutris_config.runner_config self.raw_config = self.lutris_config.raw_runner_config elif config_section == 'system': self.config = self.lutris_config.system_config self.raw_config = self.lutris_config.raw_system_config # Go thru all options. for option in self.options: if 'scope' in option: if config_section not in option['scope']: continue option_key = option['option'] value = self.config.get(option_key) default = option.get('default') if callable(option.get('choices')): option['choices'] = option['choices']() if callable(option.get('condition')): option['condition'] = option['condition']() hbox = Gtk.HBox() hbox.set_margin_left(20) self.wrapper = Gtk.HBox() self.wrapper.set_spacing(20) placeholder = Gtk.HBox() placeholder.set_size_request(32, 32) hbox.pack_end(placeholder, False, False, 5) # Set tooltip's "Default" part default = option.get('default') self.tooltip_default = default if type(default) is str else None # Generate option widget self.option_widget = None self.call_widget_generator(option, option_key, value, default) # Reset button reset_btn = Gtk.Button.new_from_icon_name('edit-clear', Gtk.IconSize.MENU) reset_btn.set_relief(Gtk.ReliefStyle.NONE) reset_btn.set_tooltip_text("Reset option to global or " "default config") reset_btn.connect('clicked', self.on_reset_button_clicked, option, self.option_widget, self.wrapper) if option_key not in self.raw_config: reset_btn.set_visible(False) reset_btn.set_no_show_all(True) placeholder.pack_start(reset_btn, False, False, 0) # Tooltip helptext = option.get("help") if type(self.tooltip_default) is str: helptext = helptext + '\n\n' if helptext else '' helptext += "<b>Default</b>: " + self.tooltip_default if value != default and option_key not in self.raw_config: helptext = helptext + '\n\n' if helptext else '' helptext += ("<i>(Italic indicates that this option is " "modified in a lower configuration level.)</i>") if helptext: self.wrapper.props.has_tooltip = True self.wrapper.connect('query-tooltip', self.on_query_tooltip, helptext) # Grey out option if condition unmet if 'condition' in option and not option['condition']: hbox.set_sensitive(False) # Hide if advanced if option.get('advanced'): hbox.get_style_context().add_class('advanced') show_advanced = settings.read_setting('show_advanced_options') if not show_advanced == 'True': hbox.set_no_show_all(True) hbox.pack_start(self.wrapper, True, True, 0) self.pack_start(hbox, False, False, 5)
def generate_widgets(self, config_section): """Parse the config dict and generates widget accordingly.""" if not self.options: no_options_label = Label("No options available") no_options_label.set_halign(Gtk.Align.CENTER) no_options_label.set_valign(Gtk.Align.CENTER) self.pack_start(no_options_label, True, True, 0) return # Select config section. if config_section == "game": self.config = self.lutris_config.game_config self.raw_config = self.lutris_config.raw_game_config elif config_section == "runner": self.config = self.lutris_config.runner_config self.raw_config = self.lutris_config.raw_runner_config elif config_section == "system": self.config = self.lutris_config.system_config self.raw_config = self.lutris_config.raw_system_config # Go thru all options. for option in self.options: if "scope" in option: if config_section not in option["scope"]: continue option_key = option["option"] value = self.config.get(option_key) default = option.get("default") if callable(option.get("choices")): option["choices"] = option["choices"]() if callable(option.get("condition")): option["condition"] = option["condition"]() self.wrapper = Gtk.Box() self.wrapper.set_spacing(12) self.wrapper.set_margin_bottom(6) # Set tooltip's "Default" part default = option.get("default") self.tooltip_default = default if isinstance(default, str) else None # Generate option widget self.option_widget = None self.call_widget_generator(option, option_key, value, default) # Reset button reset_btn = Gtk.Button.new_from_icon_name("edit-clear", Gtk.IconSize.MENU) reset_btn.set_relief(Gtk.ReliefStyle.NONE) reset_btn.set_tooltip_text("Reset option to global or " "default config") reset_btn.connect( "clicked", self.on_reset_button_clicked, option, self.option_widget, self.wrapper, ) placeholder = Gtk.Box() placeholder.set_size_request(32, 32) if option_key not in self.raw_config: reset_btn.set_visible(False) reset_btn.set_no_show_all(True) placeholder.pack_start(reset_btn, False, False, 0) # Tooltip helptext = option.get("help") if isinstance(self.tooltip_default, str): helptext = helptext + "\n\n" if helptext else "" helptext += "<b>Default</b>: " + self.tooltip_default if value != default and option_key not in self.raw_config: helptext = helptext + "\n\n" if helptext else "" helptext += ( "<i>(Italic indicates that this option is " "modified in a lower configuration level.)</i>" ) if helptext: self.wrapper.props.has_tooltip = True self.wrapper.connect("query-tooltip", self.on_query_tooltip, helptext) hbox = Gtk.Box() hbox.set_margin_left(18) hbox.pack_end(placeholder, False, False, 5) # Grey out option if condition unmet if "condition" in option and not option["condition"]: hbox.set_sensitive(False) # Hide if advanced if option.get("advanced"): hbox.get_style_context().add_class("advanced") show_advanced = settings.read_setting("show_advanced_options") if not show_advanced == "True": hbox.set_no_show_all(True) hbox.pack_start(self.wrapper, True, True, 0) self.pack_start(hbox, False, False, 0)