[gnome-tweak-tool] GMenu
- From: John Stowers <jstowers src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-tweak-tool] GMenu
- Date: Sun, 21 Jul 2013 15:58:16 +0000 (UTC)
commit c144ad140034335b3d79abc362ce0479e9745ad6
Author: Alex Muñoz <AlexMuDoz gmail com>
Date: Fri Jun 7 23:30:18 2013 -0400
GMenu
data/shell.ui | 25 +++++++-
gnome-tweak-tool | 9 ++-
gtweak/app.py | 109 +++++++++++++++++++++++++++++++
gtweak/tweakmodel.py | 16 ++++-
gtweak/tweaks/tweak_shell_extensions.py | 1 -
gtweak/tweakview.py | 10 +---
gtweak/utils.py | 23 ++++++-
7 files changed, 176 insertions(+), 17 deletions(-)
---
diff --git a/data/shell.ui b/data/shell.ui
index 5699a95..e89852c 100644
--- a/data/shell.ui
+++ b/data/shell.ui
@@ -1,7 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
- <object class="GtkWindow" id="main_window">
+ <menu id="appmenu">
+ <section>
+ <item>
+ <attribute name='label' translatable='yes'>_Reset to Defaults</attribute>
+ <attribute name='action'>app.reset</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name='label' translatable='yes'>_Help</attribute>
+ <attribute name='action'>app.help</attribute>
+ </item>
+ <item>
+ <attribute name='label' translatable='yes'>_About Tweak Tool</attribute>
+ <attribute name='action'>app.about</attribute>
+ </item>
+ <item>
+ <attribute name='label' translatable='yes'>_Quit</attribute>
+ <attribute name='action'>app.quit</attribute>
+ <attribute name='accel'><Primary>q</attribute>
+ </item>
+ </section>
+ </menu>
+ <object class="GtkApplicationWindow" id="main_window">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Tweak Tool</property>
<property name="resizable">True</property>
diff --git a/gnome-tweak-tool b/gnome-tweak-tool
index 6104959..eb7bafd 100755
--- a/gnome-tweak-tool
+++ b/gnome-tweak-tool
@@ -18,11 +18,14 @@ import optparse
import logging
import locale
import gettext
+import sys
import gi
gi.require_version("Gtk", "3.0")
import gtweak
+from gi.repository import GObject
+GObject.threads_init()
if __name__ == '__main__':
parser = optparse.OptionParser()
@@ -71,6 +74,8 @@ if __name__ == '__main__':
locale.setlocale(locale.LC_ALL, None)
gettext.install(gtweak.APP_NAME, LOCALE_DIR, names=('gettext', 'ngettext'))
- from gtweak.mainwindow import MainWindow
- MainWindow()
+ from gtweak.app import GnomeTweakTool
+ app = GnomeTweakTool()
+ exit_status = app.run(None)
+ sys.exit(exit_status)
diff --git a/gtweak/app.py b/gtweak/app.py
new file mode 100644
index 0000000..8e7d7bd
--- /dev/null
+++ b/gtweak/app.py
@@ -0,0 +1,109 @@
+# 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/>.
+
+import os.path
+
+from gi.repository import Gtk
+from gi.repository import Gio
+
+import gtweak
+from gtweak.tweakmodel import TweakModel
+from gtweak.tweakview import TweakView
+from gtweak.utils import SchemaList
+
+class GnomeTweakTool(Gtk.Application):
+ def __init__(self):
+ Gtk.Application.__init__(self,application_id="org.gnome.TweakTool")
+
+ def do_activate(self):
+ self.win = self.builder.get_object('main_window')
+ self.win.set_position(Gtk.WindowPosition.CENTER)
+ self.win.set_application(self)
+ self.win.set_size_request(720, 580)
+ toolbar = self.builder.get_object('toolbar')
+ toolbar.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)
+
+ model = TweakModel()
+ view = TweakView(self.builder, model)
+ self.builder.get_object('overview_sw').add(view.treeview)
+
+ self.win.show_all()
+ view.run()
+
+ def do_startup(self):
+ Gtk.Application.do_startup(self)
+
+ self.builder = Gtk.Builder()
+ assert(os.path.exists(gtweak.PKG_DATA_DIR))
+ filename = os.path.join(gtweak.PKG_DATA_DIR, 'shell.ui')
+ self.builder.add_from_file(filename)
+
+ appmenu = self.builder.get_object('appmenu')
+ self.set_app_menu(appmenu)
+
+ reset_action = Gio.SimpleAction.new("reset", None)
+ reset_action.connect("activate", self.reset_cb)
+ self.add_action(reset_action)
+
+ help_action = Gio.SimpleAction.new("help", None)
+ help_action.connect("activate", self.help_cb)
+ self.add_action(help_action)
+
+ about_action = Gio.SimpleAction.new("about", None)
+ about_action.connect("activate", self.about_cb)
+ self.add_action(about_action)
+
+ quit_action = Gio.SimpleAction.new("quit", None)
+ quit_action.connect("activate", self.quit_cb)
+ self.add_action(quit_action)
+
+
+ def reset_cb(self, action, parameter):
+ dialog = Gtk.MessageDialog(self.win,0, Gtk.MessageType.QUESTION,
+ Gtk.ButtonsType.OK_CANCEL, "Reset to Defaults")
+ dialog.format_secondary_text("Reset all tweak settings to the original default state?")
+ response = dialog.run()
+ if response == Gtk.ResponseType.OK:
+ s = SchemaList()
+ s.reset()
+ dialog.destroy()
+
+
+ def help_cb(self, action, parameter):
+ print "This does nothing. It is only a demonstration."
+
+ def about_cb(self, action, parameter):
+ aboutdialog = Gtk.AboutDialog()
+ aboutdialog.set_title("About Gnome Tweak Tool")
+ aboutdialog.set_program_name("Gnome Tweak Tool")
+ aboutdialog.set_copyright("Copyright \xc2\xa9 2011 - 2013 John Stowers.")
+ aboutdialog.set_logo_icon_name("gnome-tweak-tool")
+ aboutdialog.set_website("http://live.gnome.org/GnomeTweakTool")
+ aboutdialog.set_website_label("Homepage")
+ aboutdialog.set_license_type(Gtk.License.GPL_3_0)
+
+ AUTHORS = [
+ "John Stowers <john stowers gmail com>"
+ ]
+
+ aboutdialog.set_authors(AUTHORS)
+ aboutdialog.connect("response", lambda w, r: aboutdialog.destroy())
+ aboutdialog.show()
+
+ def quit_cb(self, action, parameter):
+ self.quit()
+
diff --git a/gtweak/tweakmodel.py b/gtweak/tweakmodel.py
index 904ce15..d2b472f 100644
--- a/gtweak/tweakmodel.py
+++ b/gtweak/tweakmodel.py
@@ -20,7 +20,7 @@ import glob
import os.path
import gtweak
-
+from gtweak.utils import SchemaList
from gi.repository import Gtk
def N_(x): return x
@@ -149,13 +149,23 @@ class TweakModel(Gtk.ListStore):
for mod in [getattr(mods, file_name) for file_name in tweak_files]:
groups.extend( getattr(mod, "TWEAK_GROUPS", []) )
tweaks.extend( getattr(mod, "TWEAKS", []) )
-
+
+ schemas = SchemaList()
+
for g in groups:
if g.tweaks:
self.add_tweak_group(g)
-
+ for i in g.tweaks:
+ try:
+ schemas.insert(i.key_name, i.schema_name)
+ except:
+ pass
for t in tweaks:
self.add_tweak_auto_to_group(t)
+ try:
+ schemas.insert(t.key_name, t.schema_name)
+ except:
+ pass
def add_tweak_group(self, tweakgroup):
if tweakgroup.name in self._tweak_group_names:
diff --git a/gtweak/tweaks/tweak_shell_extensions.py b/gtweak/tweaks/tweak_shell_extensions.py
index 48fa475..3a257bb 100644
--- a/gtweak/tweaks/tweak_shell_extensions.py
+++ b/gtweak/tweaks/tweak_shell_extensions.py
@@ -17,7 +17,6 @@ from gtweak.widgets import FileChooserButton, build_label_beside_widget, build_h
from gtweak.egowrapper import ExtensionsDotGnomeDotOrg
def N_(x): return x
-GObject.threads_init()
class _ShellExtensionTweak(Tweak):
diff --git a/gtweak/tweakview.py b/gtweak/tweakview.py
index f17b192..1f78ab1 100644
--- a/gtweak/tweakview.py
+++ b/gtweak/tweakview.py
@@ -42,12 +42,6 @@ class TweakView:
def __init__(self, builder, model):
self._notebook = builder.get_object('notebook')
self._detail_vbox = builder.get_object('detail_vbox')
- self._main_window = builder.get_object('main_window')
-
- self._main_window.props.title = gettext(self._main_window.props.title)
-
- self._main_window.set_size_request(740, 636)
- self._main_window.connect('destroy', Gtk.main_quit)
self._entry_manager = EntryManager(
builder.get_object('search_entry'),
@@ -63,6 +57,7 @@ class TweakView:
Gtk.TreeViewColumn(
"Tweak", Gtk.CellRendererText(), text=TweakModel.COLUMN_NAME))
self.treeview.get_selection().connect("changed", self._on_selection_changed)
+ self.treeview.show_all()
#make sure the tweak background is the correct color
ctx = builder.get_object('tweak_viewport').get_style_context ()
@@ -75,7 +70,6 @@ class TweakView:
#add all tweaks
self._tweak_vbox = builder.get_object('tweak_vbox')
for t in sorted(self._model.tweaks, key=_sort_tweak_widgets_by_widget_type):
- t.main_window = self._main_window
self._tweak_vbox.pack_start(t.widget, False, False, 0)
t.set_notify_cb(self._on_tweak_notify)
@@ -83,10 +77,8 @@ class TweakView:
self._notification_functions = {}
def run(self):
- self._main_window.show_all()
self.treeview.get_selection().select_iter(
self._model.get_tweakgroup_iter(DEFAULT_TWEAKGROUP))
- Gtk.main()
def show_only_tweaks(self, tweaks):
for t in self._model.tweaks:
diff --git a/gtweak/utils.py b/gtweak/utils.py
index 097981e..0da212b 100644
--- a/gtweak/utils.py
+++ b/gtweak/utils.py
@@ -25,7 +25,7 @@ import gtweak
from gtweak.gsettings import GSettingsSetting
from gi.repository import GLib
-
+from gi.repository import Gio
def singleton(cls):
"""
Singleton decorator that works with GObject derived types. The 'recommended'
@@ -225,6 +225,27 @@ class AutostartManager:
old.close()
new.close()
+class SchemaList:
+
+ __list = None
+
+ def __init__(self):
+
+ if SchemaList.__list == None:
+ SchemaList.__list = []
+
+ def get(self):
+ return SchemaList.__list
+
+ def insert(self, key_name, schema_name):
+ v = [key_name, schema_name]
+ SchemaList.__list.append(v)
+
+ def reset(self):
+ for i in SchemaList.__list:
+ s = Gio.Settings(i[1])
+ s.reset(i[0])
+
if __name__ == "__main__":
gtweak.DATA_DIR = "/usr/share"
gtweak.GSETTINGS_SCHEMA_DIR = "/usr/share/glib-2.0/schemas/"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]