Module gpanel
[frames] | no frames]

Source Code for Module gpanel

   1  # gpanel.py 
   2  # Version 0.96; Oct 20, 2016 
   3   
   4  ''' 
   5  Module to create a graphics window of default size 501x501 pixels (client drawing area) 
   6  using a coordinate system with x-axis from left to right, y-axis from bottom to top 
   7  (called user coordinates, default range 0..1, 0..1). 
   8   
   9  The module provides a global namespace for GPanel class methods. 
  10   
  11  The drawing methods perform drawing operation in an offscreen buffer (QPixmap) 
  12  and automatically renders it on the screen, so the graphics is shown step-by-step. 
  13   
  14  User coordinates:  (ux, uy) 
  15  Pixel coordinates: (px, py) (screen pixels) 
  16  Transformation: px = px(ux), py = py(uy) 
  17  Pixel coordinate range: 0..winWidth, 0..winHeight (0,0) upper left corner, x to the right, y downwards 
  18  User coordinate range: xmin..xmax, ymin..ymax (0,0) lower left corner, x to the right, y upwards. 
  19   
  20  Transformation: user(ux, uy) to pixel(px, py) 
  21  px = a * ux + b 
  22  py = c * uy + d 
  23  with a = winWidth / (xmax - xmin) 
  24  b = winWidth * xmin / (xmin - xmax) 
  25  c = winHeight / (ymin - ymax) 
  26  d = winHeight * ymax / (ymax - ymin) 
  27   
  28  Inverse: 
  29  ux = (px - b) / a 
  30  uy = (py - d) / c 
  31   
  32  WARNING: Because PyQt is not thread-safe, in principle all graphics drawings should be 
  33  executed in the GUI thread (for GPanel the main thread or a GUI callback). 
  34   
  35  Typical program: 
  36   
  37  from gpanel import * 
  38   
  39  makeGPanel(0, 10, 0, 10) 
  40  for ypt in range(0, 11, 1): 
  41      line(0, ypt, 10 - ypt, 0) 
  42      time.sleep(0.1) # to see what happens 
  43  keep() 
  44   
  45  keep() is blocking and keeps the graphics window open until the close button is hit or the 
  46  Python process terminates. 
  47  ''' 
  48   
  49  from __future__ import division 
  50  from PyQt4 import QtGui, QtCore 
  51  from PyQt4.QtGui import * 
  52  from PyQt4.QtCore import * 
  53  import thread 
  54  import sys, time, math 
  55  import random 
  56   
  57  _p = None 
58 59 -class _WindowNotInitialized(Exception): pass
60
61 -def _isGPanelValid():
62 if _p == None: 63 raise _WindowNotInitialized("Use \"makeGPanel()\" to create the graphics window before calling GPanel methods.")
64
65 -def makeGPanel(*args, **kwargs):
66 ''' 67 Constructs a GPanel and displays a non-resizable graphics window. 68 Defaults with no parameter: 69 Window size: 500x500 pixels 70 Window title: "GPanel". 71 User coordinates: 0, 1, 0, 1. 72 Background color: white. 73 Pen color: black. 74 Pen size: 1. 75 76 1 Parameter: Size(window_width, window_height). 77 4 Parameters: xmin, xmax, ymin, ymax. 78 79 KEEP IN MIND: To use GUI callbacks, the main program must block in the keep() function. 80 @param Size: a Size reference to define the dimension of the graphics windows. 81 @param xmin: left x user coordinate 82 @param xmax: right x user coordinate 83 @param ymin: lower y user coordinate 84 @param ymax: upper y user coordinate 85 @param kwargs: mousePressed, mouseReleased, mouseDragged, keyPressed, keyReleased, closed 86 ''' 87 global _p 88 89 if _p == None: 90 _p = GPanel(*args) 91 92 for key in kwargs: 93 if key == "mousePressed": 94 _p.addMousePressListener(kwargs[key]) 95 elif key == "mouseReleased": 96 _p.addMouseReleaseListener(kwargs[key]) 97 elif key == "mouseDragged": 98 _p.addMouseDragListener(kwargs[key]) 99 elif key == "keyPressed": 100 _p.addKeyPressListener(kwargs[key]) 101 elif key == "keyReleased": 102 _p.addKeyReleaseListener(kwargs[key]) 103 elif key == "closed": 104 _p.addCloseListener(kwargs[key]) 105 return _p
106
107 -def addCloseListener(closeListener):
108 ''' 109 Registers the given function that is called when the title bar 110 close button is hit. 111 112 If a listener (!= None) is registered, the automatic closing is disabled. 113 To close the window, call sys.exit(). 114 115 KEEP IN MIND: To use GUI callbacks, the main program must block in the keep() function. 116 @param closeListener: a callback function called when the close button is hit 117 ''' 118 _isGPanelValid() 119 _p.addCloseListener(closeListener)
120
121 -def addKeyPressListener(onKeyPressed):
122 ''' 123 Registers a callback that is invoked when a key is pressed (and the graphics window has the focus). 124 125 KEEP IN MIND: To use GUI callbacks, the main program must block in the keep() function. 126 @param onKeyPressed: a callback function called when a key is pressed 127 ''' 128 _isGPanelValid() 129 _p.addKeyPressListener(onKeyPressed)
130
131 -def addKeyReleaseListener(onKeyReleased):
132 ''' 133 Registers a callback that is invoked when a key is released (and the graphics window has the focus). 134 135 KEEP IN MIND: To use GUI callbacks, the main program must block in the keep() function. 136 @param onKeyReleased: a callback function called when a key is pressed 137 ''' 138 _isGPanelValid() 139 _p.addKeyReleaseListener(onKeyReleased)
140
141 -def addMouseDragListener(onMouseDragged):
142 ''' 143 Registers a callback that is invoked when the mouse is moved while a mouse button is pressed (drag). 144 145 KEEP IN MIND: To use GUI callbacks, the main program must block in the keep() function. 146 @param onMouseDragged: a callback function called when the moused is dragged 147 ''' 148 _isGPanelValid() 149 _p.addMouseMoveListener(onMouseDragged)
150
151 -def addMousePressListener(onMousePressed):
152 ''' 153 Registers a callback that is invoked when a mouse button is pressed. 154 Use isLeftMouseButton() or isRightMouseButton() to check which button used. 155 156 KEEP IN MIND: To use GUI callbacks, the main program must block in the keep() function. 157 @param onMousePressed: a callback function called when a mouse button is pressed 158 ''' 159 _isGPanelValid() 160 _p.addMousePressListener(onMousePressed)
161
162 -def addMouseReleaseListener(onMouseReleased):
163 ''' 164 Registers a callback that is invoked when a mouse button is releases. 165 Use isLeftMouseButton() or isRightMouseButton() to check which button used. 166 167 KEEP IN MIND: To use GUI callbacks, the main program must block in the keep() function. 168 @param onMouseReleased: a callback function called when a mouse button is released 169 ''' 170 _isGPanelValid() 171 _p.addMouseReleaseListener(onMouseReleased)
172
173 -def arc(radius, startAngle, spanAngle):
174 ''' 175 Draws a circle sector with center at the current graph cursor position, 176 given radius and given start and span angles. 177 @param radius: the radius of the arc 178 @param startAngle: starting angle in degrees, zero to east, positive counter-clockwise 179 @param spanAngle: span angle (sector angle) in degrees, positive counter-clockwise 180 ''' 181 _isGPanelValid() 182 _p.arc(radius, startAngle, spanAngle)
183
184 -def bgColor(*args):
185 ''' 186 Same as setBgColor(). 187 ''' 188 setBgColor(*args)
189
190 -def chord(radius, startAngle, spanAngle):
191 ''' 192 Draws a circle chord with center at the current graph cursor position, 193 given radius and given start and span angles (in degrees, positive 194 counter-clockwise, zero to east). 195 @param radius: the radius of the arc 196 @param startAngle: starting angle in degrees, zero to east, positive counter-clockwise 197 @param spanAngle: span angle (sector angle) in degrees, positive counter-clockwise 198 ''' 199 _isGPanelValid() 200 _p.chord(radius, startAngle, spanAngle)
201
202 -def circle(radius):
203 ''' 204 Draws a circle with center at the current graph cursor position 205 with given radius in horizontal window coordinates. 206 @param radius: the radius of the circle 207 ''' 208 _isGPanelValid() 209 _p.circle(radius)
210
211 -def clear():
212 ''' 213 Clears the graphics window and the offscreen buffer used by the window 214 (fully paint with background color). 215 Sets the current graph cursor position to (0, 0). 216 If enableRepaint(false) only clears the offscreen buffer. 217 ''' 218 _isGPanelValid() 219 _p.clear()
220
221 -def delay(delayTime):
222 ''' 223 Stop execution for given delay time. 224 @param delayTime: the delay time (in ms) 225 ''' 226 time.sleep(delayTime / 1000.0)
227
228 -def draw(*args):
229 ''' 230 Draws a line form current graph cursor position to (x, y). 231 Sets the graph cursor position to (x, y). 232 Also with one parameter of type complex, list or tuple. 233 @param x: the x coordinate of the target point 234 @param y: the y coordinate of the target point 235 @param target: (alternative) the target point as complex, list or tuple 236 ''' 237 x, y = _getCoords(*args) 238 _isGPanelValid() 239 _p.draw(x, y)
240
241 -def drawGrid(*args):
242 ''' 243 Draws a coordinate system with annotated axes. 244 (You must increase the user coordinate system at least 10% in both directions.) 245 246 Overloaded variants: 247 248 drawGrid(x, y): Grid with 10 ticks in range 0..x, 0..y. Label text depends if x, y or int or float 249 250 drawGrid(x, y, color): same with given grid color 251 252 drawGrid(x1, x2, y1, y2): same with given span x1..x2, y1..y2 253 254 drawGrid(x1, x2, y1, y2, color): same with given grid color 255 256 drawGrid(x1, x2, y1, y2, x3, y3): same with given number of ticks x3, y3 in x- and y-direction 257 ''' 258 _isGPanelValid() 259 _p.drawGrid(*args)
260
261 -def ellipse(a, b):
262 ''' 263 Draws an ellipse with center at the current graph cursor position 264 with given axes. 265 @param a: the major ellipse axis 266 @param b: the minor ellipse axis 267 ''' 268 _isGPanelValid() 269 _p.ellipse(a, b)
270
271 -def enableRepaint(enable):
272 ''' 273 Enables/Disables automatic repaint in graphics drawing methods. 274 @param enable: if True, the automatic repaint is enabled; otherwise disabled 275 ''' 276 _isGPanelValid() 277 _p.enableRepaint(enable)
278
279 -def erase():
280 ''' 281 Same as clear(), but lets the current graph cursor unganged. 282 ''' 283 _isGPanelValid() 284 _p.erase()
285
286 -def fill(x, y, color):
287 ''' 288 Fills (flood fill) the closed unicolored region with the inner point (x, y) with 289 the given color (RGB, RGBA or X11 color string). The old color to replace is 290 the color of the pixel at x, y. 291 @param x: the x coordinate of the inner point 292 @param y: the y coordinate of the inner point 293 @color: the replacement color (RGB list/tuple or X11 color string) 294 ''' 295 _isGPanelValid() 296 _p.fill(x, y, color)
297
298 -def fillArc(radius, startAngle, spanAngle):
299 ''' 300 Draws a filled circle sector with center at the current graph cursor position, 301 given radius and given start and span angles (in degrees, positive 302 counter-clockwise, zero to east). (fill color = pen color) 303 @param radius: the radius of the arc 304 @param startAngle: starting angle in degrees, zero to east, positive counter-clockwise 305 @param spanAngle: span angle (sector angle) in degrees, positive counter-clockwise 306 ''' 307 _isGPanelValid() 308 _p.fillArc(radius, startAngle, spanAngle)
309
310 -def fillChord(radius, startAngle, spanAngle):
311 ''' 312 Draws a filled circle chord with center at the current graph cursor position, 313 given radius and given start and span angles (in degrees, positive 314 counter-clockwise, zero to east). (fill color = pen color) 315 @param radius: the radius of the arc 316 @param startAngle: starting angle in degrees, zero to east, positive counter-clockwise 317 @param spanAngle: span angle (sector angle) in degrees, positive counter-clockwise 318 ''' 319 _isGPanelValid() 320 _p.fillChord(radius, startAngle, spanAngle)
321
322 -def fillCircle(radius):
323 ''' 324 Draws a filled circle with center at the current graph cursor position 325 with given radius in horizontal window coordinates (fill color = pen color). 326 @param radius: the radius of the circle 327 ''' 328 _isGPanelValid() 329 _p.fillCircle(radius)
330
331 -def fillEllipse(a, b):
332 ''' 333 Draws a filled ellipse with center at the current graph cursor position 334 with given axes (fill color = pen color). 335 @param a: the major ellipse axis 336 @param b: the minor ellipse axis 337 ''' 338 _isGPanelValid() 339 _p.fillEllipse(a, b)
340
341 -def fillPath(color):
342 ''' 343 Closes the path started with startPath() and shows a filled polygon from the saved 344 draw() positions with given color. 345 ''' 346 _isGPanelValid() 347 _p.fillPath(color)
348
349 -def fillPolygon(corners):
350 ''' 351 Draws a filled polygon with given list of vertexes (list of x, y) 352 (fill color = pen color). 353 @param corners: a list /tuple of the corner points (x, y) list/tuple 354 ''' 355 _isGPanelValid() 356 _p.fillPolygon(corners)
357
358 -def fillRectangle(*args):
359 ''' 360 Draws a filled rectangle (fill color = pen color). 361 2 parameters: Center at the current graph cursor position 362 and given width and height 363 4 parameters: Given diagonal 364 ''' 365 _isGPanelValid() 366 _p.fillRectangle(*args)
367
368 -def getDividingPoint(*args):
369 ''' 370 Returns the tuple of user coordinates of the point on the line through the point pt1 = (x1, y1) 371 and the point pt2 = (x2, y2) that is in distance ratio times the length from pt1 to pt2 from 372 pt1. For ratio < 0 the point is in the opposite direction. 373 3 parameteters: pt1, pt2 (complex/list/tuple), ratio 374 5 parameteters: x1, y1, x2, y2, ratio 375 ''' 376 if len(args) == 5: 377 x1 = args[0] 378 y1 = args[1] 379 x2 = args[2] 380 y2 = args[3] 381 ratio = args[4] 382 elif len(args) == 3: 383 x1, y1, x2, y2 = _get2Coords(args[0], args[1]) 384 ratio = args[2] 385 else: 386 raise ValueError("Illegal number of parameters.") 387 _isGPanelValid() 388 return _p.getDividingPoint(x1, y1, x2, y2, ratio)
389
390 -def getPainter():
391 ''' 392 Returns the QPainter reference used to draw into the offscreen buffer. 393 ''' 394 _isGPanelValid() 395 return _p.getPainter()
396
397 -def getPixelColor(*args):
398 ''' 399 Returns the RGBA color tuple of a pixel with given user coordinates. 400 No params: Returns color at current graph cursor position. 401 ''' 402 _isGPanelValid() 403 return _p.getPixelColor(*args)
404
405 -def getPos():
406 ''' 407 Returns a tuple with current graph cursor position (tuple, user coordinates). 408 ''' 409 _isGPanelValid() 410 return _p.getPos()
411
412 -def getPosX():
413 ''' 414 Returns the current graph cursor x-position (user coordinates). 415 @return: x coordinate of graph cursor 416 @rtype: float 417 ''' 418 _isGPanelValid() 419 return _p.getPosX()
420
421 -def getPosY():
422 ''' 423 Returns the current graph cursor y-position (user coordinates). 424 @return: y coordinate of graph cursor 425 @rtype: float 426 ''' 427 _isGPanelValid() 428 return _p.getPosY()
429
430 -def getScreenWidth():
431 ''' 432 Returns the width of the screen (in pixels). 433 @return: screen width 434 @rtype: int 435 ''' 436 return GPanel.getScreenWidth()
437
438 -def getScreenHeight():
439 ''' 440 Returns the height of the screen (in pixels). 441 @return: screen height 442 @rtype: int 443 ''' 444 return GPanel.getScreenHeight()
445
446 -def imageFromData(data, pic_format, x, y):
447 ''' 448 Draws the picture with given string data in JPEG format at user coordinates of lower left corner. 449 @param data: picture data stream in string format 450 @param pic_format: format of picture, supported: "GIF", "JPG", "BMP", "PNG", 451 "PBM", "PGM", "PPM", "TIFF", "XBM" "XPM" 452 @param x: x coordinate of lower left corner 453 @param y: y coordinate of lower left corner 454 @return: True, if operation is successful; otherwise false 455 @rtype: boolean 456 ''' 457 _isGPanelValid() 458 img = QImage() 459 rc = img.loadFromData(data, pic_format) 460 if rc: 461 image(img, x, y) 462 return True 463 return False
464
465 -def image(*args):
466 ''' 467 Draws the picture with given file path or given image at given upper-left coordinates. 468 1st parameter: image path (string) or QImage reference 469 2nd, 3rd parameters: llx, lly (lower left corner in user coordinates) 470 ''' 471 _isGPanelValid() 472 _p.showImage(*args)
473
474 -def isLeftMouseButton():
475 ''' 476 Returns True, if the last mouse action was performed with the left mouse button. 477 ''' 478 _isGPanelValid() 479 return _p.isLeftMouseButton()
480
481 -def isRightMouseButton():
482 ''' 483 Returns True, if the last mouse action was performed with the right mouse button. 484 ''' 485 _isGPanelValid() 486 return _p.isRightMouseButton()
487
488 -def keep():
489 ''' 490 Blocks until the title bar's close button is hit. Then cleans up 491 the graphics system. 492 ''' 493 _isGPanelValid() 494 _p.keep()
495
496 -def line(*args):
497 ''' 498 Draws a line with given user start and end coordinates 499 and sets the graph cursor position to the end point. 500 Also with 2 parameters of type complex, list or tuple. 501 4 parameters: x1, y1, x2, y2 502 2 parameters: pt1, pt2 as complex/list/tuple 503 ''' 504 x1, y1, x2, y2 = _get2Coords(*args) 505 _isGPanelValid() 506 _p.line(x1, y1, x2, y2)
507
508 -def lineWidth(width):
509 ''' 510 Sets the current pen size (width) (>=1). 511 Returns the previouis pen size. 512 513 Same as setPenSize(). For TigerJython compatiblity. 514 @param width: the pen width (>=1) 515 ''' 516 setPenSize(width)
517
518 -def makeColor(r, g, b):
519 ''' 520 Returns the tuple (r, g, b). For compatibility with TigerJython. 521 ''' 522 return (r, g, b)
523
524 -def move(*args):
525 ''' 526 Sets the current graph cursor position to given user coordinates. 527 (without drawing anything). 528 Also with 1 parameter of type complex, list or tuple. 529 530 Same as pos(). 531 @param x: the x coordinate of the target point 532 @param y: the y coordinate of the target point 533 @param target: (alternative) the target point as complex, list or tuple 534 ''' 535 pos(*args)
536
537 -def point(*args):
538 ''' 539 Draws a single point with current pen size and pen color at given user coordinates. 540 No params: draws a current graph cursor position 541 @param x: the x coordinate of the target point 542 @param y: the y coordinate of the target point 543 @param target: (alternative) the target point as complex, list or tuple 544 ''' 545 _isGPanelValid() 546 _p.point(*args)
547
548 -def pos(*args):
549 ''' 550 Sets the current graph cursor position to given user coordinates (x, y). 551 (without drawing anything). 552 Also with 1 parameter of type complex, list or tuple. 553 554 Same as move(). 555 @param x: the x coordinate of the target point 556 @param y: the y coordinate of the target point 557 @param target: (alternative) the target point as complex, list or tuple 558 ''' 559 x, y = _getCoords(*args) 560 _isGPanelValid() 561 _p.pos(x, y)
562
563 -def polygon(corners):
564 ''' 565 Draws a polygon with given list of vertexes (list of x, y). 566 @param corners: a list /tuple of the corner points (x, y) list/tuple 567 ''' 568 _isGPanelValid() 569 _p.polygon(corners)
570
571 -def rectangle(*args):
572 ''' 573 Draws a rectangle. 574 2 parameters: Center at the current graph cursor position 575 and given width and height. 576 4 parameters: Given diagonal 577 ''' 578 _isGPanelValid() 579 _p.rectangle(*args)
580
581 -def repaint():
582 ''' 583 Renders the offscreen buffer in the graphics window. 584 ''' 585 _isGPanelValid() 586 _p.repaint()
587
588 -def recallGraphics():
589 ''' 590 Restores the saved graphics from the image buffer. Use saveGraphics() 591 to save it. 592 593 Same as restoreGraphics() (for TigerJython compatibility). 594 ''' 595 restoreGraphics()
596
597 598 -def restoreGraphics():
599 ''' 600 Restores the saved graphics from the image buffer. Use saveGraphics() 601 to save it. 602 ''' 603 _isGPanelValid() 604 _p.restoreGraphics()
605
606 -def saveGraphics():
607 ''' 608 Saves the current graphics into a image buffer. Use restoreGraphics() 609 to restore it. 610 ''' 611 _isGPanelValid() 612 _p.saveGraphics()
613
614 -def setBgColor(*args):
615 ''' 616 Sets the background color. All drawings are erased and the current 617 graph cursor is set to (0, 0). 618 1 parameter: value considered as X11 color string 619 3 parameters: values considered as RGB (alpha = 255) 620 4 parameters: values considered as RGBA 621 ''' 622 _isGPanelValid() 623 return _p.setBgColor(*args)
624
625 -def setColor(*args):
626 ''' 627 Sets the current pen color. 628 1 parameter: - string value considered as X11 color string 629 - list considered as [r, b, g] or [r, g, b, a] 630 - tuple considered as (r, b, g) or (r, g, b, a) 631 3 parameters: values considered as RGB (alpha = 255) 632 4 parameters: values considered as RGBA 633 634 Same as setPenColor(). For TigerJython compatiblity. 635 ''' 636 return setPenColor(*args)
637
638 -def setPaintMode():
639 ''' 640 Resets the drawing mode to standard (overwriting). 641 ''' 642 _isGPanelValid() 643 _p.setPaintMode()
644
645 -def setPenColor(*args):
646 ''' 647 Sets the current pen color. 648 1 parameter: - string value considered as X11 color string 649 - list considered as [r, b, g] or [r, g, b, a] 650 - tuple considered as (r, b, g) or (r, g, b, a) 651 3 parameters: values considered as RGB (alpha = 255) 652 4 parameters: values considered as RGBA 653 ''' 654 _isGPanelValid() 655 return _p.setPenColor(*args)
656
657 -def setPenSize(size):
658 ''' 659 Sets the current pen size (width) (>=1). 660 Returns the previouis pen size. 661 Same as lineWidth(). 662 @param width: the pen width (>=1) 663 ''' 664 _isGPanelValid() 665 return _p.setPenSize(size)
666
667 -def setTitle(title):
668 ''' 669 Sets the title in the window title bar. 670 @param title: the title text 671 ''' 672 _isGPanelValid() 673 return _p.setTitle(size)
674
675 -def setUserCoords(xmin, xmax, ymin, ymax):
676 ''' 677 Set user coordinate system left_x, right_x, bottom_y, top_y. 678 @param xmin: the x coordinate at left border 679 @param xmax: the x coordinate at right border 680 @param ymin: the y coordinate at bottom border 681 @param ymax: the y coordinate at top border 682 ''' 683 _isGPanelValid() 684 _p.setUserCoords(xmin, xmax, ymin, ymax)
685
686 -def setWindowCenter():
687 ''' 688 Sets the screen position to the center of the screen. 689 ''' 690 _isGPanelValid() 691 _p.setWindowCenter()
692
693 -def setWindowPos(ulx, uly):
694 ''' 695 Sets the screen position of the graphics window. 696 @param ulx: the upper left corner's x-coordinate 697 @param ulx: the upper left corner's y-coordinate 698 ''' 699 _isGPanelValid() 700 _p.setWindowPos(ulx, uly)
701
702 -def setXORMode():
703 ''' 704 Performs pixel color XOR operation with the existing background pixel. 705 Be aware that if the background is white, drawing with a white pen shows a black pixel. 706 ''' 707 _isGPanelValid() 708 _p.setXORMode()
709
710 -def startPath():
711 ''' 712 Starts recording the path vertexes. The positions of subsequent draw() operations are saved. 713 The path is used to show a filled polygon when fillPath() is called. 714 ''' 715 _isGPanelValid() 716 _p.startPath()
717
718 -def storeGraphics():
719 ''' 720 Saves the current graphics into a image buffer. Use restoreGraphics() 721 to restore it. 722 723 Same as saveGraphics() (for TigerJython compatibility). 724 ''' 725 saveGraphics()
726
727 -def text(*args):
728 ''' 729 Draws a text at given position (user coordinates). 730 1 parameter: at current graph cursor position 731 2 parameters: target point (comolex/list/tuple), text 732 3 parameters: x, y, text 733 ''' 734 _isGPanelValid() 735 _p.text(*args)
736
737 -def title(title):
738 ''' 739 Sets the title in the window title bar. 740 Same as setTitle(), for TigerJython compatibility. 741 @param title: the title text 742 ''' 743 _isGPanelValid() 744 _p.setTitle(title)
745
746 -def toPixel(user):
747 ''' 748 Returns pixel coordinates (tuple) of given user coordinates (tuple). 749 ''' 750 _isGPanelValid() 751 return _p.toPixel(user)
752
753 -def toPixelHeight(userHeight):
754 ''' 755 Returns pixel y-increment of given user y-increment (always positive). 756 ''' 757 _isGPanelValid() 758 return p.toPixelHeight(userHeight)
759
760 -def toPixelWidth(userWidth):
761 ''' 762 Returns pixel x-increment of given user x-increment (always positive). 763 ''' 764 _isGPanelValid() 765 return _p.toPixelWidth(userWidth)
766
767 -def toPixelX(userX):
768 ''' 769 Returns pixel x-coordinate of given user x-coordinate. 770 ''' 771 _isGPanelValid() 772 return _p.toPixelX(userX)
773
774 -def toPixelY(userY):
775 ''' 776 Returns pixel y-coordinate of given user y-coordinate. 777 ''' 778 _isGPanelValid() 779 return _p.toPixelY(userY)
780
781 -def toUser(pixel):
782 ''' 783 Returns user coordinates (tuple) of given pixel coordinates (tuple). 784 ''' 785 _isGPanelValid() 786 return _p.toUser(pixel)
787
788 -def toUserHeight(pixelHeight):
789 ''' 790 Returns user y-increment of given pixel y-increment (always positive). 791 ''' 792 _isGPanelValid() 793 return _p.toUserHeight(pixelHeight)
794
795 -def toUserWidth(pixelWidth):
796 ''' 797 Returns user x-increment of given pixel x-increment (always positive). 798 ''' 799 _isGPanelValid() 800 return _p.toUserWidth(pixelWidth)
801
802 -def toUserX(pixelX):
803 ''' 804 Returns user x-coordinate of given pixel x-coordinate. 805 ''' 806 _isGPanelValid() 807 return _p.toUserX(pixelX)
808
809 -def toUserY(pixelY):
810 ''' 811 Returns user y-coordinate of given pixel y-coordinate. 812 ''' 813 _isGPanelValid() 814 return _p.toUserY(pixelY)
815
816 -def window(xmin, xmax, ymin, ymax):
817 ''' 818 Set user coordinate system left_x, right_x, bottom_y, top_y 819 820 Same as setUserCoords(). For TigerJython compatiblity. 821 @param xmin: the x coordinate at left border 822 @param xmax: the x coordinate at right border 823 @param ymin: the y coordinate at bottom border 824 @param ymax: the y coordinate at top border 825 ''' 826 _isGPanelValid() 827 _p.setUserCoords(xmin, xmax, ymin, ymax)
828
829 -def _getCoords(*args):
830 if len(args) == 2: 831 return args[0], args[1] 832 elif len(args) == 1: 833 if type(args[0]) == complex: 834 return args[0].real, args[0].imag 835 elif type(args[0]) == list or type(args[0]) == tuple: 836 return args[0][0], args[0][1] 837 else: 838 raise ValueError("Illegal parameter type.") 839 else: 840 raise ValueError("Illegal number of parameters.")
841
842 -def _get2Coords(*args):
843 if len(args) == 4: 844 return args[0], args[1], args[2], args[3] 845 elif len(args) == 2: 846 val = [] 847 for arg in args: 848 if type(arg) == complex: 849 val.append(arg.real) 850 val.append(arg.imag) 851 elif type(args) == list or type(args) == tuple: 852 val.append(arg[0]) 853 val.append(arg[1]) 854 else: 855 raise ValueError("Illegal parameter type.") 856 return val[0], val[1], val[2], val[3] 857 else: 858 raise ValueError("Illegal number of parameters.")
859
860 # ------------------------ end of GPanel methods ----------- 861 862 -def run(f):
863 ''' 864 Calls f() in a new thread. 865 ''' 866 thread.start_new_thread(f, ())
867
868 869 -def getRandomX11Color():
870 ''' 871 Returns a random X11 color string. 872 ''' 873 return GPanel.getRandomX11Color()
874
875 # Code from: http://code.activestate.com 876 -def linfit(X, Y):
877 ''' 878 Returns a and b in y = a*x + b for given list X of x values and 879 corresponding list Y of values. 880 ''' 881 def mean(Xs): 882 return sum(Xs) / len(Xs)
883 m_X = mean(X) 884 m_Y = mean(Y) 885 886 def std(Xs, m): 887 normalizer = len(Xs) - 1 888 return math.sqrt(sum((pow(x - m, 2) for x in Xs)) / normalizer) 889 890 def pearson_r(Xs, Ys): 891 sum_xy = 0 892 sum_sq_v_x = 0 893 sum_sq_v_y = 0 894 895 for (x, y) in zip(Xs, Ys): 896 var_x = x - m_X 897 var_y = y - m_Y 898 sum_xy += var_x * var_y 899 sum_sq_v_x += pow(var_x, 2) 900 sum_sq_v_y += pow(var_y, 2) 901 return sum_xy / math.sqrt(sum_sq_v_x * sum_sq_v_y) 902 903 r = pearson_r(X, Y) 904 b = r * (std(Y, m_Y) / std(X, m_X)) 905 A = m_Y - b * m_X 906 return b, A 907
908 909 910 911 # ----------------------------- Size class ------------------------- 912 -class Size():
913 ''' 914 Class that defines the pair width, height of dimension attributes. 915 '''
916 - def __init__(self, width, height):
917 self.width = width 918 self.height = height
919
920 # ===================================================================== 921 # ============================= GPanel class ========================== 922 # ===================================================================== 923 -class GPanel(QtGui.QWidget):
924 ''' 925 Class to create a graphics window of default size 501x501 pixels (client drawing area) 926 using a coordinate system with x-axis from left to right, y-axis from bottom to top 927 (called user coordinates, default range 0..1, 0..1). 928 929 The drawing methods perform drawing operation in an offscreen buffer (QPixmap) 930 and automatically renders it on the screen, so the graphics is shown step-by-step. 931 932 933 The drawing methods perform drawing operation in an offscreen buffer (pixmap) 934 and automatically renders it on the screen, so the graphics is shown step-by-step. 935 936 Pixel coordinate range: 0..winWidth, 0..winHeight (0,0) upper left corner, x to the right, y downwards 937 User coordinate range: xmin..xmax, ymin..ymax (0,0) lower left corner, x to the right, y upwards. 938 939 Transformation: user(ux, uy) to pixel(px, py) 940 px = a * ux + b 941 py = c * uy + d 942 with a = winWidth / (xmax - xmin) 943 b = winWidth * xmin / (xmin - xmax) 944 c = winHeight / (ymin - ymax) 945 d = winHeight * ymax / (ymax - ymin) 946 947 Inverse: 948 ux = (px - b) / a 949 uy = (py - d) / c 950 951 WARNING: Because PyQt is not thread-safe, in principle all graphics drawings should be 952 executed in the GUI thread (for GPanel the main thread or a GUI callback). 953 954 Typical program: 955 956 from gpanel import * 957 958 p = GPanel(0, 10, 0, 10) 959 for ypt in range(0, 11, 1): 960 p.line(0, ypt, 10 - ypt, 0) 961 time.sleep(0.1) # to see what happens 962 p.keep() 963 964 keep() is blocking and keeps the graphics panel open until the close button is hit or the 965 Python process terminates. 966 ''' 967
968 - def __init__(self, *args):
969 ''' 970 Constructs a GPanel and displays a non-resizable graphics window. 971 Defaults with no parameter: 972 Window size: 500x500 pixels 973 Window title: "GPanel" 974 User coordinates: 0, 1, 0, 1 975 Background color: white 976 Pen color: black 977 Pen size: 1 978 979 1 Parameter: Size(window_width, window_height) 980 4 Parameters: xmin, xmax, ymin, ymax 981 @param Size: a Size refererence that defines the width and height of the graphics window. 982 ''' 983 self._app = QtGui.QApplication(sys.argv) 984 super(GPanel, self).__init__() 985 self.xmin = 0 986 self.xmax = 1 987 self.ymin = 0 988 self.ymax = 1 989 self.winWidth = 500 990 self.winHeight = 500 991 if not (len(args) == 0 or len(args) == 1 or len(args) == 4): 992 raise ValueError("Illegal parameter list") 993 if len(args) == 1: 994 self.winWidth = args[0].width 995 self.winHeight = args[0].height 996 elif len(args) == 4: 997 self.xmin = args[0] 998 self.xmax = args[1] 999 self.ymin = args[2] 1000 self.ymax = args[3] 1001 self._initUI()
1002
1003 - def _initUI(self):
1004 self._setDefaults() 1005 self._label = QLabel() 1006 self._pixmap = QPixmap(QSize(self.winWidth + 1, self.winHeight + 1)) 1007 self._vbox = QVBoxLayout() 1008 self._vbox.setContentsMargins(1, 1, 1, 1) 1009 self.setLayout(self._vbox) 1010 self._painter = QPainter(self._pixmap) 1011 self.paintEvent(0) 1012 self.clear() 1013 self.show() 1014 self.setFixedSize(self.winWidth + 3, self.winHeight + 3) 1015 self.setAttribute(Qt.WA_TranslucentBackground)
1016
1017 - def _setDefaults(self):
1018 self.setWindowTitle('GPanel') 1019 self._penSize = 1 1020 self._penColor = QColor(0, 0, 0) 1021 self._bgColor = QColor(255, 255, 255, 255) 1022 1023 # default pos of GPanel window 1024 ulx = 10 1025 uly = 10 1026 super(GPanel, self).move(ulx, uly) # position 1027 1028 self._xCurrent = 0 1029 self._yCurrent = 0 1030 self._enableRepaint = True 1031 self._adjust() 1032 self._onMousePressed = None 1033 self._onMouseReleased = None 1034 self._onMouseDragged = None 1035 self._onKeyPressed = None 1036 self._onKeyReleased = None 1037 self._isLeftMouseButton = False 1038 self._isRightMouseButton = False 1039 self._inMouseMoveCallback = False 1040 self._closeListener = None 1041 self._pathHistory = None 1042 self._savePixmap = None
1043
1044 - def clear(self):
1045 ''' 1046 Clears the graphics window and the offscreen buffer used by the window 1047 (fully paint with background color). 1048 Sets the current graph cursor position to (0, 0). 1049 If enableRepaint(false) only clears the offscreen buffer. 1050 ''' 1051 self._painter.setPen(QPen(self._bgColor, 1)) 1052 self._painter.fillRect(QRect(0, 0, self.winWidth + 1, self.winHeight + 1), self._bgColor) 1053 self._painter.setPen(QPen(self._penColor, self._penSize)) 1054 self._xCurrent = 0 1055 self._yCurrent = 0 1056 if self._enableRepaint: 1057 self.repaint()
1058
1059 - def erase(self):
1060 ''' 1061 Same as clear(), but lets the current graph cursor unganged. 1062 ''' 1063 self._painter.setPen(QPen(self._bgColor, 1)) 1064 self._painter.fillRect(QRect(0, 0, self.winWidth + 1, self.winHeight + 1), self._bgColor) 1065 self._painter.setPen(QPen(self._penColor, self._penSize)) 1066 if self._enableRepaint: 1067 self.repaint()
1068
1069 - def keep(self):
1070 ''' 1071 Blocks until the title bar's close button is hit. Then cleans up 1072 the graphics system. 1073 ''' 1074 self._app.exec_() # blocking 1075 self._painter.end() 1076 sys.exit(0)
1077
1078 - def setTitle(self, title):
1079 ''' 1080 Sets the title in the window title bar. 1081 @param title: the title text 1082 ''' 1083 self.setWindowTitle(title)
1084 1085 # overwrite
1086 - def paintEvent(self, e):
1087 self._label.setPixmap(self._pixmap) 1088 self._vbox.addWidget(self._label)
1089
1090 - def setPenColor(self, *args):
1091 ''' 1092 Sets the current pen color. 1093 1 parameter: - string value considered as X11 color string 1094 - list considered as [r, b, g] or [r, g, b, a] 1095 - tuple considered as (r, b, g) or (r, g, b, a) 1096 3 parameters: values considered as RGB (alpha = 255) 1097 4 parameters: values considered as RGBA 1098 ''' 1099 if len(args) == 1: 1100 if type(args[0]) == str: 1101 try: 1102 rgb = x11ColorDict[args[0]] 1103 except KeyError: 1104 raise ValueError("X11 color", args[0], "not found") 1105 r = rgb[0] 1106 g = rgb[1] 1107 b = rgb[2] 1108 a = 255 1109 elif type(args[0]) == list or type(args[0]) == tuple: 1110 if len(args[0]) == 3: 1111 r = args[0][0] 1112 g = args[0][1] 1113 b = args[0][2] 1114 a = 255 1115 elif len(args[0]) == 4: 1116 r = args[0][0] 1117 g = args[0][1] 1118 b = args[0][2] 1119 a = args[0][3] 1120 else: 1121 raise ValueError("Illegal parameter list") 1122 else: 1123 raise ValueError("Illegal parameter list") 1124 1125 elif len(args) == 3: 1126 r = args[0] 1127 g = args[1] 1128 b = args[2] 1129 a = 255 1130 1131 elif len(args) == 4: 1132 r = args[0] 1133 g = args[1] 1134 b = args[2] 1135 a = 255 1136 1137 else: 1138 raise ValueError("Illegal number of arguments") 1139 1140 self._penColor = QColor(r, g, b, a) 1141 self._painter.setPen(QPen(self._penColor, self._penSize))
1142
1143 - def setPenSize(self, size):
1144 ''' 1145 Sets the current pen size (width) (>=1). 1146 Returns the previous pen size. 1147 @param width: the pen width >=1) 1148 ''' 1149 oldPenSize = self._penSize 1150 self._penSize = size 1151 self._painter.setPen(QPen(self._penColor, self._penSize)) 1152 return oldPenSize
1153 1154 # coordinate transformations
1155 - def toPixel(self, user):
1156 ''' 1157 Returns pixel coordinates (tuple) of given user coordinates (tupel). 1158 ''' 1159 return self.toPixelX(user[0]), self.toPixelY(user[1])
1160
1161 - def toPixelX(self, userX):
1162 ''' 1163 Returns pixel x-coordinate of given user x-coordinate. 1164 ''' 1165 return (int)(self._a * userX + self._b)
1166
1167 - def toPixelY(self, userY):
1168 ''' 1169 Returns pixel y-coordinate of given user y-coordinate. 1170 ''' 1171 return (int)(self._c * userY + self._d)
1172
1173 - def toPixelWidth(self, userWidth):
1174 ''' 1175 Returns pixel x-increment of given user x-increment (always positive). 1176 ''' 1177 return int(abs(self._a * userWidth))
1178
1179 - def toPixelHeight(self, userHeight):
1180 ''' 1181 Returns pixel y-increment of given user y-increment (always positive). 1182 ''' 1183 return int(abs(self._c * userHeight))
1184
1185 - def toUser(self, pixel):
1186 ''' 1187 Returns user coordinates (tuple) of given pixel coordinates (tuple). 1188 ''' 1189 return self.toUserX(pixel[0]), self.toUserY(pixel[1])
1190
1191 - def toUserX(self, pixelX):
1192 ''' 1193 Returns user x-coordinate of given pixel x-coordinate. 1194 ''' 1195 a = self.winWidth / (self.xmax - self.xmin) 1196 b = self.winWidth * self.xmin / (self.xmin - self.xmax) 1197 return (pixelX - b) / a
1198
1199 - def toUserY(self, pixelY):
1200 ''' 1201 Returns user y-coordinate of given pixel y-coordinate. 1202 ''' 1203 c = self.winHeight / (self.ymin - self.ymax) 1204 d = self.winHeight * self.ymax / (self.ymax - self.ymin) 1205 return (pixelY - d) / c
1206
1207 - def toUserWidth(self, pixelWidth):
1208 ''' 1209 Returns user x-increment of given pixel x-increment (always positive). 1210 ''' 1211 a = self.winWidth / (self.xmax - self.xmin) 1212 return abs(pixelWidth / a)
1213
1214 - def toUserHeight(self, pixelHeight):
1215 ''' 1216 Returns user y-increment of given pixel y-increment (always positive). 1217 ''' 1218 c = self.winWidth / (self._ymin - self._ymax) 1219 return abs(pixelHeight / c)
1220
1221 - def setUserCoords(self, xmin, xmax, ymin, ymax):
1222 ''' 1223 Set user coordinate system left_x, right_x, bottom_y, top_y 1224 @param xmin: the x coordinate at left border 1225 @param xmax: the x coordinate at right border 1226 @param ymin: the y coordinate at bottom border 1227 @param ymax: the y coordinate at top border 1228 ''' 1229 self.xmin = xmin 1230 self.xmax = xmax 1231 self.ymin = ymin 1232 self.ymax = ymax 1233 self._adjust()
1234
1235 - def _adjust(self):
1236 self._a = self.winWidth / (self.xmax - self.xmin) 1237 self._b = self.winWidth * self.xmin / (self.xmin - self.xmax) 1238 self._c = self.winHeight / (self.ymin - self.ymax) 1239 self._d = self.winHeight * self.ymax / (self.ymax - self.ymin)
1240 1241 # end of coordinate transformations 1242
1243 - def repaint(self):
1244 ''' 1245 Renders the offscreen buffer in the graphics window. 1246 ''' 1247 self.update() 1248 QApplication.processEvents()
1249
1250 - def enableRepaint(self, enable):
1251 ''' 1252 Enables/Disables automatic repaint in graphics drawing methods. 1253 @param enable: if True, the automatic repaint is enabled; otherwise disabled 1254 ''' 1255 self._enableRepaint = enable
1256
1257 - def line(self, x1, y1, x2, y2):
1258 ''' 1259 Draws a line with given user start and end coordinates 1260 and sets the graph cursor position to the end point. 1261 Also with 2 parameters of type complex, list or tuple. 1262 4 parameters: x1, y1, x2, y2 1263 2 parameters: pt1, pt2 as complex/list/tuple 1264 ''' 1265 xStart = self.toPixelX(x1) 1266 yStart = self.toPixelY(y1) 1267 xEnd = self.toPixelX(x2) 1268 yEnd = self.toPixelY(y2) 1269 self._painter.drawLine(xStart, yStart, xEnd, yEnd) 1270 self._xCurrent = x2 1271 self._yCurrent = y2 1272 if self._enableRepaint: 1273 self.repaint()
1274
1275 - def pos(self, x, y):
1276 ''' 1277 Sets the current graph cursor position to given user coordinates. 1278 (without drawing anything, same as move()). 1279 @param x: the x coordinate of the target point 1280 @param y: the y coordinate of the target point 1281 @param target: (alternative) the target point as complex, list or tuple 1282 ''' 1283 self._xCurrent = x 1284 self._yCurrent = y
1285
1286 - def move(self, x, y):
1287 # Overrides super.move() 1288 ''' 1289 Sets the current graph cursor position to given user coordinates. 1290 (without drawing anything, same as pos()). 1291 @param x: the x coordinate of the target point 1292 @param y: the y coordinate of the target point 1293 @param target: (alternative) the target point as complex, list or tuple 1294 ''' 1295 self.pos(x, y)
1296
1297 - def draw(self, x, y):
1298 ''' 1299 Draws a line form current graph cursor position to (x, y). 1300 Sets the graph cursor position to (x, y). 1301 @param x: the x coordinate of the target point 1302 @param y: the y coordinate of the target point 1303 @param target: (alternative) the target point as complex, list or tuple 1304 ''' 1305 self.line(self._xCurrent, self._yCurrent, x, y) 1306 if self._pathHistory != None: 1307 self._pathHistory.append([x, y])
1308
1309 - def getPos():
1310 ''' 1311 Returns a tuple with current graph cursor position (tuple, user coordinates). 1312 ''' 1313 return self._xCurrent, self._yCurrent
1314
1315 - def getPosX(self):
1316 ''' 1317 Returns the current graph cursor x-position (user coordinates). 1318 ''' 1319 return self._xCurrent
1320
1321 - def getPosY(self):
1322 ''' 1323 Returns the current graph cursor y-position (user coordinates). 1324 ''' 1325 return self._yCurrent
1326
1327 - def text(self, *args):
1328 ''' 1329 Draws a text at given position (user coordinates). 1330 1 parameter: at current graph cursor position 1331 2 parameters: target point (comolex/list/tuple), text 1332 3 parameters: x, y, text 1333 ''' 1334 if len(args) == 1: 1335 xPos = self.toPixelX(self._xCurrent) 1336 yPos = self.toPixelY(self._yCurrent) 1337 text = args[0] 1338 elif len(args) == 2: 1339 xPos, yPos = _getCoords(args[0][:-1]) 1340 text = args[1] 1341 elif len(args) == 3: 1342 xPos = self.toPixelX(args[0]) 1343 yPos = self.toPixelY(args[1]) 1344 text = args[2] 1345 else: 1346 raise ValueError("Illegal number of arguments") 1347 1348 self._painter.drawText(xPos, yPos, text) 1349 if self._enableRepaint: 1350 self.repaint()
1351
1352 - def addCloseListener(self, closeListener):
1353 ''' 1354 Registers the given function that is called when the title bar 1355 close button is hit. If a listener (!= None) is registered, 1356 the automatic closing is disabled. To close the window, call 1357 sys.exit(). 1358 1359 KEEP IN MIND: To use GUI callbacks, the main program must block in the keep() function. 1360 @param closeListener: a callback function called when the close button is hit 1361 ''' 1362 self._closeListener = closeListener
1363
1364 - def closeEvent(self, e):
1365 # Override 1366 if self._closeListener != None: 1367 e.ignore() 1368 self._closeListener()
1369
1370 - def setBgColor(self, *args):
1371 ''' 1372 Sets the background color. All drawings are erased and the current 1373 graph cursor is set to (0, 0). 1374 1375 1 parameter: value considered as X11 color string 1376 3 parameters: values considered as RGB (alpha = 255) 1377 4 parameters: values considered as RGBA 1378 ''' 1379 if len(args) == 1: 1380 try: 1381 rgb = x11ColorDict[args[0]] 1382 except KeyError: 1383 raise ValueError("X11 color", args[0], "not found") 1384 r = rgb[0] 1385 g = rgb[1] 1386 b = rgb[2] 1387 a = 255 1388 elif len(args) == 3: 1389 r = args[0] 1390 g = args[1] 1391 b = args[2] 1392 a = 255 1393 elif len(args) == 4: 1394 r = args[0] 1395 g = args[1] 1396 b = args[2] 1397 a = args[3] 1398 else: 1399 raise ValueError("Illegal number of arguments") 1400 self._bgColor = QColor(r, g, b, a) 1401 self.clear()
1402 1403
1404 - def circle(self, radius):
1405 ''' 1406 Draws a circle with center at the current graph cursor position 1407 with given radius in horizontal window coordinates. 1408 @param radius: the radius of the circle 1409 ''' 1410 xPix = self.toPixelX(self._xCurrent) 1411 yPix = self.toPixelY(self._yCurrent) 1412 rPix = self.toPixelWidth(radius) 1413 self._painter.drawEllipse(QPointF(xPix, yPix), rPix, rPix) 1414 if self._enableRepaint: 1415 self.repaint()
1416
1417 - def fillCircle(self, radius):
1418 ''' 1419 Draws a filled circle with center at the current graph cursor position 1420 with given radius in horizontal window coordinates (fill color = pen color). 1421 @param radius: the radius of the circle 1422 ''' 1423 xPix = self.toPixelX(self._xCurrent) 1424 yPix = self.toPixelY(self._yCurrent) 1425 rPix = self.toPixelWidth(radius) 1426 self._painter.setPen(Qt.NoPen) 1427 self._painter.setBrush(QBrush(self._penColor)) 1428 self._painter.drawEllipse(QPointF(xPix, yPix), rPix, rPix) 1429 if self._enableRepaint: 1430 self.repaint() 1431 self._painter.setPen(QPen(self._penColor, self._penSize)) 1432 self._painter.setBrush(Qt.NoBrush)
1433 1434
1435 - def ellipse(self, a, b):
1436 ''' 1437 Draws an ellipse with center at the current graph cursor position 1438 with given axes. 1439 @param a: the major ellipse axis 1440 @param b: the minor ellipse axis 1441 ''' 1442 xPix = self.toPixelX(self._xCurrent) 1443 yPix = self.toPixelY(self._yCurrent) 1444 aPix = self.toPixelWidth(a) 1445 bPix = self.toPixelHeight(b) 1446 self._painter.drawEllipse(QPointF(xPix, yPix), aPix, bPix) 1447 if self._enableRepaint: 1448 self.repaint()
1449
1450 - def fillEllipse(self, a, b):
1451 ''' 1452 Draws a filled ellipse with center at the current graph cursor position 1453 with given axes (fill color = pen color). 1454 @param a: the major ellipse axis 1455 @param b: the minor ellipse axis 1456 ''' 1457 xPix = self.toPixelX(self._xCurrent) 1458 yPix = self.toPixelY(self._yCurrent) 1459 aPix = self.toPixelWidth(a) 1460 bPix = self.toPixelHeight(b) 1461 self._painter.setPen(Qt.NoPen) 1462 self._painter.setBrush(QBrush(self._penColor)) 1463 self._painter.drawEllipse(QPointF(xPix, yPix), aPix, bPix) 1464 if self._enableRepaint: 1465 self.repaint() 1466 self._painter.setPen(QPen(self._penColor, self._penSize)) 1467 self._painter.setBrush(Qt.NoBrush)
1468
1469 - def rectangle(self, *args):
1470 ''' 1471 Draws a rectangle. 1472 2 parameters: Center at the current graph cursor position 1473 and given width and height. 1474 4 parameters: Given diagonal 1475 ''' 1476 if len(args) == 2: 1477 wPix = self.toPixelWidth(args[0]) 1478 hPix = self.toPixelHeight(args[1]) 1479 ulx = self.toPixelX(self._xCurrent) - wPix // 2 1480 uly = self.toPixelY(self._yCurrent) - hPix // 2 1481 elif len(args) == 4: 1482 wPix = self.toPixelWidth(args[2] - args[0]) 1483 hPix = self.toPixelHeight(args[3] - args[1]) 1484 ulx = self.toPixelX(args[0]) 1485 uly = self.toPixelX(args[1]) 1486 self._painter.drawRect(ulx, uly, wPix, hPix) 1487 if self._enableRepaint: 1488 self.repaint()
1489
1490 - def fillRectangle(self, *args):
1491 ''' 1492 Draws a filled rectangle (fill color = pen color). 1493 2 parameters: Center at the current graph cursor position 1494 and given width and height. 1495 4 parameters: Given diagonal 1496 ''' 1497 if len(args) == 2: 1498 wPix = self.toPixelWidth(args[0]) 1499 hPix = self.toPixelHeight(args[1]) 1500 ulx = self.toPixelX(self._xCurrent) - wPix // 2 1501 uly = self.toPixelX(self._xCurrent) - hPix // 2 1502 elif len(args) == 4: 1503 wPix = self.toPixelWidth(args[2] - args[0]) 1504 hPix = self.toPixelHeight(args[3] - args[1]) 1505 ulx = self.toPixelX(args[0]) 1506 uly = self.toPixelX(args[1]) 1507 self._painter.setPen(Qt.NoPen) 1508 self._painter.setBrush(QBrush(self._penColor)) 1509 self._painter.drawRect(ulx, uly, wPix, hPix) 1510 if self._enableRepaint: 1511 self.repaint() 1512 self._painter.setPen(QPen(self._penColor, self._penSize)) 1513 self._painter.setBrush(Qt.NoBrush)
1514
1515 - def polygon(self, corners):
1516 ''' 1517 Draws a polygon with given list of vertexes (list of x, y). 1518 @param corners: a list /tuple of the corner points (x, y) list/tuple 1519 ''' 1520 nodes = [] 1521 for pt in corners: 1522 node = QPointF(self.toPixelX(pt[0]), self.toPixelY(pt[1])) 1523 nodes.append(node) 1524 p = QPolygonF(nodes) 1525 self._painter.drawPolygon(p) 1526 if self._enableRepaint: 1527 self.repaint()
1528
1529 - def fillPolygon(self, corners):
1530 ''' 1531 Draws a filled polygon with given list of vertexes (list of x, y) 1532 (fill color = pen color). 1533 @param corners: a list /tuple of the corner points (x, y) list/tuple 1534 ''' 1535 nodes = [] 1536 for pt in corners: 1537 node = QPointF(self.toPixelX(pt[0]), self.toPixelY(pt[1])) 1538 nodes.append(node) 1539 p = QPolygonF(nodes) 1540 self._painter.setPen(Qt.NoPen) 1541 self._painter.setBrush(QBrush(self._penColor)) 1542 self._painter.drawPolygon(p) 1543 if self._enableRepaint: 1544 self.repaint() 1545 self._painter.setPen(QPen(self._penColor, self._penSize)) 1546 self._painter.setBrush(Qt.NoBrush)
1547
1548 - def arc(self, r, startAngle, spanAngle):
1549 ''' 1550 Draws a circle sector with center at the current graph cursor position, 1551 given radius and given start and span angles. 1552 @param radius: the radius of the arc 1553 @param startAngle: starting angle in degrees, zero to east, positive counter-clockwise 1554 @param spanAngle: span angle (sector angle) in degrees, positive counter-clockwise 1555 ''' 1556 xPix = self.toPixelX(self._xCurrent) 1557 yPix = self.toPixelY(self._yCurrent) 1558 rPix = self.toPixelWidth(r) 1559 topLeft = QPoint(xPix - rPix, yPix - rPix) 1560 bottomRight = QPoint(xPix + rPix, yPix + rPix) 1561 rect = QRect(topLeft, bottomRight) 1562 self._painter.drawArc(rect, int(16 * startAngle), int(16 * spanAngle)) 1563 if self._enableRepaint: 1564 self.repaint()
1565
1566 - def fillArc(self, r, startAngle, spanAngle):
1567 ''' 1568 Draws a filled circle sector with center at the current graph cursor position, 1569 given radius and given start and span angles. 1570 @param radius: the radius of the arc 1571 @param startAngle: starting angle in degrees, zero to east, positive counter-clockwise 1572 @param spanAngle: span angle (sector angle) in degrees, positive counter-clockwise 1573 ''' 1574 xPix = self.toPixelX(self._xCurrent) 1575 yPix = self.toPixelY(self._yCurrent) 1576 rPix = self.toPixelWidth(r) 1577 topLeft = QPoint(xPix - rPix, yPix - rPix) 1578 bottomRight = QPoint(xPix + rPix, yPix + rPix) 1579 rect = QRect(topLeft, bottomRight) 1580 self._painter.setPen(Qt.NoPen) 1581 self._painter.setBrush(QBrush(self._penColor)) 1582 self._painter.drawChord(rect, int(16 * startAngle), int(16 * spanAngle)) 1583 1584 # Draw sector triangle 1585 xStart = int(xPix + rPix * math.cos(math.radians(startAngle))) 1586 yStart = int(yPix - rPix * math.sin(math.radians(startAngle))) 1587 xEnd = int(xPix + rPix * math.cos(math.radians(startAngle + spanAngle))) 1588 yEnd = int(yPix - rPix * math.sin(math.radians(startAngle + spanAngle))) 1589 triangle = [[xPix, yPix], [xStart, yStart], [xEnd, yEnd]] 1590 nodes = [] 1591 for pt in triangle: 1592 node = QPointF(pt[0], pt[1]) 1593 nodes.append(node) 1594 p = QPolygonF(nodes) 1595 self._painter.drawPolygon(p) 1596 1597 if self._enableRepaint: 1598 self.repaint() 1599 self._painter.setPen(QPen(self._penColor, self._penSize)) 1600 self._painter.setBrush(Qt.NoBrush)
1601
1602 - def chord(self, r, startAngle, spanAngle):
1603 ''' 1604 Draws a circle chord with center at the current graph cursor position, 1605 given radius and given start and span angles (in degrees, positive 1606 counter-clockwise, zero to east). 1607 @param radius: the radius of the arc 1608 @param startAngle: starting angle in degrees, zero to east, positive counter-clockwise 1609 @param spanAngle: span angle (sector angle) in degrees, positive counter-clockwise 1610 ''' 1611 xPix = self.toPixelX(self._xCurrent) 1612 yPix = self.toPixelY(self._yCurrent) 1613 rPix = self.toPixelWidth(r) 1614 topLeft = QPoint(xPix - rPix, yPix - rPix) 1615 bottomRight = QPoint(xPix + rPix, yPix + rPix) 1616 rect = QRect(topLeft, bottomRight) 1617 self._painter.drawChord(rect, int(16 * startAngle), int(16 * spanAngle)) 1618 if self._enableRepaint: 1619 self.repaint()
1620
1621 - def fillChord(self, r, startAngle, spanAngle):
1622 ''' 1623 Draws a filled circle chord with center at the current graph cursor position, 1624 given radius and given start and span angles (in degrees, positive 1625 counter-clockwise, zero to east). 1626 @param radius: the radius of the arc 1627 @param startAngle: starting angle in degrees, zero to east, positive counter-clockwise 1628 @param spanAngle: span angle (sector angle) in degrees, positive counter-clockwise 1629 ''' 1630 xPix = self.toPixelX(self._xCurrent) 1631 yPix = self.toPixelY(self._yCurrent) 1632 rPix = self.toPixelWidth(r) 1633 topLeft = QPoint(xPix - rPix, yPix - rPix) 1634 bottomRight = QPoint(xPix + rPix, yPix + rPix) 1635 rect = QRect(topLeft, bottomRight) 1636 self._painter.setPen(Qt.NoPen) 1637 self._painter.setBrush(QBrush(self._penColor)) 1638 self._painter.drawChord(rect, int(16 * startAngle), int(16 * spanAngle)) 1639 if self._enableRepaint: 1640 self.repaint() 1641 self._painter.setPen(QPen(self._penColor, self._penSize)) 1642 self._painter.setBrush(Qt.NoBrush)
1643
1644 - def startPath(self):
1645 ''' 1646 Starts recording the path vertexes. The positions of subsequent draw() operations are saved. 1647 The path is used to show a filled polygon when fillPath() is called. 1648 ''' 1649 self._pathHistory = [[self._xCurrent, self._yCurrent]]
1650
1651 - def fillPath(self, color):
1652 ''' 1653 Closes the path started with startPath() and shows a filled polygon from the saved 1654 draw() positions with given color. 1655 ''' 1656 if self._pathHistory == None: 1657 raise Exception("Must call startPath() before fillPath()") 1658 oldColor = self._penColor 1659 oldSize = self._penSize 1660 self.setPenColor(color) 1661 self.setPenSize(1) 1662 self.fillPolygon(self._pathHistory) 1663 self._painter.setPen(QPen(oldColor, oldSize)) 1664 self.polygon(self._pathHistory) # draw outline again 1665 self._pathHistory = None
1666
1667 - def showImage(self, *args):
1668 ''' 1669 Draws the picture with given file path or given image at given upper-left coordinates. 1670 1st parameter: image path (string) or QImage reference 1671 2nd, 3rd parameters: llx, lly (lower left corner in user coordinates) 1672 ''' 1673 if type(args[0])== str: 1674 img = QImage(args[0]) 1675 else: 1676 img = args[0] 1677 xPix = self.toPixelX(args[1]) 1678 yPix = img.height() - self.toPixelY(args[2]) 1679 self._painter.drawImage(xPix, yPix, img) 1680 if self._enableRepaint: 1681 self.repaint()
1682
1683 - def point(self, *args):
1684 ''' 1685 Draws a single point with current pen size and pen color at given user coordinates. 1686 No params: draws a current graph cursor position 1687 @param x: the x coordinate of the target point 1688 @param y: the y coordinate of the target point 1689 @param target: (alternative) the target point as complex, list or tuple 1690 ''' 1691 if len(args) == 0: 1692 xPix = self.toPixelX(self._xCurrent) 1693 yPix = self.toPixelY(self._yCurrent) 1694 elif len(args) == 1: 1695 pt = _getCoords(*args) 1696 xPix = self.toPixelX(pt[0]) 1697 yPix = self.toPixelY(pt[1]) 1698 elif len(args) == 2: 1699 xPix = self.toPixelX(args[0]) 1700 yPix = self.toPixelY(args[1]) 1701 else: 1702 raise ValueError("Illegal number of arguments") 1703 self._painter.drawPoint(QPointF(xPix, yPix)) 1704 if self._enableRepaint: 1705 self.repaint()
1706
1707 - def getPixelColor(self, *args):
1708 ''' 1709 Returns the RGBA color tuple of a pixel with given user coordinates. 1710 No params: Returns color at current graph cursor position. 1711 ''' 1712 if len(args) == 0: 1713 xPix = self.toPixelX(self._xCurrent) 1714 yPix = self.toPixelY(self._yCurrent) 1715 elif len(args) == 2: 1716 xPix = self.toPixelX(args[0]) 1717 yPix = self.toPixelY(args[1]) 1718 else: 1719 raise ValueError("Illegal number of parameters.") 1720 img = self._pixmap.toImage() 1721 c = img.pixel(xPix, yPix) 1722 return QColor(c).getRgb() # RGBA
1723
1724 - def fill(self, x, y, color):
1725 ''' 1726 Fills the closed unicolored region with the inner point (x, y) with 1727 the given color (RGB, RGBA or X11 color string). The old color to replace is 1728 the color of the pixel at x, y. 1729 @param x: the x coordinate of the inner point 1730 @param y: the y coordinate of the inner point 1731 @param color: the replacement color (RGB list/tuple or X11 color string) 1732 ''' 1733 if type(color) == str: 1734 try: 1735 color = x11ColorDict[color] 1736 except KeyError: 1737 raise ValueError("X11 color", color, "not found") 1738 1739 xPix = self.toPixelX(x) 1740 yPix = self.toPixelY(y) 1741 im = self._pixmap.toImage() 1742 col= QColor(im.pixel(xPix, yPix)) 1743 oldColor = [col.red(), col.green(), col.blue()] 1744 1745 img = GPanel.floodFill(self._pixmap, [self.toPixelX(x), self.toPixelY(y)], oldColor, color) 1746 self._painter.drawImage(0, 0, img) 1747 if self._enableRepaint: 1748 self.repaint()
1749
1750 - def getPainter(self):
1751 ''' 1752 Returns the QPainter reference used to draw into the offscreen buffer. 1753 ''' 1754 return self._painter
1755 1756
1757 - def drawGrid(self, *args):
1758 ''' 1759 Draws a coordinate system with annotated axes. 1760 (You must increase the user coordinate system at least 10% in both directions.) 1761 drawGrid(x, y): Grid with 10 ticks in range 0..x, 0..y. Label text depends if x, y or int or float 1762 drawGrid(x, y, color): same with given grid color 1763 drawGrid(x1, x2, y1, y2): same with given span x1..x2, y1..y2 1764 drawGrid(x1, x2, y1, y2, color): same with given grid color 1765 drawGrid(x1, x2, y1, y2, x3, y3): same with given number of ticks x3, y3 in x- and y-direction 1766 ''' 1767 if len(args) == 2: 1768 self._drawGrid(0, args[0], 0, args[1], 10, 10, None) 1769 if len(args) == 3: 1770 self._drawGrid(0, args[0], 0, args[1], 10, 10, args[2]) 1771 elif len(args) == 4: 1772 self._drawGrid(args[0], args[1], args[2], args[3], 10, 10, None) 1773 elif len(args) == 5: 1774 self._drawGrid(args[0], args[1], args[2], args[3], 10, 10, args[4]) 1775 elif len(args) == 6: 1776 self._drawGrid(args[0], args[1], args[2], args[3], args[4], args[5], None) 1777 elif len(args) == 7: 1778 self._drawGrid(args[0], args[1], args[2], args[3], args[4], args[5], args[6]) 1779 else: 1780 raise ValueError("Illegal number of parameters.")
1781 1782
1783 - def _drawGrid(self, xmin, xmax, ymin, ymax, xticks, yticks, color):
1784 # Save current cursor and color 1785 xPos = self.getPosX() 1786 yPos = self.getPosY() 1787 if color != None: 1788 oldColor = self.setColor(color) 1789 # Horizontal 1790 for i in range(yticks + 1): 1791 y = ymin + (ymax - ymin) / float(yticks) * i 1792 self.line(xmin, y, xmax, y) 1793 if isinstance(ymin, float) or isinstance(ymax, float): 1794 self.text(xmin - 0.09 * (xmax - xmin), y, str(y)) 1795 else: 1796 self.text(xmin - 0.09 * (xmax - xmin), y, str(int(y))) 1797 # Vertical 1798 for k in range(xticks + 1): 1799 x = xmin + (xmax - xmin) / float(xticks) * k 1800 self.line(x, ymin, x, ymax) 1801 if isinstance(xmin, float) or isinstance(xmax, float): 1802 self.text(x, ymin - 0.05 * (ymax - ymin), str(x)) 1803 else: 1804 self.text(x, ymin - 0.05 * (ymax - ymin), str(int(x))) 1805 # Restore cursor and color 1806 self.pos(xPos, yPos) 1807 if color != None: 1808 self.setColor(oldColor)
1809
1810 - def addMousePressListener(self, onMousePressed):
1811 ''' 1812 Registers a callback that is invoked when a mouse button is pressed. 1813 Use isLeftMouseButton() or isRightMouseButton() to check which button used. 1814 1815 KEEP IN MIND: To use GUI callbacks, the main program must block in the keep() function. 1816 @param onMousePressed: a callback function called when a mouse button is pressed 1817 ''' 1818 self._onMousePressed = onMousePressed
1819
1820 - def addMouseReleaseListener(self, onMouseReleased):
1821 ''' 1822 Registers a callback that is invoked when a mouse button is releases. 1823 Use isLeftMouseButton() or isRightMouseButton() to check which button used. 1824 1825 KEEP IN MIND: To use GUI callbacks, the main program must block in the keep() function. 1826 @param onMouseReleased: a callback function called when a mouse button is released 1827 ''' 1828 self._onMouseReleased = onMouseReleased
1829
1830 - def addMouseDragListener(self, onMouseDragged):
1831 ''' 1832 Registers a callback that is invoked when the mouse is moved while a mouse button is pressed (drag). 1833 1834 KEEP IN MIND: To use GUI callbacks, the main program must block in the keep() function. 1835 @param onMouseDragged: a callback function called when the moused is dragged 1836 ''' 1837 self._onMouseDragged = onMouseDragged
1838
1839 - def isLeftMouseButton(self):
1840 ''' 1841 Returns True, if the last mouse action was performed with the left mouse button. 1842 ''' 1843 return self._isLeftMouseButton
1844
1845 - def isRightMouseButton(self):
1846 ''' 1847 Returns True, if the last mouse action was performed with the right mouse button. 1848 ''' 1849 return self._isRightMouseButton
1850
1851 - def addKeyPressListener(self, onKeyPressed):
1852 ''' 1853 Registers a callback that is invoked when a key is pressed (and the graphics window has the focus). 1854 1855 KEEP IN MIND: To use GUI callbacks, the main program must block in the keep() function. 1856 @param onKeyPressed: a callback function called when a key is pressed 1857 ''' 1858 self._onKeyPressed = onKeyPressed
1859
1860 - def addKeyReleaseListener(self, onKeyReleased):
1861 ''' 1862 Registers a callback that is invoked when a key is released (and the graphics window has the focus). 1863 1864 KEEP IN MIND: To use GUI callbacks, the main program must block in the keep() function. 1865 @param onKeyReleased: a callback function called when a key is released 1866 ''' 1867 self._onKeyReleased = onKeyReleased
1868
1869 - def getScreenWidth(self):
1870 ''' 1871 Returns the screen width in pixels. 1872 ''' 1873 screen_resolution = self._app.desktop().screenGeometry() 1874 return screen_resolution.width()
1875
1876 - def getScreenHeight(self):
1877 ''' 1878 Returns the screen height in pixels. 1879 ''' 1880 screen_resolution = self._app.desktop().screenGeometry() 1881 return screen_resolution.height()
1882 1883
1884 - def setWindowCenter(self):
1885 ''' 1886 Sets the screen position to the center of the screen. 1887 ''' 1888 frameGm = self.frameGeometry() 1889 centerPoint = QtGui.QDesktopWidget().availableGeometry().center() 1890 frameGm.moveCenter(centerPoint) 1891 super(GPanel, self).move(frameGm.topLeft())
1892
1893 - def setWindowPos(self, ulx, uly):
1894 ''' 1895 Sets the screen position of the graphics window. 1896 @param ulx: the upper left corner's x-coordinate 1897 @param ulx: the upper left corner's y-coordinate 1898 ''' 1899 super(GPanel, self).move(ulx, uly)
1900
1901 - def saveGraphics(self):
1902 ''' 1903 Saves the current graphics into a image buffer. Use restoreGraphics() 1904 to restore it. 1905 ''' 1906 self._savePixmap = self._pixmap.copy(QRect())
1907
1908 - def restoreGraphics(self):
1909 ''' 1910 Restores the saved graphics from the image buffer. Use saveGraphics() 1911 to save it. 1912 ''' 1913 if self._savePixmap == None: 1914 raise Exception("Store graphics buffer is empty.") 1915 img = self._savePixmap.toImage() 1916 self._painter.drawImage(0, 0, img) 1917 if self._enableRepaint: 1918 self.repaint()
1919
1920 - def setXORMode(self):
1921 ''' 1922 Performs pixel color XOR operation with the existing background pixel. 1923 Be aware that if the background is white, drawing with a white pen shows a black pixel 1924 ''' 1925 self._painter.setCompositionMode(QPainter.RasterOp_SourceXorDestination)
1926 1927
1928 - def setPaintMode(self):
1929 ''' 1930 Resets the drawing mode to standard (overwriting). 1931 ''' 1932 self._painter.setCompositionMode(QPainter.CompositionMode_SourceOver)
1933 1934 1935 # ------------- Mouse events ----------------------------
1936 - def mousePressEvent(self, e):
1937 pos = QPoint(e.pos()) 1938 self._isLeftMouseButton = (e.button() == Qt.LeftButton) 1939 self._isRightMouseButton = (e.button() == Qt.RightButton) 1940 if self._onMousePressed != None: 1941 self._onMousePressed(self.toUserX(pos.x()), self.toUserY(pos.y()))
1942
1943 - def mouseReleaseEvent(self, e):
1944 pos = QPoint(e.pos()) 1945 self._isLeftMouseButton = (e.button() == Qt.LeftButton) 1946 self._isRightMouseButton = (e.button() != Qt.RightButton) 1947 if self._onMouseReleased != None: 1948 self._onMouseReleased(self.toUserX(pos.x()), self.toUserY(pos.y()))
1949
1950 - def mouseMoveEvent(self, e):
1951 # reject reentrance 1952 if self._inMouseMoveCallback: 1953 return 1954 self._inMouseMoveCallback = True 1955 pos = QPoint(e.pos()) 1956 if self._onMouseDragged != None: 1957 self._onMouseDragged(self.toUserX(pos.x()), self.toUserY(pos.y())) 1958 self._inMouseMoveCallback = False
1959 1960 # ------------- Key events ---------------------------
1961 - def keyPressEvent(self, e):
1962 key = e.key() 1963 if self._onKeyPressed != None: 1964 self._onKeyPressed(key)
1965
1966 - def keyReleaseEvent(self, e):
1967 key = e.key() 1968 if self._onKeyReleased != None: 1969 self._onKeyReleased(key)
1970 1971 # ------------- static methods ------------------------------- 1972 1973 @staticmethod
1974 - def getDividingPoint(x1, y1, x2, y2, ratio):
1975 ''' 1976 Returns the tuple of user coordinates of the point on the line through the point pt1 = (x1, y1) 1977 and the point pt2 = (x2, y2) that is in distance ratio times the length from pt1 to pt2 from 1978 pt1. For ratio < 0 the point is in the opposite direction. 1979 3 parameteters: pt1, pt2 (complex/list/tuple), ratio 1980 5 parameteters: x1, y1, x2, y2, ratio 1981 ''' 1982 v1 = (x1, y1) 1983 v2 = (x2, y2) 1984 dv = (v2[0] - v1[0], v2[1] - v1[1]) # = v2 - v1 1985 v = (v1[0] + ratio * dv[0], v1[1] + ratio * dv[1]) # v1 + ratio * dv 1986 return v[0], v[1]
1987 1988 @staticmethod
1989 - def floodFill(pm, pt, oldColor, newColor):
1990 # Implementation from Hardik Gajjar of algorithm 1991 # at http://en.wikipedia.org/wiki/Flood_fill 1992 ''' 1993 Fills a bounded single-colored region with 1994 the given color. The given point is part of the region and used 1995 to specify it. 1996 @param pm the pixmap containing the connected region 1997 @param pt a point inside the region 1998 @param oldColor the old color of the region (RGB list/tuple) 1999 @param newColor the new color of the region (RGB list/tuple) 2000 @return a new qImage with the transformed region 2001 ''' 2002 image = pm.toImage() 2003 oldColor = QColor(oldColor[0], oldColor[1], oldColor[2]).rgb() 2004 newColor = QColor(newColor[0], newColor[1], newColor[2]).rgb() 2005 q = [pt] 2006 2007 # Perform filling operation 2008 while len(q) > 0: 2009 n = q.pop(0) 2010 if QColor(image.pixel(n[0], n[1])).rgb() != oldColor: 2011 continue 2012 2013 w = n 2014 e = [n[0] + 1, n[1]] 2015 while w[0] > 0 and QColor(image.pixel(w[0], w[1])).rgb() == oldColor: 2016 image.setPixel(w[0], w[1], newColor) 2017 if w[1] > 0 and QColor(image.pixel(w[0], w[1] - 1)).rgb() == oldColor: 2018 q.append([w[0], w[1] - 1]) 2019 if w[1] < image.height() - 1 and QColor(image.pixel(w[0], w[1] + 1)).rgb() == oldColor: 2020 q.append([w[0], w[1] + 1]) 2021 w[0] -= 1 2022 2023 while e[0] < image.width() - 1 and QColor(image.pixel(e[0], e[1])).rgb() == oldColor: 2024 image.setPixel(e[0], e[1], newColor) 2025 if e[1] > 0 and QColor(image.pixel(e[0], e[1] - 1)).rgb() == oldColor: 2026 q.append([e[0], e[1] - 1]) 2027 if e[1] < image.height() - 1 and QColor(image.pixel(e[0], e[1] + 1)).rgb() == oldColor: 2028 q.append([e[0], e[1] + 1]) 2029 e[0] += 1 2030 return image
2031 2032 @staticmethod
2033 - def getRandomX11Color():
2034 ''' 2035 Returns a random X11 color string. 2036 ''' 2037 r = random.randint(0, 540) 2038 c = x11ColorDict.keys() 2039 return c[r]
2040 2041 ''' 2042 X11 to RGB color mapping 2043 ''' 2044 x11ColorDict = { 2045 "aqua":[0, 255, 255], 2046 "cornflower":[100, 149, 237], 2047 "crimson":[220, 20, 60], 2048 "fuchsia":[255, 0, 255], 2049 "indigo":[75, 0, 130], 2050 "lime":[50, 205, 50], 2051 "silver":[192, 192, 192], 2052 "ghost white":[248, 248, 255], 2053 "snow":[255, 250, 250], 2054 "ghostwhite":[248, 248, 255], 2055 "white smoke":[245, 245, 245], 2056 "whitesmoke":[245, 245, 245], 2057 "gainsboro":[220, 220, 220], 2058 "floral white":[255, 250, 240], 2059 "floralwhite":[255, 250, 240], 2060 "old lace":[253, 245, 230], 2061 "oldlace":[253, 245, 230], 2062 "linen":[250, 240, 230], 2063 "antique white":[250, 235, 215], 2064 "antiquewhite":[250, 235, 215], 2065 "papaya whip":[255, 239, 213], 2066 "papayawhip":[255, 239, 213], 2067 "blanched almond":[255, 235, 205], 2068 "blanchedalmond":[255, 235, 205], 2069 "bisque":[255, 228, 196], 2070 "peach puff":[255, 218, 185], 2071 "peachpuff":[255, 218, 185], 2072 "navajo white":[255, 222, 173], 2073 "navajowhite":[255, 222, 173], 2074 "moccasin":[255, 228, 181], 2075 "cornsilk":[255, 248, 220], 2076 "ivory":[255, 255, 240], 2077 "lemon chiffon":[255, 250, 205], 2078 "lemonchiffon":[255, 250, 205], 2079 "seashell":[255, 245, 238], 2080 "honeydew":[240, 255, 240], 2081 "mint cream":[245, 255, 250], 2082 "mintcream":[245, 255, 250], 2083 "azure":[240, 255, 255], 2084 "alice blue":[240, 248, 255], 2085 "aliceblue":[240, 248, 255], 2086 "lavender":[230, 230, 250], 2087 "lavender blush":[255, 240, 245], 2088 "lavenderblush":[255, 240, 245], 2089 "misty rose":[255, 228, 225], 2090 "mistyrose":[255, 228, 225], 2091 "white":[255, 255, 255], 2092 "black":[0, 0, 0], 2093 "dark slate gray":[47, 79, 79], 2094 "darkslategray":[47, 79, 79], 2095 "dark slate grey":[47, 79, 79], 2096 "darkslategrey":[47, 79, 79], 2097 "dim gray":[105, 105, 105], 2098 "dimgray":[105, 105, 105], 2099 "dim grey":[105, 105, 105], 2100 "dimgrey":[105, 105, 105], 2101 "slate gray":[112, 128, 144], 2102 "slategray":[112, 128, 144], 2103 "slate grey":[112, 128, 144], 2104 "slategrey":[112, 128, 144], 2105 "light slate gray":[119, 136, 153], 2106 "lightslategray":[119, 136, 153], 2107 "light slate grey":[119, 136, 153], 2108 "lightslategrey":[119, 136, 153], 2109 "gray":[190, 190, 190], 2110 "grey":[190, 190, 190], 2111 "light grey":[211, 211, 211], 2112 "lightgrey":[211, 211, 211], 2113 "light gray":[211, 211, 211], 2114 "lightgray":[211, 211, 211], 2115 "midnight blue":[25, 25, 112], 2116 "midnightblue":[25, 25, 112], 2117 "navy":[0, 0, 128], 2118 "navy blue":[0, 0, 128], 2119 "navyblue":[0, 0, 128], 2120 "cornflower blue":[100, 149, 237], 2121 "cornflowerblue":[100, 149, 237], 2122 "dark slate blue":[72, 61, 139], 2123 "darkslateblue":[72, 61, 139], 2124 "slate blue":[106, 90, 205], 2125 "slateblue":[106, 90, 205], 2126 "medium slate blue":[123, 104, 238], 2127 "mediumslateblue":[123, 104, 238], 2128 "light slate blue":[132, 112, 255], 2129 "lightslateblue":[132, 112, 255], 2130 "medium blue":[0, 0, 205], 2131 "mediumblue":[0, 0, 205], 2132 "royal blue":[65, 105, 225], 2133 "royalblue":[65, 105, 225], 2134 "blue":[0, 0, 255], 2135 "dodger blue":[30, 144, 255], 2136 "dodgerblue":[30, 144, 255], 2137 "deep sky blue":[0, 191, 255], 2138 "deepskyblue":[0, 191, 255], 2139 "sky blue":[135, 206, 235], 2140 "skyblue":[135, 206, 235], 2141 "light sky blue":[135, 206, 250], 2142 "lightskyblue":[135, 206, 250], 2143 "steel blue":[70, 130, 180], 2144 "steelblue":[70, 130, 180], 2145 "light steel blue":[176, 196, 222], 2146 "lightsteelblue":[176, 196, 222], 2147 "light blue":[173, 216, 230], 2148 "lightblue":[173, 216, 230], 2149 "powder blue":[176, 224, 230], 2150 "powderblue":[176, 224, 230], 2151 "pale turquoise":[175, 238, 238], 2152 "paleturquoise":[175, 238, 238], 2153 "dark turquoise":[0, 206, 209], 2154 "darkturquoise":[0, 206, 209], 2155 "medium turquoise":[72, 209, 204], 2156 "mediumturquoise":[72, 209, 204], 2157 "turquoise":[64, 224, 208], 2158 "cyan":[0, 255, 255], 2159 "light cyan":[224, 255, 255], 2160 "lightcyan":[224, 255, 255], 2161 "cadet blue":[95, 158, 160], 2162 "cadetblue":[95, 158, 160], 2163 "medium aquamarine":[102, 205, 170], 2164 "mediumaquamarine":[102, 205, 170], 2165 "aquamarine":[127, 255, 212], 2166 "dark green":[0, 100, 0], 2167 "darkgreen":[0, 100, 0], 2168 "dark olive green":[85, 107, 47], 2169 "darkolivegreen":[85, 107, 47], 2170 "dark sea green":[143, 188, 143], 2171 "darkseagreen":[143, 188, 143], 2172 "sea green":[46, 139, 87], 2173 "seagreen":[46, 139, 87], 2174 "medium sea green":[60, 179, 113], 2175 "mediumseagreen":[60, 179, 113], 2176 "light sea green":[32, 178, 170], 2177 "lightseagreen":[32, 178, 170], 2178 "pale green":[152, 251, 152], 2179 "palegreen":[152, 251, 152], 2180 "spring green":[0, 255, 127], 2181 "springgreen":[0, 255, 127], 2182 "lawn green":[124, 252, 0], 2183 "lawngreen":[124, 252, 0], 2184 "green":[0, 255, 0], 2185 "chartreuse":[127, 255, 0], 2186 "medium spring green":[0, 250, 154], 2187 "mediumspringgreen":[0, 250, 154], 2188 "green yellow":[173, 255, 47], 2189 "greenyellow":[173, 255, 47], 2190 "lime green":[50, 205, 50], 2191 "limegreen":[50, 205, 50], 2192 "yellow green":[154, 205, 50], 2193 "yellowgreen":[154, 205, 50], 2194 "forest green":[34, 139, 34], 2195 "forestgreen":[34, 139, 34], 2196 "olive drab":[107, 142, 35], 2197 "olivedrab":[107, 142, 35], 2198 "dark khaki":[189, 183, 107], 2199 "darkkhaki":[189, 183, 107], 2200 "khaki":[240, 230, 140], 2201 "pale goldenrod":[238, 232, 170], 2202 "palegoldenrod":[238, 232, 170], 2203 "light goldenrod yellow":[250, 250, 210], 2204 "lightgoldenrodyellow":[250, 250, 210], 2205 "light yellow":[255, 255, 224], 2206 "lightyellow":[255, 255, 224], 2207 "yellow":[255, 255, 0], 2208 "gold":[255, 215, 0], 2209 "light goldenrod":[238, 221, 130], 2210 "lightgoldenrod":[238, 221, 130], 2211 "goldenrod":[218, 165, 32], 2212 "dark goldenrod":[184, 134, 11], 2213 "darkgoldenrod":[184, 134, 11], 2214 "rosy brown":[188, 143, 143], 2215 "rosybrown":[188, 143, 143], 2216 "indian red":[205, 92, 92], 2217 "indianred":[205, 92, 92], 2218 "saddle brown":[139, 69, 19], 2219 "saddlebrown":[139, 69, 19], 2220 "sienna":[160, 82, 45], 2221 "peru":[205, 133, 63], 2222 "burlywood":[222, 184, 135], 2223 "beige":[245, 245, 220], 2224 "wheat":[245, 222, 179], 2225 "sandy brown":[244, 164, 96], 2226 "sandybrown":[244, 164, 96], 2227 "tan":[210, 180, 140], 2228 "chocolate":[210, 105, 30], 2229 "firebrick":[178, 34, 34], 2230 "brown":[165, 42, 42], 2231 "dark salmon":[233, 150, 122], 2232 "darksalmon":[233, 150, 122], 2233 "salmon":[250, 128, 114], 2234 "light salmon":[255, 160, 122], 2235 "lightsalmon":[255, 160, 122], 2236 "orange":[255, 165, 0], 2237 "dark orange":[255, 140, 0], 2238 "darkorange":[255, 140, 0], 2239 "coral":[255, 127, 80], 2240 "light coral":[240, 128, 128], 2241 "lightcoral":[240, 128, 128], 2242 "tomato":[255, 99, 71], 2243 "orange red":[255, 69, 0], 2244 "orangered":[255, 69, 0], 2245 "red":[255, 0, 0], 2246 "hot pink":[255, 105, 180], 2247 "hotpink":[255, 105, 180], 2248 "deep pink":[255, 20, 147], 2249 "deeppink":[255, 20, 147], 2250 "pink":[255, 192, 203], 2251 "light pink":[255, 182, 193], 2252 "lightpink":[255, 182, 193], 2253 "pale violet red":[219, 112, 147], 2254 "palevioletred":[219, 112, 147], 2255 "maroon":[176, 48, 96], 2256 "medium violet red":[199, 21, 133], 2257 "mediumvioletred":[199, 21, 133], 2258 "violet red":[208, 32, 144], 2259 "violetred":[208, 32, 144], 2260 "magenta":[255, 0, 255], 2261 "violet":[238, 130, 238], 2262 "plum":[221, 160, 221], 2263 "orchid":[218, 112, 214], 2264 "medium orchid":[186, 85, 211], 2265 "mediumorchid":[186, 85, 211], 2266 "dark orchid":[153, 50, 204], 2267 "darkorchid":[153, 50, 204], 2268 "dark violet":[148, 0, 211], 2269 "darkviolet":[148, 0, 211], 2270 "blue violet":[138, 43, 226], 2271 "blueviolet":[138, 43, 226], 2272 "purple":[160, 32, 240], 2273 "medium purple":[147, 112, 219], 2274 "mediumpurple":[147, 112, 219], 2275 "thistle":[216, 191, 216], 2276 "snow1":[255, 250, 250], 2277 "snow2":[238, 233, 233], 2278 "snow3":[205, 201, 201], 2279 "snow4":[139, 137, 137], 2280 "seashell1":[255, 245, 238], 2281 "seashell2":[238, 229, 222], 2282 "seashell3":[205, 197, 191], 2283 "seashell4":[139, 134, 130], 2284 "antiquewhite1":[255, 239, 219], 2285 "antiquewhite2":[238, 223, 204], 2286 "antiquewhite3":[205, 192, 176], 2287 "antiquewhite4":[139, 131, 120], 2288 "bisque1":[255, 228, 196], 2289 "bisque2":[238, 213, 183], 2290 "bisque3":[205, 183, 158], 2291 "bisque4":[139, 125, 107], 2292 "peachpuff1":[255, 218, 185], 2293 "peachpuff2":[238, 203, 173], 2294 "peachpuff3":[205, 175, 149], 2295 "peachpuff4":[139, 119, 101], 2296 "navajowhite1":[255, 222, 173], 2297 "navajowhite2":[238, 207, 161], 2298 "navajowhite3":[205, 179, 139], 2299 "navajowhite4":[139, 121, 94], 2300 "lemonchiffon1":[255, 250, 205], 2301 "lemonchiffon2":[238, 233, 191], 2302 "lemonchiffon3":[205, 201, 165], 2303 "lemonchiffon4":[139, 137, 112], 2304 "cornsilk1":[255, 248, 220], 2305 "cornsilk2":[238, 232, 205], 2306 "cornsilk3":[205, 200, 177], 2307 "cornsilk4":[139, 136, 120], 2308 "ivory1":[255, 255, 240], 2309 "ivory2":[238, 238, 224], 2310 "ivory3":[205, 205, 193], 2311 "ivory4":[139, 139, 131], 2312 "honeydew1":[240, 255, 240], 2313 "honeydew2":[224, 238, 224], 2314 "honeydew3":[193, 205, 193], 2315 "honeydew4":[131, 139, 131], 2316 "lavenderblush1":[255, 240, 245], 2317 "lavenderblush2":[238, 224, 229], 2318 "lavenderblush3":[205, 193, 197], 2319 "lavenderblush4":[139, 131, 134], 2320 "mistyrose1":[255, 228, 225], 2321 "mistyrose2":[238, 213, 210], 2322 "mistyrose3":[205, 183, 181], 2323 "mistyrose4":[139, 125, 123], 2324 "azure1":[240, 255, 255], 2325 "azure2":[224, 238, 238], 2326 "azure3":[193, 205, 205], 2327 "azure4":[131, 139, 139], 2328 "slateblue1":[131, 111, 255], 2329 "slateblue2":[122, 103, 238], 2330 "slateblue3":[105, 89, 205], 2331 "slateblue4":[71, 60, 139], 2332 "royalblue1":[72, 118, 255], 2333 "royalblue2":[67, 110, 238], 2334 "royalblue3":[58, 95, 205], 2335 "royalblue4":[39, 64, 139], 2336 "blue1":[0, 0, 255], 2337 "blue2":[0, 0, 238], 2338 "blue3":[0, 0, 205], 2339 "blue4":[0, 0, 139], 2340 "dodgerblue1":[30, 144, 255], 2341 "dodgerblue2":[28, 134, 238], 2342 "dodgerblue3":[24, 116, 205], 2343 "dodgerblue4":[16, 78, 139], 2344 "steelblue1":[99, 184, 255], 2345 "steelblue2":[92, 172, 238], 2346 "steelblue3":[79, 148, 205], 2347 "steelblue4":[54, 100, 139], 2348 "deepskyblue1":[0, 191, 255], 2349 "deepskyblue2":[0, 178, 238], 2350 "deepskyblue3":[0, 154, 205], 2351 "deepskyblue4":[0, 104, 139], 2352 "skyblue1":[135, 206, 255], 2353 "skyblue2":[126, 192, 238], 2354 "skyblue3":[108, 166, 205], 2355 "skyblue4":[74, 112, 139], 2356 "lightskyblue1":[176, 226, 255], 2357 "lightskyblue2":[164, 211, 238], 2358 "lightskyblue3":[141, 182, 205], 2359 "lightskyblue4":[96, 123, 139], 2360 "slategray1":[198, 226, 255], 2361 "slategray2":[185, 211, 238], 2362 "slategray3":[159, 182, 205], 2363 "slategray4":[108, 123, 139], 2364 "lightsteelblue1":[202, 225, 255], 2365 "lightsteelblue2":[188, 210, 238], 2366 "lightsteelblue3":[162, 181, 205], 2367 "lightsteelblue4":[110, 123, 139], 2368 "lightblue1":[191, 239, 255], 2369 "lightblue2":[178, 223, 238], 2370 "lightblue3":[154, 192, 205], 2371 "lightblue4":[104, 131, 139], 2372 "lightcyan1":[224, 255, 255], 2373 "lightcyan2":[209, 238, 238], 2374 "lightcyan3":[180, 205, 205], 2375 "lightcyan4":[122, 139, 139], 2376 "paleturquoise1":[187, 255, 255], 2377 "paleturquoise2":[174, 238, 238], 2378 "paleturquoise3":[150, 205, 205], 2379 "paleturquoise4":[102, 139, 139], 2380 "cadetblue1":[152, 245, 255], 2381 "cadetblue2":[142, 229, 238], 2382 "cadetblue3":[122, 197, 205], 2383 "cadetblue4":[83, 134, 139], 2384 "turquoise1":[0, 245, 255], 2385 "turquoise2":[0, 229, 238], 2386 "turquoise3":[0, 197, 205], 2387 "turquoise4":[0, 134, 139], 2388 "cyan1":[0, 255, 255], 2389 "cyan2":[0, 238, 238], 2390 "cyan3":[0, 205, 205], 2391 "cyan4":[0, 139, 139], 2392 "darkslategray1":[151, 255, 255], 2393 "darkslategray2":[141, 238, 238], 2394 "darkslategray3":[121, 205, 205], 2395 "darkslategray4":[82, 139, 139], 2396 "aquamarine1":[127, 255, 212], 2397 "aquamarine2":[118, 238, 198], 2398 "aquamarine3":[102, 205, 170], 2399 "aquamarine4":[69, 139, 116], 2400 "darkseagreen1":[193, 255, 193], 2401 "darkseagreen2":[180, 238, 180], 2402 "darkseagreen3":[155, 205, 155], 2403 "darkseagreen4":[105, 139, 105], 2404 "seagreen1":[84, 255, 159], 2405 "seagreen2":[78, 238, 148], 2406 "seagreen3":[67, 205, 128], 2407 "seagreen4":[46, 139, 87], 2408 "palegreen1":[154, 255, 154], 2409 "palegreen2":[144, 238, 144], 2410 "palegreen3":[124, 205, 124], 2411 "palegreen4":[84, 139, 84], 2412 "springgreen1":[0, 255, 127], 2413 "springgreen2":[0, 238, 118], 2414 "springgreen3":[0, 205, 102], 2415 "springgreen4":[0, 139, 69], 2416 "green1":[0, 255, 0], 2417 "green2":[0, 238, 0], 2418 "green3":[0, 205, 0], 2419 "green4":[0, 139, 0], 2420 "chartreuse1":[127, 255, 0], 2421 "chartreuse2":[118, 238, 0], 2422 "chartreuse3":[102, 205, 0], 2423 "chartreuse4":[69, 139, 0], 2424 "olivedrab1":[192, 255, 62], 2425 "olivedrab2":[179, 238, 58], 2426 "olivedrab3":[154, 205, 50], 2427 "olivedrab4":[105, 139, 34], 2428 "darkolivegreen1":[202, 255, 112], 2429 "darkolivegreen2":[188, 238, 104], 2430 "darkolivegreen3":[162, 205, 90], 2431 "darkolivegreen4":[110, 139, 61], 2432 "khaki1":[255, 246, 143], 2433 "khaki2":[238, 230, 133], 2434 "khaki3":[205, 198, 115], 2435 "khaki4":[139, 134, 78], 2436 "lightgoldenrod1":[255, 236, 139], 2437 "lightgoldenrod2":[238, 220, 130], 2438 "lightgoldenrod3":[205, 190, 112], 2439 "lightgoldenrod4":[139, 129, 76], 2440 "lightyellow1":[255, 255, 224], 2441 "lightyellow2":[238, 238, 209], 2442 "lightyellow3":[205, 205, 180], 2443 "lightyellow4":[139, 139, 122], 2444 "yellow1":[255, 255, 0], 2445 "yellow2":[238, 238, 0], 2446 "yellow3":[205, 205, 0], 2447 "yellow4":[139, 139, 0], 2448 "gold1":[255, 215, 0], 2449 "gold2":[238, 201, 0], 2450 "gold3":[205, 173, 0], 2451 "gold4":[139, 117, 0], 2452 "goldenrod1":[255, 193, 37], 2453 "goldenrod2":[238, 180, 34], 2454 "goldenrod3":[205, 155, 29], 2455 "goldenrod4":[139, 105, 20], 2456 "darkgoldenrod1":[255, 185, 15], 2457 "darkgoldenrod2":[238, 173, 14], 2458 "darkgoldenrod3":[205, 149, 12], 2459 "darkgoldenrod4":[139, 101, 8], 2460 "rosybrown1":[255, 193, 193], 2461 "rosybrown2":[238, 180, 180], 2462 "rosybrown3":[205, 155, 155], 2463 "rosybrown4":[139, 105, 105], 2464 "indianred1":[255, 106, 106], 2465 "indianred2":[238, 99, 99], 2466 "indianred3":[205, 85, 85], 2467 "indianred4":[139, 58, 58], 2468 "sienna1":[255, 130, 71], 2469 "sienna2":[238, 121, 66], 2470 "sienna3":[205, 104, 57], 2471 "sienna4":[139, 71, 38], 2472 "burlywood1":[255, 211, 155], 2473 "burlywood2":[238, 197, 145], 2474 "burlywood3":[205, 170, 125], 2475 "burlywood4":[139, 115, 85], 2476 "wheat1":[255, 231, 186], 2477 "wheat2":[238, 216, 174], 2478 "wheat3":[205, 186, 150], 2479 "wheat4":[139, 126, 102], 2480 "tan1":[255, 165, 79], 2481 "tan2":[238, 154, 73], 2482 "tan3":[205, 133, 63], 2483 "tan4":[139, 90, 43], 2484 "chocolate1":[255, 127, 36], 2485 "chocolate2":[238, 118, 33], 2486 "chocolate3":[205, 102, 29], 2487 "chocolate4":[139, 69, 19], 2488 "firebrick1":[255, 48, 48], 2489 "firebrick2":[238, 44, 44], 2490 "firebrick3":[205, 38, 38], 2491 "firebrick4":[139, 26, 26], 2492 "brown1":[255, 64, 64], 2493 "brown2":[238, 59, 59], 2494 "brown3":[205, 51, 51], 2495 "brown4":[139, 35, 35], 2496 "salmon1":[255, 140, 105], 2497 "salmon2":[238, 130, 98], 2498 "salmon3":[205, 112, 84], 2499 "salmon4":[139, 76, 57], 2500 "lightsalmon1":[255, 160, 122], 2501 "lightsalmon2":[238, 149, 114], 2502 "lightsalmon3":[205, 129, 98], 2503 "lightsalmon4":[139, 87, 66], 2504 "orange1":[255, 165, 0], 2505 "orange2":[238, 154, 0], 2506 "orange3":[205, 133, 0], 2507 "orange4":[139, 90, 0], 2508 "darkorange1":[255, 127, 0], 2509 "darkorange2":[238, 118, 0], 2510 "darkorange3":[205, 102, 0], 2511 "darkorange4":[139, 69, 0], 2512 "coral1":[255, 114, 86], 2513 "coral2":[238, 106, 80], 2514 "coral3":[205, 91, 69], 2515 "coral4":[139, 62, 47], 2516 "tomato1":[255, 99, 71], 2517 "tomato2":[238, 92, 66], 2518 "tomato3":[205, 79, 57], 2519 "tomato4":[139, 54, 38], 2520 "orangered1":[255, 69, 0], 2521 "orangered2":[238, 64, 0], 2522 "orangered3":[205, 55, 0], 2523 "orangered4":[139, 37, 0], 2524 "red1":[255, 0, 0], 2525 "red2":[238, 0, 0], 2526 "red3":[205, 0, 0], 2527 "red4":[139, 0, 0], 2528 "deeppink1":[255, 20, 147], 2529 "deeppink2":[238, 18, 137], 2530 "deeppink3":[205, 16, 118], 2531 "deeppink4":[139, 10, 80], 2532 "hotpink1":[255, 110, 180], 2533 "hotpink2":[238, 106, 167], 2534 "hotpink3":[205, 96, 144], 2535 "hotpink4":[139, 58, 98], 2536 "pink1":[255, 181, 197], 2537 "pink2":[238, 169, 184], 2538 "pink3":[205, 145, 158], 2539 "pink4":[139, 99, 108], 2540 "lightpink1":[255, 174, 185], 2541 "lightpink2":[238, 162, 173], 2542 "lightpink3":[205, 140, 149], 2543 "lightpink4":[139, 95, 101], 2544 "palevioletred1":[255, 130, 171], 2545 "palevioletred2":[238, 121, 159], 2546 "palevioletred3":[205, 104, 137], 2547 "palevioletred4":[139, 71, 93], 2548 "maroon1":[255, 52, 179], 2549 "maroon2":[238, 48, 167], 2550 "maroon3":[205, 41, 144], 2551 "maroon4":[139, 28, 98], 2552 "violetred1":[255, 62, 150], 2553 "violetred2":[238, 58, 140], 2554 "violetred3":[205, 50, 120], 2555 "violetred4":[139, 34, 82], 2556 "magenta1":[255, 0, 255], 2557 "magenta2":[238, 0, 238], 2558 "magenta3":[205, 0, 205], 2559 "magenta4":[139, 0, 139], 2560 "orchid1":[255, 131, 250], 2561 "orchid2":[238, 122, 233], 2562 "orchid3":[205, 105, 201], 2563 "orchid4":[139, 71, 137], 2564 "plum1":[255, 187, 255], 2565 "plum2":[238, 174, 238], 2566 "plum3":[205, 150, 205], 2567 "plum4":[139, 102, 139], 2568 "mediumorchid1":[224, 102, 255], 2569 "mediumorchid2":[209, 95, 238], 2570 "mediumorchid3":[180, 82, 205], 2571 "mediumorchid4":[122, 55, 139], 2572 "darkorchid1":[191, 62, 255], 2573 "darkorchid2":[178, 58, 238], 2574 "darkorchid3":[154, 50, 205], 2575 "darkorchid4":[104, 34, 139], 2576 "purple1":[155, 48, 255], 2577 "purple2":[145, 44, 238], 2578 "purple3":[125, 38, 205], 2579 "purple4":[85, 26, 139], 2580 "mediumpurple1":[171, 130, 255], 2581 "mediumpurple2":[159, 121, 238], 2582 "mediumpurple3":[137, 104, 205], 2583 "mediumpurple4":[93, 71, 139], 2584 "thistle1":[255, 225, 255], 2585 "thistle2":[238, 210, 238], 2586 "thistle3":[205, 181, 205], 2587 "thistle4":[139, 123, 139], 2588 "gray0":[0, 0, 0], 2589 "grey0":[0, 0, 0], 2590 "gray1":[3, 3, 3], 2591 "grey1":[3, 3, 3], 2592 "gray2":[5, 5, 5], 2593 "grey2":[5, 5, 5], 2594 "gray3":[8, 8, 8], 2595 "grey3":[8, 8, 8], 2596 "gray4":[10, 10, 10], 2597 "grey4":[10, 10, 10], 2598 "gray5":[13, 13, 13], 2599 "grey5":[13, 13, 13], 2600 "gray6":[15, 15, 15], 2601 "grey6":[15, 15, 15], 2602 "gray7":[18, 18, 18], 2603 "grey7":[18, 18, 18], 2604 "gray8":[20, 20, 20], 2605 "grey8":[20, 20, 20], 2606 "gray9":[23, 23, 23], 2607 "grey9":[23, 23, 23], 2608 "gray10":[26, 26, 26], 2609 "grey10":[26, 26, 26], 2610 "gray11":[28, 28, 28], 2611 "grey11":[28, 28, 28], 2612 "gray12":[31, 31, 31], 2613 "grey12":[31, 31, 31], 2614 "gray13":[33, 33, 33], 2615 "grey13":[33, 33, 33], 2616 "gray14":[36, 36, 36], 2617 "grey14":[36, 36, 36], 2618 "gray15":[38, 38, 38], 2619 "grey15":[38, 38, 38], 2620 "gray16":[41, 41, 41], 2621 "grey16":[41, 41, 41], 2622 "gray17":[43, 43, 43], 2623 "grey17":[43, 43, 43], 2624 "gray18":[46, 46, 46], 2625 "grey18":[46, 46, 46], 2626 "gray19":[48, 48, 48], 2627 "grey19":[48, 48, 48], 2628 "gray20":[51, 51, 51], 2629 "grey20":[51, 51, 51], 2630 "gray21":[54, 54, 54], 2631 "grey21":[54, 54, 54], 2632 "gray22":[56, 56, 56], 2633 "grey22":[56, 56, 56], 2634 "gray23":[59, 59, 59], 2635 "grey23":[59, 59, 59], 2636 "gray24":[61, 61, 61], 2637 "grey24":[61, 61, 61], 2638 "gray25":[64, 64, 64], 2639 "grey25":[64, 64, 64], 2640 "gray26":[66, 66, 66], 2641 "grey26":[66, 66, 66], 2642 "gray27":[69, 69, 69], 2643 "grey27":[69, 69, 69], 2644 "gray28":[71, 71, 71], 2645 "grey28":[71, 71, 71], 2646 "gray29":[74, 74, 74], 2647 "grey29":[74, 74, 74], 2648 "gray30":[77, 77, 77], 2649 "grey30":[77, 77, 77], 2650 "gray31":[79, 79, 79], 2651 "grey31":[79, 79, 79], 2652 "gray32":[82, 82, 82], 2653 "grey32":[82, 82, 82], 2654 "gray33":[84, 84, 84], 2655 "grey33":[84, 84, 84], 2656 "gray34":[87, 87, 87], 2657 "grey34":[87, 87, 87], 2658 "gray35":[89, 89, 89], 2659 "grey35":[89, 89, 89], 2660 "gray36":[92, 92, 92], 2661 "grey36":[92, 92, 92], 2662 "gray37":[94, 94, 94], 2663 "grey37":[94, 94, 94], 2664 "gray38":[97, 97, 97], 2665 "grey38":[97, 97, 97], 2666 "gray39":[99, 99, 99], 2667 "grey39":[99, 99, 99], 2668 "gray40":[102, 102, 102], 2669 "grey40":[102, 102, 102], 2670 "gray41":[105, 105, 105], 2671 "grey41":[105, 105, 105], 2672 "gray42":[107, 107, 107], 2673 "grey42":[107, 107, 107], 2674 "gray43":[110, 110, 110], 2675 "grey43":[110, 110, 110], 2676 "gray44":[112, 112, 112], 2677 "grey44":[112, 112, 112], 2678 "gray45":[115, 115, 115], 2679 "grey45":[115, 115, 115], 2680 "gray46":[117, 117, 117], 2681 "grey46":[117, 117, 117], 2682 "gray47":[120, 120, 120], 2683 "grey47":[120, 120, 120], 2684 "gray48":[122, 122, 122], 2685 "grey48":[122, 122, 122], 2686 "gray49":[125, 125, 125], 2687 "grey49":[125, 125, 125], 2688 "gray50":[127, 127, 127], 2689 "grey50":[127, 127, 127], 2690 "gray51":[130, 130, 130], 2691 "grey51":[130, 130, 130], 2692 "gray52":[133, 133, 133], 2693 "grey52":[133, 133, 133], 2694 "gray53":[135, 135, 135], 2695 "grey53":[135, 135, 135], 2696 "gray54":[138, 138, 138], 2697 "grey54":[138, 138, 138], 2698 "gray55":[140, 140, 140], 2699 "grey55":[140, 140, 140], 2700 "gray56":[143, 143, 143], 2701 "grey56":[143, 143, 143], 2702 "gray57":[145, 145, 145], 2703 "grey57":[145, 145, 145], 2704 "gray58":[148, 148, 148], 2705 "grey58":[148, 148, 148], 2706 "gray59":[150, 150, 150], 2707 "grey59":[150, 150, 150], 2708 "gray60":[153, 153, 153], 2709 "grey60":[153, 153, 153], 2710 "gray61":[156, 156, 156], 2711 "grey61":[156, 156, 156], 2712 "gray62":[158, 158, 158], 2713 "grey62":[158, 158, 158], 2714 "gray63":[161, 161, 161], 2715 "grey63":[161, 161, 161], 2716 "gray64":[163, 163, 163], 2717 "grey64":[163, 163, 163], 2718 "gray65":[166, 166, 166], 2719 "grey65":[166, 166, 166], 2720 "gray66":[168, 168, 168], 2721 "grey66":[168, 168, 168], 2722 "gray67":[171, 171, 171], 2723 "grey67":[171, 171, 171], 2724 "gray68":[173, 173, 173], 2725 "grey68":[173, 173, 173], 2726 "gray69":[176, 176, 176], 2727 "grey69":[176, 176, 176], 2728 "gray70":[179, 179, 179], 2729 "grey70":[179, 179, 179], 2730 "gray71":[181, 181, 181], 2731 "grey71":[181, 181, 181], 2732 "gray72":[184, 184, 184], 2733 "grey72":[184, 184, 184], 2734 "gray73":[186, 186, 186], 2735 "grey73":[186, 186, 186], 2736 "gray74":[189, 189, 189], 2737 "grey74":[189, 189, 189], 2738 "gray75":[191, 191, 191], 2739 "grey75":[191, 191, 191], 2740 "gray76":[194, 194, 194], 2741 "grey76":[194, 194, 194], 2742 "gray77":[196, 196, 196], 2743 "grey77":[196, 196, 196], 2744 "gray78":[199, 199, 199], 2745 "grey78":[199, 199, 199], 2746 "gray79":[201, 201, 201], 2747 "grey79":[201, 201, 201], 2748 "gray80":[204, 204, 204], 2749 "grey80":[204, 204, 204], 2750 "gray81":[207, 207, 207], 2751 "grey81":[207, 207, 207], 2752 "gray82":[209, 209, 209], 2753 "grey82":[209, 209, 209], 2754 "gray83":[212, 212, 212], 2755 "grey83":[212, 212, 212], 2756 "gray84":[214, 214, 214], 2757 "grey84":[214, 214, 214], 2758 "gray85":[217, 217, 217], 2759 "grey85":[217, 217, 217], 2760 "gray86":[219, 219, 219], 2761 "grey86":[219, 219, 219], 2762 "gray87":[222, 222, 222], 2763 "grey87":[222, 222, 222], 2764 "gray88":[224, 224, 224], 2765 "grey88":[224, 224, 224], 2766 "gray89":[227, 227, 227], 2767 "grey89":[227, 227, 227], 2768 "gray90":[229, 229, 229], 2769 "grey90":[229, 229, 229], 2770 "gray91":[232, 232, 232], 2771 "grey91":[232, 232, 232], 2772 "gray92":[235, 235, 235], 2773 "grey92":[235, 235, 235], 2774 "gray93":[237, 237, 237], 2775 "grey93":[237, 237, 237], 2776 "gray94":[240, 240, 240], 2777 "grey94":[240, 240, 240], 2778 "gray95":[242, 242, 242], 2779 "grey95":[242, 242, 242], 2780 "gray96":[245, 245, 245], 2781 "grey96":[245, 245, 245], 2782 "gray97":[247, 247, 247], 2783 "grey97":[247, 247, 247], 2784 "gray98":[250, 250, 250], 2785 "grey98":[250, 250, 250], 2786 "gray99":[252, 252, 252], 2787 "grey99":[252, 252, 252], 2788 "gray100":[255, 255, 255], 2789 "grey100":[255, 255, 255], 2790 "dark grey":[169, 169, 169], 2791 "darkgrey":[169, 169, 169], 2792 "dark gray":[169, 169, 169], 2793 "darkgray":[169, 169, 169], 2794 "dark blue":[0, 0, 139], 2795 "darkblue":[0, 0, 139], 2796 "dark cyan":[0, 139, 139], 2797 "darkcyan":[0, 139, 139], 2798 "dark magenta":[139, 0, 139], 2799 "darkmagenta":[139, 0, 139], 2800 "dark red":[139, 0, 0], 2801 "darkred":[139, 0, 0], 2802 "light green":[144, 238, 144], 2803 "lightgreen":[144, 238, 144], 2804 "olive":[128, 128, 0], 2805 "teal":[0, 128, 128]} 2806 2807 2808 # ------------- Key constants ------------------------------- 2809 2810 ''' 2811 The key names used by Qt. 2812 Constant Value Description 2813 2814 Qt.Key_Escape 0x01000000 2815 2816 Qt.Key_Tab 0x01000001 2817 2818 Qt.Key_Backtab 0x01000002 2819 2820 Qt.Key_Backspace 0x01000003 2821 2822 Qt.Key_Return 0x01000004 2823 2824 Qt.Key_Enter 0x01000005 Typically located on the keypad. 2825 2826 Qt.Key_Insert 0x01000006 2827 2828 Qt.Key_Delete 0x01000007 2829 2830 Qt.Key_Pause 0x01000008 The Pause/Break key (Note: Not anything to do with pausing media) 2831 2832 Qt.Key_Print 0x01000009 2833 2834 Qt.Key_SysReq 0x0100000a 2835 2836 Qt.Key_Clear 0x0100000b 2837 2838 Qt.Key_Home 0x01000010 2839 2840 Qt.Key_End 0x01000011 2841 2842 Qt.Key_Left 0x01000012 2843 2844 Qt.Key_Up 0x01000013 2845 2846 Qt.Key_Right 0x01000014 2847 2848 Qt.Key_Down 0x01000015 2849 2850 Qt.Key_PageUp 0x01000016 2851 2852 Qt.Key_PageDown 0x01000017 2853 2854 Qt.Key_Shift 0x01000020 2855 2856 Qt.Key_Control 0x01000021 On Mac OS X, this corresponds to the Command keys. 2857 2858 Qt.Key_Meta 0x01000022 On Mac OS X, this corresponds to the Control keys. On Windows keyboards, this key is mapped to the Windows key. 2859 2860 Qt.Key_Alt 0x01000023 2861 2862 Qt.Key_AltGr 0x01001103 On Windows, when the KeyDown event for this key is sent, the Ctrl+Alt modifiers are also set. 2863 2864 Qt.Key_CapsLock 0x01000024 2865 2866 Qt.Key_NumLock 0x01000025 2867 2868 Qt.Key_ScrollLock 0x01000026 2869 2870 Qt.Key_F1 0x01000030 2871 2872 Qt.Key_F2 0x01000031 2873 2874 Qt.Key_F3 0x01000032 2875 2876 Qt.Key_F4 0x01000033 2877 2878 Qt.Key_F5 0x01000034 2879 2880 Qt.Key_F6 0x01000035 2881 2882 Qt.Key_F7 0x01000036 2883 2884 Qt.Key_F8 0x01000037 2885 2886 Qt.Key_F9 0x01000038 2887 2888 Qt.Key_F10 0x01000039 2889 2890 Qt.Key_F11 0x0100003a 2891 2892 Qt.Key_F12 0x0100003b 2893 2894 Qt.Key_F13 0x0100003c 2895 2896 Qt.Key_F14 0x0100003d 2897 2898 Qt.Key_F15 0x0100003e 2899 2900 Qt.Key_F16 0x0100003f 2901 2902 Qt.Key_F17 0x01000040 2903 2904 Qt.Key_F18 0x01000041 2905 2906 Qt.Key_F19 0x01000042 2907 2908 Qt.Key_F20 0x01000043 2909 2910 Qt.Key_F21 0x01000044 2911 2912 Qt.Key_F22 0x01000045 2913 2914 Qt.Key_F23 0x01000046 2915 2916 Qt.Key_F24 0x01000047 2917 2918 Qt.Key_F25 0x01000048 2919 2920 Qt.Key_F26 0x01000049 2921 2922 Qt.Key_F27 0x0100004a 2923 2924 Qt.Key_F28 0x0100004b 2925 2926 Qt.Key_F29 0x0100004c 2927 2928 Qt.Key_F30 0x0100004d 2929 2930 Qt.Key_F31 0x0100004e 2931 2932 Qt.Key_F32 0x0100004f 2933 2934 Qt.Key_F33 0x01000050 2935 2936 Qt.Key_F34 0x01000051 2937 2938 Qt.Key_F35 0x01000052 2939 2940 Qt.Key_Super_L 0x01000053 2941 2942 Qt.Key_Super_R 0x01000054 2943 2944 Qt.Key_Menu 0x01000055 2945 2946 Qt.Key_Hyper_L 0x01000056 2947 2948 Qt.Key_Hyper_R 0x01000057 2949 2950 Qt.Key_Help 0x01000058 2951 2952 Qt.Key_Direction_L 0x01000059 2953 2954 Qt.Key_Direction_R 0x01000060 2955 2956 Qt.Key_Space 0x20 2957 2958 Qt.Key_Any Key_Space 2959 2960 Qt.Key_Exclam 0x21 2961 2962 Qt.Key_QuoteDbl 0x22 2963 2964 Qt.Key_NumberSign 0x23 2965 2966 Qt.Key_Dollar 0x24 2967 2968 Qt.Key_Percent 0x25 2969 2970 Qt.Key_Ampersand 0x26 2971 2972 Qt.Key_Apostrophe 0x27 2973 2974 Qt.Key_ParenLeft 0x28 2975 2976 Qt.Key_ParenRight 0x29 2977 2978 Qt.Key_Asterisk 0x2a 2979 2980 Qt.Key_Plus 0x2b 2981 2982 Qt.Key_Comma 0x2c 2983 2984 Qt.Key_Minus 0x2d 2985 2986 Qt.Key_Period 0x2e 2987 2988 Qt.Key_Slash 0x2f 2989 2990 Qt.Key_0 0x30 2991 2992 Qt.Key_1 0x31 2993 2994 Qt.Key_2 0x32 2995 2996 Qt.Key_3 0x33 2997 2998 Qt.Key_4 0x34 2999 3000 Qt.Key_5 0x35 3001 3002 Qt.Key_6 0x36 3003 3004 Qt.Key_7 0x37 3005 3006 Qt.Key_8 0x38 3007 3008 Qt.Key_9 0x39 3009 3010 Qt.Key_Colon 0x3a 3011 3012 Qt.Key_Semicolon 0x3b 3013 3014 Qt.Key_Less 0x3c 3015 3016 Qt.Key_Equal 0x3d 3017 3018 Qt.Key_Greater 0x3e 3019 3020 Qt.Key_Question 0x3f 3021 3022 Qt.Key_At 0x40 3023 3024 Qt.Key_A 0x41 3025 3026 Qt.Key_B 0x42 3027 3028 Qt.Key_C 0x43 3029 3030 Qt.Key_D 0x44 3031 3032 Qt.Key_E 0x45 3033 3034 Qt.Key_F 0x46 3035 3036 Qt.Key_G 0x47 3037 3038 Qt.Key_H 0x48 3039 3040 Qt.Key_I 0x49 3041 3042 Qt.Key_J 0x4a 3043 3044 Qt.Key_K 0x4b 3045 3046 Qt.Key_L 0x4c 3047 3048 Qt.Key_M 0x4d 3049 3050 Qt.Key_N 0x4e 3051 3052 Qt.Key_O 0x4f 3053 3054 Qt.Key_P 0x50 3055 3056 Qt.Key_Q 0x51 3057 3058 Qt.Key_R 0x52 3059 3060 Qt.Key_S 0x53 3061 3062 Qt.Key_T 0x54 3063 3064 Qt.Key_U 0x55 3065 3066 Qt.Key_V 0x56 3067 3068 Qt.Key_W 0x57 3069 3070 Qt.Key_X 0x58 3071 3072 Qt.Key_Y 0x59 3073 3074 Qt.Key_Z 0x5a 3075 3076 Qt.Key_BracketLeft 0x5b 3077 3078 Qt.Key_Backslash 0x5c 3079 3080 Qt.Key_BracketRight 0x5d 3081 3082 Qt.Key_AsciiCircum 0x5e 3083 3084 Qt.Key_Underscore 0x5f 3085 3086 Qt.Key_QuoteLeft 0x60 3087 3088 Qt.Key_BraceLeft 0x7b 3089 3090 Qt.Key_Bar 0x7c 3091 3092 Qt.Key_BraceRight 0x7d 3093 3094 Qt.Key_AsciiTilde 0x7e 3095 3096 Qt.Key_nobreakspace 0x0a0 3097 3098 Qt.Key_exclamdown 0x0a1 3099 3100 Qt.Key_cent 0x0a2 3101 3102 Qt.Key_sterling 0x0a3 3103 3104 Qt.Key_currency 0x0a4 3105 3106 Qt.Key_yen 0x0a5 3107 3108 Qt.Key_brokenbar 0x0a6 3109 3110 Qt.Key_section 0x0a7 3111 3112 Qt.Key_diaeresis 0x0a8 3113 3114 Qt.Key_copyright 0x0a9 3115 3116 Qt.Key_ordfeminine 0x0aa 3117 3118 Qt.Key_guillemotleft 0x0ab 3119 3120 Qt.Key_notsign 0x0ac 3121 3122 Qt.Key_hyphen 0x0ad 3123 3124 Qt.Key_registered 0x0ae 3125 3126 Qt.Key_macron 0x0af 3127 3128 Qt.Key_degree 0x0b0 3129 3130 Qt.Key_plusminus 0x0b1 3131 3132 Qt.Key_twosuperior 0x0b2 3133 3134 Qt.Key_threesuperior 0x0b3 3135 3136 Qt.Key_acute 0x0b4 3137 3138 Qt.Key_mu 0x0b5 3139 3140 Qt.Key_paragraph 0x0b6 3141 3142 Qt.Key_periodcentered 0x0b7 3143 3144 Qt.Key_cedilla 0x0b8 3145 3146 Qt.Key_onesuperior 0x0b9 3147 3148 Qt.Key_masculine 0x0ba 3149 3150 Qt.Key_guillemotright 0x0bb 3151 3152 Qt.Key_onequarter 0x0bc 3153 3154 Qt.Key_onehalf 0x0bd 3155 3156 Qt.Key_threequarters 0x0be 3157 3158 Qt.Key_questiondown 0x0bf 3159 3160 Qt.Key_Agrave 0x0c0 3161 3162 Qt.Key_Aacute 0x0c1 3163 3164 Qt.Key_Acircumflex 0x0c2 3165 3166 Qt.Key_Atilde 0x0c3 3167 3168 Qt.Key_Adiaeresis 0x0c4 3169 3170 Qt.Key_Aring 0x0c5 3171 3172 Qt.Key_AE 0x0c6 3173 3174 Qt.Key_Ccedilla 0x0c7 3175 3176 Qt.Key_Egrave 0x0c8 3177 3178 Qt.Key_Eacute 0x0c9 3179 3180 Qt.Key_Ecircumflex 0x0ca 3181 3182 Qt.Key_Ediaeresis 0x0cb 3183 3184 Qt.Key_Igrave 0x0cc 3185 3186 Qt.Key_Iacute 0x0cd 3187 3188 Qt.Key_Icircumflex 0x0ce 3189 3190 Qt.Key_Idiaeresis 0x0cf 3191 3192 Qt.Key_ETH 0x0d0 3193 3194 Qt.Key_Ntilde 0x0d1 3195 3196 Qt.Key_Ograve 0x0d2 3197 3198 Qt.Key_Oacute 0x0d3 3199 3200 Qt.Key_Ocircumflex 0x0d4 3201 3202 Qt.Key_Otilde 0x0d5 3203 3204 Qt.Key_Odiaeresis 0x0d6 3205 3206 Qt.Key_multiply 0x0d7 3207 3208 Qt.Key_Ooblique 0x0d8 3209 3210 Qt.Key_Ugrave 0x0d9 3211 3212 Qt.Key_Uacute 0x0da 3213 3214 Qt.Key_Ucircumflex 0x0db 3215 3216 Qt.Key_Udiaeresis 0x0dc 3217 3218 Qt.Key_Yacute 0x0dd 3219 3220 Qt.Key_THORN 0x0de 3221 3222 Qt.Key_ssharp 0x0df 3223 3224 Qt.Key_division 0x0f7 3225 3226 Qt.Key_ydiaeresis 0x0ff 3227 3228 Qt.Key_Multi_key 0x01001120 3229 3230 Qt.Key_Codeinput 0x01001137 3231 3232 Qt.Key_SingleCandidate 0x0100113c 3233 3234 Qt.Key_MultipleCandidate 0x0100113d 3235 3236 Qt.Key_PreviousCandidate 0x0100113e 3237 3238 Qt.Key_Mode_switch 0x0100117e 3239 3240 Qt.Key_Kanji 0x01001121 3241 3242 Qt.Key_Muhenkan 0x01001122 3243 3244 Qt.Key_Henkan 0x01001123 3245 3246 Qt.Key_Romaji 0x01001124 3247 3248 Qt.Key_Hiragana 0x01001125 3249 3250 Qt.Key_Katakana 0x01001126 3251 3252 Qt.Key_Hiragana_Katakana 0x01001127 3253 3254 Qt.Key_Zenkaku 0x01001128 3255 3256 Qt.Key_Hankaku 0x01001129 3257 3258 Qt.Key_Zenkaku_Hankaku 0x0100112a 3259 3260 Qt.Key_Touroku 0x0100112b 3261 3262 Qt.Key_Massyo 0x0100112c 3263 3264 Qt.Key_Kana_Lock 0x0100112d 3265 3266 Qt.Key_Kana_Shift 0x0100112e 3267 3268 Qt.Key_Eisu_Shift 0x0100112f 3269 3270 Qt.Key_Eisu_toggle 0x01001130 3271 3272 Qt.Key_Hangul 0x01001131 3273 3274 Qt.Key_Hangul_Start 0x01001132 3275 3276 Qt.Key_Hangul_End 0x01001133 3277 3278 Qt.Key_Hangul_Hanja 0x01001134 3279 3280 Qt.Key_Hangul_Jamo 0x01001135 3281 3282 Qt.Key_Hangul_Romaja 0x01001136 3283 3284 Qt.Key_Hangul_Jeonja 0x01001138 3285 3286 Qt.Key_Hangul_Banja 0x01001139 3287 3288 Qt.Key_Hangul_PreHanja 0x0100113a 3289 3290 Qt.Key_Hangul_PostHanja 0x0100113b 3291 3292 Qt.Key_Hangul_Special 0x0100113f 3293 3294 Qt.Key_Dead_Grave 0x01001250 3295 3296 Qt.Key_Dead_Acute 0x01001251 3297 3298 Qt.Key_Dead_Circumflex 0x01001252 3299 3300 Qt.Key_Dead_Tilde 0x01001253 3301 3302 Qt.Key_Dead_Macron 0x01001254 3303 3304 Qt.Key_Dead_Breve 0x01001255 3305 3306 Qt.Key_Dead_Abovedot 0x01001256 3307 3308 Qt.Key_Dead_Diaeresis 0x01001257 3309 3310 Qt.Key_Dead_Abovering 0x01001258 3311 3312 Qt.Key_Dead_Doubleacute 0x01001259 3313 3314 Qt.Key_Dead_Caron 0x0100125a 3315 3316 Qt.Key_Dead_Cedilla 0x0100125b 3317 3318 Qt.Key_Dead_Ogonek 0x0100125c 3319 3320 Qt.Key_Dead_Iota 0x0100125d 3321 3322 Qt.Key_Dead_Voiced_Sound 0x0100125e 3323 3324 Qt.Key_Dead_Semivoiced_Sound 0x0100125f 3325 3326 Qt.Key_Dead_Belowdot 0x01001260 3327 3328 Qt.Key_Dead_Hook 0x01001261 3329 3330 Qt.Key_Dead_Horn 0x01001262 3331 3332 Qt.Key_Back 0x01000061 3333 3334 Qt.Key_Forward 0x01000062 3335 3336 Qt.Key_Stop 0x01000063 3337 3338 Qt.Key_Refresh 0x01000064 3339 3340 Qt.Key_VolumeDown 0x01000070 3341 3342 Qt.Key_VolumeMute 0x01000071 3343 3344 Qt.Key_VolumeUp 0x01000072 3345 3346 Qt.Key_BassBoost 0x01000073 3347 3348 Qt.Key_BassUp 0x01000074 3349 3350 Qt.Key_BassDown 0x01000075 3351 3352 Qt.Key_TrebleUp 0x01000076 3353 3354 Qt.Key_TrebleDown 0x01000077 3355 3356 Qt.Key_MediaPlay 0x01000080 A key setting the state of the media player to play 3357 3358 Qt.Key_MediaStop 0x01000081 A key setting the state of the media player to stop 3359 3360 Qt.Key_MediaPrevious 0x01000082 3361 3362 Qt.Key_MediaNext 0x01000083 3363 3364 Qt.Key_MediaRecord 0x01000084 3365 3366 Qt.Key_MediaPause 0x1000085 A key setting the state of the media player to pause (Note: not the pause/break key) 3367 3368 Qt.Key_MediaTogglePlayPause 0x1000086 A key to toggle the play/pause state in the media player (rather than setting an absolute state) 3369 3370 Qt.Key_HomePage 0x01000090 3371 3372 Qt.Key_Favorites 0x01000091 3373 3374 Qt.Key_Search 0x01000092 3375 3376 Qt.Key_Standby 0x01000093 3377 3378 Qt.Key_OpenUrl 0x01000094 3379 3380 Qt.Key_LaunchMail 0x010000a0 3381 3382 Qt.Key_LaunchMedia 0x010000a1 3383 3384 Qt.Key_Launch0 0x010000a2 On X11 this key is mapped to "My Computer" (XF86XK_MyComputer) key for legacy reasons. 3385 3386 Qt.Key_Launch1 0x010000a3 On X11 this key is mapped to "Calculator" (XF86XK_Calculator) key for legacy reasons. 3387 3388 Qt.Key_Launch2 0x010000a4 On X11 this key is mapped to XF86XK_Launch0 key for legacy reasons. 3389 3390 Qt.Key_Launch3 0x010000a5 On X11 this key is mapped to XF86XK_Launch1 key for legacy reasons. 3391 3392 Qt.Key_Launch4 0x010000a6 On X11 this key is mapped to XF86XK_Launch2 key for legacy reasons. 3393 3394 Qt.Key_Launch5 0x010000a7 On X11 this key is mapped to XF86XK_Launch3 key for legacy reasons. 3395 3396 Qt.Key_Launch6 0x010000a8 On X11 this key is mapped to XF86XK_Launch4 key for legacy reasons. 3397 3398 Qt.Key_Launch7 0x010000a9 On X11 this key is mapped to XF86XK_Launch5 key for legacy reasons. 3399 3400 Qt.Key_Launch8 0x010000aa On X11 this key is mapped to XF86XK_Launch6 key for legacy reasons. 3401 3402 Qt.Key_Launch9 0x010000ab On X11 this key is mapped to XF86XK_Launch7 key for legacy reasons. 3403 3404 Qt.Key_LaunchA 0x010000ac On X11 this key is mapped to XF86XK_Launch8 key for legacy reasons. 3405 3406 Qt.Key_LaunchB 0x010000ad On X11 this key is mapped to XF86XK_Launch9 key for legacy reasons. 3407 3408 Qt.Key_LaunchC 0x010000ae On X11 this key is mapped to XF86XK_LaunchA key for legacy reasons. 3409 3410 Qt.Key_LaunchD 0x010000af On X11 this key is mapped to XF86XK_LaunchB key for legacy reasons. 3411 3412 Qt.Key_LaunchE 0x010000b0 On X11 this key is mapped to XF86XK_LaunchC key for legacy reasons. 3413 3414 Qt.Key_LaunchF 0x010000b1 On X11 this key is mapped to XF86XK_LaunchD key for legacy reasons. 3415 3416 Qt.Key_LaunchG 0x0100010e On X11 this key is mapped to XF86XK_LaunchE key for legacy reasons. 3417 3418 Qt.Key_LaunchH 0x0100010f On X11 this key is mapped to XF86XK_LaunchF key for legacy reasons. 3419 3420 Qt.Key_MonBrightnessUp 0x010000b2 3421 3422 Qt.Key_MonBrightnessDown 0x010000b3 3423 3424 Qt.Key_KeyboardLightOnOff 0x010000b4 3425 3426 Qt.Key_KeyboardBrightnessUp 0x010000b5 3427 3428 Qt.Key_KeyboardBrightnessDown 0x010000b6 3429 3430 Qt.Key_PowerOff 0x010000b7 3431 3432 Qt.Key_WakeUp 0x010000b8 3433 3434 Qt.Key_Eject 0x010000b9 3435 3436 Qt.Key_ScreenSaver 0x010000ba 3437 3438 Qt.Key_WWW 0x010000bb 3439 3440 Qt.Key_Memo 0x010000bc 3441 3442 Qt.Key_LightBulb 0x010000bd 3443 3444 Qt.Key_Shop 0x010000be 3445 3446 Qt.Key_History 0x010000bf 3447 3448 Qt.Key_AddFavorite 0x010000c0 3449 3450 Qt.Key_HotLinks 0x010000c1 3451 3452 Qt.Key_BrightnessAdjust 0x010000c2 3453 3454 Qt.Key_Finance 0x010000c3 3455 3456 Qt.Key_Community 0x010000c4 3457 3458 Qt.Key_AudioRewind 0x010000c5 3459 3460 Qt.Key_BackForward 0x010000c6 3461 3462 Qt.Key_ApplicationLeft 0x010000c7 3463 3464 Qt.Key_ApplicationRight 0x010000c8 3465 3466 Qt.Key_Book 0x010000c9 3467 3468 Qt.Key_CD 0x010000ca 3469 3470 Qt.Key_Calculator 0x010000cb On X11 this key is not mapped for legacy reasons. Use Qt.Key_Launch1 instead. 3471 3472 Qt.Key_ToDoList 0x010000cc 3473 3474 Qt.Key_ClearGrab 0x010000cd 3475 3476 Qt.Key_Close 0x010000ce 3477 3478 Qt.Key_Copy 0x010000cf 3479 3480 Qt.Key_Cut 0x010000d0 3481 3482 Qt.Key_Display 0x010000d1 3483 3484 Qt.Key_DOS 0x010000d2 3485 3486 Qt.Key_Documents 0x010000d3 3487 3488 Qt.Key_Excel 0x010000d4 3489 3490 Qt.Key_Explorer 0x010000d5 3491 3492 Qt.Key_Game 0x010000d6 3493 3494 Qt.Key_Go 0x010000d7 3495 3496 Qt.Key_iTouch 0x010000d8 3497 3498 Qt.Key_LogOff 0x010000d9 3499 3500 Qt.Key_Market 0x010000da 3501 3502 Qt.Key_Meeting 0x010000db 3503 3504 Qt.Key_MenuKB 0x010000dc 3505 3506 Qt.Key_MenuPB 0x010000dd 3507 3508 Qt.Key_MySites 0x010000de 3509 3510 Qt.Key_News 0x010000df 3511 3512 Qt.Key_OfficeHome 0x010000e0 3513 3514 Qt.Key_Option 0x010000e1 3515 3516 Qt.Key_Paste 0x010000e2 3517 3518 Qt.Key_Phone 0x010000e3 3519 3520 Qt.Key_Calendar 0x010000e4 3521 3522 Qt.Key_Reply 0x010000e5 3523 3524 Qt.Key_Reload 0x010000e6 3525 3526 Qt.Key_RotateWindows 0x010000e7 3527 3528 Qt.Key_RotationPB 0x010000e8 3529 3530 Qt.Key_RotationKB 0x010000e9 3531 3532 Qt.Key_Save 0x010000ea 3533 3534 Qt.Key_Send 0x010000eb 3535 3536 Qt.Key_Spell 0x010000ec 3537 3538 Qt.Key_SplitScreen 0x010000ed 3539 3540 Qt.Key_Support 0x010000ee 3541 3542 Qt.Key_TaskPane 0x010000ef 3543 3544 Qt.Key_Terminal 0x010000f0 3545 3546 Qt.Key_Tools 0x010000f1 3547 3548 Qt.Key_Travel 0x010000f2 3549 3550 Qt.Key_Video 0x010000f3 3551 3552 Qt.Key_Word 0x010000f4 3553 3554 Qt.Key_Xfer 0x010000f5 3555 3556 Qt.Key_ZoomIn 0x010000f6 3557 3558 Qt.Key_ZoomOut 0x010000f7 3559 3560 Qt.Key_Away 0x010000f8 3561 3562 Qt.Key_Messenger 0x010000f9 3563 3564 Qt.Key_WebCam 0x010000fa 3565 3566 Qt.Key_MailForward 0x010000fb 3567 3568 Qt.Key_Pictures 0x010000fc 3569 3570 Qt.Key_Music 0x010000fd 3571 3572 Qt.Key_Battery 0x010000fe 3573 3574 Qt.Key_Bluetooth 0x010000ff 3575 3576 Qt.Key_WLAN 0x01000100 3577 3578 Qt.Key_UWB 0x01000101 3579 3580 Qt.Key_AudioForward 0x01000102 3581 3582 Qt.Key_AudioRepeat 0x01000103 3583 3584 Qt.Key_AudioRandomPlay 0x01000104 3585 3586 Qt.Key_Subtitle 0x01000105 3587 3588 Qt.Key_AudioCycleTrack 0x01000106 3589 3590 Qt.Key_Time 0x01000107 3591 3592 Qt.Key_Hibernate 0x01000108 3593 3594 Qt.Key_View 0x01000109 3595 3596 Qt.Key_TopMenu 0x0100010a 3597 3598 Qt.Key_PowerDown 0x0100010b 3599 3600 Qt.Key_Suspend 0x0100010c 3601 3602 Qt.Key_ContrastAdjust 0x0100010d 3603 3604 Qt.Key_MediaLast 0x0100ffff 3605 3606 Qt.Key_unknown 0x01ffffff 3607 3608 Qt.Key_Call 0x01100004 A key to answer or initiate a call (see Qt.Key_ToggleCallHangup for a key to toggle current call state) 3609 3610 Qt.Key_Camera 0x01100020 A key to activate the camera shutter 3611 3612 Qt.Key_CameraFocus 0x01100021 A key to focus the camera 3613 3614 Qt.Key_Context1 0x01100000 3615 3616 Qt.Key_Context2 0x01100001 3617 3618 Qt.Key_Context3 0x01100002 3619 3620 Qt.Key_Context4 0x01100003 3621 3622 Qt.Key_Flip 0x01100006 3623 3624 Qt.Key_Hangup 0x01100005 A key to end an ongoing call (see Qt.Key_ToggleCallHangup for a key to toggle current call state) 3625 3626 Qt.Key_No 0x01010002 3627 3628 Qt.Key_Select 0x01010000 3629 3630 Qt.Key_Yes 0x01010001 3631 3632 Qt.Key_ToggleCallHangup 0x01100007 A key to toggle the current call state (ie. either answer, or hangup) depending on current call state 3633 3634 Qt.Key_VoiceDial 0x01100008 3635 3636 Qt.Key_LastNumberRedial 0x01100009 3637 3638 Qt.Key_Execute 0x01020003 3639 3640 Qt.Key_Printer 0x01020002 3641 3642 Qt.Key_Play 0x01020005 3643 3644 Qt.Key_Sleep 0x01020004 3645 3646 Qt.Key_Zoom 0x01020006 3647 3648 Qt.Key_Cancel 0x01020001 3649 ''' 3650