Ejemplo n.º 1
0
 def test_columns(self):
     self.assertEqual(self.store.get_n_columns(),
                      len(_DummyObject.Meta.get_column_properties()))
     self.assertEqual(self.store.get_column_type(self.store.c_name),
                      GObject.type_from_name("gchararray"))
     self.assertEqual(self.store.get_column_type(self.store.c_number),
                      GObject.type_from_name("gdouble"))
     self.assertEqual(self.store.get_column_type(self.store.c_test),
                      GObject.type_from_name("PyObject"))
Ejemplo n.º 2
0
 def test_type_from_name(self):
     # A complete test is not needed here since the TYPE_* defines are created
     # using this method.
     self.assertRaises(RuntimeError, GObject.type_from_name,
                       '!NOT_A_REAL_TYPE!')
     self.assertEqual(GObject.type_from_name('GObject'),
                      GObject.TYPE_OBJECT)
     self.assertEqual(GObject.type_from_name('GObject'),
                      GObject.GObject.__gtype__)
Ejemplo n.º 3
0
    def test_from_name(self):
        self.assertEqual(GObject.type_from_name("glong"), GObject.TYPE_LONG)
        self.assertEqual(GObject.type_from_name("GObject"),
                         GObject.TYPE_OBJECT)
        # gi fails..
        try:
            self.assertEqual(GObject.type_from_name("invalid"),
                             GObject.TYPE_INVALID)
        except RuntimeError:
            pass

        self.assertRaises(TypeError, GObject.GType.from_name, None)
        self.assertRaises(TypeError, GObject.GType.from_name, [])
        GObject.GType.from_name(u"void")
Ejemplo n.º 4
0
    def test_from_name(self):
        self.assertEqual(GObject.type_from_name("glong"), GObject.TYPE_LONG)
        self.assertEqual(
            GObject.type_from_name("GObject"), GObject.TYPE_OBJECT)
        # gi fails..
        try:
            self.assertEqual(
                GObject.type_from_name("invalid"), GObject.TYPE_INVALID)
        except RuntimeError:
            pass

        self.assertRaises(TypeError, GObject.GType.from_name, None)
        self.assertRaises(TypeError, GObject.GType.from_name, [])
        GObject.GType.from_name(u"void")
Ejemplo n.º 5
0
 def __init__(self, exec_by_ibus):
     engine_name = "replace-with-kanji-python" if exec_by_ibus else "replace-with-kanji-python (debug)"
     self.__component = IBus.Component.new(
         "org.freedesktop.IBus.ReplaceWithKanji",
         "Replace With Kanji Input Method", "0.8.0", "Apache",
         "Esrille Inc. <*****@*****.**>",
         "https://github.com/esrille/ibus-replace-with-kanji",
         "/usr/bin/exec", "ibus-replace-with-kanji")
     engine = IBus.EngineDesc.new("replace-with-kanji-python", engine_name,
                                  "Japanese Replace With Kanji", "ja",
                                  "Apache",
                                  "Esrille Inc. <*****@*****.**>", "",
                                  "us")
     self.__component.add_engine(engine)
     self.__mainloop = GLib.MainLoop()
     self.__bus = IBus.Bus()
     self.__bus.connect("disconnected", self.__bus_disconnected_cb)
     self.__factory = IBus.Factory.new(self.__bus.get_connection())
     self.__factory.add_engine(
         "replace-with-kanji-python",
         GObject.type_from_name("EngineReplaceWithKanji"))
     if exec_by_ibus:
         self.__bus.request_name("org.freedesktop.IBus.ReplaceWithKanji", 0)
     else:
         self.__bus.register_component(self.__component)
         self.__bus.set_global_engine_async("replace-with-kanji-python", -1,
                                            None, None, None)
Ejemplo n.º 6
0
 def __init__(self, exec_by_ibus):
     self.__id = 0
     engine_name = "BoGo Engine"
     self.__component = \
       IBus.Component.new("org.freedesktop.IBus.BoGoPython",
                          "BoGo Engine for IBus",
                          "0.2",
                          "GPLv3",
                          "Long T. Dam <*****@*****.**>",
                          "https://github.com/BoGoEngine/ibus-bogo-python",
                          "/usr/bin/exec",
                          "ibus-bogo")
     engine = IBus.EngineDesc(name="bogo-python",
                              longname=engine_name,
                              description="BoGo Engine for IBus",
                              language="vi",
                              license="GPLv3",
                              author="Long T. Dam <*****@*****.**>",
                              icon=current_path + "/data/ibus-bogo.svg",
                              layout="us")
     self.__component.add_engine(engine)
     self.__mainloop = GObject.MainLoop()
     self.__bus = IBus.Bus()
     self.__bus.connect("disconnected", self.__bus_disconnected_cb)
     self.__config = Config()
     self.__factory = IBus.Factory.new(self.__bus.get_connection())
     self.__factory.add_engine("bogo-python",
                               GObject.type_from_name("EngineBoGo"))
     if exec_by_ibus:
         self.__bus.request_name("org.freedesktop.IBus.BoGoPython", 0)
     else:
         self.__bus.register_component(self.__component)
         self.__bus.set_global_engine_async("bogo-python", -1, None, None,
                                            None)
Ejemplo n.º 7
0
    def test_gtypes(self):
        gchararray_gtype = GObject.type_from_name('gchararray')
        gtype = Everything.test_gtype(str)
        self.assertEqual(gchararray_gtype, gtype)
        gtype = Everything.test_gtype('gchararray')
        self.assertEqual(gchararray_gtype, gtype)
        gobject_gtype = GObject.GObject.__gtype__
        gtype = Everything.test_gtype(GObject.GObject)
        self.assertEqual(gobject_gtype, gtype)
        gtype = Everything.test_gtype('GObject')
        self.assertEqual(gobject_gtype, gtype)
        self.assertRaises(TypeError, Everything.test_gtype, 'invalidgtype')

        class NotARegisteredClass(object):
            pass

        self.assertRaises(TypeError, Everything.test_gtype, NotARegisteredClass)

        class ARegisteredClass(GObject.GObject):
            __gtype_name__ = 'EverythingTestsARegisteredClass'

        gtype = Everything.test_gtype('EverythingTestsARegisteredClass')
        self.assertEqual(ARegisteredClass.__gtype__, gtype)
        gtype = Everything.test_gtype(ARegisteredClass)
        self.assertEqual(ARegisteredClass.__gtype__, gtype)
        self.assertRaises(TypeError, Everything.test_gtype, 'ARegisteredClass')
Ejemplo n.º 8
0
 def __init__(self, exec_by_ibus):
     engine_name = "KeyboardChorder" if exec_by_ibus else "KeyboardChorder dbg"
     self.__component = \
             IBus.Component.new("com.github.bfredl.KeyboardChorder",
                                "KeyboardChorder IBus component",
                                "0.0.0",
                                "MIT",
                                "Björn Linse <*****@*****.**> ",
                                "http://bfredl.github.io",
                                "/usr/bin/FIXME",
                                "ibus-FIXME")
     engine = IBus.EngineDesc.new("KeyboardChorder",
                                  engine_name,
                                  "Crazy keyboard chords",
                                  "en",
                                  "MIT",
                                  "Björn Linse <*****@*****.**> ",
                                  "",
                                  "se")
     self.__component.add_engine(engine)
     self.__mainloop = GLib.MainLoop()
     self.__bus = IBus.Bus()
     self.__bus.connect("disconnected", self.__bus_disconnected_cb)
     self.__factory = IBus.Factory.new(self.__bus.get_connection())
     self.__factory.add_engine("KeyboardChorder",
             GObject.type_from_name("ChordEngine"))
     if exec_by_ibus:
         self.__bus.request_name("com.github.bfredl.KeyboardChorder", 0)
     else:
         self.__bus.register_component(self.__component)
         self.__bus.set_global_engine_async(
                 "KeyboardChorder", -1, None, None, None)
Ejemplo n.º 9
0
    def test_gtypes(self):
        gchararray_gtype = GObject.type_from_name("gchararray")
        gtype = Everything.test_gtype(str)
        self.assertEqual(gchararray_gtype, gtype)
        gtype = Everything.test_gtype("gchararray")
        self.assertEqual(gchararray_gtype, gtype)
        gobject_gtype = GObject.GObject.__gtype__
        gtype = Everything.test_gtype(GObject.GObject)
        self.assertEqual(gobject_gtype, gtype)
        gtype = Everything.test_gtype("GObject")
        self.assertEqual(gobject_gtype, gtype)
        self.assertRaises(TypeError, Everything.test_gtype, "invalidgtype")

        class NotARegisteredClass(object):
            pass

        self.assertRaises(TypeError, Everything.test_gtype, NotARegisteredClass)

        class ARegisteredClass(GObject.GObject):
            __gtype_name__ = "EverythingTestsARegisteredClass"

        gtype = Everything.test_gtype("EverythingTestsARegisteredClass")
        self.assertEqual(ARegisteredClass.__gtype__, gtype)
        gtype = Everything.test_gtype(ARegisteredClass)
        self.assertEqual(ARegisteredClass.__gtype__, gtype)
        self.assertRaises(TypeError, Everything.test_gtype, "ARegisteredClass")
Ejemplo n.º 10
0
 def __init__(self, exec_by_ibus: bool) -> None:
     engine_name = "deepspeech" if exec_by_ibus else "deepspeech (debug)"
     self.__component = IBus.Component.new(
         "org.freedesktop.IBus.DeepSpeech",
         "DeepSpeech Speech Recognition Component",
         "0.1.0",
         "GPL",
         "Mike Sheldon <*****@*****.**>",
         "https://github.com/Elleo/ibus-deepspeech",
         "/usr/bin/exec",
         "ibus-deepspeech",
     )
     engine = IBus.EngineDesc.new(
         "deepspeech",
         engine_name,
         "English Speech Recognition (DeepSpeech)",
         "en",
         "GPL",
         "Mike Sheldon <*****@*****.**>",
         "",
         "us",
     )
     self.__component.add_engine(engine)
     self.__mainloop = GLib.MainLoop()
     self.__bus = IBus.Bus()
     self.__bus.connect("disconnected", self.__bus_disconnected_cb)
     self.__factory = IBus.Factory.new(self.__bus.get_connection())
     self.__factory.add_engine("deepspeech",
                               GObject.type_from_name("EngineDeepSpeech"))
     if exec_by_ibus:
         self.__bus.request_name("org.freedesktop.IBus.DeepSpeech", 0)
     else:
         self.__bus.register_component(self.__component)
         self.__bus.set_global_engine_async("deepspeech", -1, None, None,
                                            None)
Ejemplo n.º 11
0
def _check_videosink():
    from gi.repository import Gst
    from gi.repository import Gdk
    from gi.repository import GObject

    global videosink_factory

    try:
        # If using GdkBroadwayDisplay make sure not to try to use gtkglsink
        # as it would segfault right away.
        if GObject.type_is_a(Gdk.Display.get_default().__gtype__, GObject.type_from_name("GdkBroadwayDisplay")):
            videosink_factory = Gst.ElementFactory.find("gtksink")
            return True
    except RuntimeError:
        pass

    if "gtkglsink" in os.environ.get("PITIVI_UNSTABLE_FEATURES", ""):
        sink = Gst.ElementFactory.make("gtkglsink", None)
        if not sink:
            videosink_factory = sink.get_factory()
        elif sink.set_state(Gst.State.READY) == Gst.StateChangeReturn.SUCCESS:
            videosink_factory = sink.get_factory()
            sink.set_state(Gst.State.NULL)
        else:
            videosink_factory = Gst.ElementFactory.find("gtksink")
    else:
        videosink_factory = Gst.ElementFactory.find("gtksink")

    if videosink_factory:
        return True

    return False
Ejemplo n.º 12
0
 def __init__(self, exec_by_ibus):
     self.__id = 0
     engine_name = "BoGo Engine"
     self.__component = \
       IBus.Component.new("org.freedesktop.IBus.BoGoPython",
                          "BoGo Engine for IBus",
                          "0.2",
                          "GPLv3",
                          "Long T. Dam <*****@*****.**>",
                          "https://github.com/BoGoEngine/ibus-bogo-python",
                          "/usr/bin/exec",
                          "ibus-bogo")
     engine = IBus.EngineDesc(name = "bogo-python",
                               longname = engine_name,
                               description = "BoGo Engine for IBus",
                               language = "vi",
                               license = "GPLv3",
                               author = "Long T. Dam <*****@*****.**>",
                               icon = current_path + "/data/ibus-bogo.svg",
                               layout = "us")
     self.__component.add_engine(engine)
     self.__mainloop = GObject.MainLoop()
     self.__bus = IBus.Bus()
     self.__bus.connect("disconnected", self.__bus_disconnected_cb)
     self.__config = Config()
     self.__factory = IBus.Factory.new(self.__bus.get_connection())
     self.__factory.add_engine("bogo-python",
             GObject.type_from_name("EngineBoGo"))
     if exec_by_ibus:
         self.__bus.request_name("org.freedesktop.IBus.BoGoPython", 0)
     else:
         self.__bus.register_component(self.__component)
         self.__bus.set_global_engine_async(
                 "bogo-python", -1, None, None, None)
Ejemplo n.º 13
0
 def __init__(self, exec_by_ibus):
     engine_name = "enchant python" if exec_by_ibus else "enchant python (debug)"
     self.__component = \
             IBus.Component.new("org.freedesktop.IBus.EnchantPython",
                                "Enchant Python Component",
                                "0.1.0",
                                "GPL",
                                "Peng Huang <*****@*****.**>",
                                "http://example.com",
                                "/usr/bin/exec",
                                "ibus-enchant")
     engine = IBus.EngineDesc.new("enchant-python", engine_name,
                                  "English Enchant", "en", "GPL",
                                  "Peng Huang <*****@*****.**>",
                                  "", "us")
     self.__component.add_engine(engine)
     self.__mainloop = GLib.MainLoop()
     self.__bus = IBus.Bus()
     self.__bus.connect("disconnected", self.__bus_disconnected_cb)
     self.__factory = IBus.Factory.new(self.__bus.get_connection())
     self.__factory.add_engine("enchant-python",
                               GObject.type_from_name("EngineEnchant"))
     if exec_by_ibus:
         self.__bus.request_name("org.freedesktop.IBus.EnchantPython", 0)
     else:
         self.__bus.register_component(self.__component)
         self.__bus.set_global_engine_async("enchant-python", -1, None,
                                            None, None)
Ejemplo n.º 14
0
    def test_gtypes(self):
        gchararray_gtype = GObject.type_from_name('gchararray')
        gtype = Everything.test_gtype(str)
        self.assertEqual(gchararray_gtype, gtype)
        gtype = Everything.test_gtype('gchararray')
        self.assertEqual(gchararray_gtype, gtype)
        gobject_gtype = GObject.GObject.__gtype__
        gtype = Everything.test_gtype(GObject.GObject)
        self.assertEqual(gobject_gtype, gtype)
        gtype = Everything.test_gtype('GObject')
        self.assertEqual(gobject_gtype, gtype)
        self.assertRaises(TypeError, Everything.test_gtype, 'invalidgtype')

        class NotARegisteredClass(object):
            pass

        self.assertRaises(TypeError, Everything.test_gtype,
                          NotARegisteredClass)

        class ARegisteredClass(GObject.GObject):
            __gtype_name__ = 'EverythingTestsARegisteredClass'

        gtype = Everything.test_gtype('EverythingTestsARegisteredClass')
        self.assertEqual(ARegisteredClass.__gtype__, gtype)
        gtype = Everything.test_gtype(ARegisteredClass)
        self.assertEqual(ARegisteredClass.__gtype__, gtype)
        self.assertRaises(TypeError, Everything.test_gtype, 'ARegisteredClass')
Ejemplo n.º 15
0
 def __init__(self, exec_by_ibus):
     engine_name = "uniemoji"
     if not exec_by_ibus:
         engine_name += " (debug)"
         global debug_on
         debug_on = True
     self.component = \
             IBus.Component.new("org.freedesktop.IBus.UniEmoji",
                                "Unicode emoji and symbols by name",
                                "0.1.0",
                                "GPL",
                                "Lalo Martins <*****@*****.**>",
                                "https://github.com/lalomartins/ibus-uniemoji",
                                "/usr/bin/exec",
                                "uniemoji")
     engine = IBus.EngineDesc.new("uniemoji", engine_name,
                                  "Unicode emoji and symbols by name", "",
                                  "GPL",
                                  "Lalo Martins <*****@*****.**>",
                                  "", "us")
     self.component.add_engine(engine)
     self.mainloop = GLib.MainLoop()
     self.bus = IBus.Bus()
     self.bus.connect("disconnected", self.bus_disconnected_cb)
     self.factory = IBus.Factory.new(self.bus.get_connection())
     self.factory.add_engine("uniemoji", GObject.type_from_name("UniEmoji"))
     if exec_by_ibus:
         self.bus.request_name("org.freedesktop.IBus.UniEmoji", 0)
     else:
         self.bus.register_component(self.component)
         self.bus.set_global_engine_async("uniemoji", -1, None, None, None)
Ejemplo n.º 16
0
 def __init__(self, exec_by_ibus):
     self._mainloop = GLib.MainLoop()
     self._bus = IBus.Bus()
     self._bus.connect("disconnected", self._bus_disconnected_cb)
     self._factory = IBus.Factory(self._bus)
     self._factory.add_engine("hiragana",
                              GObject.type_from_name("EngineHiragana"))
     if exec_by_ibus:
         self._bus.request_name("org.freedesktop.IBus.Hiragana", 0)
     else:
         self._component = IBus.Component(
             name="org.freedesktop.IBus.Hiragana",
             description="Hiragana IME",
             version=package.get_version(),
             license="Apache",
             author="Esrille Inc. <*****@*****.**>",
             homepage="https://github.com/esrille/" + package.get_name(),
             textdomain=package.get_name())
         engine = IBus.EngineDesc(name="hiragana",
                                  longname="Hiragana IME",
                                  description="Hiragana IME",
                                  language="ja",
                                  license="Apache",
                                  author="Esrille Inc. <*****@*****.**>",
                                  icon=package.get_name(),
                                  layout="default")
         self._component.add_engine(engine)
         self._bus.register_component(self._component)
         self._bus.set_global_engine_async("hiragana", -1, None, None, None)
Ejemplo n.º 17
0
    def _launchPipeline(self):
        self.debug(
            'Now generating waveforms for: %s', path_from_uri(self._uri))
        self.pipeline = Gst.parse_launch("uridecodebin name=decode uri=" +
                                         self._uri + " ! waveformbin name=wave"
                                         " ! fakesink qos=false name=faked")
        # This line is necessary so we can instantiate GstTranscoder's
        # GstCpuThrottlingClock below.
        Gst.ElementFactory.make("uritranscodebin", None)
        clock = GObject.new(GObject.type_from_name("GstCpuThrottlingClock"))
        clock.props.cpu_usage = self._max_cpu_usage
        self.pipeline.use_clock(clock)
        faked = self.pipeline.get_by_name("faked")
        faked.props.sync = True
        self._wavebin = self.pipeline.get_by_name("wave")
        asset = self.ges_elem.get_parent().get_asset()
        self._wavebin.props.uri = asset.get_id()
        self._wavebin.props.duration = asset.get_duration()
        decode = self.pipeline.get_by_name("decode")
        decode.connect("autoplug-select", self._autoplug_select_cb)
        bus = self.pipeline.get_bus()
        bus.add_signal_watch()

        asset = self.ges_elem.get_parent().get_asset()
        self.n_samples = asset.get_duration() / SAMPLE_DURATION
        bus.connect("message", self._busMessageCb)
Ejemplo n.º 18
0
    def create_engine(self, factory, engine_name):
        if engine_name == "bogo":
            dbus_path = "/org/freedesktop/IBus/Engine/%d" % self.engine_count

            # It looks like the GObject's new_with_type constructor also
            # calls __init__ but without arguments so there will be error
            # messages like this:
            #
            # TypeError: __init__() missing 1 required positional argument
            #
            # We will ignore that message by temporarily redirect stderr
            # to /dev/null

            f = open('/dev/null', 'w')
            stderr = sys.stderr
            sys.stderr = f

            engine = Engine.new_with_type(GObject.type_from_name("EngineBoGo"),
                                          "bogo-python",
                                          dbus_path,
                                          self.bus.get_connection())

            sys.stderr = stderr
            f.close()

            Engine.__init__(engine, self.config, self.abbr_expander, self.auto_corrector)

            self.engine_count += 1
            return engine
Ejemplo n.º 19
0
def _check_videosink():
    from gi.repository import Gst
    from gi.repository import Gdk
    from gi.repository import GObject
    global videosink_factory

    try:
        # If using GdkBroadwayDisplay make sure not to try to use gtkglsink
        # as it would segfault right away.
        if GObject.type_is_a(Gdk.Display.get_default().__gtype__,
                             GObject.type_from_name("GdkBroadwayDisplay")):
            videosink_factory = Gst.ElementFactory.find("gtksink")
            return True
    except RuntimeError:
        pass

    if "gtkglsink" in os.environ.get("PITIVI_UNSTABLE_FEATURES", ''):
        sink = Gst.ElementFactory.make("gtkglsink", None)
        if not sink:
            videosink_factory = sink.get_factory()
        elif sink.set_state(Gst.State.READY) == Gst.StateChangeReturn.SUCCESS:
            videosink_factory = sink.get_factory()
            sink.set_state(Gst.State.NULL)
        else:
            videosink_factory = Gst.ElementFactory.find("gtksink")
    else:
        videosink_factory = Gst.ElementFactory.find("gtksink")

    if videosink_factory:
        return True

    return False
Ejemplo n.º 20
0
 def __init__(self, exec_by_ibus):
     self.__component = IBus.Component.new("org.freedesktop.IBus.SharadaBraille",
                                       "Sharada-Braille Component",
                                       "0.1.0",
                                       "GPL",
                                       "Nalin.x.Linux <*****@*****.**>",
                                       "http://example.com",
                                       "/usr/bin/exec",
                                       "sharada-braille")
                                       
     engine = IBus.EngineDesc.new("sharada-braille",
                                 "Sharada-Braille",
                                 "Sharada-Braille",
                                 "",
                                 "GPL",
                                 "Nalin.x.Linux <*****@*****.**>",
                                 "",
                                 "")
     self.__component.add_engine(engine)
     self.__mainloop = GLib.MainLoop()
     self.__bus = IBus.Bus()
     self.__bus.connect("disconnected", self.__bus_disconnected_cb)
     self.__factory = IBus.Factory.new(self.__bus.get_connection())
     self.__factory.add_engine("sharada-braille", GObject.type_from_name("EngineSharadaBraille"))        
     
     if exec_by_ibus:
         self.__bus.request_name("org.freedesktop.IBus.SharadaBraille", 0)
     else:
         self.__bus.register_component(self.__component)
         self.__bus.set_global_engine_async("sharada-braille", -1, None, None, None)
Ejemplo n.º 21
0
 def __init__(self, exec_by_ibus):
     engine_name = "enchant python" if exec_by_ibus else "enchant python (debug)"
     self.__component = \
             IBus.Component.new("org.freedesktop.IBus.EnchantPython",
                                "Enchant Python Component",
                                "0.1.0",
                                "GPL",
                                "Peng Huang <*****@*****.**>",
                                "http://example.com",
                                "/usr/bin/exec",
                                "ibus-enchant")
     engine = IBus.EngineDesc.new("enchant-python",
                                  engine_name,
                                  "English Enchant",
                                  "en",
                                  "GPL",
                                  "Peng Huang <*****@*****.**>",
                                  "",
                                  "us")
     self.__component.add_engine(engine)
     self.__mainloop = GLib.MainLoop()
     self.__bus = IBus.Bus()
     self.__bus.connect("disconnected", self.__bus_disconnected_cb)
     self.__factory = IBus.Factory.new(self.__bus.get_connection())
     self.__factory.add_engine("enchant-python",
             GObject.type_from_name("EngineEnchant"))
     if exec_by_ibus:
         self.__bus.request_name("org.freedesktop.IBus.EnchantPython", 0)
     else:
         self.__bus.register_component(self.__component)
         self.__bus.set_global_engine_async(
                 "enchant-python", -1, None, None, None)
Ejemplo n.º 22
0
 def __init__(self, exec_by_ibus):
     engine_name = "unicode-db-python" if exec_by_ibus else "unicode-db-python (debug)"
     self.__component = \
             IBus.Component.new("org.freedesktop.IBus.UnicodeDb",
                                "Unicode Db Input Method",
                                "0.1.0",
                                "GPL",
                                "Daniel Sim <*****@*****.**>",
                                "http://example.com",
                                "/usr/bin/exec",
                                "ibus-unicode-db")
     engine = IBus.EngineDesc.new("unicode-db-python",
                                  engine_name,
                                  "English Unicode Db",
                                  "en",
                                  "GPL",
                                  "Daniel Sim <*****@*****.**>",
                                  "",
                                  "us")
     self.__component.add_engine(engine)
     self.__mainloop = GLib.MainLoop()
     self.__bus = IBus.Bus()
     self.__bus.connect("disconnected", self.__bus_disconnected_cb)
     self.__factory = IBus.Factory.new(self.__bus.get_connection())
     self.__factory.add_engine("unicode-db-python",
             GObject.type_from_name("EngineUnicodeDb"))
     if exec_by_ibus:
         self.__bus.request_name("org.freedesktop.IBus.UnicodeDb", 0)
     else:
         self.__bus.register_component(self.__component)
         self.__bus.set_global_engine_async(
                 "unicode-db-python", -1, None, None, None)
Ejemplo n.º 23
0
    def create_engine(self, factory, engine_name):
        if engine_name == "bogo":
            dbus_path = "/org/freedesktop/IBus/Engine/%d" % self.engine_count

            # It looks like the GObject's new_with_type constructor also
            # calls __init__ but without arguments so there will be error
            # messages like this:
            #
            # TypeError: __init__() missing 1 required positional argument
            #
            # We will ignore that message by temporarily redirect stderr
            # to /dev/null

            f = open('/dev/null', 'w')
            stderr = sys.stderr
            sys.stderr = f

            engine = Engine.new_with_type(GObject.type_from_name("EngineBoGo"),
                                          "bogo-python",
                                          dbus_path,
                                          self.bus.get_connection())

            sys.stderr = stderr
            f.close()

            Engine.__init__(engine, self.config, self.abbr_expander, self.icon)

            self.engine_count += 1
            return engine
Ejemplo n.º 24
0
    def _launchPipeline(self):
        self.debug('Now generating waveforms for: %s',
                   path_from_uri(self._uri))
        self.pipeline = Gst.parse_launch("uridecodebin name=decode uri=" +
                                         self._uri + " ! waveformbin name=wave"
                                         " ! fakesink qos=false name=faked")
        # This line is necessary so we can instantiate GstTranscoder's
        # GstCpuThrottlingClock below.
        Gst.ElementFactory.make("uritranscodebin", None)
        clock = GObject.new(GObject.type_from_name("GstCpuThrottlingClock"))
        clock.props.cpu_usage = self._max_cpu_usage
        self.pipeline.use_clock(clock)
        faked = self.pipeline.get_by_name("faked")
        faked.props.sync = True
        self._wavebin = self.pipeline.get_by_name("wave")
        asset = self.ges_elem.get_asset().get_filesource_asset()
        self._wavebin.props.uri = asset.get_id()
        self._wavebin.props.duration = asset.get_duration()
        decode = self.pipeline.get_by_name("decode")
        decode.connect("autoplug-select", self._autoplug_select_cb)
        bus = self.pipeline.get_bus()
        bus.add_signal_watch()

        self.n_samples = asset.get_duration() / SAMPLE_DURATION
        bus.connect("message", self._busMessageCb)
Ejemplo n.º 25
0
    def _launch_pipeline(self):
        self.pipeline = Gst.parse_launch("uridecodebin name=decode uri=" +
                                         self._uri + " ! waveformbin name=wave"
                                         " ! fakesink qos=false name=faked")

        Gst.ElementFactory.make("uritranscodebin", None)

        clock = GObject.new(GObject.type_from_name("GstCpuThrottlingClock"))
        clock.props.cpu_usage = 90
        self.pipeline.use_clock(clock)

        faked = self.pipeline.get_by_name("faked")
        faked.props.sync = True
        self._wavebin = self.pipeline.get_by_name("wave")

        self._wavebin.props.uri = self._asset.get_id()
        self._wavebin.props.duration = self._asset.get_duration()
        decode = self.pipeline.get_by_name("decode")
        decode.connect("autoplug-select", self._autoplug_select_cb)
        bus = self.pipeline.get_bus()
        self.pipeline.set_state(Gst.State.PLAYING)
        bus.add_signal_watch()
        self.n_samples = self._asset.get_duration() / SAMPLE_DURATION
        bus.connect("message::error", self.__on_bus_error)
        bus.connect("message::eos", self.__on_bus_eos)
Ejemplo n.º 26
0
 def test_value_array_from_gvalue_list(self):
     value = GObject.Value(GObject.ValueArray, [
         GObject.Value(GObject.TYPE_UINT, 0xffffffff),
         GObject.Value(GObject.TYPE_STRING, 'foo_bar')])
     self.assertEqual(value.g_type, GObject.type_from_name('GValueArray'))
     self.assertEqual(value.get_value(), [0xffffffff, 'foo_bar'])
     self.assertEqual(testhelper.value_array_get_nth_type(value, 0), GObject.TYPE_UINT)
     self.assertEqual(testhelper.value_array_get_nth_type(value, 1), GObject.TYPE_STRING)
Ejemplo n.º 27
0
 def test_value_array_from_gvalue_list(self):
     value = GObject.Value(GObject.ValueArray, [
         GObject.Value(GObject.TYPE_UINT, 0xffffffff),
         GObject.Value(GObject.TYPE_STRING, 'foo_bar')])
     self.assertEqual(value.g_type, GObject.type_from_name('GValueArray'))
     self.assertEqual(value.get_value(), [0xffffffff, 'foo_bar'])
     self.assertEqual(testhelper.value_array_get_nth_type(value, 0), GObject.TYPE_UINT)
     self.assertEqual(testhelper.value_array_get_nth_type(value, 1), GObject.TYPE_STRING)
Ejemplo n.º 28
0
    def get(self, gtype_name, *params):
        """Fetch an object by identity, via an internal cache.

        A cache is used, to avoid overconstruction.  If construction is needed,
        the type name is used to obtain the Python class representing the
        GObject type, which is then instantiated by passing its Python
        constructor the supplied parameters as its ``*args``.

        Construction parameters are assumed to qualify and specialize objects
        sufficiently for `params` plus the type name to form a meaningful
        identity for the object.

        This is the same concept of identity the cache uses.  If the
        construction parameters need to change during the lifetime of the
        object to maintain this identity, the `rebadge()` method can be used to
        update them and allow the object to be reconstructed correctly for the
        next session.

        :param gtype_name: a registered name (cf. __gtype_name__)
        :type gtype_name: str
        :param params: parameters for the Python constructor
        :type params: tuple
        :returns: the newly constructed object
        :rtype: GObject
        :raises ConstructError: when construction fails.

        Fires `object_created()` after an object has been successfully created.

        """
        key = self._make_key(gtype_name, params)
        if key in self._cache:
            return self._cache[key]
        logger.debug("Creating %r via factory", key)
        try:
            gtype = GObject.type_from_name(gtype_name)
        except RuntimeError:
            raise ConstructError(
                "Cannot construct a '%s': module not imported?"
                % gtype_name
            )
        if self._required_type:
            if not gtype.is_a(self._required_type):
                raise ConstructError(
                    "%s is not a subclass of %s"
                    % (gtype_name, self._required_type.__gtype__.name)
                )
        try:
            product = gtype.pytype(*params)
        except Exception:
            warn("Failed to construct a %s (pytype=%r, params=%r)"
                 % (gtype_name, gtype.pytype, params),
                 RuntimeWarning)
            raise
        product.__key = key
        self._cache[key] = product
        self.object_created(product)
        return product
Ejemplo n.º 29
0
    def test_gerror_boxing(self):
        error = GLib.Error('test message', domain='mydomain', code=42)
        value = GObject.Value(GLib.Error, error)
        self.assertEqual(value.g_type, GObject.type_from_name('GError'))

        unboxed = value.get_value()
        self.assertEqual(unboxed.message, error.message)
        self.assertEqual(unboxed.domain, error.domain)
        self.assertEqual(unboxed.code, error.code)
Ejemplo n.º 30
0
    def get(self, gtype_name, *params):
        """Fetch an object by identity, via an internal cache.

        A cache is used, to avoid overconstruction.  If construction is needed,
        the type name is used to obtain the Python class representing the
        GObject type, which is then instantiated by passing its Python
        constructor the supplied parameters as its ``*args``.

        Construction parameters are assumed to qualify and specialize objects
        sufficiently for `params` plus the type name to form a meaningful
        identity for the object.

        This is the same concept of identity the cache uses.  If the
        construction parameters need to change during the lifetime of the
        object to maintain this identity, the `rebadge()` method can be used to
        update them and allow the object to be reconstructed correctly for the
        next session.

        :param gtype_name: a registered name (cf. __gtype_name__)
        :type gtype_name: str
        :param params: parameters for the Python constructor
        :type params: sequence
        :returns: the newly constructed object
        :rtype: GObject
        :raises ConstructError: when construction fails.

        Fires `object_created()` after an object has been successfully created.

        """
        key = self._make_key(gtype_name, params)
        if key in self._cache:
            return self._cache[key]
        logger.debug("Creating %r via factory", key)
        try:
            gtype = GObject.type_from_name(gtype_name)
        except RuntimeError:
            raise ConstructError(
                "Cannot construct a '%s': module not imported?"
                % gtype_name
            )
        if self._required_type:
            if not gtype.is_a(self._required_type):
                raise ConstructError(
                    "%s is not a subclass of %s"
                    % (gtype_name, self._required_type.__gtype__.name)
                )
        try:
            product = gtype.pytype(*params)
        except Exception:
            warn("Failed to construct a %s (pytype=%r, params=%r)"
                 % (gtype_name, gtype.pytype, params),
                 RuntimeWarning)
            raise
        product.__key = key
        self._cache[key] = product
        self.object_created(product)
        return product
Ejemplo n.º 31
0
def _using_broadway_display():
    from gi.repository import Gdk
    from gi.repository import GObject
    try:
        gdk_broadway_display_type = GObject.type_from_name("GdkBroadwayDisplay")
    except RuntimeError:
        return False
    display = Gdk.Display.get_default()
    return GObject.type_is_a(display.__gtype__, gdk_broadway_display_type)
Ejemplo n.º 32
0
    def test_gerror_boxing(self):
        error = GLib.Error('test message', domain='mydomain', code=42)
        value = GObject.Value(GLib.Error, error)
        self.assertEqual(value.g_type, GObject.type_from_name('GError'))

        unboxed = value.get_value()
        self.assertEqual(unboxed.message, error.message)
        self.assertEqual(unboxed.domain, error.domain)
        self.assertEqual(unboxed.code, error.code)
Ejemplo n.º 33
0
 def test_registered_type_info(self):
     info = repo.find_by_name('GIMarshallingTests', 'Object')
     # Call these from the class because GIObjectInfo overrides them
     self.assertEqual(GIRepository.RegisteredTypeInfo.get_g_type(info),
                      GObject.type_from_name('GIMarshallingTestsObject'))
     self.assertEqual(GIRepository.RegisteredTypeInfo.get_type_name(info),
                      'GIMarshallingTestsObject')
     self.assertEqual(GIRepository.RegisteredTypeInfo.get_type_init(info),
                      'gi_marshalling_tests_object_get_type')
Ejemplo n.º 34
0
 def getDBObjectDerived(self, typename, types):
     children = GObject.type_children(typename)
     for gtype in children:
         childname = GObject.type_name(gtype)
         self.getDBObjectDerived(childname, types)
         # FIXME, core should support some routines to check if type could have storage
         if (GObject.type_is_a(
                 gtype, GObject.type_from_name("MidgardBaseInterface"))
                 or gtype.is_abstract() or childname == "MidgardMetadata"):
             continue
         types.append(childname)
Ejemplo n.º 35
0
 def getDBObjectDerived(self, typename, types):
   children = GObject.type_children(typename)
   for gtype in children:
     childname = GObject.type_name(gtype)
     self.getDBObjectDerived(childname, types)
     # FIXME, core should support some routines to check if type could have storage 
     if (GObject.type_is_a(gtype, GObject.type_from_name("MidgardBaseInterface"))
         or gtype.is_abstract()
         or childname == "MidgardMetadata"):
       continue
     types.append(childname)
Ejemplo n.º 36
0
def is_instance_of_gtype_name(instance, name):
    """Returns False if the gtype can't be found"""

    try:
        gtype = GObject.type_from_name(name)
    except Exception:
        return False
    else:
        pytype = gtype.pytype
        if pytype is None:
            return False
        return isinstance(instance, pytype)
Ejemplo n.º 37
0
def is_instance_of_gtype_name(instance, name):
    """Returns False if the gtype can't be found"""

    try:
        gtype = GObject.type_from_name(name)
    except Exception:
        return False
    else:
        pytype = gtype.pytype
        if pytype is None:
            return False
        return isinstance(instance, pytype)
Ejemplo n.º 38
0
 def __init__(self, exec_by_ibus):
     component = IBus.Component.new_from_file('%s/plover.xml' % DATA_DIR)
     self.__component = component
     self.__mainloop = GLib.MainLoop()
     self.__bus = IBus.Bus()
     self.__bus.connect("disconnected", self.__bus_disconnected_cb)
     self.__factory = IBus.Factory.new(self.__bus.get_connection())
     self.__factory.add_engine('plover', GObject.type_from_name("EnginePlover"))
     if exec_by_ibus:
         self.__bus.request_name("org.freedesktop.IBus.Plover", 0)
     else:
         self.__bus.register_component(self.__component)
 def _construct(self, gtype_name):
     try:
         gtype = GObject.type_from_name(gtype_name)
     except RuntimeError:
         warn("Cannot construct a new %s: not loaded?" % (gtype_name, ),
              RuntimeWarning)
         return None
     if not gtype.is_a(Gtk.Widget):
         warn("%s is not a Gtk.Widget subclass" % (gtype_name, ),
              RuntimeWarning)
         return None
     widget = gtype.pytype()
     return widget
Ejemplo n.º 40
0
 def _construct(self, gtype_name):
     try:
         gtype = GObject.type_from_name(gtype_name)
     except RuntimeError:
         warn("Cannot construct a new %s: not loaded?" % (gtype_name,),
              RuntimeWarning)
         return None
     if not gtype.is_a(Gtk.Widget):
         warn("%s is not a Gtk.Widget subclass" % (gtype_name,),
              RuntimeWarning)
         return None
     widget = gtype.pytype()
     return widget
Ejemplo n.º 41
0
    def __init__(self, controller):
        Gtk.Box.__init__(self)
        self.set_orientation(Gtk.Orientation.VERTICAL)
        self.set_homogeneous(False)
        self.set_spacing(12)
        self.controller = controller

        vb_left = Gtk.Box(False, 3)
        vb_left.set_orientation(Gtk.Orientation.VERTICAL)
        self.photo_label = Gtk.Label('Take a photo:')
        vb_left.pack_start(self.photo_label, False, False, 0)
        f = Gtk.Frame()
        self.webcam = UbiquityWebcam.Webcam()
        self.webcam.connect('image-captured', self.image_captured)
        f.add(self.webcam)
        vb_left.pack_start(f, True, True, 0)

        vb_right = Gtk.Box(False, 3)
        vb_right.set_orientation(Gtk.Orientation.VERTICAL)
        self.existing_label = Gtk.Label('Or choose an existing picture:')
        vb_right.pack_start(self.existing_label, False, False, 0)
        iv = Gtk.IconView()
        iv.connect('selection-changed', self.selection_changed)
        # TODO cjwatson 2012-03-21: Gtk.IconView should work this out
        # itself, but I think that depends on having correct
        # height-for-width geometry management everywhere, and we don't yet.
        # See LP #961025.
        iv.set_columns(2)
        sw = Gtk.ScrolledWindow()
        sw.set_shadow_type(Gtk.ShadowType.IN)
        sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
        sw.add(iv)
        vb_right.pack_start(sw, True, True, 0)

        hb = Gtk.Box(True, 30)
        hb.pack_start(vb_left, True, True, 0)
        hb.pack_start(vb_right, True, True, 0)
        self.pack_start(hb, True, True, 0)

        self.selected_image = Gtk.Image()
        self.selected_image.set_size_request(96, 96)
        self.pack_start(self.selected_image, True, True, 0)

        m = Gtk.ListStore(GObject.type_from_name('GdkPixbuf'))
        iv.set_model(m)
        iv.set_pixbuf_column(0)
        if os.path.exists(FACES_PATH):
            for path in sorted(os.listdir(FACES_PATH)):
                pb = GdkPixbuf.Pixbuf.new_from_file(
                                    os.path.join(FACES_PATH, path))
                m.append([pb])
Ejemplo n.º 42
0
    def __init__(self, controller):
        Gtk.Box.__init__(self)
        self.set_orientation(Gtk.Orientation.VERTICAL)
        self.set_homogeneous(False)
        self.set_spacing(12)
        self.controller = controller

        vb_left = Gtk.Box(False, 3)
        vb_left.set_orientation(Gtk.Orientation.VERTICAL)
        self.photo_label = Gtk.Label('Take a photo:')
        vb_left.pack_start(self.photo_label, False, False, 0)
        f = Gtk.Frame()
        self.webcam = UbiquityWebcam.Webcam()
        self.webcam.connect('image-captured', self.image_captured)
        f.add(self.webcam)
        vb_left.pack_start(f, True, True, 0)

        vb_right = Gtk.Box(False, 3)
        vb_right.set_orientation(Gtk.Orientation.VERTICAL)
        self.existing_label = Gtk.Label('Or choose an existing picture:')
        vb_right.pack_start(self.existing_label, False, False, 0)
        iv = Gtk.IconView()
        iv.connect('selection-changed', self.selection_changed)
        # TODO cjwatson 2012-03-21: Gtk.IconView should work this out
        # itself, but I think that depends on having correct
        # height-for-width geometry management everywhere, and we don't yet.
        # See LP #961025.
        iv.set_columns(2)
        sw = Gtk.ScrolledWindow()
        sw.set_shadow_type(Gtk.ShadowType.IN)
        sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
        sw.add(iv)
        vb_right.pack_start(sw, True, True, 0)

        hb = Gtk.Box(True, 30)
        hb.pack_start(vb_left, True, True, 0)
        hb.pack_start(vb_right, True, True, 0)
        self.pack_start(hb, True, True, 0)

        self.selected_image = Gtk.Image()
        self.selected_image.set_size_request(96, 96)
        self.pack_start(self.selected_image, True, True, 0)

        m = Gtk.ListStore(GObject.type_from_name('GdkPixbuf'))
        iv.set_model(m)
        iv.set_pixbuf_column(0)
        if os.path.exists(FACES_PATH):
            for path in sorted(os.listdir(FACES_PATH)):
                pb = GdkPixbuf.Pixbuf.new_from_file(
                    os.path.join(FACES_PATH, path))
                m.append([pb])
Ejemplo n.º 43
0
def register_engine(bus, live=False):
    log.debug('Registering the component')
    component = IBus.Component(
        name=COMPONENT,
        description='DeepSpeech-in-docker input method',
        version='1.0',
        license='LGPL',
        author='Mike C. Fletcher',
        homepage='https://github.com/mcfletch/deepspeech-docker',
        command_line='listener-ibus',
        textdomain='en',  # TODO: is this really language?
    )
    component.add_engine(ListenerEngine.DESCRIPTION)
    connection = bus.get_connection()
    if not connection:
        raise RuntimeError("IBus has no connection")
    factory = IBus.Factory.new(connection)
    log.info("Adding ibus engine at %r", SERVICE_NAME)
    factory.add_engine(SERVICE_NAME, GObject.type_from_name(NAME))
    if not live:
        log.info(
            'Running in development (non-live) mode with direct registation')
        ListenerEngine.stand_alone = True
        assert bus.register_component(
            component), "Unable to register our component"

        def on_set_engine(source, result, data=None):
            if result.had_error():
                log.error("Unable to register!")
                MAINLOOP.quit()
            else:
                log.info('Set engine called: %s, %s, %s', source, result, data)

        def set_engine():
            log.info("Registering IBus Service at %r", SERVICE_NAME)
            bus.set_global_engine_async(
                SERVICE_NAME,
                5000,  # shouldn't take this long!
                None,
                on_set_engine,
                None,
            )

        GLib.idle_add(set_engine)
    else:
        log.info('Registering for activation via DBUS')
        GLib.idle_add(
            bus.request_name,
            COMPONENT,
            IBus.BusNameFlag.ALLOW_REPLACEMENT,
        )
Ejemplo n.º 44
0
    def __init__(self, Gst_element, ignore_list=IGNORE_LIST):
        self._Gst_element = Gst_element
        _properties_list = GObject.list_properties(self._Gst_element)
        self.children = []

        #print( Gst.Object.get_properties(self._Gst_element))

        self.implements_childproxy = GObject.type_from_name(
            "GstChildProxy") in GObject.type_interfaces(self._Gst_element)

        if (self.implements_childproxy):
            for i in range(self._Gst_element.get_children_count()):
                self.children.append(
                    Element(self._Gst_element.get_child_by_index(i)))

        if hasattr(self._Gst_element, "get_factory"):
            self.name = self._Gst_element.get_factory().get_name()
        else:
            self.name = self._Gst_element.get_name()

        self.number_properties = number_properties = []
        self.boolean_properties = boolean_properties = []
        self.string_properties = string_properties = []
        self.enum_properties = enum_properties = []

        for property in _properties_list:
            if property.name in ignore_list:
                logger.debug("Property {0} is in ignore list, skipping".format(
                    property.name))

            elif property.value_type in NUMBER_GTYPES:
                number_property = NumberProperty(property, self)
                number_properties.append(number_property)

            elif property.value_type == GObject.TYPE_BOOLEAN:
                boolean_property = BooleanProperty(property, self)
                boolean_properties.append(boolean_property)

            elif property.value_type in STRING_GTYPES:
                string_property = StringProperty(property, self)
                string_properties.append(string_property)

            elif property.value_type.is_a(GObject.TYPE_ENUM):
                enum_property = EnumProperty(property, self)
                enum_properties.append(enum_property)

            else:
                logger.error(
                    "Property '{0}' with type {1} has no associated known types, skipping"
                    .format(property.name, property.value_type))
Ejemplo n.º 45
0
    def _busMessageCb(self, bus, message):
        if message.type == Gst.MessageType.EOS:
            self._prepareSamples()
            self._startRendering()
            self.stopGeneration()

        elif message.type == Gst.MessageType.ERROR:
            if self.adapter:
                self.adapter.stop()
                self.adapter = None
            # Something went wrong TODO : recover
            self.stopGeneration()
            self._num_failures += 1
            if self._num_failures < 2:
                self.warning(
                    "Issue during waveforms generation: %s"
                    " for the %ith time, trying again with no rate "
                    " modulation", message.parse_error(), self._num_failures)
                bus.disconnect_by_func(self._busMessageCb)
                self._launchPipeline()
                self.becomeControlled()
            else:
                Gst.debug_bin_to_dot_file_with_ts(
                    self.pipeline, Gst.DebugGraphDetails.ALL,
                    "error-generating-waveforms")
                self.error("Aborting due to waveforms generation issue: %s",
                           message.parse_error())

        elif message.type == Gst.MessageType.STATE_CHANGED:
            prev, new, unused_pending_state = message.parse_state_changed()
            if message.src == self.pipeline:
                if prev == Gst.State.READY and new == Gst.State.PAUSED:
                    self.pipeline.seek(
                        1.0, Gst.Format.TIME,
                        Gst.SeekFlags.FLUSH | Gst.SeekFlags.ACCURATE,
                        Gst.SeekType.SET, 0, Gst.SeekType.NONE, -1)

                # In case we failed previously, we won't modulate next time
                elif not self.adapter and prev == Gst.State.PAUSED and \
                        new == Gst.State.PLAYING and self._num_failures == 0:
                    # This line is necessary so we can instantiate GstTranscoder's
                    # GstCpuThrottlingClock below.
                    Gst.ElementFactory.make("uritranscodebin", None)
                    clock = GObject.new(
                        GObject.type_from_name("GstCpuThrottlingClock"))
                    clock.props.cpu_usage = self.app.settings.previewers_max_cpu
                    self.pipeline.use_clock(clock)
Ejemplo n.º 46
0
    def __init__(self, data: str) -> None:
        self.data = data
        xml = ET.fromstring(data)

        name = None
        parent = None
        for e in xml.iter('template'):
            name = e.get('class')
            parent = e.get('parent')
            break

        if name is None or parent is None:
            raise ValueError(
                "Template tag is missing 'class' or 'parent' attribute")

        self.name = name
        self.parent = GObject.type_from_name(parent).pytype
Ejemplo n.º 47
0
    def __init__(self, exec_by_ibus, engine_name):
        component_path = GLib.build_filenamev([datadir, "..", "ibus", "component", "%s.xml" % engine_name])
        self.__component = IBus.Component.new_from_file(component_path)

        self.__mainloop = GLib.MainLoop()

        self.__bus = IBus.Bus()
        self.__bus.connect("disconnected", self.__bus_disconnected_cb)

        self.__factory = IBus.Factory.new(self.__bus.get_connection())
        engine_classtype = "Engine%s" % engine_name.capitalize()
        self.__factory.add_engine(engine_name, GObject.type_from_name(engine_classtype))

        if exec_by_ibus:
            self.__bus.request_name(self.__component.get_name(), 0)
        else:
            self.__bus.register_component(self.__component)
 def get_widget(self, uri, window):
     if self.space_bar != None:
         if self.current_uri != uri:
             self.current_uri = uri
             self.do_the_right_thing()
         return None
     if self.nfb_type == None:
         try:
             self.nfb_type = GObject.type_from_name("NautilusFloatingBar")
         except:
             return None
     self.current_uri = uri
     if not uri.startswith("file://"):
         return None
     dummy = Gtk.Box()
     dummy.connect("realize", self.bar_init)
     return dummy
Ejemplo n.º 49
0
    def __init__(self, Gst_element, ignore_list=IGNORE_LIST):
        self._Gst_element = Gst_element
        _properties_list = GObject.list_properties(self._Gst_element)
        self.children = []
        
        #print( Gst.Object.get_properties(self._Gst_element))
        
        self.implements_childproxy = GObject.type_from_name("GstChildProxy") in GObject.type_interfaces(self._Gst_element)
        
        if (self.implements_childproxy):
            for i in range(self._Gst_element.get_children_count()):
                self.children.append(Element(self._Gst_element.get_child_by_index(i)))
        
        if hasattr(self._Gst_element, "get_factory"):
            self.name = self._Gst_element.get_factory().get_name()
        else:
            self.name = self._Gst_element.get_name()

        self.number_properties = number_properties = []
        self.boolean_properties = boolean_properties = []
        self.string_properties = string_properties = []
        self.enum_properties = enum_properties = []

        for property in _properties_list:
            if property.name in ignore_list:
                logger.debug("Property {0} is in ignore list, skipping".format(property.name))

            elif property.value_type in NUMBER_GTYPES:
                number_property = NumberProperty(property, self)
                number_properties.append(number_property)

            elif property.value_type == GObject.TYPE_BOOLEAN:
                boolean_property = BooleanProperty(property, self)
                boolean_properties.append(boolean_property)

            elif property.value_type in STRING_GTYPES: 
                string_property = StringProperty(property, self)
                string_properties.append(string_property)
          
            elif property.value_type.is_a(GObject.TYPE_ENUM):
                enum_property = EnumProperty(property, self)
                enum_properties.append(enum_property)

            else:
                logger.error("Property '{0}' with type {1} has no associated known types, skipping".format(property.name, property.value_type))
Ejemplo n.º 50
0
 def __init__(self, exec_by_ibus):
     self.mainloop = GLib.MainLoop()
     self.bus = IBus.Bus()
     self.bus.connect('disconnected', self.bus_disconnected_cb)
     self.factory = IBus.Factory.new(self.bus.get_connection())
     self.factory.add_engine('uniemoji',
                             GObject.type_from_name('UniEmojiIBusEngine'))
     if exec_by_ibus:
         self.bus.request_name('org.freedesktop.IBus.UniEmoji', 0)
     else:
         xml_path = os.path.join(__base_dir__, 'uniemoji.xml')
         if os.path.exists(xml_path):
             component = IBus.Component.new_from_file(xml_path)
         else:
             xml_path = os.path.join(os.path.dirname(__base_dir__), 'ibus',
                                     'component', 'uniemoji.xml')
             component = IBus.Component.new_from_file(xml_path)
         self.bus.register_component(component)
Ejemplo n.º 51
0
    def __init__(self):
        Gtk.VBox.__init__(self)
        self.set_spacing(12)

        vb_left = Gtk.VBox.new(False, 3)
        # TODO i18n
        l = Gtk.Label('Take a photo:')
        vb_left.pack_start(l, False, False, 0)
        f = Gtk.Frame()
        self.webcam = UbiquityWebcam.Webcam()
        self.webcam.connect('image-captured', self.image_captured)
        f.add(self.webcam)
        vb_left.add(f)

        vb_right = Gtk.VBox.new(False, 3)
        # TODO i18n
        l = Gtk.Label('Or choose an existing picture:')
        vb_right.pack_start(l, False, False, 0)
        iv = Gtk.IconView()
        iv.connect('selection-changed', self.selection_changed)
        sw = Gtk.ScrolledWindow()
        sw.set_shadow_type(Gtk.ShadowType.IN)
        sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
        sw.add(iv)
        vb_right.add(sw)

        hb = Gtk.HBox.new(True, 30)
        hb.add(vb_left)
        hb.add(vb_right)
        self.add(hb)

        self.selected_image = Gtk.Image()
        self.selected_image.set_size_request(96, 96)
        self.add(self.selected_image)

        m = Gtk.ListStore(GObject.type_from_name('GdkPixbuf'))
        iv.set_model(m)
        iv.set_pixbuf_column(0)
        if os.path.exists(FACES_PATH):
            for path in os.listdir(FACES_PATH):
                pb = GdkPixbuf.Pixbuf.new_from_file(
                                    os.path.join(FACES_PATH, path))
                m.append([pb])
Ejemplo n.º 52
0
 def __init__(self, exec_by_ibus):
     if not exec_by_ibus:
         global debug_on
         debug_on = True
     self.mainloop = GLib.MainLoop()
     self.bus = IBus.Bus()
     self.bus.connect("disconnected", self.bus_disconnected_cb)
     self.factory = IBus.Factory.new(self.bus.get_connection())
     self.factory.add_engine("uniemoji", GObject.type_from_name("UniEmojiIBusEngine"))
     if exec_by_ibus:
         self.bus.request_name("org.freedesktop.IBus.UniEmoji", 0)
     else:
         xml_path = os.path.join(__base_dir__, "uniemoji.xml")
         if os.path.exists(xml_path):
             component = IBus.Component.new_from_file(xml_path)
         else:
             xml_path = os.path.join(os.path.dirname(__base_dir__), "ibus", "component", "uniemoji.xml")
             component = IBus.Component.new_from_file(xml_path)
         self.bus.register_component(component)
Ejemplo n.º 53
0
 def test_gvalue_converters(self):
     surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 10, 10)
     context = cairo.Context(surface)
     matrix = cairo.Matrix()
     objects = {
         'CairoContext': context,
         'CairoSurface': surface,
         'CairoFontFace': context.get_font_face(),
         'CairoScaledFont': context.get_scaled_font(),
         'CairoPattern': context.get_source(),
         'CairoMatrix': matrix,
     }
     for type_name, cairo_obj in objects.items():
         gtype = GObject.type_from_name(type_name)
         v = GObject.Value()
         assert v.init(gtype) is None
         assert v.get_value() is None
         v.set_value(None)
         assert v.get_value() is None
         v.set_value(cairo_obj)
         assert v.get_value() == cairo_obj
Ejemplo n.º 54
0
 def __init__(self, exec_by_ibus):
     engine_name = "uniemoji"
     if not exec_by_ibus:
         engine_name += " (debug)"
         global debug_on
         debug_on = True
     self.component = \
             IBus.Component.new("org.freedesktop.IBus.UniEmoji",
                                "Unicode emoji and symbols by name",
                                "0.1.0",
                                "GPL",
                                "Lalo Martins <*****@*****.**>",
                                "https://github.com/lalomartins/ibus-uniemoji",
                                "/usr/bin/exec",
                                "uniemoji")
     engine = IBus.EngineDesc.new("uniemoji",
                                  engine_name,
                                  "Unicode emoji and symbols by name",
                                  "",
                                  "GPL",
                                  "Lalo Martins <*****@*****.**>",
                                  "",
                                  "us")
     self.component.add_engine(engine)
     self.mainloop = GLib.MainLoop()
     self.bus = IBus.Bus()
     self.bus.connect("disconnected", self.bus_disconnected_cb)
     self.factory = IBus.Factory.new(self.bus.get_connection())
     self.factory.add_engine("uniemoji",
             GObject.type_from_name("UniEmoji"))
     if exec_by_ibus:
         self.bus.request_name("org.freedesktop.IBus.UniEmoji", 0)
     else:
         self.bus.register_component(self.component)
         self.bus.set_global_engine_async(
                 "uniemoji", -1, None, None, None)
    def __build_profile_section(self):
        self.profile_store = Gtk.ListStore(
                GObject.type_from_name('gchararray'),
                GObject.type_from_name('gchararray'))

        self.profile_view = Gtk.TreeView();
        self.profile_view.set_model(self.profile_store)
        self.name_column = Gtk.CellRendererText()
        self.name_column.set_property('editable', True)
        
        # just like gtk_tree_view_insert_column_with_attributes()
        column1 = Gtk.TreeViewColumn()
        column1.set_title(g(PROFILE_NAME))
        column1.pack_start(self.name_column, True)
        column1.add_attribute(self.name_column, 'text', COLUMN['name'])
        self.profile_view.insert_column(column1, ColumnIds.LEFT)
        column1.set_sort_column_id(ColumnIds.LEFT)

        self.dir_column = Gtk.CellRendererText()
        self.dir_column.set_property('editable', True)

        # same
        column2 = Gtk.TreeViewColumn()
        column2.set_title(g(PROFILE_DIR))
        column2.pack_start(self.dir_column, True)
        column2.add_attribute(self.dir_column, 'text', COLUMN['dir'])
        self.profile_view.insert_column(column2, ColumnIds.RIGHT)
        column2.set_sort_column_id(ColumnIds.RIGHT)

        column1.set_resizable(True)
        column2.set_resizable(True)

        sw = Gtk.ScrolledWindow(None, None)
        sw.add(self.profile_view)

        self.selection = self.profile_view.get_selection()
        self.profile_view.connect('button-press-event',
                lambda w, e: self.__on_button_pressed_cb(e))

        self.tbtn_new = Gtk.ToolButton.new_from_stock(Gtk.STOCK_NEW)
        self.tbtn_new.set_tooltip_text(g(NEW_PROFILE_TEXT))
        self.tbtn_edit = Gtk.ToolButton.new_from_stock(Gtk.STOCK_EDIT)
        self.tbtn_edit.set_tooltip_text(g(EDIT_PROFILE_TEXT))
        self.tbtn_browse = Gtk.ToolButton.new_from_stock(Gtk.STOCK_OPEN)
        self.tbtn_browse.set_tooltip_text(g(BROWSE_PROFILE_TEXT))
        self.tbtn_del = Gtk.ToolButton.new_from_stock(Gtk.STOCK_DELETE)
        self.tbtn_del.set_tooltip_text(g(DELETE_PROFILE_BTN_TEXT))
        self.tbtn_manage = Gtk.ToolButton.new_from_stock(Gtk.STOCK_PREFERENCES)
        self.tbtn_manage.set_tooltip_text(g(MANAGE_PROFILE_TEXT))
        self.tbtn_new.connect('clicked', lambda d:
                self.__on_new_cb())
        self.tbtn_edit.connect('clicked', lambda d:
                self.__on_edit_cb())
        self.tbtn_del.connect('clicked', lambda d:
                self.__on_delete_cb())
        self.tbtn_browse.connect('clicked', lambda d:
                self.__on_browse_cb())
        self.tbtn_manage.connect('clicked', lambda d:
                self.__on_manage_cb())
        self.item_manage.connect('activate', lambda d:
                self.__on_manage_cb())
        
        toolbar = Gtk.Toolbar()
        toolbar.set_orientation(Gtk.Orientation.HORIZONTAL)
        toolbar.set_style(Gtk.ToolbarStyle.ICONS)
        toolbar.add(self.tbtn_new)
        toolbar.add(self.tbtn_edit)
        toolbar.add(self.tbtn_browse)
        toolbar.add(self.tbtn_del)
        toolbar.add(self.tbtn_manage)
        toolbar.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)

        self.tbtn_edit.set_sensitive(False)
        self.tbtn_browse.set_sensitive(False)
        self.tbtn_del.set_sensitive(False)
        self.tbtn_manage.set_sensitive(False)

        hbox = Gtk.VBox(False, SPACING)
        hbox.pack_start(toolbar, False, False, 0)
        hbox.pack_start(sw, True, True, 0)

        return hbox
Ejemplo n.º 56
0
 def test_pytype(self):
     self.assertTrue(GObject.type_from_name("gint").pytype is int)
Ejemplo n.º 57
0
 def test_pytype_2(self):
     self.assertTrue(GObject.type_from_name("GStrv").pytype == [str])