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

📄 opt_processors.py

📁 用python实现的邮件过滤器
💻 PY
📖 第 1 页 / 共 2 页
字号:
            edit = self.GetControl()            win32gui.SendMessage(edit, win32con.WM_SETTEXT, 0, str_val)    def OnCommand(self, wparam, lparam):        code = win32api.HIWORD(wparam)        if code==win32con.EN_CHANGE:            try:                self.UpdateValue_FromControl()                self.UpdateSlider_FromEdit()            except ValueError:                # They are typing - value may be currently invalid                pass    def Init(self):        OptionControlProcessor.Init(self)        if self.slider_id:            self.InitSlider()    def InitSlider(self):        slider = self.GetControl(self.slider_id)        # xxx - this wont be right if min <> 0 :(        assert self.min_val == 0, "sue me"        win32gui.SendMessage(slider, commctrl.TBM_SETRANGE, 0, MAKELONG(0, self.ticks))        # sigh - these values may not be right        win32gui.SendMessage(slider, commctrl.TBM_SETLINESIZE, 0, 1)        win32gui.SendMessage(slider, commctrl.TBM_SETPAGESIZE, 0, self.ticks/20)        win32gui.SendMessage(slider, commctrl.TBM_SETTICFREQ, self.ticks/10, 0)    def UpdateControl_FromValue(self):        win32gui.SendMessage(self.GetControl(), win32con.WM_SETTEXT, 0,                             str(self.GetOptionValue()))        self.UpdateSlider_FromEdit()    def UpdateSlider_FromEdit(self):        slider = self.GetControl(self.slider_id)        # done as the user is typing into the edit control, so we must not        # complain here about invalid values as it is likely to only be        # temporarily invalid until they finish.        try:            # 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 = float(self.GetOptionValue())            # Convert it to our range.            val *= float(self.ticks) / self.max_val            val = int(val)        except ValueError:            return        win32gui.SendMessage(slider, commctrl.TBM_SETPOS, 1, val)    def UpdateValue_FromControl(self):        buf_size = 100        buf = win32gui.PyMakeBuffer(buf_size)        nchars = win32gui.SendMessage(self.GetControl(), win32con.WM_GETTEXT,                                      buf_size, buf)        str_val = buf[:nchars]        val = float(str_val)        if val < self.min_val or val > self.max_edit_val:            raise ValueError, "Value must be between %d and %d" % (self.min_val, self.max_val)        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):    def __init__(self, window, control_ids,                 option, option_include_sub = None,                 use_fqn = False, name_joiner = "; "):        self.button_id = control_ids[1]        self.use_fqn = use_fqn        self.name_joiner = name_joiner        if option_include_sub:            incl_sub_sect_name, incl_sub_option_name = \                                option_include_sub.split(".")            self.option_include_sub = \                            window.config.get_option(incl_sub_sect_name,                                                      incl_sub_option_name)        else:            self.option_include_sub = None        OptionControlProcessor.__init__(self, window, control_ids, option)    def DoBrowse(self):        mgr = self.window.manager        is_multi = self.option.multiple_values_allowed()        if is_multi:            ids = self.GetOptionValue()        else:            ids = [self.GetOptionValue()]        from dialogs import FolderSelector        if self.option_include_sub:            cb_state = self.option_include_sub.get()        else:            cb_state = None # don't show it.        d = FolderSelector.FolderSelector(self.window.hwnd,                                            mgr,                                            ids,                                            single_select=not is_multi,                                            checkbox_state=cb_state)        if d.DoModal() == win32con.IDOK:            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()            return True        return False    def OnCommand(self, wparam, lparam):        id = win32api.LOWORD(wparam)        if id == self.button_id:            self.DoBrowse()    def GetPopupHelpText(self, idFrom):        if idFrom == self.button_id:            return "Displays a list from which you can select folders."        return OptionControlProcessor.GetPopupHelpText(self, idFrom)    def UpdateControl_FromValue(self):        # Set the static to folder names        mgr = self.window.manager        if self.option.multiple_values_allowed():            ids = self.GetOptionValue()        else:            ids = [self.GetOptionValue()]        names = []        for eid in ids:            if eid is not None:                try:                    folder = mgr.message_store.GetFolder(eid)                    if self.use_fqn:                        name = folder.GetFQName()                    else:                        name = folder.name                except mgr.message_store.MsgStoreException:                    name = "<unknown folder>"                names.append(name)        win32gui.SetWindowText(self.GetControl(), self.name_joiner.join(names))    def UpdateValue_FromControl(self):        pass

⌨️ 快捷键说明

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