Ejemplo n.º 1
0
        fset=lambda self, v: setattr(self, 'blue', int(v * self.MAX_VALUE)))

    def to_floats(self):
        """Return (red_float, green_float, blue_float) triple."""

        return (self.red_float, self.green_float, self.blue_float)

    @staticmethod
    def from_floats(red, green, blue):
        """Return a new Color object from red/green/blue values from 0.0 to 1.0."""

        return Color(int(red * Color.MAX_VALUE), int(green * Color.MAX_VALUE),
                     int(blue * Color.MAX_VALUE))


Color = override(Color)
__all__.append('Color')

if Gdk._version == '3.0':

    class RGBA(Gdk.RGBA):
        def __init__(self, red=1.0, green=1.0, blue=1.0, alpha=1.0):
            Gdk.RGBA.__init__(self)
            self.red = red
            self.green = green
            self.blue = blue
            self.alpha = alpha

        def __eq__(self, other):
            return self.equal(other)
Ejemplo n.º 2
0
Archivo: Pango.py Proyecto: Readon/pgi
# USA

from pgi.overrides import override, get_introspection_module


Pango = get_introspection_module('Pango')

__all__ = []


class Context(Pango.Context):

    def get_metrics(self, desc, language=None):
        return super(Context, self).get_metrics(desc, language)

Context = override(Context)
__all__.append('Context')


class FontDescription(Pango.FontDescription):

    def __new__(cls, string=None):
        if string is not None:
            return Pango.font_description_from_string(string)
        else:
            return Pango.FontDescription.__new__(cls)

FontDescription = override(FontDescription)
__all__.append('FontDescription')

Ejemplo n.º 3
0
                fn = GLib.unix_signal_add
            else:
                fn = GLib.unix_signal_add_full
            self._signal_source = fn(GLib.PRIORITY_DEFAULT, signal.SIGINT, _handler, self)

    def __del__(self):
        if hasattr(self, '_signal_source'):
            GLib.source_remove(self._signal_source)

    def run(self):
        super(MainLoop, self).run()
        if hasattr(self, '_quit_by_sigint'):
            # caught by _main_loop_sigint_handler()
            raise KeyboardInterrupt

MainLoop = override(MainLoop)
__all__.append('MainLoop')


class MainContext(GLib.MainContext):
    # Backwards compatible API with default value
    def iteration(self, may_block=True):
        return super(MainContext, self).iteration(may_block)

MainContext = override(MainContext)
__all__.append('MainContext')


class Source(GLib.Source):
    def __new__(cls, *args, **kwargs):
        # use our custom pyg_source_new() here as g_source_new() is not
Ejemplo n.º 4
0
Pango = get_introspection_module('Pango')

__all__ = []


class FontDescription(Pango.FontDescription):
    def __new__(cls, string=None):
        if string is not None:
            return Pango.font_description_from_string(string)
        else:
            return Pango.FontDescription.__new__(cls)

    def __init__(self, *args, **kwargs):
        return super(FontDescription, self).__init__()


FontDescription = override(FontDescription)
__all__.append('FontDescription')


class Layout(Pango.Layout):
    def __new__(cls, context):
        return Pango.Layout.new(context)

    def set_markup(self, text, length=-1):
        super(Layout, self).set_markup(text, length)


Layout = override(Layout)
__all__.append('Layout')
Ejemplo n.º 5
0
            return self.get_object()
        elif gtype == TYPE_UNICHAR:
            return self.get_uint()
        elif gtype == TYPE_GTYPE:
            return self.get_gtype()
        elif gtype == TYPE_VARIANT:
            return self.get_variant()
        elif gtype == TYPE_PYOBJECT:
            pass
        else:
            return None

    def __repr__(self):
        return '<Value (%s) %s>' % (self.g_type.name, self.get_value())

Value = override(Value)
__all__.append('Value')


def type_from_name(name):
    type_ = GObjectModule.type_from_name(name)
    if type_ == TYPE_INVALID:
        raise RuntimeError('unknown type name: %s' % name)
    return type_

__all__.append('type_from_name')


def type_parent(type_):
    parent = GObjectModule.type_parent(type_)
    if parent == TYPE_INVALID:
Ejemplo n.º 6
0
        elif gtype == TYPE_UNICHAR:
            return self.get_uint()
        elif gtype == TYPE_GTYPE:
            return self.get_gtype()
        elif gtype == TYPE_VARIANT:
            return self.get_variant()
        elif gtype == TYPE_PYOBJECT:
            pass
        else:
            return None

    def __repr__(self):
        return '<Value (%s) %s>' % (self.g_type.name, self.get_value())


Value = override(Value)
__all__.append('Value')


def type_from_name(name):
    type_ = GObjectModule.type_from_name(name)
    if type_ == TYPE_INVALID:
        raise RuntimeError('unknown type name: %s' % name)
    return type_


__all__.append('type_from_name')


def type_parent(type_):
    parent = GObjectModule.type_parent(type_)
Ejemplo n.º 7
0
Archivo: Gio.py Proyecto: pwaller/pgi
    def __iter__(self):
        return self

    def __next__(self):
        file_info = self.next_file(None)

        if file_info is not None:
            return file_info
        else:
            raise StopIteration

    # python 2 compat for the iter protocol
    next = __next__


FileEnumerator = override(FileEnumerator)
__all__.append('FileEnumerator')


class MenuItem(Gio.MenuItem):
    def set_attribute(self, attributes):
        for (name, format_string, value) in attributes:
            self.set_attribute_value(name, GLib.Variant(format_string, value))


MenuItem = override(MenuItem)
__all__.append('MenuItem')


class Settings(Gio.Settings):
    '''Provide dictionary-like access to GLib.Settings.'''
Ejemplo n.º 8
0
class Rectangle(Structure):
    _fields_ = [
        ("x1", c_double),
        ("y1", c_double),
        ("x2", c_double),
        ("y2", c_double),
    ]

    def __repr__(self):
        fmt = '<Rectangle x1="{:8.3f}" y1="{:8.3f}" x2="{:8.3f}" y2="{:8.3f}">'
        return fmt.format(self.x1, self.y1, self.x2, self.y2)


class Page(Poppler.Page):

    def get_text_layout(self):
        length = c_uint()
        ptr = c_void_p()

        args = c_void_p(self._obj), byref(ptr), byref(length)
        ok = poppler_page_get_text_layout(*args)
        if not ok:
            return False, None

        result = (Rectangle * length.value).from_address(ptr.value)
        _FreeFinalizer.track(result, ptr)
        return True, result

Page = override(Page)
__all__.append('Page')
Ejemplo n.º 9
0
    def __iter__(self):
        return self

    def __next__(self):
        file_info = self.next_file(None)

        if file_info is not None:
            return file_info
        else:
            raise StopIteration

    # python 2 compat for the iter protocol
    next = __next__


FileEnumerator = override(FileEnumerator)
__all__.append('FileEnumerator')


class MenuItem(Gio.MenuItem):
    def set_attribute(self, attributes):
        for (name, format_string, value) in attributes:
            self.set_attribute_value(name, GLib.Variant(format_string, value))


MenuItem = override(MenuItem)
__all__.append('MenuItem')


class Settings(Gio.Settings):
    '''Provide dictionary-like access to GLib.Settings.'''
Ejemplo n.º 10
0
Pango = get_introspection_module('Pango')

__all__ = []


class FontDescription(Pango.FontDescription):

    def __new__(cls, string=None):
        if string is not None:
            return Pango.font_description_from_string(string)
        else:
            return Pango.FontDescription.__new__(cls)

    def __init__(self, *args, **kwargs):
        return super(FontDescription, self).__init__()

FontDescription = override(FontDescription)
__all__.append('FontDescription')


class Layout(Pango.Layout):

    def __new__(cls, context):
        return Pango.Layout.new(context)

    def set_markup(self, text, length=-1):
        super(Layout, self).set_markup(text, length)

Layout = override(Layout)
__all__.append('Layout')
Ejemplo n.º 11
0
                          fset=lambda self, v: setattr(self, 'blue', int(v * self.MAX_VALUE)))

    def to_floats(self):
        """Return (red_float, green_float, blue_float) triple."""

        return (self.red_float, self.green_float, self.blue_float)

    @staticmethod
    def from_floats(red, green, blue):
        """Return a new Color object from red/green/blue values from 0.0 to 1.0."""

        return Color(int(red * Color.MAX_VALUE),
                     int(green * Color.MAX_VALUE),
                     int(blue * Color.MAX_VALUE))

Color = override(Color)
__all__.append('Color')

if Gdk._version == '3.0':
    class RGBA(Gdk.RGBA):
        def __init__(self, red=1.0, green=1.0, blue=1.0, alpha=1.0):
            Gdk.RGBA.__init__(self)
            self.red = red
            self.green = green
            self.blue = blue
            self.alpha = alpha

        def __eq__(self, other):
            return self.equal(other)

        def __repr__(self):
Ejemplo n.º 12
0
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
# USA

from pgi.overrides import override, get_introspection_module

Pango = get_introspection_module('Pango')

__all__ = []


class Context(Pango.Context):
    def get_metrics(self, desc, language=None):
        return super(Context, self).get_metrics(desc, language)


Context = override(Context)
__all__.append('Context')


class FontDescription(Pango.FontDescription):
    def __new__(cls, string=None):
        if string is not None:
            return Pango.font_description_from_string(string)
        else:
            return Pango.FontDescription.__new__(cls)


FontDescription = override(FontDescription)
__all__.append('FontDescription')

Ejemplo n.º 13
0
class Rectangle(Structure):
    _fields_ = [
        ("x1", c_double),
        ("y1", c_double),
        ("x2", c_double),
        ("y2", c_double),
    ]

    def __repr__(self):
        fmt = '<Rectangle x1="{:8.3f}" y1="{:8.3f}" x2="{:8.3f}" y2="{:8.3f}">'
        return fmt.format(self.x1, self.y1, self.x2, self.y2)


class Page(Poppler.Page):
    def get_text_layout(self):
        length = c_uint()
        ptr = c_void_p()

        args = c_void_p(self._obj), byref(ptr), byref(length)
        ok = poppler_page_get_text_layout(*args)
        if not ok:
            return False, None

        result = (Rectangle * length.value).from_address(ptr.value)
        _FreeFinalizer.track(result, ptr)
        return True, result


Page = override(Page)
__all__.append('Page')
Ejemplo n.º 14
0
            return self.get_object()
        elif gtype == TYPE_UNICHAR:
            return self.get_uint()
        elif gtype == TYPE_GTYPE:
            return self.get_gtype()
        elif gtype == TYPE_VARIANT:
            return self.get_variant()
        elif gtype == TYPE_PYOBJECT:
            pass
        else:
            return None

    def __repr__(self):
        return '<Value (%s) %s>' % (self.g_type.name, self.get_value())

Value = override(Value)
__all__.append('Value')


def type_from_name(name):
    type_ = GObjectModule.type_from_name(name)
    if type_ == TYPE_INVALID:
        raise RuntimeError('unknown type name: %s' % name)
    return type_

__all__.append('type_from_name')


def type_parent(type_):
    parent = GObjectModule.type_parent(type_)
    if parent == TYPE_INVALID: