A GraphWin is a toplevel window for displaying graphics.
| 236 | # Graphics classes start here |
| 237 | |
| 238 | class GraphWin(tk.Canvas): |
| 239 | |
| 240 | """A GraphWin is a toplevel window for displaying graphics.""" |
| 241 | |
| 242 | def __init__(self, title="Graphics Window", |
| 243 | width=200, height=200, autoflush=False): |
| 244 | """ init doc """ |
| 245 | _tkCall(self.__init_help, title, width, height, autoflush) |
| 246 | |
| 247 | |
| 248 | def __init_help(self, title, width, height, autoflush): |
| 249 | master = tk.Toplevel(_root) |
| 250 | master.protocol("WM_DELETE_WINDOW", self.__close_help) |
| 251 | tk.Canvas.__init__(self, master, width=width, height=height) |
| 252 | self.master.title(title) |
| 253 | self.pack() |
| 254 | master.resizable(0,0) |
| 255 | self.foreground = "black" |
| 256 | self.items = [] |
| 257 | self.mouseX = None |
| 258 | self.mouseY = None |
| 259 | self.bind("<Button-1>", self._onClick) |
| 260 | self.height = height |
| 261 | self.width = width |
| 262 | self.autoflush = autoflush |
| 263 | self._mouseCallback = None |
| 264 | self.trans = None |
| 265 | self.closed = False |
| 266 | if autoflush: _root.update() |
| 267 | |
| 268 | def __checkOpen(self): |
| 269 | if self.closed: |
| 270 | raise GraphicsError, "window is closed" |
| 271 | |
| 272 | def setBackground(self, color): |
| 273 | """Set background color of the window""" |
| 274 | self.__checkOpen() |
| 275 | _tkExec(self.config, bg=color) |
| 276 | #self.config(bg=color) |
| 277 | |
| 278 | def setCoords(self, x1, y1, x2, y2): |
| 279 | """Set coordinates of window to run from (x1,y1) in the |
| 280 | lower-left corner to (x2,y2) in the upper-right corner.""" |
| 281 | self.trans = Transform(self.width, self.height, x1, y1, x2, y2) |
| 282 | |
| 283 | def close(self): |
| 284 | if self.closed: return |
| 285 | _tkCall(self.__close_help) |
| 286 | |
| 287 | def __close_help(self): |
| 288 | """Close the window""" |
| 289 | self.closed = True |
| 290 | self.master.destroy() |
| 291 | _root.update() |
| 292 | |
| 293 | def isClosed(self): |
| 294 | return self.closed |
| 295 |
no outgoing calls
no test coverage detected