source: lliurex-connect/trunk/fuentes/lliurex-connect/usr/share/lliurex-connect/splash.py @ 5140

Last change on this file since 5140 was 5140, checked in by joamuran, 4 years ago

wip

  • Property svn:executable set to *
File size: 6.0 KB
Line 
1#!/usr/bin/env python3
2import gi
3import os
4import apt
5import subprocess
6gi.require_version('Gtk', '3.0')
7gi.require_version("WebKit", "3.0")
8from gi.repository import Gtk, Gdk, Pango, WebKit, Gio
9import webbrowser
10import iniparse
11from appdirs import *
12
13import gettext
14gettext.textdomain('lliurex-connect')
15_ = gettext.gettext
16
17
18class Splash(Gtk.Window):
19
20    def setTogled(self, widget, data=None):
21        if(self.active==True):
22            self.active=False
23        else:
24            self.active=True;
25           
26        #print("self active is"+str(self.active));
27        pass
28       
29
30    def __init__(self, checked):
31        Gtk.Window.__init__(self, title="splashtitle")
32        #print (checked);
33        # Set check status
34        self.active=False;
35        self.chromeInstalled=False;
36       
37        if (checked=="True"):
38            self.active=True;
39           
40        # Is google chrome installed
41        cache=apt.Cache()
42        self.chromeInstalled=cache['google-chrome-stable'].is_installed
43                       
44       
45        # Creating main container       
46        container = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
47        container.set_border_width(10)
48        self.add(container)
49       
50        #Create Webkit view
51       
52        self.view = WebKit.WebView();
53        self.view.open(os.path.abspath("help/info.html"));
54        self.view.connect('navigation-policy-decision-requested', self.on_nav_request)
55        self.view.connect('load-finished', self._finished_loading)
56        #view.connect("navigation-requested", self.on_click_link)
57       
58        # Create Message "Don't show in the future"
59        row = Gtk.ListBoxRow()
60        hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50)
61        label = Gtk.Label("Do not show this message", xalign=0)
62        check = Gtk.CheckButton()
63        check.set_active(self.active)
64        check.connect("toggled", self.setTogled, "check button")
65        hbox.pack_start(check, False, True, 0)
66        hbox.pack_start(label, True, True, 0)
67        row.add(hbox)
68       
69        # Create Close Button
70        buttonClose = Gtk.Button(label="Close")
71        buttonClose.connect("clicked", self.quit);
72        hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50)
73        hbox.pack_end(buttonClose, False, True, 0);
74       
75        container.add(self.view);
76        container.add(row);
77        container.add(hbox);
78
79        #view.execute_script("$('#info').html('%s')" % "Pajaritos tralari");
80       
81        #view.execute_script('tralari()');
82       
83    #def on_click_link(self, view, frame, request):
84    #   print("Mavigation change requested")
85    #   #self.webview.get_back_forward_list().clear()
86    #   return False
87    #    pass
88   
89    def _finished_loading(self, webview, webfame):
90        description=_("LliureX Connect is a suite of tools to achieve the connection between tablet and your LliureX computer. For the mirroring capabilities, you need an Chrome extension called AllCast Receicer.");
91        google_desc=_("You need Google Chrome to use Mirroring capabilities in this computer. Press the following link to download Google Chrome.");
92        google_link=_("Download Chrome");
93        allcast_desc=_("Allcast Receiver is a Google Chrome App to receive video streaming from an Android Device through Recording and Mirroring App.");
94        allcast_link=_("Download AllCast Receiver");
95        mirroring_desc=_("Screen Recording and Mirror allows you to send video streaming to AllCast Receiver Google Chrome app.");
96        mirroring_link=_("Go to app Screen Recording and Mirror in Google Play");
97        xserver_desc=_("XDSL Server is a Linux graphical server for your Android device. It alloys you to launch any application in yout system and see it in your device.");
98        xserver_link=_("Go to app X Server for Android in Google Play");
99   
100        parameters='"'+description+'","'+google_desc+'","'+google_link+'","'+allcast_desc+'","'+allcast_link+'","'+mirroring_desc+'","'+mirroring_link+'","'+xserver_desc+'","'+xserver_link+'"';
101       
102        print (parameters);
103       
104        self.view.execute_script('populateText('+parameters+')');
105        pass
106   
107    def on_nav_request(self, view, frame, request, action, policy, data=None):
108       
109        # Loading URL in Firefox
110        url = request.get_uri()
111       
112        browser="firefox ";
113        if (self.chromeInstalled):
114            browser="/opt/google/chrome/google-chrome ";
115       
116        command=browser+url;
117   
118        proc = subprocess.Popen([command], shell=True, stdout=subprocess.PIPE)
119        (out, err) = proc.communicate()
120       
121       
122        policy.ignore()
123       
124   
125   
126
127    def quit(self, self2):
128   
129        configdir=user_config_dir("lliurex-connect");
130        if not os.path.exists(configdir):
131            os.makedirs(configdir)
132   
133        configfile=configdir+"/config.ini";
134       
135        Config=iniparse.ConfigParser();
136        Config.add_section('main')
137        Config.set("main", "ShowAlways", str(self.active))
138        with open(configfile, "w") as configfile:
139            Config.write(configfile);
140       
141        Gtk.main_quit()
142        pass
143
144
145        ''' ids del info.html...
146        info
147        mirror_description
148        mirrror_app_link
149       
150        xsdl_description
151        xsdl_app_link'''
152
153
154def checkConfigFile():
155    configfile=user_config_dir("lliurex-connect")+"/config.ini";
156    Config=iniparse.ConfigParser();
157       
158    try:
159      Config.read(configfile);
160      showConfig=Config.get("main", "ShowAlways")
161      #print(showConfig);
162    except Exception as e:
163      #print ("Exception...");
164      showConfig='True'
165       
166    #print ("showCongif is "+str(showConfig));
167    return showConfig
168       
169    pass
170   
171
172def splashwindow():
173    checked=checkConfigFile()
174    #print (checked);
175    window = Splash(checked)
176    window.set_size_request(640, 480);
177    window.set_decorated(False)
178    window.set_resizable(False)
179    window.set_position(Gtk.WindowPosition.CENTER)
180    window.connect("delete-event", Gtk.main_quit)
181    window.show_all()
182    Gtk.main()
183
184splashwindow()
185
186
Note: See TracBrowser for help on using the repository browser.