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