1995-08-31 10:50:16 -03:00
|
|
|
#
|
|
|
|
# MkDistr - User Interface.
|
|
|
|
#
|
|
|
|
# Jack Jansen, CWI, August 1995
|
|
|
|
#
|
|
|
|
# XXXX To be done (requires mods of FrameWork and toolbox interfaces too):
|
|
|
|
# - Give dialogs titles (need dlg->win conversion)
|
|
|
|
# - Place dialogs better (???)
|
|
|
|
# - <return> as <ok>
|
|
|
|
# - big box around ok button
|
|
|
|
# - window-close crashes on reopen (why?)
|
|
|
|
# - Box around lists (???)
|
|
|
|
# - Change cursor while busy (need cursor support in Qd)
|
|
|
|
#
|
2001-08-25 09:15:04 -03:00
|
|
|
from Carbon import Res
|
|
|
|
from Carbon import Dlg
|
|
|
|
from Carbon import Ctl
|
|
|
|
from Carbon import List
|
|
|
|
from Carbon import Win
|
|
|
|
from Carbon import Qd
|
1995-08-31 10:50:16 -03:00
|
|
|
from FrameWork import *
|
|
|
|
import EasyDialogs
|
|
|
|
import macfs
|
1996-08-28 11:18:58 -03:00
|
|
|
import os
|
|
|
|
import sys
|
1995-08-31 10:50:16 -03:00
|
|
|
|
|
|
|
# Resource IDs
|
|
|
|
ID_MAIN = 514
|
|
|
|
MAIN_LIST=1
|
|
|
|
MAIN_MKDISTR=2
|
|
|
|
MAIN_CHECK=3
|
|
|
|
MAIN_INCLUDE=4
|
|
|
|
MAIN_EXCLUDE=5
|
|
|
|
|
1996-08-28 11:18:58 -03:00
|
|
|
ID_INCWINDOW=515
|
|
|
|
ID_EXCWINDOW=517
|
1995-08-31 10:50:16 -03:00
|
|
|
INCEXC_DELETE=2
|
|
|
|
INCEXC_CHANGE=3
|
|
|
|
INCEXC_ADD=4
|
|
|
|
|
|
|
|
ID_INCLUDE=512
|
|
|
|
ID_EXCLUDE=513
|
1996-08-28 11:18:58 -03:00
|
|
|
DLG_OK=1 # Include for include, exclude for exclude
|
1995-08-31 10:50:16 -03:00
|
|
|
DLG_CANCEL=2
|
1996-08-28 11:18:58 -03:00
|
|
|
DLG_SRCPATH=3
|
|
|
|
DLG_DSTPATH=4 # include dialog only
|
|
|
|
DLG_EXCLUDE=5 # Exclude, include dialog only
|
1995-08-31 10:50:16 -03:00
|
|
|
|
|
|
|
ID_DTYPE=516
|
1996-08-28 11:18:58 -03:00
|
|
|
DTYPE_EXIST=1
|
|
|
|
DTYPE_NEW=2
|
|
|
|
DTYPE_CANCEL=3
|
1995-08-31 10:50:16 -03:00
|
|
|
|
|
|
|
class EditDialogWindow(DialogWindow):
|
|
|
|
"""Include/exclude editor (modeless dialog window)"""
|
|
|
|
|
1996-08-28 11:18:58 -03:00
|
|
|
def open(self, id, (src, dst), callback, cancelrv):
|
1995-08-31 10:50:16 -03:00
|
|
|
self.id = id
|
|
|
|
self.callback = callback
|
|
|
|
self.cancelrv = cancelrv
|
|
|
|
DialogWindow.open(self, id)
|
2001-02-14 13:07:04 -04:00
|
|
|
tp, h, rect = self.dlg.GetDialogItem(DLG_SRCPATH)
|
1995-08-31 10:50:16 -03:00
|
|
|
Dlg.SetDialogItemText(h, src)
|
2001-02-14 13:07:04 -04:00
|
|
|
self.dlg.SetDialogDefaultItem(DLG_OK)
|
|
|
|
self.dlg.SetDialogCancelItem(DLG_CANCEL)
|
1995-08-31 10:50:16 -03:00
|
|
|
if id == ID_INCLUDE:
|
2001-02-14 13:07:04 -04:00
|
|
|
tp, h, rect = self.dlg.GetDialogItem(DLG_DSTPATH)
|
1996-08-28 11:18:58 -03:00
|
|
|
if dst == None:
|
|
|
|
dst = ''
|
1995-08-31 10:50:16 -03:00
|
|
|
Dlg.SetDialogItemText(h, dst)
|
2001-02-14 13:07:04 -04:00
|
|
|
self.dlg.DrawDialog()
|
1995-08-31 10:50:16 -03:00
|
|
|
|
|
|
|
def do_itemhit(self, item, event):
|
1996-08-28 11:18:58 -03:00
|
|
|
if item in (DLG_OK, DLG_CANCEL, DLG_EXCLUDE):
|
1995-08-31 10:50:16 -03:00
|
|
|
self.done(item)
|
|
|
|
# else it is not interesting
|
|
|
|
|
|
|
|
def done(self, item):
|
2001-02-14 13:07:04 -04:00
|
|
|
tp, h, rect = self.dlg.GetDialogItem(DLG_SRCPATH)
|
1996-08-28 11:18:58 -03:00
|
|
|
src = Dlg.GetDialogItemText(h)
|
1995-08-31 10:50:16 -03:00
|
|
|
if item == DLG_OK:
|
|
|
|
if self.id == ID_INCLUDE:
|
2001-02-14 13:07:04 -04:00
|
|
|
tp, h, rect = self.dlg.GetDialogItem(DLG_DSTPATH)
|
1995-08-31 10:50:16 -03:00
|
|
|
dst = Dlg.GetDialogItemText(h)
|
1996-08-28 11:18:58 -03:00
|
|
|
rv = (src, dst)
|
1995-08-31 10:50:16 -03:00
|
|
|
else:
|
1996-08-28 11:18:58 -03:00
|
|
|
rv = (src, None)
|
|
|
|
elif item == DLG_EXCLUDE:
|
|
|
|
rv = (src, None)
|
1995-08-31 10:50:16 -03:00
|
|
|
else:
|
|
|
|
rv = self.cancelrv
|
|
|
|
self.close()
|
1996-08-28 11:18:58 -03:00
|
|
|
self.callback((item in (DLG_OK, DLG_EXCLUDE)), rv)
|
1995-08-31 10:50:16 -03:00
|
|
|
|
|
|
|
class ListWindow(DialogWindow):
|
|
|
|
"""A dialog window containing a list as its main item"""
|
|
|
|
|
|
|
|
def open(self, id, contents):
|
|
|
|
self.id = id
|
|
|
|
DialogWindow.open(self, id)
|
1996-08-28 11:18:58 -03:00
|
|
|
Qd.SetPort(self.wid)
|
2001-02-14 13:07:04 -04:00
|
|
|
tp, h, rect = self.dlg.GetDialogItem(MAIN_LIST)
|
1996-08-28 11:18:58 -03:00
|
|
|
self.listrect = rect
|
|
|
|
rect2 = rect[0]+1, rect[1]+1, rect[2]-16, rect[3]-16 # Scroll bar space
|
1995-08-31 10:50:16 -03:00
|
|
|
self.list = List.LNew(rect2, (0, 0, 1, len(contents)), (0,0), 0, self.wid,
|
|
|
|
0, 1, 1, 1)
|
|
|
|
self.setlist(contents)
|
|
|
|
|
|
|
|
def setlist(self, contents):
|
|
|
|
self.list.LDelRow(0, 0)
|
|
|
|
self.list.LSetDrawingMode(0)
|
|
|
|
if contents:
|
|
|
|
self.list.LAddRow(len(contents), 0)
|
|
|
|
for i in range(len(contents)):
|
|
|
|
self.list.LSetCell(contents[i], (0, i))
|
|
|
|
self.list.LSetDrawingMode(1)
|
1996-08-28 11:18:58 -03:00
|
|
|
##self.list.LUpdate(self.wid.GetWindowPort().visRgn)
|
2001-01-23 10:58:20 -04:00
|
|
|
self.wid.InvalWindowRect(self.listrect)
|
1995-08-31 10:50:16 -03:00
|
|
|
|
|
|
|
def additem(self, item):
|
|
|
|
where = self.list.LAddRow(1, 0)
|
|
|
|
self.list.LSetCell(item, (0, where))
|
|
|
|
|
|
|
|
def delgetitem(self, item):
|
|
|
|
data = self.list.LGetCell(1000, (0, item))
|
|
|
|
self.list.LDelRow(1, item)
|
|
|
|
return data
|
|
|
|
|
|
|
|
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_dclick(self.delgetselection())
|
|
|
|
|
|
|
|
def delgetselection(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 = []
|
|
|
|
items.reverse()
|
|
|
|
for i in items:
|
|
|
|
values.append(self.delgetitem(i))
|
|
|
|
return values
|
|
|
|
|
|
|
|
def do_rawupdate(self, window, event):
|
1996-04-12 13:34:58 -03:00
|
|
|
Qd.SetPort(window)
|
1996-08-28 11:18:58 -03:00
|
|
|
Qd.FrameRect(self.listrect)
|
1996-04-10 11:52:18 -03:00
|
|
|
self.list.LUpdate(self.wid.GetWindowPort().visRgn)
|
1995-08-31 10:50:16 -03:00
|
|
|
|
|
|
|
def do_close(self):
|
|
|
|
self.close()
|
|
|
|
|
|
|
|
def close(self):
|
|
|
|
del self.list
|
|
|
|
DialogWindow.close(self)
|
|
|
|
|
|
|
|
def mycb_add(self, ok, item):
|
|
|
|
if item:
|
1996-08-28 11:18:58 -03:00
|
|
|
self.additem(item[0])
|
1995-08-31 10:50:16 -03:00
|
|
|
self.cb_add(item)
|
|
|
|
|
|
|
|
class MainListWindow(ListWindow):
|
|
|
|
"""The main window"""
|
|
|
|
|
|
|
|
def open(self, id, cb_check, cb_run, cb_add):
|
|
|
|
ListWindow.open(self, id, [])
|
2001-02-14 13:07:04 -04:00
|
|
|
self.dlg.SetDialogDefaultItem(MAIN_INCLUDE)
|
1995-08-31 10:50:16 -03:00
|
|
|
self.cb_run = cb_run
|
|
|
|
self.cb_check = cb_check
|
|
|
|
self.cb_add = cb_add
|
1996-08-28 11:18:58 -03:00
|
|
|
setwatchcursor()
|
|
|
|
list = self.cb_check()
|
|
|
|
self.setlist(list)
|
|
|
|
setarrowcursor()
|
1995-08-31 10:50:16 -03:00
|
|
|
|
|
|
|
def do_itemhit(self, item, event):
|
|
|
|
if item == MAIN_LIST:
|
|
|
|
self.do_listhit(event)
|
|
|
|
if item == MAIN_MKDISTR:
|
1996-08-28 11:18:58 -03:00
|
|
|
setwatchcursor()
|
2000-05-05 20:07:43 -03:00
|
|
|
self.cb_run()
|
1996-08-28 11:18:58 -03:00
|
|
|
setarrowcursor()
|
1995-08-31 10:50:16 -03:00
|
|
|
if item == MAIN_CHECK:
|
1996-08-28 11:18:58 -03:00
|
|
|
setwatchcursor()
|
1995-08-31 10:50:16 -03:00
|
|
|
list = self.cb_check()
|
|
|
|
self.setlist(list)
|
1996-08-28 11:18:58 -03:00
|
|
|
setarrowcursor()
|
1995-08-31 10:50:16 -03:00
|
|
|
if item == MAIN_INCLUDE:
|
|
|
|
self.do_dclick(self.delgetselection())
|
|
|
|
if item == MAIN_EXCLUDE:
|
|
|
|
for i in self.delgetselection():
|
1996-08-28 11:18:58 -03:00
|
|
|
self.cb_add((i, None))
|
1995-08-31 10:50:16 -03:00
|
|
|
|
|
|
|
def do_dclick(self, list):
|
|
|
|
if not list:
|
|
|
|
list = ['']
|
|
|
|
for l in list:
|
|
|
|
w = EditDialogWindow(self.parent)
|
1996-08-28 11:18:58 -03:00
|
|
|
w.open(ID_INCLUDE, (l, None), self.mycb_add, None)
|
1995-08-31 10:50:16 -03:00
|
|
|
|
|
|
|
def mycb_add(self, ok, item):
|
|
|
|
if item:
|
|
|
|
self.cb_add(item)
|
|
|
|
|
|
|
|
class IncListWindow(ListWindow):
|
|
|
|
"""An include/exclude window"""
|
|
|
|
def open(self, id, editid, contents, cb_add, cb_del, cb_get):
|
|
|
|
ListWindow.open(self, id, contents)
|
2001-02-14 13:07:04 -04:00
|
|
|
self.dlg.SetDialogDefaultItem(INCEXC_CHANGE)
|
1995-08-31 10:50:16 -03:00
|
|
|
self.editid = editid
|
|
|
|
self.cb_add = cb_add
|
|
|
|
self.cb_del = cb_del
|
|
|
|
self.cb_get = cb_get
|
|
|
|
|
|
|
|
def do_itemhit(self, item, event):
|
|
|
|
if item == MAIN_LIST:
|
|
|
|
self.do_listhit(event)
|
|
|
|
if item == INCEXC_DELETE:
|
|
|
|
old = self.delgetselection()
|
|
|
|
for i in old:
|
|
|
|
self.cb_del(i)
|
|
|
|
if item == INCEXC_CHANGE:
|
|
|
|
self.do_dclick(self.delgetselection())
|
|
|
|
if item == INCEXC_ADD:
|
|
|
|
w = EditDialogWindow(self.parent)
|
1996-08-28 11:18:58 -03:00
|
|
|
w.open(self.editid, ('', None), self.mycb_add, None)
|
1995-08-31 10:50:16 -03:00
|
|
|
|
|
|
|
def do_dclick(self, list):
|
|
|
|
if not list:
|
|
|
|
list = ['']
|
|
|
|
for l in list:
|
|
|
|
old = self.cb_get(l)
|
|
|
|
self.cb_del(l)
|
|
|
|
w = EditDialogWindow(self.parent)
|
|
|
|
w.open(self.editid, old, self.mycb_add, old)
|
|
|
|
|
|
|
|
class MkDistrUI(Application):
|
|
|
|
def __init__(self, main):
|
|
|
|
self.main = main
|
|
|
|
Application.__init__(self)
|
|
|
|
self.mwin = MainListWindow(self)
|
|
|
|
self.mwin.open(ID_MAIN, self.main.check, self.main.run, self.main.inc.add)
|
|
|
|
self.iwin = None
|
|
|
|
self.ewin = None
|
|
|
|
|
|
|
|
def makeusermenus(self):
|
|
|
|
self.filemenu = m = Menu(self.menubar, "File")
|
|
|
|
self.includeitem = MenuItem(m, "Show Include window", "", self.showinc)
|
|
|
|
self.excludeitem = MenuItem(m, "Show Exclude window", "", self.showexc)
|
|
|
|
self.saveitem = MenuItem(m, "Save databases", "S", self.save)
|
|
|
|
self.quititem = MenuItem(m, "Quit", "Q", self.quit)
|
|
|
|
|
|
|
|
def quit(self, *args):
|
|
|
|
if self.main.is_modified():
|
|
|
|
rv = EasyDialogs.AskYesNoCancel('Database modified. Save?', -1)
|
|
|
|
if rv == -1:
|
|
|
|
return
|
|
|
|
if rv == 1:
|
|
|
|
self.main.save()
|
2000-10-12 18:22:26 -03:00
|
|
|
self._quit()
|
1995-08-31 10:50:16 -03:00
|
|
|
|
|
|
|
def save(self, *args):
|
|
|
|
self.main.save()
|
|
|
|
|
|
|
|
def showinc(self, *args):
|
|
|
|
if self.iwin:
|
|
|
|
if self._windows.has_key(self.iwin):
|
|
|
|
self.iwin.close()
|
|
|
|
del self.iwin
|
|
|
|
self.iwin = IncListWindow(self)
|
1996-08-28 11:18:58 -03:00
|
|
|
self.iwin.open(ID_INCWINDOW, ID_INCLUDE, self.main.inc.getall(), self.main.inc.add,
|
1995-08-31 10:50:16 -03:00
|
|
|
self.main.inc.delete, self.main.inc.get)
|
|
|
|
|
|
|
|
def showexc(self, *args):
|
|
|
|
if self.ewin:
|
|
|
|
if self._windows.has_key(self.ewin):
|
|
|
|
self.ewin.close()
|
|
|
|
del self.ewin
|
|
|
|
self.ewin = IncListWindow(self)
|
1996-08-28 11:18:58 -03:00
|
|
|
self.ewin.open(ID_EXCWINDOW, ID_EXCLUDE, self.main.exc.getall(), self.main.exc.add,
|
1995-08-31 10:50:16 -03:00
|
|
|
self.main.exc.delete, self.main.exc.get)
|
|
|
|
|
|
|
|
def do_about(self, id, item, window, event):
|
|
|
|
EasyDialogs.Message("Test the MkDistr user interface.")
|
|
|
|
|
|
|
|
def GetType():
|
|
|
|
"""Ask user for distribution type"""
|
|
|
|
while 1:
|
1996-08-28 11:18:58 -03:00
|
|
|
d = Dlg.GetNewDialog(ID_DTYPE, -1)
|
|
|
|
d.SetDialogDefaultItem(DTYPE_EXIST)
|
|
|
|
d.SetDialogCancelItem(DTYPE_CANCEL)
|
|
|
|
while 1:
|
|
|
|
rv = ModalDialog(None)
|
|
|
|
if rv in (DTYPE_EXIST, DTYPE_NEW, DTYPE_CANCEL):
|
|
|
|
break
|
|
|
|
del d
|
|
|
|
if rv == DTYPE_CANCEL:
|
|
|
|
sys.exit(0)
|
|
|
|
if rv == DTYPE_EXIST:
|
|
|
|
## macfs.SetFolder(':(MkDistr)')
|
|
|
|
fss, ok = macfs.StandardGetFile('TEXT')
|
|
|
|
if not ok:
|
|
|
|
sys.exit(0)
|
|
|
|
path = fss.as_pathname()
|
|
|
|
basename = os.path.split(path)[-1]
|
|
|
|
if basename[-8:] <> '.include':
|
|
|
|
EasyDialogs.Message('That is not a distribution include file')
|
|
|
|
else:
|
|
|
|
return basename[:-8]
|
|
|
|
else:
|
|
|
|
name = EasyDialogs.AskString('Distribution name:')
|
|
|
|
if name:
|
|
|
|
return name
|
|
|
|
sys.exit(0)
|
1995-08-31 10:50:16 -03:00
|
|
|
|
|
|
|
def InitUI():
|
|
|
|
"""Initialize stuff needed by UI (a resource file)"""
|
2000-06-20 18:59:25 -03:00
|
|
|
Res.FSpOpenResFile('MkDistr.rsrc', 1)
|
1995-08-31 10:50:16 -03:00
|
|
|
|
|
|
|
class _testerhelp:
|
|
|
|
def __init__(self, which):
|
|
|
|
self.which = which
|
|
|
|
|
|
|
|
def get(self):
|
|
|
|
return [self.which+'-one', self.which+'-two']
|
|
|
|
|
|
|
|
def add(self, value):
|
|
|
|
if value:
|
|
|
|
print 'ADD', self.which, value
|
|
|
|
|
|
|
|
def delete(self, value):
|
|
|
|
print 'DEL', self.which, value
|
|
|
|
|
|
|
|
class _test:
|
|
|
|
def __init__(self):
|
|
|
|
import sys
|
2000-06-20 18:59:25 -03:00
|
|
|
Res.FSpOpenResFile('MkDistr.rsrc', 1)
|
1995-08-31 10:50:16 -03:00
|
|
|
self.inc = _testerhelp('include')
|
|
|
|
self.exc = _testerhelp('exclude')
|
|
|
|
self.ui = MkDistrUI(self)
|
|
|
|
self.ui.mainloop()
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
def check(self):
|
|
|
|
print 'CHECK'
|
|
|
|
return ['rv1', 'rv2']
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
print 'RUN'
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
_test()
|