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