[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2868] trunk/py/scripts/addons/ space_view3d_screencast_keys.py: pep8 compliancy
Bart Crouch
bartius.crouch at gmail.com
Thu Jan 5 16:24:23 CET 2012
Revision: 2868
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2868
Author: crouch
Date: 2012-01-05 15:24:18 +0000 (Thu, 05 Jan 2012)
Log Message:
-----------
pep8 compliancy
general code cleaning
reset multiplier after text has disappeared
support for mousewheel in icon-display
improved fading, using a timer
Modified Paths:
--------------
trunk/py/scripts/addons/space_view3d_screencast_keys.py
Modified: trunk/py/scripts/addons/space_view3d_screencast_keys.py
===================================================================
--- trunk/py/scripts/addons/space_view3d_screencast_keys.py 2012-01-05 15:08:32 UTC (rev 2867)
+++ trunk/py/scripts/addons/space_view3d_screencast_keys.py 2012-01-05 15:24:18 UTC (rev 2868)
@@ -16,12 +16,14 @@
#
# ##### END GPL LICENSE BLOCK #####
+# <pep8 compliant>
+
bl_info = {
'name': 'Screencast Keys',
- 'author': 'Paulo Gomes, Bart Crouch, John E. Herrenyo',
- 'version': (1, 4),
- 'blender': (2, 5, 9),
- 'api': 39933,
+ 'author': 'Paulo Gomes, Bart Crouch, John E. Herrenyo, Gaia Clary',
+ 'version': (1, 5),
+ 'blender': (2, 6, 1),
+ 'api': 43073,
'location': 'View3D > Properties panel > Screencast Keys',
'warning': '',
'description': 'Display keys pressed in the 3d-view, '\
@@ -33,53 +35,47 @@
'category': '3D View'}
-# #####
-#
-# Modification history:
-# - Version 1,4
-# - 07-sep-2011 (Gaia Clary):
-# - settings now stored in blend file
-# - grouping mouse&text
-# - mouse_size and font_size separated
-# - boundingBox for improved readability.
-# - missing mouse "release" clicks added
-#
-# ####
-
-
import bgl
import blf
import bpy
import time
+
MOUSE_RATIO = 0.535
+
def getDisplayLocation(context):
- sc = context.scene
- mouse_size = sc.screencast_keys_mouse_size
- pos_x = int( (context.region.width - mouse_size*MOUSE_RATIO) * sc.screencast_keys_pos_x / 100)
- pos_y = int( (context.region.height - mouse_size) * sc.screencast_keys_pos_y / 100)
- return pos_x, pos_y
+ scene = context.scene
+ mouse_size = scene.screencast_keys_mouse_size
+ pos_x = int( (context.region.width - mouse_size * MOUSE_RATIO) * \
+ scene.screencast_keys_pos_x / 100)
+ pos_y = int( (context.region.height - mouse_size) *
+ scene.screencast_keys_pos_y / 100)
+
+ return(pos_x, pos_y)
+
+
def getBoundingBox(current_width, current_height, new_text):
w,h = blf.dimensions(0,new_text)
if w > current_width:
current_width = w
current_height += h
- return current_width, current_height
+ return(current_width, current_height)
+
+
def draw_callback_px(self, context):
wm = context.window_manager
sc = context.scene
if not wm.screencast_keys_keys:
return
-
+
font_size = sc.screencast_keys_font_size
mouse_size = sc.screencast_keys_mouse_size
link = sc.screencast_keys_link
pos_x, pos_y = getDisplayLocation(context)
-
# draw text in the 3d-view
# ========================
blf.size(0, sc.screencast_keys_font_size, 72)
@@ -107,17 +103,17 @@
alpha = min(1.0, max(0.0, 2 * (2 - label_time)))
bgl.glColor4f(r, g, b, alpha)
blf.draw(0, self.key[i])
- text_width, text_height = getBoundingBox(text_width, text_height, self.key[i])
+ text_width, text_height = getBoundingBox(text_width, text_height,
+ self.key[i])
row_count += 1
- final = i
+ final = i + 1
else:
break
# get rid of status texts that aren't displayed anymore
- self.key = self.key[:final+1]
- self.time = self.time[:final+1]
-
-
+ self.key = self.key[:final]
+ self.time = self.time[:final]
+
# draw graphical representation of the mouse
# ==========================================
if sc.screencast_keys_mouse == 'icon':
@@ -132,51 +128,34 @@
if shape:
alpha = min(1.0, max(0.0, 2 * (2 - click_time)))
draw_mouse(context, shape, "filled", alpha)
- final = i
+ final = i + 1
else:
break
-
# get rid of mouse clicks that aren't displayed anymore
- self.mouse = self.mouse[:final+1]
- self.mouse_time = self.mouse_time[:final+1]
+ self.mouse = self.mouse[:final]
+ self.mouse_time = self.mouse_time[:final]
-
# Draw border (if enabled)
# ========================
- if link == True and row_count > 0:
- bgl.glEnable(bgl.GL_BLEND)
- bgl.glBegin(bgl.GL_QUADS)
- bgl.glLineWidth(2)
- bgl.glColor4f(r, g, b, 0.2)
- drawRectangle(pos_x , pos_y , text_width+mouse_size*MOUSE_RATIO*1.3 , max(mouse_size, font_size*row_count), 4 )
- bgl.glEnd()
- bgl.glBegin(bgl.GL_LINES)
- bgl.glColor4f(r, g, b, alpha )
- drawRectangle(pos_x , pos_y , text_width+mouse_size*MOUSE_RATIO*1.3 , max(mouse_size, font_size*row_count), 4 )
- bgl.glEnd()
+ if link and row_count > 0:
+ padding = 8
+ x0 = max(0, pos_x - padding)
+ y0 = max(0, pos_y - padding)
+ x1 = pos_x + text_width + mouse_size * MOUSE_RATIO * 1.3 + padding
+ y1 = pos_y + max(mouse_size, font_size * row_count) + padding
+ positions = [[x0, y0], [x0, y1], [x1, y1], [x1, y0]]
+ settings = [[bgl.GL_QUADS, min(0.2, alpha)], [bgl.GL_LINE_LOOP, alpha]]
+ for mode, box_alpha in settings:
+ bgl.glEnable(bgl.GL_BLEND)
+ bgl.glBegin(mode)
+ bgl.glColor4f(r, g, b, box_alpha)
+ for v1, v2 in positions:
+ bgl.glVertex2f(v1, v2)
+ bgl.glEnd()
-# Draw a line. currently not used.
-def drawLinef(from_x, from_y, to_x, to_y):
- bgl.glVertex2f(from_x, from_y)
- bgl.glVertex2f(to_x, to_y)
-
-# Draw a rectangle. Currently not used
-def drawRectangle (ox, oy, ow, oh, padding=0):
-
- x = ox - 2*padding
- y = oy - padding
- w = ow + 4 * padding
- h = oh + 2 * padding
-
- drawLinef(x, y, x+w, y)
- drawLinef(x+w, y, x+w, y+h)
- drawLinef(x+w, y+h, x , y+h)
- drawLinef(x , y+h, x , y)
-
-
def draw_mouse(context, shape, style, alpha):
# shape and position
sc = context.scene
@@ -185,7 +164,7 @@
link = sc.screencast_keys_link
pos_x, pos_y = getDisplayLocation(context)
- if link==True:
+ if link:
offset_x = pos_x
else:
offset_x = context.region.width - pos_x - (mouse_size * MOUSE_RATIO)
@@ -193,7 +172,7 @@
offset_y = pos_y
if font_size > mouse_size:
offset_y += (font_size - mouse_size) / 2
-
+
shape_data = get_shape_data(shape)
bgl.glTranslatef(offset_x, offset_y, 0)
@@ -201,15 +180,14 @@
# color
r, g, b = sc.screencast_keys_color
bgl.glEnable(bgl.GL_BLEND)
- #bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
- #bgl.glColor4f(r, g, b, alpha)
-
+ bgl.glColor4f(r, g, b, alpha)
+
# inner shape for filled style
if style == "filled":
inner_shape = []
for i in shape_data:
inner_shape.append(i[0])
-
+
# outer shape
for i in shape_data:
shape_segment = i
@@ -217,16 +195,14 @@
shape_segment[1] = [mouse_size * k for k in shape_segment[1]]
shape_segment[2] = [mouse_size * k for k in shape_segment[2]]
shape_segment[3] = [mouse_size * k for k in shape_segment[3]]
-
+
# create the buffer
shape_buffer = bgl.Buffer(bgl.GL_FLOAT, [4, 3], shape_segment)
-
+
# create the map and draw the triangle fan
bgl.glMap1f(bgl.GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, shape_buffer)
bgl.glEnable(bgl.GL_MAP1_VERTEX_3)
- bgl.glColor4f(r, g, b, alpha)
-
if style == "outline":
bgl.glBegin(bgl.GL_LINE_STRIP)
else: # style == "filled"
@@ -234,22 +210,21 @@
for j in range(10):
bgl.glEvalCoord1f(j / 10.0)
x, y, z = shape_segment[3]
-
+
# make sure the last vertex is indeed the last one, to avoid gaps
bgl.glVertex3f(x, y, z)
bgl.glEnd()
bgl.glDisable(bgl.GL_MAP1_VERTEX_3)
-
+
# draw interior
if style == "filled":
- bgl.glColor4f(r, g, b, alpha)
bgl.glBegin(bgl.GL_TRIANGLE_FAN)
for i in inner_shape:
j = [mouse_size * k for k in i]
x, y, z = j
bgl.glVertex3f(x, y, z)
bgl.glEnd()
-
+
bgl.glTranslatef(-offset_x, -offset_y, 0)
@@ -339,6 +314,44 @@
[0.303, 0.833, 0.0],
[0.302, 0.817, 0.0],
[0.301, 0.8, 0.0]]]
+ elif shape == "middle_down_button":
+ data = [[[0.301, 0.8, 0.0],
+ [0.298, 0.768, 0.0],
+ [0.231, 0.768, 0.0],
+ [0.228, 0.8, 0.0]],
+ [[0.228, 0.8, 0.0],
+ [0.226, 0.817, 0.0],
+ [0.225, 0.833, 0.0],
+ [0.224, 0.85, 0.0]],
+ [[0.224, 0.85, 0.0],
+ [0.264, 0.873, 0.0],
+ [0.284, 0.873, 0.0],
+ [0.305, 0.85, 0.0]],
+ [[0.305, 0.85, 0.0],
+ [0.303, 0.833, 0.0],
+ [0.302, 0.817, 0.0],
+ [0.301, 0.8, 0.0]]]
+ elif shape == "middle_up_button":
+ data = [[[0.270, 0.873, 0.0],
+ [0.264, 0.873, 0.0],
+ [0.222, 0.877, 0.0],
+ [0.224, 0.9, 0.0]],
+ [[0.224, 0.9, 0.0],
+ [0.225, 0.917, 0.0],
+ [0.226, 0.933, 0.0],
+ [0.228, 0.95, 0.0]],
+ [[0.228, 0.95, 0.0],
+ [0.231, 0.982, 0.0],
+ [0.298, 0.982, 0.0],
+ [0.301, 0.95, 0.0]],
+ [[0.301, 0.95, 0.0],
+ [0.302, 0.933, 0.0],
+ [0.303, 0.917, 0.0],
+ [0.305, 0.9, 0.0]],
+ [[0.305, 0.9, 0.0],
+ [0.307, 0.877, 0.0],
+ [0.284, 0.873, 0.0],
+ [0.270, 0.873, 0.0]]]
elif shape == "right_button":
data = [[[0.375, 0.763, 0.0],
[0.402, 0.755, 0.0],
@@ -364,20 +377,25 @@
[0.334, 0.77, 0.0],
[0.348, 0.771, 0.0],
[0.375, 0.763, 0.0]]]
-
+
return(data)
# return the shape that belongs to the given event
def map_mouse_event(event):
shape = False
-
+
if event == 'LEFTMOUSE':
shape = "left_button"
elif event == 'MIDDLEMOUSE':
shape = "middle_button"
elif event == 'RIGHTMOUSE':
shape = "right_button"
+ elif event == 'WHEELDOWNMOUSE':
+ shape = "middle_down_button"
+ elif event == 'WHEELUPMOUSE':
+ shape = "middle_up_button"
+
return(shape)
@@ -387,34 +405,38 @@
bl_description = "Display keys pressed in the 3D-view"
last_activity = 'NONE'
+ _handle = None
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list