1 | #!/usr/bin/env python3 |
---|
2 | |
---|
3 | # http://candidtim.github.io/appindicator/2014/09/13/ubuntu-appindicator-step-by-step.html |
---|
4 | # Menus: http://zetcode.com/gui/pygtk/ |
---|
5 | |
---|
6 | import os |
---|
7 | import gi |
---|
8 | gi.require_version("Gtk", "3.0") |
---|
9 | gi.require_version("WebKit", "3.0") |
---|
10 | import subprocess |
---|
11 | from gi.repository import Gtk |
---|
12 | from gi.repository import GdkPixbuf |
---|
13 | gi.require_version("AppIndicator3", "0.1") |
---|
14 | from gi.repository import AppIndicator3 as appindicator |
---|
15 | import iniparse |
---|
16 | from appdirs import * |
---|
17 | |
---|
18 | import gettext |
---|
19 | gettext.textdomain('lliurex-connect') |
---|
20 | _ = gettext.gettext |
---|
21 | |
---|
22 | |
---|
23 | class connectionAssistant: |
---|
24 | def __init__(self): |
---|
25 | self.APPINDICATOR_ID = 'myappindicator' |
---|
26 | self.ManagedConnection=None |
---|
27 | pass |
---|
28 | |
---|
29 | def main(self): |
---|
30 | indicator = appindicator.Indicator.new(self.APPINDICATOR_ID, os.path.abspath('img/tabletllxcon.png'), appindicator.IndicatorCategory.SYSTEM_SERVICES) |
---|
31 | indicator.set_status(appindicator.IndicatorStatus.ACTIVE) |
---|
32 | indicator.set_menu(self.build_menu()) |
---|
33 | Gtk.main() |
---|
34 | pass |
---|
35 | |
---|
36 | |
---|
37 | def checkNWManaged(self): |
---|
38 | with open("/etc/NetworkManager/NetworkManager.conf",'r') as fin: |
---|
39 | for line in fin: |
---|
40 | if (line.find("managed=true")!=-1): |
---|
41 | return True; |
---|
42 | return False |
---|
43 | |
---|
44 | |
---|
45 | def createStaticMenuOption(self, image, label, cb): |
---|
46 | |
---|
47 | pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale( |
---|
48 | filename=os.path.abspath(image), |
---|
49 | width=16, |
---|
50 | height=16, |
---|
51 | preserve_aspect_ratio=True) |
---|
52 | |
---|
53 | img=Gtk.Image.new_from_pixbuf(pixbuf) |
---|
54 | |
---|
55 | item=Gtk.ImageMenuItem() |
---|
56 | item.set_image(img) |
---|
57 | item.set_label(label) |
---|
58 | item.set_always_show_image(True) |
---|
59 | |
---|
60 | item.connect('activate', cb) |
---|
61 | return item |
---|
62 | pass; |
---|
63 | |
---|
64 | def build_menu(self): |
---|
65 | menu=Gtk.Menu() |
---|
66 | |
---|
67 | # Item 1: Enable/Disable wifi |
---|
68 | |
---|
69 | self.ManagedConnection=self.checkNWManaged(); |
---|
70 | if (self.ManagedConnection): |
---|
71 | item1Text=_("Disable Wireless Management"); |
---|
72 | icon="img/wifion.png"; |
---|
73 | else: |
---|
74 | item1Text=_("Enable Wireless Management"); |
---|
75 | icon="img/wifioff.png"; |
---|
76 | |
---|
77 | |
---|
78 | item1=self.createStaticMenuOption(icon, item1Text, self.cbSetupWifi); |
---|
79 | menu.append(item1) |
---|
80 | |
---|
81 | item2=self.createStaticMenuOption('img/mirror.png', _("Mirror Android on this computer"), self.cbMirror); |
---|
82 | menu.append(item2) |
---|
83 | |
---|
84 | item3=self.createStaticMenuOption('img/xsdl.png', _("Launch Application into Android XSDL Server"), self.cbXSDL); |
---|
85 | menu.append(item3) |
---|
86 | |
---|
87 | itemquit=self.createStaticMenuOption('img/quit.png', _("Quit"), self.quit); |
---|
88 | menu.append(itemquit) |
---|
89 | |
---|
90 | menu.show_all() |
---|
91 | return menu |
---|
92 | |
---|
93 | def cbSetupWifi(self, widget): |
---|
94 | self.ManagedConnection=self.checkNWManaged() |
---|
95 | if (self.ManagedConnection): |
---|
96 | command='gksudo ManageWifi.sh false'; |
---|
97 | else: |
---|
98 | command='gksudo ManageWifi.sh true'; |
---|
99 | |
---|
100 | proc = subprocess.Popen([command], shell=True, stdout=subprocess.PIPE) |
---|
101 | (out, err) = proc.communicate() |
---|
102 | '''print "out:" |
---|
103 | print out |
---|
104 | print "err:" |
---|
105 | print err''' |
---|
106 | |
---|
107 | # Set up |
---|
108 | self.ManagedConnection=self.checkNWManaged(); |
---|
109 | if (self.ManagedConnection): |
---|
110 | self.set_label(_("Disable Wireless Management")); |
---|
111 | icon="img/wifion.png"; |
---|
112 | pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale( |
---|
113 | filename=os.path.abspath(icon), |
---|
114 | width=16, |
---|
115 | height=16, |
---|
116 | preserve_aspect_ratio=True); |
---|
117 | img=Gtk.Image.new_from_pixbuf(pixbuf) |
---|
118 | self.set_image(img); |
---|
119 | |
---|
120 | else: |
---|
121 | self.set_label(_("Enable Wireless Management")); |
---|
122 | icon="img/wifioff.png"; |
---|
123 | pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale( |
---|
124 | filename=os.path.abspath(icon), |
---|
125 | width=16, |
---|
126 | height=16, |
---|
127 | preserve_aspect_ratio=True); |
---|
128 | img=Gtk.Image.new_from_pixbuf(pixbuf) |
---|
129 | self.set_image(img); |
---|
130 | |
---|
131 | pass |
---|
132 | |
---|
133 | def cbMirror(self, widget): |
---|
134 | command="exec /opt/google/chrome/chrome --profile-directory=Default --app-id=hjbljnpdahefgnopeohlaeohgkiidnoe"; |
---|
135 | proc = subprocess.Popen([command], shell=True, stdout=subprocess.PIPE) |
---|
136 | #(out, err) = proc.communicate() |
---|
137 | #print "out" |
---|
138 | #print out |
---|
139 | #print "err" |
---|
140 | #print err |
---|
141 | pass |
---|
142 | |
---|
143 | def cbXSDL(self, widget): |
---|
144 | command="/usr/bin/xserver.sh"; |
---|
145 | proc = subprocess.Popen([command], shell=True, stdout=subprocess.PIPE) |
---|
146 | (out, err) = proc.communicate() |
---|
147 | '''print "out" |
---|
148 | print out |
---|
149 | print "err" |
---|
150 | print err''' |
---|
151 | pass |
---|
152 | |
---|
153 | def checkHelp(self): |
---|
154 | # requires python3-appdirs |
---|
155 | # requires python3-iniparse |
---|
156 | configfile=user_config_dir("lliurex-connect")+"/config.ini"; |
---|
157 | Config=iniparse.ConfigParser(); |
---|
158 | |
---|
159 | try: |
---|
160 | print ("Reading "+str(configfile)); |
---|
161 | Config.read(configfile); |
---|
162 | showConfig=Config.get("main", "ShowAlways") |
---|
163 | |
---|
164 | except Exception as e: |
---|
165 | print ("Exception..."); |
---|
166 | showConfig='True' |
---|
167 | |
---|
168 | print ("showCongif is "+str(showConfig)); |
---|
169 | |
---|
170 | if (showConfig=='True'): |
---|
171 | #os.system("./splash.py") |
---|
172 | os.system("/usr/share/lliurex-connect/splash.py") |
---|
173 | pass |
---|
174 | |
---|
175 | def quit(self, self2): |
---|
176 | Gtk.main_quit() |
---|
177 | pass |
---|
178 | |
---|
179 | |
---|
180 | if __name__ == "__main__": |
---|
181 | app=connectionAssistant() |
---|
182 | app.checkHelp(); |
---|
183 | app.main(); |
---|
184 | |
---|
185 | |
---|
186 | |
---|
187 | |
---|