diff options
Diffstat (limited to 'vnclauncher.py')
-rwxr-xr-x | vnclauncher.py | 97 |
1 files changed, 56 insertions, 41 deletions
diff --git a/vnclauncher.py b/vnclauncher.py index 8c8b8eb..bea74ff 100755 --- a/vnclauncher.py +++ b/vnclauncher.py @@ -56,8 +56,7 @@ class VncLauncherActivity(activity.Activity): self.get_ipbutton = ToolButton(icon_name="get_ip", tooltip=_("Get the current IP")) - - + ## self.messages = gtk.TreeView() self.messages.set_rules_hint(True) @@ -65,20 +64,21 @@ class VncLauncherActivity(activity.Activity): self.messages.set_model(modelo) render = gtk.CellRendererText() render1 = gtk.CellRendererText() - + column1 = gtk.TreeViewColumn(_("Hour"), render, markup=0) - column2 = gtk.TreeViewColumn(_("Message"), render1, markup=1) - column1.add_attribute(render, 'foreground-gdk', 2) - column2.add_attribute(render1, 'foreground-gdk', 2) - - + column2 = gtk.TreeViewColumn(_("Message"), render1, markup=1) + column1.add_attribute(render, 'foreground-gdk', 2) + column2.add_attribute(render1, 'foreground-gdk', 2) + 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>Start of activity.</b>\n"), color]) + modelo.insert(0, [time.strftime("\n<b>%H:%M:%S</b>\n"), + _("\n<b>Start of activity.</b>\n"), color]) self.showed_message_stop = True self.showed_message_start = False + self.isrunning = True self.stop_vnc.connect("clicked", self.__stop_vnc) self.start_vnc.connect("clicked", self.__start_vnc) @@ -95,7 +95,7 @@ class VncLauncherActivity(activity.Activity): 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) @@ -105,9 +105,10 @@ class VncLauncherActivity(activity.Activity): 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.set_policy(gtk.POLICY_AUTOMATIC, + gtk.POLICY_AUTOMATIC) self.messages_scroll.add_with_viewport(self.messages) self.set_toolbar_box(self.toolbarbox) @@ -115,21 +116,24 @@ class VncLauncherActivity(activity.Activity): 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 == "": + if self.start_vnc.get_active() and pid == "" and self.isrunning: 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>It has stopped unexpectedly the server..</b>\n"), color]) + self.messages.get_model().insert(self.last_message, + [time.strftime("\n<b>%H:%M:%S</b>\n"), + ("\n<b>It has stopped unexpectedly the server..</b>\n"), + color]) self.last_message += 1 return True - + def __get_x11vnc_path(self): system = platform.machine() color = gtk.gdk.color_parse("dark red") @@ -138,19 +142,23 @@ class VncLauncherActivity(activity.Activity): message = _("PATH: %s") % self.path else: 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/") + self.path = os.path.join(activity.get_bundle_path(), + "bin", "arm", "x11vnc") 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/") + self.path = os.path.join(activity.get_bundle_path(), + "bin", "x64", "x11vnc") else: - self.path = os.path.join(activity.get_bundle_path(), "bin", "i586", "x11vnc") - os.environ["LD_LIBRARY_PATH"] = self.path.replace("x11vnc", "lib/") + 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.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): def servidor(): @@ -166,11 +174,13 @@ class VncLauncherActivity(activity.Activity): 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>VNC server is started</b>\n"), color]) + self.messages.get_model().insert(self.last_message, + [time.strftime("\n<b>%H:%M:%S</b>\n"), + ("\n<b>VNC server is started</b>\n"), color]) self.last_message += 1 - + def __stop_vnc(self, widget): - + if not self.showed_message_stop: self.showed_message_stop = True pass @@ -182,23 +192,26 @@ class VncLauncherActivity(activity.Activity): color = gtk.gdk.color_parse('red') os.system("kill " + self.pid_nuevo) - - self.messages.get_model().insert(self.last_message, [time.strftime("\n<b>%H:%M:%S</b>\n"), _("\n<b>The VNC server is now stopped.</b>\n"), color]) + + self.messages.get_model().insert(self.last_message, + [time.strftime("\n<b>%H:%M:%S</b>\n"), + ("\n<b>The VNC server is now stopped.</b>\n"), + color]) self.last_message += 1 - - + def close(self): + self.isrunning = False pid = commands.getoutput("pidof x11vnc") - commands.getoutput("kill " + pid) + os.system("kill " + pid) self.destroy() - + def __get_ip(self, widget): system = platform.platform() if "olpc" in system: target = "eth0" else: target = "wlan0" - + ifconfig = "/sbin/ifconfig" cmd = "%s %s" % (ifconfig, target) output = commands.getoutput(cmd) @@ -207,17 +220,19 @@ class VncLauncherActivity(activity.Activity): inet = output.find('inet') if inet >= 0: start = inet + len('inet') - end = output.find(" ",start + 1) + end = output.find(" ", start + 1) ip = output[start:end] else: ip = error - - ip = ip.replace(":", "") + + ip = ip.replace(":", "") if error == _("No wireless connection."): mensaje = error else: - mensaje = "IP: " + ip + 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.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 |