desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Iterate over all struct names in no defined order'
def iternames(self):
for index in xrange(self.__get_count_cached()): (yield self.__get_name_cached(index))
'Unref all structs and clear cache'
def clear(self):
self.__infos.clear() self.__names.clear()
'Creates a new class similar to namedtuple. Pass a list of field names or None for no field name. >>> x = ResultTuple._new_type([None, "bar"]) >>> x((1, 3)) ResultTuple(1, bar=3)'
@classmethod def _new_type(cls, args):
fformat = [('%r' if (f is None) else ('%s=%%r' % f)) for f in args] fformat = ('(%s)' % ', '.join(fformat)) class _ResultTuple(cls, ): __slots__ = () _fformat = fformat if args: for (i, a) in enumerate(args): if (a is not None): vars...
'Returns a ReturnValue instance for param type \'index\''
def get_param_type(self, index):
assert (index in (0, 1)) type_info = self.type.get_param_type(index) type_cls = get_return_class(type_info) instance = type_cls(None, type_info, [], self.backend) instance.setup() return instance
'If we get None if the pointer type is NULL'
@property def can_unpack_none(self):
return False
'Returns a ReturnValue instance for param type \'index\''
def get_param_type(self, index):
assert (index in (0, 1)) type_info = self.type.get_param_type(index) type_cls = get_argument_class(type_info) instance = type_cls(None, [], self.backend, None, type_info) instance.setup() return instance
'seq is a sequence of names to reserve'
def add_blacklist(self, seq):
self._blacklist.update(seq)
'Get a random new name, pass an obj to get a cached one'
def __call__(self, *args):
if (not args): self._count += 1 res = ('t%d' % self._count) else: obj = args[0] try: return self._obj_cache[id(obj)][0] except KeyError: self._count += 1 res = ('e%d' % self._count) self._obj_cache[id(obj)] = (res, obj) ...
'Request a name, might return the name or a similar one if already used or reserved'
def request_name(self, name):
while (name in self._blacklist): name += '_' self._blacklist.add(name) return name
'Add a code dependency so it gets inserted into globals'
def add_dependency(self, name, obj):
if (name in self._deps): if (self._deps[name] is obj): return raise ValueError(('There exists a different dep with the same name : %r' % name)) self._deps[name] = obj
'Append this block to another one, passing all dependencies'
def write_into(self, block, level=0):
for (line, l) in self._lines: block.write_line(line, (level + l)) for (name, obj) in _compat.iteritems(self._deps): block.add_dependency(name, obj)
'Append a new line'
def write_line(self, line, level=0):
self._lines.append((line, level))
'Append multiple new lines'
def write_lines(self, lines, level=0):
for line in lines: self.write_line(line, level)
'Execute the python code and returns the global dict. kwargs can contain extra dependencies that get only used at compile time.'
def compile(self, **kwargs):
code = compile(str(self), '<string>', 'exec') global_dict = dict(self._deps) global_dict.update(kwargs) _compat.exec_(code, global_dict) return global_dict
'Print the code block to stdout. Does syntax highlighting if possible.'
def pprint(self, file_=sys.stdout):
code = [] if self._deps: code.append('# dependencies:') for (k, v) in _compat.iteritems(self._deps): code.append(('# %s: %r' % (k, v))) code.append(str(self)) code = '\n'.join(code) if file_.isatty(): try: from pygments import highlight ...
'Returns a ReturnValue instance for param type \'index\''
def get_param_type(self, index):
assert (index in (0, 1)) type_info = self.type.get_param_type(index) type_cls = get_field_class(type_info) instance = type_cls(self.backend, type_info, None) instance.setup() return instance
'Returns a pointer containing the value. This only works for int32/uint32/utf-8..'
def pack_pointer(self, name):
return self.parse(("\nraise $_.TypeError('Can\\'t convert %(type_name)s to pointer: %%r' %% $in_)\n" % {'type_name': type(self).__name__}), in_=name)['in_']
'Gives a ForeignStruct implementation or None'
def _import_foreign(self):
struct_info = self.type.get_interface() assert isinstance(struct_info, GIStructInfo) if (not struct_info.is_foreign): return return foreign.get_foreign(struct_info.namespace, struct_info.name)
'Creates a GError exception and takes ownership if own is True'
@classmethod def _from_gerror(cls, error, own=True):
if (not own): error = error.copy() self = cls() self._error = error return self
'Takes bytes and returns a GITypelib, or raises GIError'
@classmethod def new_from_memory(cls, data):
size = len(data) copy = g_memdup(data, size) ptr = cast(copy, POINTER(guint8)) try: with gerror(GIError) as error: return GITypelib._new_from_memory(ptr, size, error) except GIError: free(copy) raise
'A class decorator to register sub types of GIBaseInfo'
@classmethod def _register(cls, info_type):
def wrap(reg_cls): cls.__types[info_type] = reg_cls return reg_cls return wrap
'Make the Python instance take ownership of the GIBaseInfo. i.e. unref if the python instance gets gc\'ed.'
def _take_ownership(self):
if self: ptr = cast(self.value, GIBaseInfo) _UnrefFinalizer.track(self, ptr) self.__owns = True
'Casts a GIBaseInfo instance to the right sub type. The original GIBaseInfo can\'t have ownership. Will take ownership.'
@classmethod def _cast(cls, base_info, take_ownership=True):
type_value = base_info.type.value try: new_obj = cast(base_info, cls.__types[type_value]) except KeyError: new_obj = base_info if take_ownership: assert (not base_info.__owns) new_obj._take_ownership() return new_obj
'Track an object which needs destruction when it is garbage collected.'
@classmethod def track(cls, obj, ptr):
cls._objects.add(cls(obj, ptr))
'Get a hopefully cache constructor'
@classmethod def _generate_constructor(cls, names):
cache = cls._constructors if (names in cache): return cache[names] elif (len(cache) > 3): cache.clear() func = generate_constructor(cls, names) cache[names] = func return func
'set_property(property_name: str, value: object) Set property *property_name* to *value*.'
def set_property(self, name, value):
if (not hasattr(self.props, name)): raise TypeError(('Unknown property: %r' % name)) setattr(self.props, name, value)
'get_property(property_name: str) -> object Retrieves a property value.'
def get_property(self, name):
if (not hasattr(self.props, name)): raise TypeError(('Unknown property: %r' % name)) return getattr(self.props, name)
'connect(detailed_signal: str, handler: function, *args) -> handler_id: int The connect() method adds a function or method (handler) to the end of the list of signal handlers for the named detailed_signal but before the default class signal handler. An optional set of parameters may be specified after the handler param...
def connect(self, detailed_signal, handler, *args):
return self.__connect(0, detailed_signal, handler, *args)
'connect_after(detailed_signal: str, handler: function, *args) -> handler_id: int The connect_after() method is similar to the connect() method except that the handler is added to the signal handler list after the default class signal handler. Otherwise the details of handler definition and invocation are the same.'
def connect_after(self, detailed_signal, handler, *args):
flags = GConnectFlags.CONNECT_AFTER return self.__connect(flags, detailed_signal, handler, *args)
'handler_block(handler_id: int) -> None Blocks a handler of an instance so it will not be called during any signal emissions unless :meth:`handler_unblock` is called for that *handler_id*. Thus "blocking" a signal handler means to temporarily deactivate it, a signal handler has to be unblocked exactly the same amount o...
def handler_block(self, handler_id):
signal_handler_block(self._obj, handler_id)
'handler_unblock(handler_id: int) -> None'
def handler_unblock(self, handler_id):
signal_handler_unblock(self._obj, handler_id)
'emit(signal_name: str, *args) -> None Emit signal *signal_name*. Signal arguments must follow, e.g. if your signal is of type ``(int,)``, it must be emitted with:: self.emit(signal_name, 42)'
def emit(self, signal_name, *args):
raise NotImplementedError
'freeze_notify() -> None This method freezes all the "notify::" signals (which are emitted when any property is changed) until the :meth:`thaw_notify` method is called. It recommended to use the *with* statement when calling :meth:`freeze_notify`, that way it is ensured that :meth:`thaw_notify` is called implicitly at ...
def freeze_notify(self):
raise NotImplementedError
'thaw_notify() -> None Thaw all the "notify::" signals which were thawed by :meth:`freeze_notify`. It is recommended to not call :meth:`thaw_notify` explicitly but use :meth:`freeze_notify` together with the *with* statement.'
def thaw_notify(self):
raise NotImplementedError
'Class decorator'
@classmethod def register(cls, namespace, name):
def func(kind): cls._FOREIGN[(namespace, name)] = kind() return kind return func
'Raises KeyError'
@classmethod def get(cls, namespace, name):
return cls._FOREIGN[(namespace, name)]
'Create a GVariant object from given format and argument list. This method recursively calls itself for complex structures (arrays, dictionaries, boxed). Return a tuple (variant, rest_format, rest_args) with the generated GVariant, the remainder of the format string, and the remainder of the arguments. If args is None,...
def _create(self, format, args):
constructor = self._LEAF_CONSTRUCTORS.get(format[0]) if constructor: if (args is not None): if (not args): raise TypeError('not enough arguments for GVariant format string') v = constructor(args[0]) return (v, format[1:], args[1:]) ...
'Handle the case where the outermost type of format is a tuple.'
def _create_tuple(self, format, args):
format = format[1:] if (args is None): rest_format = format while rest_format: if rest_format.startswith(')'): break rest_format = self._create(rest_format, None)[1] else: raise TypeError('tuple type string not closed wit...
'Handle the case where the outermost type of format is a dict.'
def _create_dict(self, format, args):
builder = None if ((args is None) or (not args[0])): rest_format = self._create(format[2:], None)[1] rest_format = self._create(rest_format, None)[1] if (not rest_format.startswith('}')): raise TypeError('dictionary type string not closed with }') re...
'Handle the case where the outermost type of format is an array.'
def _create_array(self, format, args):
builder = None if ((args is None) or (not args[0])): rest_format = self._create(format[1:], None)[1] element_type = format[:(len(format) - len(rest_format))] builder = GLib.VariantBuilder.new(variant_type_from_string(element_type)) else: builder = GLib.VariantBuilder.new(vari...
'Create a GVariant from a native Python object. format_string is a standard GVariant type signature, value is a Python object whose structure has to match the signature. Examples: GLib.Variant(\'i\', 1) GLib.Variant(\'(is)\', (1, \'hello\')) GLib.Variant(\'(asa{sv})\', ([], {\'foo\': GLib.Variant(\'b\', True), \'bar\':...
def __new__(cls, format_string, value):
creator = _VariantCreator() (v, rest_format, _) = creator._create(format_string, [value]) if rest_format: raise TypeError(('invalid remaining format string: "%s"' % rest_format)) v.format_string = format_string return v
'Decompose a GVariant into a native Python object.'
def unpack(self):
LEAF_ACCESSORS = {'b': self.get_boolean, 'y': self.get_byte, 'n': self.get_int16, 'q': self.get_uint16, 'i': self.get_int32, 'u': self.get_uint32, 'x': self.get_int64, 't': self.get_uint64, 'h': self.get_handle, 'd': self.get_double, 's': self.get_string, 'o': self.get_string, 'g': self.get_string} la = LEAF_AC...
'Return a list of the element signatures of the topmost signature tuple. If the signature is not a tuple, it returns one element with the entire signature. If the signature is an empty tuple, the result is []. This is useful for e. g. iterating over method parameters which are passed as a single Variant.'
@classmethod def split_signature(klass, signature):
if (signature == '()'): return [] if (not signature.startswith('(')): return [signature] result = [] head = '' tail = signature[1:(-1)] while tail: c = tail[0] head += c tail = tail[1:] if (c in ('m', 'a')): continue if (c in ('...
'Return (red_float, green_float, blue_float) triple.'
def to_floats(self):
return (self.red_float, self.green_float, self.blue_float)
'Return a new Color object from red/green/blue values from 0.0 to 1.0.'
@staticmethod def from_floats(red, green, blue):
return Color(int((red * Color.MAX_VALUE)), int((green * Color.MAX_VALUE)), int((blue * Color.MAX_VALUE)))
'Convert a D-BUS return variant into an appropriate return value'
@classmethod def _unpack_result(klass, result):
result = result.unpack() if (len(result) == 1): result = result[0] elif (len(result) == 0): result = None return result
'style_get_property(property_name, value=None) :param property_name: the name of a style property :type property_name: :obj:`str` :param value: Either :obj:`None` or a correctly initialized :obj:`GObject.Value` :type value: :obj:`GObject.Value` or :obj:`None` :returns: The Python value of the style property {{ docs }}'...
def style_get_property(self, property_name, value=None):
if (value is None): prop = self.find_style_property(property_name) if (prop is None): raise ValueError(('Class "%s" does not contain style property "%s"' % (self, property_name))) value = GObject.Value(prop.value_type) Gtk.Widget.style_get_property(self, ...
'child_get_property(child, property_name, value=None) :param child: a widget which is a child of `self` :type child: :obj:`Gtk.Widget` :param property_name: the name of the property to get :type property_name: :obj:`str` :param value: Either :obj:`None` or a correctly initialized :obj:`GObject.Value` :type value: :obj:...
def child_get_property(self, child, property_name, value=None):
if (value is None): prop = self.find_child_property(property_name) if (prop is None): raise ValueError(('Class "%s" does not contain child property "%s"' % (self, property_name))) value = GObject.Value(prop.value_type) Gtk.Container.child_get_property(sel...
'Returns a list of child property values for the given names.'
def child_get(self, child, *prop_names):
return [self.child_get_property(child, name) for name in prop_names]
'Set a child properties on the given child to key/value pairs.'
def child_set(self, child, **kwargs):
for (name, value) in kwargs.items(): name = name.replace('_', '-') self.child_set_property(child, name, value)
'insert_text(self, text, position) :param new_text: the text to append :type new_text: :obj:`str` :param position: location of the position text will be inserted at :type position: :obj:`int` :returns: location of the position text will be inserted at :rtype: :obj:`int` Inserts `new_text` into the contents of the widge...
def insert_text(self, text, position):
return super(Editable, self).insert_text(text, (-1), position)
'The add_actions() method is a convenience method that creates a number of gtk.Action objects based on the information in the list of action entry tuples contained in entries and adds them to the action group. The entry tuples can vary in size from one to six items with the following information: * The name of the act...
def add_actions(self, entries, user_data=None):
try: iter(entries) except TypeError: raise TypeError('entries must be iterable') def _process_action(name, stock_id=None, label=None, accelerator=None, tooltip=None, callback=None): action = Action(name=name, label=label, tooltip=tooltip, stock_id=stock_id) if (callb...
'The add_toggle_actions() method is a convenience method that creates a number of gtk.ToggleAction objects based on the information in the list of action entry tuples contained in entries and adds them to the action group. The toggle action entry tuples can vary in size from one to seven items with the following inform...
def add_toggle_actions(self, entries, user_data=None):
try: iter(entries) except TypeError: raise TypeError('entries must be iterable') def _process_action(name, stock_id=None, label=None, accelerator=None, tooltip=None, callback=None, is_active=False): action = Gtk.ToggleAction(name=name, label=label, tooltip=tooltip, stock_id=...
'The add_radio_actions() method is a convenience method that creates a number of gtk.RadioAction objects based on the information in the list of action entry tuples contained in entries and adds them to the action group. The entry tuples can vary in size from one to six items with the following information: * The name ...
def add_radio_actions(self, entries, value=None, on_change=None, user_data=None):
try: iter(entries) except TypeError: raise TypeError('entries must be iterable') first_action = None def _process_action(group_source, name, stock_id=None, label=None, accelerator=None, tooltip=None, entry_value=0): action = RadioAction(name=name, label=label, tooltip=to...
'add_ui_from_string(buffer, length=-1) {{ all }}'
def add_ui_from_string(self, buffer, length=(-1)):
return Gtk.UIManager.add_ui_from_string(self, buffer, length)
'connect_signals(self, obj_or_map) Connect signals specified by this builder to a name, handler mapping. Connect signal, name, and handler sets specified in the builder with the given mapping "obj_or_map". The handler/value aspect of the mapping can also contain a tuple in the form of (handler [,arg1 [,argN]]) allowing...
def connect_signals(self, obj_or_map):
self.connect_signals_full(_builder_connect_callback, obj_or_map)
'add_from_string(buffer, length=-1) {{ all }}'
def add_from_string(self, buffer, length=(-1)):
return Gtk.Builder.add_from_string(self, buffer, length)
'add_objects_from_string(buffer, object_ids) :param buffer: the string to parse :type buffer: :obj:`str` :param object_ids: array of objects to build :type object_ids: [:obj:`str`] :raises: :class:`GLib.Error` :returns: A positive value on success, 0 if an error occurred :rtype: :obj:`int` {{ docs }}'
def add_objects_from_string(self, buffer, object_ids):
length = (-1) return Gtk.Builder.add_objects_from_string(self, buffer, length, object_ids)
'add_buttons(*args) The add_buttons() method adds several buttons to the Gtk.Dialog using the button data passed as arguments to the method. This method is the same as calling the Gtk.Dialog.add_button() repeatedly. The button data pairs - button text (or stock ID) and a response ID integer are passed individually. For...
def add_buttons(self, *args):
def _button(b): while b: (t, r) = b[0:2] b = b[2:] (yield (t, r)) try: for (text, response) in _button(args): self.add_button(text, response) except IndexError: raise TypeError('Must pass an even number of arguments')
'Creates a tag and adds it to the tag table of the TextBuffer. :param str tag_name: Name of the new tag, or None :param **properties: Keyword list of properties and their values :returns: A new tag. This is equivalent to creating a Gtk.TextTag and then adding the tag to the buffer\'s tag table. The returned tag is owne...
def create_tag(self, tag_name=None, **properties):
tag = Gtk.TextTag(name=tag_name, **properties) self._get_or_create_tag_table().add(tag) return tag
'set_text(text, length=-1) {{ all }}'
def set_text(self, text, length=(-1)):
Gtk.TextBuffer.set_text(self, text, length)
'insert(iter, text, length=-1) {{ all }}'
def insert(self, iter, text, length=(-1)):
Gtk.TextBuffer.insert(self, iter, text, length)
':param path: the :obj:`Gtk.TreePath`-struct :type path: :obj:`Gtk.TreePath` :raises: :class:`ValueError` if `path` doesn\'t exist :returns: a :obj:`Gtk.TreeIter` :rtype: :obj:`Gtk.TreeIter` Returns an iterator pointing to `path`. If `path` does not exist :class:`ValueError` is raised.'
def get_iter(self, path):
path = self._coerce_path(path) (success, aiter) = super(TreeModel, self).get_iter(path) if (not success): raise ValueError(("invalid tree path '%s'" % path)) return aiter
':param iter: the :obj:`Gtk.TreeIter`-struct :type iter: :obj:`Gtk.TreeIter` :returns: a :obj:`Gtk.TreeIter` or :obj:`None` :rtype: :obj:`Gtk.TreeIter` or :obj:`None` Returns an iterator pointing to the node following `iter` at the current level. If there is no next `iter`, :obj:`None` is returned.'
def iter_next(self, iter):
next_iter = iter.copy() success = super(TreeModel, self).iter_next(next_iter) if success: return next_iter
':param iter: the :obj:`Gtk.TreeIter`-struct :type iter: :obj:`Gtk.TreeIter` :returns: a :obj:`Gtk.TreeIter` or :obj:`None` :rtype: :obj:`Gtk.TreeIter` or :obj:`None` Returns an iterator pointing to the previous node at the current level. If there is no previous `iter`, :obj:`None` is returned.'
def iter_previous(self, iter):
prev_iter = iter.copy() success = super(TreeModel, self).iter_previous(prev_iter) if success: return prev_iter
':param treeiter: the :obj:`Gtk.TreeIter` :type treeiter: :obj:`Gtk.TreeIter` :param row: a list of values for each column :type row: [:obj:`object`] Sets all values of a row pointed to by `treeiter` from a list of values passes as `row`. The length of the row has to match the number of columns of the model. :obj:`None...
def set_row(self, treeiter, row):
(converted_row, columns) = self._convert_row(row) for column in columns: value = row[column] if (value is None): continue self.set_value(treeiter, column, value)
'Convert value to a GObject.Value of the expected type'
def _convert_value(self, column, value):
if isinstance(value, GObject.Value): return value return GObject.Value(self.get_column_type(column), value)
':param treeiter: the :obj:`Gtk.TreeIter` :type treeiter: :obj:`Gtk.TreeIter` :param \*columns: a list of column indices to fetch :type columns: (:obj:`int`) Returns a tuple of all values specified by their indices in `columns` in the order the indices are contained in `columns` Also see :obj:`Gtk.TreeStore.get_value`\...
def get(self, treeiter, *columns):
n_columns = self.get_n_columns() values = [] for col in columns: if (not isinstance(col, int)): raise TypeError('column numbers must be ints') if ((col < 0) or (col >= n_columns)): raise ValueError('column number is out of range') va...
'append(row=None) :param row: a list of values to apply to the newly append row or :obj:`None` :type row: [:obj:`object`] or :obj:`None` :returns: :obj:`Gtk.TreeIter` of the appended row :rtype: :obj:`Gtk.TreeIter` If `row` is :obj:`None` the appended row will be empty and to fill in values you need to call :obj:`Gtk.L...
def append(self, row=None):
if row: return self._do_insert((-1), row) else: return Gtk.ListStore.append(self)
'prepend(row=None) :param row: a list of values to apply to the newly prepend row or :obj:`None` :type row: [:obj:`object`] or :obj:`None` :returns: :obj:`Gtk.TreeIter` of the prepended row :rtype: :obj:`Gtk.TreeIter` If `row` is :obj:`None` the prepended row will be empty and to fill in values you need to call :obj:`G...
def prepend(self, row=None):
return self._do_insert(0, row)
'insert(position, row=None) :param position: the position the new row will be inserted at :type position: :obj:`int` :param row: a list of values to apply to the newly inserted row or :obj:`None` :type row: [:obj:`object`] or :obj:`None` :returns: :obj:`Gtk.TreeIter` of the inserted row :rtype: :obj:`Gtk.TreeIter` If `...
def insert(self, position, row=None):
return self._do_insert(position, row)
'insert_before(sibling, row=None) :param sibling: A valid :obj:`Gtk.TreeIter`, or :obj:`None` :type sibling: :obj:`Gtk.TreeIter` or :obj:`None` :param row: a list of values to apply to the newly inserted row or :obj:`None` :type row: [:obj:`object`] or :obj:`None` :returns: :obj:`Gtk.TreeIter` pointing to the new row :...
def insert_before(self, sibling, row=None):
treeiter = Gtk.ListStore.insert_before(self, sibling) if (row is not None): self.set_row(treeiter, row) return treeiter
'insert_after(sibling, row=None) :param sibling: A valid :obj:`Gtk.TreeIter`, or :obj:`None` :type sibling: :obj:`Gtk.TreeIter` or :obj:`None` :param row: a list of values to apply to the newly inserted row or :obj:`None` :type row: [:obj:`object`] or :obj:`None` :returns: :obj:`Gtk.TreeIter` pointing to the new row :r...
def insert_after(self, sibling, row=None):
treeiter = Gtk.ListStore.insert_after(self, sibling) if (row is not None): self.set_row(treeiter, row) return treeiter
'{{ all }} `value` can also be a Python value and will be converted to a :obj:`GObject.Value` using the corresponding column type (See :obj:`Gtk.ListStore.set_column_types`\()).'
def set_value(self, treeiter, column, value):
value = self._convert_value(column, value) Gtk.ListStore.set_value(self, treeiter, column, value)
'The tree path of the row'
@property def path(self):
return self.model.get_path(self.iter)
'The next :obj:`Gtk.TreeModelRow` or None'
@property def next(self):
return self.get_next()
'The previous :obj:`Gtk.TreeModelRow` or None'
@property def previous(self):
return self.get_previous()
'The parent :obj:`Gtk.TreeModelRow` or htis row or None'
@property def parent(self):
return self.get_parent()
'Returns the next :obj:`Gtk.TreeModelRow` or None'
def get_next(self):
next_iter = self.model.iter_next(self.iter) if next_iter: return TreeModelRow(self.model, next_iter)
'Returns the previous :obj:`Gtk.TreeModelRow` or None'
def get_previous(self):
prev_iter = self.model.iter_previous(self.iter) if prev_iter: return TreeModelRow(self.model, prev_iter)
'Returns the parent :obj:`Gtk.TreeModelRow` or htis row or None'
def get_parent(self):
parent_iter = self.model.iter_parent(self.iter) if parent_iter: return TreeModelRow(self.model, parent_iter)
'Returns a :obj:`Gtk.TreeModelRowIter` for the row\'s children'
def iterchildren(self):
child_iter = self.model.iter_children(self.iter) return TreeModelRowIter(self.model, child_iter)
'append(parent, row=None) :param parent: A valid :obj:`Gtk.TreeIter`, or :obj:`None` :type parent: :obj:`Gtk.TreeIter` or :obj:`None` :param row: a list of values to apply to the newly inserted row or :obj:`None` :type row: [:obj:`object`] or :obj:`None` :returns: obj:`Gtk.TreeIter` pointing to the inserted row :rtype:...
def append(self, parent, row=None):
return self._do_insert(parent, (-1), row)
'prepend(parent, row=None) :param parent: A valid :obj:`Gtk.TreeIter`, or :obj:`None` :type parent: :obj:`Gtk.TreeIter` or :obj:`None` :param row: a list of values to apply to the newly inserted row or :obj:`None` :type row: [:obj:`object`] or :obj:`None` :returns: obj:`Gtk.TreeIter` pointing to the inserted row :rtype...
def prepend(self, parent, row=None):
return self._do_insert(parent, 0, row)
'insert(parent, position, row=None) :param parent: A valid :obj:`Gtk.TreeIter`, or :obj:`None` :type parent: :obj:`Gtk.TreeIter` or :obj:`None` :param position: position to insert the new row, or -1 for last :type position: :obj:`int` :param row: a list of values to apply to the newly inserted row or :obj:`None` :type ...
def insert(self, parent, position, row=None):
return self._do_insert(parent, position, row)
'insert_before(parent, sibling, row=None) :param parent: A valid :obj:`Gtk.TreeIter`, or :obj:`None` :type parent: :obj:`Gtk.TreeIter` or :obj:`None` :param sibling: A valid :obj:`Gtk.TreeIter`, or :obj:`None` :type sibling: :obj:`Gtk.TreeIter` or :obj:`None` :param row: a list of values to apply to the newly inserted ...
def insert_before(self, parent, sibling, row=None):
treeiter = Gtk.TreeStore.insert_before(self, parent, sibling) if (row is not None): self.set_row(treeiter, row) return treeiter
':param parent: A valid :obj:`Gtk.TreeIter`, or :obj:`None` :type parent: :obj:`Gtk.TreeIter` or :obj:`None` :param sibling: A valid :obj:`Gtk.TreeIter`, or :obj:`None` :type sibling: :obj:`Gtk.TreeIter` or :obj:`None` :param row: a list of values to apply to the newly inserted row or :obj:`None` :type row: [:obj:`obje...
def insert_after(self, parent, sibling, row=None):
treeiter = Gtk.TreeStore.insert_after(self, parent, sibling) if (row is not None): self.set_row(treeiter, row) return treeiter
'{{ all }} `value` can also be a Python value and will be converted to a :obj:`GObject.Value` using the corresponding column type (See :obj:`Gtk.ListStore.set_column_types`\()).'
def set_value(self, treeiter, column, value):
value = self._convert_value(column, value) Gtk.TreeStore.set_value(self, treeiter, column, value)
':param position: The position to insert the new column in :type position: :obj:`int` :param title: The title to set the header to :type title: :obj:`str` :param cell: The :obj:`Gtk.CellRenderer` :type cell: :obj:`Gtk.CellRenderer` {{ docs }}'
def insert_column_with_attributes(self, position, title, cell, **kwargs):
column = TreeViewColumn() column.set_title(title) column.pack_start(cell, False) self.insert_column(column, position) column.set_attributes(cell, **kwargs)
':param cell_renderer: the :obj:`Gtk.CellRenderer` we\'re setting the attributes of :type cell_renderer: :obj:`Gtk.CellRenderer` {{ docs }}'
def set_attributes(self, cell_renderer, **attributes):
Gtk.CellLayout.clear_attributes(self, cell_renderer) for (name, value) in attributes.items(): Gtk.CellLayout.add_attribute(self, cell_renderer, name, value)
':returns: :model: the :obj:`Gtk.TreeModel` :iter: The :obj:`Gtk.TreeIter` or :obj:`None` :rtype: (**model**: :obj:`Gtk.TreeModel`, **iter**: :obj:`Gtk.TreeIter` or :obj:`None`) {{ docs }}'
def get_selected(self):
(success, model, aiter) = super(TreeSelection, self).get_selected() if success: return (model, aiter) else: return (model, None)
':returns: A list containing a :obj:`Gtk.TreePath` for each selected row and a :obj:`Gtk.TreeModel` or :obj:`None`. :rtype: (:obj:`Gtk.TreeModel`, [:obj:`Gtk.TreePath`]) {{ docs }}'
def get_selected_rows(self):
(rows, model) = super(TreeSelection, self).get_selected_rows() return (model, rows)
'Set the value of the child model'
def set_value(self, iter, column, value):
iter = self.convert_iter_to_child_iter(iter) self.get_model().set_value(iter, column, value)
'Helper function to fetch values from owning section. Returns a 2-tuple: the value, and the section where it was found.'
def _fetch(self, key):
save_interp = self.section.main.interpolation self.section.main.interpolation = False current_section = self.section while True: val = current_section.get(key) if (val is not None): break val = current_section.get('DEFAULT', {}).get(key) if (val is not None): ...
'Implementation-dependent helper function. Will be passed a match object corresponding to the interpolation key we just found (e.g., "%(foo)s" or "$foo"). Should look up that key in the appropriate config file section (using the ``_fetch()`` helper function) and return a 3-tuple: (key, value, section) ``key`` is the na...
def _parse_match(self, match):
raise NotImplementedError()
'* parent is the section above * depth is the depth level of this section * main is the main ConfigObj * indict is a dictionary to initialise the section with'
def __init__(self, parent, depth, main, indict=None, name=None):
if (indict is None): indict = {} dict.__init__(self) self.parent = parent self.main = main self.depth = depth self.name = name self._initialise() for (entry, value) in indict.iteritems(): self[entry] = value
'Fetch the item and do string interpolation.'
def __getitem__(self, key):
val = dict.__getitem__(self, key) if (self.main.interpolation and isinstance(val, basestring)): return self._interpolate(key, val) return val
'Correctly set a value. Making dictionary values Section instances. (We have to special case \'Section\' instances - which are also dicts) Keys must be strings. Values need only be strings (or lists of strings) if ``main.stringify`` is set. ``unrepr`` must be set when setting a value to a dictionary, without creating a...
def __setitem__(self, key, value, unrepr=False):
if (not isinstance(key, basestring)): raise ValueError(('The key "%s" is not a string.' % key)) if (not self.comments.has_key(key)): self.comments[key] = [] self.inline_comments[key] = '' if (key in self.defaults): self.defaults.remove(key) if isinstance...
'Remove items from the sequence when deleting.'
def __delitem__(self, key):
dict.__delitem__(self, key) if (key in self.scalars): self.scalars.remove(key) else: self.sections.remove(key) del self.comments[key] del self.inline_comments[key]
'A version of ``get`` that doesn\'t bypass string interpolation.'
def get(self, key, default=None):
try: return self[key] except KeyError: return default