diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..0146a5f --- /dev/null +++ b/.flake8 @@ -0,0 +1,6 @@ +[flake8] + +# E402 module level import not at top of file +# gi.require_version() is required before later imports + +ignore = E402 diff --git a/README.md b/README.md index 212d884..56b7488 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,56 @@ What is this? ============= -This activity helps you broadcast your screen to another computer. It will automatically launch a VNC server (X11vnc) and display your IP address. You can then connect and view the screen of Sugar on another conmputer using any VNC client (e.g. TigerVNC, UltraVNC Viewer, RealVNC, etc). +This activity helps you broadcast your screen to another computer. It will automatically launch a VNC server (X11vnc) and display your IP address. You can then connect and view the screen of Sugar on another conmputer using any VNC client (e.g. TigerVNC, UltraVNC Viewer, RealVNC, TightVNC etc). + VncLauncher is not part of the Sugar desktop, but can be added. Please refer to; + +* [How to Get Sugar on sugarlabs.org](https://sugarlabs.org/), +* [How to use Sugar](https://help.sugarlabs.org/), + +VncLauncher depends on Python, [Sugar +Toolkit](https://github.com/sugarlabs/sugar-toolkit-gtk3), GTK+ 3, Pango, Vte and x11vnc. + How to use? =========== - VncLauncher is not part of the Sugar desktop, but can be added. Please refer to; +* Firstly, make sure your Sugar is connected to the wireless network or mesh network. You can also find the network information at the bottom of the screen inside Sugar. +* Select VncLauncher Activity to start the activity. +* Click at “Please Click to find the current IP address” to see your current IP address. +* VncLauncher depends on x11vnc, Please follow details given below _(How to install dependencies?)_ to install x11vnc. Also an alternate way to install x11vnc is to click OK ,which can be seen in dialog box after clicking on “Start X11 VNC Server”. Click “Start X11 VNC Server” to start your Sugar as a server so that your PC can connect to your Sugar. +* Click “Stop X11 VNC Server” or Exit VNC Launcher Activity, when you want to disconnect sugar from your PC. But “Exit VNC Launcher Activity” will close down the Activity. The Stop button will only stop connection and allow you to start the connection anytime. +* In your PC, select the viewer program, Viewer programs which supports VncLauncher are TigerVNC, UltraVNC Viewer, RealVNC and TightVNC. You can also follow "_How to install vncviewer?_" to install RealVNC. +* Enter your Sugar's ip address and click Connect. (Note***, Make sure your PC connect to the same network as the Sugar) . + +How to install dependencies? +=========================================== + +Install the x11vnc + +* Update the package index, + - On Ubuntu/Debian systems, run + ```sudo apt update``` + - On Fedora systems, run + ```sudo dnf update``` +* Install `x11vnc`, + - On Ubuntu/Debian systems, run + ```sudo apt install x11vnc``` + - On Fedora systems, run + ```sudo dnf install x11vnc``` + + +How to install vncviewer? +=========================================== + +Install RealVNC + +* [Download VNC Viewer](https://www.realvnc.com/en/connect/download/viewer/linux/) +* Install the VNC Viewer program: + - Open a Terminal. + - Change directory to the download location, e.g. cd ~/Downloads + - Run one of the following commands, depending on your version of Linux + - ```sudo apt install ./``` # Ubuntu/Debian + - ```sudo yum install -y ``` # Fedora + - Sign in using your RealVNC account credentials. You should see the remote computer appear in your team. + - Click or tap to connect. You are prompted to authenticate to VNC Server. -* [How to Get Sugar on sugarlabs.org](https://sugarlabs.org/), -* [How to use Sugar](https://help.sugarlabs.org/), -* [How to use VncLauncher](http://wiki.laptop.org/go/VNC_Launcher) diff --git a/activity/activity.info b/activity/activity.info index b595144..dc5298a 100755 --- a/activity/activity.info +++ b/activity/activity.info @@ -2,6 +2,6 @@ name = VncLauncher activity_version = 7 bundle_id = org.laptop.VncLauncher -exec = sugar-activity vnclauncher.VncLauncherActivity +exec = sugar-activity3 vnclauncher.VncLauncherActivity icon = activity-vnclauncher summary = With this activity you can show the content of your screen on other computers using the VNC protocol. diff --git a/bin/arm/lib/libminilzo.so.0 b/bin/arm/lib/libminilzo.so.0 deleted file mode 100755 index d02c5c9..0000000 Binary files a/bin/arm/lib/libminilzo.so.0 and /dev/null differ diff --git a/bin/arm/lib/libvncclient.so.0 b/bin/arm/lib/libvncclient.so.0 deleted file mode 100755 index 2673441..0000000 Binary files a/bin/arm/lib/libvncclient.so.0 and /dev/null differ diff --git a/bin/arm/lib/libvncserver.so.0 b/bin/arm/lib/libvncserver.so.0 deleted file mode 100755 index afd5e44..0000000 Binary files a/bin/arm/lib/libvncserver.so.0 and /dev/null differ diff --git a/bin/arm/x11vnc b/bin/arm/x11vnc deleted file mode 100755 index b49a8e5..0000000 Binary files a/bin/arm/x11vnc and /dev/null differ diff --git a/bin/x86-64/lib/libgcrypt.so.20 b/bin/x86-64/lib/libgcrypt.so.20 deleted file mode 100644 index 7c1f048..0000000 Binary files a/bin/x86-64/lib/libgcrypt.so.20 and /dev/null differ diff --git a/bin/x86-64/lib/libjpeg.so.8 b/bin/x86-64/lib/libjpeg.so.8 deleted file mode 100644 index 634cbf9..0000000 Binary files a/bin/x86-64/lib/libjpeg.so.8 and /dev/null differ diff --git a/bin/x86-64/lib/libvncclient.so.0 b/bin/x86-64/lib/libvncclient.so.0 deleted file mode 100644 index f753ef9..0000000 Binary files a/bin/x86-64/lib/libvncclient.so.0 and /dev/null differ diff --git a/bin/x86-64/lib/libvncserver.so.0 b/bin/x86-64/lib/libvncserver.so.0 deleted file mode 100644 index c41bb22..0000000 Binary files a/bin/x86-64/lib/libvncserver.so.0 and /dev/null differ diff --git a/bin/x86-64/x11vnc b/bin/x86-64/x11vnc deleted file mode 100755 index 87af96c..0000000 Binary files a/bin/x86-64/x11vnc and /dev/null differ diff --git a/bin/x86/README b/bin/x86/README deleted file mode 100644 index 4f7e6ce..0000000 --- a/bin/x86/README +++ /dev/null @@ -1,3 +0,0 @@ -The package for this x11vnc binary was broken due to dependency on Xvfb. -The package Xvfb is not available, then I removed that dependency and recompiled the rpm. -The spec file is here for reference. diff --git a/bin/x86/lib/libgnutls.so.26 b/bin/x86/lib/libgnutls.so.26 deleted file mode 100755 index 0cb93e6..0000000 Binary files a/bin/x86/lib/libgnutls.so.26 and /dev/null differ diff --git a/bin/x86/lib/libminilzo.so.0 b/bin/x86/lib/libminilzo.so.0 deleted file mode 100755 index 7564c96..0000000 Binary files a/bin/x86/lib/libminilzo.so.0 and /dev/null differ diff --git a/bin/x86/lib/libtasn1.so.3 b/bin/x86/lib/libtasn1.so.3 deleted file mode 100755 index 4eea58f..0000000 Binary files a/bin/x86/lib/libtasn1.so.3 and /dev/null differ diff --git a/bin/x86/lib/libvncclient.so.0 b/bin/x86/lib/libvncclient.so.0 deleted file mode 100755 index 279244d..0000000 Binary files a/bin/x86/lib/libvncclient.so.0 and /dev/null differ diff --git a/bin/x86/lib/libvncserver.so.0 b/bin/x86/lib/libvncserver.so.0 deleted file mode 100755 index 97070e9..0000000 Binary files a/bin/x86/lib/libvncserver.so.0 and /dev/null differ diff --git a/bin/x86/x11vnc b/bin/x86/x11vnc deleted file mode 100755 index 96f7aaa..0000000 Binary files a/bin/x86/x11vnc and /dev/null differ diff --git a/bin/x86/x11vnc.spec b/bin/x86/x11vnc.spec deleted file mode 100644 index 0181eae..0000000 --- a/bin/x86/x11vnc.spec +++ /dev/null @@ -1,274 +0,0 @@ -Summary: VNC server for the current X11 session -Summary(ru): VNC-сервер для текущей сессии X11 -Name: x11vnc -Version: 0.9.13 -Release: 3%{?dist} -License: GPLv2 -Group: User Interface/X -URL: http://www.karlrunge.com/x11vnc/ -Source0: http://downloads.sourceforge.net/libvncserver/%{name}-%{version}.tar.gz - -BuildRequires: libjpeg-devel, zlib-devel, openssl-devel -BuildRequires: xorg-x11-proto-devel, libXext-devel, libXtst-devel -BuildRequires: libXfixes-devel, libvncserver-devel - - - -# In Fedora 12 /usr/include/X11/extensions/XInput.h in libXi-devel but in -# previous versions in xorg-x11-proto-devel /usr/include/X11/extensions/shmproto.h -# placed in libXext-devel in F12 and in xorg-x11-proto-devel early. -%if 0%{?fedora} > 11 -BuildRequires: libXi-devel libXext-devel -%else -BuildRequires: xorg-x11-proto-devel -%endif -#Requires: xorg-x11-server-Xvfb - -# Fedora don't want hardcoded rpaths. -Patch1: x11vnc-0.9.8-disableRpath.patch - -# Package intended to EL-5 too, so we still need define BuildRoot -BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) - -%description -What WinVNC is to Windows x11vnc is to X Window System, i.e. a server -which serves the current X Window System desktop via RFB (VNC) -protocol to the user. - -Based on the ideas of x0rfbserver and on LibVNCServer it has evolved into a -versatile and productive while still easy to use program. - -%description -l ru -Это подобно VNC-серверу под Windows - VNC-сервер, который предоставля- -ет доступ к текущей X-сессии пользователя по протоколу (VNC). -Таким образом, Вы всегда можете вернуться к работе удаленно, даже если -сессия была стандартно запущена локально. Более того, доступ к Логин- -менеджеру также может быть осуществлена (GDM, KDM, XDM etc) - -Базируется на идее x0rfbserver и LibVNCServer x11vnc эволюционировал -в гибкий и производительный инструмент, который, однако, остается -просто в использовании. - -# Required java not available on EL-5.ppc -%if ! ( (%{_arch}==ppc && 5 == 0%{?rhel}) || (%{_arch}==ppc64 && 6 == 0%{?rhel}) ) -%package javaviewers -Version: %{version} -Summary: VNC clients (browser java applets) -Summary(ru): VNC-клиенты в виде java-аплетов для браузеров -Requires: %{name} = %{version}-%{release} -License: GPLv2+ -Group: User Interface/X -# EL-5 does not support noarch subpackages ( https://fedorahosted.org/fedora-infrastructure/ticket/1772#comment:4 ) -%if 0%{?fedora} > 9 || 0%{?rhel} > 5 -BuildArch: noarch -%endif -BuildRequires: java-devel >= 1:1.6.0 -BuildRequires: jpackage-utils - -%description javaviewers -The package contains the corresponding java clients for %{name}. They -can be used with any java-enabled browser and provide an easy access to -the server without the need to install software on the client machine. - -%description -l ru javaviewers -Java-клиенты для использования совместно с %{name} прямо из браузера -без необходимости ставить какой бы то ни было софт. - -Должно по идее работать с любым современным браузером, где есть -поддержка Java -%endif # EL.ppc - -%prep -%setup -q -%patch1 -p0 -b .rpath - -# fix source perms for the -debuginfo package rpmlint warnings -find -name "*.c" -o -name "*.h" -exec %{__chmod} 0644 {} \; - -for file in README AUTHORS; do - # ISO-8859-1 is my assumption. - iconv -f ISO-8859-1 -t UTF-8 "$file" > "$file.new" - touch --reference "$file" "$file.new" - mv "$file.new" "$file" -done - -# Delete prebuilt binaries -find -name '*.jar' -exec rm {} \; - -%build -%configure --with-system-libvncserver --without-tightvnc-filetransfer - -%if ! ( (%{_arch}==ppc && 5 == 0%{?rhel}) || (%{_arch}==ppc64 && 6 == 0%{?rhel}) ) -# First rebuild jars, what have been removed in %%prep. -pushd classes/ssl/src -%{__make} %{?_smp_mflags} - # Alternative to patch Makefiles. - for jarfile in *.jar; do - %{__ln_s} src/$jarfile ../; - %{__ln_s} ssl/src/$jarfile ../../; - done -popd -%else -%{__rm} -rf classes -sed -ri 's/(DUST_)?SUBDIRS = x11vnc classes/\1SUBDIRS = x11vnc/' Makefile -%endif - -%{__make} %{?_smp_mflags} - -%install -%{__rm} -rf %{buildroot} -%{__make} install DESTDIR="%{buildroot}" - -%if ! ( (%{_arch}==ppc && 5 == 0%{?rhel}) || (%{_arch}==ppc64 && 6 == 0%{?rhel}) ) -# And Java viewers -pushd classes/ssl -%{__make} install DESTDIR="%{buildroot}" -popd - -# Rename README file to avoid name bump -%{__mv} classes/ssl/src/tight/README classes/ssl/src/tight/README.tight -%{__mv} classes/ssl/src/ultra/README classes/ssl/src/ultra/README.ultra -%endif - -%clean -%{__rm} -rf %{buildroot} - -%files -%defattr(-,root,root,-) -%doc AUTHORS ChangeLog COPYING NEWS README TODO -%{_mandir}/man1/x11vnc.1* -%{_bindir}/x11vnc -%{_datadir}/applications/x11vnc.desktop - -%if ! ( (%{_arch}==ppc && 5 == 0%{?rhel}) || (%{_arch}==ppc64 && 6 == 0%{?rhel}) ) -%files javaviewers -%defattr(-,root,root,-) -%doc classes/ssl/README classes/ssl/src/tight/README.tight classes/ssl/src/ultra/README.ultra -%{_datadir}/%{name} -%exclude %{_datadir}/%{name}/classes/ssl/README -%endif - -%changelog -* Fri Feb 17 2012 Deepak Bhole 0.9.13-3 -- Resolves rhbz#794475 -- Patch from Omair Majid to remove explicit Java 6 req. - -* Sat Jan 14 2012 Fedora Release Engineering - 0.9.13-2 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_17_Mass_Rebuild - -* Sun Dec 11 2011 Pavel Alexeev - 0.9.13-1 -- Update to 0.9.13 version (asked in bz#669780) -- Drop x11vnc-0.9.8-XShm-explicit-include.patch - -* Mon Feb 07 2011 Fedora Release Engineering - 0.9.12-18 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_15_Mass_Rebuild - -* Tue Jan 18 2011 Pavel Alexeev - 0.9.12-17 -- Update to last version 0.9.12 with hope it fix BZ#646694 and by request BZ#666612 -- Change java related exclusion to El6 too. - -* Sun Nov 1 2009 Pavel Alexeev - 0.9.8-16 -- Noarch subpackage became only on Fedora - ( https://fedorahosted.org/fedora-infrastructure/ticket/1772#comment:4 ) -- Also -javaviewers subpackage compleatly disabled on PPC arch on EL-5 because - there no java-devel >= 1:1.6.0 and java-1.6.0-openjdk-devel. - ( https://fedorahosted.org/fedora-infrastructure/ticket/1772#comment:4 ) - -* Tue Oct 6 2009 Pavel Alexeev - 0.9.8-14 -- Make -javaviewers subpackage noarch. - -* Sun Oct 4 2009 Pavel Alexeev - 0.9.8-13 -- Small fis requires release. -- Rename README file to avoid name bump - -* Fri Sep 25 2009 Pavel Alexeev - 0.9.8-12 -- Own %%{_datadir}/%%{name} instead of %%{_datadir}/%%{name}/classes -- Add Requires: %%{name} = %%{version}-%%{release} in subpackage. -- Change summary and description for javaviewers subpackage. -- Remove %%doc marker from man-page. -- %%defattr(-,root,root,0755) -> %%defattr(-,root,root,-) -- Add classes/ssl/src/tight/README classes/ssl/src/ultra/README files into - javaviewers subpackage %%doc (thank you Orcan Ogetbil) -- ln -s replaced by %%{__ln_s} -- Set License: GPLv2+ for javaviewers subpackage (Thanks Spot) - -* Mon Aug 31 2009 Pavel Alexeev - 0.9.8-11 -- Remove all prebuilt *.jar-files in %%prep section and try build it from source. -- Add BR java-1.6.0-openjdk-devel -- Introduce new subpackage x11vnc-javaviewers. -- Add separate build java-viewers. -- Add Russian localized versions of Summary and descrioptions. - -* Wed Aug 26 2009 Pavel Alexeev - 0.9.8-10 -- Fix some spelling, change some cosmetic things. -- Delete Patch0 and hacks to link with system lzo package - it is not needed - anymore as we link it with systel libvncserver instead. -- Delete BR lzo-devel -- Remiove empty directory %%{_datadir}/%%{name}/ - -* Sun Aug 9 2009 Pavel Alexeev - 0.9.8-9 -- Add Requires: Xvfb - -* Fri Aug 7 2009 Pavel Alexeev - 0.9.8-8 -- Link to shared lzo instead of minilzo for all (not only EL-5). -- Add BuildRequires: /usr/include/X11/extensions/XShm.h -- Patch2: x11vnc-0.9.8-XShm-explicit-include.patch -- Step to conditional BR for Fedora 12, add - Patch2: x11vnc-0.9.8-XShm-explicit-include.patch to build on it. - -* Tue Aug 4 2009 Pavel Alexeev - 0.9.8-7 -- Change license to GPLv2 without plus according to x11vnc.c - source (thanks to Christian Krause). -- For consistency macros usage replace "ln -s" by %%{__ln_s}, - mv by %%{__mv} and similar (chmod, sed). -- Change find call to avoid using xargs in chmod sources command. - -* Wed Jul 29 2009 Pavel Alexeev - 0.9.8-6 -- Build with openssl unconditionally. -- Add Patch1: x11vnc-0.9.8-disableRpath.patch -- fix source perms for the -debuginfo package rpmlint warnings - -* Tue Jul 21 2009 Pavel Alexeev - 0.9.8-5 -- Try use lzo instead of minilzo in EL-5 (minilzo is not bundled in it). -- Try use system libvncserver library (--with-system-libvncserver - configure option) instead of bundled one. -- System libvncserver built without tightvnc-filetransfer support. - Now disable it there (--without-filetransfer) - And according to it change License to only GPLv2+ - ./configure --help misleading, using --without-tightvnc-filetransfer - -* Tue Jul 21 2009 Pavel Alexeev - 0.9.8-4 -- All changes inspired by started Fedora Review (thank you to Christian Krause). -- README and AUTHORS files converted into UTF-8. -- Explicit mention previous author in changelog and delet old entries of it. -- Source renamed to Source0. -- Source0 URL changed to long (correct) variant: - http://downloads.sourceforge.net/libvncserver/%%{name}-%%{version}.tar.gz - was http://dl.sf.net/libvncserver/x11vnc-%%{version}.tar.gz -- Add BR: /usr/include/X11/extensions/XInput.h; In F12 it is located in - libXi-devel but in previous versions in xorg-x11-proto-devel - so, to do not make conditional requires, require explicit file. -- Remove prebuild binaries clients. -- Remove Requires: minilzo it will be automatically propogated. -- Add BR: libvncserver-devel - -* Fri Jul 10 2009 Pavel Alexeev - 0.9.8-3 -- Add BR openssl-devel to provide SSL capability (thanks Manuel Wolfshant). -- Requires: minilzo, BR lzo-devel and Patch0: - 11vnc-0.9.8-use-system-minilzo.patch to use system version of library. -- Add "and GPLv2" to License. See comment above why. -- Add BuildRequires: libXfixes-devel - -* Fri Jul 10 2009 Pavel Alexeev - 0.9.8-2 -- Import http://packages.sw.be/x11vnc/x11vnc-0.9.7-1.rf.src.rpm to maintain it in fedora: - Packager: Dag Wieers - Vendor: Dag Apt Repository, http://dag.wieers.com/apt/ -- Step to version 0.9.8 -- Reformat spec with tabs. -- Comment out (leave for history) Packager and Vendor tags -- Remove defines of several macros like dtag, conditional _without_modxorg -- Remove all stuff around conditional build _without_modxorg -- Add -%%(%%{__id_u} -n) part into buildroot. -- Make setup quiet. -- Remove "rf" Release suffix and replace it by %%{?dist} -- License from GPL changed to GPLv2+ diff --git a/setup.py b/setup.py index 95a687c..61a2f86 100755 --- a/setup.py +++ b/setup.py @@ -16,5 +16,5 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -from sugar.activity import bundlebuilder -bundlebuilder.start('VncLauncher') +from sugar3.activity import bundlebuilder +bundlebuilder.start() diff --git a/vnclauncher.py b/vnclauncher.py index e39111d..7aa829c 100755 --- a/vnclauncher.py +++ b/vnclauncher.py @@ -15,11 +15,14 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +import sys import os - +import gi import logging from gettext import gettext as _ - +gi.require_version('Gtk', '3.0') +gi.require_version('Vte', '2.91') +gi.require_version('Gdk', '3.0') from gi.repository import Gtk from gi.repository import Gdk from gi.repository import GLib @@ -29,40 +32,52 @@ from sugar3.activity import activity from sugar3 import env -import ConfigParser +import configparser import os.path -import platform -from jarabe.model import network import struct -import socket +import platform +import subprocess +_NM_SERVICE = 'org.freedesktop.NetworkManager' +_NM_IFACE = 'org.freedesktop.NetworkManager' +_NM_PATH = '/org/freedesktop/NetworkManager' +_NM_DEVICE_IFACE = 'org.freedesktop.NetworkManager.Device' class VncLauncherActivity(activity.Activity): def _ipaddr_(self, button): self.ipbutton = button - button.set_label('Please Click to find current IP address \n\n' + - 'Error!! check connection') - bus = dbus.SystemBus() - obj = bus.get_object(network.NM_SERVICE, network.NM_PATH) - netmgr = dbus.Interface(obj, network.NM_IFACE) - netmgr.GetDevices(reply_handler=self.__get_devices_reply_cb, - error_handler=self.__get_devices_error_cb) - - def __get_devices_reply_cb(self, devices): - bus = dbus.SystemBus() - for device_op in devices: - device = bus.get_object(network.NM_SERVICE, device_op) - device_props = dbus.Interface(device, dbus.PROPERTIES_IFACE) - ip_address = device_props.Get( - network.NM_DEVICE_IFACE, 'Ip4Address') - ipaddr = socket.inet_ntoa(struct.pack('I', ip_address)) - if ipaddr != "0.0.0.0" and ipaddr != "127.0.0.1": + RetMyIPs = subprocess.check_output(['hostname', '-s', '-I']).decode('utf-8')[:-1] + myhostname = subprocess.check_output(['hostname']).decode('utf-8') + total_IPs = RetMyIPs.split() + IPs = "\n".join(total_IPs) + if RetMyIPs != "0.0.0.0" and RetMyIPs != "127.0.0.1": + logging.debug("Found IP Addresses") + dialog = Gtk.MessageDialog( + transient_for=self, + flags=0, + message_type=Gtk.MessageType.INFO, + buttons=Gtk.ButtonsType.OK, + text="IP Addresses" + ) + dialog.format_secondary_text( + IPs + '\n\n'+ + "Your Hostname is " + myhostname + ) + response = dialog.run() + + if response == Gtk.ResponseType.OK: + logging.debug("Got IP Addresses") self.ipbutton.set_label( - 'Please Click to find current IP address \n\nIP=' + ipaddr) + 'Please Click to find current IP address') + dialog.destroy() + + else: + self.ipbutton.set_label( + 'Please Click to find current IP address \n\n' + + 'Error!! check connection' + ) - def __get_devices_error_cb(self, err): - pass def __init__(self, handle): activity.Activity.__init__(self, handle) @@ -103,38 +118,49 @@ def __init__(self, handle): self._vte = VTE() self._vte.show() + self._vte.connect("child-exited", self._quit_cb) box.pack_start(self._vte, True, True, 0) box.pack_start(table, False, False, 0) self.set_canvas(box) box.show() + self._vte.grab_focus() + + def _quit_cb(self, vte, data=None): + sys.exit(0) def stopVNC(self, button): cmd = "\x03" # Ctrl+C - self._vte.feed_child(cmd, -1) + self._vte.feed_child(cmd.encode('utf-8')) 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): - logging.error('Using x11vnc installed in the system') + logging.debug('Using x11vnc installed in the system') + self._vte.feed_child(cmd.encode('utf-8')) else: - # check platform - if platform.machine().startswith('arm'): - path = os.path.join(activity.get_bundle_path(), 'bin/arm') - else: - if platform.architecture()[0] == '64bit': - path = os.path.join(activity.get_bundle_path(), - 'bin/x86-64') - else: - path = os.path.join(activity.get_bundle_path(), 'bin/x86') - self._vte.feed_child( - "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:%s/lib\n" % path, -1) - cmd = os.path.join(path, 'x11vnc') + "\n" - logging.error('Using %s', cmd) - self._vte.feed_child(cmd, -1) + dialog = Gtk.MessageDialog( + transient_for=self, + flags=0, + message_type=Gtk.MessageType.INFO, + buttons=Gtk.ButtonsType.OK, + text="x11vnc is not installed" + ) + dialog.format_secondary_text( + "Install x11vnc by clicking on OK" + ) + response = dialog.run() + + if response == Gtk.ResponseType.OK: + logging.debug("Installing x11vnc") + if platform.version().find("Ubuntu") > -1 or platform.version().find("Debian") > -1: + cmd = "apt install x11vnc" + if platform.platform().find("Fedora") > -1: + cmd = "dnf install x11vnc" + self._vte.feed_child(cmd.encode('utf-8')) + dialog.destroy() def __key_press_cb(self, window, event): return False @@ -144,16 +170,8 @@ class VTE(Vte.Terminal): def __init__(self): Vte.Terminal.__init__(self) - self._configure_vte() - if hasattr(Vte.Terminal, "spawn_sync"): - self.connect("child-exited", lambda term: term.spawn_sync( - Vte.PtyFlags.DEFAULT, os.environ["HOME"], ["/bin/bash"], [], - GLib.SpawnFlags.DO_NOT_REAP_CHILD, None, None)) - else: - self.connect("child-exited", lambda term: term.fork_full_command( - Vte.PtyFlags.DEFAULT, os.environ["HOME"], ["/bin/bash"], [], - GLib.SpawnFlags.DO_NOT_REAP_CHILD, None, None)) - + self.configure_terminal() + os.chdir(os.environ["HOME"]) if hasattr(Vte.Terminal, "spawn_sync"): self.spawn_sync( @@ -174,8 +192,13 @@ def __init__(self): None, None) - def _configure_vte(self): - conf = ConfigParser.ConfigParser() + def color_parse(self, color): + rgba = Gdk.RGBA() + rgba.parse(color) + return rgba + + def configure_terminal(self): + conf = configparser.ConfigParser() conf_file = os.path.join(env.get_profile_path(), 'terminalrc') if os.path.isfile(conf_file): @@ -202,61 +225,63 @@ def _configure_vte(self): else: bg_color = '#FFFFFF' conf.set('terminal', 'bg_color', bg_color) - self.set_colors(Gdk.color_parse(fg_color), - Gdk.color_parse(bg_color), - []) + + self.set_colors(self.color_parse(bg_color), + self.color_parse(fg_color), []) if conf.has_option('terminal', 'cursor_blink'): blink = conf.getboolean('terminal', 'cursor_blink') else: - blink = False + blink = 'False' conf.set('terminal', 'cursor_blink', blink) - + blink = Vte.CursorBlinkMode(0) if blink == 'False' else Vte.CursorBlinkMode(1) self.set_cursor_blink_mode(blink) if conf.has_option('terminal', 'bell'): bell = conf.getboolean('terminal', 'bell') else: - bell = False + bell = 'False' conf.set('terminal', 'bell', bell) self.set_audible_bell(bell) if conf.has_option('terminal', 'scrollback_lines'): scrollback_lines = conf.getint('terminal', 'scrollback_lines') else: - scrollback_lines = 1000 + scrollback_lines = '1000' conf.set('terminal', 'scrollback_lines', scrollback_lines) - self.set_scrollback_lines(scrollback_lines) + self.set_scrollback_lines(int(scrollback_lines)) self.set_allow_bold(True) if conf.has_option('terminal', 'scroll_on_keystroke'): scroll_key = conf.getboolean('terminal', 'scroll_on_keystroke') else: - scroll_key = False + 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') else: - scroll_output = False + scroll_output = 'False' conf.set('terminal', 'scroll_on_output', scroll_output) self.set_scroll_on_output(scroll_output) - if conf.has_option('terminal', 'emulation'): - emulation = conf.get('terminal', 'emulation') - else: - emulation = 'xterm' - conf.set('terminal', 'emulation', emulation) - self.set_emulation(emulation) + if hasattr(self, 'set_emulation'): + 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') - else: - visible_bell = False - conf.set('terminal', 'visible_bell', visible_bell) - self.set_visible_bell(visible_bell) + if hasattr(self, 'set_visible_bell'): + if conf.has_option('terminal', 'visible_bell'): + visible_bell = conf.getboolean('terminal', 'visible_bell') + 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):