当前位置: 首页>>代码示例>>Python>>正文


Python Bus.connect方法代码示例

本文整理汇总了Python中bus.Bus.connect方法的典型用法代码示例。如果您正苦于以下问题:Python Bus.connect方法的具体用法?Python Bus.connect怎么用?Python Bus.connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bus.Bus的用法示例。


在下文中一共展示了Bus.connect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestWindow

# 需要导入模块: from bus import Bus [as 别名]
# 或者: from bus.Bus import connect [as 别名]
    class TestWindow(gtk.Window):
        def __init__(self):
            super(TestWindow,self).__init__()

            self.__bus = Bus()
            print self.__bus.get_name()
            self.__bus.connect("disconnected", gtk.main_quit)
            context_path = self.__bus.create_input_context("Test")
            print context_path
            self.__context = InputContext(self.__bus, context_path)
            self.__context.set_capabilities (9)

            self.__context.connect("commit-text", self.__commit_text_cb)
            self.__context.connect("update-preedit-text", self.__update_preedit_text_cb)
            self.__context.connect("show-preedit-text", self.__show_preedit_text_cb)
            self.__context.connect("update-auxiliary-text", self.__update_auxiliary_text_cb)
            self.__context.connect("update-lookup-table", self.__update_lookup_table_cb)

            self.set_events(gtk.gdk.KEY_PRESS_MASK | gtk.gdk.KEY_RELEASE_MASK | gtk.gdk.FOCUS_CHANGE_MASK)

            self.connect("key-press-event", self.__key_press_event_cb)
            self.connect("key-release-event", self.__key_release_event_cb)
            self.connect("delete-event", gtk.main_quit)
            self.connect("focus-in-event", lambda *args: self.__context.focus_in())
            self.connect("focus-out-event", lambda *args: self.__context.focus_out())

            self.show_all()

        def __commit_text_cb(self, context, text):
            print "commit-text:", text.text

        def __update_preedit_text_cb(self, context, text, cursor_pos, visible):
            print "preedit-text:", text.text, cursor_pos, visible

        def __show_preedit_text_cb(self, context):
            print "show-preedit-text"

        def __hide_preedit_text_cb(self, context):
            print "hide-preedit-text"

        def __update_auxiliary_text_cb(self, context, text, visible):
            print "auxiliary-text:", text.text, visible

        def __update_lookup_table_cb(self, context, table, visible):
            print "update-lookup-table:", visible

        def __key_press_event_cb(self, widget, event):
            self.__context.process_key_event(event.keyval, event.state)

        def __key_release_event_cb(self, widget, event):
            self.__context.process_key_event(event.keyval, event.state | modifier.RELEASE_MASK)
开发者ID:Acidburn0zzz,项目名称:ibus,代码行数:53,代码来源:inputcontext.py

示例2: TestPanel

# 需要导入模块: from bus import Bus [as 别名]
# 或者: from bus.Bus import connect [as 别名]
    class TestPanel(PanelBase):
        def __init__(self):
            self.__bus = Bus()
            self.__bus.connect("disconnected", gtk.main_quit)
            super(TestPanel, self).__init__(self.__bus)
            self.__bus.request_name(IBUS_SERVICE_PANEL, 0)

        def focus_in(self, ic):
            print "focus-in:", ic
            context = InputContext(self.__bus, ic)
            info = context.get_factory_info()
            print "factory:", info.name

        def focus_out(self, ic):
            print "focus-out:", ic

        def update_auxiliary_text(self, text, visible):
            print "update-auxiliary-text:", text.text

        def update_lookup_table(self, table, visible):
            print "update-lookup-table", table
开发者ID:Acidburn0zzz,项目名称:ibus,代码行数:23,代码来源:panel.py

示例3: Peer

# 需要导入模块: from bus import Bus [as 别名]
# 或者: from bus.Bus import connect [as 别名]
class Peer(object):
    def __init__(self, share_path, host=None, port=None):
        self.host, self.port = (host or ALL), (port or PORT)
        self.db = dal.DB("sqlite://")
        self.db.define_table("config", dal.Field("key", key=True), dal.Field("value"))
        if "peerid" not in self.db.config:
            self.db.config["peerid"] = hex(random.getrandbits(48))[2:14]
        self.db.define_table(
            "peers",
            dal.Field("peerid"),
            dal.Field(
                "address",
                serialize=lambda x: "%s:%i" % x,
                convert=lambda x: tuple(f(a) for f, a in zip((str, int), x.rsplit(":", 1))),
            ),
            dal.Field("ignore", default=False),
        )
        self.db.define_table("resources", dal.Field("path", key=True), dal.Field("age", int), dal.Field("real_path"))
        if os.path.isdir(share_path) and share_path[-1] != "/":
            share_path += "/"
        for path in find(os.path.abspath(share_path)):
            short_path = path[len(share_path) :]
            print path, short_path
            self.db.resources.insert(path=short_path, age=mod_time(os.stat(path)), real_path=path)
        self.bus = Bus()
        self.bus.connect(MessageType.HeardFromPeer, self.introduce)
        self.bus.connect(MessageType.Request, self.notify)
        self.bus.connect(MessageType.RemoteUpdate, self.remote_update)
        self.public = Broadcaster(self.bus, self.db.config["peerid"], (self.host, self.port))
        self.private = Whisperer(self.bus, (self.host, self.port))

    def start(self):
        self.bus.start()
        self.public.start()
        self.private.start()

    def announce(self):
        self.broadcaster.send("Hello?")

    def remote_update(self, message):
        if self.filter(message.path):
            self.private.retrieve(message.address, message.path)

    def introduce(self, message):
        print message
        self.db.peers.insert(**message)

    def notify(self, message):
        print message
        self.public.send(self.db.resources[message.path].age)

    def stop(self):
        self.private.stop()
        self.public.stop()
        self.bus.stop()
开发者ID:orbnauticus,项目名称:CloneServer,代码行数:57,代码来源:__init__.py


注:本文中的bus.Bus.connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。