[Spambayes-checkins] spambayes/Outlook2000/dialogs dlgcore.py,
1.1.2.2, 1.1.2.3 opt_processors.py, 1.1.2.1,
1.1.2.2 processors.py, 1.1.2.2, 1.1.2.3 test_dialogs.py,
1.1.2.3, 1.1.2.4
Mark Hammond
mhammond at users.sourceforge.net
Sun Aug 3 23:20:45 EDT 2003
Update of /cvsroot/spambayes/spambayes/Outlook2000/dialogs
In directory sc8-pr-cvs1:/tmp/cvs-serv24720
Modified Files:
Tag: outlook-dialog-branch
dlgcore.py opt_processors.py processors.py test_dialogs.py
Log Message:
Back off from having each processor keep a copy of the value in self.value.
This made is very difficult to make controls "depend" on each other.
Added "enable filtering" (which uses the same smarts as the trunk) and
2 status processors.
Index: dlgcore.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/dialogs/Attic/dlgcore.py,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -d -r1.1.2.2 -r1.1.2.3
*** dlgcore.py 4 Aug 2003 04:09:18 -0000 1.1.2.2
--- dlgcore.py 4 Aug 2003 05:20:43 -0000 1.1.2.3
***************
*** 111,114 ****
--- 111,121 ----
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 = {
***************
*** 186,190 ****
for p in self.all_processors:
try:
! p.Done(True)
except ValueError, why:
mb_flags = win32con.MB_ICONEXCLAMATION | win32con.MB_OK
--- 193,197 ----
for p in self.all_processors:
try:
! p.Done()
except ValueError, why:
mb_flags = win32con.MB_ICONEXCLAMATION | win32con.MB_OK
Index: opt_processors.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/dialogs/Attic/opt_processors.py,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -d -r1.1.2.1 -r1.1.2.2
*** opt_processors.py 4 Aug 2003 01:15:47 -0000 1.1.2.1
--- opt_processors.py 4 Aug 2003 05:20:43 -0000 1.1.2.2
***************
*** 23,27 ****
else:
self.option = None
- self.value = None
def GetPopupHelpText(self, idFrom):
--- 23,26 ----
***************
*** 29,52 ****
# We override Init, and break it into 2 steps.
- # - Load option into self.value
- # - set the control from self.value.
def Init(self):
- self.LoadOptionValue()
self.UpdateControl_FromValue()
! # We override Done into 2 similar steps
! # - Update self.value from the current contents of the control.
! # - Write self.value back to the option.
! def Done(self, saving):
! if saving:
! self.UpdateValue_FromControl()
! self.StoreOptionValue()
! def LoadOptionValue(self):
! self.value = self.option.get()
! def StoreOptionValue(self):
! print "Setting", self.option.name, "to", self.value
! self.option.set(self.value)
# Only sub-classes know how to update their controls from the value.
--- 28,49 ----
# We override Init, and break it into 2 steps.
def Init(self):
self.UpdateControl_FromValue()
! def Done(self):
! self.UpdateValue_FromControl()
! def NotifyOptionChanged(self, option = None):
! if option is None:
! option = self.option
! self.window.OnOptionChanged(self, option)
! def SetOptionValue(self, value, option = None):
! if option is None:
! option = self.option
! print "Setting option '%s' (%s) -> %s" % \
! (option.display_name(), option.name, value)
! option.set(value)
! self.NotifyOptionChanged(option)
# Only sub-classes know how to update their controls from the value.
***************
*** 56,60 ****
raise NotImplementedError
! # "Bool" buttons are simple - just toggle self.value on the click.
# (Little more complex to handle "radio buttons" that are also boolean
# where we must "uncheck" the other button.
--- 53,57 ----
raise NotImplementedError
! # "Bool" buttons are simple - just toggle the value on the click.
# (Little more complex to handle "radio buttons" that are also boolean
# where we must "uncheck" the other button.
***************
*** 65,75 ****
self.UpdateValue_FromControl()
def UpdateControl_FromValue(self):
! win32gui.SendMessage(self.GetControl(), win32con.BM_SETCHECK, self.value)
for other in self.other_ids:
! win32gui.SendMessage(self.GetControl(other), win32con.BM_SETCHECK, not self.value)
def UpdateValue_FromControl(self):
check = win32gui.SendMessage(self.GetControl(), win32con.BM_GETCHECK)
check = not not check # force bool!
! self.value = check
# A "Combo" processor, that loads valid strings from the option.
--- 62,73 ----
self.UpdateValue_FromControl()
def UpdateControl_FromValue(self):
! value = self.option.get()
! win32gui.SendMessage(self.GetControl(), win32con.BM_SETCHECK, value)
for other in self.other_ids:
! win32gui.SendMessage(self.GetControl(other), win32con.BM_SETCHECK, not value)
def UpdateValue_FromControl(self):
check = win32gui.SendMessage(self.GetControl(), win32con.BM_GETCHECK)
check = not not check # force bool!
! self.SetOptionValue(check)
# A "Combo" processor, that loads valid strings from the option.
***************
*** 79,85 ****
combo = self.GetControl()
index = sel_index = 0
for s in self.option.valid_input():
win32gui.SendMessage(combo, win32con.CB_ADDSTRING, 0, s)
! if self.value.startswith(s):
sel_index = index
index += 1
--- 77,84 ----
combo = self.GetControl()
index = sel_index = 0
+ value = self.option.get()
for s in self.option.valid_input():
win32gui.SendMessage(combo, win32con.CB_ADDSTRING, 0, s)
! if value.startswith(s):
sel_index = index
index += 1
***************
*** 93,98 ****
win32gui.SendMessage(combo, win32con.CB_GETLBTEXT, sel, buffer)
# Trim the \0 from the end.
! self.value = buffer.tostring()[:-1]
! print "Combo gave me", self.value
class EditNumberProcessor(OptionControlProcessor):
--- 92,96 ----
win32gui.SendMessage(combo, win32con.CB_GETLBTEXT, sel, buffer)
# Trim the \0 from the end.
! self.SetOptionValue(buffer.tostring()[:-1])
class EditNumberProcessor(OptionControlProcessor):
***************
*** 142,146 ****
def UpdateControl_FromValue(self):
! win32gui.SendMessage(self.GetControl(), win32con.WM_SETTEXT, 0, str(self.value))
self.UpdateSlider_FromEdit()
--- 140,144 ----
def UpdateControl_FromValue(self):
! win32gui.SendMessage(self.GetControl(), win32con.WM_SETTEXT, 0, str(self.option.get()))
self.UpdateSlider_FromEdit()
***************
*** 150,154 ****
# Get as float so we dont fail should the .0 be there, but
# then convert to int as the slider only works with ints
! val = int(float(self.value))
except ValueError:
return
--- 148,152 ----
# Get as float so we dont fail should the .0 be there, but
# then convert to int as the slider only works with ints
! val = int(float(self.option.get()))
except ValueError:
return
***************
*** 164,168 ****
if val < 0 or val > 100:
raise ValueError, "Value must be between 0 and 100"
! self.value = val
# Folder IDs, and the "include_sub" option, if applicable.
--- 162,166 ----
if val < 0 or val > 100:
raise ValueError, "Value must be between 0 and 100"
! self.SetOptionValue(val)
# Folder IDs, and the "include_sub" option, if applicable.
***************
*** 181,194 ****
OptionControlProcessor.__init__(self, window, control_ids, option)
- def LoadOptionValue(self):
- self.value = self.option.get()
- if self.option_include_sub:
- self.value_include_sub = self.option_include_sub.get()
-
- def StoreOptionValue(self):
- self.option.set(self.value)
- if self.option_include_sub:
- self.option_include_sub.set(self.value_include_sub)
-
def OnCommand(self, wparam, lparam):
mgr = self.window.manager
--- 179,182 ----
***************
*** 197,206 ****
is_multi = self.option.multiple_values_allowed()
if is_multi:
! ids = self.value
else:
! ids = [self.value]
from dialogs import FolderSelector
if self.option_include_sub:
! cb_state = self.value_include_sub
else:
cb_state = None # don't show it.
--- 185,194 ----
is_multi = self.option.multiple_values_allowed()
if is_multi:
! ids = self.option.get()
else:
! ids = [self.optin.get()]
from dialogs import FolderSelector
if self.option_include_sub:
! cb_state = self.option_include_sub.get()
else:
cb_state = None # don't show it.
***************
*** 212,220 ****
ids, include_sub = d.GetSelectedIDs()
if is_multi:
! self.value = ids
else:
! self.value = ids[0]
if self.option_include_sub:
! self.value_include_sub = include_sub
self.UpdateControl_FromValue()
--- 200,208 ----
ids, include_sub = d.GetSelectedIDs()
if is_multi:
! self.SetOptionValue(ids)
else:
! self.SetOptionValue(ids[0])
if self.option_include_sub:
! self.SetOptionValue(include_sub, self.option_include_sub)
self.UpdateControl_FromValue()
***************
*** 228,234 ****
mgr = self.window.manager
if self.option.multiple_values_allowed():
! ids = self.value
else:
! ids = [self.value]
names = []
for eid in ids:
--- 216,222 ----
mgr = self.window.manager
if self.option.multiple_values_allowed():
! ids = self.option.get()
else:
! ids = [self.option.get()]
names = []
for eid in ids:
***************
*** 242,246 ****
def UpdateValue_FromControl(self):
- # We only update our self.value via the dialog, so
- # no need to copy control value to self.value.
pass
--- 230,232 ----
Index: processors.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/dialogs/Attic/processors.py,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -d -r1.1.2.2 -r1.1.2.3
*** processors.py 4 Aug 2003 04:09:18 -0000 1.1.2.2
--- processors.py 4 Aug 2003 05:20:43 -0000 1.1.2.3
***************
*** 19,23 ****
def Init(self):
pass
! def Done(self, saving):
pass
def GetControl(self, control_id = None):
--- 19,23 ----
def Init(self):
pass
! def Done(self):
pass
def GetControl(self, control_id = None):
***************
*** 34,37 ****
--- 34,39 ----
def OnMessage(self, msg, wparam, lparam):
raise RuntimeError, "I don't hook any messages, so I shouldn't be called"
+ def OnOptionChanged(self, option):
+ pass
class ButtonProcessor(ControlProcessor):
Index: test_dialogs.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/dialogs/Attic/test_dialogs.py,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -C2 -d -r1.1.2.3 -r1.1.2.4
*** test_dialogs.py 4 Aug 2003 04:09:18 -0000 1.1.2.3
--- test_dialogs.py 4 Aug 2003 05:20:43 -0000 1.1.2.4
***************
*** 26,29 ****
--- 26,87 ----
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:
+ 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, status)
+ 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"""
***************
*** 83,86 ****
--- 141,147 ----
(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"),
More information about the Spambayes-checkins
mailing list