-
Notifications
You must be signed in to change notification settings - Fork 30
/
useValidator.py
54 lines (48 loc) · 2.11 KB
/
useValidator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#coding:utf-8
import wx
import os
class InputValidator(wx.PyValidator):# 创建验证器子类
def __init__(self,flag):
wx.PyValidator.__init__(self)
##传入一个校验的标志
self.flag = flag
# def ProList(self):
# self.datahandle = DataHandle(gen._filedata)
# pdata = self.datahandle.ReadData()
# proList = []
# for kid in pdata:
# proList.append(pdata[kid]["ProName"])
# return proList
def Clone(self):
return InputValidator(self.flag)
def Validate(self, win):#1 使用验证器方法
textCtrl = self.GetWindow()
text = textCtrl.GetValue()
if self.flag in ["name_t","fpath_t","logpath_t","save_path_t"] and len(text) == 0:
wx.MessageBox(u"输入不能不空",u"错误",wx.OK | wx.ICON_ERROR)
textCtrl.SetBackgroundColour("pink")
textCtrl.SetFocus()
textCtrl.Refresh()
return False
elif self.flag == "fpath_t" and not (text.upper().endswith(".EXE") or text.upper().endswith(".BAT")) :
wx.MessageBox(u"输入的程序路径必须为可执行文件",u"错误",wx.OK | wx.ICON_ERROR)
textCtrl.SetBackgroundColour("pink")
textCtrl.SetFocus()
textCtrl.Refresh()
return False
elif self.flag in ["fpath_t","logpath_t"] and not os.path.exists(text):
wx.MessageBox(u"输入的程序路径不存在",u"错误",wx.OK | wx.ICON_ERROR)
textCtrl.SetBackgroundColour("pink")
textCtrl.SetFocus()
textCtrl.Refresh()
return False
# elif self.flag == "fpath_t" and text in self.ProList():
# wx.MessageBox(u"该项目的进程已经存在",u"错误",wx.OK | wx.ICON_ERROR)
else:
textCtrl.SetBackgroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
textCtrl.Refresh()
return True
def TransferToWindow(self):
return True
def TransferFromWindow(self):
return True