| 3562 | return Turtle._screen |
| 3563 | |
| 3564 | class _Screen(TurtleScreen): |
| 3565 | |
| 3566 | _root = None |
| 3567 | _canvas = None |
| 3568 | _title = _CFG["title"] |
| 3569 | |
| 3570 | def __init__(self): |
| 3571 | # XXX there is no need for this code to be conditional, |
| 3572 | # as there will be only a single _Screen instance, anyway |
| 3573 | # XXX actually, the turtle demo is injecting root window, |
| 3574 | # so perhaps the conditional creation of a root should be |
| 3575 | # preserved (perhaps by passing it as an optional parameter) |
| 3576 | if _Screen._root is None: |
| 3577 | _Screen._root = self._root = _Root() |
| 3578 | self._root.title(_Screen._title) |
| 3579 | self._root.ondestroy(self._destroy) |
| 3580 | if _Screen._canvas is None: |
| 3581 | width = _CFG["width"] |
| 3582 | height = _CFG["height"] |
| 3583 | canvwidth = _CFG["canvwidth"] |
| 3584 | canvheight = _CFG["canvheight"] |
| 3585 | leftright = _CFG["leftright"] |
| 3586 | topbottom = _CFG["topbottom"] |
| 3587 | self._root.setupcanvas(width, height, canvwidth, canvheight) |
| 3588 | _Screen._canvas = self._root._getcanvas() |
| 3589 | TurtleScreen.__init__(self, _Screen._canvas) |
| 3590 | self.setup(width, height, leftright, topbottom) |
| 3591 | |
| 3592 | def setup(self, width=_CFG["width"], height=_CFG["height"], |
| 3593 | startx=_CFG["leftright"], starty=_CFG["topbottom"]): |
| 3594 | """ Set the size and position of the main window. |
| 3595 | |
| 3596 | Arguments: |
| 3597 | width: as integer a size in pixels, as float a fraction of the screen. |
| 3598 | Default is 50% of screen. |
| 3599 | height: as integer the height in pixels, as float a fraction of the |
| 3600 | screen. Default is 75% of screen. |
| 3601 | startx: if positive, starting position in pixels from the left |
| 3602 | edge of the screen, if negative from the right edge |
| 3603 | Default, startx=None is to center window horizontally. |
| 3604 | starty: if positive, starting position in pixels from the top |
| 3605 | edge of the screen, if negative from the bottom edge |
| 3606 | Default, starty=None is to center window vertically. |
| 3607 | |
| 3608 | Examples (for a Screen instance named screen): |
| 3609 | >>> screen.setup (width=200, height=200, startx=0, starty=0) |
| 3610 | |
| 3611 | sets window to 200x200 pixels, in upper left of screen |
| 3612 | |
| 3613 | >>> screen.setup(width=.75, height=0.5, startx=None, starty=None) |
| 3614 | |
| 3615 | sets window to 75% of screen by 50% of screen and centers |
| 3616 | """ |
| 3617 | if not hasattr(self._root, "set_geometry"): |
| 3618 | return |
| 3619 | sw = self._root.win_width() |
| 3620 | sh = self._root.win_height() |
| 3621 | if isinstance(width, float) and 0 <= width <= 1: |