Added ScrolledWindow (a window with one or two scrollbars)

This commit is contained in:
Jack Jansen 1996-04-12 16:24:44 +00:00
parent 7853647dd1
commit e353215bf7
2 changed files with 172 additions and 2 deletions

View File

@ -27,6 +27,7 @@ from Windows import *
import EasyDialogs
kHighLevelEvent = 23 # Don't know what header file this should come from
SCROLLBARWIDTH = 16 # Again, not a clue...
# Map event 'what' field to strings
@ -358,14 +359,14 @@ class MenuBar:
def addmenu(self, title, after = 0):
id = self.getnextid()
print 'Newmenu', title, id # XXXX
if DEBUG: print 'Newmenu', title, id # XXXX
m = NewMenu(id, title)
m.InsertMenu(after)
DrawMenuBar()
return id, m
def delmenu(self, id):
print 'Delmenu', id # XXXX
if DEBUG: print 'Delmenu', id # XXXX
DeleteMenu(id)
def addpopup(self, title = ''):
@ -611,6 +612,89 @@ class ControlsWindow(Window):
else:
if DEBUG: print "FindControl(%s, %s) -> (%s, %s)" % \
(local, window, ctltype, control)
self.do_contentclick(local, modifiers, event)
class ScrolledWindow(ControlsWindow):
def __init__(self, parent):
self.barx = self.bary = None
ControlsWindow.__init__(self, parent)
def scrollbars(self, wantx=1, wanty=1):
SetPort(self.wid)
self.barx = self.bary = None
x0, y0, x1, y1 = self.wid.GetWindowPort().portRect
vx, vy = self.getscrollbarvalues()
if wantx:
rect = x0-1, y1-(SCROLLBARWIDTH-1), x1-(SCROLLBARWIDTH-2), y1+1
self.barx = NewControl(self.wid, rect, "", 1, vx, 0, 32767, 16, 0)
if wanty:
rect = x1-(SCROLLBARWIDTH-1), y0-1, x1+1, y1-(SCROLLBARWIDTH-2)
self.bary = NewControl(self.wid, rect, "", 1, vy, 0, 32767, 16, 0)
def do_postclose(self):
self.barx = self.bary = None
ControlsWindow.do_postclose(self)
def do_activate(self, onoff, event):
if onoff:
onoff = 0
else:
onoff = 255
if self.barx:
self.barx.HiliteControl(onoff)
if self.bary:
self.bary.HiliteControl(onoff)
def do_postresize(self, width, height, window):
l, t, r, b = self.wid.GetWindowPort().portRect
if self.barx:
self.barx.MoveControl(l-1, b-(SCROLLBARWIDTH-1))
self.barx.SizeControl((r-l)-(SCROLLBARWIDTH-2), SCROLLBARWIDTH)
if self.bary:
self.bary.MoveControl(r-(SCROLLBARWIDTH-1), t-1)
self.bary.SizeControl(SCROLLBARWIDTH, (b-t)-(SCROLLBARWIDTH-2))
InvalRect((l, t, r, b))
def do_controlhit(self, window, control, pcode, event):
if control == self.barx:
bar = self.barx
which = 'x'
elif control == self.bary:
bar = self.bary
which = 'y'
else:
return 0
value = None
if pcode == inUpButton:
what = '-'
elif pcode == inDownButton:
what = '+'
elif pcode == inPageUp:
what = '--'
elif pcode == inPageDown:
what = '++'
else:
what = 'set'
value = bar.GetControlValue()
self.scrollbar_callback(which, what, value)
self.updatescrollbars()
return 1
def updatescrollbars(self):
SetPort(self.wid)
vx, vy = self.getscrollbarvalues()
if self.barx:
self.barx.SetControlValue(vx)
if self.bary:
self.bary.SetControlValue(vy)
# To be overridden:
def getscrollbarvalues(self):
return 0, 0
def scrollbar_callback(self, which, what, value):
print 'scroll', which, what, value
class DialogWindow(Window):
"""A modeless dialog window"""

View File

@ -0,0 +1,86 @@
# Test FrameWork scrollbars
# Draw a window in which the user can type.
#
# This test expects Win, Evt and FrameWork (and anything used by those)
# to work.
#
# Actually, it is more a test of FrameWork by now....
from FrameWork import *
import Win
import Qd
import TE
import os
class MyWindow(ScrolledWindow):
def open(self, name):
r = (40, 40, 400, 300)
w = Win.NewWindow(r, name, 1, 0, -1, 1, 0x55555555)
self.ourrect = 0, 0, 360-SCROLLBARWIDTH-1, 260-SCROLLBARWIDTH-1
Qd.SetPort(w)
w.DrawGrowIcon()
self.wid = w
self.do_postopen()
self.vx = self.vy = 0
self.scrollbars()
def getscrollbarvalues(self):
return self.vx, self.vy
def scrollbar_callback(self, which, what, value):
if what == '-':
delta = -1
elif what == '--':
delta = -100
elif what == '+':
delta = 1
elif what == '++':
delta = 100
if which == 'x':
if value:
self.vx = value
else:
self.vx = self.vx + delta
else:
if value:
self.vy = value
else:
self.vy = self.vy + delta
Win.InvalRect(self.ourrect)
def do_update(self, wid, event):
Qd.EraseRect(self.ourrect)
Qd.MoveTo(40, 40)
Qd.DrawString("x=%d, y=%d"%(self.vx, self.vy))
class TestSW(Application):
def __init__(self):
Application.__init__(self)
self.num = 0
self.listoflists = []
def makeusermenus(self):
self.filemenu = m = Menu(self.menubar, "File")
self.newitem = MenuItem(m, "New window...", "O", self.open)
self.quititem = MenuItem(m, "Quit", "Q", self.quit)
def open(self, *args):
w = MyWindow(self)
w.open('Window %d'%self.num)
self.num = self.num + 1
self.listoflists.append(w)
def quit(self, *args):
raise self
def do_about(self, id, item, window, event):
EasyDialogs.Message("""Test scrolling FrameWork windows""")
def main():
App = TestSW()
App.mainloop()
if __name__ == '__main__':
main()