1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
#!/usr/bin/python
# Ubuntu Tweak - Ubuntu Configuration Tool
#
# Copyright (C) 2007-2011 Tualatrix Chou <tualatrix@gmail.com>
#
# Ubuntu Tweak 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 2 of the License, or
# (at your option) any later version.
#
# Ubuntu Tweak 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 Ubuntu Tweak; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
import os
import optparse
import logging
import dbus
import dbus.service
import dbus.mainloop.glib
from gi.repository import Unique, GObject, Gdk, Gtk
Gdk.threads_init()
GObject.threads_init()
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
dbus.mainloop.glib.threads_init()
from ubuntutweak import system
from ubuntutweak.common.consts import VERSION, IS_INSTALLED, IS_TESTING, DATA_DIR
from ubuntutweak.common.debug import enable_debugging
def show_splash():
win = Gtk.Window(type=Gtk.WindowType.POPUP)
win.set_position(Gtk.WindowPosition.CENTER)
vbox = Gtk.VBox()
image = Gtk.Image()
image.set_from_file(os.path.join(DATA_DIR, 'pixmaps/splash.png'))
vbox.pack_start(image, True, True, 0)
win.add(vbox)
win.show_all()
while Gtk.events_pending():
Gtk.main_iteration()
return win
class UbuntuTweakApp(Unique.App):
_window = None
log = logging.getLogger('Launcher')
def __init__(self, name='com.ubuntu-tweak.Tweak', startup_id=''):
Unique.App.__init__(self, name=name, startup_id=startup_id)
self.log.debug("Distribution: %s\nApplication: %s\nDesktop:%s" % (system.DISTRO,
system.APP,
system.DESKTOP))
self.connect('message-received', self.on_message_received)
def set_window(self, window):
self._window = window
self.watch_window(self._window.mainwindow)
def on_message_received(self, app, command, message, time):
self.log.debug("on_message_received: command: %s, message: %s, time: %s" % (
command, message, time))
try:
if command == Unique.Command.ACTIVATE:
self._window.present()
if message.get_text():
self._window.select_target_feature(message.get_text())
elif command == Unique.Command.OPEN:
self._window.do_load_module(message.get_text())
except Exception, e:
self.log.error(e)
return False
def run(self):
Gtk.main()
if __name__ == "__main__":
parser = optparse.OptionParser(prog="ubuntu-tweak",
version="%%prog %s" % VERSION,
description="Ubuntu Tweak is a tool for Ubuntu that makes it easy to configure your system and desktop settings.")
parser.add_option("-d", "--debug", action="store_true", default=False,
help="Generate more debugging information. [default: %default]")
parser.add_option("-m", "--module", dest="module", default='',
help="Start module directly. [default: %default]")
parser.add_option("-f", "--feature", dest="feature", default='',
help="Start feature directly. [default: %default]")
options, args = parser.parse_args()
if options.debug or not IS_INSTALLED or IS_TESTING:
enable_debugging()
app = UbuntuTweakApp()
if app.is_running():
message = Unique.MessageData()
if options.feature:
message.set_text(options.feature, -1)
app.send_message(Unique.Command.ACTIVATE, message)
if options.module:
message = Unique.MessageData()
message.set_text(options.module, -1)
app.send_message(Unique.Command.OPEN, message)
else:
splash_window = show_splash()
from ubuntutweak.main import UbuntuTweakWindow
window = UbuntuTweakWindow(feature=options.feature, module=options.module, splash_window=splash_window)
app.set_window(window)
app.run()
|