diff options
author | Sebastian Koslowski <koslowski@kit.edu> | 2015-07-21 16:39:57 +0200 |
---|---|---|
committer | Sebastian Koslowski <koslowski@kit.edu> | 2015-07-21 16:39:57 +0200 |
commit | 7345de003ff2f916f0e6344c12f1ae1fc95fdf54 (patch) | |
tree | 2c840f5dbe8ff3f23b73da7e5f8ed098b504ec7d /grc/gui/Utils.py | |
parent | 5352def55ddde9dbdd34469920056f650f41adf2 (diff) |
grc: clean-up gui/Utils.py
Diffstat (limited to 'grc/gui/Utils.py')
-rw-r--r-- | grc/gui/Utils.py | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/grc/gui/Utils.py b/grc/gui/Utils.py index 9a0a59cda7..44df79f52c 100644 --- a/grc/gui/Utils.py +++ b/grc/gui/Utils.py @@ -1,5 +1,5 @@ """ -Copyright 2008-2011 Free Software Foundation, Inc. +Copyright 2008-2011,2015 Free Software Foundation, Inc. This file is part of GNU Radio GNU Radio Companion is free software; you can redistribute it and/or @@ -17,13 +17,16 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA """ -from Constants import POSSIBLE_ROTATIONS, CANVAS_GRID_SIZE -from Cheetah.Template import Template import pygtk pygtk.require('2.0') import gtk import gobject +from Cheetah.Template import Template + +from Constants import POSSIBLE_ROTATIONS, CANVAS_GRID_SIZE + + def rotate_pixmap(gc, src_pixmap, dst_pixmap, angle=gtk.gdk.PIXBUF_ROTATE_COUNTERCLOCKWISE): """ Load the destination pixmap with a rotated version of the source pixmap. @@ -46,6 +49,7 @@ def rotate_pixmap(gc, src_pixmap, dst_pixmap, angle=gtk.gdk.PIXBUF_ROTATE_COUNTE pixbuf = pixbuf.rotate_simple(angle) dst_pixmap.draw_pixbuf(gc, pixbuf, 0, 0, 0, 0) + def get_rotated_coordinate(coor, rotation): """ Rotate the coordinate by the given rotation. @@ -57,21 +61,19 @@ def get_rotated_coordinate(coor, rotation): Returns: the rotated coordinates """ - #handles negative angles + # handles negative angles rotation = (rotation + 360)%360 if rotation not in POSSIBLE_ROTATIONS: raise ValueError('unusable rotation angle "%s"'%str(rotation)) - #determine the number of degrees to rotate + # determine the number of degrees to rotate cos_r, sin_r = { - 0: (1, 0), - 90: (0, 1), - 180: (-1, 0), - 270: (0, -1), + 0: (1, 0), 90: (0, 1), 180: (-1, 0), 270: (0, -1), }[rotation] x, y = coor - return (x*cos_r + y*sin_r, -x*sin_r + y*cos_r) + return x * cos_r + y * sin_r, -x * sin_r + y * cos_r + -def get_angle_from_coordinates((x1,y1), (x2,y2)): +def get_angle_from_coordinates((x1, y1), (x2, y2)): """ Given two points, calculate the vector direction from point1 to point2, directions are multiples of 90 degrees. @@ -82,12 +84,11 @@ def get_angle_from_coordinates((x1,y1), (x2,y2)): Returns: the direction in degrees """ - if y1 == y2:#0 or 180 - if x2 > x1: return 0 - else: return 180 - else:#90 or 270 - if y2 > y1: return 270 - else: return 90 + if y1 == y2: # 0 or 180 + return 0 if x2 > x1 else 180 + else: # 90 or 270 + return 270 if y2 > y1 else 90 + def parse_template(tmpl_str, **kwargs): """ @@ -109,10 +110,11 @@ def parse_template(tmpl_str, **kwargs): # print str(kwargs['param'].get_error_messages()) return str(Template(tmpl_str, kwargs)) + def align_to_grid(coor): _align = lambda: int(round(x / (1.0 * CANVAS_GRID_SIZE)) * CANVAS_GRID_SIZE) try: return [_align() for x in coor] except TypeError: x = coor - return _align()
\ No newline at end of file + return _align() |