Blame ibus/text.py

Packit 3ff832
# vim:set et sts=4 sw=4:
Packit 3ff832
#
Packit 3ff832
# ibus - The Input Bus
Packit 3ff832
#
Packit 3ff832
# Copyright (c) 2007-2010 Peng Huang <shawn.p.huang@gmail.com>
Packit 3ff832
# Copyright (c) 2007-2010 Red Hat, Inc.
Packit 3ff832
#
Packit 3ff832
# This library is free software; you can redistribute it and/or
Packit 3ff832
# modify it under the terms of the GNU Lesser General Public
Packit 3ff832
# License as published by the Free Software Foundation; either
Packit 3ff832
# version 2.1 of the License, or (at your option) any later version.
Packit 3ff832
#
Packit 3ff832
# This library is distributed in the hope that it will be useful,
Packit 3ff832
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 3ff832
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 3ff832
# Lesser General Public License for more details.
Packit 3ff832
#
Packit 3ff832
# You should have received a copy of the GNU Lesser General Public
Packit 3ff832
# License along with this library; if not, write to the Free Software
Packit 3ff832
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
Packit 3ff832
# USA
Packit 3ff832
Packit 3ff832
__all__ = (
Packit 3ff832
        "Text",
Packit 3ff832
    )
Packit 3ff832
Packit 3ff832
import dbus
Packit 3ff832
from exception import IBusException
Packit 3ff832
from serializable import *
Packit 3ff832
from attribute import AttrList
Packit 3ff832
Packit 3ff832
class Text(Serializable):
Packit 3ff832
    __gtype_name__ = "PYIBusText"
Packit 3ff832
    __NAME__ = "IBusText"
Packit 3ff832
    def __init__ (self, text="", attrs=None):
Packit 3ff832
        super(Text, self).__init__()
Packit 3ff832
        self.__text = text
Packit 3ff832
        self.__attrs = attrs
Packit 3ff832
Packit 3ff832
    def get_text(self):
Packit 3ff832
        return self.__text
Packit 3ff832
Packit 3ff832
    def get_attributes(self):
Packit 3ff832
        return self.__attrs
Packit 3ff832
Packit 3ff832
    text        = property(get_text)
Packit 3ff832
    attributes  = property(get_attributes)
Packit 3ff832
Packit 3ff832
    def serialize(self, struct):
Packit 3ff832
        super(Text, self).serialize(struct)
Packit 3ff832
        struct.append (dbus.String(self.__text))
Packit 3ff832
        if self.__attrs == None:
Packit 3ff832
            self.__attrs = AttrList()
Packit 3ff832
        struct.append (serialize_object(self.__attrs))
Packit 3ff832
Packit 3ff832
    def deserialize(self, struct):
Packit 3ff832
        super(Text, self).deserialize(struct)
Packit 3ff832
Packit 3ff832
        self.__text = struct.pop(0)
Packit 3ff832
        self.__attrs = deserialize_object(struct.pop(0))
Packit 3ff832
Packit 3ff832
def test():
Packit 3ff832
    text = Text("Hello")
Packit 3ff832
    value = serialize_object(text)
Packit 3ff832
    text = deserialize_object(value)
Packit 3ff832
Packit 3ff832
if __name__ == "__main__":
Packit 3ff832
    test()