Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgnacio Rodríguez <ignaciorodriguez@sugarlabs.org>2013-05-18 15:36:56 (GMT)
committer Ignacio Rodríguez <ignaciorodriguez@sugarlabs.org>2013-05-18 15:36:56 (GMT)
commitda06435a79d0c32c435b4d2df57c3d541af701cd (patch)
tree641dea68d7328874ec42c8e9b2c55873ab8f22ea
parent9da92ad4e8085fa503726b64524ff54be5fe6cb3 (diff)
Ahora muestra la IP.
-rwxr-xr-xvnclauncher.py372
1 files changed, 176 insertions, 196 deletions
diff --git a/vnclauncher.py b/vnclauncher.py
index 5eefe09..c580cc4 100755
--- a/vnclauncher.py
+++ b/vnclauncher.py
@@ -1,6 +1,7 @@
-# Copyright (C) 2007, Eduardo Silva <edsiper@gmail.com>.
-# Copyright (C) 2008, One Laptop Per Child
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
# Copyright (C) 2013, SomosAzucar
+# Version especial de VncLauncher con nuevos cambios.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -16,228 +17,207 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+import gtk
+import time
+import gobject
import os
+import commands
+import platform
+from threading import Thread
-import logging
from gettext import gettext as _
-import gtk
-import dbus
-
from sugar.activity import activity
-from sugar import env
+from sugar.graphics.radiotoolbutton import RadioToolButton
from sugar.graphics.toolbutton import ToolButton
-from sugar.graphics.palette import Palette
-from sugar.graphics.roundbox import CanvasRoundBox
-import ConfigParser
-import os
-import os.path
-import vte
-import pango
-import commands
-import sys
-import platform
-import logging
+from sugar.graphics.toolbarbox import ToolbarBox
+from sugar.activity.widgets import StopButton
+from sugar.activity.widgets import ActivityToolbarButton
class VncLauncherActivity(activity.Activity):
- def _ipaddr_(self,button):
- ifconfig="/sbin/ifconfig"
- ifaces=['eth0','msh0']
- for iface in ifaces:
- cmd="%s %s" % (ifconfig, iface)
- output=commands.getoutput(cmd)
- ipaddr="Error!!"
- error=_("Error!! check wireless connection")
- inet = output.find('inet')
- if inet >= 0:
- print iface
- start=inet + len('inet')
- end=output.find(" ",start + 1)
- if iface == 'eth0':
- ipaddr='Ethernet IP= '+ output[start:end]
- else:
- ipaddr='Mesh IP='+ output[start:end]
- break
- else:
- ipaddr=error
-
- button.set_label(_('Please Click to find current IP address \n\n') +
- ipaddr)
-
def __init__(self, handle):
activity.Activity.__init__(self, handle)
-
- logging.debug('Starting the X11 VNC activity')
-
- self.set_title(_('X11 VNC Server Activity'))
- self.connect('key-press-event', self.__key_press_cb)
- args=_("Please Click to find current IP address")
- box = gtk.HBox(False, 10)
- table=gtk.Table(4,1,True)
- button=gtk.Button(args)
- button.connect("clicked",self._ipaddr_)
- table.attach(button,0,1,0,1,gtk.FILL|gtk.EXPAND,gtk.EXPAND|gtk.FILL,25,25)
- button.show()
- button=gtk.Button(_("Start X11 VNC Server"))
- button.connect("clicked",self.connectVNC)
- table.attach(button,0,1,1,2,gtk.FILL|gtk.EXPAND,gtk.FILL|gtk.EXPAND,25,25)
- button.show()
-
- button=gtk.Button(_("Stop X11 VNC Server"))
- button.connect("clicked",self.stopVNC)
- table.attach(button,0,1,2,3,gtk.FILL,gtk.FILL,25,25)
- button.show()
-
- button=gtk.Button(_("Exit VncLauncherActivity"))
- button.connect("clicked",lambda w:gtk.main_quit())
- table.attach(button,0,1,3,4,gtk.FILL,gtk.FILL,25,25)
- button.show()
- table.show()
-
- self._vte = VTE()
- self._vte.show()
-
- box.pack_start(self._vte)
- box.pack_start(table, False, False, 0)
-
- self.set_canvas(box)
- box.show()
-
- def stopVNC(self,button):
-
- cmd = "kill " + commands.getoutput('pidof x11vnc')
- self._vte.fork_command(cmd)
-
- def connectVNC(self,button):
- self._vte.grab_focus()
- # check if x11vnc is installed
- cmd = '/usr/bin/x11vnc'
- if os.path.isfile(cmd) and os.access(cmd, os.X_OK) and os.path.exists(cmd):
- logging.error('Using x11vnc installed in the system')
- self.env = "/usr/lib"
- else:
- if platform.machine().startswith('arm'):
- path = os.path.join(activity.get_bundle_path(),
- 'bin/arm')
- elif platform.machine().startswith('x86_64'):
- path = os.path.join(activity.get_bundle_path(),
- 'bin/x86')
- else:
- path = os.path.join(activity.get_bundle_path(),
- 'bin/i586')
- self.env = {'LD_LIBRARY_PATH':'%s/lib' % path}
- cmd = os.path.join(path, 'x11vnc')
- logging.error('Using %s', cmd)
+ self.max_participants = 1
- self._vte.fork_command(cmd, envv=self.env)
+ self.toolbarbox = ToolbarBox()
+ self.toolbar = self.toolbarbox.toolbar
- def __key_press_cb(self, window, event):
- return False
+ self.start_vnc = RadioToolButton(icon_name="start_vnc",
+ tooltip=_("Iniciar servidor VNC"))
-class VTE(vte.Terminal):
- def __init__(self):
- vte.Terminal.__init__(self)
- self._configure_vte()
- self.connect("child-exited", lambda term: term.fork_command())
+ self.stop_vnc = RadioToolButton(icon_name="stop_vnc",
+ tooltip=_("Detener servidor VNC"),
+ group=self.start_vnc)
- os.chdir(os.environ["HOME"])
- self.fork_command()
+ self.stop_vnc.set_active(True)
- def _configure_vte(self):
- conf = ConfigParser.ConfigParser()
- conf_file = os.path.join(env.get_profile_path(), 'terminalrc')
+ self.get_ipbutton = ToolButton(icon_name="get_ip",
+ tooltip=_("Obtener la IP actual"))
+
+
+ ##
+ self.messages = gtk.TreeView()
+ self.messages.set_rules_hint(True)
+ modelo = gtk.ListStore(str, str, gtk.gdk.Color)
+ self.messages.set_model(modelo)
+ render = gtk.CellRendererText()
+ render1 = gtk.CellRendererText()
+
+ column1 = gtk.TreeViewColumn(_("Hora"), render, markup=0)
+ column2 = gtk.TreeViewColumn(_("Mensaje"), render1, markup=1)
+ column1.add_attribute(render, 'foreground-gdk', 2)
+ column2.add_attribute(render1, 'foreground-gdk', 2)
+
- if os.path.isfile(conf_file):
- f = open(conf_file, 'r')
- conf.readfp(f)
- f.close()
+ self.messages.append_column(column1)
+ self.messages.append_column(column2)
+ color = gtk.gdk.color_parse("dark blue")
+ modelo.insert(0, [time.strftime("\n<b>%H:%M:%S</b>\n"), _("\n<b>Inicio de actividad.</b>\n"), color])
+
+ self.showed_message_stop = True
+ self.showed_message_start = False
+
+ self.stop_vnc.connect("clicked", self.__stop_vnc)
+ self.start_vnc.connect("clicked", self.__start_vnc)
+ self.clear_model = ToolButton(icon_name="clear_console",
+ tooltip=_("Eliminar mensajes"))
+ self.clear_model.connect("clicked", lambda x: modelo.clear())
+ self.get_ipbutton.connect("clicked", self.__get_ip)
+ self.last_message = 1
+
+ self.__get_x11vnc_path()
+ ##
+ separator = gtk.SeparatorToolItem()
+ separator.props.draw = False
+ separator.set_expand(True)
+
+ self.stop_activity = StopButton(self)
+
+ self.toolbar.insert(ActivityToolbarButton(self), -1)
+ self.toolbar.insert(gtk.SeparatorToolItem(), -1)
+ self.toolbar.insert(self.start_vnc, -1)
+ self.toolbar.insert(self.stop_vnc, -1)
+ self.toolbar.insert(gtk.SeparatorToolItem(), -1)
+ self.toolbar.insert(self.get_ipbutton, -1)
+ self.toolbar.insert(self.clear_model, -1)
+ self.toolbar.insert(separator, -1)
+ self.toolbar.insert(self.stop_activity, -1)
+
+ self.messages_scroll = gtk.ScrolledWindow()
+ self.messages_scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
+ self.messages_scroll.add_with_viewport(self.messages)
+
+ self.set_toolbar_box(self.toolbarbox)
+ self.set_canvas(self.messages_scroll)
+
+ self.show_all()
+ gobject.timeout_add(100, self.__check_is_on)
+
+ def __check_is_on(self):
+ pid = commands.getoutput("pidof x11vnc")
+ if self.start_vnc.get_active() and pid == "":
+ self.showed_message_stop = True
+ self.stop_vnc.set_active(True)
+ self.start_vnc.set_active(False)
+ self.showed_message_start = False
+
+ color = gtk.gdk.color_parse("dark red")
+ self.messages.get_model().insert(self.last_message, [time.strftime("\n<b>%H:%M:%S</b>\n"), _("\n<b>Se ha detenido inhesperadamente el servidor.</b>\n"), color])
+ self.last_message += 1
+
+ return True
+
+ def __get_x11vnc_path(self):
+ system = platform.machine()
+ color = gtk.gdk.color_parse("dark red")
+ if os.path.exists("/usr/bin/x11vnc"):
+ self.path = "/usr/bin/x11vnc"
+ message = _("PATH: %s") % self.path
else:
- conf.add_section('terminal')
+ if "arm" in system:
+ self.path = os.path.join(activity.get_bundle_path(), "bin", "arm", "x11vnc")
+ os.environ["LD_LIBRARY_PATH"] = self.path.replace("x11vnc", "lib/")
+ elif "64" in system:
+ self.path = os.path.join(activity.get_bundle_path(), "bin", "x64", "x11vnc")
+ os.environ["LD_LIBRARY_PATH"] = self.path.replace("x11vnc", "lib/")
+ else:
+ self.path = os.path.join(activity.get_bundle_path(), "bin", "i586", "x11vnc")
+ os.environ["LD_LIBRARY_PATH"] = self.path.replace("x11vnc", "lib/")
+ message = _("PATH: %s") % self.path
+
+ self.messages.get_model().insert(self.last_message, [time.strftime("\n<b>%H:%M:%S</b>\n"), "<b>" + message + "</b>", color])
+ self.last_message += 1
+
+ def __start_vnc(self, widget):
- if conf.has_option('terminal', 'font'):
- font = conf.get('terminal', 'font')
- else:
- font = 'Monospace 8'
- conf.set('terminal', 'font', font)
- self.set_font(pango.FontDescription(font))
+ def servidor():
+ commands.getoutput(self.path)
+ Thread(target=servidor).start()
- if conf.has_option('terminal', 'fg_color'):
- fg_color = conf.get('terminal', 'fg_color')
- else:
- fg_color = '#000000'
- conf.set('terminal', 'fg_color', fg_color)
- if conf.has_option('terminal', 'bg_color'):
- bg_color = conf.get('terminal', 'bg_color')
+ if not self.showed_message_start:
+ self.showed_message_start = True
+ pass
else:
- bg_color = '#FFFFFF'
- conf.set('terminal', 'bg_color', bg_color)
- self.set_colors(gtk.gdk.color_parse (fg_color),
- gtk.gdk.color_parse (bg_color),
- [])
-
- if conf.has_option('terminal', 'cursor_blink'):
- blink = conf.getboolean('terminal', 'cursor_blink')
+ return
+
+ self.showed_message_stop = False
+ self.isrunning = True
+ color = gtk.gdk.color_parse("green")
+ self.messages.get_model().insert(self.last_message, [time.strftime("\n<b>%H:%M:%S</b>\n"), _("\n<b>Se inició el servidor VNC</b>\n"), color])
+ self.last_message += 1
+
+ def __stop_vnc(self, widget):
+
+ if not self.showed_message_stop:
+ self.showed_message_stop = True
+ pass
else:
- blink = False
- conf.set('terminal', 'cursor_blink', blink)
-
- self.set_cursor_blinks(blink)
+ return
- if conf.has_option('terminal', 'bell'):
- bell = conf.getboolean('terminal', 'bell')
- else:
- bell = False
- conf.set('terminal', 'bell', bell)
- self.set_audible_bell(bell)
+ self.showed_message_start = False
+ self.pid_nuevo = commands.getoutput("pidof x11vnc")
+ color = gtk.gdk.color_parse('red')
+
+ os.system("kill " + self.pid_nuevo)
- if conf.has_option('terminal', 'scrollback_lines'):
- scrollback_lines = conf.getint('terminal', 'scrollback_lines')
+ self.messages.get_model().insert(self.last_message, [time.strftime("\n<b>%H:%M:%S</b>\n"), _("\n<b>El servidor VNC está ahora detenido.</b>\n"), color])
+ self.last_message += 1
+
+
+ def close(self):
+ pid = commands.getoutput("pidof x11vnc")
+ commands.getoutput("kill " + pid)
+ self.destroy()
+
+ def __get_ip(self, widget):
+ system = platform.platform()
+ if "olpc" in system:
+ target = "eth0"
else:
- scrollback_lines = 1000
- conf.set('terminal', 'scrollback_lines', scrollback_lines)
-
- self.set_scrollback_lines(scrollback_lines)
- self.set_allow_bold(True)
+ target = "wlan0"
- if conf.has_option('terminal', 'scroll_on_keystroke'):
- scroll_key = conf.getboolean('terminal', 'scroll_on_keystroke')
- else:
- scroll_key = False
- conf.set('terminal', 'scroll_on_keystroke', scroll_key)
- self.set_scroll_on_keystroke(scroll_key)
-
- if conf.has_option('terminal', 'scroll_on_output'):
- scroll_output = conf.getboolean('terminal', 'scroll_on_output')
+ ifconfig = "/sbin/ifconfig"
+ cmd = "%s %s" % (ifconfig, target)
+ output = commands.getoutput(cmd)
+ error = _("Sin conexión inalámbrica.")
+ ip = error
+ inet = output.find('inet')
+ if inet >= 0:
+ start = inet + len('inet')
+ end = output.find(" ",start + 1)
+ ip = output[start:end]
else:
- scroll_output = False
- conf.set('terminal', 'scroll_on_output', scroll_output)
- self.set_scroll_on_output(scroll_output)
+ ip = error
- if conf.has_option('terminal', 'emulation'):
- emulation = conf.get('terminal', 'emulation')
- else:
- emulation = 'xterm'
- conf.set('terminal', 'emulation', emulation)
- self.set_emulation(emulation)
-
- if conf.has_option('terminal', 'visible_bell'):
- visible_bell = conf.getboolean('terminal', 'visible_bell')
+ ip = ip.replace(":", "")
+ if error == "Sin conexión inalámbrica.":
+ mensaje = error
else:
- visible_bell = False
- conf.set('terminal', 'visible_bell', visible_bell)
- self.set_visible_bell(visible_bell)
- conf.write(open(conf_file, 'w'))
-
- def on_gconf_notification(self, client, cnxn_id, entry, what):
- self.reconfigure_vte()
-
- def on_vte_button_press(self, term, event):
- if event.button == 3:
- self.do_popup(event)
- return True
-
- def on_vte_popup_menu(self, term):
- pass
+ mensaje = "IP: " + ip
+ color = gtk.gdk.color_parse("dark blue")
+ self.messages.get_model().insert(self.last_message, [time.strftime("\n<b>%H:%M:%S</b>\n"), "\n<b>" + mensaje + "</b>\n", color])
+
+ self.last_message += 1