Update of /cvsroot/spambayes/spambayes/Outlook2000/dialogs
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29379/Outlook2000/dialogs
Modified Files:
dialog_map.py opt_processors.py
Added Files:
win32struct.py
Log Message:
Add a "Notifications" tab to SpamBayes Manager for configuring notification
sounds.
--- NEW FILE: win32struct.py ---
# This module provides helper classes for various structs (currently only
# OPENFILENAME) that need to be passed to Win32 api functions as strings.
#
# The base cStruct class is a slightly modified version of an example posted
# by Telion <[EMAIL PROTECTED]> to the PythonCE mailing list.
# http://mail.python.org/pipermail/pythonce/2002-October/000204.html
import struct, array
import win32gui
class cStruct(object):
# cStruct class uses following struct information.
# (name, fs, initial_value)
#
# "name" is used for accessing value
# "fs" is format string for that value (see struct module doc)
# For lpstr, lpcstr, lpxxx, use 'P'.
# "initial_value" default value
def __init__(self, sd):
self.sd = list(sd)
self.nlst = [i[0] for i in sd]
self.fs = "".join([i[1] for i in sd])
t = [i[2] for i in sd]
self.data = struct.pack(self.fs, *t)
def __setattr__(self, name, v):
if name in ['sd', 'nlst', 'fs', 'data', 'ptr'] or name not in self.nlst:
object.__setattr__(self, name, v)
return
t = list(struct.unpack(self.fs, self.data))
i = self.nlst.index(name)
if i > -1:
t[i] = v
self.data = struct.pack(self.fs, *t)
def __getattr__(self, name):
t = struct.unpack(self.fs, self.data)
i = self.nlst.index(name)
if i > -1:
return t[i]
else:
raise AttributeError
def __str__(self):
return self.data
def dump(self): # use this to see the data
t = struct.unpack(self.fs, self.data)
ii = 0
for i in self.nlst:
print i, "=", t[ii]
ii += 1
print "fs =", self.fs
return
class OPENFILENAME(cStruct):
_struct_def = ( \
('lStructSize', 'L', 0), # size of struct (filled in by __init__)
('hwndOwner', 'P', 0),
('hInstance', 'P', 0),
('lpstrFilter', 'P', 0), # File type filter
('lpstrCustomFilter', 'P', 0),
('nMaxCustFilter', 'L', 0),
('nFilterIndex', 'L', 0),
('lpstrFile', 'P', 0), # Initial filename and filename buffer
('nMaxFile', 'L', 0), # Size of filename string (should be >= 256)
('lpstrFileTitle', 'P', 0), # (optional) base name receiving buffer
('nMaxFileTitle', 'L', 0), # max size of above
('lpstrInitialDir', 'P', 0), # (optional) initial directory
('lpstrTitle', 'P', 0), # Title of dialog
('Flags', 'L', 0),
('nFileOffset', 'H', 0),
('nFileExtension', 'H', 0),
('lpstrDefExt', 'P', 0), # default extension
('lCustData', 'l', 0),
('lpfnHook', 'P', 0),
('lpTemplateName', 'P', 0)
)
def __init__(self, max_filename_len):
cStruct.__init__(self, self._struct_def)
self.lStructSize = struct.calcsize(self.fs)
self.fn_buf = array.array("c", '\0'*max_filename_len)
self.fn_buf_addr, self.fn_buf_len = self.fn_buf.buffer_info()
self.lpstrFile = self.fn_buf_addr
self.nMaxFile = self.fn_buf_len
def setFilename(self, filename):
win32gui.PySetString(self.fn_buf_addr, filename, self.fn_buf_len - 1)
def getFilename(self):
return win32gui.PyGetString(self.fn_buf_addr)
def setTitle(self, title):
if isinstance(title, unicode):
title = title.encode("mbcs")
self.title_buf = array.array("c", title+'\0')
self.lpstrTitle = self.title_buf.buffer_info()[0]
def setInitialDir(self, initialDir):
if isinstance(initialDir, unicode):
initialDir = initialDir.encode("mbcs")
self.initialDir_buf = array.array("c", initialDir+'\0')
self.lpstrInitialDir = self.initialDir_buf.buffer_info()[0]
def setFilter(self, fileFilter):
if isinstance(fileFilter, unicode):
fileFilter = fileFilter.encode("mbcs")
fileFilter = fileFilter.replace('|', '\0') + '\0'
self.fileFilter_buf = array.array("c", fileFilter+'\0')
self.lpstrFilter = self.fileFilter_buf.buffer_info()[0]
Index: dialog_map.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/dialogs/dialog_map.py,v
retrieving revision 1.49
retrieving revision 1.50
diff -C2 -d -r1.49 -r1.50
*** dialog_map.py 18 Jan 2005 18:23:10 -0000 1.49
--- dialog_map.py 11 Feb 2005 21:05:51 -0000 1.50
***************
*** 444,448 ****
(TabProcessor, "IDC_TAB",
"""IDD_GENERAL IDD_FILTER IDD_TRAINING
! IDD_STATISTICS IDD_ADVANCED"""),
(CommandButtonProcessor, "IDC_ABOUT_BTN", ShowAbout, ()),
),
--- 444,449 ----
(TabProcessor, "IDC_TAB",
"""IDD_GENERAL IDD_FILTER IDD_TRAINING
! IDD_STATISTICS IDD_NOTIFICATIONS
! IDD_ADVANCED"""),
(CommandButtonProcessor, "IDC_ABOUT_BTN", ShowAbout, ()),
),
***************
*** 519,522 ****
--- 520,539 ----
"IDC_LAST_RESET_DATE"),
),
+ "IDD_NOTIFICATIONS" : (
+ (BoolButtonProcessor, "IDC_ENABLE_SOUNDS",
"Notification.notify_sound_enabled",
+ """IDC_HAM_SOUND IDC_BROWSE_HAM_SOUND
+ IDC_UNSURE_SOUND IDC_BROWSE_UNSURE_SOUND
+ IDC_SPAM_SOUND IDC_BROWSE_SPAM_SOUND
+ IDC_ACCUMULATE_DELAY_SLIDER
+ IDC_ACCUMULATE_DELAY_TEXT"""),
+ (FilenameProcessor, "IDC_HAM_SOUND IDC_BROWSE_HAM_SOUND",
+ "Notification.notify_ham_sound", _("Sound
Files (*.wav)|*.wav|All Files (*.*)|*.*")),
+ (FilenameProcessor, "IDC_UNSURE_SOUND IDC_BROWSE_UNSURE_SOUND",
+ "Notification.notify_unsure_sound", _("Sound
Files (*.wav)|*.wav|All Files (*.*)|*.*")),
+ (FilenameProcessor, "IDC_SPAM_SOUND IDC_BROWSE_SPAM_SOUND",
+ "Notification.notify_spam_sound", _("Sound
Files (*.wav)|*.wav|All Files (*.*)|*.*")),
+ (EditNumberProcessor, "IDC_ACCUMULATE_DELAY_TEXT
IDC_ACCUMULATE_DELAY_SLIDER",
+ "Notification.notify_accumulate_delay", 0,
30, 20, 60),
+ ),
"IDD_ADVANCED" : (
(BoolButtonProcessor, "IDC_BUT_TIMER_ENABLED",
"Filter.timer_enabled",
Index: opt_processors.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/dialogs/opt_processors.py,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** opt_processors.py 28 Oct 2004 04:29:00 -0000 1.16
--- opt_processors.py 11 Feb 2005 21:05:54 -0000 1.17
***************
*** 252,255 ****
--- 252,305 ----
self.SetOptionValue(val)
+ class FilenameProcessor(OptionControlProcessor):
+ def __init__(self, window, control_ids, option, file_filter="All
Files|*.*"):
+ self.button_id = control_ids[1]
+ self.file_filter = file_filter
+ OptionControlProcessor.__init__(self, window, control_ids, option)
+
+ def GetPopupHelpText(self, idFrom):
+ if idFrom == self.button_id:
+ return "Displays a dialog from which you can select a file."
+ return OptionControlProcessor.GetPopupHelpText(self, id)
+
+ def DoBrowse(self):
+ from win32struct import OPENFILENAME
+ ofn = OPENFILENAME(512)
+ ofn.hwndOwner = self.window.hwnd
+ ofn.setFilter(self.file_filter)
+ ofn.setTitle(_("Browse for file"))
+ def_filename = self.GetOptionValue()
+ if (len(def_filename) > 0):
+ from os.path import basename
+ ofn.setInitialDir(basename(def_filename))
+ ofn.setFilename(def_filename)
+ ofn.Flags = win32con.OFN_FILEMUSTEXIST
+ retval = win32gui.GetOpenFileName(str(ofn))
+ if (retval == win32con.IDOK):
+ self.SetOptionValue(ofn.getFilename())
+ self.UpdateControl_FromValue()
+ return True
+ return False
+
+ def OnCommand(self, wparam, lparam):
+ id = win32api.LOWORD(wparam)
+ code = win32api.HIWORD(wparam)
+ if id == self.button_id:
+ self.DoBrowse()
+ elif code==win32con.EN_CHANGE:
+ self.UpdateValue_FromControl()
+
+ def UpdateControl_FromValue(self):
+ win32gui.SendMessage(self.GetControl(), win32con.WM_SETTEXT, 0,
+ self.GetOptionValue())
+
+ def UpdateValue_FromControl(self):
+ buf_size = 256
+ buf = win32gui.PyMakeBuffer(buf_size)
+ nchars = win32gui.SendMessage(self.GetControl(), win32con.WM_GETTEXT,
+ buf_size, buf)
+ str_val = buf[:nchars]
+ self.SetOptionValue(str_val)
+
# Folder IDs, and the "include_sub" option, if applicable.
class FolderIDProcessor(OptionControlProcessor):
_______________________________________________
Spambayes-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/spambayes-checkins