Skip to content
This repository has been archived by the owner on Apr 24, 2022. It is now read-only.

Commit

Permalink
Port unique to GtkApplication, no longer depends on gir1.2-unique-3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tualatrix committed Sep 17, 2013
1 parent 5a82d67 commit fb2da72
Showing 1 changed file with 48 additions and 53 deletions.
101 changes: 48 additions & 53 deletions ubuntu-tweak
Expand Up @@ -19,14 +19,15 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA


import os import os
import sys
import optparse import optparse
import logging import logging


import dbus import dbus
import dbus.service import dbus.service
import dbus.mainloop.glib import dbus.mainloop.glib


from gi.repository import Unique, GObject, Gdk, Gtk from gi.repository import GObject, Gdk, Gtk, Gio


Gdk.threads_init() Gdk.threads_init()
GObject.threads_init() GObject.threads_init()
Expand Down Expand Up @@ -56,73 +57,67 @@ def show_splash():


return win 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 _window = None
log = logging.getLogger('Launcher') log = logging.getLogger('Launcher')


def __init__(self, name='com.ubuntu-tweak.Tweak', startup_id=''): def __init__(self, application_id='com.ubuntu-tweak.Tweak'):
Unique.App.__init__(self, name=name, startup_id=startup_id) 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, self.log.debug("Distribution: %s\nApplication: %s\nDesktop:%s" % (system.DISTRO,
system.APP, system.APP,
system.DESKTOP)) system.DESKTOP))
self.connect('message-received', self.on_message_received)
def set_window(self, window): self.connect('activate', self.on_activated)
self._window = window self.connect('startup', self.on_startup)
self.watch_window(self._window.mainwindow) self.connect('command-line', self.on_command_line)


def on_message_received(self, app, command, message, time): def on_startup(self, app):
self.log.debug("on_message_received: command: %s, message: %s, time: %s" % ( splash_window = show_splash()
command, message, time)) from ubuntutweak.main import UbuntuTweakWindow
try:
if command == Unique.Command.ACTIVATE: self._window = UbuntuTweakWindow(feature=options.feature, module=options.module, splash_window=splash_window)
self._window.present() self.add_window(self._window.mainwindow)
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() Gtk.main()


def on_activated(self, app):
if self.get_windows():
self.get_windows()[0].present()


if __name__ == "__main__": def on_command_line(self, app, commandline):
parser = optparse.OptionParser(prog="ubuntu-tweak", self.log.debug("on_command_line: %s", commandline.get_arguments())
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: options, args = parse_args(commandline.get_arguments())
enable_debugging()


app = UbuntuTweakApp() self.on_activated(app)


if app.is_running():
message = Unique.MessageData()
if options.feature: if options.feature:
message.set_text(options.feature, -1) self._window.select_target_feature(options.feature)

app.send_message(Unique.Command.ACTIVATE, message)


if options.module: if options.module:
message = Unique.MessageData() self._window.do_load_module(options.module)
message.set_text(options.module, -1)
app.send_message(Unique.Command.OPEN, message)
else:
splash_window = show_splash()


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) if options.debug or not IS_INSTALLED or IS_TESTING:
app.set_window(window) enable_debugging()
app.run()
app = UbuntuTweakApp()
app.run(sys.argv)

0 comments on commit fb2da72

Please sign in to comment.