Exemplo n.º 1
0
class MapStats(activity.Activity):
    def __init__(self, handle):
        activity.Activity.__init__(self, handle)
        self.set_title('MapStats')

        # The XOCom object helps us communicate with the browser
        # This uses web/index.html as the default page to load
        self.xocom = XOCom()

        toolbox = activity.ActivityToolbox(self)
        self.set_toolbox(toolbox)
        toolbox.show()

        self.set_canvas(self.xocom.create_webview())

    def write_file(self, filename):
        content = self.xocom.send_to_browser('write')
        if content:
            fh = open(filename, 'w')
            fh.write(content)
            fh.close()

    def read_file(self, filename):
        fh = open(filename, 'r')
        content = fh.read()

        def send_delayed_read():
            self.xocom.send_to_browser('read', content)
            return False

        # We must delay this to give the browser time to start up
        # It would be better if this send_to_browser was instead triggered
        # once the browser had finished loading.
        gobject.timeout_add(5000, send_delayed_read)
Exemplo n.º 2
0
class SocialCalcActivity (activity.Activity):
    def __init__(self, handle):
        activity.Activity.__init__(self, handle)
        self.set_title('SocialCalc')

        # The XOCom object helps us communicate with the browser
        # This uses web/index.html as the default page to load
        self.xocom = XOCom()

        toolbox = activity.ActivityToolbox(self)
        self.set_toolbox(toolbox)
        toolbox.show()

        self.set_canvas( self.xocom.create_webview() )

    def write_file(self, filename):
        content = self.xocom.send_to_browser('write')
        if content:
            fh = open(filename, 'w')
            fh.write(content)
            fh.close()

    def read_file(self, filename):
        fh = open(filename, 'r')
        content = fh.read()
        def send_delayed_read():
            self.xocom.send_to_browser('read', content)
            return False
        # We must delay this to give the browser time to start up
        # It would be better if this send_to_browser was instead triggered
        # once the browser had finished loading.
        gobject.timeout_add(5000, send_delayed_read)
Exemplo n.º 3
0
    def __init__(self, handle):
        activity.Activity.__init__(self, handle)
        self.set_title('SocialCalc')
        self._logger = logging.getLogger('OnePageWiki-Activity')

        # The XOCom object helps us communicate with the browser
        # This uses web/index.html as the default page to load
        self.xocom = XOCom(self.control_sending_text)                   #REMEMBER THAT I HAVE STILL TO SEND THE ARGUMENT IN THE XOCOM CLASS

        toolbox = ToolbarBox()

        activity_button = ActivityButton(self)
        toolbox.toolbar.insert(activity_button, 0)
        activity_button.show()

        title_entry = TitleEntry(self)
        toolbox.toolbar.insert(title_entry, -1)
        title_entry.show()
        
        separator = Gtk.SeparatorToolItem()
        separator.props.draw = False
        separator.set_expand(True)
        toolbox.toolbar.insert(separator, -1)
        separator.show()

        stop_button = ShareButton(self)
        toolbox.toolbar.insert(stop_button, -1)
        stop_button.show()
        self.set_toolbar_box(toolbox)
        toolbox.show()

        stop_button = StopButton(self)
        toolbox.toolbar.insert(stop_button, -1)
        stop_button.show()

        self.set_toolbar_box(toolbox)
        toolbox.show()
        ##self.xocom.send_to_browser_localize(['initlocalize'])

        self.set_canvas( self.xocom.create_webview() )

        self.hellotube = None  # Shared session    #REQUIRED
        self.initiating = False
        
        self.pservice = presenceservice.get_instance()
        
        owner = self.pservice.get_owner()
        self.owner = owner   
        
        self.connect('shared', self._shared_cb)
        self.connect('joined', self._joined_cb)
        
        self.filename=''       #ADDED SPECIFICALLY TO CALL WRITE AND READ METHODS
        self.content=''

        #calling to initialize strings in localization
        #should wait for init complete from browser
        GObject.timeout_add(4000, self.xocom.send_to_browser_localize,['initlocalize'])
Exemplo n.º 4
0
    def __init__(self, handle):
        activity.Activity.__init__(self, handle)
        self.set_title('MapStats')

        # The XOCom object helps us communicate with the browser
        # This uses web/index.html as the default page to load
        self.xocom = XOCom()

        toolbox = activity.ActivityToolbox(self)
        self.set_toolbox(toolbox)
        toolbox.show()

        self.set_canvas(self.xocom.create_webview())
Exemplo n.º 5
0
    def __init__(self, handle):
        activity.Activity.__init__(self, handle)
        self.set_title("SocialCalc")
        self._logger = logging.getLogger("OnePageWiki-Activity")

        # The XOCom object helps us communicate with the browser
        # This uses web/index.html as the default page to load
        self.xocom = XOCom(
            self.control_sending_text
        )  # REMEMBER THAT I HAVE STILL TO SEND THE ARGUMENT IN THE XOCOM CLASS

        toolbox = ToolbarBox()

        activity_button = ActivityButton(self)
        toolbox.toolbar.insert(activity_button, 0)
        activity_button.show()

        title_entry = TitleEntry(self)
        toolbox.toolbar.insert(title_entry, -1)
        title_entry.show()

        separator = Gtk.SeparatorToolItem()
        separator.props.draw = False
        separator.set_expand(True)
        toolbox.toolbar.insert(separator, -1)
        separator.show()

        stop_button = ShareButton(self)
        toolbox.toolbar.insert(stop_button, -1)
        stop_button.show()
        self.set_toolbar_box(toolbox)
        toolbox.show()

        stop_button = StopButton(self)
        toolbox.toolbar.insert(stop_button, -1)
        stop_button.show()

        self.set_toolbar_box(toolbox)
        toolbox.show()
        ##self.xocom.send_to_browser_localize(['initlocalize'])

        self.set_canvas(self.xocom.create_webview())

        self.hellotube = None  # Shared session    #REQUIRED
        self.initiating = False

        self.pservice = presenceservice.get_instance()

        owner = self.pservice.get_owner()
        self.owner = owner

        self.connect("shared", self._shared_cb)
        self.connect("joined", self._joined_cb)

        self.filename = ""  # ADDED SPECIFICALLY TO CALL WRITE AND READ METHODS
        self.content = ""

        # calling to initialize strings in localization
        # should wait for init complete from browser
        GObject.timeout_add(4000, self.xocom.send_to_browser_localize, ["initlocalize"])
Exemplo n.º 6
0
    def __init__(self, handle):
        activity.Activity.__init__(self, handle)
        self.set_title('SocialCalc')
        self._logger = logging.getLogger('OnePageWiki-Activity')

        # The XOCom object helps us communicate with the browser
        # This uses web/index.html as the default page to load
        self.xocom = XOCom(self.control_sending_text)                   #REMEMBER THAT I HAVE STILL TO SEND THE ARGUMENT IN THE XOCOM CLASS

        toolbox = activity.ActivityToolbox(self)
        self.set_toolbox(toolbox)
        toolbox.show()
        ##self.xocom.send_to_browser_localize(['initlocalize'])

        self.set_canvas( self.xocom.create_webview() )
        
        self.hellotube = None  # Shared session    #REQUIRED
        self.initiating = False
        
        self.pservice = presenceservice.get_instance()
        
        owner = self.pservice.get_owner()
        self.owner = owner   
        
        self.connect('shared', self._shared_cb)
        self.connect('joined', self._joined_cb)
        
        self.filename=''       #ADDED SPECIFICALLY TO CALL WRITE AND READ METHODS
        self.content=''

        #calling to initialize strings in localization
        #should wait for init complete from browser
        gobject.timeout_add(4000, self.xocom.send_to_browser_localize,['initlocalize'])
Exemplo n.º 7
0
class ElementsActivity(activity.Activity):
    def __init__(self, handle):
        activity.Activity.__init__(self, handle)
        self.set_title('Elements')

        act_root = self.get_activity_root()
        path_data = os.path.join(act_root, "data")
        self.file_name = os.path.join(path_data, "datos.js")
        # The XOCom object helps us communicate with the browser
        # This uses web/index.html as the default page to load
        self.xocom = XOCom("file://" + os.path.join(
            os.path.dirname(os.path.abspath(__file__)), "web/allelements.xml"))

        toolbox = activity.ActivityToolbox(self)
        self.set_toolbox(toolbox)
        toolbox.show()

        self.set_canvas(self.xocom.create_webview())

        self.read_file(self.file_name)

    def write_file(self, filename):
        print "Grabando", filename
        content = self.xocom.send_to_browser('write')

        if content:
            fh = open(filename, 'w')
            fh.write(content)
            fh.close()

    def read_file(self, filename):
        print "Leyendo", filename
        content = "textos = new Array();"
        if os.path.exists(filename):
            fh = open(filename, 'r')
            content = fh.read()
            print content

        def send_delayed_read():
            self.xocom.send_to_browser('read', content)
            return False

        # We must delay this to give the browser time to start up
        # It would be better if this send_to_browser was instead triggered
        # once the browser had finished loading.
        gobject.timeout_add(5000, send_delayed_read)
Exemplo n.º 8
0
    def __init__(self, handle):
        activity.Activity.__init__(self, handle)
        self.set_title('Elements')

        act_root = self.get_activity_root()
        path_data = os.path.join(act_root, "data")
        self.file_name = os.path.join(path_data, "datos.js")
        # The XOCom object helps us communicate with the browser
        # This uses web/index.html as the default page to load
        self.xocom = XOCom("file://" + os.path.join(
            os.path.dirname(os.path.abspath(__file__)), "web/allelements.xml"))

        toolbox = activity.ActivityToolbox(self)
        self.set_toolbox(toolbox)
        toolbox.show()

        self.set_canvas(self.xocom.create_webview())

        self.read_file(self.file_name)
Exemplo n.º 9
0
    def __init__(self, handle):
        activity.Activity.__init__(self, handle)
        self.set_title('SocialCalc')

        # The XOCom object helps us communicate with the browser
        # This uses web/index.html as the default page to load
        self.xocom = XOCom()

        toolbox = activity.ActivityToolbox(self)
        self.set_toolbox(toolbox)
        toolbox.show()

        self.set_canvas( self.xocom.create_webview() )
    def __init__(self, handle):
        activity.Activity.__init__(self, handle)
        self.set_title('SocialCalc')

        # The XOCom object helps us communicate with the browser
        # This uses web/index.html as the default page to load
        self.xocom = XOCom()

        toolbox = activity.ActivityToolbox(self)
        self.set_toolbox(toolbox)
        toolbox.show()

        self.set_canvas( self.xocom.create_webview() )
        activity_toolbar_ext = SpreadSheetActivityToolbar(toolbox, self.set_canvas, self)

        self._edit_toolbar = SpreadsheetEditToolbar(self, self._edit_toolbar, set_canvas)
        toolbox.add_toolbar(_('Edit'),self._edit_toolbar)
        self._edit_toolbar.show()

        view_toolbar = ViewToolbar (self.set_canvas)
        self.set_canvas.show()
Exemplo n.º 11
0
class SocialCalcActivity (activity.Activity):
    def __init__(self, handle):
        activity.Activity.__init__(self, handle)
        self.set_title('SocialCalc')
        self._logger = logging.getLogger('OnePageWiki-Activity')

        # The XOCom object helps us communicate with the browser
        # This uses web/index.html as the default page to load
        self.xocom = XOCom(self.control_sending_text)                   #REMEMBER THAT I HAVE STILL TO SEND THE ARGUMENT IN THE XOCOM CLASS

        toolbox = ToolbarBox()

        activity_button = ActivityButton(self)
        toolbox.toolbar.insert(activity_button, 0)
        activity_button.show()

        title_entry = TitleEntry(self)
        toolbox.toolbar.insert(title_entry, -1)
        title_entry.show()
        
        separator = Gtk.SeparatorToolItem()
        separator.props.draw = False
        separator.set_expand(True)
        toolbox.toolbar.insert(separator, -1)
        separator.show()

        stop_button = ShareButton(self)
        toolbox.toolbar.insert(stop_button, -1)
        stop_button.show()
        self.set_toolbar_box(toolbox)
        toolbox.show()

        stop_button = StopButton(self)
        toolbox.toolbar.insert(stop_button, -1)
        stop_button.show()

        self.set_toolbar_box(toolbox)
        toolbox.show()
        ##self.xocom.send_to_browser_localize(['initlocalize'])

        self.set_canvas( self.xocom.create_webview() )

        self.hellotube = None  # Shared session    #REQUIRED
        self.initiating = False
        
        self.pservice = presenceservice.get_instance()
        
        owner = self.pservice.get_owner()
        self.owner = owner   
        
        self.connect('shared', self._shared_cb)
        self.connect('joined', self._joined_cb)
        
        self.filename=''       #ADDED SPECIFICALLY TO CALL WRITE AND READ METHODS
        self.content=''

        #calling to initialize strings in localization
        #should wait for init complete from browser
        GObject.timeout_add(4000, self.xocom.send_to_browser_localize,['initlocalize'])


    def _shared_cb(self, activity):
        self._logger.debug('My activity was shared')
        print 'my activity is shared'
        self.initiating = True
        self._sharing_setup()

        self._logger.debug('This is my activity: making a tube...')
        print 'This is my activity: making a tube...'
        id = self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].OfferDBusTube(
            SERVICE, {})
        
    def _sharing_setup(self):
        if self.shared_activity is None:
            self._logger.error('Failed to share or join activity')
            print 'Failed to share or join activity'
            return

        self.conn = self.shared_activity.telepathy_conn
        self.tubes_chan = self.shared_activity.telepathy_tubes_chan
        self.text_chan = self.shared_activity.telepathy_text_chan

        self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].connect_to_signal(
            'NewTube', self._new_tube_cb)

        self.shared_activity.connect('buddy-joined', self._buddy_joined_cb)
        self.shared_activity.connect('buddy-left', self._buddy_left_cb)

        #self.entry.set_sensitive(True)
        #self.entry.grab_focus()

        # Optional - included for example:
        # Find out who's already in the shared activity:
        #for buddy in self._shared_activity.get_joined_buddies():
            #self._logger.debug('Buddy %s is already in the activity',
                               #buddy.props.nick)

    def _list_tubes_reply_cb(self, tubes):
        for tube_info in tubes:
            self._new_tube_cb(*tube_info)

    def _list_tubes_error_cb(self, e):
        self._logger.error('ListTubes() failed: %s', e)
        

    def _joined_cb(self, activity):
        if not self._shared_activity:
            return

        self._logger.debug('Joined an existing shared activity')
        print 'Joined an existing shared activity'
        self.initiating = False
        self._sharing_setup()

        self._logger.debug('This is not my activity: waiting for a tube...')
        print 'This is not my activity: waiting for a tube...'
        self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].ListTubes(
            reply_handler=self._list_tubes_reply_cb,
            error_handler=self._list_tubes_error_cb)

    def _new_tube_cb(self, id, initiator, type, service, params, state):
        self._logger.debug('New tube: ID=%d initator=%d type=%d service=%s '
                     'params=%r state=%d', id, initiator, type, service,
                     params, state)
        if (type == telepathy.TUBE_TYPE_DBUS and
            service == SERVICE):
            if state == telepathy.TUBE_STATE_LOCAL_PENDING:
                self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].AcceptDBusTube(id)
            tube_conn = TubeConnection(self.conn,
                self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES],
                id, group_iface=self.text_chan[telepathy.CHANNEL_INTERFACE_GROUP])
            self.hellotube = TextSync(tube_conn, self.initiating,
                                      self._get_buddy,self.read_shared,self.write_shared,self.xocom)

    def _buddy_joined_cb (self, activity, buddy):
        """Called when a buddy joins the shared activity.

        This doesn't do much here as HelloMesh doesn't have much 
        functionality. It's up to you do do interesting things
        with the Buddy...
        """
        self._logger.debug('Buddy %s joined', buddy.props.nick)
        print 'Buddy %s joined' % (buddy.props.nick)

    def _buddy_left_cb (self, activity, buddy):
        """Called when a buddy leaves the shared activity.

        This doesn't do much here as HelloMesh doesn't have much 
        functionality. It's up to you do do interesting things
        with the Buddy...
        """
        self._logger.debug('Buddy %s left', buddy.props.nick)
        print 'Buddy %s left' % (buddy.props.nick)

    def _get_buddy(self, cs_handle):
        """Get a Buddy from a channel specific handle."""
        self._logger.debug('Trying to find owner of handle %u...', cs_handle)
        group = self.text_chan[telepathy.CHANNEL_INTERFACE_GROUP]
        my_csh = group.GetSelfHandle()
        self._logger.debug('My handle in that group is %u', my_csh)
        if my_csh == cs_handle:
            handle = self.conn.GetSelfHandle()
            self._logger.debug('CS handle %u belongs to me, %u', cs_handle, handle)
        elif group.GetGroupFlags() & telepathy.CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES:
            handle = group.GetHandleOwners([cs_handle])[0]
            self._logger.debug('CS handle %u belongs to %u', cs_handle, handle)
        else:
            handle = cs_handle
            self._logger.debug('non-CS handle %u belongs to itself', handle)
            # XXX: deal with failure to get the handle owner
            assert handle != 0
        return self.pservice.get_buddy_by_telepathy_handle(
            self.conn.service_name, self.conn.object_path, handle)

    def write_file(self, filename):
        
##        print 'in write file'                       
##        print content
##        print 'filename is   ',filename,'  mime  ',self.metadata['mime_type']
        self.metadata['mime_type']='application/scalc'  ## The mime_type is changed beacause the name of file still remains .wk* even when it is saved and
                                                      ## opened in scalc format. So, to distinguish it from original one because, the mime_type of a binary
                                                    ## .wk* file would be application/vnd.lotus-1-2-3

        ##self.xocom.send_to_browser_localize(['initlocalize'])
        content = self.xocom.send_to_browser('write')
        if content:
            fh = open(filename, 'w')
            fh.write(content)
            fh.close()
       
        if not self.hellotube==None:
            if flag_WriteFromWriteFile:
                #self.control_sending_text()   COMMENTED ONLY FOR THIS TIME WHILE CHECKING UNCOMMENT IT OVER THE TIME
                self.hellotube.SendText(['whole',content])  #COMMENT THIS LINE AT THAT TIME
            

    def read_file(self, filename):
        #print '\nin read file\n'
        file_extension_value=intero.check_file_extension(filename)
        print ' \nthe extension is ',file_extension_value[1],' and the value is ',file_extension_value[0],'\n'
        
        if  file_extension_value[0] and (self.metadata['mime_type']!='application/scalc') :
            fh = open(filename, 'rb')
            #print 'filename is   ',filename,'  mime  ',self.metadata['mime_type']
            #print self.metadata['mime_type']
            content = fh.read()
            fh.close()
            #print content 
            content=intero.convert(content,file_extension_value[1])

        else:
            fh = open(filename, 'r')
            content = fh.read()
            fh.close()
            
        #print content
        #return
        def send_delayed_read():
            self.xocom.send_to_browser('read', content)
            return False
        # We must delay this to give the browser time to start up
        # It would be better if this send_to_browser was instead triggered
        # once the browser had finished loading.
        GObject.timeout_add(5000, send_delayed_read)

        
    def write_shared(self):
        content=self.xocom.send_to_browser('write')
        global_content=content
        self.content=content
        return content
        #self.hellotube.SendText(self.content)
    
    def read_shared(self,content):
        self.xocom.send_to_browser('read',content)
        
    def control_sending_text(self,array='', topic='', str=''):
        if not str=='':         #just to check that the string is received from the js part
            print 'reached control_sending_text from js part   ',str
        #content=self.write_shared()
        #content=array
        
        if str=='execute':
            print 'in execute in control_sending_text'
            global_content=array[1]
            self.content=global_content
            self.hellotube.SendText(array)
Exemplo n.º 12
0
import os
import gtk
import time
import hulahop
hulahop.startup(os.path.expanduser('~/.test-hulahop'))
from XOCom import XOCom

# The XOCom object helps us communicate with the browser
uri = "file:///home/olpc/src/socialcalc-xocom/web/index.html"
xocom = XOCom(uri)

# This is just a simple way to trigger events from python for testing
# Handler for keypresses in the GTK Application
#   r - call the javascript 'read' hook with a dummy string
#   w - call the javascript 'write' hook and print out the result
def keypress(window, event):
    key = event.string
    if key == 'w':
        result = xocom.send_to_browser('write')
        if result:
            print "Result from browser - '%s'"%result
        else:
            print "No data received in the browser's response"
    if key == 'r':
        message = "I am a monkey - %s"%time.time()
        print "Sending '%s'"%message
        result = xocom.send_to_browser('read', message)
    if key == 'q':
        quit(None)

Exemplo n.º 13
0
class SocialCalcActivity(activity.Activity):
    def __init__(self, handle):
        activity.Activity.__init__(self, handle)
        self.set_title("SocialCalc")
        self._logger = logging.getLogger("OnePageWiki-Activity")

        # The XOCom object helps us communicate with the browser
        # This uses web/index.html as the default page to load
        self.xocom = XOCom(
            self.control_sending_text
        )  # REMEMBER THAT I HAVE STILL TO SEND THE ARGUMENT IN THE XOCOM CLASS

        toolbox = ToolbarBox()

        activity_button = ActivityButton(self)
        toolbox.toolbar.insert(activity_button, 0)
        activity_button.show()

        title_entry = TitleEntry(self)
        toolbox.toolbar.insert(title_entry, -1)
        title_entry.show()

        separator = Gtk.SeparatorToolItem()
        separator.props.draw = False
        separator.set_expand(True)
        toolbox.toolbar.insert(separator, -1)
        separator.show()

        stop_button = ShareButton(self)
        toolbox.toolbar.insert(stop_button, -1)
        stop_button.show()
        self.set_toolbar_box(toolbox)
        toolbox.show()

        stop_button = StopButton(self)
        toolbox.toolbar.insert(stop_button, -1)
        stop_button.show()

        self.set_toolbar_box(toolbox)
        toolbox.show()
        ##self.xocom.send_to_browser_localize(['initlocalize'])

        self.set_canvas(self.xocom.create_webview())

        self.hellotube = None  # Shared session    #REQUIRED
        self.initiating = False

        self.pservice = presenceservice.get_instance()

        owner = self.pservice.get_owner()
        self.owner = owner

        self.connect("shared", self._shared_cb)
        self.connect("joined", self._joined_cb)

        self.filename = ""  # ADDED SPECIFICALLY TO CALL WRITE AND READ METHODS
        self.content = ""

        # calling to initialize strings in localization
        # should wait for init complete from browser
        GObject.timeout_add(4000, self.xocom.send_to_browser_localize, ["initlocalize"])

    def _shared_cb(self, activity):
        self._logger.debug("My activity was shared")
        print "my activity is shared"
        self.initiating = True
        self._sharing_setup()

        self._logger.debug("This is my activity: making a tube...")
        print "This is my activity: making a tube..."
        id = self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].OfferDBusTube(SERVICE, {})

    def _sharing_setup(self):
        if self.shared_activity is None:
            self._logger.error("Failed to share or join activity")
            print "Failed to share or join activity"
            return

        self.conn = self.shared_activity.telepathy_conn
        self.tubes_chan = self.shared_activity.telepathy_tubes_chan
        self.text_chan = self.shared_activity.telepathy_text_chan

        self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].connect_to_signal("NewTube", self._new_tube_cb)

        self.shared_activity.connect("buddy-joined", self._buddy_joined_cb)
        self.shared_activity.connect("buddy-left", self._buddy_left_cb)

        # self.entry.set_sensitive(True)
        # self.entry.grab_focus()

        # Optional - included for example:
        # Find out who's already in the shared activity:
        # for buddy in self._shared_activity.get_joined_buddies():
        # self._logger.debug('Buddy %s is already in the activity',
        # buddy.props.nick)

    def _list_tubes_reply_cb(self, tubes):
        for tube_info in tubes:
            self._new_tube_cb(*tube_info)

    def _list_tubes_error_cb(self, e):
        self._logger.error("ListTubes() failed: %s", e)

    def _joined_cb(self, activity):
        if not self._shared_activity:
            return

        self._logger.debug("Joined an existing shared activity")
        print "Joined an existing shared activity"
        self.initiating = False
        self._sharing_setup()

        self._logger.debug("This is not my activity: waiting for a tube...")
        print "This is not my activity: waiting for a tube..."
        self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].ListTubes(
            reply_handler=self._list_tubes_reply_cb, error_handler=self._list_tubes_error_cb
        )

    def _new_tube_cb(self, id, initiator, type, service, params, state):
        self._logger.debug(
            "New tube: ID=%d initator=%d type=%d service=%s " "params=%r state=%d",
            id,
            initiator,
            type,
            service,
            params,
            state,
        )
        if type == telepathy.TUBE_TYPE_DBUS and service == SERVICE:
            if state == telepathy.TUBE_STATE_LOCAL_PENDING:
                self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].AcceptDBusTube(id)
            tube_conn = TubeConnection(
                self.conn,
                self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES],
                id,
                group_iface=self.text_chan[telepathy.CHANNEL_INTERFACE_GROUP],
            )
            self.hellotube = TextSync(
                tube_conn, self.initiating, self._get_buddy, self.read_shared, self.write_shared, self.xocom
            )

    def _buddy_joined_cb(self, activity, buddy):
        """Called when a buddy joins the shared activity.

        This doesn't do much here as HelloMesh doesn't have much 
        functionality. It's up to you do do interesting things
        with the Buddy...
        """
        self._logger.debug("Buddy %s joined", buddy.props.nick)
        print "Buddy %s joined" % (buddy.props.nick)

    def _buddy_left_cb(self, activity, buddy):
        """Called when a buddy leaves the shared activity.

        This doesn't do much here as HelloMesh doesn't have much 
        functionality. It's up to you do do interesting things
        with the Buddy...
        """
        self._logger.debug("Buddy %s left", buddy.props.nick)
        print "Buddy %s left" % (buddy.props.nick)

    def _get_buddy(self, cs_handle):
        """Get a Buddy from a channel specific handle."""
        self._logger.debug("Trying to find owner of handle %u...", cs_handle)
        group = self.text_chan[telepathy.CHANNEL_INTERFACE_GROUP]
        my_csh = group.GetSelfHandle()
        self._logger.debug("My handle in that group is %u", my_csh)
        if my_csh == cs_handle:
            handle = self.conn.GetSelfHandle()
            self._logger.debug("CS handle %u belongs to me, %u", cs_handle, handle)
        elif group.GetGroupFlags() & telepathy.CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES:
            handle = group.GetHandleOwners([cs_handle])[0]
            self._logger.debug("CS handle %u belongs to %u", cs_handle, handle)
        else:
            handle = cs_handle
            self._logger.debug("non-CS handle %u belongs to itself", handle)
            # XXX: deal with failure to get the handle owner
            assert handle != 0
        return self.pservice.get_buddy_by_telepathy_handle(self.conn.service_name, self.conn.object_path, handle)

    def write_file(self, filename):

        ##        print 'in write file'
        ##        print content
        ##        print 'filename is   ',filename,'  mime  ',self.metadata['mime_type']
        self.metadata[
            "mime_type"
        ] = (
            "application/scalc"
        )  ## The mime_type is changed beacause the name of file still remains .wk* even when it is saved and
        ## opened in scalc format. So, to distinguish it from original one because, the mime_type of a binary
        ## .wk* file would be application/vnd.lotus-1-2-3

        ##self.xocom.send_to_browser_localize(['initlocalize'])
        content = self.xocom.send_to_browser("write")
        if content:
            fh = open(filename, "w")
            fh.write(content)
            fh.close()

        if not self.hellotube == None:
            if flag_WriteFromWriteFile:
                # self.control_sending_text()   COMMENTED ONLY FOR THIS TIME WHILE CHECKING UNCOMMENT IT OVER THE TIME
                self.hellotube.SendText(["whole", content])  # COMMENT THIS LINE AT THAT TIME

    def read_file(self, filename):
        # print '\nin read file\n'
        file_extension_value = intero.check_file_extension(filename)
        print " \nthe extension is ", file_extension_value[1], " and the value is ", file_extension_value[0], "\n"

        if file_extension_value[0] and (self.metadata["mime_type"] != "application/scalc"):
            fh = open(filename, "rb")
            # print 'filename is   ',filename,'  mime  ',self.metadata['mime_type']
            # print self.metadata['mime_type']
            content = fh.read()
            fh.close()
            # print content
            content = intero.convert(content, file_extension_value[1])

        else:
            fh = open(filename, "r")
            content = fh.read()
            fh.close()

        # print content
        # return
        def send_delayed_read():
            self.xocom.send_to_browser("read", content)
            return False

        # We must delay this to give the browser time to start up
        # It would be better if this send_to_browser was instead triggered
        # once the browser had finished loading.
        GObject.timeout_add(5000, send_delayed_read)

    def write_shared(self):
        content = self.xocom.send_to_browser("write")
        global_content = content
        self.content = content
        return content
        # self.hellotube.SendText(self.content)

    def read_shared(self, content):
        self.xocom.send_to_browser("read", content)

    def control_sending_text(self, array="", topic="", str=""):
        if not str == "":  # just to check that the string is received from the js part
            print "reached control_sending_text from js part   ", str
        # content=self.write_shared()
        # content=array

        if str == "execute":
            print "in execute in control_sending_text"
            global_content = array[1]
            self.content = global_content
            self.hellotube.SendText(array)