diff options
author | Sebastian Koslowski <koslowski@kit.edu> | 2014-08-19 17:02:33 +0200 |
---|---|---|
committer | Sebastian Koslowski <koslowski@kit.edu> | 2014-08-19 17:31:33 +0200 |
commit | 0dd158155c074113ec1cc6a3de7ecdd2be7d65e8 (patch) | |
tree | c29e8d9382426d23ae110187a6b2c375c8864bd9 /grc/gui/Utils.py | |
parent | 842d8c9d9aac5f7a48a78a9d6babc865570b81c8 (diff) |
grc: snap-to-grid (WIP)
Diffstat (limited to 'grc/gui/Utils.py')
-rw-r--r-- | grc/gui/Utils.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/grc/gui/Utils.py b/grc/gui/Utils.py index ebd5aefca7..9a0a59cda7 100644 --- a/grc/gui/Utils.py +++ b/grc/gui/Utils.py @@ -17,7 +17,7 @@ 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 +from Constants import POSSIBLE_ROTATIONS, CANVAS_GRID_SIZE from Cheetah.Template import Template import pygtk pygtk.require('2.0') @@ -108,3 +108,11 @@ def parse_template(tmpl_str, **kwargs): # print tmpl_str # 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 |