]> git.gag.com Git - debian/gnuradio/blob - grc/src/grc/gui/elements/Utils.py
34f084343e374e3128a3ad8c5836b9b2b493e726
[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 #@author Josh Blum
22
23 def get_angle_from_coordinates((x1,y1), (x2,y2)):
24         """!
25         Given two points, calculate the vector direction from point1 to point2, directions are multiples of 90 degrees.
26         @param (x1,y1) the coordinate of point 1
27         @param (x2,y2) the coordinate of point 2
28         @return the direction in degrees
29         """
30         if y1 == y2:#0 or 180           
31                 if x2 > x1: return 0
32                 else: return 180                
33         else:#90 or 270
34                 if y2 > y1: return 270
35                 else: return 90
36
37 def xml_encode(string):
38         """
39         Encode a string into an xml safe string by replacing special characters.
40         @param string the input string
41         @return output string with safe characters
42         """
43         string = str(string)
44         for char, safe in (
45                         ('&', '&'),
46                         ('<', '&lt;'),
47                         ('>', '&gt;'),
48                         ('"', '&quot;'),
49                         ("'", '&apos;'),
50         ): string = string.replace(char, safe)
51         return string
52