moved author attribution out of individual files and put in AUTHORS
[debian/gnuradio] / grc / src / grc / gui / elements / Utils.py
1 """
2 Copyright 2008 Free Software Foundation, Inc.
3 This file is part of GNU Radio
4
5 GNU Radio Companion is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 GNU Radio Companion is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18 """
19 ##@package grc.gui.elements.Utils
20 #Shared functions for flow graph elements.
21
22 def get_angle_from_coordinates((x1,y1), (x2,y2)):
23         """!
24         Given two points, calculate the vector direction from point1 to point2, directions are multiples of 90 degrees.
25         @param (x1,y1) the coordinate of point 1
26         @param (x2,y2) the coordinate of point 2
27         @return the direction in degrees
28         """
29         if y1 == y2:#0 or 180           
30                 if x2 > x1: return 0
31                 else: return 180                
32         else:#90 or 270
33                 if y2 > y1: return 270
34                 else: return 90
35
36 def xml_encode(string):
37         """
38         Encode a string into an xml safe string by replacing special characters.
39         @param string the input string
40         @return output string with safe characters
41         """
42         string = str(string)
43         for char, safe in (
44                         ('&', '&'),
45                         ('<', '&lt;'),
46                         ('>', '&gt;'),
47                         ('"', '&quot;'),
48                         ("'", '&apos;'),
49         ): string = string.replace(char, safe)
50         return string
51