summaryrefslogtreecommitdiff
path: root/grc/src/platforms/gui/Utils.py
diff options
context:
space:
mode:
authorjblum2008-09-07 21:38:12 +0000
committerjblum2008-09-07 21:38:12 +0000
commitc86f6c23c6883f73d953d64c28ab42cedb77e4d7 (patch)
tree0193b2a649eb0f7f1065912862de340a02848e16 /grc/src/platforms/gui/Utils.py
parentddec4fc07744a6519086b1b111f29d551b7f19c6 (diff)
downloadgnuradio-c86f6c23c6883f73d953d64c28ab42cedb77e4d7.tar.gz
gnuradio-c86f6c23c6883f73d953d64c28ab42cedb77e4d7.tar.bz2
gnuradio-c86f6c23c6883f73d953d64c28ab42cedb77e4d7.zip
Merged r9481:9518 on jblum/grc_reorganize into trunk. Reorganized grc source under gnuradio.grc module. Trunk passes make distcheck.
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9525 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'grc/src/platforms/gui/Utils.py')
-rw-r--r--grc/src/platforms/gui/Utils.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/grc/src/platforms/gui/Utils.py b/grc/src/platforms/gui/Utils.py
new file mode 100644
index 000000000..17750ef45
--- /dev/null
+++ b/grc/src/platforms/gui/Utils.py
@@ -0,0 +1,71 @@
+"""
+Copyright 2008 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+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
+
+def get_rotated_coordinate(coor, rotation):
+ """
+ Rotate the coordinate by the given rotation.
+ @param coor the coordinate x, y tuple
+ @param rotation the angle in degrees
+ @return the rotated coordinates
+ """
+ #handles negative angles
+ rotation = (rotation + 360)%360
+ assert rotation in POSSIBLE_ROTATIONS
+ #determine the number of degrees to rotate
+ cos_r, sin_r = {
+ 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)
+
+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.
+ @param (x1,y1) the coordinate of point 1
+ @param (x2,y2) the coordinate of point 2
+ @return 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
+
+def xml_encode(string):
+ """
+ Encode a string into an xml safe string by replacing special characters.
+ Needed for gtk pango markup in labels.
+ @param string the input string
+ @return output string with safe characters
+ """
+ string = str(string)
+ for char, safe in (
+ ('&', '&'),
+ ('<', '&lt;'),
+ ('>', '&gt;'),
+ ('"', '&quot;'),
+ ("'", '&apos;'),
+ ): string = string.replace(char, safe)
+ return string