⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dialog_map.py

📁 用python实现的邮件过滤器
💻 PY
📖 第 1 页 / 共 2 页
字号:
        os.system('start ' + win32api.GetShortPathName(py_name))def ResetConfig(window):    question = _("This will reset all configuration options to their default values\r\n\r\n" \               "It will not reset the folders you have selected, nor your\r\n" \               "training information, but all other options will be reset\r\n" \               "and SpamBayes will need to be re-enabled before it will\r\n" \               "continue filtering.\r\n\r\n" \               "Are you sure you wish to reset all options?")    flags = win32con.MB_ICONQUESTION | win32con.MB_YESNO | win32con.MB_DEFBUTTON2    if win32gui.MessageBox(window.hwnd,                           question, "SpamBayes",flags) == win32con.IDYES:        options = window.config._options        for sect in options.sections():            for opt_name in options.options_in_section(sect):                opt = options.get_option(sect, opt_name)                if not opt.no_restore():                    assert opt.is_valid(opt.default_value), \                           "Resetting '%s' to invalid default %r" % (opt.display_name(), opt.default_value)                    opt.set(opt.default_value)        window.LoadAllControls()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        # This 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.window.config, self.idd)        self.window.LoadAllControls()    def GetPopupHelpText(self, id):        dd = self.window.manager.dialog_parser.dialogs[self.idd]        return _("Displays the %s dialog") % dd.captionclass HiddenDialogCommand(DialogCommand):    def __init__(self, window, control_ids, idd):        DialogCommand.__init__(self, window, control_ids, idd)    def Init(self):        DialogCommand.Init(self)        # Hide it        win32gui.SetWindowText(self.GetControl(), "")    def OnCommand(self, wparam, lparam):        pass    def OnRButtonUp(self, wparam, lparam):        self.OnClicked(0)    def GetPopupHelpText(self, id):        return _("Nothing to see here.")class ShowWizardCommand(DialogCommand):    def OnClicked(self, id):        import win32con        existing = self.window        manager = self.window.manager        # Kill the main dialog - but first have to find it!        dlg = self.window.hwnd        while dlg:            style = win32api.GetWindowLong(dlg, win32con.GWL_STYLE)            if not style & win32con.WS_CHILD:                break            dlg = win32gui.GetParent(dlg)        else:            assert 0, "no parent!"        try:            parent = win32gui.GetParent(dlg)        except win32gui.error:            parent = 0 # no parent        win32gui.EndDialog(dlg, win32con.IDOK)        # And show the wizard.        ShowWizard(parent, manager, self.idd, use_existing_config = True)def WizardFinish(mgr, window):    print _("Wizard Done!")def WizardTrainer(mgr, config, progress):    import os, manager, train    bayes_base = os.path.join(mgr.data_directory, "$sbwiz$default_bayes_database")    mdb_base = os.path.join(mgr.data_directory, "$sbwiz$default_message_database")    fnames = []    for ext in ".pck", ".db":        fnames.append(bayes_base+ext)        fnames.append(mdb_base+ext)    config.wizard.temp_training_names = fnames    # determine which db manager to use, and create it.    ManagerClass = manager.GetStorageManagerClass()    db_manager = ManagerClass(bayes_base, mdb_base)    classifier_data = manager.ClassifierData(db_manager, mgr)    classifier_data.InitNew()    rescore = config.training.rescore    if rescore:        stages = (_("Training"), .3), (_("Saving"), .1), (_("Scoring"), .6)    else:        stages = (_("Training"), .9), (_("Saving"), .1)    progress.set_stages(stages)    train.real_trainer(classifier_data, config, mgr.message_store, progress)    # xxx - more hacks - we should pass the classifier data in.    orig_classifier_data = mgr.classifier_data    mgr.classifier_data = classifier_data # temporary    try:        progress.tick()        if rescore:            # Setup the "filter now" config to what we want.            now_config = config.filter_now            now_config.only_unread = False            now_config.only_unseen = False            now_config.action_all = False            now_config.folder_ids = config.training.ham_folder_ids + \                                    config.training.spam_folder_ids            now_config.include_sub = config.training.ham_include_sub or \                                     config.training.spam_include_sub            import filter            filter.filterer(mgr, config, progress)        bayes = classifier_data.bayes        progress.set_status(_("Completed training with %d spam and %d good messages") \                            % (bayes.nspam, bayes.nham))    finally:        mgr.wizard_classifier_data = classifier_data        mgr.classifier_data = orig_classifier_datafrom async_processor import AsyncCommandProcessorimport filter, traindialog_map = {    "IDD_MANAGER" : (        (CloseButtonProcessor,    "IDOK IDCANCEL"),        (TabProcessor,            "IDC_TAB",                                  """IDD_GENERAL IDD_FILTER IDD_TRAINING                                  IDD_STATISTICS IDD_NOTIFICATIONS                                  IDD_ADVANCED"""),        (CommandButtonProcessor,  "IDC_ABOUT_BTN", ShowAbout, ()),    ),    "IDD_GENERAL": (        (ImageProcessor,          "IDC_LOGO_GRAPHIC"),        (VersionStringProcessor,  "IDC_VERSION"),        (TrainingStatusProcessor, "IDC_TRAINING_STATUS"),        (FilterEnableProcessor,   "IDC_BUT_FILTER_ENABLE", "Filter.enabled"),        (FilterStatusProcessor,   "IDC_FILTER_STATUS"),        (ShowWizardCommand,       "IDC_BUT_WIZARD", "IDD_WIZARD"),        (CommandButtonProcessor,  "IDC_BUT_RESET", ResetConfig, ()),        ),    "IDD_FILTER_NOW" : (        (CloseButtonProcessor,    "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"),                                  """IDCANCEL IDC_BUT_UNSEEN                                  IDC_BUT_UNREAD IDC_BROWSE IDC_BUT_ACT_SCORE                                  IDC_BUT_ACT_ALL"""),    ),    "IDD_FILTER" : (        (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"),        (BoolButtonProcessor,     "IDC_MARK_SPAM_AS_READ",    "Filter.spam_mark_as_read"),        (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"),        (BoolButtonProcessor,     "IDC_MARK_UNSURE_AS_READ",    "Filter.unsure_mark_as_read"),        (FolderIDProcessor,       "IDC_FOLDER_HAM IDC_BROWSE_HAM",                                  "Filter.ham_folder_id"),        (ComboProcessor,          "IDC_ACTION_HAM", "Filter.ham_action"),        ),    "IDD_TRAINING" : (        (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"),                                  "IDOK IDCANCEL IDC_BROWSE_HAM IDC_BROWSE_SPAM " \                                  "IDC_BUT_REBUILD IDC_BUT_RESCORE"),        (BoolButtonProcessor,     "IDC_BUT_TRAIN_FROM_SPAM_FOLDER",                                  "Training.train_recovered_spam"),        (BoolButtonProcessor,     "IDC_BUT_TRAIN_TO_SPAM_FOLDER",                                  "Training.train_manual_spam"),        (ComboProcessor,          "IDC_DEL_SPAM_RS", "General.delete_as_spam_message_state",         _("not change the message,mark the message as read,mark the message as unread")),        (ComboProcessor,          "IDC_RECOVER_RS", "General.recover_from_spam_message_state",         _("not change the message,mark the message as read,mark the message as unread")),    ),    "IDD_STATISTICS" : (        (StatsProcessor,        "IDC_STATISTICS IDC_BUT_RESET_STATS " \                                "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",                                """IDC_DELAY1_TEXT IDC_DELAY1_SLIDER                                   IDC_DELAY2_TEXT IDC_DELAY2_SLIDER                                   IDC_INBOX_TIMER_ONLY"""),        (EditNumberProcessor,   "IDC_DELAY1_TEXT IDC_DELAY1_SLIDER", "Filter.timer_start_delay", 0, 10, 20, 60),        (EditNumberProcessor,   "IDC_DELAY2_TEXT IDC_DELAY2_SLIDER", "Filter.timer_interval", 0, 10, 20, 60),        (BoolButtonProcessor,   "IDC_INBOX_TIMER_ONLY", "Filter.timer_only_receive_folders"),        (CommandButtonProcessor,  "IDC_SHOW_DATA_FOLDER", ShowDataFolder, ()),        (DialogCommand,         "IDC_BUT_SHOW_DIAGNOSTICS", "IDD_DIAGNOSTIC"),        ),    "IDD_DIAGNOSTIC" : (        (BoolButtonProcessor,     "IDC_SAVE_SPAM_SCORE",    "Filter.save_spam_info"),        (IntProcessor,   "IDC_VERBOSE_LOG",  "General.verbose"),        (CommandButtonProcessor, "IDC_BUT_VIEW_LOG", ShowLog, ()),        (CloseButtonProcessor,    "IDOK IDCANCEL"),        ),    # All the wizards    "IDD_WIZARD": (        (ImageProcessor,          "IDC_WIZ_GRAPHIC"),        (CloseButtonProcessor,  "IDCANCEL"),        (wiz.ConfigureWizardProcessor, "IDC_FORWARD_BTN IDC_BACK_BTN IDC_PAGE_PLACEHOLDER",         """IDD_WIZARD_WELCOME IDD_WIZARD_FOLDERS_WATCH IDD_WIZARD_FOLDERS_REST         IDD_WIZARD_FOLDERS_TRAIN IDD_WIZARD_TRAIN         IDD_WIZARD_TRAINING_IS_IMPORTANT         IDD_WIZARD_FINISHED_UNCONFIGURED IDD_WIZARD_FINISHED_UNTRAINED         IDD_WIZARD_FINISHED_TRAINED IDD_WIZARD_FINISHED_TRAIN_LATER         """,         WizardFinish),        ),    "IDD_WIZARD_WELCOME": (        (CommandButtonProcessor,  "IDC_BUT_ABOUT", ShowAbout, ()),        (RadioButtonProcessor,    "IDC_BUT_PREPARATION", "Wizard.preparation"),        ),    "IDD_WIZARD_TRAINING_IS_IMPORTANT" : (        (BoolButtonProcessor,     "IDC_BUT_TRAIN IDC_BUT_UNTRAINED",    "Wizard.will_train_later"),        (CommandButtonProcessor,  "IDC_BUT_ABOUT", ShowTrainingDoc, ()),    ),    "IDD_WIZARD_FOLDERS_REST": (        (wiz.EditableFolderIDProcessor,"IDC_FOLDER_CERTAIN IDC_BROWSE_SPAM",                                      "Filter.spam_folder_id", "Wizard.spam_folder_name",                                      "Training.spam_folder_ids"),        (wiz.EditableFolderIDProcessor,"IDC_FOLDER_UNSURE IDC_BROWSE_UNSURE",                                      "Filter.unsure_folder_id", "Wizard.unsure_folder_name"),    ),    "IDD_WIZARD_FOLDERS_WATCH": (        (wiz.WatchFolderIDProcessor,"IDC_FOLDER_WATCH IDC_BROWSE_WATCH",                                    "Filter.watch_folder_ids"),    ),    "IDD_WIZARD_FOLDERS_TRAIN": (        (wiz.TrainFolderIDProcessor,"IDC_FOLDER_HAM IDC_BROWSE_HAM",                                    "Training.ham_folder_ids"),        (wiz.TrainFolderIDProcessor,"IDC_FOLDER_CERTAIN IDC_BROWSE_SPAM",                                    "Training.spam_folder_ids"),        (BoolButtonProcessor,     "IDC_BUT_RESCORE",    "Training.rescore"),    ),    "IDD_WIZARD_TRAIN" : (        (wiz.WizAsyncProcessor,   "IDC_PROGRESS IDC_PROGRESS_TEXT",                                  WizardTrainer, "", "",                                  ""),    ),    "IDD_WIZARD_FINISHED_UNCONFIGURED": (    ),    "IDD_WIZARD_FINISHED_UNTRAINED": (    ),    "IDD_WIZARD_FINISHED_TRAINED": (        (WizardTrainingStatusProcessor, "IDC_TRAINING_STATUS"),    ),    "IDD_WIZARD_FINISHED_TRAIN_LATER" : (    ),}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -