Example #1
0
    def generate_file_chooser(self, option, path=None):
        """Generate a file chooser button to select a file."""
        option_name = option['option']
        label = Label(option['label'])
        file_chooser = Gtk.FileChooserButton("Choose a file for %s" % label)
        file_chooser.set_size_request(200, 30)

        if 'default_path' in option:
            config_key = option['default_path']
            default_path = self.lutris_config.system_config.get(config_key)
            if default_path and os.path.exists(default_path):
                file_chooser.set_current_folder(default_path)

        file_chooser.set_action(Gtk.FileChooserAction.OPEN)
        file_chooser.connect("file-set", self.on_chooser_file_set,
                             option_name)
        if path:
            # If path is relative, complete with game dir
            if not os.path.isabs(path):
                path = os.path.join(self.game.directory, path)
            file_chooser.unselect_all()
            file_chooser.select_filename(path)
        label.set_alignment(0.5, 0.5)
        file_chooser.set_valign(Gtk.Align.CENTER)
        self.wrapper.pack_start(label, False, False, 0)
        self.wrapper.pack_start(file_chooser, True, True, 0)
        self.option_widget = file_chooser
Example #2
0
    def generate_file_chooser(self, option, path=None):
        """Generate a file chooser button to select a file."""
        option_name = option['option']
        label = Label(option['label'])
        file_chooser = Gtk.FileChooserButton("Choose a file for %s" % label)
        file_chooser.set_size_request(200, 30)

        if 'default_path' in option:
            config_key = option['default_path']
            default_path = self.lutris_config.system_config.get(config_key)
            if default_path and os.path.exists(default_path):
                file_chooser.set_current_folder(default_path)

        file_chooser.set_action(Gtk.FileChooserAction.OPEN)
        file_chooser.connect("file-set", self.on_chooser_file_set, option_name)
        if path:
            # If path is relative, complete with game dir
            if not os.path.isabs(path):
                path = os.path.join(self.game.directory, path)
            file_chooser.unselect_all()
            file_chooser.select_filename(path)
        label.set_alignment(0.5, 0.5)
        file_chooser.set_valign(Gtk.Align.CENTER)
        self.wrapper.pack_start(label, False, False, 0)
        self.wrapper.pack_start(file_chooser, True, True, 0)
        self.option_widget = file_chooser
Example #3
0
    def generate_file_chooser(self, option, path=None):
        """Generate a file chooser button to select a file."""
        option_name = option['option']
        label = Label(option['label'])
        file_chooser = FileChooserEntry(
            title='Select file',
            action=Gtk.FileChooserAction.OPEN,
            default_path=path  # reverse_expanduser(path)
        )
        file_chooser.set_size_request(200, 30)

        if 'default_path' in option:
            config_key = option['default_path']
            default_path = self.lutris_config.system_config.get(config_key)
            if default_path and os.path.exists(default_path):
                file_chooser.entry.set_text(default_path)

        if path:
            # If path is relative, complete with game dir
            if not os.path.isabs(path):
                path = os.path.expanduser(path)
            file_chooser.entry.set_text(path)

        file_chooser.set_valign(Gtk.Align.CENTER)
        label.set_alignment(0.5, 0.5)
        self.wrapper.pack_start(label, False, False, 0)
        self.wrapper.pack_start(file_chooser, True, True, 0)
        self.option_widget = file_chooser
        file_chooser.entry.connect('changed', self._on_chooser_file_set,
                                   option_name)
Example #4
0
    def generate_editable_grid(self, option_name, label, value=None):
        value = value or {}
        value = list(value.items())
        label = Label(label)
        label.set_alignment(0.5, 0)

        grid = EditableGrid(value, columns=["Key", "Value"])
        grid.connect('changed', self.on_grid_changed, option_name)
        self.wrapper.pack_start(label, False, False, 0)
        self.wrapper.pack_start(grid, True, True, 0)
        self.option_widget = grid
Example #5
0
 def generate_entry(self, option_name, label, value=None):
     """Generate an entry box."""
     label = Label(label)
     entry = Gtk.Entry()
     if value:
         entry.set_text(value)
     entry.connect("changed", self.entry_changed, option_name)
     label.set_alignment(0.5, 0.5)
     self.wrapper.pack_start(label, False, False, 0)
     self.wrapper.pack_start(entry, True, True, 0)
     self.option_widget = entry
Example #6
0
    def generate_editable_grid(self, option_name, label, value=None):
        value = value or {}
        value = list(value.items())
        label = Label(label)
        label.set_alignment(0.5, 0)

        grid = EditableGrid(value, columns=["Key", "Value"])
        grid.connect('changed', self.on_grid_changed, option_name)
        self.wrapper.pack_start(label, False, False, 0)
        self.wrapper.pack_start(grid, True, True, 0)
        self.option_widget = grid
Example #7
0
 def generate_entry(self, option_name, label, value=None):
     """Generate an entry box."""
     label = Label(label)
     entry = Gtk.Entry()
     if value:
         entry.set_text(value)
     entry.connect("changed", self.entry_changed, option_name)
     label.set_alignment(0.5, 0.5)
     self.wrapper.pack_start(label, False, False, 0)
     self.wrapper.pack_start(entry, True, True, 0)
     self.option_widget = entry
Example #8
0
 def generate_directory_chooser(self, option_name, label_text, value=None):
     """Generate a file chooser button to select a directory."""
     label = Label(label_text)
     directory_chooser = FileChooserEntry(
         title='Select folder',
         action=Gtk.FileChooserAction.SELECT_FOLDER,
         default_path=reverse_expanduser(value))
     directory_chooser.entry.connect('changed', self.on_chooser_dir_set,
                                     option_name)
     directory_chooser.set_valign(Gtk.Align.CENTER)
     label.set_alignment(0.5, 0.5)
     self.wrapper.pack_start(label, False, False, 0)
     self.wrapper.pack_start(directory_chooser, True, True, 0)
     self.option_widget = directory_chooser
Example #9
0
 def generate_range(self, option_name, min_val, max_val, label, value=None):
     """Generate a ranged spin button."""
     adjustment = Gtk.Adjustment(float(min_val), float(min_val),
                                 float(max_val), 1, 0, 0)
     spin_button = Gtk.SpinButton()
     spin_button.set_adjustment(adjustment)
     if value:
         spin_button.set_value(value)
     spin_button.connect('changed', self.on_spin_button_changed,
                         option_name)
     label = Label(label)
     label.set_alignment(0.5, 0.5)
     self.wrapper.pack_start(label, False, False, 0)
     self.wrapper.pack_start(spin_button, True, True, 0)
     self.option_widget = spin_button
Example #10
0
 def generate_directory_chooser(self, option_name, label_text, value=None):
     """Generate a file chooser button to select a directory."""
     label = Label(label_text)
     directory_chooser = FileChooserEntry(
         title='Select folder',
         action=Gtk.FileChooserAction.SELECT_FOLDER,
         default_path=reverse_expanduser(value)
     )
     directory_chooser.entry.connect('changed', self.on_chooser_dir_set,
                                     option_name)
     directory_chooser.set_valign(Gtk.Align.CENTER)
     label.set_alignment(0.5, 0.5)
     self.wrapper.pack_start(label, False, False, 0)
     self.wrapper.pack_start(directory_chooser, True, True, 0)
     self.option_widget = directory_chooser
Example #11
0
 def generate_range(self, option_name, min_val, max_val, label, value=None):
     """Generate a ranged spin button."""
     adjustment = Gtk.Adjustment(float(min_val), float(min_val),
                                 float(max_val), 1, 0, 0)
     spin_button = Gtk.SpinButton()
     spin_button.set_adjustment(adjustment)
     if value:
         spin_button.set_value(value)
     spin_button.connect('changed', self.on_spin_button_changed,
                         option_name)
     label = Label(label)
     label.set_alignment(0.5, 0.5)
     self.wrapper.pack_start(label, False, False, 0)
     self.wrapper.pack_start(spin_button, True, True, 0)
     self.option_widget = spin_button
Example #12
0
    def generate_combobox(self,
                          option_name,
                          choices,
                          label,
                          value=None,
                          default=None,
                          has_entry=False):
        """Generate a combobox (drop-down menu)."""
        liststore = Gtk.ListStore(str, str)
        for choice in choices:
            if type(choice) is str:
                choice = [choice, choice]
            if choice[1] == default and not has_entry:
                # Do not add default label to editable dropdowns since this gets
                # added to the actual value.
                liststore.append([choice[0] + "  (default)", default])
                self.tooltip_default = choice[0]
            else:
                liststore.append(choice)
        # With entry ("choice_with_entry" type)
        if has_entry:
            combobox = Gtk.ComboBox.new_with_model_and_entry(liststore)
            combobox.set_entry_text_column(0)
            if value:
                combobox.get_child().set_text(value)
        # No entry ("choice" type)
        else:
            combobox = Gtk.ComboBox.new_with_model(liststore)
            cell = Gtk.CellRendererText()
            combobox.pack_start(cell, True)
            combobox.add_attribute(cell, 'text', 0)
            combobox.set_id_column(1)

            choices = list(v for k, v in choices)
            if value in choices:
                combobox.set_active_id(value)
            else:
                combobox.set_active_id(default)

        combobox.connect('changed', self.on_combobox_change, option_name)
        combobox.connect('scroll-event', self.on_combobox_scroll)
        label = Label(label)
        label.set_alignment(0.5, 0.5)
        combobox.set_valign(Gtk.Align.CENTER)
        self.wrapper.pack_start(label, False, False, 0)
        self.wrapper.pack_start(combobox, True, True, 0)
        self.option_widget = combobox
Example #13
0
    def generate_combobox(self, option_name, choices, label,
                          value=None, default=None, has_entry=False):
        """Generate a combobox (drop-down menu)."""
        liststore = Gtk.ListStore(str, str)
        for choice in choices:
            if type(choice) is str:
                choice = [choice, choice]
            if choice[1] == default:
                liststore.append([choice[0] + "  (default)", default])
                self.tooltip_default = choice[0]
            else:
                liststore.append(choice)
        # With entry ("choice_with_entry" type)
        if has_entry:
            combobox = Gtk.ComboBox.new_with_model_and_entry(liststore)
            combobox.set_entry_text_column(1)
            if value:
                combobox.get_child().set_text(value)
        # No entry ("choice" type)
        else:
            combobox = Gtk.ComboBox.new_with_model(liststore)
            cell = Gtk.CellRendererText()
            combobox.pack_start(cell, True)
            combobox.add_attribute(cell, 'text', 0)
            combobox.set_id_column(1)

            choices = list(v for k, v in choices)
            if value in choices:
                combobox.set_active_id(value)
            else:
                combobox.set_active_id(default)

        combobox.connect('changed', self.on_combobox_change, option_name)
        label = Label(label)
        label.set_alignment(0.5, 0.5)
        combobox.set_valign(Gtk.Align.CENTER)
        self.wrapper.pack_start(label, False, False, 0)
        self.wrapper.pack_start(combobox, True, True, 0)
        self.option_widget = combobox