Permalink
Browse files

Port unique to GtkApplication, no longer depends on gir1.2-unique-3.0

  • Loading branch information...
tualatrix committed Sep 17, 2013
1 parent 5a82d67 commit fb2da72c493f7eb8af3f7f8b994464d1a410533a
Showing with 48 additions and 53 deletions.
  1. +48 −53 ubuntu-tweak
View
@@ -19,14 +19,15 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
import os
import sys
import optparse
import logging
import dbus
import dbus.service
import dbus.mainloop.glib
from gi.repository import Unique, GObject, Gdk, Gtk
from gi.repository import GObject, Gdk, Gtk, Gio
Gdk.threads_init()
GObject.threads_init()
@@ -56,73 +57,67 @@ def show_splash():
return win
def parse_args(argv):
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]")
return parser.parse_args(argv)
class UbuntuTweakApp(Unique.App):
class UbuntuTweakApp(Gtk.Application):
_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)
def __init__(self, application_id='com.ubuntu-tweak.Tweak'):
Gtk.Application.__init__(self,
application_id=application_id,
flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE)
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):
self.connect('activate', self.on_activated)
self.connect('startup', self.on_startup)
self.connect('command-line', self.on_command_line)
def on_startup(self, app):
splash_window = show_splash()
from ubuntutweak.main import UbuntuTweakWindow
self._window = UbuntuTweakWindow(feature=options.feature, module=options.module, splash_window=splash_window)
self.add_window(self._window.mainwindow)
Gtk.main()
def on_activated(self, app):
if self.get_windows():
self.get_windows()[0].present()
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()
def on_command_line(self, app, commandline):
self.log.debug("on_command_line: %s", commandline.get_arguments())
if options.debug or not IS_INSTALLED or IS_TESTING:
enable_debugging()
options, args = parse_args(commandline.get_arguments())
app = UbuntuTweakApp()
self.on_activated(app)
if app.is_running():
message = Unique.MessageData()
if options.feature:
message.set_text(options.feature, -1)
app.send_message(Unique.Command.ACTIVATE, message)
self._window.select_target_feature(options.feature)
if options.module:
message = Unique.MessageData()
message.set_text(options.module, -1)
app.send_message(Unique.Command.OPEN, message)
else:
splash_window = show_splash()
self._window.do_load_module(options.module)
from ubuntutweak.main import UbuntuTweakWindow
if __name__ == "__main__":
options, args = parse_args(sys.argv)
window = UbuntuTweakWindow(feature=options.feature, module=options.module, splash_window=splash_window)
app.set_window(window)
app.run()
if options.debug or not IS_INSTALLED or IS_TESTING:
enable_debugging()
app = UbuntuTweakApp()
app.run(sys.argv)

0 comments on commit fb2da72

Please sign in to comment.