1############################################################################# 2## 3## Copyright (C) 2013 Riverbank Computing Limited. 4## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 5## All rights reserved. 6## 7## This file is part of the examples of PyQt. 8## 9## $QT_BEGIN_LICENSE:LGPL$ 10## Commercial Usage 11## Licensees holding valid Qt Commercial licenses may use this file in 12## accordance with the Qt Commercial License Agreement provided with the 13## Software or, alternatively, in accordance with the terms contained in 14## a written agreement between you and Nokia. 15## 16## GNU Lesser General Public License Usage 17## Alternatively, this file may be used under the terms of the GNU Lesser 18## General Public License version 2.1 as published by the Free Software 19## Foundation and appearing in the file LICENSE.LGPL included in the 20## packaging of this file. Please review the following information to 21## ensure the GNU Lesser General Public License version 2.1 requirements 22## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 23## 24## In addition, as a special exception, Nokia gives you certain additional 25## rights. These rights are described in the Nokia Qt LGPL Exception 26## version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27## 28## GNU General Public License Usage 29## Alternatively, this file may be used under the terms of the GNU 30## General Public License version 3.0 as published by the Free Software 31## Foundation and appearing in the file LICENSE.GPL included in the 32## packaging of this file. Please review the following information to 33## ensure the GNU General Public License version 3.0 requirements will be 34## met: http://www.gnu.org/copyleft/gpl.html. 35## 36## If you have questions regarding the use of this file, please contact 37## Nokia at qt-info@nokia.com. 38## $QT_END_LICENSE$ 39## 40############################################################################# 41 42 43import sys 44 45from PyQt5.QtGui import QColor, QFont 46from PyQt5.QtWidgets import QMessageBox, QWidget 47 48 49class Colors(object): 50 # Colors: 51 sceneBg1 = QColor(91, 91, 91) 52 sceneBg1Line = QColor(114, 108, 104) 53 sceneBg2 = QColor(0, 0, 0) 54 sceneLine = QColor(255, 255, 255) 55 paperBg = QColor(100, 100, 100) 56 menuTextFg = QColor(255, 0, 0) 57 buttonBgLow = QColor(255, 255, 255, 90) 58 buttonBgHigh = QColor(255, 255, 255, 20) 59 buttonText = QColor(255, 255, 255) 60 tt_green = QColor(166, 206, 57) 61 fadeOut = QColor(206, 246, 117, 0) 62 heading = QColor(190, 230, 80) 63 contentColor = "<font color='#eeeeee'>" 64 glVersion = "Not detected!" 65 66 # Guides: 67 stageStartY = 8 68 stageHeight = 536 69 stageStartX = 8 70 stageWidth = 785 71 contentStartY = 22 72 contentHeight = 510 73 74 # Properties: 75 noTicker = False 76 noRescale = False 77 noAnimations = False 78 noBlending = False 79 noScreenSync = False 80 fullscreen = False 81 usePixmaps = False 82 useLoop = False 83 showBoundingRect = False 84 showFps = False 85 noAdapt = False 86 noWindowMask = True 87 useButtonBalls = False 88 useEightBitPalette = False 89 noTimerUpdate = False 90 noTickerMorph = False 91 adapted = False 92 verbose = False 93 pause = True 94 95 fps = 100 96 menuCount = 18 97 animSpeed = 1.0 98 benchmarkFps = -1.0 99 tickerLetterCount = 80; 100 tickerMoveSpeed = 0.4 101 tickerMorphSpeed = 2.5 102 tickerText = ".EROM ETAERC .SSEL EDOC" 103 rootMenuName = "PyQt Examples" 104 105 @staticmethod 106 def contentFont(): 107 font = QFont() 108 font.setStyleStrategy(QFont.PreferAntialias) 109 110 if sys.platform == 'darwin': 111 font.setPixelSize(14) 112 font.setFamily('Arial') 113 else: 114 font.setPixelSize(13) 115 font.setFamily('Verdana') 116 117 return font 118 119 @staticmethod 120 def headingFont(): 121 font = QFont() 122 font.setStyleStrategy(QFont.PreferAntialias) 123 124 font.setPixelSize(23) 125 font.setBold(True) 126 font.setFamily('Verdana') 127 128 return font; 129 130 @staticmethod 131 def buttonFont(): 132 font = QFont() 133 font.setStyleStrategy(QFont.PreferAntialias) 134 135 font.setPixelSize(11) 136 font.setFamily('Verdana') 137 138 return font 139 140 @staticmethod 141 def tickerFont(): 142 font = QFont() 143 font.setStyleStrategy(QFont.PreferAntialias) 144 145 if sys.platform == 'darwin': 146 font.setPixelSize(11) 147 font.setBold(True) 148 font.setFamily('Arial') 149 else: 150 font.setPixelSize(10) 151 font.setBold(True) 152 font.setFamily('sans serif') 153 154 return font 155 156 @classmethod 157 def debug(cls, *args): 158 if cls.verbose: 159 sys.stderr.write("%s\n" % " ".join([str(arg) for arg in args])) 160 161 @classmethod 162 def parseArgs(cls, argv): 163 # Some arguments should be processed before others. Handle them now. 164 if "-verbose" in argv: 165 cls.verbose = True 166 167 # Handle the rest of the arguments. They may override attributes 168 # already set. 169 for s in argv: 170 if s == "-no-ticker": 171 cls.noTicker = True 172 elif s.startswith("-ticker"): 173 cls.noTicker = not bool(parseFloat(s, "-ticker")) 174 elif s == "-no-animations": 175 cls.noAnimations = True 176 elif s.startswith("-animations"): 177 cls.noAnimations = not bool(parseFloat(s, "-animations")) 178 elif s == "-no-adapt": 179 # Don't adapt the animations based on the actual performance. 180 cls.noAdapt = True 181 elif s == "-low": 182 cls.setLowSettings() 183 elif s == "-no-rescale": 184 cls.noRescale = True 185 elif s == "-use-pixmaps": 186 cls.usePixmaps = True 187 elif s == "-fullscreen": 188 cls.fullscreen = True 189 elif s == "-show-br": 190 cls.showBoundingRect = True 191 elif s == "-show-fps": 192 cls.showFps = True 193 elif s == "-no-blending": 194 cls.noBlending = True 195 elif s == "-no-sync": 196 cls.noScreenSync = True 197 elif s.startswith("-menu"): 198 cls.menuCount = int(parseFloat(s, "-menu")) 199 elif s.startswith("-use-timer-update"): 200 cls.noTimerUpdate = not bool(parseFloat(s, "-use-timer-update")) 201 elif s.startswith("-pause"): 202 cls.pause = bool(parseFloat(s, "-pause")) 203 elif s == "-no-ticker-morph": 204 cls.noTickerMorph = True 205 elif s == "-use-window-mask": 206 cls.noWindowMask = False 207 elif s == "-use-loop": 208 cls.useLoop = True 209 elif s == "-use-8bit": 210 cls.useEightBitPalette = True 211 elif s.startswith("-8bit"): 212 cls.useEightBitPalette = bool(parseFloat(s, "-8bit")) 213 elif s == "-use-balls": 214 cls.useButtonBalls = True 215 elif s.startswith("-ticker-letters"): 216 cls.tickerLetterCount = int(parseFloat(s, "-ticker-letters")) 217 elif s.startswith("-ticker-text"): 218 cls.tickerText = parseText(s, "-ticker-text") 219 elif s.startswith("-ticker-speed"): 220 cls.tickerMoveSpeed = parseFloat(s, "-ticker-speed") 221 elif s.startswith("-ticker-morph-speed"): 222 cls.tickerMorphSpeed = parseFloat(s, "-ticker-morph-speed") 223 elif s.startswith("-animation-speed"): 224 cls.animSpeed = parseFloat(s, "-animation-speed") 225 elif s.startswith("-fps"): 226 cls.fps = int(parseFloat(s, "-fps")) 227 elif s.startswith("-h") or s.startswith("-help"): 228 QMessageBox.warning(None, "Arguments", 229 "Usage: qtdemo.py [-verbose] [-no-adapt] " 230 "[-fullscreen] [-ticker[0|1]] " 231 "[-animations[0|1]] [-no-blending] [-no-sync] " 232 "[-use-timer-update[0|1]] [-pause[0|1]] " 233 "[-use-window-mask] [-no-rescale] [-use-pixmaps] " 234 "[-show-fps] [-show-br] [-8bit[0|1]] [-menu<int>] " 235 "[-use-loop] [-use-balls] [-animation-speed<float>] " 236 "[-fps<int>] [-low] [-ticker-letters<int>] " 237 "[-ticker-speed<float>] [-no-ticker-morph] " 238 "[-ticker-morph-speed<float>] [-ticker-text<string>]") 239 sys.exit(0) 240 241 cls.postConfigure() 242 243 @classmethod 244 def setLowSettings(cls): 245 cls.noTicker = True 246 cls.noTimerUpdate = True 247 cls.fps = 30 248 cls.usePixmaps = True 249 cls.noAnimations = True 250 cls.noBlending = True 251 252 @classmethod 253 def postConfigure(cls): 254 if not cls.noAdapt: 255 w = QWidget() 256 257 if w.depth() < 16: 258 cls.useEightBitPalette = True 259 cls.adapted = True 260 cls.debug("- Adapt: Color depth less than 16 bit. Using 8 bit palette") 261 262 263def parseFloat(argument, name): 264 try: 265 value = float(parseText(argument, name)) 266 except ValueError: 267 value = 0.0 268 269 return value 270 271 272def parseText(argument, name): 273 if len(name) == len(argument): 274 QMessageBox.warning(None, "Arguments", 275 "No argument number found for %s. Remember to put name and " 276 "value adjacent! (e.g. -fps100)") 277 sys.exit(0) 278 279 return argument[len(name):] 280