Created
September 8, 2014 14:57
-
-
Save mgedmin/0cd9e0ab5cb51d833289 to your computer and use it in GitHub Desktop.
Using g_application_add_main_option_entries() with PyGObject
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from gi.repository import GLib, Gtk | |
def make_option(long_name, short_name=None, flags=0, arg=GLib.OptionArg.NONE, | |
arg_data=None, description=None, arg_description=None): | |
# surely something like this should exist inside PyGObject itself?! | |
option = GLib.OptionEntry() | |
option.long_name = long_name.lstrip('-') | |
option.short_name = 0 if not short_name else short_name.lstrip('-') | |
option.flags = flags | |
option.arg = arg | |
option.arg_data = arg_data | |
option.description = description | |
option.arg_description = arg_description | |
return option | |
# Usage example: | |
class MyApp(Gtk.Application): | |
def __init__(self, *args, **kw): | |
super(MyApp, self).__init__(*args, **kw) | |
self.add_main_option_entries([ | |
make_option("--version", description="Show version number and exit"), | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment