From 383de1d3c95423b53eff8d972c2dd7706a37d9dd Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Thu, 17 Jan 2013 17:23:50 +0000 Subject: using constants for suffix and mimetype --- (limited to 'TurtleArt') diff --git a/TurtleArt/taconstants.py b/TurtleArt/taconstants.py index 6985ce0..97a26b7 100644 --- a/TurtleArt/taconstants.py +++ b/TurtleArt/taconstants.py @@ -21,10 +21,12 @@ from gettext import gettext as _ -# -# Sprite layers -# +# Packaging constants +SUFFIX = ['.ta', '.tb'] +MAGICNUMBER = 'TB' +MIMETYPE = ['application/x-turtle-art', 'application/vnd.turtleblocks'] +# Sprite layers OVERLAY_LAYER = 400 TURTLE_LAYER = 500 BLOCK_LAYER = 600 @@ -45,9 +47,7 @@ BOX_COLORS = {'red': ["#FF0000", "#A00000"], 'white': ["#FFFFFF", "#A0A0A0"], 'black': ["#000000", "#000000"]} -# # Misc. parameters -# PALETTE_HEIGHT = 120 PALETTE_WIDTH = 175 SELECTOR_WIDTH = 55 @@ -84,9 +84,7 @@ CONSTANTS = {'leftpos': None, 'toppos': None, 'rightpos': None, 'purple': 90, 'titlex': None, 'titley': None, 'leftx': None, 'topy': None, 'rightx': None, 'bottomy': None} -# # Blocks that are expandable -# EXPANDABLE_STYLE = ['boolean-style', 'compare-porch-style', 'compare-style', 'number-style-porch', 'number-style', 'basic-style-2arg', 'number-style-block', 'box-style-media'] @@ -100,9 +98,7 @@ EXPANDABLE_ARGS = ['list', 'myfunc1arg', 'myfunc2arg', 'myfunc3arg', 'userdefined', 'userdefined2args', 'userdefined3args', 'loadblock', 'loadblock2arg', 'loadblock3arg'] -# # Deprecated block styles that need dock adjustments -# OLD_DOCK = ['and', 'or', 'plus', 'minus', 'division', 'product', 'remainder'] CONTENT_ARGS = ['show', 'showaligned', 'push', 'storein', 'storeinbox1', @@ -110,9 +106,7 @@ CONTENT_ARGS = ['show', 'showaligned', 'push', 'storein', 'storeinbox1', PREFIX_DICTIONARY = {} -# # These blocks get a special skin -# BLOCKS_WITH_SKIN = [] PYTHON_SKIN = [] @@ -125,9 +119,7 @@ NO_IMPORT = [] EXPAND_SKIN = {} -# # Status blocks -# OVERLAY_SHAPES = ['Cartesian', 'Cartesian_labeled', 'polar', 'metric'] STATUS_SHAPES = ['status', 'info', 'nostack', 'dupstack', 'noinput', @@ -135,15 +127,11 @@ STATUS_SHAPES = ['status', 'info', 'nostack', 'dupstack', 'noinput', 'negroot', 'syntaxerror', 'nofile', 'nojournal', 'zerodivide', 'notanumber', 'incompatible', 'help', 'print'] -# # Emulate Sugar toolbar when running from outside of Sugar -# TOOLBAR_SHAPES = ['hideshowoff', 'eraseron', 'run-fastoff', 'run-slowoff', 'stopiton'] -# # Legacy names -# OLD_NAMES = {'product': 'product2', 'storeinbox': 'storein', 'minus': 'minus2', 'division': 'division2', 'plus': 'plus2', 'and': 'and2', 'or': 'or2', 'less': 'less2', 'greater': 'greater2', @@ -157,15 +145,12 @@ OLD_NAMES = {'product': 'product2', 'storeinbox': 'storein', 'minus': 'minus2', 'sandwichtop2': 'sandwichtop', 'image': 'show', 'container': 'indentity2', 'insertimage': 'show'} -# # Define the relative size and postion of media objects # (w, h, x, y, dx, dy) # TITLEXY = (0.9375, 0.875) -# # Relative placement of portfolio objects (used by deprecated blocks) -# TEMPLATES = {'t1x1': (0.5, 0.5, 0.0625, 0.125, 1.05, 0), 't2z1': (0.5, 0.5, 0.0625, 0.125, 1.05, 1.05), 't1x2': (0.45, 0.45, 0.0625, 0.125, 1.05, 1.05), @@ -190,9 +175,7 @@ VOICES = {'af': 'afrikaans', 'cy': 'welsh-test', 'el': 'greek', 'cs': 'czech', 'it': 'italian', 'pl': 'polish', 'ru': 'russian_test', 'sv': 'swedish', 'tr': 'turkish'} -# # Macros (groups of blocks) -# MACROS = { 'ifthenelse': # Because it is too big to fit on the palette [[0, 'ifelse', 0, 0, [None, None, None, None, None]]], diff --git a/TurtleArt/tautils.py b/TurtleArt/tautils.py index 7d3a351..5f1635b 100644 --- a/TurtleArt/tautils.py +++ b/TurtleArt/tautils.py @@ -1,5 +1,5 @@ #copyright (c) 2007-8, Playful Invention Company. -#Copyright (c) 2008-12, Walter Bender +#Copyright (c) 2008-13, Walter Bender #Permission is hereby granted, free of charge, to any person obtaining a copy #of this software and associated documentation files (the "Software"), to deal @@ -44,7 +44,7 @@ except (ImportError, AttributeError): from StringIO import StringIO from taconstants import (HIT_HIDE, HIT_SHOW, XO1, XO15, XO175, XO30, XO4, - UNKNOWN) + UNKNOWN, MAGICNUMBER) import logging _logger = logging.getLogger('turtleart-activity') @@ -140,8 +140,12 @@ def json_load(text): if OLD_SUGAR_SYSTEM is True: listdata = json.read(text) else: - # Strip out leading and trailing whitespace, nulls, and newlines - clean_text = text.lstrip() + # Remove MAGIC NUMBER, if present, and leading whitespace + if text[0:2] == MAGICNUMBER: + clean_text = text[2:].lstrip() + else: + clean_text = text.lstrip() + # Strip out trailing whitespace, nulls, and newlines clean_text = clean_text.replace('\12', '') clean_text = clean_text.replace('\00', '') clean_text = clean_text.rstrip() diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py index a7432d7..ba072f6 100644 --- a/TurtleArt/tawindow.py +++ b/TurtleArt/tawindow.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- #Copyright (c) 2007, Playful Invention Company -#Copyright (c) 2008-12, Walter Bender +#Copyright (c) 2008-13, Walter Bender #Copyright (c) 2009-11 Raúl Gutiérrez Segalés #Copyright (c) 2011 Collabora Ltd. @@ -54,7 +54,7 @@ from taconstants import (HORIZONTAL_PALETTE, VERTICAL_PALETTE, BLOCK_SCALE, OLD_NAMES, DEFAULT_TURTLE, TURTLE_LAYER, EXPANDABLE, NO_IMPORT, TEMPLATES, PYTHON_SKIN, PALETTE_HEIGHT, STATUS_LAYER, OLD_DOCK, EXPANDABLE_ARGS, XO1, XO15, XO175, XO30, XO4, TITLEXY, CONTENT_ARGS, - CONSTANTS, EXPAND_SKIN, PROTO_LAYER, EXPANDABLE_FLOW) + CONSTANTS, EXPAND_SKIN, PROTO_LAYER, EXPANDABLE_FLOW, SUFFIX) from tapalette import (palette_names, palette_blocks, expandable_blocks, block_names, content_blocks, default_values, special_names, block_styles, help_strings, hidden_proto_blocks, string_or_number_args, @@ -3401,8 +3401,8 @@ may not terminate.', False) self.load_save_folder) if _file_name is None: return - if not _file_name[-3:] in ['.ta', '.tb']: - _file_name = _file_name + '.tb' + if not _file_name[-3:] in SUFFIX: + _file_name = _file_name + SUFFIX[1] self.load_files(_file_name, create_new_project) if create_new_project: self.save_file_name = os.path.basename(_file_name) @@ -3698,19 +3698,19 @@ may not terminate.', False) else: self.process_data(data_from_file(ta_file)) - def save_file(self, _file_name=None): + def save_file(self, file_name=None): ''' Start a project to a file ''' if self.save_folder is not None: self.load_save_folder = self.save_folder - if _file_name is None: - _file_name, self.load_save_folder = get_save_name('.t[a-b]', - self.load_save_folder, self.save_file_name) - if _file_name is None: + if file_name is None: + file_name, self.load_save_folder = get_save_name( + '.t[a-b]', self.load_save_folder, self.save_file_name) + if file_name is None: return - if not _file_name[-3:] in ['.ta', '.tb']: - _file_name = _file_name + '.tb' - data_to_file(self.assemble_data_to_save(), _file_name) - self.save_file_name = os.path.basename(_file_name) + if not file_name[-3:] in SUFFIX: + file_name = file_name + SUFFIX[1] + data_to_file(self.assemble_data_to_save(), file_name) + self.save_file_name = os.path.basename(file_name) if not self.running_sugar: self.save_folder = self.load_save_folder @@ -3852,14 +3852,17 @@ may not terminate.', False) dy *= h return(w, h, x, y, dx, dy) - def save_for_upload(self, _file_name): + def save_for_upload(self, file_name): ''' Grab the current canvas and save it for upload ''' - if _file_name[-3:] in ['.ta', '.tb']: - _file_name = _file_name[0: -3] - data_to_file(self.assemble_data_to_save(), _file_name + '.ta') - save_picture(self.canvas, _file_name + '.png') - ta_file = _file_name + '.ta' - image_file = _file_name + '.png' + if not file_name[-3:] in SUFFIX: + ta_name = file_name + SUFFIX[1] + image_file = file_name + '.png' + else: + ta_file = file_name + image_file = file_name[0:-3] + '.png' + + data_to_file(self.assemble_data_to_save(), ta_file) + save_picture(self.canvas, image_file) return ta_file, image_file def save_as_image(self, name="", svg=False): -- cgit v0.9.1