gstreamer-python 1.27.90__cp313-cp313-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gstreamer_python/Lib/girepository-1.0/GdkPixbuf-2.0.typelib +0 -0
- gstreamer_python/Lib/girepository-1.0/HarfBuzz-0.0.typelib +0 -0
- gstreamer_python/Lib/girepository-1.0/Json-1.0.typelib +0 -0
- gstreamer_python/Lib/girepository-1.0/Pango-1.0.typelib +0 -0
- gstreamer_python/Lib/girepository-1.0/PangoCairo-1.0.typelib +0 -0
- gstreamer_python/Lib/girepository-1.0/Soup-3.0.typelib +0 -0
- gstreamer_python/Lib/gstreamer-1.0/gstpython.dll +0 -0
- gstreamer_python/Lib/site-packages/PyGObject-3.50.2.dist-info/METADATA +21 -0
- gstreamer_python/Lib/site-packages/cairo/__init__.py +25 -0
- gstreamer_python/Lib/site-packages/cairo/__init__.pyi +5889 -0
- gstreamer_python/Lib/site-packages/cairo/_cairo.cp313-win_amd64.pyd +0 -0
- gstreamer_python/Lib/site-packages/cairo/include/py3cairo.h +266 -0
- gstreamer_python/Lib/site-packages/cairo/py.typed +0 -0
- gstreamer_python/Lib/site-packages/gi/__init__.py +197 -0
- gstreamer_python/Lib/site-packages/gi/_constants.py +47 -0
- gstreamer_python/Lib/site-packages/gi/_error.py +55 -0
- gstreamer_python/Lib/site-packages/gi/_gi.cp313-win_amd64.pyd +0 -0
- gstreamer_python/Lib/site-packages/gi/_gi_cairo.cp313-win_amd64.pyd +0 -0
- gstreamer_python/Lib/site-packages/gi/_gtktemplate.py +307 -0
- gstreamer_python/Lib/site-packages/gi/_option.py +379 -0
- gstreamer_python/Lib/site-packages/gi/_ossighelper.py +275 -0
- gstreamer_python/Lib/site-packages/gi/_propertyhelper.py +402 -0
- gstreamer_python/Lib/site-packages/gi/_signalhelper.py +249 -0
- gstreamer_python/Lib/site-packages/gi/docstring.py +205 -0
- gstreamer_python/Lib/site-packages/gi/events.py +674 -0
- gstreamer_python/Lib/site-packages/gi/importer.py +153 -0
- gstreamer_python/Lib/site-packages/gi/module.py +269 -0
- gstreamer_python/Lib/site-packages/gi/overrides/GES.py +94 -0
- gstreamer_python/Lib/site-packages/gi/overrides/GIMarshallingTests.py +72 -0
- gstreamer_python/Lib/site-packages/gi/overrides/GLib.py +882 -0
- gstreamer_python/Lib/site-packages/gi/overrides/GObject.py +692 -0
- gstreamer_python/Lib/site-packages/gi/overrides/Gdk.py +444 -0
- gstreamer_python/Lib/site-packages/gi/overrides/GdkPixbuf.py +53 -0
- gstreamer_python/Lib/site-packages/gi/overrides/Gio.py +655 -0
- gstreamer_python/Lib/site-packages/gi/overrides/Gst.py +1273 -0
- gstreamer_python/Lib/site-packages/gi/overrides/GstAnalytics.py +106 -0
- gstreamer_python/Lib/site-packages/gi/overrides/GstApp.py +50 -0
- gstreamer_python/Lib/site-packages/gi/overrides/GstAudio.py +18 -0
- gstreamer_python/Lib/site-packages/gi/overrides/GstPbutils.py +99 -0
- gstreamer_python/Lib/site-packages/gi/overrides/GstVideo.py +17 -0
- gstreamer_python/Lib/site-packages/gi/overrides/Gtk.py +1707 -0
- gstreamer_python/Lib/site-packages/gi/overrides/Pango.py +58 -0
- gstreamer_python/Lib/site-packages/gi/overrides/__init__.py +357 -0
- gstreamer_python/Lib/site-packages/gi/overrides/_gi_gst.cp313-win_amd64.pyd +0 -0
- gstreamer_python/Lib/site-packages/gi/overrides/_gi_gst_analytics.cp313-win_amd64.pyd +0 -0
- gstreamer_python/Lib/site-packages/gi/overrides/keysyms.py +53 -0
- gstreamer_python/Lib/site-packages/gi/pygtkcompat.py +26 -0
- gstreamer_python/Lib/site-packages/gi/repository/__init__.py +28 -0
- gstreamer_python/Lib/site-packages/gi/types.py +350 -0
- gstreamer_python/Lib/site-packages/pycairo-1.27.0.dist-info/METADATA +9 -0
- gstreamer_python/__init__.py +32 -0
- gstreamer_python-1.27.90.dist-info/METADATA +26 -0
- gstreamer_python-1.27.90.dist-info/RECORD +55 -0
- gstreamer_python-1.27.90.dist-info/WHEEL +5 -0
- gstreamer_python-1.27.90.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
# Copyright 2015 Dustin Spicuzza <dustin@virtualroadside.com>
|
|
2
|
+
# 2018 Nikita Churaev <lamefun.x0r@gmail.com>
|
|
3
|
+
# 2018 Christoph Reiter <reiter.christoph@gmail.com>
|
|
4
|
+
#
|
|
5
|
+
# This library is free software; you can redistribute it and/or
|
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
|
7
|
+
# License as published by the Free Software Foundation; either
|
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13
|
+
# Lesser General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
|
16
|
+
# License along with this library; if not, write to the Free Software
|
|
17
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
|
|
18
|
+
# USA
|
|
19
|
+
|
|
20
|
+
import os
|
|
21
|
+
from collections import abc
|
|
22
|
+
from functools import partial
|
|
23
|
+
|
|
24
|
+
from gi.repository import GLib, GObject, Gio
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _extract_handler_and_args(obj_or_map, handler_name):
|
|
28
|
+
handler = None
|
|
29
|
+
if isinstance(obj_or_map, abc.Mapping):
|
|
30
|
+
handler = obj_or_map.get(handler_name, None)
|
|
31
|
+
else:
|
|
32
|
+
handler = getattr(obj_or_map, handler_name, None)
|
|
33
|
+
|
|
34
|
+
if handler is None:
|
|
35
|
+
raise AttributeError('Handler %s not found' % handler_name)
|
|
36
|
+
|
|
37
|
+
args = ()
|
|
38
|
+
if isinstance(handler, abc.Sequence):
|
|
39
|
+
if len(handler) == 0:
|
|
40
|
+
raise TypeError("Handler %s tuple can not be empty" % handler)
|
|
41
|
+
args = handler[1:]
|
|
42
|
+
handler = handler[0]
|
|
43
|
+
|
|
44
|
+
elif not callable(handler):
|
|
45
|
+
raise TypeError('Handler %s is not a method, function or tuple' % handler)
|
|
46
|
+
|
|
47
|
+
return handler, args
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def define_builder_scope():
|
|
51
|
+
from gi.repository import Gtk
|
|
52
|
+
|
|
53
|
+
class BuilderScope(GObject.GObject, Gtk.BuilderScope):
|
|
54
|
+
|
|
55
|
+
def __init__(self, scope_object=None):
|
|
56
|
+
super().__init__()
|
|
57
|
+
self._scope_object = scope_object
|
|
58
|
+
|
|
59
|
+
def do_create_closure(self, builder, func_name, flags, obj):
|
|
60
|
+
current_object = builder.get_current_object() or self._scope_object
|
|
61
|
+
|
|
62
|
+
if not self._scope_object:
|
|
63
|
+
current_object = builder.get_current_object()
|
|
64
|
+
if func_name not in current_object.__gtktemplate_methods__:
|
|
65
|
+
return None
|
|
66
|
+
|
|
67
|
+
current_object.__gtktemplate_handlers__.add(func_name)
|
|
68
|
+
handler_name = current_object.__gtktemplate_methods__[func_name]
|
|
69
|
+
else:
|
|
70
|
+
current_object = self._scope_object
|
|
71
|
+
handler_name = func_name
|
|
72
|
+
|
|
73
|
+
swapped = int(flags & Gtk.BuilderClosureFlags.SWAPPED)
|
|
74
|
+
if swapped:
|
|
75
|
+
raise RuntimeError(
|
|
76
|
+
"%r not supported" % GObject.ConnectFlags.SWAPPED)
|
|
77
|
+
return None
|
|
78
|
+
|
|
79
|
+
handler, args = _extract_handler_and_args(current_object, handler_name)
|
|
80
|
+
|
|
81
|
+
if obj:
|
|
82
|
+
p = partial(handler, *args, swap_data=obj)
|
|
83
|
+
else:
|
|
84
|
+
p = partial(handler, *args)
|
|
85
|
+
|
|
86
|
+
p.__gtk_template__ = True
|
|
87
|
+
return p
|
|
88
|
+
|
|
89
|
+
return BuilderScope
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def connect_func(builder, obj, signal_name, handler_name,
|
|
93
|
+
connect_object, flags, cls):
|
|
94
|
+
|
|
95
|
+
if handler_name not in cls.__gtktemplate_methods__:
|
|
96
|
+
return
|
|
97
|
+
|
|
98
|
+
method_name = cls.__gtktemplate_methods__[handler_name]
|
|
99
|
+
template_inst = builder.get_object(cls.__gtype_name__)
|
|
100
|
+
template_inst.__gtktemplate_handlers__.add(handler_name)
|
|
101
|
+
handler = getattr(template_inst, method_name)
|
|
102
|
+
|
|
103
|
+
after = int(flags & GObject.ConnectFlags.AFTER)
|
|
104
|
+
swapped = int(flags & GObject.ConnectFlags.SWAPPED)
|
|
105
|
+
if swapped:
|
|
106
|
+
raise RuntimeError(
|
|
107
|
+
"%r not supported" % GObject.ConnectFlags.SWAPPED)
|
|
108
|
+
|
|
109
|
+
if connect_object is not None:
|
|
110
|
+
if after:
|
|
111
|
+
func = obj.connect_object_after
|
|
112
|
+
else:
|
|
113
|
+
func = obj.connect_object
|
|
114
|
+
func(signal_name, handler, connect_object)
|
|
115
|
+
else:
|
|
116
|
+
if after:
|
|
117
|
+
func = obj.connect_after
|
|
118
|
+
else:
|
|
119
|
+
func = obj.connect
|
|
120
|
+
func(signal_name, handler)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def register_template(cls):
|
|
124
|
+
from gi.repository import Gtk
|
|
125
|
+
|
|
126
|
+
bound_methods = {}
|
|
127
|
+
bound_widgets = {}
|
|
128
|
+
|
|
129
|
+
for attr_name, obj in list(cls.__dict__.items()):
|
|
130
|
+
if isinstance(obj, CallThing):
|
|
131
|
+
setattr(cls, attr_name, obj._func)
|
|
132
|
+
handler_name = obj._name
|
|
133
|
+
if handler_name is None:
|
|
134
|
+
handler_name = attr_name
|
|
135
|
+
|
|
136
|
+
if handler_name in bound_methods:
|
|
137
|
+
old_attr_name = bound_methods[handler_name]
|
|
138
|
+
raise RuntimeError(
|
|
139
|
+
"Error while exposing handler %r as %r, "
|
|
140
|
+
"already available as %r" % (
|
|
141
|
+
handler_name, attr_name, old_attr_name))
|
|
142
|
+
else:
|
|
143
|
+
bound_methods[handler_name] = attr_name
|
|
144
|
+
elif isinstance(obj, Child):
|
|
145
|
+
widget_name = obj._name
|
|
146
|
+
if widget_name is None:
|
|
147
|
+
widget_name = attr_name
|
|
148
|
+
|
|
149
|
+
if widget_name in bound_widgets:
|
|
150
|
+
old_attr_name = bound_widgets[widget_name]
|
|
151
|
+
raise RuntimeError(
|
|
152
|
+
"Error while exposing child %r as %r, "
|
|
153
|
+
"already available as %r" % (
|
|
154
|
+
widget_name, attr_name, old_attr_name))
|
|
155
|
+
else:
|
|
156
|
+
bound_widgets[widget_name] = attr_name
|
|
157
|
+
cls.bind_template_child_full(widget_name, obj._internal, 0)
|
|
158
|
+
|
|
159
|
+
cls.__gtktemplate_methods__ = bound_methods
|
|
160
|
+
cls.__gtktemplate_widgets__ = bound_widgets
|
|
161
|
+
|
|
162
|
+
if Gtk._version == "4.0":
|
|
163
|
+
BuilderScope = define_builder_scope()
|
|
164
|
+
cls.set_template_scope(BuilderScope())
|
|
165
|
+
else:
|
|
166
|
+
cls.set_connect_func(connect_func, cls)
|
|
167
|
+
|
|
168
|
+
base_init_template = cls.init_template
|
|
169
|
+
cls.__dontuse_ginstance_init__ = \
|
|
170
|
+
lambda s: init_template(s, cls, base_init_template)
|
|
171
|
+
# To make this file work with older PyGObject we expose our init code
|
|
172
|
+
# as init_template() but make it a noop when we call it ourselves first
|
|
173
|
+
cls.init_template = cls.__dontuse_ginstance_init__
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def init_template(self, cls, base_init_template):
|
|
177
|
+
self.init_template = lambda: None
|
|
178
|
+
|
|
179
|
+
if self.__class__ is not cls:
|
|
180
|
+
raise TypeError(
|
|
181
|
+
"Inheritance from classes with @Gtk.Template decorators "
|
|
182
|
+
"is not allowed at this time")
|
|
183
|
+
|
|
184
|
+
self.__gtktemplate_handlers__ = set()
|
|
185
|
+
|
|
186
|
+
base_init_template(self)
|
|
187
|
+
|
|
188
|
+
for widget_name, attr_name in self.__gtktemplate_widgets__.items():
|
|
189
|
+
self.__dict__[attr_name] = self.get_template_child(cls, widget_name)
|
|
190
|
+
|
|
191
|
+
for handler_name, attr_name in self.__gtktemplate_methods__.items():
|
|
192
|
+
if handler_name not in self.__gtktemplate_handlers__:
|
|
193
|
+
raise RuntimeError(
|
|
194
|
+
"Handler '%s' was declared with @Gtk.Template.Callback "
|
|
195
|
+
"but was not present in template" % handler_name)
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
class Child(object):
|
|
199
|
+
|
|
200
|
+
def __init__(self, name=None, **kwargs):
|
|
201
|
+
self._name = name
|
|
202
|
+
self._internal = kwargs.pop("internal", False)
|
|
203
|
+
if kwargs:
|
|
204
|
+
raise TypeError("Unhandled arguments: %r" % kwargs)
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
class CallThing(object):
|
|
208
|
+
|
|
209
|
+
def __init__(self, name, func):
|
|
210
|
+
self._name = name
|
|
211
|
+
self._func = func
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
class Callback(object):
|
|
215
|
+
|
|
216
|
+
def __init__(self, name=None):
|
|
217
|
+
self._name = name
|
|
218
|
+
|
|
219
|
+
def __call__(self, func):
|
|
220
|
+
return CallThing(self._name, func)
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def validate_resource_path(path):
|
|
224
|
+
"""Raises GLib.Error in case the resource doesn't exist"""
|
|
225
|
+
|
|
226
|
+
try:
|
|
227
|
+
Gio.resources_get_info(path, Gio.ResourceLookupFlags.NONE)
|
|
228
|
+
except GLib.Error:
|
|
229
|
+
# resources_get_info() doesn't handle overlays but we keep using it
|
|
230
|
+
# as a fast path.
|
|
231
|
+
# https://gitlab.gnome.org/GNOME/pygobject/issues/230
|
|
232
|
+
Gio.resources_lookup_data(path, Gio.ResourceLookupFlags.NONE)
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
class Template(object):
|
|
236
|
+
|
|
237
|
+
def __init__(self, **kwargs):
|
|
238
|
+
self.string = None
|
|
239
|
+
self.filename = None
|
|
240
|
+
self.resource_path = None
|
|
241
|
+
if "string" in kwargs:
|
|
242
|
+
self.string = kwargs.pop("string")
|
|
243
|
+
elif "filename" in kwargs:
|
|
244
|
+
self.filename = kwargs.pop("filename")
|
|
245
|
+
elif "resource_path" in kwargs:
|
|
246
|
+
self.resource_path = kwargs.pop("resource_path")
|
|
247
|
+
else:
|
|
248
|
+
raise TypeError(
|
|
249
|
+
"Requires one of the following arguments: "
|
|
250
|
+
"string, filename, resource_path")
|
|
251
|
+
|
|
252
|
+
if kwargs:
|
|
253
|
+
raise TypeError("Unhandled keyword arguments %r" % kwargs)
|
|
254
|
+
|
|
255
|
+
@classmethod
|
|
256
|
+
def from_file(cls, filename):
|
|
257
|
+
return cls(filename=filename)
|
|
258
|
+
|
|
259
|
+
@classmethod
|
|
260
|
+
def from_string(cls, string):
|
|
261
|
+
return cls(string=string)
|
|
262
|
+
|
|
263
|
+
@classmethod
|
|
264
|
+
def from_resource(cls, resource_path):
|
|
265
|
+
return cls(resource_path=resource_path)
|
|
266
|
+
|
|
267
|
+
Callback = Callback
|
|
268
|
+
|
|
269
|
+
Child = Child
|
|
270
|
+
|
|
271
|
+
def __call__(self, cls):
|
|
272
|
+
from gi.repository import Gtk
|
|
273
|
+
|
|
274
|
+
if not isinstance(cls, type) or not issubclass(cls, Gtk.Widget):
|
|
275
|
+
raise TypeError("Can only use @Gtk.Template on Widgets")
|
|
276
|
+
|
|
277
|
+
if "__gtype_name__" not in cls.__dict__:
|
|
278
|
+
raise TypeError(
|
|
279
|
+
"%r does not have a __gtype_name__. Set it to the name "
|
|
280
|
+
"of the class in your template" % cls.__name__)
|
|
281
|
+
|
|
282
|
+
if hasattr(cls, "__gtktemplate_methods__"):
|
|
283
|
+
raise TypeError("Cannot nest template classes")
|
|
284
|
+
|
|
285
|
+
if self.string is not None:
|
|
286
|
+
data = self.string
|
|
287
|
+
if not isinstance(data, bytes):
|
|
288
|
+
data = data.encode("utf-8")
|
|
289
|
+
bytes_ = GLib.Bytes.new(data)
|
|
290
|
+
cls.set_template(bytes_)
|
|
291
|
+
register_template(cls)
|
|
292
|
+
return cls
|
|
293
|
+
elif self.resource_path is not None:
|
|
294
|
+
validate_resource_path(self.resource_path)
|
|
295
|
+
cls.set_template_from_resource(self.resource_path)
|
|
296
|
+
register_template(cls)
|
|
297
|
+
return cls
|
|
298
|
+
else:
|
|
299
|
+
assert self.filename is not None
|
|
300
|
+
file_ = Gio.File.new_for_path(os.fspath(self.filename))
|
|
301
|
+
bytes_ = GLib.Bytes.new(file_.load_contents()[1])
|
|
302
|
+
cls.set_template(bytes_)
|
|
303
|
+
register_template(cls)
|
|
304
|
+
return cls
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
__all__ = ["Template"]
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
# -*- Mode: Python -*-
|
|
2
|
+
# pygobject - Python bindings for the GObject library
|
|
3
|
+
# Copyright (C) 2006 Johannes Hoelzl
|
|
4
|
+
#
|
|
5
|
+
# glib/option.py: GOption command line parser
|
|
6
|
+
#
|
|
7
|
+
# This library is free software; you can redistribute it and/or
|
|
8
|
+
# modify it under the terms of the GNU Lesser General Public
|
|
9
|
+
# License as published by the Free Software Foundation; either
|
|
10
|
+
# version 2.1 of the License, or (at your option) any later version.
|
|
11
|
+
#
|
|
12
|
+
# This library is distributed in the hope that it will be useful,
|
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
15
|
+
# Lesser General Public License for more details.
|
|
16
|
+
#
|
|
17
|
+
# You should have received a copy of the GNU Lesser General Public
|
|
18
|
+
# License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
19
|
+
|
|
20
|
+
"""GOption command line parser
|
|
21
|
+
|
|
22
|
+
Extends optparse to use the GOptionGroup, GOptionEntry and GOptionContext
|
|
23
|
+
objects. So it is possible to use the gtk, gnome_program and gstreamer command
|
|
24
|
+
line groups and contexts.
|
|
25
|
+
|
|
26
|
+
Use this interface instead of the raw wrappers of GOptionContext and
|
|
27
|
+
GOptionGroup in glib.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
import sys
|
|
31
|
+
import optparse
|
|
32
|
+
import warnings
|
|
33
|
+
from optparse import OptParseError, OptionError, OptionValueError, \
|
|
34
|
+
BadOptionError, OptionConflictError
|
|
35
|
+
from .module import get_introspection_module
|
|
36
|
+
|
|
37
|
+
from gi import _gi, PyGIDeprecationWarning
|
|
38
|
+
from gi._error import GError
|
|
39
|
+
GLib = get_introspection_module('GLib')
|
|
40
|
+
|
|
41
|
+
OPTION_CONTEXT_ERROR_QUARK = GLib.quark_to_string(GLib.option_error_quark())
|
|
42
|
+
|
|
43
|
+
__all__ = [
|
|
44
|
+
"OptParseError",
|
|
45
|
+
"OptionError",
|
|
46
|
+
"OptionValueError",
|
|
47
|
+
"BadOptionError",
|
|
48
|
+
"OptionConflictError",
|
|
49
|
+
"Option",
|
|
50
|
+
"OptionGroup",
|
|
51
|
+
"OptionParser",
|
|
52
|
+
"make_option",
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class Option(optparse.Option):
|
|
57
|
+
"""Represents a command line option
|
|
58
|
+
|
|
59
|
+
To use the extended possibilities of the GOption API Option
|
|
60
|
+
(and make_option) are extended with new types and attributes.
|
|
61
|
+
|
|
62
|
+
Types:
|
|
63
|
+
filename The supplied arguments are read as filename, GOption
|
|
64
|
+
parses this type in with the GLib filename encoding.
|
|
65
|
+
|
|
66
|
+
:ivar optional_arg:
|
|
67
|
+
This does not need a arguement, but it can be supplied.
|
|
68
|
+
:ivar hidden:
|
|
69
|
+
The help list does not show this option
|
|
70
|
+
:ivar in_main:
|
|
71
|
+
This option apears in the main group, this should only
|
|
72
|
+
be used for backwards compatibility.
|
|
73
|
+
|
|
74
|
+
Use Option.REMAINING as option name to get all positional arguments.
|
|
75
|
+
|
|
76
|
+
.. NOTE::
|
|
77
|
+
Every argument to an option is passed as utf-8 coded string, the only
|
|
78
|
+
exception are options which use the 'filename' type, its arguments
|
|
79
|
+
are passed as strings in the GLib filename encoding.
|
|
80
|
+
|
|
81
|
+
For further help, see optparse.Option.
|
|
82
|
+
"""
|
|
83
|
+
TYPES = optparse.Option.TYPES + (
|
|
84
|
+
'filename',
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
ATTRS = optparse.Option.ATTRS + [
|
|
88
|
+
'hidden',
|
|
89
|
+
'in_main',
|
|
90
|
+
'optional_arg',
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
REMAINING = '--' + GLib.OPTION_REMAINING
|
|
94
|
+
|
|
95
|
+
def __init__(self, *args, **kwargs):
|
|
96
|
+
warnings.warn(
|
|
97
|
+
"gi.repository.GLib.option.Option is deprecated, use gi.repository.GLib.OptionEntry instead",
|
|
98
|
+
PyGIDeprecationWarning
|
|
99
|
+
)
|
|
100
|
+
optparse.Option.__init__(self, *args, **kwargs)
|
|
101
|
+
if not self._long_opts:
|
|
102
|
+
raise ValueError("%s at least one long option name.")
|
|
103
|
+
|
|
104
|
+
if len(self._long_opts) < len(self._short_opts):
|
|
105
|
+
raise ValueError(
|
|
106
|
+
"%s at least more long option names than short option names.")
|
|
107
|
+
|
|
108
|
+
if not self.help:
|
|
109
|
+
raise ValueError("%s needs a help message.", self._long_opts[0])
|
|
110
|
+
|
|
111
|
+
def _set_opt_string(self, opts):
|
|
112
|
+
if self.REMAINING in opts:
|
|
113
|
+
self._long_opts.append(self.REMAINING)
|
|
114
|
+
optparse.Option._set_opt_string(self, opts)
|
|
115
|
+
if len(self._short_opts) > len(self._long_opts):
|
|
116
|
+
raise OptionError("goption.Option needs more long option names "
|
|
117
|
+
"than short option names")
|
|
118
|
+
|
|
119
|
+
def _to_goptionentries(self):
|
|
120
|
+
flags = 0
|
|
121
|
+
|
|
122
|
+
if self.hidden:
|
|
123
|
+
flags |= GLib.OptionFlags.HIDDEN
|
|
124
|
+
|
|
125
|
+
if self.in_main:
|
|
126
|
+
flags |= GLib.OptionFlags.IN_MAIN
|
|
127
|
+
|
|
128
|
+
if self.takes_value():
|
|
129
|
+
if self.optional_arg:
|
|
130
|
+
flags |= GLib.OptionFlags.OPTIONAL_ARG
|
|
131
|
+
else:
|
|
132
|
+
flags |= GLib.OptionFlags.NO_ARG
|
|
133
|
+
|
|
134
|
+
if self.type == 'filename':
|
|
135
|
+
flags |= GLib.OptionFlags.FILENAME
|
|
136
|
+
|
|
137
|
+
for (long_name, short_name) in zip(self._long_opts, self._short_opts):
|
|
138
|
+
short_bytes = short_name[1]
|
|
139
|
+
if not isinstance(short_bytes, bytes):
|
|
140
|
+
short_bytes = short_bytes.encode("utf-8")
|
|
141
|
+
yield (long_name[2:], short_bytes, flags, self.help, self.metavar)
|
|
142
|
+
|
|
143
|
+
for long_name in self._long_opts[len(self._short_opts):]:
|
|
144
|
+
yield (long_name[2:], b'\0', flags, self.help, self.metavar)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
class OptionGroup(optparse.OptionGroup):
|
|
148
|
+
"""A group of command line options.
|
|
149
|
+
|
|
150
|
+
:param str name:
|
|
151
|
+
The groups name, used to create the --help-{name} option
|
|
152
|
+
:param str description:
|
|
153
|
+
Shown as title of the groups help view
|
|
154
|
+
:param str help_description:
|
|
155
|
+
Shown as help to the --help-{name} option
|
|
156
|
+
:param list option_list:
|
|
157
|
+
The options used in this group, must be option.Option()
|
|
158
|
+
:param dict defaults:
|
|
159
|
+
A dicitionary of default values
|
|
160
|
+
:param translation_domain:
|
|
161
|
+
Sets the translation domain for gettext().
|
|
162
|
+
|
|
163
|
+
.. NOTE::
|
|
164
|
+
This OptionGroup does not exactly map the optparse.OptionGroup
|
|
165
|
+
interface. There is no parser object to supply, but it is possible
|
|
166
|
+
to set default values and option_lists. Also the default values and
|
|
167
|
+
values are not shared with the OptionParser.
|
|
168
|
+
|
|
169
|
+
To pass a OptionGroup into a function which expects a GOptionGroup (e.g.
|
|
170
|
+
gnome_program_init() ). OptionGroup.get_option_group() can be used.
|
|
171
|
+
|
|
172
|
+
For further help, see optparse.OptionGroup.
|
|
173
|
+
"""
|
|
174
|
+
def __init__(self, name, description, help_description="",
|
|
175
|
+
option_list=None, defaults=None,
|
|
176
|
+
translation_domain=None):
|
|
177
|
+
warnings.warn(
|
|
178
|
+
"gi.repository.GLib.option.OptionGroup is deprecated, use gi.repository.GLib.OptionContext instead",
|
|
179
|
+
PyGIDeprecationWarning
|
|
180
|
+
)
|
|
181
|
+
optparse.OptionContainer.__init__(self, Option, 'error', description)
|
|
182
|
+
self.name = name
|
|
183
|
+
self.parser = None
|
|
184
|
+
self.help_description = help_description
|
|
185
|
+
if defaults:
|
|
186
|
+
self.defaults = defaults
|
|
187
|
+
|
|
188
|
+
self.values = None
|
|
189
|
+
|
|
190
|
+
self.translation_domain = translation_domain
|
|
191
|
+
|
|
192
|
+
if option_list:
|
|
193
|
+
for option in option_list:
|
|
194
|
+
self.add_option(option)
|
|
195
|
+
|
|
196
|
+
def _create_option_list(self):
|
|
197
|
+
self.option_list = []
|
|
198
|
+
self._create_option_mappings()
|
|
199
|
+
|
|
200
|
+
def _to_goptiongroup(self, parser):
|
|
201
|
+
def callback(option_name, option_value, group):
|
|
202
|
+
if option_name.startswith('--'):
|
|
203
|
+
opt = self._long_opt[option_name]
|
|
204
|
+
else:
|
|
205
|
+
opt = self._short_opt[option_name]
|
|
206
|
+
|
|
207
|
+
try:
|
|
208
|
+
opt.process(option_name, option_value, self.values, parser)
|
|
209
|
+
except OptionValueError:
|
|
210
|
+
error = sys.exc_info()[1]
|
|
211
|
+
gerror = GError(str(error))
|
|
212
|
+
gerror.domain = OPTION_CONTEXT_ERROR_QUARK
|
|
213
|
+
gerror.code = GLib.OptionError.BAD_VALUE
|
|
214
|
+
gerror.message = str(error)
|
|
215
|
+
raise gerror
|
|
216
|
+
|
|
217
|
+
group = _gi.OptionGroup(self.name, self.description,
|
|
218
|
+
self.help_description, callback)
|
|
219
|
+
if self.translation_domain:
|
|
220
|
+
group.set_translation_domain(self.translation_domain)
|
|
221
|
+
|
|
222
|
+
entries = []
|
|
223
|
+
for option in self.option_list:
|
|
224
|
+
entries.extend(option._to_goptionentries())
|
|
225
|
+
|
|
226
|
+
group.add_entries(entries)
|
|
227
|
+
|
|
228
|
+
return group
|
|
229
|
+
|
|
230
|
+
def get_option_group(self, parser=None):
|
|
231
|
+
""" Returns the corresponding GOptionGroup object.
|
|
232
|
+
|
|
233
|
+
Can be used as parameter for gnome_program_init(), gtk_init().
|
|
234
|
+
"""
|
|
235
|
+
self.set_values_to_defaults()
|
|
236
|
+
return self._to_goptiongroup(parser)
|
|
237
|
+
|
|
238
|
+
def set_values_to_defaults(self):
|
|
239
|
+
for option in self.option_list:
|
|
240
|
+
default = self.defaults.get(option.dest)
|
|
241
|
+
if isinstance(default, str):
|
|
242
|
+
opt_str = option.get_opt_string()
|
|
243
|
+
self.defaults[option.dest] = option.check_value(
|
|
244
|
+
opt_str, default)
|
|
245
|
+
self.values = optparse.Values(self.defaults)
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
class OptionParser(optparse.OptionParser):
|
|
249
|
+
"""Command line parser with GOption support.
|
|
250
|
+
|
|
251
|
+
:param bool help_enabled:
|
|
252
|
+
The --help, --help-all and --help-{group} options are enabled (default).
|
|
253
|
+
:param bool ignore_unknown_options:
|
|
254
|
+
Do not throw a exception when a option is not knwon, the option
|
|
255
|
+
will be in the result list.
|
|
256
|
+
|
|
257
|
+
.. NOTE::
|
|
258
|
+
The OptionParser interface is not the exactly the same as the
|
|
259
|
+
optparse.OptionParser interface. Especially the usage parameter
|
|
260
|
+
is only used to show the metavar of the arguements.
|
|
261
|
+
|
|
262
|
+
OptionParser.add_option_group() does not only accept OptionGroup instances
|
|
263
|
+
but also glib.OptionGroup, which is returned by gtk_get_option_group().
|
|
264
|
+
|
|
265
|
+
Only glib.option.OptionGroup and glib.option.Option instances should
|
|
266
|
+
be passed as groups and options.
|
|
267
|
+
|
|
268
|
+
For further help, see optparse.OptionParser.
|
|
269
|
+
"""
|
|
270
|
+
|
|
271
|
+
def __init__(self, *args, **kwargs):
|
|
272
|
+
warnings.warn(
|
|
273
|
+
"gi.repository.GLib.option.OptionParser is deprecated, use gi.repository.GLib.OptionContext instead",
|
|
274
|
+
PyGIDeprecationWarning
|
|
275
|
+
)
|
|
276
|
+
if 'option_class' not in kwargs:
|
|
277
|
+
kwargs['option_class'] = Option
|
|
278
|
+
self.help_enabled = kwargs.pop('help_enabled', True)
|
|
279
|
+
self.ignore_unknown_options = kwargs.pop('ignore_unknown_options',
|
|
280
|
+
False)
|
|
281
|
+
optparse.OptionParser.__init__(self, add_help_option=False,
|
|
282
|
+
*args, **kwargs)
|
|
283
|
+
|
|
284
|
+
def set_usage(self, usage):
|
|
285
|
+
if usage is None:
|
|
286
|
+
self.usage = ''
|
|
287
|
+
elif usage.startswith("%prog"):
|
|
288
|
+
self.usage = usage[len("%prog"):]
|
|
289
|
+
else:
|
|
290
|
+
self.usage = usage
|
|
291
|
+
|
|
292
|
+
def _to_goptioncontext(self, values):
|
|
293
|
+
if self.description:
|
|
294
|
+
parameter_string = self.usage + " - " + self.description
|
|
295
|
+
else:
|
|
296
|
+
parameter_string = self.usage
|
|
297
|
+
context = _gi.OptionContext(parameter_string)
|
|
298
|
+
context.set_help_enabled(self.help_enabled)
|
|
299
|
+
context.set_ignore_unknown_options(self.ignore_unknown_options)
|
|
300
|
+
|
|
301
|
+
for option_group in self.option_groups:
|
|
302
|
+
if isinstance(option_group, _gi.OptionGroup):
|
|
303
|
+
g_group = option_group
|
|
304
|
+
else:
|
|
305
|
+
g_group = option_group.get_option_group(self)
|
|
306
|
+
context.add_group(g_group)
|
|
307
|
+
|
|
308
|
+
def callback(option_name, option_value, group):
|
|
309
|
+
if option_name.startswith('--'):
|
|
310
|
+
opt = self._long_opt[option_name]
|
|
311
|
+
else:
|
|
312
|
+
opt = self._short_opt[option_name]
|
|
313
|
+
opt.process(option_name, option_value, values, self)
|
|
314
|
+
|
|
315
|
+
main_group = _gi.OptionGroup(None, None, None, callback)
|
|
316
|
+
main_entries = []
|
|
317
|
+
for option in self.option_list:
|
|
318
|
+
main_entries.extend(option._to_goptionentries())
|
|
319
|
+
main_group.add_entries(main_entries)
|
|
320
|
+
context.set_main_group(main_group)
|
|
321
|
+
|
|
322
|
+
return context
|
|
323
|
+
|
|
324
|
+
def add_option_group(self, *args, **kwargs):
|
|
325
|
+
if isinstance(args[0], str):
|
|
326
|
+
optparse.OptionParser.add_option_group(self,
|
|
327
|
+
OptionGroup(self, *args, **kwargs))
|
|
328
|
+
return
|
|
329
|
+
elif len(args) == 1 and not kwargs:
|
|
330
|
+
if isinstance(args[0], OptionGroup):
|
|
331
|
+
if not args[0].parser:
|
|
332
|
+
args[0].parser = self
|
|
333
|
+
if args[0].parser is not self:
|
|
334
|
+
raise ValueError("invalid OptionGroup (wrong parser)")
|
|
335
|
+
if isinstance(args[0], _gi.OptionGroup):
|
|
336
|
+
self.option_groups.append(args[0])
|
|
337
|
+
return
|
|
338
|
+
optparse.OptionParser.add_option_group(self, *args, **kwargs)
|
|
339
|
+
|
|
340
|
+
def _get_all_options(self):
|
|
341
|
+
options = self.option_list[:]
|
|
342
|
+
for group in self.option_groups:
|
|
343
|
+
if isinstance(group, optparse.OptionGroup):
|
|
344
|
+
options.extend(group.option_list)
|
|
345
|
+
return options
|
|
346
|
+
|
|
347
|
+
def _process_args(self, largs, rargs, values):
|
|
348
|
+
context = self._to_goptioncontext(values)
|
|
349
|
+
|
|
350
|
+
# _process_args() returns the remaining parameters in rargs.
|
|
351
|
+
# The prepended program name is used to all g_set_prgname()
|
|
352
|
+
# The program name is cut away so it doesn't appear in the result.
|
|
353
|
+
rargs[:] = context.parse([sys.argv[0]] + rargs)[1:]
|
|
354
|
+
|
|
355
|
+
def parse_args(self, args=None, values=None):
|
|
356
|
+
try:
|
|
357
|
+
options, args = optparse.OptionParser.parse_args(
|
|
358
|
+
self, args, values)
|
|
359
|
+
except GError:
|
|
360
|
+
error = sys.exc_info()[1]
|
|
361
|
+
if error.domain != OPTION_CONTEXT_ERROR_QUARK:
|
|
362
|
+
raise
|
|
363
|
+
if error.code == GLib.OptionError.BAD_VALUE:
|
|
364
|
+
raise OptionValueError(error.message)
|
|
365
|
+
elif error.code == GLib.OptionError.UNKNOWN_OPTION:
|
|
366
|
+
raise BadOptionError(error.message)
|
|
367
|
+
elif error.code == GLib.OptionError.FAILED:
|
|
368
|
+
raise OptParseError(error.message)
|
|
369
|
+
else:
|
|
370
|
+
raise
|
|
371
|
+
|
|
372
|
+
for group in self.option_groups:
|
|
373
|
+
for key, value in group.values.__dict__.items():
|
|
374
|
+
options.ensure_value(key, value)
|
|
375
|
+
|
|
376
|
+
return options, args
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
make_option = Option
|