[Spambayes-checkins] spambayes/Outlook2000/dialogs dialog_map.py,
NONE, 1.1.2.1 __init__.py, 1.2, 1.2.4.1 test_dialogs.py,
1.1.2.6, 1.1.2.7 AsyncDialog.py, 1.8, NONE DialogGlobals.py,
1.1, NONE FilterDialog.py, 1.20, NONE ManagerDialog.py, 1.10,
NONE TrainingDialog.py, 1.13, NONE
Mark Hammond
mhammond at users.sourceforge.net
Mon Aug 4 01:21:17 EDT 2003
Update of /cvsroot/spambayes/spambayes/Outlook2000/dialogs
In directory sc8-pr-cvs1:/tmp/cvs-serv8156/dialogs
Modified Files:
Tag: outlook-dialog-branch
__init__.py test_dialogs.py
Added Files:
Tag: outlook-dialog-branch
dialog_map.py
Removed Files:
Tag: outlook-dialog-branch
AsyncDialog.py DialogGlobals.py FilterDialog.py
ManagerDialog.py TrainingDialog.py
Log Message:
Brutal! Delete the old dialogs, and the manager now shows the new ones
inside outlook! Not modal though.
--- NEW FILE: dialog_map.py ---
# This module is part of the spambayes project, which is Copyright 2003
# The Python Software Foundation and is covered by the Python Software
# Foundation license.
from processors import *
from opt_processors import *
from dialogs import ShowDialog
# "dialog specific" processors:
class VersionStringProcessor(ControlProcessor):
def Init(self):
from spambayes.Version import get_version_string
import sys
version_key = "Full Description"
if hasattr(sys, "frozen"):
version_key += " Binary"
version_string = get_version_string("Outlook", version_key)
win32gui.SendMessage(self.GetControl(), win32con.WM_SETTEXT,
0, version_string)
def GetPopupHelpText(self, cid):
return "The version of SpamBayes running"
class TrainingStatusProcessor(ControlProcessor):
def Init(self):
bayes = self.window.manager.bayes
nspam = bayes.nspam
nham = bayes.nham
if nspam > 0 and nham > 0:
db_status = "Database has %d good and %d spam" % (nham, nspam)
else:
db_status = "Database has no training information"
win32gui.SendMessage(self.GetControl(), win32con.WM_SETTEXT,
0, db_status)
class FilterEnableProcessor(BoolButtonProcessor):
def UpdateValue_FromControl(self):
check = win32gui.SendMessage(self.GetControl(), win32con.BM_GETCHECK)
if check:
reason = self.window.manager.GetDisabledReason()
if reason is not None:
win32gui.SendMessage(self.GetControl(), win32con.BM_SETCHECK, 0)
raise ValueError, reason
check = not not check # force bool!
self.SetOptionValue(check)
class FilterStatusProcessor(ControlProcessor):
def OnOptionChanged(self, option):
self.Init()
def Init(self):
manager = self.window.manager
reason = manager.GetDisabledReason()
if reason is not None:
win32gui.SendMessage(self.GetControl(), win32con.WM_SETTEXT,
0, reason)
return
if not manager.config.filter.enabled:
status = "Filtering is disabled. Select 'Enable Filtering' to enable"
win32gui.SendMessage(self.GetControl(), win32con.WM_SETTEXT,
0, status)
return
# ok, enabled and working - put together the status text.
config = manager.config.filter
certain_spam_name = manager.FormatFolderNames(
[config.spam_folder_id], False)
if config.unsure_folder_id:
unsure_name = manager.FormatFolderNames(
[config.unsure_folder_id], False)
unsure_text = "unsure managed in '%s'" % (unsure_name,)
else:
unsure_text = "unsure messages untouched"
watch_names = manager.FormatFolderNames(
config.watch_folder_ids, config.watch_include_sub)
filter_status = "Watching '%s'. Spam managed in '%s', %s" \
% (watch_names,
certain_spam_name,
unsure_text)
win32gui.SendMessage(self.GetControl(), win32con.WM_SETTEXT,
0, filter_status)
def ShowAbout(mgr):
"""Displays the main SpamBayes documentation in your Web browser"""
import sys, os
if hasattr(sys, "frozen"):
# Same directory as to the executable.
fname = os.path.join(os.path.dirname(sys.argv[0]),
"about.html")
else:
# In the parent (ie, main Outlook2000) dir
fname = os.path.join(os.path.dirname(__file__),
os.pardir,
"about.html")
fname = os.path.abspath(fname)
if os.path.isfile(fname):
SetWaitCursor(1)
os.startfile(fname)
SetWaitCursor(0)
else:
print "Cant find about - fix messagebox"
self.MessageBox("Can't find about.html")
class DialogCommand(ButtonProcessor):
def __init__(self, window, control_ids, idd):
self.idd = idd
ButtonProcessor.__init__(self, window, control_ids)
def OnClicked(self, id):
parent = self.window.hwnd
# Thos form and the other form may "share" options, or at least
# depend on others. So we must save the current form back to the
# options object, display the new dialog, then reload the current
# form from the options object/
self.window.SaveAllControls()
ShowDialog(parent, self.window.manager, self.idd)
self.window.LoadAllControls()
def GetPopupHelpText(self, id):
dd = self.window.manager.dialog_parser.dialogs[self.idd]
return "Displays the %s dialog" % dd.caption
from async_processor import AsyncCommandProcessor
import filter, train
dialog_map = {
"IDD_MANAGER" : (
(CloseButtonProcessor, "IDOK IDCANCEL"),
(VersionStringProcessor, "IDC_VERSION"),
(TrainingStatusProcessor, "IDC_TRAINING_STATUS"),
(FilterEnableProcessor, "IDC_BUT_FILTER_ENABLE", "Filter.enabled"),
(FilterStatusProcessor, "IDC_FILTER_STATUS"),
(BoolButtonProcessor, "IDC_BUT_TRAIN_FROM_SPAM_FOLDER",
"Training.train_recovered_spam"),
(BoolButtonProcessor, "IDC_BUT_TRAIN_TO_SPAM_FOLDER",
"Training.train_manual_spam"),
(DialogCommand, "IDC_BUT_FILTER_NOW", "IDD_FILTER_NOW"),
(DialogCommand, "IDC_BUT_FILTER_DEFINE", "IDD_FILTER"),
(DialogCommand, "IDC_BUT_TRAIN_NOW", "IDD_TRAINING"),
(CommandButtonProcessor, "IDC_BUT_ABOUT", ShowAbout, ()),
),
"IDD_FILTER_NOW" : (
(CloseButtonProcessor, "IDOK IDCANCEL"),
(BoolButtonProcessor, "IDC_BUT_UNREAD", "Filter_Now.only_unread"),
(BoolButtonProcessor, "IDC_BUT_UNSEEN", "Filter_Now.only_unseen"),
(BoolButtonProcessor, "IDC_BUT_ACT_ALL IDC_BUT_ACT_SCORE",
"Filter_Now.action_all"),
(FolderIDProcessor, "IDC_FOLDER_NAMES IDC_BROWSE",
"Filter_Now.folder_ids",
"Filter_Now.include_sub"),
(AsyncCommandProcessor, "IDC_START IDC_PROGRESS IDC_PROGRESS_TEXT",
filter.filterer, "Start Filtering", "Stop Filtering",
"IDC_BUT_UNSEEN IDC_BUT_UNREAD IDC_BROWSE " \
"IDOK IDC_BUT_ACT_SCORE IDC_BUT_ACT_ALL"),
),
"IDD_FILTER" : (
(CloseButtonProcessor, "IDOK IDCANCEL"),
(FolderIDProcessor, "IDC_FOLDER_WATCH IDC_BROWSE_WATCH",
"Filter.watch_folder_ids",
"Filter.watch_include_sub"),
(ComboProcessor, "IDC_ACTION_CERTAIN", "Filter.spam_action"),
(FolderIDProcessor, "IDC_FOLDER_CERTAIN IDC_BROWSE_CERTAIN",
"Filter.spam_folder_id"),
(EditNumberProcessor, "IDC_EDIT_CERTAIN IDC_SLIDER_CERTAIN",
"Filter.spam_threshold"),
(FolderIDProcessor, "IDC_FOLDER_UNSURE IDC_BROWSE_UNSURE",
"Filter.unsure_folder_id"),
(EditNumberProcessor, "IDC_EDIT_UNSURE IDC_SLIDER_UNSURE",
"Filter.unsure_threshold"),
(ComboProcessor, "IDC_ACTION_UNSURE", "Filter.unsure_action"),
(DialogCommand, "IDC_BUT_FILTER_NOW", "IDD_FILTER_NOW"),
),
"IDD_TRAINING" : (
(CloseButtonProcessor, "IDOK IDCANCEL"),
(FolderIDProcessor, "IDC_STATIC_HAM IDC_BROWSE_HAM",
"Training.ham_folder_ids",
"Training.ham_include_sub"),
(FolderIDProcessor, "IDC_STATIC_SPAM IDC_BROWSE_SPAM",
"Training.spam_folder_ids",
"Training.spam_include_sub"),
(BoolButtonProcessor, "IDC_BUT_RESCORE", "Training.rescore"),
(BoolButtonProcessor, "IDC_BUT_REBUILD", "Training.rebuild"),
(AsyncCommandProcessor, "IDC_START IDC_PROGRESS IDC_PROGRESS_TEXT",
train.trainer, "Start Training", "Stop",
"IDC_BROWSE_HAM IDC_BROWSE_SPAM " \
"IDC_BUT_REBUILD IDC_BUT_RESCORE"),
)
}
Index: __init__.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/dialogs/__init__.py,v
retrieving revision 1.2
retrieving revision 1.2.4.1
diff -C2 -d -r1.2 -r1.2.4.1
*** __init__.py 19 Oct 2002 18:14:01 -0000 1.2
--- __init__.py 4 Aug 2003 07:21:15 -0000 1.2.4.1
***************
*** 1,2 ****
--- 1,19 ----
# This package defines dialog boxes used by the main
# SpamBayes Outlook 2k integration code.
+
+ def LoadDialogs(rc_file = "dialogs.rc"):
+ import os
+ from resources import rcparser
+ if not os.path.isabs(rc_file):
+ rc_file = os.path.join( os.path.dirname( rcparser.__file__ ), rc_file)
+ return rcparser.ParseDialogs(rc_file)
+
+ def ShowDialog(parent, manager, idd):
+ """Displays another dialog"""
+ if manager.dialog_parser is None:
+ manager.dialog_parser = LoadDialogs()
+ import dialog_map
+ commands = dialog_map.dialog_map[idd]
+ import dlgcore
+ dlg = dlgcore.Dialog(parent, manager, idd, commands)
+ dlg.DoModal()
Index: test_dialogs.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/dialogs/Attic/test_dialogs.py,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -C2 -d -r1.1.2.6 -r1.1.2.7
*** test_dialogs.py 4 Aug 2003 06:55:19 -0000 1.1.2.6
--- test_dialogs.py 4 Aug 2003 07:21:15 -0000 1.1.2.7
***************
*** 1,4 ****
! # Hack for testing - setup sys.path
if __name__=='__main__':
try:
import spambayes.Options
--- 1,5 ----
! # Test code for the SpamBayes dialogs.
if __name__=='__main__':
+ # Hack for testing - setup sys.path
try:
import spambayes.Options
***************
*** 7,214 ****
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), "..", "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), "..")))
-
- from processors import *
- from opt_processors import *
-
- # "dialog specific" processors:
- class VersionStringProcessor(ControlProcessor):
- def Init(self):
- from spambayes.Version import get_version_string
- import sys
- version_key = "Full Description"
- if hasattr(sys, "frozen"):
- version_key += " Binary"
- version_string = get_version_string("Outlook", version_key)
- win32gui.SendMessage(self.GetControl(), win32con.WM_SETTEXT,
- 0, version_string)
-
- def GetPopupHelpText(self, cid):
- return "The version of SpamBayes running"
-
- class TrainingStatusProcessor(ControlProcessor):
- def Init(self):
- bayes = self.window.manager.bayes
- nspam = bayes.nspam
- nham = bayes.nham
- if nspam > 0 and nham > 0:
- db_status = "Database has %d good and %d spam" % (nham, nspam)
- else:
- db_status = "Database has no training information"
- win32gui.SendMessage(self.GetControl(), win32con.WM_SETTEXT,
- 0, db_status)
-
- class FilterEnableProcessor(BoolButtonProcessor):
- def UpdateValue_FromControl(self):
- check = win32gui.SendMessage(self.GetControl(), win32con.BM_GETCHECK)
- if check:
- reason = self.window.manager.GetDisabledReason()
- if reason is not None:
- win32gui.SendMessage(self.GetControl(), win32con.BM_SETCHECK, 0)
- raise ValueError, reason
- check = not not check # force bool!
- self.SetOptionValue(check)
- class FilterStatusProcessor(ControlProcessor):
- def OnOptionChanged(self, option):
- self.Init()
-
- def Init(self):
- manager = self.window.manager
- reason = manager.GetDisabledReason()
- if reason is not None:
- win32gui.SendMessage(self.GetControl(), win32con.WM_SETTEXT,
- 0, reason)
- return
- if not manager.config.filter.enabled:
- status = "Filtering is disabled. Select 'Enable Filtering' to enable"
- win32gui.SendMessage(self.GetControl(), win32con.WM_SETTEXT,
- 0, status)
- return
- # ok, enabled and working - put together the status text.
- config = manager.config.filter
- certain_spam_name = manager.FormatFolderNames(
- [config.spam_folder_id], False)
- if config.unsure_folder_id:
- unsure_name = manager.FormatFolderNames(
- [config.unsure_folder_id], False)
- unsure_text = "unsure managed in '%s'" % (unsure_name,)
- else:
- unsure_text = "unsure messages untouched"
-
- watch_names = manager.FormatFolderNames(
- config.watch_folder_ids, config.watch_include_sub)
- filter_status = "Watching '%s'. Spam managed in '%s', %s" \
- % (watch_names,
- certain_spam_name,
- unsure_text)
- win32gui.SendMessage(self.GetControl(), win32con.WM_SETTEXT,
- 0, filter_status)
-
- def ShowAbout(mgr):
- """Displays the main SpamBayes documentation in your Web browser"""
- import sys, os
- if hasattr(sys, "frozen"):
- # Same directory as to the executable.
- fname = os.path.join(os.path.dirname(sys.argv[0]),
- "about.html")
- else:
- # In the parent (ie, main Outlook2000) dir
- fname = os.path.join(os.path.dirname(__file__),
- os.pardir,
- "about.html")
- fname = os.path.abspath(fname)
- if os.path.isfile(fname):
- SetWaitCursor(1)
- os.startfile(fname)
- SetWaitCursor(0)
- else:
- print "Cant find about - fix messagebox"
- self.MessageBox("Can't find about.html")
-
- class DialogCommand(ButtonProcessor):
- def __init__(self, window, control_ids, idd):
- self.idd = idd
- ButtonProcessor.__init__(self, window, control_ids)
- def OnClicked(self, id):
- parent = self.window.hwnd
- # Thos form and the other form may "share" options, or at least
- # depend on others. So we must save the current form back to the
- # options object, display the new dialog, then reload the current
- # form from the options object/
- self.window.SaveAllControls()
- ShowDialog(parent, self.window.manager, self.idd)
- self.window.LoadAllControls()
-
- def GetPopupHelpText(self, id):
- dd = self.window.manager.dialog_parser.dialogs[self.idd]
- return "Displays the %s dialog" % dd.caption
-
- from async_processor import AsyncCommandProcessor
-
- import filter, train
-
- dialog_map = {
- "IDD_MANAGER" : (
- (CloseButtonProcessor, "IDOK IDCANCEL"),
- (VersionStringProcessor, "IDC_VERSION"),
- (TrainingStatusProcessor, "IDC_TRAINING_STATUS"),
- (FilterEnableProcessor, "IDC_BUT_FILTER_ENABLE", "Filter.enabled"),
- (FilterStatusProcessor, "IDC_FILTER_STATUS"),
- (BoolButtonProcessor, "IDC_BUT_TRAIN_FROM_SPAM_FOLDER",
- "Training.train_recovered_spam"),
- (BoolButtonProcessor, "IDC_BUT_TRAIN_TO_SPAM_FOLDER",
- "Training.train_manual_spam"),
- (DialogCommand, "IDC_BUT_FILTER_NOW", "IDD_FILTER_NOW"),
- (DialogCommand, "IDC_BUT_FILTER_DEFINE", "IDD_FILTER"),
- (DialogCommand, "IDC_BUT_TRAIN_NOW", "IDD_TRAINING"),
- (CommandButtonProcessor, "IDC_BUT_ABOUT", ShowAbout, ()),
- ),
- "IDD_FILTER_NOW" : (
- (CloseButtonProcessor, "IDOK IDCANCEL"),
- (BoolButtonProcessor, "IDC_BUT_UNREAD", "Filter_Now.only_unread"),
- (BoolButtonProcessor, "IDC_BUT_UNSEEN", "Filter_Now.only_unseen"),
- (BoolButtonProcessor, "IDC_BUT_ACT_ALL IDC_BUT_ACT_SCORE",
- "Filter_Now.action_all"),
- (FolderIDProcessor, "IDC_FOLDER_NAMES IDC_BROWSE",
- "Filter_Now.folder_ids",
- "Filter_Now.include_sub"),
- (AsyncCommandProcessor, "IDC_START IDC_PROGRESS IDC_PROGRESS_TEXT",
- filter.filterer, "Start Filtering", "Stop Filtering",
- "IDC_BUT_UNSEEN IDC_BUT_UNREAD IDC_BROWSE " \
- "IDOK IDC_BUT_ACT_SCORE IDC_BUT_ACT_ALL"),
- ),
- "IDD_FILTER" : (
- (CloseButtonProcessor, "IDOK IDCANCEL"),
- (FolderIDProcessor, "IDC_FOLDER_WATCH IDC_BROWSE_WATCH",
- "Filter.watch_folder_ids",
- "Filter.watch_include_sub"),
- (ComboProcessor, "IDC_ACTION_CERTAIN", "Filter.spam_action"),
-
- (FolderIDProcessor, "IDC_FOLDER_CERTAIN IDC_BROWSE_CERTAIN",
- "Filter.spam_folder_id"),
- (EditNumberProcessor, "IDC_EDIT_CERTAIN IDC_SLIDER_CERTAIN",
- "Filter.spam_threshold"),
-
- (FolderIDProcessor, "IDC_FOLDER_UNSURE IDC_BROWSE_UNSURE",
- "Filter.unsure_folder_id"),
- (EditNumberProcessor, "IDC_EDIT_UNSURE IDC_SLIDER_UNSURE",
- "Filter.unsure_threshold"),
-
- (ComboProcessor, "IDC_ACTION_UNSURE", "Filter.unsure_action"),
- (DialogCommand, "IDC_BUT_FILTER_NOW", "IDD_FILTER_NOW"),
- ),
- "IDD_TRAINING" : (
- (CloseButtonProcessor, "IDOK IDCANCEL"),
- (FolderIDProcessor, "IDC_STATIC_HAM IDC_BROWSE_HAM",
- "Training.ham_folder_ids",
- "Training.ham_include_sub"),
- (FolderIDProcessor, "IDC_STATIC_SPAM IDC_BROWSE_SPAM",
- "Training.spam_folder_ids",
- "Training.spam_include_sub"),
- (BoolButtonProcessor, "IDC_BUT_RESCORE", "Training.rescore"),
- (BoolButtonProcessor, "IDC_BUT_REBUILD", "Training.rebuild"),
- (AsyncCommandProcessor, "IDC_START IDC_PROGRESS IDC_PROGRESS_TEXT",
- train.trainer, "Start Training", "Stop",
- "IDC_BROWSE_HAM IDC_BROWSE_SPAM " \
- "IDC_BUT_REBUILD IDC_BUT_RESCORE"),
- )
- }
-
- def LoadDialogs(rc_file):
- from dialogs.resources import rcparser
- if not os.path.isabs(rc_file):
- rc_file = os.path.join( os.path.dirname( rcparser.__file__ ), rc_file)
- return rcparser.ParseDialogs(rc_file)
-
- def ShowDialog(parent, manager, idd):
- """Displays another dialog"""
- commands = dialog_map[idd]
- import dlgcore
- dlg = dlgcore.Dialog(parent, manager, idd, commands)
- dlg.DoModal()
-
- if __name__=='__main__':
import manager
mgr = manager.GetManager()
! mgr.dialog_parser = LoadDialogs("dialogs.rc")
ShowDialog(0, mgr, "IDD_MANAGER")
--- 8,14 ----
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), "..", "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), "..")))
import manager
mgr = manager.GetManager()
! from dialogs import ShowDialog
ShowDialog(0, mgr, "IDD_MANAGER")
--- AsyncDialog.py DELETED ---
--- DialogGlobals.py DELETED ---
--- FilterDialog.py DELETED ---
--- ManagerDialog.py DELETED ---
--- TrainingDialog.py DELETED ---
More information about the Spambayes-checkins
mailing list