def __init__(self): tweaks = [AutostartTitle()] self.asm = AutostartManager() files = self.asm.get_user_autostart_files() for f in files: try: df = Gio.DesktopAppInfo.new_from_filename(f) except TypeError: logging.warning("Error loading desktopfile: %s" % f) continue if not AutostartFile(df).is_start_at_login_enabled(): continue sdf = _StartupTweak(df) sdf.btn.connect("clicked", self._on_remove_clicked, sdf, df) tweaks.append(sdf) add = AddStartupTweak() add.btn.connect("clicked", self._on_add_clicked) tweaks.append(add) ListBoxTweakGroup.__init__(self, _("Startup Applications"), *tweaks, css_class='tweak-group-startup') self.set_header_func(_list_header_func, None) self.connect("row-activated", lambda b, row: add.btn.activate() if row == add else None)
def __init__(self): tweaks = [] self.asm = AutostartManager() files = self.asm.get_user_autostart_files() for f in files: try: df = Gio.DesktopAppInfo.new_from_filename(f) except TypeError: logging.warning("Error loading desktopfile: %s" % f) continue sdf = _StartupTweak(df) sdf.btn.connect("clicked", self._on_remove_clicked, sdf, df) tweaks.append( sdf ) add = AddStartupTweak() add.btn.connect("clicked", self._on_add_clicked) tweaks.append(add) ListBoxTweakGroup.__init__(self, _("Startup Applications"), *tweaks, css_class='tweak-group-white') self.set_header_func(_list_header_func, None)
def __init__(self): tweaks = [] self.asm = AutostartManager() files = self.asm.get_user_autostart_files() for f in files: try: df = Gio.DesktopAppInfo.new_from_filename(f) except TypeError: logging.warning("Error loading desktopfile: %s" % f) continue if not AutostartFile(df).is_start_at_login_enabled(): continue sdf = _StartupTweak(df) sdf.btn.connect("clicked", self._on_remove_clicked, sdf, df) tweaks.append( sdf ) add = AddStartupTweak() add.btn.connect("clicked", self._on_add_clicked) tweaks.append(add) ListBoxTweakGroup.__init__(self, _("Startup Applications"), *tweaks, css_class='tweak-group-startup') self.set_header_func(_list_header_func, None) self.connect("row-activated", lambda b, row: add.btn.activate() if row == add else None)
class AutostartListBoxTweakGroup(ListBoxTweakGroup): def __init__(self): tweaks = [] self.asm = AutostartManager() files = self.asm.get_user_autostart_files() for f in files: try: df = Gio.DesktopAppInfo.new_from_filename(f) except TypeError: logging.warning("Error loading desktopfile: %s" % f) continue sdf = _StartupTweak(df) sdf.btn.connect("clicked", self._on_remove_clicked, sdf, df) tweaks.append( sdf ) add = AddStartupTweak() add.btn.connect("clicked", self._on_add_clicked) tweaks.append(add) ListBoxTweakGroup.__init__(self, _("Startup Applications"), *tweaks, css_class='tweak-group-white') self.set_header_func(_list_header_func, None) def _on_remove_clicked(self, btn, widget, df): self.remove(widget) AutostartFile(df).update_start_at_login(False) def _on_add_clicked(self, btn): a = _AppChooser( self.main_window, set(self._get_running_executables())) a.show_all() resp = a.run() if resp == Gtk.ResponseType.OK: df = a.get_selected_app() if df: AutostartFile(df).update_start_at_login(True) sdf = _StartupTweak(df) sdf.btn.connect("clicked", self._on_remove_clicked, sdf, df) self.add_tweak_row(sdf, 0).show_all() a.destroy() def _get_running_executables(self): exes = [] cmd = subprocess.Popen([ 'ps','-e','-w','-w','-U', os.getlogin(),'-o','cmd'], stdout=subprocess.PIPE) out = cmd.communicate()[0] for l in out.split('\n'): exe = l.split(' ')[0] if exe and exe[0] != '[': #kernel process exes.append( os.path.basename(exe) ) return exes
class DesktopIconTweak(GSettingsSwitchTweak): def __init__(self, **options): GSettingsSwitchTweak.__init__(self, "org.gnome.desktop.background", "show-desktop-icons", **options) #when the user enables nautilus to draw the desktop icons, set nautilus #to autostart self.nautilus = AutostartManager("nautilus.desktop", autostart_desktop_filename="nautilus-autostart.desktop", exec_cmd="nautilus -n") #we only need to install the desktop file on old versions of nautilus/gnome-session. #new ones use the new AutostartCondition and watch the gsettings key automatically if not self.nautilus.uses_autostart_condition("GSettings"): self.settings.connect('changed::'+self.key_name, self._on_setting_changed) def _on_setting_changed(self, setting, key): self.nautilus.update_start_at_login( self.settings.get_boolean(key))
class AutostartListBoxTweakGroup(ListBoxTweakGroup): def __init__(self): tweaks = [AutostartTitle()] self.asm = AutostartManager() files = self.asm.get_user_autostart_files() for f in files: try: df = Gio.DesktopAppInfo.new_from_filename(f) except TypeError: logging.warning("Error loading desktopfile: %s" % f) continue if not AutostartFile(df).is_start_at_login_enabled(): continue sdf = _StartupTweak(df) sdf.btn.connect("clicked", self._on_remove_clicked, sdf, df) tweaks.append(sdf) add = AddStartupTweak() add.btn.connect("clicked", self._on_add_clicked) tweaks.append(add) ListBoxTweakGroup.__init__(self, _("Startup Applications"), *tweaks, css_class='tweak-group-startup') self.set_header_func(_list_header_func, None) self.connect("row-activated", lambda b, row: add.btn.activate() if row == add else None) def _on_remove_clicked(self, btn, widget, df): self.remove(widget) AutostartFile(df).update_start_at_login(False) def _on_add_clicked(self, btn): Gio.Application.get_default().mark_busy() startup_apps = set() self.foreach(lambda row: startup_apps.add(row.app_id) if type(row) is _StartupTweak else None) a = _AppChooser(self.main_window, set(self._get_running_executables()), startup_apps) a.show_all() Gio.Application.get_default().unmark_busy() resp = a.run() if resp == Gtk.ResponseType.OK: df = a.get_selected_app() if df: AutostartFile(df).update_start_at_login(True) sdf = _StartupTweak(df) sdf.btn.connect("clicked", self._on_remove_clicked, sdf, df) self.add_tweak_row(sdf, 0).show_all() a.destroy() def _get_running_executables(self): exes = [] cmd = subprocess.Popen( ['ps', '-e', '-w', '-w', '-U', str(os.getuid()), '-o', 'cmd'], stdout=subprocess.PIPE) out = cmd.communicate()[0] for l in out.decode('utf8').split('\n'): exe = l.split(' ')[0] if exe and exe[0] != '[': #kernel process exes.append(os.path.basename(exe)) return exes