Example #1
0
    def __init__(self, view):
        Gtk.ActionBar.__init__(self)

        left_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        left_box.get_style_context().add_class("linked")
        self.pack_start(left_box)

        self.refresh_button = IconButton('view-refresh-symbolic')
        self.settings_button = IconButton('system-run-symbolic')

        self.refresh_button.connect(
            'clicked', lambda _: view.app_window.views['runner'].rerun())
        self.settings_button.connect(
            'clicked', lambda _: view.app_window.views.switch('settings'))

        left_box.pack_start(self.refresh_button, False, False, 0)
        left_box.pack_start(self.settings_button, False, False, 0)

        right_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        right_box.get_style_context().add_class(Gtk.STYLE_CLASS_LINKED)

        self.script_btn = IconButton('emblem-documents-symbolic',
                                     'Render script from')
        self.script_btn.connect('clicked', self.on_generate_script)

        self.script_type_btn = MultipleChoiceButton(RENDER_CHOICES, 'All',
                                                    'All')
        self.script_type_btn.set_relief(Gtk.ReliefStyle.NORMAL)

        right_box.pack_start(self.script_btn, True, True, 0)
        right_box.pack_start(self.script_type_btn, True, False, 0)

        self.pack_end(right_box)
        self.set_sensitive(False)
Example #2
0
    def __init__(self, editor_view):
        Gtk.FileChooserWidget.__init__(self)

        self.editor_view = editor_view
        self.set_select_multiple(False)
        self.set_create_folders(False)
        self.set_action(Gtk.FileChooserAction.SAVE)
        self.set_do_overwrite_confirmation(True)

        self.file_type = MultipleChoiceButton(
            ['sh', 'json', 'csv'], 'sh', 'sh'
        )
        self.file_type.set_halign(Gtk.Align.START)
        self.file_type.set_hexpand(True)
        self.file_type.connect('row-selected', self.on_file_type_changed)
        self.file_type.props.margin_end = 10

        self.confirm = SuggestedButton('Save')
        self.confirm.connect('clicked', self.on_save_clicked)
        self.confirm.set_halign(Gtk.Align.END)
        self.confirm.set_hexpand(False)
        self.confirm.set_sensitive(False)
        self.confirm.props.margin_end = 10

        self.cancel_button = IconButton('window-close-symbolic', 'Cancel')
        self.cancel_button.connect('clicked', self.on_cancel_clicked)
        self.cancel_button.set_halign(Gtk.Align.END)
        self.cancel_button.set_hexpand(False)

        self.connect('selection-changed', self.on_selection_changed)

        file_type_label = Gtk.Label('<b>Filetype</b>')
        file_type_label.set_use_markup(True)
        file_type_label.props.margin_end = 5
        file_type_label.get_style_context().add_class(
            Gtk.STYLE_CLASS_DIM_LABEL
        )

        self.extra_box = Gtk.Grid()
        self.extra_box.attach(self.file_type, 0, 0, 1, 1)
        self.extra_box.attach(self.confirm, 1, 0, 1, 1)
        self.extra_box.attach_next_to(
            file_type_label,
            self.file_type,
            Gtk.PositionType.LEFT,
            1,
            1
        )

        self.extra_box.set_hexpand(True)
        self.extra_box.set_halign(Gtk.Align.FILL)
Example #3
0
def choice_widget(settings, key_name, summary, _):
    """Create a widget for choosing between a list of selections"""
    schema = settings.props.settings_schema
    key = schema.get_key(key_name)

    selected = settings.get_string(key_name)
    default = key.get_default_value().get_string()

    range_type, range_variant = key.get_range()
    if range_type != "enum":
        LOGGER.warning("%s is not an enum.", key_name)
        return

    choices = list(range_variant)
    button = MultipleChoiceButton(choices, default, selected)
    button.connect("row-selected", lambda _: settings.set_string(key_name, button.get_selected_choice()))

    settings.bind(key_name, button.value_label, "choice", 0)
    return button
Example #4
0
def choice_widget(settings, key_name, summary, _):
    """Create a widget for choosing between a list of selections"""
    schema = settings.props.settings_schema
    key = schema.get_key(key_name)

    selected = settings.get_string(key_name)
    default = key.get_default_value().get_string()

    range_type, range_variant = key.get_range()
    if range_type != 'enum':
        LOGGER.warning('%s is not an enum.', key_name)
        return

    choices = list(range_variant)
    button = MultipleChoiceButton(choices, default, selected)
    button.connect(
        'row-selected',
        lambda _: settings.set_string(key_name, button.get_selected_choice()))

    settings.bind(key_name, button.value_label, 'choice', 0)
    return button
Example #5
0
    def __init__(self, editor_view):
        Gtk.FileChooserWidget.__init__(self)

        self.editor_view = editor_view
        self.set_select_multiple(False)
        self.set_create_folders(False)
        self.set_action(Gtk.FileChooserAction.SAVE)
        self.set_do_overwrite_confirmation(True)

        self.file_type = MultipleChoiceButton(
            ['sh', 'json', 'csv'], 'sh', 'sh'
        )
        self.file_type.set_halign(Gtk.Align.START)
        self.file_type.set_hexpand(True)
        self.file_type.connect('row-selected', self.on_file_type_changed)
        self.file_type.props.margin_end = 10

        self.confirm = SuggestedButton('Save')
        self.confirm.connect('clicked', self.on_save_clicked)
        self.confirm.set_halign(Gtk.Align.END)
        self.confirm.set_hexpand(False)
        self.confirm.set_sensitive(False)
        self.confirm.props.margin_end = 10

        self.cancel_button = IconButton('window-close-symbolic', 'Cancel')
        self.cancel_button.connect('clicked', self.on_cancel_clicked)
        self.cancel_button.set_halign(Gtk.Align.END)
        self.cancel_button.set_hexpand(False)

        self.connect('selection-changed', self.on_selection_changed)

        file_type_label = Gtk.Label('<b>Filetype</b>')
        file_type_label.set_use_markup(True)
        file_type_label.props.margin_end = 5
        file_type_label.get_style_context().add_class(
            Gtk.STYLE_CLASS_DIM_LABEL
        )

        self.extra_box = Gtk.Grid()
        self.extra_box.attach(self.file_type, 0, 0, 1, 1)
        self.extra_box.attach(self.confirm, 1, 0, 1, 1)
        self.extra_box.attach_next_to(
            file_type_label,
            self.file_type,
            Gtk.PositionType.LEFT,
            1,
            1
        )

        self.extra_box.set_hexpand(True)
        self.extra_box.set_halign(Gtk.Align.FILL)
Example #6
0
    def __init__(self, view):
        Gtk.ActionBar.__init__(self)

        left_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        left_box.get_style_context().add_class("linked")
        self.pack_start(left_box)

        self.refresh_button = IconButton('view-refresh-symbolic')
        self.settings_button = IconButton('system-run-symbolic')

        self.refresh_button.connect(
            'clicked', lambda _: view.app_window.views['runner'].rerun()
        )
        self.settings_button.connect(
            'clicked', lambda _: view.app_window.views.switch('settings')
        )

        left_box.pack_start(self.refresh_button, False, False, 0)
        left_box.pack_start(self.settings_button, False, False, 0)

        right_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        right_box.get_style_context().add_class(
            Gtk.STYLE_CLASS_LINKED
        )

        self.script_btn = IconButton(
            'emblem-documents-symbolic', 'Render script from'
        )
        self.script_btn.connect(
            'clicked', self.on_generate_script
        )

        self.script_type_btn = MultipleChoiceButton(
            ['All', 'Filtered', 'Selected'], 'All', 'All'
        )
        self.script_type_btn.set_relief(Gtk.ReliefStyle.NORMAL)

        right_box.pack_start(self.script_btn, True, True, 0)
        right_box.pack_start(self.script_type_btn, True, False, 0)

        self.pack_end(right_box)
        self.set_sensitive(False)
Example #7
0
class ResultActionBar(Gtk.ActionBar):
    """Down right bar with the controls"""
    __gsignals__ = {
        'generate-all-script': (GObject.SIGNAL_RUN_FIRST, None, ()),
        'generate-filtered-script': (GObject.SIGNAL_RUN_FIRST, None, ()),
        'generate-selection-script': (GObject.SIGNAL_RUN_FIRST, None, ())
    }

    def __init__(self, view):
        Gtk.ActionBar.__init__(self)

        left_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        left_box.get_style_context().add_class("linked")
        self.pack_start(left_box)

        self.refresh_button = IconButton('view-refresh-symbolic')
        self.settings_button = IconButton('system-run-symbolic')

        self.refresh_button.connect(
            'clicked', lambda _: view.app_window.views['runner'].rerun())
        self.settings_button.connect(
            'clicked', lambda _: view.app_window.views.switch('settings'))

        left_box.pack_start(self.refresh_button, False, False, 0)
        left_box.pack_start(self.settings_button, False, False, 0)

        right_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        right_box.get_style_context().add_class(Gtk.STYLE_CLASS_LINKED)

        self.script_btn = IconButton('emblem-documents-symbolic',
                                     'Render script from')
        self.script_btn.connect('clicked', self.on_generate_script)

        self.script_type_btn = MultipleChoiceButton(RENDER_CHOICES, 'All',
                                                    'All')
        self.script_type_btn.set_relief(Gtk.ReliefStyle.NORMAL)

        right_box.pack_start(self.script_btn, True, True, 0)
        right_box.pack_start(self.script_type_btn, True, False, 0)

        self.pack_end(right_box)
        self.set_sensitive(False)

    def set_choice(self, choice):
        """Set the current choice. Might be one of RENDER_CHOICES"""
        if choice not in RENDER_CHOICES:
            raise ValueError("Bad choice for button: " + choice)

        self.script_type_btn.set_selected_choice(choice)

    def on_generate_script(self, _):
        """Called when the left side of the compound button was clicked."""
        choice = self.script_type_btn.get_selected_choice().lower()

        if choice == 'all':
            self.emit('generate-all-script')
        elif choice == 'filtered':
            self.emit('generate-filtered-script')
        elif choice == 'selected':
            self.emit('generate-selection-script')
        else:
            LOGGER.error('Bug: bad choice selection: %s', choice)

    def set_sensitive(self, mode):
        """Set the gen-script button (non)-sensitive and (non)-suggested"""
        btn_ctx = self.script_btn.get_style_context()
        type_ctx = self.script_type_btn.get_style_context()

        if mode:
            btn_ctx.add_class(Gtk.STYLE_CLASS_SUGGESTED_ACTION)
            type_ctx.add_class(Gtk.STYLE_CLASS_SUGGESTED_ACTION)
        else:
            btn_ctx.remove_class(Gtk.STYLE_CLASS_SUGGESTED_ACTION)
            type_ctx.remove_class(Gtk.STYLE_CLASS_SUGGESTED_ACTION)

        self.script_btn.set_sensitive(mode)
        self.script_type_btn.set_sensitive(mode)

    def is_sensitive(self):
        return self.script_btn.is_sensitive()
Example #8
0
class ScriptSaverDialog(Gtk.FileChooserWidget):
    """GtkFileChooserWidget tailored for saving a `Script` instance."""

    __gsignals__ = {
        'saved': (GObject.SIGNAL_RUN_FIRST, None, ()),
    }

    def __init__(self, editor_view):
        Gtk.FileChooserWidget.__init__(self)

        self.editor_view = editor_view
        self.set_select_multiple(False)
        self.set_create_folders(False)
        self.set_action(Gtk.FileChooserAction.SAVE)
        self.set_do_overwrite_confirmation(True)

        self.file_type = MultipleChoiceButton(['sh', 'json', 'csv'], 'sh',
                                              'sh')
        self.file_type.set_halign(Gtk.Align.START)
        self.file_type.set_hexpand(True)
        self.file_type.connect('row-selected', self.on_file_type_changed)
        self.file_type.props.margin_end = 10

        self.confirm = SuggestedButton('Save')
        self.confirm.connect('clicked', self.on_save_clicked)
        self.confirm.set_halign(Gtk.Align.END)
        self.confirm.set_hexpand(False)
        self.confirm.set_sensitive(False)
        self.confirm.props.margin_end = 10

        self.cancel_button = IconButton('window-close-symbolic', 'Cancel')
        self.cancel_button.connect('clicked', self.on_cancel_clicked)
        self.cancel_button.set_halign(Gtk.Align.END)
        self.cancel_button.set_hexpand(False)

        self.connect('selection-changed', self.on_selection_changed)

        file_type_label = Gtk.Label('<b>Filetype</b>')
        file_type_label.set_use_markup(True)
        file_type_label.props.margin_end = 5
        file_type_label.get_style_context().add_class(
            Gtk.STYLE_CLASS_DIM_LABEL)

        self.extra_box = Gtk.Grid()
        self.extra_box.attach(self.file_type, 0, 0, 1, 1)
        self.extra_box.attach(self.confirm, 1, 0, 1, 1)
        self.extra_box.attach_next_to(file_type_label, self.file_type,
                                      Gtk.PositionType.LEFT, 1, 1)

        self.extra_box.set_hexpand(True)
        self.extra_box.set_halign(Gtk.Align.FILL)

    def show_controls(self):
        """Show cancel, save and file type chooser buttons."""
        self.editor_view.add_header_widget(self.extra_box)
        self.editor_view.add_header_widget(self.cancel_button,
                                           align=Gtk.Align.START)

        self.update_file_suggestion()

    def update_file_suggestion(self):
        """Suggest a name for the script to save."""
        file_type = self.file_type.get_selected_choice() or 'sh'
        self.set_current_name(time.strftime('rmlint-%FT%T%z.' + file_type))

    def on_file_type_changed(self, _):
        """Called once the user chose a different format"""
        current_path = self.get_filename()
        if not current_path:
            self.update_file_suggestion()
        else:
            try:
                path, _ = current_path.rsplit('.', 1)
                self.set_current_name(
                    path + '.' + self.file_type.get_selected_choice() or '')
            except ValueError:
                # No extension. Leave it.
                pass

    def _exit_from_save(self):
        """Preparation to go back to script view."""
        self.emit('saved')
        self.editor_view.clear_header_widgets()

    def on_cancel_clicked(self, _):
        """Signal handler for the cancel button."""
        self._exit_from_save()

    def on_save_clicked(self, _):
        """Called once the user clicked the `Save` button"""
        file_type = self.file_type.get_selected_choice()
        abs_path = self.get_filename()

        runner = self.editor_view.app_window.views['runner'].runner
        LOGGER.info('Saving script as `%s` to: %s', file_type, abs_path)
        runner.save(abs_path, file_type)
        self._exit_from_save()

    def on_selection_changed(self, _):
        """Called once a file or directory was clicked"""
        filename = self.get_filename()
        self.confirm.set_sensitive(bool(filename))

        # Make sure the user-typed extension gets set in teh type chooser also.
        name = self.get_current_name()
        *_, extension = name.rsplit('.', 1)
        self.file_type.set_selected_choice(extension)
Example #9
0
class ScriptSaverDialog(Gtk.FileChooserWidget):
    """GtkFileChooserWidget tailored for saving a `Script` instance."""

    __gsignals__ = {
        'saved': (GObject.SIGNAL_RUN_FIRST, None, ()),
    }

    def __init__(self, editor_view):
        Gtk.FileChooserWidget.__init__(self)

        self.editor_view = editor_view
        self.set_select_multiple(False)
        self.set_create_folders(False)
        self.set_action(Gtk.FileChooserAction.SAVE)
        self.set_do_overwrite_confirmation(True)

        self.file_type = MultipleChoiceButton(
            ['sh', 'json', 'csv'], 'sh', 'sh'
        )
        self.file_type.set_halign(Gtk.Align.START)
        self.file_type.set_hexpand(True)
        self.file_type.connect('row-selected', self.on_file_type_changed)
        self.file_type.props.margin_end = 10

        self.confirm = SuggestedButton('Save')
        self.confirm.connect('clicked', self.on_save_clicked)
        self.confirm.set_halign(Gtk.Align.END)
        self.confirm.set_hexpand(False)
        self.confirm.set_sensitive(False)
        self.confirm.props.margin_end = 10

        self.cancel_button = IconButton('window-close-symbolic', 'Cancel')
        self.cancel_button.connect('clicked', self.on_cancel_clicked)
        self.cancel_button.set_halign(Gtk.Align.END)
        self.cancel_button.set_hexpand(False)

        self.connect('selection-changed', self.on_selection_changed)

        file_type_label = Gtk.Label('<b>Filetype</b>')
        file_type_label.set_use_markup(True)
        file_type_label.props.margin_end = 5
        file_type_label.get_style_context().add_class(
            Gtk.STYLE_CLASS_DIM_LABEL
        )

        self.extra_box = Gtk.Grid()
        self.extra_box.attach(self.file_type, 0, 0, 1, 1)
        self.extra_box.attach(self.confirm, 1, 0, 1, 1)
        self.extra_box.attach_next_to(
            file_type_label,
            self.file_type,
            Gtk.PositionType.LEFT,
            1,
            1
        )

        self.extra_box.set_hexpand(True)
        self.extra_box.set_halign(Gtk.Align.FILL)

    def show_controls(self):
        """Show cancel, save and file type chooser buttons."""
        self.editor_view.add_header_widget(self.extra_box)
        self.editor_view.add_header_widget(
            self.cancel_button, align=Gtk.Align.START
        )

        self.update_file_suggestion()

    def update_file_suggestion(self):
        """Suggest a name for the script to save."""
        file_type = self.file_type.get_selected_choice() or 'sh'
        self.set_current_name(time.strftime('rmlint-%FT%T%z.' + file_type))

    def on_file_type_changed(self, _):
        """Called once the user chose a different format"""
        current_path = self.get_filename()
        if not current_path:
            self.update_file_suggestion()
        else:
            try:
                path, _ = current_path.rsplit('.', 1)
                self.set_current_name(
                    path + '.' + self.file_type.get_selected_choice() or ''
                )
            except ValueError:
                # No extension. Leave it.
                pass

    def _exit_from_save(self):
        """Preparation to go back to script view."""
        self.emit('saved')
        self.editor_view.clear_header_widgets()

    def on_cancel_clicked(self, _):
        """Signal handler for the cancel button."""
        self._exit_from_save()

    def on_save_clicked(self, _):
        """Called once the user clicked the `Save` button"""
        file_type = self.file_type.get_selected_choice()
        abs_path = self.get_filename()

        runner = self.editor_view.app_window.views['runner'].runner
        LOGGER.info('Saving script as `%s` to: %s', file_type, abs_path)
        runner.save(abs_path, file_type)
        self._exit_from_save()

    def on_selection_changed(self, _):
        """Called once a file or directory was clicked"""
        filename = self.get_filename()
        self.confirm.set_sensitive(bool(filename))

        # Make sure the user-typed extension gets set in teh type chooser also.
        name = self.get_current_name()
        *_, extension = name.rsplit('.', 1)
        self.file_type.set_selected_choice(extension)
Example #10
0
class ResultActionBar(Gtk.ActionBar):
    """Down right bar with the controls"""
    __gsignals__ = {
        'generate-all-script': (GObject.SIGNAL_RUN_FIRST, None, ()),
        'generate-filtered-script': (GObject.SIGNAL_RUN_FIRST, None, ()),
        'generate-selection-script': (GObject.SIGNAL_RUN_FIRST, None, ())
    }

    def __init__(self, view):
        Gtk.ActionBar.__init__(self)

        left_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        left_box.get_style_context().add_class("linked")
        self.pack_start(left_box)

        self.refresh_button = IconButton('view-refresh-symbolic')
        self.settings_button = IconButton('system-run-symbolic')

        self.refresh_button.connect(
            'clicked', lambda _: view.app_window.views['runner'].rerun()
        )
        self.settings_button.connect(
            'clicked', lambda _: view.app_window.views.switch('settings')
        )

        left_box.pack_start(self.refresh_button, False, False, 0)
        left_box.pack_start(self.settings_button, False, False, 0)

        right_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        right_box.get_style_context().add_class(
            Gtk.STYLE_CLASS_LINKED
        )

        self.script_btn = IconButton(
            'emblem-documents-symbolic', 'Render script from'
        )
        self.script_btn.connect(
            'clicked', self.on_generate_script
        )

        self.script_type_btn = MultipleChoiceButton(
            ['All', 'Filtered', 'Selected'], 'All', 'All'
        )
        self.script_type_btn.set_relief(Gtk.ReliefStyle.NORMAL)

        right_box.pack_start(self.script_btn, True, True, 0)
        right_box.pack_start(self.script_type_btn, True, False, 0)

        self.pack_end(right_box)
        self.set_sensitive(False)

    def on_generate_script(self, _):
        """Called when the left side of the compound button was clicked."""
        choice = self.script_type_btn.get_selected_choice().lower()

        if choice == 'all':
            self.emit('generate-all-script')
        elif choice == 'filtered':
            self.emit('generate-filtered-script')
        elif choice == 'selected':
            self.emit('generate-selection-script')
        else:
            LOGGER.error('Bug: bad choice selection: %s', choice)

    def set_sensitive(self, mode):
        """Set the gen-script button (non)-sensitive and (non)-suggested"""
        btn_ctx = self.script_btn.get_style_context()
        type_ctx = self.script_type_btn.get_style_context()

        if mode:
            btn_ctx.add_class(Gtk.STYLE_CLASS_SUGGESTED_ACTION)
            type_ctx.add_class(Gtk.STYLE_CLASS_SUGGESTED_ACTION)
        else:
            btn_ctx.remove_class(Gtk.STYLE_CLASS_SUGGESTED_ACTION)
            type_ctx.remove_class(Gtk.STYLE_CLASS_SUGGESTED_ACTION)

        self.script_btn.set_sensitive(mode)
        self.script_type_btn.set_sensitive(mode)

    def is_sensitive(self):
        return self.script_btn.is_sensitive()