Merge pull request #4735 from cg110/fix_web_server_mem_leak
[vuplus_xbmc] / tools / Linux / FEH.py
1 import os
2 import sys
3 import re
4
5 AvailableOutputs = []
6 Output = None
7
8 try:
9     from qt import *
10     AvailableOutputs.append("--error-output=Qt")
11 except:
12     pass
13 try:
14     import pygtk
15     pygtk.require('2.0')
16     import gtk
17     AvailableOutputs.append("--error-output=GTK")
18 except:
19     pass
20 try:
21     import pygame
22     import datetime
23     AvailableOutputs.append("--error-output=SDL")
24 except:
25     pass
26
27 def error(errorLine):
28     if Output == "--error-output=Qt":
29         createQt(errorLine)
30     elif Output == "--error-output=GTK":
31         createGTK(errorLine)
32     elif Output == "--error-output=SDL":
33         createSDL(errorLine)
34     else:
35         try:
36             print(errorLine)
37         except:
38             print(errorLine)
39
40     exit(1)
41
42 def createQt(errorLine):
43     app = QApplication(sys.argv)
44     QObject.connect(app, SIGNAL('lastWindowClosed()')
45                        , app
46                        , SLOT('quit()')
47                        )
48     
49     dialog = QDialog(None, "Error", 0, 0)
50     dialog.setCaption(dialog.tr("Error"))
51     layout=QVBoxLayout(dialog)
52     layout.setSpacing(6)
53     layout.setMargin(5)
54
55     label=QLabel(errorLine, dialog)
56
57     layout.addWidget(label)
58
59     bnExit=QPushButton("Quit", dialog, "add")
60     dialog.connect(bnExit, SIGNAL("clicked()"), qApp, SLOT("quit()"))
61
62     layout.addWidget(bnExit)
63
64     app.setMainWidget(dialog)
65     dialog.show()
66     app.exec_loop()
67
68 def createGTK(errorLine):
69     window = gtk.Window(gtk.WINDOW_TOPLEVEL)
70     window.connect("destroy", lambda w: gtk.main_quit())
71
72     window.set_title("Error")
73     vbox = gtk.VBox(False, 5)
74     window.add(vbox)
75     window.set_border_width(5)
76
77     frame = gtk.Frame()
78     frame.set_shadow_type(gtk.SHADOW_NONE)
79     label = gtk.Label(errorLine)
80     frame.add(label)
81     vbox.pack_start(frame, False, False, 0)
82
83     button = gtk.Button("Quit")
84     button.connect_object("clicked", gtk.Widget.destroy, window)
85
86     vbox.pack_start(button, False, False, 0)
87
88     window.show_all ()
89
90     gtk.main()
91
92 def createSDL(errorLine):
93     pygame.init()
94     pygame.font.init()
95     pygame.display.set_caption("Error")
96
97     size = width, height = 800, 600
98     speed = [2, 2]
99     black = 0, 0, 0
100
101     screen = pygame.display.set_mode(size)
102     font = pygame.font.Font(None, 32)
103
104     autoQuit = 10
105     start = datetime.datetime.now()
106     finish = datetime.datetime.now()
107     delta = finish - start
108     while delta.seconds < autoQuit:
109         for event in pygame.event.get():
110             if event.type == pygame.QUIT or event.type == pygame.KEYDOWN:
111                 sys.exit()
112
113         screen.fill(black)
114
115         place = [200, 200]
116         for line in errorLine.split('\n'):
117             text = font.render(line, 1, (255,255,255) )
118             place[1] += font.size(line)[1]
119             screen.blit(text, text.get_rect().move(place))
120             
121
122         quitline = "Press any button to continue ("
123         quitline += str(autoQuit - delta.seconds)
124         quitline += ")"
125         text = font.render(quitline, 1, (255,255,255) )
126         screen.blit(text, text.get_rect().move(200,400))
127
128         pygame.display.flip()
129
130         finish = datetime.datetime.now()
131         delta = finish - start
132
133 def badDirectRendering():
134     out = os.popen("glxinfo | grep \"direct rendering\"", 'r')
135     line = out.read()
136     direct = "Yes" not in line
137     out.close()
138
139     return direct
140
141 def badColorDepth():
142     out = os.popen('xdpyinfo | grep "depth of root"', 'r')
143     
144     p = re.compile("([0-9]*) planes")
145     for line in out.readlines():
146         match = p.search(line)
147         if (match is not None):
148             if int(match.group(1)) > 16:
149                 bitDepth = False
150             else:
151                 bitDepth = True
152     out.close()
153
154     return bitDepth
155
156 def possibleOutput(text):
157     return text in sys.argv and text in AvailableOutputs
158
159 if __name__=="__main__":
160     if len(AvailableOutputs) > 0:
161         Output = AvailableOutputs[0]
162     else:
163         Output = None
164
165     for text in sys.argv:
166         if possibleOutput(text):
167             Output = text
168
169     if "--no-test" in sys.argv:
170         exit(0)
171
172     if (badDirectRendering()):
173         error("XBMC needs hardware accelerated OpenGL rendering.\nInstall an appropriate graphics driver.\n\nPlease consult XBMC Wiki for supported hardware\nhttp://wiki.xbmc.org/?title=Supported_hardware")
174
175     if (badColorDepth()):
176         error("XBMC cannot run unless the\nscreen color depth is atleast 24 bit.\n\nPlease reconfigure your screen.")