def do_startup(self, **kw): Gtk.Application.do_startup(self, **kw) # Make tranlsating strings possible: # (We use the same message catalouge as rmlint) gettext.install('rmlint') rel_dir = os.path.dirname(__file__) resource_file = os.path.join(rel_dir, 'resources/shredder.gresource') LOGGER.info('Loading resources from: ' + resource_file) resource_bundle = Gio.Resource.load(resource_file) Gio.resources_register(resource_bundle) # Load the application CSS files. css_data = Gio.resources_lookup_data( '/org/gnome/shredder/shredder.css', 0) try: load_css_from_data(css_data.get_data()) except Exception as err: LOGGER.warning("Failed to load css data: " + str(err)) # Init the config system self.settings = Gio.Settings.new('org.gnome.Shredder') self.win = MainWindow(self) self.add_action( _create_action('settings', lambda *_: self.win.views.switch('settings'))) self.add_action( _create_action('about', lambda *_: AboutDialog(self.win).show_all())) self.add_action( _create_action('search', lambda *_: self.win.views.set_search_mode(True))) self.add_action( _create_action('activate', lambda *_: self.win.views.do_default_action())) self.add_action(_create_action('quit', lambda *_: self.quit())) self.set_accels_for_action('app.quit', ['<Ctrl>Q']) self.set_accels_for_action('app.search', ['<Ctrl>F']) self.set_accels_for_action('app.activate', ['<Ctrl>Return']) # Set the fallback window title. # This is only used if no .desktop file is provided. self.win.set_wmclass(APP_TITLE, APP_TITLE) # Load the application icon self.win.set_default_icon(_load_app_icon()) LOGGER.debug('Instancing views.') self.win.views.add_view(SettingsView(self), 'settings') self.win.views.add_view(LocationView(self), 'locations') self.win.views.add_view(RunnerView(self), 'runner') self.win.views.add_view(EditorView(self), 'editor') LOGGER.debug('Done instancing views.') initial_view = 'locations' if self.cmd_opts.tagged or self.cmd_opts.untagged: self.win.views['runner'].trigger_run(self.cmd_opts.untagged or [], self.cmd_opts.tagged or []) initial_view = 'runner' if self.cmd_opts.show_settings: initial_view = 'settings' for path in self.cmd_opts.locations or []: self.win.views['locations'].add_recent_item(path) if self.cmd_opts.script: self.win.views['editor'].override_script( Script(self.cmd_opts.script)) initial_view = 'editor' # Set the default view visible at startup self.win.views.switch(initial_view) self.win.show_all()
def __init__(self, win): View.__init__(self, win) self._last_runner = None self.script = Script.create_dummy() control_grid = Gtk.Grid() control_grid.set_hexpand(False) control_grid.set_vexpand(False) control_grid.set_halign(Gtk.Align.CENTER) control_grid.set_valign(Gtk.Align.CENTER) self.info_label = Gtk.Label(use_markup=True, justify=Gtk.Justification.CENTER) self.info_label.get_style_context().add_class( Gtk.STYLE_CLASS_DIM_LABEL) self.set_info_review_text() self.icon_stack = _create_icon_stack() self.text_view, buffer_ = _create_source_view() self.text_view.set_name('ShredderScriptEditor') self.text_view.set_vexpand(True) self.text_view.set_valign(Gtk.Align.FILL) self.text_view.set_hexpand(True) self.text_view.set_halign(Gtk.Align.FILL) self.save_button = OverlaySaveButton() self.save_button.add(scrolled(self.text_view)) self.save_chooser = ScriptSaverDialog(self) def on_save_button_clicked(_): """Switch to the save dialog in the stack.""" self.set_search_mode(False) self.left_stack.set_visible_child_name('chooser') self.save_chooser.show_controls() self.set_info_help_text() self.set_correct_icon() self.run_button.set_sensitive(False) def on_save_clicked(_): """Switch back when the user has saved.""" self.left_stack.set_visible_child_name('script') self.set_info_review_text() self.set_correct_icon() self.run_button.set_sensitive(True) self.save_button.connect('save-clicked', on_save_button_clicked) self.save_chooser.connect('saved', on_save_clicked) buffer_.create_tag("original", weight=Pango.Weight.BOLD) buffer_.create_tag("normal") self.run_label = RunningLabel() self.run_label.set_hexpand(False) self.run_label.set_halign(Gtk.Align.FILL) self.left_stack = Gtk.Stack() self.left_stack.set_transition_type(Gtk.StackTransitionType.SLIDE_UP) spinner = Gtk.Spinner() spinner.start() self.left_stack.add_named(spinner, 'loading') self.left_stack.add_named(self.save_button, 'script') self.left_stack.add_named(self.save_chooser, 'chooser') self.left_stack.add_named(scrolled(self.run_label), 'list') separator = Gtk.Separator(orientation=Gtk.Orientation.VERTICAL) left_pane = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) left_pane.pack_start(self.left_stack, True, True, 0) left_pane.pack_start(separator, False, False, 0) self.run_button = RunButton('user-trash-symbolic', 'Run Script') self.run_button.button.connect('clicked', self.on_run_script_clicked) self.run_button.set_halign(Gtk.Align.CENTER) self.run_button.connect('notify::dry-run', lambda *_: self.set_correct_icon()) control_grid.attach(self.info_label, 0, 0, 1, 1) control_grid.attach_next_to(self.run_button, self.info_label, Gtk.PositionType.BOTTOM, 1, 1) control_grid.attach_next_to(self.icon_stack, self.info_label, Gtk.PositionType.TOP, 1, 1) control_grid.set_border_width(15) self.stack = Gtk.Stack() self.stack.set_transition_type(Gtk.StackTransitionType.SLIDE_UP) self.stack.add_named(control_grid, 'danger') self.stack.add_named(_create_running_screen(), 'progressing') self.stack.add_named(_create_finished_screen(self._switch_back), 'finished') self.left_stack.set_visible_child_name('script') paned = Gtk.Paned() paned.pack1(left_pane, True, True) paned.pack2(self.stack, True, True) paned.props.position = 920 self.add(paned) self._last_search = None self.search_entry.connect('search-changed', self.on_search_changed) try: self.search_entry.connect('next-match', self.on_search_changed) except TypeError: LOGGER.warning( 'Old gtk version; skipping through matches will not work.')
def on_replay_finish(self, _, runner): """Called once ``rmlint --replay`` finished running.""" LOGGER.info('Loading script from temporary directory') self.override_script(Script(runner.get_sh_path()))
def __init__(self, win): View.__init__(self, win) self._last_runner = None self.script = Script.create_dummy() control_grid = Gtk.Grid() control_grid.set_hexpand(False) control_grid.set_vexpand(False) control_grid.set_halign(Gtk.Align.CENTER) control_grid.set_valign(Gtk.Align.CENTER) self.info_label = Gtk.Label( use_markup=True, justify=Gtk.Justification.CENTER ) self.info_label.get_style_context().add_class( Gtk.STYLE_CLASS_DIM_LABEL ) self.set_info_review_text() self.icon_stack = _create_icon_stack() self.text_view, buffer_ = _create_source_view() self.text_view.set_name('ShredderScriptEditor') self.text_view.set_vexpand(True) self.text_view.set_valign(Gtk.Align.FILL) self.text_view.set_hexpand(True) self.text_view.set_halign(Gtk.Align.FILL) self.save_button = OverlaySaveButton() self.save_button.add(scrolled(self.text_view)) self.save_chooser = ScriptSaverDialog(self) def on_save_button_clicked(_): """Switch to the save dialog in the stack.""" self.set_search_mode(False) self.left_stack.set_visible_child_name('chooser') self.save_chooser.show_controls() self.set_info_help_text() self.set_correct_icon() self.run_button.set_sensitive(False) def on_save_clicked(_): """Switch back when the user has saved.""" self.left_stack.set_visible_child_name('script') self.set_info_review_text() self.set_correct_icon() self.run_button.set_sensitive(True) self.save_button.connect( 'save-clicked', on_save_button_clicked ) self.save_chooser.connect( 'saved', on_save_clicked ) buffer_.create_tag("original", weight=Pango.Weight.BOLD) buffer_.create_tag("normal") self.run_label = RunningLabel() self.run_label.set_hexpand(False) self.run_label.set_halign(Gtk.Align.FILL) self.left_stack = Gtk.Stack() self.left_stack.set_transition_type( Gtk.StackTransitionType.SLIDE_UP ) spinner = Gtk.Spinner() spinner.start() self.left_stack.add_named(spinner, 'loading') self.left_stack.add_named(self.save_button, 'script') self.left_stack.add_named(self.save_chooser, 'chooser') self.left_stack.add_named(scrolled(self.run_label), 'list') separator = Gtk.Separator(orientation=Gtk.Orientation.VERTICAL) left_pane = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) left_pane.pack_start(self.left_stack, True, True, 0) left_pane.pack_start(separator, False, False, 0) self.run_button = RunButton( 'user-trash-symbolic', 'Run Script' ) self.run_button.button.connect('clicked', self.on_run_script_clicked) self.run_button.set_halign(Gtk.Align.CENTER) self.run_button.connect( 'notify::dry-run', lambda *_: self.set_correct_icon() ) control_grid.attach(self.info_label, 0, 0, 1, 1) control_grid.attach_next_to( self.run_button, self.info_label, Gtk.PositionType.BOTTOM, 1, 1 ) control_grid.attach_next_to( self.icon_stack, self.info_label, Gtk.PositionType.TOP, 1, 1 ) control_grid.set_border_width(15) self.stack = Gtk.Stack() self.stack.set_transition_type(Gtk.StackTransitionType.SLIDE_UP) self.stack.add_named(control_grid, 'danger') self.stack.add_named(_create_running_screen(), 'progressing') self.stack.add_named( _create_finished_screen(self._switch_back), 'finished' ) self.left_stack.set_visible_child_name('script') paned = Gtk.Paned() paned.pack1(left_pane, True, True) paned.pack2(self.stack, True, True) paned.props.position = 920 self.add(paned) self._last_search = None self.search_entry.connect( 'search-changed', self.on_search_changed ) try: self.search_entry.connect( 'next-match', self.on_search_changed ) except TypeError: LOGGER.warning('Old gtk version; skipping through matches will not work.')