1 | #!/usr/bin/env python |
---|
2 | # -*- coding: utf-8 -* |
---|
3 | |
---|
4 | |
---|
5 | import os |
---|
6 | import multiprocessing |
---|
7 | import time |
---|
8 | import random |
---|
9 | import xmlrpclib |
---|
10 | import cairo |
---|
11 | import grp |
---|
12 | import sys |
---|
13 | import subprocess |
---|
14 | import json |
---|
15 | |
---|
16 | try: |
---|
17 | import gi |
---|
18 | gi.require_version('Gtk', '3.0') |
---|
19 | gi.require_version('PangoCairo', '1.0') |
---|
20 | from gi.repository import Gtk, Gdk, GObject, GLib, PangoCairo, Pango |
---|
21 | |
---|
22 | except Exception as e: |
---|
23 | print e |
---|
24 | #zero-server-wizard initialization forces me to do this |
---|
25 | |
---|
26 | import signal |
---|
27 | signal.signal(signal.SIGINT, signal.SIG_DFL) |
---|
28 | |
---|
29 | import gettext |
---|
30 | gettext.textdomain('zero-center') |
---|
31 | _ = gettext.gettext |
---|
32 | |
---|
33 | |
---|
34 | BAR_HEIGHT=90 |
---|
35 | CONF_X=5 |
---|
36 | |
---|
37 | if os.path.exists("/home/lliurex/banners/"): |
---|
38 | BANNER_PATH="/home/lliurex/banners/" |
---|
39 | else: |
---|
40 | BANNER_PATH="/usr/share/banners/lliurex-neu/" |
---|
41 | |
---|
42 | |
---|
43 | class CategoriesParser: |
---|
44 | |
---|
45 | CATEGORIES_PATH="/usr/share/zero-center/categories/" |
---|
46 | |
---|
47 | def __init__(self): |
---|
48 | |
---|
49 | self.parse_categories() |
---|
50 | |
---|
51 | #def init |
---|
52 | |
---|
53 | def parse_categories(self,path=None): |
---|
54 | |
---|
55 | self.categories=[] |
---|
56 | |
---|
57 | if path==None: |
---|
58 | path=self.CATEGORIES_PATH |
---|
59 | |
---|
60 | for item in os.listdir(path): |
---|
61 | file_path=path+item |
---|
62 | |
---|
63 | f=open(file_path) |
---|
64 | lines=f.readlines() |
---|
65 | f.close() |
---|
66 | |
---|
67 | cat={} |
---|
68 | |
---|
69 | for line in lines: |
---|
70 | key,value=line.split("=") |
---|
71 | cat[key]=value.strip("\n") |
---|
72 | if key=="level": |
---|
73 | cat[key]=int(cat[key]) |
---|
74 | |
---|
75 | self.categories.append(cat) |
---|
76 | |
---|
77 | tmp=[] |
---|
78 | |
---|
79 | while len(self.categories)>0: |
---|
80 | selected_index=0 |
---|
81 | index=0 |
---|
82 | level=0 |
---|
83 | for item in self.categories: |
---|
84 | if item["level"]>level: |
---|
85 | level=item["level"] |
---|
86 | selected_index=index |
---|
87 | |
---|
88 | |
---|
89 | index+=1 |
---|
90 | |
---|
91 | tmp.append(self.categories[selected_index]) |
---|
92 | self.categories.pop(selected_index) |
---|
93 | |
---|
94 | self.categories=tmp |
---|
95 | |
---|
96 | #def parse_categories |
---|
97 | |
---|
98 | |
---|
99 | #class CategoriesParser |
---|
100 | |
---|
101 | |
---|
102 | class AppParser: |
---|
103 | |
---|
104 | BASE_DIR="/usr/share/zero-center/" |
---|
105 | APP_PATH=BASE_DIR+"applications/" |
---|
106 | ZMD_PATH=BASE_DIR+"zmds/" |
---|
107 | |
---|
108 | |
---|
109 | def __init__(self): |
---|
110 | |
---|
111 | self.categories=["ID","Name","Comment","Icon","Category","Icon","ScriptPath","Groups","Service","Locks"] |
---|
112 | self.apps={} |
---|
113 | self.app_list=[] |
---|
114 | self.configured=[] |
---|
115 | #print("[ZeroCenter] Parsing apps...") |
---|
116 | self.parse_all() |
---|
117 | |
---|
118 | #def init |
---|
119 | |
---|
120 | |
---|
121 | def add_app(self,app): |
---|
122 | |
---|
123 | try: |
---|
124 | if app["Category"].lower() not in self.apps: |
---|
125 | self.apps[app["Category"].lower()]=[] |
---|
126 | |
---|
127 | self.apps[app["Category"].lower()].append(app) |
---|
128 | self.app_list.append(app["ID"]) |
---|
129 | except: |
---|
130 | pass |
---|
131 | |
---|
132 | #def add_app |
---|
133 | |
---|
134 | def parse_all(self,dir=None): |
---|
135 | |
---|
136 | if dir==None: |
---|
137 | dir=self.APP_PATH |
---|
138 | |
---|
139 | for item in os.listdir(dir): |
---|
140 | file_path=self.APP_PATH+item |
---|
141 | app=self.parse_file(file_path) |
---|
142 | self.add_app(app) |
---|
143 | |
---|
144 | #def parse_all |
---|
145 | |
---|
146 | |
---|
147 | def parse_file(self,file_path): |
---|
148 | |
---|
149 | f=open(file_path) |
---|
150 | lines=f.readlines() |
---|
151 | f.close() |
---|
152 | id=file_path.split("/")[-1].split(".")[0] |
---|
153 | app={} |
---|
154 | for item in lines: |
---|
155 | try: |
---|
156 | key,value=item.split("=") |
---|
157 | app[key]=value.strip("\n") |
---|
158 | except: |
---|
159 | pass |
---|
160 | |
---|
161 | app["ID"]=id |
---|
162 | app["configured"]=-1 |
---|
163 | app["custom_msg"]="" |
---|
164 | |
---|
165 | app["bar_height"]=BAR_HEIGHT |
---|
166 | app["conf_alpha"]=1.0 |
---|
167 | |
---|
168 | |
---|
169 | app["expanding"]=False |
---|
170 | app["restoring"]=False |
---|
171 | |
---|
172 | return app |
---|
173 | |
---|
174 | #def parse_file |
---|
175 | |
---|
176 | |
---|
177 | #class AppParser |
---|
178 | |
---|
179 | |
---|
180 | class ZeroCenter: |
---|
181 | |
---|
182 | def __init__(self): |
---|
183 | |
---|
184 | self.client=xmlrpclib.ServerProxy("https://localhost:9779") |
---|
185 | self.create_user_env() |
---|
186 | self.categories_parser=CategoriesParser() |
---|
187 | self.app_parser=AppParser() |
---|
188 | self.configured_apps=[] |
---|
189 | self.get_states() |
---|
190 | |
---|
191 | self.mprocess=multiprocessing.Process() |
---|
192 | self.commands=["set-configured","set-non-configured","set-failed","set-custom-text","add-zero-center-notification","remove-zero-center-notification","help","add-pulsating-color","remove-pulsating-color","non-animated","animated"] |
---|
193 | self.drawing_mode=True |
---|
194 | self.msg_text="" |
---|
195 | self.msg_x=0 |
---|
196 | self.scrolling=False |
---|
197 | |
---|
198 | try: |
---|
199 | self.msg_text=self.client.get_zc_messages("","ZCenterVariables",self.lang) |
---|
200 | if self.msg_text=="": |
---|
201 | txt=self.client.lliurex_version("","LliurexVersion") |
---|
202 | if type(txt)==type([]): |
---|
203 | self.msg_text=str(txt[1]) |
---|
204 | else: |
---|
205 | f=open("/etc/lsb-release") |
---|
206 | lines=f.readlines() |
---|
207 | f.close() |
---|
208 | for line in lines: |
---|
209 | if "DISTRIB_DESCRIPTION" in line: |
---|
210 | self.msg_text=line.split("=")[1] |
---|
211 | #Load slave_blacklist |
---|
212 | self.blacklist=self.client.get_variable("","VariablesManager","SLAVE_BLACKLIST") |
---|
213 | |
---|
214 | except: |
---|
215 | self.msg_text="" |
---|
216 | |
---|
217 | #self.msg_text="hi, i'm a long enough text so that it won't show in just one line. I wonder how many lines I can get inside the box. In my restless dreams I see that town, Silent Hill. I don't know what to type, but I have to keep typing" |
---|
218 | #57 |
---|
219 | |
---|
220 | #def init |
---|
221 | |
---|
222 | |
---|
223 | def get_states(self): |
---|
224 | |
---|
225 | try: |
---|
226 | var=self.client.get_all_states("","ZCenterVariables") |
---|
227 | except: |
---|
228 | local_path="/var/lib/n4d/variables-dir/ZEROCENTER" |
---|
229 | if os.path.exists(local_path): |
---|
230 | f=open(local_path) |
---|
231 | var=json.load(f)["ZEROCENTER"]["value"] |
---|
232 | f.close() |
---|
233 | else: |
---|
234 | var={} |
---|
235 | |
---|
236 | try: |
---|
237 | for cat in self.app_parser.apps: |
---|
238 | |
---|
239 | for app in self.app_parser.apps[cat]: |
---|
240 | app["configured"]=0 |
---|
241 | |
---|
242 | if app["ID"] in var: |
---|
243 | for key in ["state","pulsating","time","custom_text"]: |
---|
244 | if key in var[app["ID"]]: |
---|
245 | app[key]=var[app["ID"]][key] |
---|
246 | |
---|
247 | |
---|
248 | if "state" in app: |
---|
249 | app["configured"]=app["state"] |
---|
250 | |
---|
251 | if app["configured"]==1: |
---|
252 | self.configured_apps.append(app["ID"]) |
---|
253 | |
---|
254 | |
---|
255 | except Exception as e: |
---|
256 | print e |
---|
257 | pass |
---|
258 | |
---|
259 | #def get_states |
---|
260 | |
---|
261 | |
---|
262 | def get_translation(self,text): |
---|
263 | |
---|
264 | for category in self.categories_parser.categories: |
---|
265 | |
---|
266 | if text.lower()==category["name"].lower(): |
---|
267 | for lang in self.language: |
---|
268 | try: |
---|
269 | return category["name["+lang+"]"] |
---|
270 | except Exception as e: |
---|
271 | pass |
---|
272 | return category["name"] |
---|
273 | |
---|
274 | return text |
---|
275 | |
---|
276 | #def get_translation |
---|
277 | |
---|
278 | |
---|
279 | def get_name(self,app): |
---|
280 | |
---|
281 | for lang in self.language: |
---|
282 | try: |
---|
283 | return app["Name["+lang+"]"] |
---|
284 | except: |
---|
285 | pass |
---|
286 | |
---|
287 | return app["Name"] |
---|
288 | |
---|
289 | #def get_name |
---|
290 | |
---|
291 | |
---|
292 | def get_comment(self,app): |
---|
293 | |
---|
294 | for lang in self.language: |
---|
295 | try: |
---|
296 | return app["Comment["+lang+"]"] |
---|
297 | except: |
---|
298 | pass |
---|
299 | |
---|
300 | return app["Comment"] |
---|
301 | |
---|
302 | #def get_name |
---|
303 | |
---|
304 | |
---|
305 | def create_user_env(self): |
---|
306 | |
---|
307 | try: |
---|
308 | self.lang=os.environ["LANGUAGE"].replace(".UTF-8","").split(":")[0] |
---|
309 | self.language=os.environ["LANGUAGE"].replace(".UTF-8","").split(":") |
---|
310 | if "es_ES" in self.language and "es" not in self.language: |
---|
311 | self.language.insert(self.language.index("es_ES")+1,"es") |
---|
312 | self.lang=self.lang.split("_")[0] |
---|
313 | |
---|
314 | if "ca_ES@valencia" in self.language: |
---|
315 | self.language.insert(self.language.index("ca_ES@valencia"),"qcv") |
---|
316 | except: |
---|
317 | try: |
---|
318 | self.lang=os.environ["LANG"].replace(".UTF-8","") |
---|
319 | self.language=[] |
---|
320 | self.language.append(self.lang) |
---|
321 | self.lang=self.lang.split("_")[0] |
---|
322 | |
---|
323 | except: |
---|
324 | self.lang="en" |
---|
325 | |
---|
326 | |
---|
327 | groups={} |
---|
328 | |
---|
329 | for item in grp.getgrall(): |
---|
330 | if len(item.gr_mem)>0: |
---|
331 | if item.gr_name not in groups: |
---|
332 | groups[item.gr_name]=item.gr_mem |
---|
333 | else: |
---|
334 | groups[item.gr_name]=list(groups[item.gr_name]+item.gr_mem) |
---|
335 | |
---|
336 | |
---|
337 | self.user_groups=[] |
---|
338 | try: |
---|
339 | for item in groups: |
---|
340 | if os.environ["USER"] in groups[item]: |
---|
341 | self.user_groups.append(item) |
---|
342 | |
---|
343 | self.user_groups.append("*") |
---|
344 | except: |
---|
345 | pass |
---|
346 | |
---|
347 | #def create_user_area |
---|
348 | |
---|
349 | |
---|
350 | def start_gui(self): |
---|
351 | |
---|
352 | |
---|
353 | self.icon_theme=Gtk.IconTheme() |
---|
354 | self.icon_theme.set_custom_theme("lliurex-neu") |
---|
355 | |
---|
356 | builder=Gtk.Builder() |
---|
357 | if os.path.exists("/srv/svn/pandora/zero-center2/install-files/usr/share/zero-center/rsrc/zero-center.glade"): |
---|
358 | builder.add_from_file("/srv/svn/pandora/zero-center2/install-files/usr/share/zero-center/rsrc/zero-center.glade") |
---|
359 | else: |
---|
360 | builder.add_from_file("/usr/share/zero-center/rsrc/zero-center.glade") |
---|
361 | self.window=builder.get_object("window1") |
---|
362 | self.window.connect("delete_event",self.close_window) |
---|
363 | self.window.set_name("BLACK") |
---|
364 | self.buttons_vbox=builder.get_object("buttons_vbox") |
---|
365 | self.content_hbox=builder.get_object("main_box") |
---|
366 | self.content_hbox.override_background_color(Gtk.StateType.NORMAL, Gdk.RGBA(0.2,0.2,0.2,1)) |
---|
367 | self.window_box=builder.get_object("window_box") |
---|
368 | self.viewport=builder.get_object("viewport1") |
---|
369 | self.viewport.set_name("ORANGE") |
---|
370 | self.category_combobox=builder.get_object("category_combobox") |
---|
371 | self.msg_label=builder.get_object("llx_label") |
---|
372 | self.msg_label.connect("draw",self.drawing_label_event) |
---|
373 | self.msg_label.set_tooltip_text(self.msg_text) |
---|
374 | |
---|
375 | self.progress_bar=builder.get_object("progressbar") |
---|
376 | self.progress_label=builder.get_object("progress_label") |
---|
377 | self.progress_label.set_name("WHITE") |
---|
378 | |
---|
379 | self.add_categories_to_window("All") |
---|
380 | self.set_css_info() |
---|
381 | |
---|
382 | self.window.show() |
---|
383 | GObject.threads_init() |
---|
384 | Gtk.main() |
---|
385 | |
---|
386 | #def start_gui |
---|
387 | |
---|
388 | |
---|
389 | def scroll_me(self,img): |
---|
390 | |
---|
391 | if self.msg_x > (self.scroll_width)*-1: |
---|
392 | self.msg_x-=1 |
---|
393 | else: |
---|
394 | self.msg_x=401 |
---|
395 | img.queue_draw() |
---|
396 | return self.scrolling |
---|
397 | |
---|
398 | #def scroll_me |
---|
399 | |
---|
400 | |
---|
401 | def set_msg_label_text(self,txt): |
---|
402 | |
---|
403 | self.msg_text=txt |
---|
404 | self.msg_label.queue_draw() |
---|
405 | |
---|
406 | #def set_msg_label_text() |
---|
407 | |
---|
408 | |
---|
409 | def drawing_label_event(self,widget,ctx): |
---|
410 | |
---|
411 | lg1 = cairo.LinearGradient(0.0,18.0, 400.0, 18.0) |
---|
412 | lg1.add_color_stop_rgba(0, 0.38, 0.38, 0.38, 1) |
---|
413 | lg1.add_color_stop_rgba(0.1, 0.2, 0.2, 0.2, 1) |
---|
414 | lg1.add_color_stop_rgba(0.9, 0.2, 0.2, 0.2, 1) |
---|
415 | lg1.add_color_stop_rgba(1, 0.38, 0.38, 0.38, 1) |
---|
416 | ctx.rectangle(0, 0, 400, 18) |
---|
417 | ctx.set_source(lg1) |
---|
418 | ctx.fill() |
---|
419 | |
---|
420 | tmp_text=self.msg_text |
---|
421 | |
---|
422 | if len(tmp_text)>66: |
---|
423 | if self.drawing_mode: |
---|
424 | if not self.scrolling: |
---|
425 | self.scrolling=True |
---|
426 | self.msg_x=200 |
---|
427 | GLib.timeout_add(12,self.scroll_me,widget) |
---|
428 | else: |
---|
429 | tmp_text=tmp_text[:63] |
---|
430 | tmp_text=" " + tmp_text+u" …" |
---|
431 | else: |
---|
432 | self.scrolling=False |
---|
433 | spaces=90-len(tmp_text) |
---|
434 | space="".join([" "]*(spaces/2)) |
---|
435 | tmp_text=space+tmp_text+space |
---|
436 | |
---|
437 | |
---|
438 | |
---|
439 | tmp_text=tmp_text.replace("[","<b>[") |
---|
440 | tmp_text=tmp_text.replace("]","] </b>") |
---|
441 | |
---|
442 | x=self.msg_x |
---|
443 | pctx = PangoCairo.create_layout(ctx) |
---|
444 | desc = Pango.font_description_from_string ("Ubuntu 9") |
---|
445 | pctx.set_font_description(desc) |
---|
446 | ctx.set_source_rgb(0.9,0.9,0.9) |
---|
447 | pctx.set_markup(tmp_text) |
---|
448 | self.scroll_width=pctx.get_pixel_size()[0] |
---|
449 | ctx.move_to(x,0) |
---|
450 | PangoCairo.show_layout(ctx, pctx) |
---|
451 | |
---|
452 | #def set_msg_label |
---|
453 | |
---|
454 | |
---|
455 | def set_css_info(self): |
---|
456 | |
---|
457 | css = """ |
---|
458 | |
---|
459 | #BLACK { |
---|
460 | background-image: -gtk-gradient (linear, left top, left bottom, from (#1a1a1a), to (#616161)); |
---|
461 | |
---|
462 | } |
---|
463 | |
---|
464 | #ORANGE { |
---|
465 | background-image: -gtk-gradient (linear, left top, left bottom, from (#575757), to (#373737)); |
---|
466 | |
---|
467 | } |
---|
468 | |
---|
469 | #BLACKEXPANDER { |
---|
470 | background-image: -gtk-gradient (linear, left top, left bottom, from (#1a1a1a), to (#1a1a1a)); |
---|
471 | color: white; |
---|
472 | box-shadow: 50px 50px; |
---|
473 | |
---|
474 | } |
---|
475 | |
---|
476 | #WHITE { |
---|
477 | color: white; |
---|
478 | text-shadow: 0px 1px black; |
---|
479 | } |
---|
480 | |
---|
481 | #WHITE-15 { |
---|
482 | color: white; |
---|
483 | font-size: 15px; |
---|
484 | text-shadow: 1px 2px black; |
---|
485 | } |
---|
486 | |
---|
487 | |
---|
488 | #BLACKBUTTON{ |
---|
489 | background-image: -gtk-gradient (linear, left top, left bottom, from (#2a2a2a), to (#616161)); |
---|
490 | color: #e0e0e0; |
---|
491 | border-color: #000; |
---|
492 | border-style: none; |
---|
493 | border-radius: 10px; |
---|
494 | |
---|
495 | } |
---|
496 | |
---|
497 | |
---|
498 | |
---|
499 | #APPBUTTON{ |
---|
500 | |
---|
501 | padding: 0px 0px; |
---|
502 | border:none; |
---|
503 | background-image: none; |
---|
504 | box-shadow: none; |
---|
505 | background-color: transparent; |
---|
506 | box-shadow: 0px 2px 5px rgba(0,0,0,0.8); |
---|
507 | |
---|
508 | } |
---|
509 | |
---|
510 | #APPBUTTON:hover{ |
---|
511 | |
---|
512 | |
---|
513 | border-width: 0; |
---|
514 | border-radius: 0px; |
---|
515 | border-color: transparent; |
---|
516 | border: none; |
---|
517 | box-shadow: 0px 1px 8px rgba(0,0,0,1); |
---|
518 | } |
---|
519 | |
---|
520 | GtkSeparator { |
---|
521 | color: rgba(255,255,255,0.8); |
---|
522 | } |
---|
523 | |
---|
524 | """ |
---|
525 | |
---|
526 | self.style_provider=Gtk.CssProvider() |
---|
527 | self.style_provider.load_from_data(css) |
---|
528 | |
---|
529 | Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(),self.style_provider,Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) |
---|
530 | |
---|
531 | #def set_css_info |
---|
532 | |
---|
533 | |
---|
534 | def get_banner_image(self,app): |
---|
535 | |
---|
536 | package_rsrc_path=BANNER_PATH |
---|
537 | img_path=package_rsrc_path+"package.png" |
---|
538 | |
---|
539 | for item in os.listdir(package_rsrc_path): |
---|
540 | f,ext=item.split(".") |
---|
541 | if app["Icon"] == f: |
---|
542 | img_path=package_rsrc_path+item |
---|
543 | |
---|
544 | |
---|
545 | img=cairo.ImageSurface.create_from_png(img_path) |
---|
546 | ctx=cairo.Context(img) |
---|
547 | |
---|
548 | if not self.check_app_dependences(app): |
---|
549 | ctx.set_source_rgba(0.5,0.5,0.5,0.7) |
---|
550 | ctx.rectangle(0,0,235,110) |
---|
551 | ctx.fill() |
---|
552 | |
---|
553 | |
---|
554 | ctx.set_source_rgba(0,0,0,0.8) |
---|
555 | ctx.rectangle(0,90,235,110) |
---|
556 | ctx.fill() |
---|
557 | |
---|
558 | |
---|
559 | show_status=True |
---|
560 | if "Depends" in app: |
---|
561 | |
---|
562 | if not self.check_app_dependences(app): |
---|
563 | |
---|
564 | lg1 = cairo.LinearGradient(0.0,110.0, 200.0, 110.0) |
---|
565 | lg1.add_color_stop_rgba(0, 0.7, 0, 0, 1) |
---|
566 | lg1.add_color_stop_rgba(1, 1, 0.2, 0.2, 0) |
---|
567 | ctx.rectangle(0, 0, 200, 20) |
---|
568 | ctx.set_source(lg1) |
---|
569 | ctx.fill() |
---|
570 | |
---|
571 | ctx.select_font_face("Ubuntu") |
---|
572 | ctx.set_font_size(15) |
---|
573 | ctx.move_to(5,15) |
---|
574 | ctx.set_source_rgba(1,1,1,app["conf_alpha"]) |
---|
575 | |
---|
576 | ctx.show_text(_("Unmet dependences")) |
---|
577 | ctx.stroke() |
---|
578 | |
---|
579 | show_status=False |
---|
580 | |
---|
581 | |
---|
582 | if "Service" in app and show_status: |
---|
583 | |
---|
584 | if app["Service"].lower()=="true": |
---|
585 | |
---|
586 | if app["configured"]==1: |
---|
587 | |
---|
588 | lg1 = cairo.LinearGradient(0.0,110.0, 200.0, 110.0) |
---|
589 | |
---|
590 | lg1.add_color_stop_rgba(0, 0, 0.2, 0, 1) |
---|
591 | lg1.add_color_stop_rgba(1, 0, 1, 0, 0) |
---|
592 | ctx.rectangle(0, 0, 200, 20) |
---|
593 | ctx.set_source(lg1) |
---|
594 | ctx.fill() |
---|
595 | |
---|
596 | ctx.select_font_face("Ubuntu") |
---|
597 | ctx.set_font_size(15) |
---|
598 | ctx.move_to(5,15) |
---|
599 | ctx.set_source_rgb(1,1,1) |
---|
600 | |
---|
601 | ctx.show_text(_("Configured")) |
---|
602 | ctx.stroke() |
---|
603 | |
---|
604 | |
---|
605 | elif app["configured"]==0: |
---|
606 | |
---|
607 | lg1 = cairo.LinearGradient(0.0,110.0, 200.0, 110.0) |
---|
608 | |
---|
609 | lg1.add_color_stop_rgba(0, 0.7, 0, 0, 1) |
---|
610 | lg1.add_color_stop_rgba(1, 1, 0.2, 0.2, 0) |
---|
611 | ctx.rectangle(0, 0, 200, 20) |
---|
612 | ctx.set_source(lg1) |
---|
613 | ctx.fill() |
---|
614 | |
---|
615 | ctx.select_font_face("Ubuntu") |
---|
616 | ctx.set_font_size(15) |
---|
617 | ctx.move_to(5,15) |
---|
618 | ctx.set_source_rgb(1,1,1) |
---|
619 | |
---|
620 | ctx.show_text(_("Not configured")) |
---|
621 | ctx.stroke() |
---|
622 | |
---|
623 | else: |
---|
624 | lg1 = cairo.LinearGradient(0.0,110.0, 200.0, 110.0) |
---|
625 | lg1.add_color_stop_rgba(0, 1, 0, 0, 1) |
---|
626 | lg1.add_color_stop_rgba(1, 1, 0.2, 0.2, 0) |
---|
627 | ctx.rectangle(0, 0, 200, 20) |
---|
628 | ctx.set_source(lg1) |
---|
629 | ctx.fill() |
---|
630 | |
---|
631 | ctx.select_font_face("Ubuntu") |
---|
632 | ctx.set_font_size(15) |
---|
633 | ctx.move_to(5,15) |
---|
634 | ctx.set_source_rgba(1,1,1,app["conf_alpha"]) |
---|
635 | |
---|
636 | ctx.show_text(_("Failed")) |
---|
637 | ctx.stroke() |
---|
638 | |
---|
639 | ctx.select_font_face("Ubuntu") |
---|
640 | ctx.set_font_size(15) |
---|
641 | ctx.move_to(5,105) |
---|
642 | ctx.set_source_rgb(1,1,1) |
---|
643 | txt="" |
---|
644 | fix=True |
---|
645 | |
---|
646 | text=self.get_name(app) |
---|
647 | |
---|
648 | |
---|
649 | for char in range(30): |
---|
650 | try: |
---|
651 | txt+=text[char] |
---|
652 | except: |
---|
653 | fix=False |
---|
654 | break |
---|
655 | |
---|
656 | if fix: |
---|
657 | txt+="…" |
---|
658 | |
---|
659 | ctx.show_text(txt) |
---|
660 | ctx.stroke() |
---|
661 | |
---|
662 | #img.write_to_png(self.user_rsrc_path+item) |
---|
663 | image=Gtk.Image() |
---|
664 | #image.set_from_file(self.user_rsrc_path+item) |
---|
665 | image.set_from_pixbuf(Gdk.pixbuf_get_from_surface(img,0,0,235,110)) |
---|
666 | image.set_name("BIMAGE") |
---|
667 | return image |
---|
668 | |
---|
669 | #def get_image |
---|
670 | |
---|
671 | |
---|
672 | def drawing_banner_event(self,widget,ctx,app): |
---|
673 | |
---|
674 | package_rsrc_path=BANNER_PATH |
---|
675 | img_path=package_rsrc_path+"package.png" |
---|
676 | for item in os.listdir(package_rsrc_path): |
---|
677 | f,ext=item.split(".") |
---|
678 | if app["Icon"] == f: |
---|
679 | img_path=package_rsrc_path+item |
---|
680 | |
---|
681 | |
---|
682 | img=cairo.ImageSurface.create_from_png(img_path) |
---|
683 | ctx.set_source_surface(img,0,0) |
---|
684 | |
---|
685 | if not self.check_app_dependences(app): |
---|
686 | ctx.paint_with_alpha(0.2) |
---|
687 | ctx.set_source_rgba(0.5,0.5,0.5,0.7) |
---|
688 | ctx.rectangle(0,0,235,110) |
---|
689 | ctx.fill() |
---|
690 | else: |
---|
691 | ctx.paint() |
---|
692 | |
---|
693 | |
---|
694 | if "pulsating" in app and app["pulsating"]: |
---|
695 | |
---|
696 | ''' |
---|
697 | if app["pulsating"]: |
---|
698 | ctx.set_source_rgba(1,1,1,app["pulsating_alpha"]) |
---|
699 | ctx.rectangle(0,0,235,110) |
---|
700 | ctx.fill() |
---|
701 | ''' |
---|
702 | |
---|
703 | app.setdefault("pulsating_alpha",0.0) |
---|
704 | |
---|
705 | lg1 = cairo.LinearGradient(0.0,10.0, 235.0, 10.0) |
---|
706 | lg1.add_color_stop_rgba(0, 0, 0.0, 0.8, 0.7) |
---|
707 | lg1.add_color_stop_rgba(app["pulsating_alpha"], 0.1, 0.7, 0.9, 1) |
---|
708 | lg1.add_color_stop_rgba(1, 0, 0, 0.8, 0.5) |
---|
709 | ctx.rectangle(0,app["bar_height"],235,20) |
---|
710 | ctx.set_source(lg1) |
---|
711 | ctx.fill() |
---|
712 | ctx.set_source_rgba(0,0,0,0.8) |
---|
713 | ctx.rectangle(0,app["bar_height"]+20,235,110) |
---|
714 | ctx.fill() |
---|
715 | |
---|
716 | else: |
---|
717 | |
---|
718 | ctx.set_source_rgba(0,0,0,0.7) |
---|
719 | ctx.rectangle(0,app["bar_height"],235,110) |
---|
720 | ctx.fill() |
---|
721 | |
---|
722 | show_status=True |
---|
723 | if "Depends" in app: |
---|
724 | |
---|
725 | if not self.check_app_dependences(app): |
---|
726 | |
---|
727 | lg1 = cairo.LinearGradient(0.0,110.0, 200.0, 110.0) |
---|
728 | lg1.add_color_stop_rgba(0, 0.7, 0, 0, 1) |
---|
729 | lg1.add_color_stop_rgba(1, 1, 0.2, 0.2, 0) |
---|
730 | ctx.rectangle(0, 0, 200, 20) |
---|
731 | ctx.set_source(lg1) |
---|
732 | ctx.fill() |
---|
733 | |
---|
734 | ctx.select_font_face("Ubuntu") |
---|
735 | ctx.set_font_size(15) |
---|
736 | |
---|
737 | ctx.move_to(6,16) |
---|
738 | ctx.set_source_rgba(0,0,0,app["conf_alpha"]) |
---|
739 | ctx.show_text(_("Unmet dependences")) |
---|
740 | ctx.stroke() |
---|
741 | |
---|
742 | |
---|
743 | ctx.move_to(5,15) |
---|
744 | ctx.set_source_rgba(1,1,1,app["conf_alpha"]) |
---|
745 | ctx.show_text(_("Unmet dependences")) |
---|
746 | ctx.stroke() |
---|
747 | |
---|
748 | show_status=False |
---|
749 | |
---|
750 | if "Service" in app and show_status: |
---|
751 | |
---|
752 | if app["Service"].lower()=="true": |
---|
753 | |
---|
754 | if app["configured"]==1: |
---|
755 | |
---|
756 | lg1 = cairo.LinearGradient(0.0,110.0, 200.0, 110.0) |
---|
757 | lg1.add_color_stop_rgba(0, 0, 0.2, 0, 1) |
---|
758 | lg1.add_color_stop_rgba(1, 0, 1, 0, 0) |
---|
759 | ctx.rectangle(0, 0, 200, 20) |
---|
760 | ctx.set_source(lg1) |
---|
761 | ctx.fill() |
---|
762 | |
---|
763 | ctx.select_font_face("Ubuntu") |
---|
764 | ctx.set_font_size(15) |
---|
765 | |
---|
766 | ctx.set_source_rgba(0,0,0,app["conf_alpha"]) |
---|
767 | ctx.move_to(6,16) |
---|
768 | ctx.show_text(_("Configured")) |
---|
769 | ctx.stroke() |
---|
770 | |
---|
771 | |
---|
772 | ctx.set_source_rgba(1,1,1,app["conf_alpha"]) |
---|
773 | ctx.move_to(5,15) |
---|
774 | ctx.show_text(_("Configured")) |
---|
775 | ctx.stroke() |
---|
776 | |
---|
777 | elif app["configured"]==-1: |
---|
778 | |
---|
779 | lg1 = cairo.LinearGradient(0.0,110.0, 200.0, 110.0) |
---|
780 | lg1.add_color_stop_rgba(0, 0.7, 0, 0, 1) |
---|
781 | lg1.add_color_stop_rgba(1, 1, 0.2, 0.2, 0) |
---|
782 | ctx.rectangle(0, 0, 200, 20) |
---|
783 | ctx.set_source(lg1) |
---|
784 | ctx.fill() |
---|
785 | |
---|
786 | ctx.select_font_face("Ubuntu") |
---|
787 | ctx.set_font_size(15) |
---|
788 | |
---|
789 | ctx.set_source_rgba(0,0,0,app["conf_alpha"]) |
---|
790 | ctx.move_to(6,16) |
---|
791 | ctx.show_text(_("Failed")) |
---|
792 | ctx.stroke() |
---|
793 | |
---|
794 | |
---|
795 | ctx.move_to(5,15) |
---|
796 | ctx.set_source_rgba(1,1,1,app["conf_alpha"]) |
---|
797 | ctx.show_text(_("Failed")) |
---|
798 | ctx.stroke() |
---|
799 | |
---|
800 | else: |
---|
801 | |
---|
802 | lg1 = cairo.LinearGradient(0.0,110.0, 200.0, 110.0) |
---|
803 | lg1.add_color_stop_rgba(0, 0.8, 0, 0, 1) |
---|
804 | lg1.add_color_stop_rgba(1, 1, 0.2, 0.2, 0) |
---|
805 | ctx.rectangle(0, 0, 200, 20) |
---|
806 | ctx.set_source(lg1) |
---|
807 | ctx.fill() |
---|
808 | |
---|
809 | ctx.select_font_face("Ubuntu") |
---|
810 | ctx.set_font_size(15) |
---|
811 | |
---|
812 | ctx.set_source_rgba(0,0,0,app["conf_alpha"]) |
---|
813 | ctx.move_to(6,16) |
---|
814 | ctx.show_text(_("Not configured")) |
---|
815 | ctx.stroke() |
---|
816 | |
---|
817 | ctx.move_to(5,15) |
---|
818 | ctx.set_source_rgba(1,1,1,app["conf_alpha"]) |
---|
819 | ctx.show_text(_("Not configured")) |
---|
820 | ctx.stroke() |
---|
821 | |
---|
822 | |
---|
823 | txt="" |
---|
824 | fix=True |
---|
825 | for char in range(30): |
---|
826 | try: |
---|
827 | txt+=self.get_name(app)[char] |
---|
828 | except: |
---|
829 | fix=False |
---|
830 | break |
---|
831 | |
---|
832 | if fix: |
---|
833 | txt+="…" |
---|
834 | |
---|
835 | |
---|
836 | ctx.select_font_face("Ubuntu") |
---|
837 | ctx.set_font_size(15) |
---|
838 | |
---|
839 | ctx.move_to(6,app["bar_height"]+16) |
---|
840 | ctx.set_source_rgb(0,0,0) |
---|
841 | ctx.show_text(txt) |
---|
842 | ctx.stroke() |
---|
843 | |
---|
844 | ctx.move_to(5,app["bar_height"]+15) |
---|
845 | ctx.set_source_rgb(0.9,0.9,0.9) |
---|
846 | ctx.show_text(txt) |
---|
847 | ctx.stroke() |
---|
848 | |
---|
849 | |
---|
850 | |
---|
851 | |
---|
852 | y=app["bar_height"]+30 |
---|
853 | pctx = PangoCairo.create_layout(ctx) |
---|
854 | desc = Pango.font_description_from_string ("Ubuntu 8") |
---|
855 | pctx.set_font_description(desc) |
---|
856 | pctx.set_alignment(Pango.Alignment.LEFT) |
---|
857 | pctx.set_justify(True) |
---|
858 | pctx.set_width(225000) |
---|
859 | pctx.set_height(10) |
---|
860 | ctx.set_source_rgb(1,1,0.8) |
---|
861 | pctx.set_text(self.get_comment(app),-1) |
---|
862 | |
---|
863 | |
---|
864 | ctx.move_to(6,y) |
---|
865 | PangoCairo.show_layout (ctx, pctx) |
---|
866 | |
---|
867 | if "custom_text" in app: |
---|
868 | |
---|
869 | ctx.set_source_rgb(0.5,0.5,1) |
---|
870 | pctx.set_text(app["custom_text"],-1) |
---|
871 | ctx.move_to(6,y+60) |
---|
872 | PangoCairo.show_layout (ctx, pctx) |
---|
873 | |
---|
874 | |
---|
875 | #def drawing_event |
---|
876 | |
---|
877 | |
---|
878 | def mouse_over(self,widget,event,app,img): |
---|
879 | |
---|
880 | if not app["expanding"]: |
---|
881 | app["restoring"]=False |
---|
882 | app["expanding"]=True |
---|
883 | GLib.timeout_add(10,self.expand_black_area,app,img) |
---|
884 | |
---|
885 | #def mouse_over |
---|
886 | |
---|
887 | |
---|
888 | def mouse_left(self,widget,event,app,img): |
---|
889 | |
---|
890 | if not app["restoring"]: |
---|
891 | app["expanding"]=False |
---|
892 | app["restoring"]=True |
---|
893 | GLib.timeout_add(10,self.restore_black_area,app,img) |
---|
894 | |
---|
895 | #def mouse_left |
---|
896 | |
---|
897 | |
---|
898 | def expand_black_area(self,app,img): |
---|
899 | |
---|
900 | while app["bar_height"]>0 and app["expanding"]: |
---|
901 | app["bar_height"]-=2 |
---|
902 | if app["conf_alpha"]>0.0: |
---|
903 | app["conf_alpha"]-=0.025 |
---|
904 | img.queue_draw() |
---|
905 | return True |
---|
906 | |
---|
907 | if not app["expanding"]: |
---|
908 | return False |
---|
909 | |
---|
910 | app["expanding"]=False |
---|
911 | app["conf_alpha"]=0.0 |
---|
912 | img.queue_draw() |
---|
913 | return False |
---|
914 | |
---|
915 | #def expand_black_area |
---|
916 | |
---|
917 | |
---|
918 | def restore_black_area(self,app,img): |
---|
919 | |
---|
920 | while app["bar_height"]<BAR_HEIGHT and app["restoring"]: |
---|
921 | app["bar_height"]+=2 |
---|
922 | if app["conf_alpha"]<1.0: |
---|
923 | app["conf_alpha"]+=0.025 |
---|
924 | img.queue_draw() |
---|
925 | return True |
---|
926 | |
---|
927 | if not app["restoring"]: |
---|
928 | return False |
---|
929 | |
---|
930 | app["restoring"]=False |
---|
931 | app["conf_alpha"]=1.0 |
---|
932 | img.queue_draw() |
---|
933 | return False |
---|
934 | |
---|
935 | #def restore_black_area |
---|
936 | |
---|
937 | |
---|
938 | def check_app_groups(self,app): |
---|
939 | |
---|
940 | sys.stdout.write(" * Checking " + app["ID"] + " ... ") |
---|
941 | groups=[] |
---|
942 | if "Groups" not in app: |
---|
943 | print("OK") |
---|
944 | return True |
---|
945 | |
---|
946 | try: |
---|
947 | |
---|
948 | if os.environ["USER"]=="root": |
---|
949 | print("OK") |
---|
950 | return True |
---|
951 | |
---|
952 | groups=app["Groups"].strip("\n").split(";") |
---|
953 | for group in groups: |
---|
954 | if group in self.user_groups: |
---|
955 | print("OK") |
---|
956 | return True |
---|
957 | |
---|
958 | except Exception as e: |
---|
959 | print e |
---|
960 | pass |
---|
961 | |
---|
962 | print "NOT ALLOWED" |
---|
963 | print "\t[!] App groups: ",sorted(groups) |
---|
964 | return False |
---|
965 | |
---|
966 | #def check_app_groups |
---|
967 | |
---|
968 | |
---|
969 | def add_pulsating(self,app,image): |
---|
970 | |
---|
971 | GLib.timeout_add(70,self.pulsate_color,app,image) |
---|
972 | |
---|
973 | #def add_pulsating |
---|
974 | |
---|
975 | |
---|
976 | def pulsate_color(self,app,image): |
---|
977 | |
---|
978 | app["pulsating_alpha"]+=app["pulsating_increment"] |
---|
979 | |
---|
980 | if app["pulsating_alpha"] >= 1.0 : |
---|
981 | |
---|
982 | app["pulsating_increment"]=-0.02 |
---|
983 | |
---|
984 | if app["pulsating_alpha"] <= 0.0 : |
---|
985 | |
---|
986 | app["pulsating_increment"]=0.02 |
---|
987 | |
---|
988 | image.queue_draw() |
---|
989 | return app["pulsating"] |
---|
990 | |
---|
991 | #def pulsate_color |
---|
992 | |
---|
993 | |
---|
994 | def check_app_dependences(self,app): |
---|
995 | |
---|
996 | if "Depends" in app: |
---|
997 | depends=app["Depends"].split(";") |
---|
998 | for dep in depends: |
---|
999 | |
---|
1000 | if dep not in self.configured_apps: |
---|
1001 | return False |
---|
1002 | |
---|
1003 | return True |
---|
1004 | |
---|
1005 | #def check_app_dependences |
---|
1006 | |
---|
1007 | |
---|
1008 | def add_categories_to_window(self,category): |
---|
1009 | |
---|
1010 | for category in self.categories_parser.categories: |
---|
1011 | |
---|
1012 | icon=category["icon"] |
---|
1013 | category=category["name"].lower() |
---|
1014 | |
---|
1015 | once=True |
---|
1016 | hbox=Gtk.HBox() |
---|
1017 | hbox.set_margin_left(10) |
---|
1018 | hbox.set_margin_right(10) |
---|
1019 | count=0 |
---|
1020 | if category in self.app_parser.apps: |
---|
1021 | for app in sorted(self.app_parser.apps[category]): |
---|
1022 | |
---|
1023 | if self.check_app_groups(app): |
---|
1024 | |
---|
1025 | |
---|
1026 | button=Gtk.Button() |
---|
1027 | button.set_name("APPBUTTON") |
---|
1028 | button.set_size_request(235,110) |
---|
1029 | |
---|
1030 | if not self.drawing_mode: |
---|
1031 | image=self.get_banner_image(app) |
---|
1032 | else: |
---|
1033 | image=Gtk.DrawingArea() |
---|
1034 | image.show() |
---|
1035 | image.connect("draw",self.drawing_banner_event,app) |
---|
1036 | |
---|
1037 | if "pulsating" in app: |
---|
1038 | if app["pulsating"]: |
---|
1039 | app["pulsating_alpha"]=0.0 |
---|
1040 | app["pulsating_increment"]=0.02 |
---|
1041 | self.add_pulsating(app,image) |
---|
1042 | |
---|
1043 | |
---|
1044 | button.add_events(Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.LEAVE_NOTIFY_MASK) |
---|
1045 | button.connect("motion-notify-event",self.mouse_over,app,image) |
---|
1046 | button.connect("leave_notify_event",self.mouse_left,app,image) |
---|
1047 | #button.set_size_request(245,120) |
---|
1048 | |
---|
1049 | button.add(image) |
---|
1050 | if "Name["+self.lang+"]" in app: |
---|
1051 | button.set_tooltip_text(app["Name["+self.lang+"]"]) |
---|
1052 | else: |
---|
1053 | button.set_tooltip_text(app["Name"]) |
---|
1054 | button.connect("clicked",self.app_clicked,app) |
---|
1055 | app["gtk_button"]=button |
---|
1056 | hbox.pack_start(button,True,False,0) |
---|
1057 | count+=1 |
---|
1058 | if count==3: |
---|
1059 | hbox.show_all() |
---|
1060 | if once: |
---|
1061 | self.add_label(self.get_translation(category),icon) |
---|
1062 | once=False |
---|
1063 | self.content_hbox.pack_start(hbox,False,False,10) |
---|
1064 | count=0 |
---|
1065 | hbox=Gtk.HBox() |
---|
1066 | hbox.set_margin_left(10) |
---|
1067 | hbox.set_margin_right(10) |
---|
1068 | |
---|
1069 | if count!=0: |
---|
1070 | hbox.show_all() |
---|
1071 | if once: |
---|
1072 | self.add_label(self.get_translation(category),icon) |
---|
1073 | once=False |
---|
1074 | hbox.set_halign(Gtk.Align.START) |
---|
1075 | hbox.set_margin_left(20) |
---|
1076 | children=hbox.get_children() |
---|
1077 | if len(children)>1: |
---|
1078 | for child in children[1:]: |
---|
1079 | child.set_margin_left(20) |
---|
1080 | self.content_hbox.pack_start(hbox,False,False,5) |
---|
1081 | |
---|
1082 | self.content_hbox.get_children()[-1].set_margin_bottom(10) |
---|
1083 | |
---|
1084 | #def add_categories_to_window |
---|
1085 | |
---|
1086 | |
---|
1087 | |
---|
1088 | |
---|
1089 | def add_label(self,label_name,icon_name=None): |
---|
1090 | |
---|
1091 | if icon_name==None: |
---|
1092 | icon_name="system" |
---|
1093 | |
---|
1094 | tmpbox=Gtk.HBox() |
---|
1095 | img=Gtk.Image() |
---|
1096 | img.set_from_icon_name(icon_name,Gtk.IconSize.MENU) |
---|
1097 | label=Gtk.Label(label_name) |
---|
1098 | label.set_name("WHITE-15") |
---|
1099 | expander=Gtk.HSeparator() |
---|
1100 | expander.set_margin_right(15) |
---|
1101 | tmpbox.set_margin_left(10) |
---|
1102 | tmpbox.set_margin_top(5) |
---|
1103 | tmpbox.pack_start(img,False,False,0) |
---|
1104 | tmpbox.pack_start(label,False,False,10) |
---|
1105 | tmpbox.pack_start(expander,True,True,5) |
---|
1106 | tmpbox.show_all() |
---|
1107 | self.content_hbox.pack_start(tmpbox,False,False,5) |
---|
1108 | |
---|
1109 | #def add_label |
---|
1110 | |
---|
1111 | |
---|
1112 | def app_clicked(self,widget,app): |
---|
1113 | |
---|
1114 | if self.client.get_variable("","VariablesManager","MASTER_SERVER_IP"): |
---|
1115 | if app["ID"] in self.blacklist: |
---|
1116 | result = self.open_dialog("Warning",_("We are in a center model and therefore should install this service on the master \n server to be accessible from any computer in the center, whether to continue \n with the installation on this computer the service is only available on computers \n that are in the internal network of this server."),True) |
---|
1117 | if result == Gtk.ResponseType.CANCEL: |
---|
1118 | return -1 |
---|
1119 | |
---|
1120 | if app["ID"] in self.configured_apps: |
---|
1121 | ret=self.open_dialog("Warning",_("<b>%s</b> is already configured. Do you want to execute it again?")%self.get_name(app),True) |
---|
1122 | if ret==Gtk.ResponseType.CANCEL: |
---|
1123 | return -1 |
---|
1124 | |
---|
1125 | if self.check_app_dependences(app): |
---|
1126 | |
---|
1127 | cmd="" |
---|
1128 | |
---|
1129 | if "Using" in app: |
---|
1130 | cmd+=app["Using"].strip(" ").strip("\n") +" " |
---|
1131 | |
---|
1132 | cmd+=self.app_parser.ZMD_PATH + app["ScriptPath"] |
---|
1133 | |
---|
1134 | gt=False |
---|
1135 | if "Gnome-terminal" in app: |
---|
1136 | if app["Gnome-terminal"].lower()=="true": |
---|
1137 | cmd='gnome-terminal --command="'+cmd+'"' |
---|
1138 | gt=True |
---|
1139 | |
---|
1140 | if not gt: |
---|
1141 | if "gnome-terminal" in app: |
---|
1142 | if app["gnome-terminal"].lower()=="true": |
---|
1143 | cmd='gnome-terminal --command="'+cmd+'"' |
---|
1144 | |
---|
1145 | |
---|
1146 | |
---|
1147 | blocked=False |
---|
1148 | print(' * Executing "' + cmd + '" ...') |
---|
1149 | if "Modal" in app: |
---|
1150 | if app["Modal"].lower()=="true" and not self.mprocess.is_alive(): |
---|
1151 | GLib.timeout_add(250,self.pulse_progress) |
---|
1152 | self.progress_bar.show() |
---|
1153 | |
---|
1154 | try: |
---|
1155 | txt="Executing %s"%app["Name["+self.lang+"]"] |
---|
1156 | except: |
---|
1157 | txt="Executing %s"%app["Name"] |
---|
1158 | self.progress_label.set_text(txt) |
---|
1159 | self.progress_label.show() |
---|
1160 | self.mprocess_app_name=app["Name"] |
---|
1161 | blocked=True |
---|
1162 | else: |
---|
1163 | self.open_dialog("Warning","<b>%s</b> is being executed. Please wait until it finishes."%self.mprocess_app_name ) |
---|
1164 | return -1 |
---|
1165 | |
---|
1166 | self.execute(cmd,blocked,app,widget) |
---|
1167 | |
---|
1168 | else: |
---|
1169 | |
---|
1170 | self.open_dialog("Warning","<b>%s</b> dependences have not been configured."%self.get_name(app) +"\n[ %s ]"%app["Depends"]) |
---|
1171 | |
---|
1172 | #def app_clicked |
---|
1173 | |
---|
1174 | |
---|
1175 | def check_output(self,process,app,button): |
---|
1176 | |
---|
1177 | if not process.is_alive(): |
---|
1178 | |
---|
1179 | print "[ZeroCenter] %s has ended"%app["ID"] |
---|
1180 | |
---|
1181 | if "Service" in app: |
---|
1182 | if app["Service"].lower()=="true": |
---|
1183 | |
---|
1184 | try: |
---|
1185 | self.get_states() |
---|
1186 | |
---|
1187 | for cat in self.app_parser.apps: |
---|
1188 | for item in self.app_parser.apps[cat]: |
---|
1189 | item["gtk_button"].get_child().queue_draw() |
---|
1190 | |
---|
1191 | darea=button.get_child() |
---|
1192 | darea.queue_draw() |
---|
1193 | |
---|
1194 | except Exception as e: |
---|
1195 | pass |
---|
1196 | |
---|
1197 | return process.is_alive() |
---|
1198 | |
---|
1199 | #def check_output |
---|
1200 | |
---|
1201 | |
---|
1202 | def pulse_progress(self): |
---|
1203 | |
---|
1204 | self.progress_bar.pulse() |
---|
1205 | if not self.mprocess.is_alive(): |
---|
1206 | self.progress_bar.hide() |
---|
1207 | self.progress_label.hide() |
---|
1208 | return self.mprocess.is_alive() |
---|
1209 | |
---|
1210 | #def pulse_progress |
---|
1211 | |
---|
1212 | |
---|
1213 | def execute(self,cmd,blocked=False,app=None,widget=None): |
---|
1214 | |
---|
1215 | if not blocked: |
---|
1216 | p=multiprocessing.Process(target=self._execute,args=(cmd,)) |
---|
1217 | #p.daemon=True |
---|
1218 | GLib.timeout_add(1000,self.check_output,p,app,widget) |
---|
1219 | p.start() |
---|
1220 | |
---|
1221 | if blocked: |
---|
1222 | |
---|
1223 | if not self.mprocess.is_alive(): |
---|
1224 | self.mprocess=multiprocessing.Process(target=self._execute,args=(cmd,)) |
---|
1225 | #self.mprocess.daemon=True |
---|
1226 | self.mprocess.start() |
---|
1227 | GLib.timeout_add(1000,self.check_output,self.mprocess,app,widget) |
---|
1228 | else: |
---|
1229 | self.open_dialog("Warning",_("<b>%s</b> is being executed. Please wait until it finishes.")%self.mprocess_app_name ) |
---|
1230 | |
---|
1231 | #def execute |
---|
1232 | |
---|
1233 | |
---|
1234 | def _execute(self,cmd): |
---|
1235 | |
---|
1236 | |
---|
1237 | subprocess.call(cmd,shell=True,preexec_fn=lambda: signal.signal(signal.SIGPIPE,signal.SIG_DFL)) |
---|
1238 | |
---|
1239 | #os.system(cmd) |
---|
1240 | |
---|
1241 | #def _execute |
---|
1242 | |
---|
1243 | |
---|
1244 | def close_window(self,widget,data): |
---|
1245 | |
---|
1246 | if self.mprocess.is_alive(): |
---|
1247 | ret=self.open_dialog("Warning",_("<b>%s</b> is being executed. Are you sure you want to exit?")%self.mprocess_app_name ,True) |
---|
1248 | |
---|
1249 | if ret==Gtk.ResponseType.CANCEL: |
---|
1250 | return -1 |
---|
1251 | |
---|
1252 | self.mprocess.terminate() |
---|
1253 | self.mprocess=multiprocessing.Process() |
---|
1254 | |
---|
1255 | Gtk.main_quit() |
---|
1256 | print("") |
---|
1257 | |
---|
1258 | #def close_window |
---|
1259 | |
---|
1260 | |
---|
1261 | def open_dialog(self,title,text,show_cancel=False): |
---|
1262 | |
---|
1263 | label = Gtk.Label() |
---|
1264 | label.set_markup(text) |
---|
1265 | if show_cancel: |
---|
1266 | dialog = Gtk.Dialog(title, None, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, (Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT,Gtk.STOCK_CANCEL,Gtk.ResponseType.CANCEL)) |
---|
1267 | else: |
---|
1268 | dialog = Gtk.Dialog(title, None, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, (Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT)) |
---|
1269 | hbox = Gtk.HBox() |
---|
1270 | img=Gtk.Image.new_from_icon_name("emblem-important",Gtk.IconSize.DIALOG) |
---|
1271 | hbox.pack_start(img,True,True,5) |
---|
1272 | hbox.pack_start(label,True,True,10) |
---|
1273 | hbox.show_all() |
---|
1274 | dialog.vbox.pack_start(hbox,True,True,10) |
---|
1275 | dialog.set_border_width(6) |
---|
1276 | response = dialog.run() |
---|
1277 | dialog.destroy() |
---|
1278 | return response |
---|
1279 | |
---|
1280 | #def open_dialog |
---|
1281 | |
---|
1282 | |
---|
1283 | def get_state(self,app): |
---|
1284 | |
---|
1285 | try: |
---|
1286 | configured=self.client.get_state("","ZCenterVariables",app["ID"]) |
---|
1287 | return configured |
---|
1288 | except: |
---|
1289 | return 0 |
---|
1290 | |
---|
1291 | #def get_state |
---|
1292 | |
---|
1293 | |
---|
1294 | def set_configured(self,app,key): |
---|
1295 | |
---|
1296 | if app in self.app_parser.app_list: |
---|
1297 | |
---|
1298 | try: |
---|
1299 | self.client.set_configured(key,"ZCenterVariables",app) |
---|
1300 | except Exception as e: |
---|
1301 | print e |
---|
1302 | |
---|
1303 | else: |
---|
1304 | print("[!] %s is not installed"%app) |
---|
1305 | |
---|
1306 | sys.exit(0) |
---|
1307 | |
---|
1308 | #def set_configured |
---|
1309 | |
---|
1310 | |
---|
1311 | def set_non_configured(self,app,key): |
---|
1312 | |
---|
1313 | if app in self.app_parser.app_list: |
---|
1314 | |
---|
1315 | try: |
---|
1316 | self.client.set_non_configured(key,"ZCenterVariables",app) |
---|
1317 | except: |
---|
1318 | pass |
---|
1319 | |
---|
1320 | else: |
---|
1321 | print("\t[!] %s is not installed"%app) |
---|
1322 | |
---|
1323 | sys.exit(0) |
---|
1324 | |
---|
1325 | #def set_non_configured |
---|
1326 | |
---|
1327 | def set_failed(self,app,key): |
---|
1328 | |
---|
1329 | if app in self.app_parser.app_list: |
---|
1330 | |
---|
1331 | try: |
---|
1332 | self.client.set_failed(key,"ZCenterVariables",app) |
---|
1333 | except: |
---|
1334 | pass |
---|
1335 | |
---|
1336 | else: |
---|
1337 | print("\t[!] %s is not installed"%app) |
---|
1338 | |
---|
1339 | sys.exit(0) |
---|
1340 | |
---|
1341 | #def set_non_configured |
---|
1342 | |
---|
1343 | |
---|
1344 | def set_custom_text(self,app,text,key): |
---|
1345 | |
---|
1346 | if app in self.app_parser.app_list: |
---|
1347 | |
---|
1348 | try: |
---|
1349 | self.client.set_custom_text(key,"ZCenterVariables",app,text) |
---|
1350 | except: |
---|
1351 | pass |
---|
1352 | |
---|
1353 | else: |
---|
1354 | print("\t[!] %s is not installed"%app) |
---|
1355 | |
---|
1356 | sys.exit(0) |
---|
1357 | |
---|
1358 | #def set_custom_text |
---|
1359 | |
---|
1360 | |
---|
1361 | def add_pulsating_color(self,key,app): |
---|
1362 | |
---|
1363 | try: |
---|
1364 | self.client.add_pulsating_color(key,"ZCenterVariables",app) |
---|
1365 | except: |
---|
1366 | pass |
---|
1367 | |
---|
1368 | sys.exit(0) |
---|
1369 | |
---|
1370 | #def add_pulsating_color |
---|
1371 | |
---|
1372 | |
---|
1373 | def remove_pulsating_color(self,key,app): |
---|
1374 | |
---|
1375 | try: |
---|
1376 | self.client.remove_pulsating_color(key,"ZCenterVariables",app) |
---|
1377 | except: |
---|
1378 | pass |
---|
1379 | |
---|
1380 | sys.exit(0) |
---|
1381 | |
---|
1382 | #def add_pulsating_color |
---|
1383 | |
---|
1384 | |
---|
1385 | def add_zc_notification(self,key,app,text,text_es="",text_qcv=""): |
---|
1386 | |
---|
1387 | try: |
---|
1388 | self.client.set_zc_message(key,"ZCenterVariables",app,text,text_es,text_qcv) |
---|
1389 | except Exception as e: |
---|
1390 | print e |
---|
1391 | |
---|
1392 | sys.exit(0) |
---|
1393 | |
---|
1394 | #def add_zc_notification |
---|
1395 | |
---|
1396 | |
---|
1397 | def remove_zc_notification(self,key,app): |
---|
1398 | |
---|
1399 | try: |
---|
1400 | self.client.remove_zc_message(key,"ZCenterVariables",app) |
---|
1401 | except Exception as e: |
---|
1402 | print e |
---|
1403 | |
---|
1404 | sys.exit(0) |
---|
1405 | |
---|
1406 | #def remove_zc_notification |
---|
1407 | |
---|
1408 | |
---|
1409 | def usage(self): |
---|
1410 | |
---|
1411 | print("USAGE:") |
---|
1412 | print("\tzero-center [ OPTION [ APP ] ]") |
---|
1413 | print("Options:") |
---|
1414 | print("\tset-configured APP") |
---|
1415 | print("\tset-non-configured APP") |
---|
1416 | print("\tset-custom-text APP TEXT") |
---|
1417 | print("\tadd-zero-center-notification APP TEXT_EN [TEXT_ES TEXT_QCV]") |
---|
1418 | print("\tremove-zero-center-notification APP") |
---|
1419 | print("\tadd-pulsating-color APP") |
---|
1420 | print("\tremove-pulsating-color APP") |
---|
1421 | print("\tnon-animated") |
---|
1422 | print("\tanimated") |
---|
1423 | print("\thelp") |
---|
1424 | print("") |
---|
1425 | sys.exit(0) |
---|
1426 | |
---|
1427 | #def usage |
---|
1428 | |
---|
1429 | |
---|
1430 | def check_root(): |
---|
1431 | try: |
---|
1432 | f=open("/etc/n4d/key","r") |
---|
1433 | key=f.readline().strip("\n") |
---|
1434 | f.close() |
---|
1435 | return key |
---|
1436 | except: |
---|
1437 | print("[!] You need root privileges to execute this option [!]") |
---|
1438 | sys.exit(1) |
---|
1439 | |
---|
1440 | if __name__=="__main__": |
---|
1441 | |
---|
1442 | |
---|
1443 | zc=ZeroCenter() |
---|
1444 | zc.drawing_mode=True |
---|
1445 | |
---|
1446 | if len(sys.argv)>=2: |
---|
1447 | |
---|
1448 | if sys.argv[1] not in zc.commands: |
---|
1449 | zc.usage() |
---|
1450 | sys.exit(1) |
---|
1451 | |
---|
1452 | if sys.argv[1] == "help": |
---|
1453 | zc.usage() |
---|
1454 | |
---|
1455 | if sys.argv[1] == "set-configured": |
---|
1456 | key=check_root() |
---|
1457 | zc.set_configured(sys.argv[2],key) |
---|
1458 | |
---|
1459 | if sys.argv[1] == "set-non-configured": |
---|
1460 | key=check_root() |
---|
1461 | zc.set_non_configured(sys.argv[2],key) |
---|
1462 | |
---|
1463 | if sys.argv[1] == "set-failed": |
---|
1464 | key=check_root() |
---|
1465 | zc.set_failed(sys.argv[2],key) |
---|
1466 | |
---|
1467 | if sys.argv[1] == "set-custom-text": |
---|
1468 | key=check_root() |
---|
1469 | zc.set_custom_text(sys.argv[2],sys.argv[3],key) |
---|
1470 | |
---|
1471 | if sys.argv[1] == "add-zero-center-notification": |
---|
1472 | key=check_root() |
---|
1473 | |
---|
1474 | try: |
---|
1475 | app=sys.argv[2] |
---|
1476 | except: |
---|
1477 | zc.usage() |
---|
1478 | try: |
---|
1479 | text=sys.argv[3] |
---|
1480 | except: |
---|
1481 | zc.usage() |
---|
1482 | try: |
---|
1483 | text_es=sys.argv[4] |
---|
1484 | except Exception as e: |
---|
1485 | print e |
---|
1486 | text_es="" |
---|
1487 | try: |
---|
1488 | text_qcv=sys.argv[5] |
---|
1489 | except Exception as e: |
---|
1490 | print e |
---|
1491 | text_qcv="" |
---|
1492 | |
---|
1493 | zc.add_zc_notification(key,app,text,text_es,text_qcv) |
---|
1494 | |
---|
1495 | if sys.argv[1] == "remove-zero-center-notification": |
---|
1496 | |
---|
1497 | key=check_root() |
---|
1498 | |
---|
1499 | try: |
---|
1500 | app=sys.argv[2] |
---|
1501 | except: |
---|
1502 | zc.usage() |
---|
1503 | |
---|
1504 | zc.remove_zc_notification(key,app) |
---|
1505 | |
---|
1506 | if sys.argv[1] == "add-pulsating-color": |
---|
1507 | key=check_root() |
---|
1508 | try: |
---|
1509 | app=sys.argv[2] |
---|
1510 | except: |
---|
1511 | zc.usage() |
---|
1512 | |
---|
1513 | zc.add_pulsating_color(key,app) |
---|
1514 | |
---|
1515 | if sys.argv[1] == "remove-pulsating-color": |
---|
1516 | key=check_root() |
---|
1517 | |
---|
1518 | try: |
---|
1519 | app=sys.argv[2] |
---|
1520 | except: |
---|
1521 | zc.usage() |
---|
1522 | |
---|
1523 | zc.remove_pulsating_color(key,app) |
---|
1524 | |
---|
1525 | |
---|
1526 | if sys.argv[1]=="animated": |
---|
1527 | zc.drawing_mode=True |
---|
1528 | |
---|
1529 | if sys.argv[1]=="non-animated": |
---|
1530 | zc.drawing_mode=False |
---|
1531 | |
---|
1532 | |
---|
1533 | |
---|
1534 | zc.start_gui() |
---|
1535 | |
---|