1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
|
import sys
from PyQt4 import QtGui
class Colors(object):
# Colors:
sceneBg1 = QtGui.QColor(91, 91, 91)
sceneBg1Line = QtGui.QColor(114, 108, 104)
sceneBg2 = QtGui.QColor(0, 0, 0)
sceneLine = QtGui.QColor(255, 255, 255)
paperBg = QtGui.QColor(100, 100, 100)
menuTextFg = QtGui.QColor(255, 0, 0)
buttonBgLow = QtGui.QColor(255, 255, 255, 90)
buttonBgHigh = QtGui.QColor(255, 255, 255, 20)
buttonText = QtGui.QColor(255, 255, 255)
tt_green = QtGui.QColor(166, 206, 57)
fadeOut = QtGui.QColor(206, 246, 117, 0)
heading = QtGui.QColor(190, 230, 80)
contentColor = "<font color='#eeeeee'>"
glVersion = "Not detected!"
# Guides:
stageStartY = 8
stageHeight = 536
stageStartX = 8
stageWidth = 785
contentStartY = 22
contentHeight = 510
# Properties:
openGlRendering = False
direct3dRendering = False
softwareRendering = False
openGlAvailable = True
openGlAdequate = True
direct3dAvailable = True
xRenderPresent = True
noTicker = False
noRescale = False
noAnimations = False
noBlending = False
noScreenSync = False
fullscreen = False
usePixmaps = False
useLoop = False
showBoundingRect = False
showFps = False
noAdapt = False
noWindowMask = True
useButtonBalls = False
useEightBitPalette = False
noTimerUpdate = False
noTickerMorph = False
adapted = False
verbose = False
pause = True
fps = 100
menuCount = 18
animSpeed = 1.0
animSpeedButtons = 1.0
benchmarkFps = -1.0
tickerLetterCount = 80;
tickerMoveSpeed = 0.4
tickerMorphSpeed = 2.5
tickerText = ".EROM ETAERC .SSEL EDOC"
rootMenuName = "PyQt Examples and Demos"
@staticmethod
def contentFont():
font = QtGui.QFont()
font.setStyleStrategy(QtGui.QFont.PreferAntialias)
if sys.platform == 'darwin':
font.setPixelSize(14)
font.setFamily('Arial')
else:
font.setPixelSize(13)
font.setFamily('Verdana')
return font
@staticmethod
def headingFont():
font = QtGui.QFont()
font.setStyleStrategy(QtGui.QFont.PreferAntialias)
font.setPixelSize(23)
font.setBold(True)
font.setFamily('Verdana')
return font;
@staticmethod
def buttonFont():
font = QtGui.QFont()
font.setStyleStrategy(QtGui.QFont.PreferAntialias)
font.setPixelSize(11)
font.setFamily('Verdana')
return font
@staticmethod
def tickerFont():
font = QtGui.QFont()
font.setStyleStrategy(QtGui.QFont.PreferAntialias)
if sys.platform == 'darwin':
font.setPixelSize(11)
font.setBold(True)
font.setFamily('Arial')
else:
font.setPixelSize(10)
font.setBold(True)
font.setFamily('sans serif')
return font
@classmethod
def debug(cls, *args):
if cls.verbose:
sys.stderr.write("%s\n" % " ".join([str(arg) for arg in args]))
@classmethod
def parseArgs(cls, argv):
# Some arguments should be processed before others. Handle them now.
if "-verbose" in argv:
cls.verbose = True
cls.detectSystemResources()
# Handle the rest of the arguments. They may override attributes
# already set.
for s in argv:
if s == "-opengl":
cls.openGlRendering = True
elif s == "-direct3d":
cls.direct3dRendering = True
elif s == "-software":
cls.softwareRendering = True
elif s == "-no-opengl":
cls.softwareRendering = True
elif s == "-no-ticker":
cls.noTicker = True
elif s.startswith("-ticker"):
cls.noTicker = not bool(parseFloat(s, "-ticker"))
elif s == "-no-animations":
cls.noAnimations = True
elif s.startswith("-animations"):
cls.noAnimations = not bool(parseFloat(s, "-animations"))
elif s == "-no-adapt":
cls.noAdapt = True
elif s == "-low":
cls.setLowSettings()
elif s == "-no-rescale":
cls.noRescale = True
elif s == "-use-pixmaps":
cls.usePixmaps = True
elif s == "-fullscreen":
cls.fullscreen = True
elif s == "-show-br":
cls.showBoundingRect = True
elif s == "-show-fps":
cls.showFps = True
elif s == "-no-blending":
cls.noBlending = True
elif s == "-no-sync":
cls.noScreenSync = True
elif s.startswith("-menu"):
cls.menuCount = int(parseFloat(s, "-menu"))
elif s.startswith("-use-timer-update"):
cls.noTimerUpdate = not bool(parseFloat(s, "-use-timer-update"))
elif s.startswith("-pause"):
cls.pause = bool(parseFloat(s, "-pause"))
elif s == "-no-ticker-morph":
cls.noTickerMorph = True
elif s == "-use-window-mask":
cls.noWindowMask = False
elif s == "-use-loop":
cls.useLoop = True
elif s == "-use-8bit":
cls.useEightBitPalette = True
elif s.startswith("-8bit"):
cls.useEightBitPalette = bool(parseFloat(s, "-8bit"))
elif s == "-use-balls":
cls.useButtonBalls = True
elif s.startswith("-ticker-letters"):
cls.tickerLetterCount = int(parseFloat(s, "-ticker-letters"))
elif s.startswith("-ticker-text"):
cls.tickerText = parseText(s, "-ticker-text")
elif s.startswith("-ticker-speed"):
cls.tickerMoveSpeed = parseFloat(s, "-ticker-speed")
elif s.startswith("-ticker-morph-speed"):
cls.tickerMorphSpeed = parseFloat(s, "-ticker-morph-speed")
elif s.startswith("-animation-speed"):
cls.animSpeed = parseFloat(s, "-animation-speed")
elif s.startswith("-fps"):
cls.fps = int(parseFloat(s, "-fps"))
elif s.startswith("-h") or s.startswith("-help"):
QtGui.QMessageBox.warning(None, "Arguments",
"Usage: qtdemo.py [-verbose] [-no-adapt] [-opengl] "
"[-direct3d] [-software] [-fullscreen] [-ticker[0|1]] "
"[-animations[0|1]] [-no-blending] [-no-sync] "
"[-use-timer-update[0|1]] [-pause[0|1]] "
"[-use-window-mask] [-no-rescale] [-use-pixmaps] "
"[-show-fps] [-show-br] [-8bit[0|1]] [-menu<int>] "
"[-use-loop] [-use-balls] [-animation-speed<float>] "
"[-fps<int>] [-low] [-ticker-letters<int>] "
"[-ticker-speed<float>] [-no-ticker-morph] "
"[-ticker-morph-speed<float>] [-ticker-text<string>]")
sys.exit(0)
cls.postConfigure()
@classmethod
def setLowSettings(cls):
cls.openGlRendering = False
cls.direct3dRendering = False
cls.softwareRendering = True
cls.noTicker = True
cls.noTimerUpdate = True
cls.fps = 30
cls.usePixmaps = True
cls.noAnimations = True
cls.noBlending = True
@classmethod
def detectSystemResources(cls):
try:
from PyQt4 import QtOpenGL
cls.openGlAvailable = True
except ImportError:
cls.openGlAvailable = False
if cls.openGlAvailable:
version_flags = QtOpenGL.QGLFormat.openGLVersionFlags()
if version_flags & QtOpenGL.QGLFormat.OpenGL_Version_2_0:
cls.glVersion = "2.0 or higher"
elif version_flags & QtOpenGL.QGLFormat.OpenGL_Version_1_5:
cls.glVersion = "1.5"
elif version_flags & QtOpenGL.QGLFormat.OpenGL_Version_1_4:
cls.glVersion = "1.4"
elif version_flags & QtOpenGL.QGLFormat.OpenGL_Version_1_3:
cls.glVersion = "1.3 or lower"
cls.debug("- OpenGL version:", cls.glVersion)
glw = QtOpenGL.QGLWidget()
if (not QtOpenGL.QGLFormat.hasOpenGL() or
not glw.format().directRendering() or
not (version_flags & QtOpenGL.QGLFormat.OpenGL_Version_1_5) or
glw.depth() < 24):
cls.openGlAdequate = False
cls.debug("- OpenGL not recommended on this system")
else:
cls.openGlAdequate = False
cls.debug("- OpenGL not supported by current build of Qt")
if sys.platform == 'win32':
# For now.
cls.direct3dAvailable = False
# Check if X Render is present.
if hasattr(QtGui.QPixmap, 'x11PictureHandle'):
tmp = QtGui.QPixmap(1, 1)
if not tmp.x11PictureHandle():
cls.xRenderPresent = False
cls.debug("- X render not present")
w = QtGui.QWidget()
cls.debug("- Color depth: %d" % w.depth())
@classmethod
def postConfigure(cls):
if not cls.noAdapt:
w = QtGui.QWidget()
if w.depth() < 16:
cls.useEightBitPalette = True
cls.adapted = True
cls.debug("- Adapt: Color depth less than 16 bit. Using 8 bit palette")
if not cls.xRenderPresent:
cls.setLowSettings()
cls.adapted = True
cls.debug("- Adapt: X renderer not present. Using low settings")
if sys.platform != 'win32':
if cls.direct3dRendering:
cls.direct3dRendering = False
cls.debug("- WARNING: Direct3D specified, but not supported on this platform")
if (not cls.openGlRendering and not cls.direct3dRendering and
not cls.softwareRendering):
# The user has not specified a rendering system so we do it.
if sys.platform == 'win32':
if cls.direct3dAvailable:
cls.direct3dRendering = True
if not cls.direct3dRendering:
if cls.openGlAdequate:
cls.openGlRendering = True
else:
cls.softwareRendering = True
def parseFloat(argument, name):
try:
value = float(parseText(argument, name))
except ValueError:
value = 0.0
return value
def parseText(argument, name):
if len(name) == len(argument):
QtGui.QMessageBox.warning(None, "Arguments",
"No argument number found for %s. Remember to put name and "
"value adjacent! (e.g. -fps100)")
sys.exit(0)
return argument[len(name):]
|