Changeset 122:02423600d958


Ignore:
Timestamp:
Sep 2, 2013, 2:40:56 PM (7 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Message:

Use dialogs to report save results

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • nagslang/level.py

    r118 r122  
    6767        """Check if all the polygons are closed"""
    6868        closed = True
    69         for poly in self.polygons.values():
     69        messages = []
     70        for index, poly in self.polygons.items():
    7071            if len(poly) == 0:
    7172                # We ignore empty polygons
     
    7374            elif len(poly) == 1:
    7475                closed = False
    75                 print "\033[31mError: polygon too small\033[0m"
     76                messages.append("Error: polygon %s too small" % index)
    7677            elif poly[-1] != poly[0]:
    7778                closed = False
    78                 print "\033[31mError: polygon not closed\033[0m"
    79         return closed
     79                messages.append("Error: polygon %s not closed" % index)
     80        return closed, messages
    8081
    8182    def save(self):
    82         closed = self.all_closed()
     83        closed, _ = self.all_closed()
    8384        if not closed:
    84             print 'Not saving the level'
    85             return
     85            return False
    8686        with resources.get_file('levels', self.name, mode='w') as f:
    8787            f.write('X-Size: %s\n' % self.x)
     
    9494                for point in poly:
    9595                    f.write('Point: %d %d\n' % point)
    96         print 'level %s saved' % self.name
     96        return True
    9797
    9898    def get_size(self):
  • tools/area_editor.py

    r117 r122  
    2121from albow.widget import Widget
    2222from albow.controls import Button
     23from albow.dialogs import alert
    2324
    2425sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
     
    261262
    262263    def save(self):
    263         level.save()
     264        closed, messages = self.level.all_closed()
     265        if closed:
     266            self.level.save()
     267            # display success
     268            alert("Level %s saved successfully." % self.level.name)
     269        else:
     270            # display errors
     271            alert("Failed to save level.\n\n%s" % '\n'.join(messages))
    264272
    265273    def mouse_move(self, ev):
Note: See TracChangeset for help on using the changeset viewer.