From 30159238e235c2a889fa37cc80b4d9648c8ba760 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Thu, 09 Jun 2011 21:48:22 +0000 Subject: adding CC coordinate grid for XO hardware --- diff --git a/TurtleArt/taconstants.py b/TurtleArt/taconstants.py index fdc42d1..30920d6 100644 --- a/TurtleArt/taconstants.py +++ b/TurtleArt/taconstants.py @@ -140,7 +140,7 @@ MEDIA_SHAPES = ['audiooff', 'audioon', 'audiosmall', 'pythonoff', 'pythonon', 'pythonsmall', 'list', '1x1', '1x1a', '2x1', '1x2', '2x2'] -OVERLAY_SHAPES = ['Cartesian', 'Cartesian_labeled', 'polar'] +OVERLAY_SHAPES = ['Cartesian', 'Cartesian_labeled', 'polar', 'metric'] STATUS_SHAPES = ['status', 'info', 'nostack', 'dupstack', 'noinput', 'emptyheap', 'emptybox', 'nomedia', 'nocode', 'overflowerror', diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py index 5aff270..64a32fd 100644 --- a/TurtleArt/tawindow.py +++ b/TurtleArt/tawindow.py @@ -185,6 +185,7 @@ class TurtleArtWindow(): self.media_shapes = {} self.cartesian = False self.polar = False + self.metric = False self.overlay_shapes = {} self.toolbar_shapes = {} self.toolbar_offset = 0 @@ -485,6 +486,15 @@ class TurtleArtWindow(): self.overlay_shapes['polar'].hide() self.polar = False + def set_metric(self, flag): + """ Turn on/off metric coordinates """ + if flag: + self.overlay_shapes['metric'].set_layer(OVERLAY_LAYER) + self.metric = True + else: + self.overlay_shapes['metric'].hide() + self.metric = False + def update_overlay_position(self, widget, event): """ Reposition the overlays when window size changes """ self.width = event.width @@ -507,6 +517,7 @@ class TurtleArtWindow(): self.overlay_shapes[name].type = 'overlay' self.cartesian = False self.polar = False + self.metric = False self.canvas.width = self.width self.canvas.height = self.height self.canvas.move_turtle() diff --git a/TurtleArtActivity.py b/TurtleArtActivity.py index befd5b2..61d7645 100644 --- a/TurtleArtActivity.py +++ b/TurtleArtActivity.py @@ -51,7 +51,7 @@ from TurtleArt.taconstants import ICON_SIZE, BLOCK_SCALE from TurtleArt.taexporthtml import save_html from TurtleArt.taexportlogo import save_logo from TurtleArt.tautils import data_to_file, data_to_string, data_from_string, \ - get_path, chooser + get_path, chooser, get_hardware from TurtleArt.tawindow import TurtleArtWindow from TurtleArt.tacollaboration import Collaboration @@ -362,6 +362,13 @@ class TurtleArtActivity(activity.Activity): else: self.tw.set_polar(True) + def do_metric_cb(self, button): + ''' Display metric-coordinate grid. ''' + if self.tw.metric: + self.tw.set_metric(False) + else: + self.tw.set_metric(True) + def do_rescale_cb(self, button): ''' Rescale coordinate system (100==height/2 or 100 pixels). ''' if self.tw.cartesian: @@ -374,6 +381,11 @@ class TurtleArtActivity(activity.Activity): self.tw.set_polar(False) else: polar = False + if self.tw.metric: + metric = True + self.tw.set_metric(False) + else: + polar = False if self.tw.coord_scale == 1: self.tw.coord_scale = self.tw.height / 200 self.rescale_button.set_icon('contract-coordinates') @@ -387,6 +399,8 @@ class TurtleArtActivity(activity.Activity): self.tw.set_cartesian(True) if polar: self.tw.set_polar(True) + if metric: + self.tw.set_metric(True) def get_document_path(self, async_cb, async_err_cb): ''' View TA code as part of view source. ''' @@ -544,6 +558,9 @@ class TurtleArtActivity(activity.Activity): self.do_cartesian_cb, view_toolbar_button) self._add_button('view-polar', _('Polar coordinates'), self.do_polar_cb, view_toolbar_button) + if get_hardware() in ['XO1', 'XO15']: + self._add_button('view-metric', _('Metric coordinates'), + self.do_metric_cb, view_toolbar_button) self._add_separator(view_toolbar) self.coordinates_label = self._add_label(_('xcor') + ' = 0 ' + \ _('ycor') + ' = 0 ' + _('heading') + ' = 0', view_toolbar) diff --git a/icons/view-metric.svg b/icons/view-metric.svg new file mode 100644 index 0000000..eccd71c --- /dev/null +++ b/icons/view-metric.svg @@ -0,0 +1,61 @@ + + + + + + + + image/svg+xml + + + + + + + + + + CC + + + diff --git a/images/metric.svg b/images/metric.svg new file mode 100644 index 0000000..33f6d3d --- /dev/null +++ b/images/metric.svg @@ -0,0 +1,489 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + 2 + 3 + 5 + + 5 + + 4 + + 3 + + 2 + + 1 + + –1 + + –2 + + –3 + + –4 + –1 + –2 + –3 + –4 + 0 + (–7, 5) + (7, 5) + (7, –5) + (–7, –5) + + + 4 + + –5 + + + + + –6 + + + 6 + + 7 + + –5 + + –7 + -- cgit v0.9.1