class Country: def __init__(self, states, width=950): ratio = 0.5263 self._canvas = Canvas(width, ratio * width) self._canvas.setTitle('United States') self._states = {} # map from abbrev to RenderedState bounds = None self._canvas.setAutoRefresh(False) for s in states: rendered = _RenderedState(s) self._canvas.add(rendered) self._states[s.abbrev()] = rendered bounds = _mergeBounds(rendered.getBounds(), bounds) self._canvas.zoomView(width / 950.0, Point(0, 0)) self._canvas.setAutoRefresh(True) # self._canvas.setView(Point(bounds[0],bounds[3]), Point(bounds[1],bounds[2])) def setTitle(self, title): """Set the Canvas title to the given string.""" self._canvas.setTitle(title) def setFillColor(self, stateCode, color): """Set the fill color of the state with given abbreviation to the indicated color.""" if not isinstance(stateCode, str): raise TypeError('state code must be a string') if stateCode not in self._states: raise ValueError('unknown state code: ' + stateCode) self._states[stateCode].setFillColor(color)
class Frame: def __init__(self, width, height, bgColor, title): self.frame = Canvas(width, height, bgColor, title) # constructs a new Frame object def getWidth(self): return self.frame.getWidth() # returns the width of the Frame def getHeight(self): return self.frame.getHeight() # returns the height of the Frame def setWidth(self, width): self.frame.setWidth(width) # sets a new width for the Frame def setHeight(self, height): self.frame.setHeight(height) # sets a new height for the Frame def add(self, obj): self.frame.add(obj) # adds a new object to the Frame def getContents(self): return self.frame.getContents() def close(self): self.frame.close() def wait(self): self.frame.wait() def remove(self, obj): self.frame.remove(obj) def setTitle(self, title): self.frame.setTitle(title)