--- /dev/null
+# -*- coding: utf-8 -*-
+"""
+Curseurs winwii
+
+$Id$
+$URL$
+"""
+
+import pygame
+import os
+
+
+class WarpingCursor(pygame.sprite.Sprite):
+ '''
+ The class for animating the warping cursor
+
+ durations:
+ The duration of each image in the animation
+ centerPosition:
+ The Position of the center of the cursor
+ _imagePointer:
+ A pointer to the current image
+ _animationOffset:
+ The time elapsed since when the current image should have been displayed
+ '''
+ #screen = None
+ #images = None
+ #durations = None
+ #centerPosition = None
+ #_imagePointer = None
+ #_animationOffset = None
+
+ @staticmethod
+ def _get_theme_images(name) :
+ basePath = os.path.abspath(__file__).split(os.path.sep)[:-1]
+ basePath.append('data')
+ basePath.append(name)
+ basePath = os.path.sep.join(basePath)
+ images = [f for f in os.listdir(basePath) if os.path.splitext(f)[1] == '.png']
+ return basePath, images
+
+
+ def __init__(self, theme='black', duration=75):
+ pygame.sprite.Sprite.__init__(self)
+ imagesPath, images = WarpingCursor._get_theme_images(theme)
+ flashImage = images.pop(images.index('flash.png'))
+ images.sort(lambda a, b : cmp(*[int(os.path.splitext(f)[0]) for f in [a, b]]))
+
+ self.images = []
+ for img in images :
+ imagePath = os.path.sep.join([imagesPath, img])
+ self.images = pygame.image.load(imagePath).convert_alpha()
+
+ #self.flashImagePath = flashImage
+ #self.durations = durations
+ #self.centerPosition = initCenterPosition
+ #self.flashLength = 100
+ #self.flashing = False
+ #self.image = pygame.image.load(self.images[0]).convert_alpha()
+ #self._imagePointer = 0
+ #self._animationOffset = 0
+ #self._flashTimer = 0
+
+ def update(self, elapsedTime, centerPosition):
+ '''
+ Update the cursor's look and position
+
+ elapsedTime:
+ The time passed since the previous update
+ centerPosition:
+ the new position of the creep
+ '''
+ self._updateImage(elapsedTime)
+ self.centerPosition = centerPosition
+ if self.flashing :
+ self._flashTimer += elapsedTime
+ if self._flashTimer > self.flashLength:
+ self.flashing = False
+
+ def _updateImage(self, elapsedTime):
+ '''
+ Update the cursor's image
+
+ elapsedTime:
+ The time passed since the previous update
+ '''
+ self._animationOffset += elapsedTime
+
+ if self._animationOffset > self.durations[self._imagePointer]:
+ #New animation offset is computed first, before updating the pointer
+ self._animationOffset -= self.durations[self._imagePointer]
+ #point to the next image (restarts from the beginning when it reaches the end)
+ self._imagePointer = (self._imagePointer + 1) % len(self.images)
+
+ if self.flashing:
+ self.image = pygame.image.load(self.flashImagePath).convert_alpha()
+ else :
+ self.image = pygame.image.load(self.images[self._imagePointer]).convert_alpha()
+
+ def flash(self,flashLength = None):
+ self._flashTimer = 0
+ self.flashing = True
+ if flashLength:
+ self.flashlength = flashLength
+
+ def blit(self,surface):
+ '''
+ Draw the circle on surface
+ '''
+
+ newPos = (self.centerPosition[0] - self.image.get_width() / 2, self.centerPosition[1] - self.image.get_height() / 2)
+ surface.blit(self.image, newPos)
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="48px"
+ height="48px"
+ id="svg2397"
+ sodipodi:version="0.32"
+ inkscape:version="0.46"
+ sodipodi:docname="cursor.svg"
+ inkscape:output_extension="org.inkscape.output.svg.inkscape"
+ inkscape:export-filename="/home/sbenven/Desktop/cursorGifs/cursor00.png"
+ inkscape:export-xdpi="90"
+ inkscape:export-ydpi="90">
+ <defs
+ id="defs2399">
+ <inkscape:perspective
+ sodipodi:type="inkscape:persp3d"
+ inkscape:vp_x="0 : 24 : 1"
+ inkscape:vp_y="0 : 1000 : 0"
+ inkscape:vp_z="48 : 24 : 1"
+ inkscape:persp3d-origin="24 : 16 : 1"
+ id="perspective2405" />
+ </defs>
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="7"
+ inkscape:cx="-1.2857143"
+ inkscape:cy="24.45"
+ inkscape:current-layer="layer1"
+ showgrid="true"
+ inkscape:grid-bbox="true"
+ inkscape:document-units="px"
+ inkscape:window-width="1920"
+ inkscape:window-height="1125"
+ inkscape:window-x="1680"
+ inkscape:window-y="25"
+ showguides="true"
+ inkscape:guide-bbox="true">
+ <sodipodi:guide
+ orientation="0,1"
+ position="-4.4285714,24"
+ id="guide3229" />
+ <sodipodi:guide
+ orientation="1,0"
+ position="24,-18.571429"
+ id="guide3231" />
+ </sodipodi:namedview>
+ <metadata
+ id="metadata2402">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ id="layer1"
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer">
+ <path
+ sodipodi:type="arc"
+ style="fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ id="path2413"
+ sodipodi:cx="37.57143"
+ sodipodi:cy="36.57143"
+ sodipodi:rx="21.571428"
+ sodipodi:ry="21.571428"
+ d="M 59.142859,36.57143 A 21.571428,21.571428 0 1 1 16.000002,36.57143 A 21.571428,21.571428 0 1 1 59.142859,36.57143 z"
+ transform="matrix(1.0873786,0,0,1.0873787,-16.782941,-15.838419)" />
+ <path
+ sodipodi:type="arc"
+ style="fill:#ffffff;fill-opacity:0;stroke:#000000;stroke-width:3;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="path3227"
+ sodipodi:cx="10.928572"
+ sodipodi:cy="13.928572"
+ sodipodi:rx="13.785714"
+ sodipodi:ry="13.785714"
+ d="M 24.714286,13.928572 A 13.785714,13.785714 0 1 1 -2.8571424,13.928572 A 13.785714,13.785714 0 1 1 24.714286,13.928572 z"
+ transform="matrix(1.5759606,0,0,1.567424,6.8484288,2.1217689)"
+ inkscape:export-filename="/home/sbenven/Desktop/cursorGifs/cursor100.png"
+ inkscape:export-xdpi="90"
+ inkscape:export-ydpi="90" />
+ </g>
+</svg>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="48px"
+ height="48px"
+ id="svg2397"
+ sodipodi:version="0.32"
+ inkscape:version="0.46"
+ sodipodi:docname="cursorBlue.svg"
+ inkscape:output_extension="org.inkscape.output.svg.inkscape"
+ inkscape:export-filename="/home/sbenven/Desktop/cursorGifs/cursor00.png"
+ inkscape:export-xdpi="90"
+ inkscape:export-ydpi="90">
+ <defs
+ id="defs2399">
+ <inkscape:perspective
+ sodipodi:type="inkscape:persp3d"
+ inkscape:vp_x="0 : 24 : 1"
+ inkscape:vp_y="0 : 1000 : 0"
+ inkscape:vp_z="48 : 24 : 1"
+ inkscape:persp3d-origin="24 : 16 : 1"
+ id="perspective2405" />
+ </defs>
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="7"
+ inkscape:cx="-31.071429"
+ inkscape:cy="24.45"
+ inkscape:current-layer="layer1"
+ showgrid="true"
+ inkscape:grid-bbox="true"
+ inkscape:document-units="px"
+ inkscape:window-width="1920"
+ inkscape:window-height="1125"
+ inkscape:window-x="1680"
+ inkscape:window-y="25"
+ showguides="true"
+ inkscape:guide-bbox="true">
+ <sodipodi:guide
+ orientation="0,1"
+ position="-4.4285714,24"
+ id="guide3229" />
+ <sodipodi:guide
+ orientation="1,0"
+ position="24,-18.571429"
+ id="guide3231" />
+ </sodipodi:namedview>
+ <metadata
+ id="metadata2402">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ id="layer1"
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer">
+ <path
+ sodipodi:type="arc"
+ style="fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:#0000ff;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ id="path2413"
+ sodipodi:cx="37.57143"
+ sodipodi:cy="36.57143"
+ sodipodi:rx="21.571428"
+ sodipodi:ry="21.571428"
+ d="M 59.142859,36.57143 A 21.571428,21.571428 0 1 1 16.000002,36.57143 A 21.571428,21.571428 0 1 1 59.142859,36.57143 z"
+ transform="matrix(1.0873786,0,0,1.0873787,-16.782941,-15.838419)" />
+ <path
+ sodipodi:type="arc"
+ style="fill:#ffffff;fill-opacity:0;stroke:#0000ff;stroke-width:3;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="path3227"
+ sodipodi:cx="10.928572"
+ sodipodi:cy="13.928572"
+ sodipodi:rx="13.785714"
+ sodipodi:ry="13.785714"
+ d="M 24.714286,13.928572 A 13.785714,13.785714 0 1 1 -2.8571424,13.928572 A 13.785714,13.785714 0 1 1 24.714286,13.928572 z"
+ transform="matrix(1.5759606,0,0,1.567424,6.8484293,2.1217687)"
+ inkscape:export-filename="/home/sbenven/Desktop/cursorGifs/cursor100.png"
+ inkscape:export-xdpi="90"
+ inkscape:export-ydpi="90" />
+ </g>
+</svg>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="48px"
+ height="48px"
+ id="svg2397"
+ sodipodi:version="0.32"
+ inkscape:version="0.46"
+ sodipodi:docname="cursorGreen.svg"
+ inkscape:output_extension="org.inkscape.output.svg.inkscape"
+ inkscape:export-filename="/home/sbenven/Desktop/cursorGifs/cursor00.png"
+ inkscape:export-xdpi="90"
+ inkscape:export-ydpi="90">
+ <defs
+ id="defs2399">
+ <inkscape:perspective
+ sodipodi:type="inkscape:persp3d"
+ inkscape:vp_x="0 : 24 : 1"
+ inkscape:vp_y="0 : 1000 : 0"
+ inkscape:vp_z="48 : 24 : 1"
+ inkscape:persp3d-origin="24 : 16 : 1"
+ id="perspective2405" />
+ </defs>
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="7"
+ inkscape:cx="-31.071429"
+ inkscape:cy="24.45"
+ inkscape:current-layer="layer1"
+ showgrid="true"
+ inkscape:grid-bbox="true"
+ inkscape:document-units="px"
+ inkscape:window-width="1920"
+ inkscape:window-height="1125"
+ inkscape:window-x="1680"
+ inkscape:window-y="25"
+ showguides="true"
+ inkscape:guide-bbox="true">
+ <sodipodi:guide
+ orientation="0,1"
+ position="-4.4285714,24"
+ id="guide3229" />
+ <sodipodi:guide
+ orientation="1,0"
+ position="24,-18.571429"
+ id="guide3231" />
+ </sodipodi:namedview>
+ <metadata
+ id="metadata2402">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ id="layer1"
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer">
+ <path
+ sodipodi:type="arc"
+ style="fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:#00ff00;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ id="path2413"
+ sodipodi:cx="37.57143"
+ sodipodi:cy="36.57143"
+ sodipodi:rx="21.571428"
+ sodipodi:ry="21.571428"
+ d="M 59.142859,36.57143 A 21.571428,21.571428 0 1 1 16.000002,36.57143 A 21.571428,21.571428 0 1 1 59.142859,36.57143 z"
+ transform="matrix(1.0873786,0,0,1.0873787,-16.782941,-15.838419)" />
+ <path
+ sodipodi:type="arc"
+ style="fill:#ffffff;fill-opacity:0;stroke:#00ff00;stroke-width:3;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="path3227"
+ sodipodi:cx="10.928572"
+ sodipodi:cy="13.928572"
+ sodipodi:rx="13.785714"
+ sodipodi:ry="13.785714"
+ d="M 24.714286,13.928572 A 13.785714,13.785714 0 1 1 -2.8571424,13.928572 A 13.785714,13.785714 0 1 1 24.714286,13.928572 z"
+ transform="matrix(1.5759606,0,0,1.567424,6.8484285,2.1680224)"
+ inkscape:export-filename="/home/sbenven/Desktop/cursorGifs/cursor100.png"
+ inkscape:export-xdpi="90"
+ inkscape:export-ydpi="90" />
+ </g>
+</svg>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="48px"
+ height="48px"
+ id="svg2397"
+ sodipodi:version="0.32"
+ inkscape:version="0.46"
+ sodipodi:docname="cursorRed.svg"
+ inkscape:output_extension="org.inkscape.output.svg.inkscape"
+ inkscape:export-filename="/home/sbenven/Desktop/cursorGifs/cursor00.png"
+ inkscape:export-xdpi="90"
+ inkscape:export-ydpi="90">
+ <defs
+ id="defs2399">
+ <inkscape:perspective
+ sodipodi:type="inkscape:persp3d"
+ inkscape:vp_x="0 : 24 : 1"
+ inkscape:vp_y="0 : 1000 : 0"
+ inkscape:vp_z="48 : 24 : 1"
+ inkscape:persp3d-origin="24 : 16 : 1"
+ id="perspective2405" />
+ </defs>
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="7"
+ inkscape:cx="-31.071429"
+ inkscape:cy="22.307143"
+ inkscape:current-layer="layer1"
+ showgrid="true"
+ inkscape:grid-bbox="true"
+ inkscape:document-units="px"
+ inkscape:window-width="1920"
+ inkscape:window-height="1125"
+ inkscape:window-x="1680"
+ inkscape:window-y="25"
+ showguides="true"
+ inkscape:guide-bbox="true">
+ <sodipodi:guide
+ orientation="0,1"
+ position="-4.4285714,24"
+ id="guide3229" />
+ <sodipodi:guide
+ orientation="1,0"
+ position="24,-18.571429"
+ id="guide3231" />
+ </sodipodi:namedview>
+ <metadata
+ id="metadata2402">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ id="layer1"
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer">
+ <path
+ sodipodi:type="arc"
+ style="fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ id="path2413"
+ sodipodi:cx="37.57143"
+ sodipodi:cy="36.57143"
+ sodipodi:rx="21.571428"
+ sodipodi:ry="21.571428"
+ d="M 59.142859,36.57143 A 21.571428,21.571428 0 1 1 16.000002,36.57143 A 21.571428,21.571428 0 1 1 59.142859,36.57143 z"
+ transform="matrix(1.0873786,0,0,1.0873787,-16.782941,-15.838419)" />
+ <path
+ sodipodi:type="arc"
+ style="fill:#ffffff;fill-opacity:0;stroke:#ff0000;stroke-width:3;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="path3227"
+ sodipodi:cx="10.928572"
+ sodipodi:cy="13.928572"
+ sodipodi:rx="13.785714"
+ sodipodi:ry="13.785714"
+ d="M 24.714286,13.928572 A 13.785714,13.785714 0 1 1 -2.8571424,13.928572 A 13.785714,13.785714 0 1 1 24.714286,13.928572 z"
+ transform="matrix(1.5759606,0,0,1.567424,6.9912861,2.264626)"
+ inkscape:export-filename="/home/sbenven/Desktop/cursorGifs/cursor100.png"
+ inkscape:export-xdpi="90"
+ inkscape:export-ydpi="90" />
+ </g>
+</svg>
ON_COLUMN_OVERSIZING = 1.5
-def rename_method(newName) :
+def event_handler(eventType) :
def doRename(m) :
- m.__name__ = newName
+ m.__name__ = 'eventHandler%s' % eventType
return m
return doRename
handler = getattr(self, 'eventHandler%s' % event.type, lambda e:None)
handler(event)
- @rename_method('eventHandler%s' % pygame.KEYDOWN)
+ @event_handler(pygame.KEYDOWN)
def handleKeyDown(self, event) :
if event.key == pygame.K_q:
self._running = False
if uni.isdigit() and int(uni) <=8 :
self.highlightColumn(int(uni))
+
+ @event_handler(pygame.MOUSEMOTION)
+ def handleMouseMotion(self, event) :