1 # Define window operations for STDWIN
4 from stdwinevents
import *
5 from glstdwin
import G
# Global variables
6 from glstdwin
import MASK
# Tunable constant
10 def _init(self
, title
):
11 self
._docsize
= (0, 0)
18 self
._gid
= gl
.winopen(title
)
19 gl
.winconstraints() # To remove prefsize() effect
25 del G
.windowmap
[`self
._gid`
]
26 gl
.winclose(self
._gid
)
29 def _needredraw(self
):
30 if self
in G
.drawqueue
:
31 G
.drawqueue
.remove(self
)
32 G
.drawqueue
.append(self
)
34 def begindrawing(self
):
35 from glstdwdraw
import DrawingObject
36 return DrawingObject()._init
(self
)
38 def change(self
, area
):
40 # XXX Should record the area to be drawn?
54 def scroll(self
, area
, by
):
55 # XXX ought to use gl.rectcopy()
59 def setdocsize(self
, docsize
):
60 self
._docsize
= docsize
62 def setorigin(self
, origin
):
65 def settimer(self
, decisecs
):
68 def settitle(self
, title
):
75 def _fixviewport(self
):
77 # Called after redraw or resize, and initially.
79 # Fix the coordinate system so that (0, 0) is top left,
80 # units are pixels, and positive axes point right and down.
82 # Make the viewport slightly larger than the window,
83 # and set the screenmask exactly to the window; this
84 # help fixing character clipping.
86 # Set self._area to the window rectangle in STDWIN coords.
90 x0
, x1
, y0
, y1
= gl
.getviewport()
91 width
, height
= x1
-x0
, y1
-y0
92 gl
.viewport(x0
-MASK
, x1
+MASK
, y0
-MASK
, y1
+MASK
)
93 gl
.scrmask(x0
, x1
, y0
, y1
)
94 gl
.ortho2(-MASK
, width
+MASK
, height
+MASK
, -MASK
)
95 self
._area
= (0, 0), (width
, height
)
97 def menucreate(self
, title
):
98 from glstdwmenu
import MenuObject
99 menu
= MenuObject()._init
(self
, title
)
100 self
._menus
.append(menu
)
106 if len(self
._menus
) == 1:
107 pup
= self
._menus
[0]._makepup
(0)
112 return WE_MENU
, self
, (self
._menus
[0], val
)
114 # More than one menu: use nested menus.
118 for menu
in self
._menus
:
119 pups
.append(menu
._makepup
(firstitem
))
120 firstitem
= firstitem
+ 100
122 for i
in range(len(self
._menus
)):
123 gl
.addtopup(pup
, self
._menus
[i
]._title
+ '%m', pups
[i
])
130 i_menu
, i_item
= divmod(val
, 100)
131 return WE_MENU
, self
, (self
._menus
[i_menu
], i_item
)
133 def _doshortcut(self
, char
):
134 for menu
in self
._menus
:
135 i
= menu
._checkshortcut
(char
)
137 return WE_MENU
, self
, (menu
, i
)