[Spambayes-checkins] spambayes/Outlook2000/dialogs __init__.py,
1.2.4.2, 1.2.4.3 dlgcore.py, 1.1.2.5, 1.1.2.6
Mark Hammond
mhammond at users.sourceforge.net
Tue Aug 5 02:17:21 EDT 2003
Update of /cvsroot/spambayes/spambayes/Outlook2000/dialogs
In directory sc8-pr-cvs1:/tmp/cvs-serv23289
Modified Files:
Tag: outlook-dialog-branch
__init__.py dlgcore.py
Log Message:
Break the dialog into various classes, for better reuse.
Index: __init__.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/dialogs/__init__.py,v
retrieving revision 1.2.4.2
retrieving revision 1.2.4.3
diff -C2 -d -r1.2.4.2 -r1.2.4.3
*** __init__.py 4 Aug 2003 07:39:13 -0000 1.2.4.2
--- __init__.py 5 Aug 2003 08:17:19 -0000 1.2.4.3
***************
*** 23,26 ****
import dlgcore
! dlg = dlgcore.Dialog(parent, manager, idd, commands)
dlg.DoModal()
--- 23,26 ----
import dlgcore
! dlg = dlgcore.ProcessorDialog(parent, manager, idd, commands)
dlg.DoModal()
Index: dlgcore.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/dialogs/Attic/dlgcore.py,v
retrieving revision 1.1.2.5
retrieving revision 1.1.2.6
diff -C2 -d -r1.1.2.5 -r1.1.2.6
*** dlgcore.py 4 Aug 2003 07:38:54 -0000 1.1.2.5
--- dlgcore.py 5 Aug 2003 08:17:19 -0000 1.1.2.6
***************
*** 70,103 ****
1,data)
class Dialog:
! def __init__(self, parent, manager, idd, option_handlers):
! parser = manager.dialog_parser
self.parent = parent
! self.manager = manager
! self.tt = TooltipManager(self)
self.dialog_def = parser.dialogs[idd]
self.template = self.dialog_def.createDialogTemplate()
- win32gui.InitCommonControls()
- self.hinst = win32api.GetModuleHandle(None)
- self.options = manager.options
- self.command_processors = {}
- self.processor_message_map = {} # WM_MESSAGE : [processors_who_want_it]
- self.all_processors = []
- for data in option_handlers:
- klass = data[0]
- id_names = data[1]
- rest = data[2:]
- ids = id_names.split()
- int_ids = [ parser.ids[id] for id in ids]
- instance = klass(self,int_ids, *rest)
- self.all_processors.append(instance)
- for int_id in int_ids:
- self.command_processors[int_id] = instance
- for message in instance.GetMessages():
- existing = self.processor_message_map.setdefault(message, [])
- existing.append(instance)
def _GetIDName(self, cid):
! return self.manager.dialog_parser.names.get(cid, str(cid))
def CreateWindow(self):
--- 70,85 ----
1,data)
+ # A base dialog class, that loads from resources. Has no real smarts.
class Dialog:
! def __init__(self, parent, parser, idd):
! win32gui.InitCommonControls()
! self.hinst = win32api.GetModuleHandle(None)
self.parent = parent
! self.dialog_parser = parser
self.dialog_def = parser.dialogs[idd]
self.template = self.dialog_def.createDialogTemplate()
def _GetIDName(self, cid):
! return self.dialog_parser.names.get(cid, str(cid))
def CreateWindow(self):
***************
*** 107,121 ****
return self._DoCreate(win32gui.DialogBoxIndirect)
- def OnCommandProcessorMessage(self, hwnd, msg, wparam, lparam):
- for p in self.processor_message_map[msg]:
- p.OnMessage(msg, wparam, lparam)
-
- # Called back by a processor when it changes an option. We tell all other
- # options on our page that the value changed.
- def OnOptionChanged(self, changed_by, option):
- for p in self.all_processors:
- if p is not changed_by:
- p.OnOptionChanged(option)
-
def GetMessageMap(self):
ret = {
--- 89,92 ----
***************
*** 125,147 ****
win32con.WM_INITDIALOG: self.OnInitDialog,
win32con.WM_CLOSE: self.OnClose,
- win32con.WM_HELP: self.OnHelp,
win32con.WM_DESTROY: self.OnDestroy,
- win32con.WM_LBUTTONDOWN: self.OnLButtonDown,
- win32con.WM_ACTIVATE: self.OnActivate,
}
- for key in self.processor_message_map.keys():
- if key in ret:
- print "*** WARNING: Overwriting message!!!"
- ret[key] = self.OnCommandProcessorMessage
return ret
- def _DoCreate(self, fn):
- message_map = self.GetMessageMap()
- return win32gui.DialogBoxIndirect(self.hinst, self.template, self.parent, message_map)
-
def OnInitDialog(self, hwnd, msg, wparam, lparam):
self.hwnd = hwnd
- self.LoadAllControls()
-
# centre the dialog
desktop = win32gui.GetDesktopWindow()
--- 96,105 ----
***************
*** 150,165 ****
centre_x, centre_y = win32gui.ClientToScreen( desktop, ( (dt_r-dt_l)/2, (dt_b-dt_t)/2) )
win32gui.MoveWindow(hwnd, centre_x-(r/2), centre_y-(b/2), r-l, b-t, 0)
- l,t,r,b = win32gui.GetClientRect(self.hwnd)
- self._DoSize(r-l,b-t, 1)
def OnDestroy(self, hwnd, msg, wparam, lparam):
- #print "OnDestroy"
- self.command_processors = None
- self.all_processors = None
- self.processor_message_map = None
-
- def _DoSize(self, cx, cy, repaint = 1):
pass
def OnLButtonDown(self, hwnd, msg, wparam, lparam):
self.tt.HideTooltip()
--- 108,148 ----
centre_x, centre_y = win32gui.ClientToScreen( desktop, ( (dt_r-dt_l)/2, (dt_b-dt_t)/2) )
win32gui.MoveWindow(hwnd, centre_x-(r/2), centre_y-(b/2), r-l, b-t, 0)
+ def OnCommand(self, hwnd, msg, wparam, lparam):
+ pass
+ def OnNotify(self, hwnd, msg, wparam, lparam):
+ pass
+ def OnClose(self, hwnd, msg, wparam, lparam):
+ pass
def OnDestroy(self, hwnd, msg, wparam, lparam):
pass
+ def _DoCreate(self, fn):
+ message_map = self.GetMessageMap()
+ return win32gui.DialogBoxIndirect(self.hinst, self.template, self.parent, message_map)
+ # A couple of helpers
+ def GetDlgItem(self, id):
+ if type(id)==type(''):
+ id = self.dialog_parser.ids[id]
+ return win32gui.GetDlgItem(self.hwnd, id)
+ def SetDlgItemText(self, id, text):
+ hchild = self.GetDlgItem(id)
+ win32gui.SendMessage(hchild, win32con.WM_SETTEXT, 0, text)
+
+ # A dialog with a tooltip manager
+ class TooltipDialog(Dialog):
+ def __init__(self, parent, parser, idd):
+ Dialog.__init__(self, parent, parser, idd)
+ self.tt = TooltipManager(self)
+
+ def GetMessageMap(self):
+ ret = Dialog.GetMessageMap(self)
+ ret.update( {
+ win32con.WM_HELP: self.OnHelp,
+ win32con.WM_LBUTTONDOWN: self.OnLButtonDown,
+ win32con.WM_ACTIVATE: self.OnActivate,
+ })
+ return ret
+
def OnLButtonDown(self, hwnd, msg, wparam, lparam):
self.tt.HideTooltip()
***************
*** 174,183 ****
struct.unpack(format, buf)
#print "OnHelp", cbSize, iContextType, iCtrlId, hItemHandle, dwContextID, x, y
! cp = self.command_processors.get(iCtrlId)
! tt_text = None
! if cp is not None:
! tt_text = cp.GetPopupHelpText(iCtrlId)
! else:
! print "Can not get command processor for", self._GetIDName(iCtrlId)
if tt_text:
self.tt.ShowTooltipForControl(iCtrlId, tt_text)
--- 157,161 ----
struct.unpack(format, buf)
#print "OnHelp", cbSize, iContextType, iCtrlId, hItemHandle, dwContextID, x, y
! tt_text = self.GetPopupHelpText(iCtrlId)
if tt_text:
self.tt.ShowTooltipForControl(iCtrlId, tt_text)
***************
*** 186,189 ****
--- 164,234 ----
return 1
+ def GetPopupHelpText(self, control_id):
+ return None
+
+ # A "Processor Dialog" works with Command Processors, to link SpamBayes
+ # options with control IDS, giving a "data driven" dialog.
+ class ProcessorDialog(TooltipDialog):
+ def __init__(self, parent, manager, idd, option_handlers):
+ TooltipDialog.__init__(self, parent, manager.dialog_parser, idd)
+ parser = manager.dialog_parser
+ self.manager = manager
+ self.options = manager.options
+ self.command_processors = {}
+ self.processor_message_map = {} # WM_MESSAGE : [processors_who_want_it]
+ self.all_processors = []
+ for data in option_handlers:
+ klass = data[0]
+ id_names = data[1]
+ rest = data[2:]
+ ids = id_names.split()
+ int_ids = [ parser.ids[id] for id in ids]
+ instance = klass(self,int_ids, *rest)
+ self.all_processors.append(instance)
+ for int_id in int_ids:
+ self.command_processors[int_id] = instance
+ for message in instance.GetMessages():
+ existing = self.processor_message_map.setdefault(message, [])
+ existing.append(instance)
+
+ def GetMessageMap(self):
+ ret = TooltipDialog.GetMessageMap(self)
+ for key in self.processor_message_map.keys():
+ if key in ret:
+ print "*** WARNING: Overwriting message!!!"
+ ret[key] = self.OnCommandProcessorMessage
+ return ret
+
+ def OnInitDialog(self, hwnd, msg, wparam, lparam):
+ TooltipDialog.OnInitDialog(self, hwnd, msg, wparam, lparam)
+ self.LoadAllControls()
+
+ def GetPopupHelpText(self, iCtrlId):
+ cp = self.command_processors.get(iCtrlId)
+ tt_text = None
+ if cp is not None:
+ return cp.GetPopupHelpText(iCtrlId)
+
+ print "Can not get command processor for", self._GetIDName(iCtrlId)
+ return None
+
+ def OnCommandProcessorMessage(self, hwnd, msg, wparam, lparam):
+ for p in self.processor_message_map[msg]:
+ p.OnMessage(msg, wparam, lparam)
+
+ # Called back by a processor when it changes an option. We tell all other
+ # options on our page that the value changed.
+ def OnOptionChanged(self, changed_by, option):
+ for p in self.all_processors:
+ if p is not changed_by:
+ p.OnOptionChanged(option)
+
+
+ def OnDestroy(self, hwnd, msg, wparam, lparam):
+ #print "OnDestroy"
+ self.command_processors = None
+ self.all_processors = None
+ self.processor_message_map = None
+
def LoadAllControls(self):
for p in self.all_processors:
***************
*** 208,211 ****
--- 253,258 ----
def OnClose(self, hwnd, msg, wparam, lparam):
+ if TooltipDialog.OnClose(self, hwnd, msg, wparam, lparam):
+ return 1
#print "OnClose"
if not self.SaveAllControls():
***************
*** 213,225 ****
win32gui.EndDialog(hwnd, 0)
- def OnSize(self, hwnd, msg, wparam, lparam):
- x = win32api.LOWORD(lparam)
- y = win32api.HIWORD(lparam)
- self._DoSize(x,y)
- return 1
-
def OnNotify(self, hwnd, msg, wparam, lparam):
#print "OnNotify", hwnd, msg, wparam, lparam
# Parse the NMHDR
format = "iii"
buf = win32gui.PyMakeBuffer(struct.calcsize(format), lparam)
--- 260,267 ----
win32gui.EndDialog(hwnd, 0)
def OnNotify(self, hwnd, msg, wparam, lparam):
#print "OnNotify", hwnd, msg, wparam, lparam
# Parse the NMHDR
+ TooltipDialog.OnNotify(self, hwnd, msg, wparam, lparam)
format = "iii"
buf = win32gui.PyMakeBuffer(struct.calcsize(format), lparam)
***************
*** 234,238 ****
def OnCommand(self, hwnd, msg, wparam, lparam):
! self.tt.HideTooltip()
id = win32api.LOWORD(wparam)
handler = self.command_processors.get(id)
--- 276,280 ----
def OnCommand(self, hwnd, msg, wparam, lparam):
! TooltipDialog.OnCommand(self, hwnd, msg, wparam, lparam)
id = win32api.LOWORD(wparam)
handler = self.command_processors.get(id)
More information about the Spambayes-checkins
mailing list