[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 01/06: grc: clean-up gui/Utils.py
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 01/06: grc: clean-up gui/Utils.py |
Date: |
Fri, 24 Jul 2015 15:23:08 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch maint
in repository gnuradio.
commit 7345de003ff2f916f0e6344c12f1ae1fc95fdf54
Author: Sebastian Koslowski <address@hidden>
Date: Tue Jul 21 16:39:57 2015 +0200
grc: clean-up gui/Utils.py
---
grc/gui/Utils.py | 38 ++++++++++++++++++++------------------
1 file changed, 20 insertions(+), 18 deletions(-)
diff --git a/grc/gui/Utils.py b/grc/gui/Utils.py
index 9a0a59c..44df79f 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()
- [Commit-gnuradio] [gnuradio] branch maint updated (b93e559 -> f8a9f9f), git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 04/06: volk: update submodule reference to release 1.0.2, git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 03/06: cmake: set correct vars when pkg-config finds GSL, git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 02/06: grc: ensure only valid utf-8 is passed to markup_escape_text (fixes #813), git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 01/06: grc: clean-up gui/Utils.py,
git <=
- [Commit-gnuradio] [gnuradio] 06/06: Merge remote-tracking branch 'gnuradio-wg-grc/maint_grcwg' into maint, git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 05/06: runtime: remove thread-unsafe static qualifier, git, 2015/07/24