Module gpanel :: Class GPanel
[frames] | no frames]

Class GPanel

source code

       object --+                
                |                
sip.simplewrapper --+            
                    |            
          sip.wrapper --+        
                        |        
     PyQt4.QtCore.QObject --+    
                            |    
           object --+       |    
                    |       |    
    sip.simplewrapper --+   |    
                        |   |    
 PyQt4.QtGui.QPaintDevice --+    
                            |    
          PyQt4.QtGui.QWidget --+
                                |
                               GPanel


Class to create a graphics window of default size 501x501 pixels (client drawing area)
using a coordinate system with x-axis from left to right, y-axis from bottom to top
(called user coordinates, default range 0..1, 0..1).

The drawing methods perform drawing operation in an offscreen buffer (QPixmap)
and automatically renders it on the screen, so the graphics is shown step-by-step.


The drawing methods perform drawing operation in an offscreen buffer (pixmap)
and automatically renders it on the screen, so the graphics is shown step-by-step.

Pixel coordinate range: 0..winWidth, 0..winHeight (0,0) upper left corner, x to the right, y downwards
User coordinate range: xmin..xmax, ymin..ymax (0,0) lower left corner, x to the right, y upwards.

Transformation: user(ux, uy) to pixel(px, py)
px = a * ux + b
py = c * uy + d
with a = winWidth / (xmax - xmin)
b = winWidth * xmin / (xmin - xmax)
c = winHeight / (ymin - ymax)
d = winHeight * ymax / (ymax - ymin)

Inverse:
ux = (px - b) / a
uy = (py - d) / c

WARNING: Because PyQt is not thread-safe, in principle all graphics drawings should be
executed in the GUI thread (for GPanel the main thread or a GUI callback).

Typical program:

from gpanel import *

p = GPanel(0, 10, 0, 10)
for ypt in range(0, 11, 1):
    p.line(0, ypt, 10 - ypt, 0)
    time.sleep(0.1) # to see what happens
p.keep()

keep() is blocking and keeps the graphics panel open until the close button is hit or the
Python process terminates.

Nested Classes

Inherited from PyQt4.QtGui.QWidget: RenderFlag, RenderFlags

Inherited from PyQt4.QtGui.QPaintDevice: PaintDeviceMetric

Instance Methods
 
__init__(self, *args)
Constructs a GPanel and displays a non-resizable graphics window.
source code
 
clear(self)
Clears the graphics window and the offscreen buffer used by the window (fully paint with background color).
source code
 
erase(self)
Same as clear(), but lets the current graph cursor unganged.
source code
 
keep(self)
Blocks until the title bar's close button is hit.
source code
 
setTitle(self, title)
Sets the title in the window title bar.
source code
 
paintEvent(self, e) source code
 
setPenColor(self, *args)
Sets the current pen color.
source code
 
setPenSize(self, size)
Sets the current pen size (width) (>=1).
source code
 
toPixel(self, user)
Returns pixel coordinates (tuple) of given user coordinates (tupel).
source code
 
toPixelX(self, userX)
Returns pixel x-coordinate of given user x-coordinate.
source code
 
toPixelY(self, userY)
Returns pixel y-coordinate of given user y-coordinate.
source code
 
toPixelWidth(self, userWidth)
Returns pixel x-increment of given user x-increment (always positive).
source code
 
toPixelHeight(self, userHeight)
Returns pixel y-increment of given user y-increment (always positive).
source code
 
toUser(self, pixel)
Returns user coordinates (tuple) of given pixel coordinates (tuple).
source code
 
toUserX(self, pixelX)
Returns user x-coordinate of given pixel x-coordinate.
source code
 
toUserY(self, pixelY)
Returns user y-coordinate of given pixel y-coordinate.
source code
 
toUserWidth(self, pixelWidth)
Returns user x-increment of given pixel x-increment (always positive).
source code
 
toUserHeight(self, pixelHeight)
Returns user y-increment of given pixel y-increment (always positive).
source code
 
setUserCoords(self, xmin, xmax, ymin, ymax)
Set user coordinate system left_x, right_x, bottom_y, top_y
source code
 
repaint(self)
Renders the offscreen buffer in the graphics window.
source code
 
enableRepaint(self, enable)
Enables/Disables automatic repaint in graphics drawing methods.
source code
 
line(self, x1, y1, x2, y2)
Draws a line with given user start and end coordinates and sets the graph cursor position to the end point.
source code
 
pos(self, x, y)
Sets the current graph cursor position to given user coordinates.
source code
 
move(self, x, y)
Sets the current graph cursor position to given user coordinates.
source code
 
draw(self, x, y)
Draws a line form current graph cursor position to (x, y).
source code
 
getPos()
Returns a tuple with current graph cursor position (tuple, user coordinates).
source code
 
getPosX(self)
Returns the current graph cursor x-position (user coordinates).
source code
 
getPosY(self)
Returns the current graph cursor y-position (user coordinates).
source code
 
text(self, *args)
Draws a text at given position (user coordinates).
source code
 
addCloseListener(self, closeListener)
Registers the given function that is called when the title bar close button is hit.
source code
 
closeEvent(self, e) source code
 
setBgColor(self, *args)
Sets the background color.
source code
 
circle(self, radius)
Draws a circle with center at the current graph cursor position with given radius in horizontal window coordinates.
source code
 
fillCircle(self, radius)
Draws a filled circle with center at the current graph cursor position with given radius in horizontal window coordinates (fill color = pen color).
source code
 
ellipse(self, a, b)
Draws an ellipse with center at the current graph cursor position with given axes.
source code
 
fillEllipse(self, a, b)
Draws a filled ellipse with center at the current graph cursor position with given axes (fill color = pen color).
source code
 
rectangle(self, *args)
Draws a rectangle.
source code
 
fillRectangle(self, *args)
Draws a filled rectangle (fill color = pen color).
source code
 
polygon(self, corners)
Draws a polygon with given list of vertexes (list of x, y).
source code
 
fillPolygon(self, corners)
Draws a filled polygon with given list of vertexes (list of x, y) (fill color = pen color).
source code
 
arc(self, r, startAngle, spanAngle)
Draws a circle sector with center at the current graph cursor position, given radius and given start and span angles.
source code
 
fillArc(self, r, startAngle, spanAngle)
Draws a filled circle sector with center at the current graph cursor position, given radius and given start and span angles.
source code
 
chord(self, r, startAngle, spanAngle)
Draws a circle chord with center at the current graph cursor position, given radius and given start and span angles (in degrees, positive counter-clockwise, zero to east).
source code
 
fillChord(self, r, startAngle, spanAngle)
Draws a filled circle chord with center at the current graph cursor position, given radius and given start and span angles (in degrees, positive counter-clockwise, zero to east).
source code
 
startPath(self)
Starts recording the path vertexes.
source code
 
fillPath(self, color)
Closes the path started with startPath() and shows a filled polygon from the saved draw() positions with given color.
source code
 
showImage(self, *args)
Draws the picture with given file path or given image at given upper-left coordinates.
source code
 
point(self, *args)
Draws a single point with current pen size and pen color at given user coordinates.
source code
 
getPixelColor(self, *args)
Returns the RGBA color tuple of a pixel with given user coordinates.
source code
 
fill(self, x, y, color)
Fills the closed unicolored region with the inner point (x, y) with the given color (RGB, RGBA or X11 color string).
source code
 
getPainter(self)
Returns the QPainter reference used to draw into the offscreen buffer.
source code
 
drawGrid(self, *args)
Draws a coordinate system with annotated axes.
source code
 
addMousePressListener(self, onMousePressed)
Registers a callback that is invoked when a mouse button is pressed.
source code
 
addMouseReleaseListener(self, onMouseReleased)
Registers a callback that is invoked when a mouse button is releases.
source code
 
addMouseDragListener(self, onMouseDragged)
Registers a callback that is invoked when the mouse is moved while a mouse button is pressed (drag).
source code
 
isLeftMouseButton(self)
Returns True, if the last mouse action was performed with the left mouse button.
source code
 
isRightMouseButton(self)
Returns True, if the last mouse action was performed with the right mouse button.
source code
 
addKeyPressListener(self, onKeyPressed)
Registers a callback that is invoked when a key is pressed (and the graphics window has the focus).
source code
 
addKeyReleaseListener(self, onKeyReleased)
Registers a callback that is invoked when a key is released (and the graphics window has the focus).
source code
 
getScreenWidth(self)
Returns the screen width in pixels.
source code
 
getScreenHeight(self)
Returns the screen height in pixels.
source code
 
setWindowCenter(self)
Sets the screen position to the center of the screen.
source code
 
setWindowPos(self, ulx, uly)
Sets the screen position of the graphics window.
source code
 
saveGraphics(self)
Saves the current graphics into a image buffer.
source code
 
restoreGraphics(self)
Restores the saved graphics from the image buffer.
source code
 
setXORMode(self)
Performs pixel color XOR operation with the existing background pixel.
source code
 
setPaintMode(self)
Resets the drawing mode to standard (overwriting).
source code
 
mousePressEvent(self, e) source code
 
mouseReleaseEvent(self, e) source code
 
mouseMoveEvent(self, e) source code
 
keyPressEvent(self, e) source code
 
keyReleaseEvent(self, e) source code

Inherited from PyQt4.QtGui.QWidget: acceptDrops, accessibleDescription, accessibleName, actionEvent, actions, activateWindow, addAction, addActions, adjustSize, autoFillBackground, backgroundRole, baseSize, changeEvent, childAt, childEvent, childrenRect, childrenRegion, clearFocus, clearMask, close, connectNotify, contentsMargins, contentsRect, contextMenuEvent, contextMenuPolicy, create, cursor, customContextMenuRequested, customEvent, destroy, devType, disconnectNotify, dragEnterEvent, dragLeaveEvent, dragMoveEvent, dropEvent, effectiveWinId, enabledChange, ensurePolished, enterEvent, event, find, focusInEvent, focusNextChild, focusNextPrevChild, focusOutEvent, focusPolicy, focusPreviousChild, focusProxy, focusWidget, font, fontChange, fontInfo, fontMetrics, foregroundRole, frameGeometry, frameSize, geometry, getContentsMargins, grabGesture, grabKeyboard, grabMouse, grabShortcut, graphicsEffect, graphicsProxyWidget, hasFocus, hasMouseTracking, height, heightForWidth, hide, hideEvent, inputContext, inputMethodEvent, inputMethodHints, inputMethodQuery, insertAction, insertActions, isActiveWindow, isAncestorOf, isEnabled, isEnabledTo, isEnabledToTLW, isFullScreen, isHidden, isLeftToRight, isMaximized, isMinimized, isModal, isRightToLeft, isTopLevel, isVisible, isVisibleTo, isWindow, isWindowModified, keyboardGrabber, languageChange, layout, layoutDirection, leaveEvent, locale, lower, mapFrom, mapFromGlobal, mapFromParent, mapTo, mapToGlobal, mapToParent, mask, maximumHeight, maximumSize, maximumWidth, metric, minimumHeight, minimumSize, minimumSizeHint, minimumWidth, mouseDoubleClickEvent, mouseGrabber, moveEvent, nativeParentWidget, nextInFocusChain, normalGeometry, overrideWindowFlags, overrideWindowState, paintEngine, palette, paletteChange, parentWidget, previousInFocusChain, raise_, receivers, rect, releaseKeyboard, releaseMouse, releaseShortcut, removeAction, render, resetInputContext, resize, resizeEvent, restoreGeometry, saveGeometry, scroll, sender, senderSignalIndex, setAcceptDrops, setAccessibleDescription, setAccessibleName, setAttribute, setAutoFillBackground, setBackgroundRole, setBaseSize, setContentsMargins, setContextMenuPolicy, setCursor, setDisabled, setEnabled, setFixedHeight, setFixedSize, setFixedWidth, setFocus, setFocusPolicy, setFocusProxy, setFont, setForegroundRole, setGeometry, setGraphicsEffect, setHidden, setInputContext, setInputMethodHints, setLayout, setLayoutDirection, setLocale, setMask, setMaximumHeight, setMaximumSize, setMaximumWidth, setMinimumHeight, setMinimumSize, setMinimumWidth, setMouseTracking, setPalette, setParent, setShortcutAutoRepeat, setShortcutEnabled, setShown, setSizeIncrement, setSizePolicy, setStatusTip, setStyle, setStyleSheet, setTabOrder, setToolTip, setUpdatesEnabled, setVisible, setWhatsThis, setWindowFilePath, setWindowFlags, setWindowIcon, setWindowIconText, setWindowModality, setWindowModified, setWindowOpacity, setWindowRole, setWindowState, setWindowTitle, show, showEvent, showFullScreen, showMaximized, showMinimized, showNormal, size, sizeHint, sizeIncrement, sizePolicy, stackUnder, statusTip, style, styleSheet, tabletEvent, testAttribute, timerEvent, toolTip, topLevelWidget, underMouse, ungrabGesture, unsetCursor, unsetLayoutDirection, unsetLocale, update, updateGeometry, updateMicroFocus, updatesEnabled, visibleRegion, whatsThis, wheelEvent, width, winEvent, winId, window, windowActivationChange, windowFilePath, windowFlags, windowIcon, windowIconText, windowModality, windowOpacity, windowRole, windowState, windowTitle, windowType, x, y

Inherited from PyQt4.QtCore.QObject: __getattr__, blockSignals, children, connect, deleteLater, destroyed, disconnect, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, emit, eventFilter, findChild, findChildren, inherits, installEventFilter, isWidgetType, killTimer, metaObject, moveToThread, objectName, parent, property, pyqtConfigure, removeEventFilter, setObjectName, setProperty, signalsBlocked, startTimer, thread, tr, trUtf8

Inherited from PyQt4.QtGui.QPaintDevice: colorCount, depth, heightMM, logicalDpiX, logicalDpiY, numColors, paintingActive, physicalDpiX, physicalDpiY, widthMM

Inherited from sip.simplewrapper: __new__

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods
 
getDividingPoint(x1, y1, x2, y2, ratio)
Returns the tuple of user coordinates of the point on the line through the point pt1 = (x1, y1) and the point pt2 = (x2, y2) that is in distance ratio times the length from pt1 to pt2 from pt1.
source code
 
floodFill(pm, pt, oldColor, newColor)
Fills a bounded single-colored region with the given color.
source code
 
getRandomX11Color()
Returns a random X11 color string.
source code
Class Variables

Inherited from PyQt4.QtGui.QWidget: DrawChildren, DrawWindowBackground, IgnoreMask

Inherited from PyQt4.QtCore.QObject: staticMetaObject

Inherited from PyQt4.QtGui.QPaintDevice: PdmDepth, PdmDpiX, PdmDpiY, PdmHeight, PdmHeightMM, PdmNumColors, PdmPhysicalDpiX, PdmPhysicalDpiY, PdmWidth, PdmWidthMM

Properties

Inherited from object: __class__

Method Details

__init__(self, *args)
(Constructor)

source code 

Constructs a GPanel and displays a non-resizable graphics window. Defaults with no parameter: Window size: 500x500 pixels Window title: "GPanel" User coordinates: 0, 1, 0, 1 Background color: white Pen color: black Pen size: 1

1 Parameter: Size(window_width, window_height) 4 Parameters: xmin, xmax, ymin, ymax

Parameters:
  • Size - a Size refererence that defines the width and height of the graphics window.
Overrides: object.__init__

clear(self)

source code 

Clears the graphics window and the offscreen buffer used by the window (fully paint with background color). Sets the current graph cursor position to (0, 0). If enableRepaint(false) only clears the offscreen buffer.

keep(self)

source code 

Blocks until the title bar's close button is hit. Then cleans up the graphics system.

setTitle(self, title)

source code 

Sets the title in the window title bar.

Parameters:
  • title - the title text

paintEvent(self, e)

source code 
Overrides: PyQt4.QtGui.QWidget.paintEvent

setPenColor(self, *args)

source code 

Sets the current pen color. 1 parameter: - string value considered as X11 color string

  • list considered as [r, b, g] or [r, g, b, a]
  • tuple considered as (r, b, g) or (r, g, b, a)

3 parameters: values considered as RGB (alpha = 255) 4 parameters: values considered as RGBA

setPenSize(self, size)

source code 

Sets the current pen size (width) (>=1). Returns the previous pen size.

Parameters:
  • width - the pen width >=1)

setUserCoords(self, xmin, xmax, ymin, ymax)

source code 

Set user coordinate system left_x, right_x, bottom_y, top_y

Parameters:
  • xmin - the x coordinate at left border
  • xmax - the x coordinate at right border
  • ymin - the y coordinate at bottom border
  • ymax - the y coordinate at top border

repaint(self)

source code 

Renders the offscreen buffer in the graphics window.

Overrides: PyQt4.QtGui.QWidget.repaint

enableRepaint(self, enable)

source code 

Enables/Disables automatic repaint in graphics drawing methods.

Parameters:
  • enable - if True, the automatic repaint is enabled; otherwise disabled

line(self, x1, y1, x2, y2)

source code 

Draws a line with given user start and end coordinates and sets the graph cursor position to the end point. Also with 2 parameters of type complex, list or tuple. 4 parameters: x1, y1, x2, y2 2 parameters: pt1, pt2 as complex/list/tuple

pos(self, x, y)

source code 

Sets the current graph cursor position to given user coordinates. (without drawing anything, same as move()).

Parameters:
  • x - the x coordinate of the target point
  • y - the y coordinate of the target point
  • target - (alternative) the target point as complex, list or tuple
Overrides: PyQt4.QtGui.QWidget.pos

move(self, x, y)

source code 

Sets the current graph cursor position to given user coordinates. (without drawing anything, same as pos()).

Parameters:
  • x - the x coordinate of the target point
  • y - the y coordinate of the target point
  • target - (alternative) the target point as complex, list or tuple
Overrides: PyQt4.QtGui.QWidget.move

draw(self, x, y)

source code 

Draws a line form current graph cursor position to (x, y). Sets the graph cursor position to (x, y).

Parameters:
  • x - the x coordinate of the target point
  • y - the y coordinate of the target point
  • target - (alternative) the target point as complex, list or tuple

text(self, *args)

source code 

Draws a text at given position (user coordinates). 1 parameter: at current graph cursor position 2 parameters: target point (comolex/list/tuple), text 3 parameters: x, y, text

addCloseListener(self, closeListener)

source code 

Registers the given function that is called when the title bar close button is hit. If a listener (!= None) is registered, the automatic closing is disabled. To close the window, call sys.exit().

KEEP IN MIND: To use GUI callbacks, the main program must block in the keep() function.

Parameters:
  • closeListener - a callback function called when the close button is hit

closeEvent(self, e)

source code 
Overrides: PyQt4.QtGui.QWidget.closeEvent

setBgColor(self, *args)

source code 

Sets the background color. All drawings are erased and the current graph cursor is set to (0, 0).

1 parameter: value considered as X11 color string 3 parameters: values considered as RGB (alpha = 255) 4 parameters: values considered as RGBA

circle(self, radius)

source code 

Draws a circle with center at the current graph cursor position with given radius in horizontal window coordinates.

Parameters:
  • radius - the radius of the circle

fillCircle(self, radius)

source code 

Draws a filled circle with center at the current graph cursor position with given radius in horizontal window coordinates (fill color = pen color).

Parameters:
  • radius - the radius of the circle

ellipse(self, a, b)

source code 

Draws an ellipse with center at the current graph cursor position with given axes.

Parameters:
  • a - the major ellipse axis
  • b - the minor ellipse axis

fillEllipse(self, a, b)

source code 

Draws a filled ellipse with center at the current graph cursor position with given axes (fill color = pen color).

Parameters:
  • a - the major ellipse axis
  • b - the minor ellipse axis

rectangle(self, *args)

source code 

Draws a rectangle.
2 parameters: Center at the current graph cursor position
              and given width and height.
4 parameters: Given diagonal

fillRectangle(self, *args)

source code 

Draws a filled rectangle (fill color = pen color).
2 parameters: Center at the current graph cursor position
              and given width and height.
4 parameters: Given diagonal

polygon(self, corners)

source code 

Draws a polygon with given list of vertexes (list of x, y).

Parameters:
  • corners - a list /tuple of the corner points (x, y) list/tuple

fillPolygon(self, corners)

source code 

Draws a filled polygon with given list of vertexes (list of x, y) (fill color = pen color).

Parameters:
  • corners - a list /tuple of the corner points (x, y) list/tuple

arc(self, r, startAngle, spanAngle)

source code 

Draws a circle sector with center at the current graph cursor position, given radius and given start and span angles.

Parameters:
  • radius - the radius of the arc
  • startAngle - starting angle in degrees, zero to east, positive counter-clockwise
  • spanAngle - span angle (sector angle) in degrees, positive counter-clockwise

fillArc(self, r, startAngle, spanAngle)

source code 

Draws a filled circle sector with center at the current graph cursor position, given radius and given start and span angles.

Parameters:
  • radius - the radius of the arc
  • startAngle - starting angle in degrees, zero to east, positive counter-clockwise
  • spanAngle - span angle (sector angle) in degrees, positive counter-clockwise

chord(self, r, startAngle, spanAngle)

source code 

Draws a circle chord with center at the current graph cursor position, given radius and given start and span angles (in degrees, positive counter-clockwise, zero to east).

Parameters:
  • radius - the radius of the arc
  • startAngle - starting angle in degrees, zero to east, positive counter-clockwise
  • spanAngle - span angle (sector angle) in degrees, positive counter-clockwise

fillChord(self, r, startAngle, spanAngle)

source code 

Draws a filled circle chord with center at the current graph cursor position, given radius and given start and span angles (in degrees, positive counter-clockwise, zero to east).

Parameters:
  • radius - the radius of the arc
  • startAngle - starting angle in degrees, zero to east, positive counter-clockwise
  • spanAngle - span angle (sector angle) in degrees, positive counter-clockwise

startPath(self)

source code 

Starts recording the path vertexes. The positions of subsequent draw() operations are saved. The path is used to show a filled polygon when fillPath() is called.

showImage(self, *args)

source code 

Draws the picture with given file path or given image at given upper-left coordinates. 1st parameter: image path (string) or QImage reference 2nd, 3rd parameters: llx, lly (lower left corner in user coordinates)

point(self, *args)

source code 

Draws a single point with current pen size and pen color at given user coordinates. No params: draws a current graph cursor position

Parameters:
  • x - the x coordinate of the target point
  • y - the y coordinate of the target point
  • target - (alternative) the target point as complex, list or tuple

getPixelColor(self, *args)

source code 

Returns the RGBA color tuple of a pixel with given user coordinates. No params: Returns color at current graph cursor position.

fill(self, x, y, color)

source code 

Fills the closed unicolored region with the inner point (x, y) with the given color (RGB, RGBA or X11 color string). The old color to replace is the color of the pixel at x, y.

Parameters:
  • x - the x coordinate of the inner point
  • y - the y coordinate of the inner point
  • color - the replacement color (RGB list/tuple or X11 color string)

drawGrid(self, *args)

source code 

Draws a coordinate system with annotated axes. (You must increase the user coordinate system at least 10% in both directions.) drawGrid(x, y): Grid with 10 ticks in range 0..x, 0..y. Label text depends if x, y or int or float drawGrid(x, y, color): same with given grid color drawGrid(x1, x2, y1, y2): same with given span x1..x2, y1..y2 drawGrid(x1, x2, y1, y2, color): same with given grid color drawGrid(x1, x2, y1, y2, x3, y3): same with given number of ticks x3, y3 in x- and y-direction

addMousePressListener(self, onMousePressed)

source code 

Registers a callback that is invoked when a mouse button is pressed. Use isLeftMouseButton() or isRightMouseButton() to check which button used.

KEEP IN MIND: To use GUI callbacks, the main program must block in the keep() function.

Parameters:
  • onMousePressed - a callback function called when a mouse button is pressed

addMouseReleaseListener(self, onMouseReleased)

source code 

Registers a callback that is invoked when a mouse button is releases. Use isLeftMouseButton() or isRightMouseButton() to check which button used.

KEEP IN MIND: To use GUI callbacks, the main program must block in the keep() function.

Parameters:
  • onMouseReleased - a callback function called when a mouse button is released

addMouseDragListener(self, onMouseDragged)

source code 

Registers a callback that is invoked when the mouse is moved while a mouse button is pressed (drag).

KEEP IN MIND: To use GUI callbacks, the main program must block in the keep() function.

Parameters:
  • onMouseDragged - a callback function called when the moused is dragged

addKeyPressListener(self, onKeyPressed)

source code 

Registers a callback that is invoked when a key is pressed (and the graphics window has the focus).

KEEP IN MIND: To use GUI callbacks, the main program must block in the keep() function.

Parameters:
  • onKeyPressed - a callback function called when a key is pressed

addKeyReleaseListener(self, onKeyReleased)

source code 

Registers a callback that is invoked when a key is released (and the graphics window has the focus).

KEEP IN MIND: To use GUI callbacks, the main program must block in the keep() function.

Parameters:
  • onKeyReleased - a callback function called when a key is released

setWindowPos(self, ulx, uly)

source code 

Sets the screen position of the graphics window.

Parameters:
  • ulx - the upper left corner's x-coordinate
  • ulx - the upper left corner's y-coordinate

saveGraphics(self)

source code 

Saves the current graphics into a image buffer. Use restoreGraphics() to restore it.

restoreGraphics(self)

source code 

Restores the saved graphics from the image buffer. Use saveGraphics() to save it.

setXORMode(self)

source code 

Performs pixel color XOR operation with the existing background pixel. Be aware that if the background is white, drawing with a white pen shows a black pixel

mousePressEvent(self, e)

source code 
Overrides: PyQt4.QtGui.QWidget.mousePressEvent

mouseReleaseEvent(self, e)

source code 
Overrides: PyQt4.QtGui.QWidget.mouseReleaseEvent

mouseMoveEvent(self, e)

source code 
Overrides: PyQt4.QtGui.QWidget.mouseMoveEvent

keyPressEvent(self, e)

source code 
Overrides: PyQt4.QtGui.QWidget.keyPressEvent

keyReleaseEvent(self, e)

source code 
Overrides: PyQt4.QtGui.QWidget.keyReleaseEvent

getDividingPoint(x1, y1, x2, y2, ratio)
Static Method

source code 

Returns the tuple of user coordinates of the point on the line through the point pt1 = (x1, y1) and the point pt2 = (x2, y2) that is in distance ratio times the length from pt1 to pt2 from pt1. For ratio < 0 the point is in the opposite direction. 3 parameteters: pt1, pt2 (complex/list/tuple), ratio 5 parameteters: x1, y1, x2, y2, ratio

floodFill(pm, pt, oldColor, newColor)
Static Method

source code 

Fills a bounded single-colored region with the given color. The given point is part of the region and used to specify it. @param pm the pixmap containing the connected region @param pt a point inside the region @param oldColor the old color of the region (RGB list/tuple) @param newColor the new color of the region (RGB list/tuple) @return a new qImage with the transformed region