diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 1999-12-23 14:45:02 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 1999-12-23 14:45:02 (GMT) |
commit | 3b23ed9ba640ed6426a341091e6a5ad7405158a9 (patch) | |
tree | 5f5fc3f76530ff25839e262f619c8226edee1337 /Mac/Demo/PICTbrowse | |
parent | 6a6db0724cfa6f6d7126672be68551e49f52f063 (diff) | |
download | cpython-3b23ed9ba640ed6426a341091e6a5ad7405158a9.zip cpython-3b23ed9ba640ed6426a341091e6a5ad7405158a9.tar.gz cpython-3b23ed9ba640ed6426a341091e6a5ad7405158a9.tar.bz2 |
Converted to Appearance and using a List control in stead of manually creating the List and putting it in a useritem. The old version is in oldPICTbrowse, for documentary purposes.
Diffstat (limited to 'Mac/Demo/PICTbrowse')
-rw-r--r-- | Mac/Demo/PICTbrowse/ICONbrowse.py | 27 | ||||
-rw-r--r-- | Mac/Demo/PICTbrowse/PICTbrowse.py | 28 | ||||
-rw-r--r-- | Mac/Demo/PICTbrowse/PICTbrowse.rsrc | bin | 502 -> 785 bytes | |||
-rw-r--r-- | Mac/Demo/PICTbrowse/PICTbrowse2.py | 28 | ||||
-rw-r--r-- | Mac/Demo/PICTbrowse/cicnbrowse.py | 27 | ||||
-rw-r--r-- | Mac/Demo/PICTbrowse/oldPICTbrowse.py | 165 | ||||
-rw-r--r-- | Mac/Demo/PICTbrowse/oldPICTbrowse.rsrc | bin | 0 -> 502 bytes |
7 files changed, 185 insertions, 90 deletions
diff --git a/Mac/Demo/PICTbrowse/ICONbrowse.py b/Mac/Demo/PICTbrowse/ICONbrowse.py index c4f945b..f5ea93b 100644 --- a/Mac/Demo/PICTbrowse/ICONbrowse.py +++ b/Mac/Demo/PICTbrowse/ICONbrowse.py @@ -5,6 +5,7 @@ import EasyDialogs import Res import Qd import Win +import Controls import List import sys import struct @@ -119,11 +120,11 @@ class MyDialog(FrameWork.DialogWindow): self.id = id FrameWork.DialogWindow.open(self, ID_MAIN) self.wid.SetDialogDefaultItem(MAIN_SHOW) - tp, h, rect = self.wid.GetDialogItem(MAIN_LIST) - rect2 = rect[0]+1, rect[1]+1, rect[2]-17, rect[3]-17 # Scroll bar space - self.list = List.LNew(rect2, (0, 0, 1, len(contents)), (0,0), 0, self.wid, - 0, 1, 1, 1) self.contents = contents + self.ctl = self.wid.GetDialogItemAsControl(MAIN_LIST) + h = self.ctl.GetControlDataHandle(Controls.kControlListBoxPart, + Controls.kControlListBoxListHandleTag) + self.list = List.as_List(h) self.setlist() def setlist(self): @@ -139,13 +140,6 @@ class MyDialog(FrameWork.DialogWindow): self.list.LSetDrawingMode(1) self.list.LUpdate(self.wid.GetWindowPort().visRgn) - def do_listhit(self, event): - (what, message, when, where, modifiers) = event - Qd.SetPort(self.wid) - where = Qd.GlobalToLocal(where) - if self.list.LClick(where, modifiers): - self.do_show() - def getselection(self): items = [] point = (0,0) @@ -165,21 +159,10 @@ class MyDialog(FrameWork.DialogWindow): for resid in selection: self.parent.showICON(resid) - def do_rawupdate(self, window, event): - tp, h, rect = self.wid.GetDialogItem(MAIN_LIST) - Qd.SetPort(self.wid) - Qd.FrameRect(rect) - self.list.LUpdate(self.wid.GetWindowPort().visRgn) - - def do_activate(self, activate, event): - self.list.LActivate(activate) - def do_close(self): self.close() def do_itemhit(self, item, event): - if item == MAIN_LIST: - self.do_listhit(event) if item == MAIN_SHOW: self.do_show() diff --git a/Mac/Demo/PICTbrowse/PICTbrowse.py b/Mac/Demo/PICTbrowse/PICTbrowse.py index 412716e..a28837f 100644 --- a/Mac/Demo/PICTbrowse/PICTbrowse.py +++ b/Mac/Demo/PICTbrowse/PICTbrowse.py @@ -5,6 +5,7 @@ import EasyDialogs import Res import Qd import Win +import Controls import List import sys import struct @@ -97,11 +98,11 @@ class MyDialog(FrameWork.DialogWindow): self.id = id FrameWork.DialogWindow.open(self, ID_MAIN) self.wid.SetDialogDefaultItem(MAIN_SHOW) - tp, h, rect = self.wid.GetDialogItem(MAIN_LIST) - rect2 = rect[0]+1, rect[1]+1, rect[2]-17, rect[3]-17 # Scroll bar space - self.list = List.LNew(rect2, (0, 0, 1, len(contents)), (0,0), 0, self.wid, - 0, 1, 1, 1) self.contents = contents + self.ctl = self.wid.GetDialogItemAsControl(MAIN_LIST) + h = self.ctl.GetControlDataHandle(Controls.kControlListBoxPart, + Controls.kControlListBoxListHandleTag) + self.list = List.as_List(h) self.setlist() def setlist(self): @@ -117,14 +118,6 @@ class MyDialog(FrameWork.DialogWindow): self.list.LSetDrawingMode(1) self.list.LUpdate(self.wid.GetWindowPort().visRgn) - def do_listhit(self, event): - (what, message, when, where, modifiers) = event - Qd.SetPort(self.wid) - where = Qd.GlobalToLocal(where) - print 'LISTHIT', where - if self.list.LClick(where, modifiers): - self.do_show() - def getselection(self): items = [] point = (0,0) @@ -144,21 +137,10 @@ class MyDialog(FrameWork.DialogWindow): for resid in selection: self.parent.showPICT(resid) - def do_rawupdate(self, window, event): - tp, h, rect = self.wid.GetDialogItem(MAIN_LIST) - Qd.SetPort(self.wid) - Qd.FrameRect(rect) - self.list.LUpdate(self.wid.GetWindowPort().visRgn) - - def do_activate(self, activate, event): - self.list.LActivate(activate) - def do_close(self): self.close() def do_itemhit(self, item, event): - if item == MAIN_LIST: - self.do_listhit(event) if item == MAIN_SHOW: self.do_show() diff --git a/Mac/Demo/PICTbrowse/PICTbrowse.rsrc b/Mac/Demo/PICTbrowse/PICTbrowse.rsrc Binary files differindex 7bc9dae..aae379b 100644 --- a/Mac/Demo/PICTbrowse/PICTbrowse.rsrc +++ b/Mac/Demo/PICTbrowse/PICTbrowse.rsrc diff --git a/Mac/Demo/PICTbrowse/PICTbrowse2.py b/Mac/Demo/PICTbrowse/PICTbrowse2.py index c2d9c17..60f1c70 100644 --- a/Mac/Demo/PICTbrowse/PICTbrowse2.py +++ b/Mac/Demo/PICTbrowse/PICTbrowse2.py @@ -5,6 +5,7 @@ import EasyDialogs import Res import Qd import Win +import Controls import List import sys import struct @@ -119,11 +120,11 @@ class MyDialog(FrameWork.DialogWindow): self.id = id FrameWork.DialogWindow.open(self, ID_MAIN) self.wid.SetDialogDefaultItem(MAIN_SHOW) - tp, h, rect = self.wid.GetDialogItem(MAIN_LIST) - rect2 = rect[0]+1, rect[1]+1, rect[2]-17, rect[3]-17 # Scroll bar space - self.list = List.LNew(rect2, (0, 0, 1, len(contents)), (0,0), 0, self.wid, - 0, 1, 1, 1) self.contents = contents + self.ctl = self.wid.GetDialogItemAsControl(MAIN_LIST) + h = self.ctl.GetControlDataHandle(Controls.kControlListBoxPart, + Controls.kControlListBoxListHandleTag) + self.list = List.as_List(h) self.setlist() def setlist(self): @@ -139,14 +140,6 @@ class MyDialog(FrameWork.DialogWindow): self.list.LSetDrawingMode(1) self.list.LUpdate(self.wid.GetWindowPort().visRgn) - def do_listhit(self, event): - (what, message, when, where, modifiers) = event - Qd.SetPort(self.wid) - where = Qd.GlobalToLocal(where) - print 'LISTHIT', where - if self.list.LClick(where, modifiers): - self.do_show() - def getselection(self): items = [] point = (0,0) @@ -166,21 +159,10 @@ class MyDialog(FrameWork.DialogWindow): for resid in selection: self.parent.showPICT(resid) - def do_rawupdate(self, window, event): - tp, h, rect = self.wid.GetDialogItem(MAIN_LIST) - Qd.SetPort(self.wid) - Qd.FrameRect(rect) - self.list.LUpdate(self.wid.GetWindowPort().visRgn) - - def do_activate(self, activate, event): - self.list.LActivate(activate) - def do_close(self): self.close() def do_itemhit(self, item, event): - if item == MAIN_LIST: - self.do_listhit(event) if item == MAIN_SHOW: self.do_show() diff --git a/Mac/Demo/PICTbrowse/cicnbrowse.py b/Mac/Demo/PICTbrowse/cicnbrowse.py index 8a31ccc..38e3bed 100644 --- a/Mac/Demo/PICTbrowse/cicnbrowse.py +++ b/Mac/Demo/PICTbrowse/cicnbrowse.py @@ -5,6 +5,7 @@ import EasyDialogs import Res import Qd import Win +import Controls import List import sys import struct @@ -119,11 +120,11 @@ class MyDialog(FrameWork.DialogWindow): self.id = id FrameWork.DialogWindow.open(self, ID_MAIN) self.wid.SetDialogDefaultItem(MAIN_SHOW) - tp, h, rect = self.wid.GetDialogItem(MAIN_LIST) - rect2 = rect[0]+1, rect[1]+1, rect[2]-17, rect[3]-17 # Scroll bar space - self.list = List.LNew(rect2, (0, 0, 1, len(contents)), (0,0), 0, self.wid, - 0, 1, 1, 1) self.contents = contents + self.ctl = self.wid.GetDialogItemAsControl(MAIN_LIST) + h = self.ctl.GetControlDataHandle(Controls.kControlListBoxPart, + Controls.kControlListBoxListHandleTag) + self.list = List.as_List(h) self.setlist() def setlist(self): @@ -139,13 +140,6 @@ class MyDialog(FrameWork.DialogWindow): self.list.LSetDrawingMode(1) self.list.LUpdate(self.wid.GetWindowPort().visRgn) - def do_listhit(self, event): - (what, message, when, where, modifiers) = event - Qd.SetPort(self.wid) - where = Qd.GlobalToLocal(where) - if self.list.LClick(where, modifiers): - self.do_show() - def getselection(self): items = [] point = (0,0) @@ -165,21 +159,10 @@ class MyDialog(FrameWork.DialogWindow): for resid in selection: self.parent.showCIcon(resid) - def do_rawupdate(self, window, event): - tp, h, rect = self.wid.GetDialogItem(MAIN_LIST) - Qd.SetPort(self.wid) - Qd.FrameRect(rect) - self.list.LUpdate(self.wid.GetWindowPort().visRgn) - - def do_activate(self, activate, event): - self.list.LActivate(activate) - def do_close(self): self.close() def do_itemhit(self, item, event): - if item == MAIN_LIST: - self.do_listhit(event) if item == MAIN_SHOW: self.do_show() diff --git a/Mac/Demo/PICTbrowse/oldPICTbrowse.py b/Mac/Demo/PICTbrowse/oldPICTbrowse.py new file mode 100644 index 0000000..9e9dcd5 --- /dev/null +++ b/Mac/Demo/PICTbrowse/oldPICTbrowse.py @@ -0,0 +1,165 @@ +"""browsepict - Display all "PICT" resources found""" + +import FrameWork +import EasyDialogs +import Res +import Qd +import Win +import List +import sys +import struct + +# +# Resource definitions +ID_MAIN=512 +MAIN_LIST=1 +MAIN_SHOW=2 + +# Where is the picture window? +LEFT=200 +TOP=64 + +def main(): + try: + dummy = Res.GetResource('DLOG', ID_MAIN) + except Res.Error: + try: + Res.OpenResFile("oldPICTbrowse.rsrc") + except Res.Error, arg: + EasyDialogs.Message("Cannot open PICTbrowse.rsrc: "+arg[1]) + sys.exit(1) + PICTbrowse() + +class PICTbrowse(FrameWork.Application): + def __init__(self): + # First init menus, etc. + FrameWork.Application.__init__(self) + # Next create our dialog + self.main_dialog = MyDialog(self) + # Now open the dialog + contents = self.findPICTresources() + self.main_dialog.open(ID_MAIN, contents) + # Finally, go into the event loop + self.mainloop() + + def makeusermenus(self): + self.filemenu = m = FrameWork.Menu(self.menubar, "File") + self.quititem = FrameWork.MenuItem(m, "Quit", "Q", self.quit) + + def quit(self, *args): + self._quit() + + def showPICT(self, resid): + w = PICTwindow(self) + w.open(resid) + #EasyDialogs.Message('Show PICT '+`resid`) + + def findPICTresources(self): + num = Res.CountResources('PICT') + rv = [] + for i in range(1, num+1): + Res.SetResLoad(0) + try: + r = Res.GetIndResource('PICT', i) + finally: + Res.SetResLoad(1) + id, type, name = r.GetResInfo() + rv.append(id, name) + return rv + +class PICTwindow(FrameWork.Window): + def open(self, (resid, resname)): + if not resname: + resname = '#'+`resid` + self.resid = resid + picture = Qd.GetPicture(self.resid) + # Get rect for picture + print `picture.data[:16]` + sz, t, l, b, r = struct.unpack('hhhhh', picture.data[:10]) + print 'pict:', t, l, b, r + width = r-l + height = b-t + if width < 64: width = 64 + elif width > 480: width = 480 + if height < 64: height = 64 + elif height > 320: height = 320 + bounds = (LEFT, TOP, LEFT+width, TOP+height) + print 'bounds:', bounds + + self.wid = Win.NewWindow(bounds, resname, 1, 0, -1, 1, 0) + self.wid.SetWindowPic(picture) + self.do_postopen() + +class MyDialog(FrameWork.DialogWindow): + "Main dialog window for PICTbrowse" + + def open(self, id, contents): + self.id = id + FrameWork.DialogWindow.open(self, ID_MAIN) + self.wid.SetDialogDefaultItem(MAIN_SHOW) + tp, h, rect = self.wid.GetDialogItem(MAIN_LIST) + rect2 = rect[0]+1, rect[1]+1, rect[2]-17, rect[3]-17 # Scroll bar space + self.list = List.LNew(rect2, (0, 0, 1, len(contents)), (0,0), 0, self.wid, + 0, 1, 1, 1) + self.contents = contents + self.setlist() + + def setlist(self): + self.list.LDelRow(0, 0) + self.list.LSetDrawingMode(0) + if self.contents: + self.list.LAddRow(len(self.contents), 0) + for i in range(len(self.contents)): + v = `self.contents[i][0]` + if self.contents[i][1]: + v = v + '"' + self.contents[i][1] + '"' + self.list.LSetCell(v, (0, i)) + self.list.LSetDrawingMode(1) + self.list.LUpdate(self.wid.GetWindowPort().visRgn) + + def do_listhit(self, event): + (what, message, when, where, modifiers) = event + Qd.SetPort(self.wid) + where = Qd.GlobalToLocal(where) + print 'LISTHIT', where + if self.list.LClick(where, modifiers): + self.do_show() + + def getselection(self): + items = [] + point = (0,0) + while 1: + ok, point = self.list.LGetSelect(1, point) + if not ok: + break + items.append(point[1]) + point = point[0], point[1]+1 + values = [] + for i in items: + values.append(self.contents[i]) + return values + + def do_show(self, *args): + selection = self.getselection() + for resid in selection: + self.parent.showPICT(resid) + + def do_rawupdate(self, window, event): + tp, h, rect = self.wid.GetDialogItem(MAIN_LIST) + Qd.SetPort(self.wid) + Qd.FrameRect(rect) + self.list.LUpdate(self.wid.GetWindowPort().visRgn) + + def do_activate(self, activate, event): + self.list.LActivate(activate) + + def do_close(self): + self.close() + + def do_itemhit(self, item, event): + if item == MAIN_LIST: + self.do_listhit(event) + if item == MAIN_SHOW: + self.do_show() + +main() diff --git a/Mac/Demo/PICTbrowse/oldPICTbrowse.rsrc b/Mac/Demo/PICTbrowse/oldPICTbrowse.rsrc Binary files differnew file mode 100644 index 0000000..6745d2f --- /dev/null +++ b/Mac/Demo/PICTbrowse/oldPICTbrowse.rsrc |