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)