[gnome-tweak-tool/startup-apps] Add ability to modify startup applications
- From: John Stowers <jstowers src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-tweak-tool/startup-apps] Add ability to modify startup applications
- Date: Sun, 18 Aug 2013 19:57:21 +0000 (UTC)
commit 0eb146e1b1f571ef094443948dbd0754711eba0a
Author: John Stowers <john stowers gmail com>
Date: Fri Aug 9 11:05:51 2013 +0200
Add ability to modify startup applications
data/shell.css | 6 +
gtweak/tweakmodel.py | 7 +-
gtweak/tweaks/tweak_group_startup.py | 187 ++++++++++++++++++++++++++++++++++
gtweak/tweakview.py | 2 +-
gtweak/utils.py | 8 ++-
5 files changed, 207 insertions(+), 3 deletions(-)
---
diff --git a/data/shell.css b/data/shell.css
index 9dfa581..387eb2e 100644
--- a/data/shell.css
+++ b/data/shell.css
@@ -30,6 +30,12 @@
padding-top: 20px;
}
+.tweak-group-white,
+.tweak-white,
+.tweak-white:hover {
+ background-color: white;
+}
+
/* NOT WORKING
.main-container {
padding: 20px;
diff --git a/gtweak/tweakmodel.py b/gtweak/tweakmodel.py
index ce5d4d2..4d2fa4f 100644
--- a/gtweak/tweakmodel.py
+++ b/gtweak/tweakmodel.py
@@ -74,6 +74,9 @@ class Tweak(object):
self._notification = Notification(summary, desc)
class TweakGroup(object):
+
+ main_window = None
+
def __init__(self, name, *tweaks, **options):
self.name = name
self.tweaks = [t for t in tweaks if t.loaded]
@@ -102,7 +105,7 @@ class TweakModel(Gtk.ListStore):
def tweak_groups(self):
return (row[TweakModel.COLUMN_TWEAK] for row in self)
- def load_tweaks(self):
+ def load_tweaks(self, main_window):
tweak_files = [
os.path.splitext(os.path.split(f)[-1])[0]
for f in glob.glob(os.path.join(self._tweak_dir, "tweak_group_*.py"))]
@@ -129,9 +132,11 @@ class TweakModel(Gtk.ListStore):
schemas = SchemaList()
for g in groups:
+ g.main_window = main_window
if g.tweaks:
self.add_tweak_group(g)
for i in g.tweaks:
+ i.main_window = main_window
try:
schemas.insert(i.key_name, i.schema_name)
except:
diff --git a/gtweak/tweaks/tweak_group_startup.py b/gtweak/tweaks/tweak_group_startup.py
new file mode 100644
index 0000000..8041171
--- /dev/null
+++ b/gtweak/tweaks/tweak_group_startup.py
@@ -0,0 +1,187 @@
+# This file is part of gnome-tweak-tool.
+#
+# Copyright (c) 2011 John Stowers
+#
+# gnome-tweak-tool is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# gnome-tweak-tool is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with gnome-tweak-tool. If not, see <http://www.gnu.org/licenses/>.
+from __future__ import print_function
+
+import os.path
+import subprocess
+
+from gi.repository import Gtk, GLib, Gio
+
+from gtweak.tweakmodel import Tweak
+from gtweak.widgets import ListBoxTweakGroup, UI_BOX_SPACING
+from gtweak.utils import AutostartManager
+
+def _list_header_func(row, before, user_data):
+ if before and not row.get_header():
+ row.set_header (Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL))
+
+class _AppChooser(Gtk.Dialog):
+ def __init__(self, main_window, running_exes):
+ Gtk.Dialog.__init__(self)
+
+ self._running = {}
+ self._all = {}
+
+ lb = Gtk.ListBox()
+ lb.props.margin = 5
+ lb.set_sort_func(self._sort_apps, None)
+ lb.set_header_func(_list_header_func, None)
+
+ apps = Gio.app_info_get_all()
+ for a in apps:
+ if a.should_show():
+ running = a.get_executable() in running_exes
+ w = self._build_widget(
+ a,
+ 'running' if running else '')
+ lb.add(w)
+ self._all[w] = a
+ self._running[w] = running
+
+ sw = Gtk.ScrolledWindow()
+ sw.props.hscrollbar_policy = Gtk.PolicyType.NEVER
+ sw.add(lb)
+
+ self.add_button("Add Application", Gtk.ResponseType.OK)
+
+ hb = Gtk.HeaderBar()
+ hb.props.show_close_button = True
+ hb.props.title = "Extensions"
+ self.set_titlebar(hb)
+
+ self.get_content_area().pack_start(sw, True, True, 0)
+ self.set_modal(True)
+ self.set_transient_for(main_window)
+ self.set_size_request(400,300)
+
+ self.listbox = lb
+
+ def _sort_apps(self, a, b, user_data):
+ if self._running.get(a) and not self._running.get(b):
+ return -1
+ return 1
+
+ def _build_widget(self, a, extra):
+ row = Gtk.ListBoxRow()
+ g = Gtk.Grid()
+ img = Gtk.Image.new_from_gicon(a.get_icon(),Gtk.IconSize.DIALOG)
+ g.attach(img, 0, 0, 1, 1)
+ img.props.hexpand = False
+ lbl = Gtk.Label(a.get_name(), xalign=0)
+ g.attach_next_to(lbl,img,Gtk.PositionType.RIGHT,1,1)
+ lbl.props.hexpand = True
+ lbl.props.halign = Gtk.Align.START
+ lbl.props.vexpand = False
+ lbl.props.valign = Gtk.Align.CENTER
+ if extra:
+ g.attach_next_to(
+ Gtk.Label(extra),
+ lbl,Gtk.PositionType.RIGHT,1,1)
+ row.add(g)
+ #row.get_style_context().add_class('tweak-white')
+ return row
+
+class _StartupTweak(Gtk.ListBoxRow, Tweak):
+ def __init__(self, df, **options):
+
+ Gtk.ListBoxRow.__init__(self)
+ Tweak.__init__(self,
+ df.get_name(),
+ df.get_description(),
+ **options)
+
+ grid = Gtk.Grid(column_spacing=10)
+
+ img = Gtk.Image.new_from_gicon(df.get_icon(),Gtk.IconSize.DIALOG)
+ grid.attach(img, 0, 0, 1, 1)
+
+ lbl = Gtk.Label(df.get_name(), xalign=0.0)
+ grid.attach_next_to(lbl,img,Gtk.PositionType.RIGHT,1,1)
+ lbl.props.hexpand = True
+ lbl.props.halign = Gtk.Align.START
+
+ btn = Gtk.Button("Remove")
+ grid.attach_next_to(btn,lbl,Gtk.PositionType.RIGHT,1,1)
+ btn.props.vexpand = False
+ btn.props.valign = Gtk.Align.CENTER
+
+ self.add(grid)
+
+ self.props.margin = 5
+ self.get_style_context().add_class('tweak-white')
+
+ self.btn = btn
+
+class AutostartListBoxTweakGroup(ListBoxTweakGroup):
+ def __init__(self):
+ tweaks = []
+
+ files = AutostartManager.get_user_autostart_files()
+ for f in files:
+ df = Gio.DesktopAppInfo.new_from_filename(f)
+ sdf = _StartupTweak(df)
+ sdf.btn.connect("clicked", self._on_remove_clicked, sdf, df)
+ tweaks.append( sdf )
+
+ ListBoxTweakGroup.__init__(self,
+ "Startup Applications",
+ *tweaks,
+ css_class='tweak-group-white')
+ self.set_header_func(_list_header_func, None)
+
+ btn = Gtk.Button("")
+ btn.get_style_context().remove_class("button")
+ img = Gtk.Image()
+ img.set_from_icon_name("list-add-symbolic", Gtk.IconSize.BUTTON)
+ btn.set_image(img)
+ btn.props.always_show_image = True
+ btn.connect("clicked", self._on_add_clicked)
+ #b.props.hexpand = True
+ #b.props.vexpand = True
+ self.add(btn)
+
+ def _on_remove_clicked(self, btn, widget, df):
+ self.remove(widget)
+
+ def _on_add_clicked(self, btn):
+ a = _AppChooser(
+ self.main_window,
+ set(self._get_running_executables()))
+ a.show_all()
+ a.run()
+ 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
+
+
+
+
+TWEAK_GROUPS = [
+ AutostartListBoxTweakGroup(),
+]
diff --git a/gtweak/tweakview.py b/gtweak/tweakview.py
index 7990b01..193ff96 100644
--- a/gtweak/tweakview.py
+++ b/gtweak/tweakview.py
@@ -63,7 +63,7 @@ class Window(Gtk.ApplicationWindow):
self.load_css()
self._model = model
- self._model.load_tweaks()
+ self._model.load_tweaks(self)
self.load_model_data()
self.connect("key-press-event", self._on_key_press)
diff --git a/gtweak/utils.py b/gtweak/utils.py
index 4eb19ea..73517a4 100644
--- a/gtweak/utils.py
+++ b/gtweak/utils.py
@@ -20,7 +20,7 @@ import logging
import tempfile
import shutil
import subprocess
-import dbus
+import glob
import gtweak
from gtweak.gsettings import GSettingsSetting
@@ -148,6 +148,12 @@ class AutostartManager:
dirs.extend(GLib.get_system_data_dirs())
return [os.path.join(d, "applications", self.desktop_filename) for d in dirs]
+ @staticmethod
+ def get_user_autostart_files():
+ return glob.glob(
+ os.path.join(
+ GLib.get_user_config_dir(), "autostart", "*.desktop"))
+
def get_autostart_condition(self):
for f in self._get_system_autostart_files():
if os.path.exists(f):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]