我一直在为Linux和Mac编写一个打印机驱动程序后端,它显示一个允许用户选择打印机的窗口。部分过程是用户输入用户名和密码进行认证。它在Linux上很好用。但是,我有一个奇怪的问题。当我以普通用户的身份在OSX Mountain Lion上运行脚本时,它可以正常工作。但是,当我通过CUPS后端运行它时(如用户_lp),尽管被选中,用户名和密码框突然不会接收文本。部分原因是应用程序无法在所有窗口上生成。wx.TextCtrl有蓝色轮廓,但不会在wxMac中接收文本
我已经搜索并阅读了关于Mac如何需要.app包,但即使尝试后,它也没有解决我的问题。这里是我的登录窗口类:
class LoginDialog(wx.Dialog):
def __init__(self, parent, id=-1, title="Login",
pos=wx.DefaultPosition,
size=wx.Size(350, 150),
style=wx.STAY_ON_TOP | wx.DEFAULT_FRAME_STYLE):
wx.Dialog.__init__(self, parent, id, title, pos, size, style)
wx.StaticText(self, -1, 'Please enter your CAEDM username and password.',
wx.Point(15,5))
wx.StaticText(self, -1, 'Username:', wx.Point(20, 32))
wx.StaticText(self, -1, 'Password: ', wx.Point(25, 57))
self.nameBox = wx.TextCtrl(self, 1, 'password', wx.Point(100, 30),
wx.Size(170, -1))
self.passwordBox = wx.TextCtrl(self, 2, '', wx.Point(100, 55),
wx.Size(170, -1), style=wx.TE_PASSWORD)
self.btnOK = wx.Button(self, wx.ID_OK, ' OK ', wx.Point(60, 90),
wx.DefaultSize)
self.btnOK.SetDefault()
self.btnCancel = wx.Button(self, wx.ID_CANCEL, ' Cancel ', wx.Point(160, 90),
wx.DefaultSize)
self.https_user = []
def https_bind(self):
val = self.ShowModal()
self.SetFocus()
if val == wx.ID_OK:
u = self.nameBox.GetValue()
p = self.passwordBox.GetValue()
#since the username passed by CUPS is trash, we have to re-invent it (authenticate against HTTPS)
try:
os.environ['REQUESTS_CA_BUNDLE'] = RESOURCE_DIR + '/cacert.pem'
cert = requests.get("https://lp.et.byu.edu/pa/submit.php", auth=(u, p))
print cert.status_code
if (cert.status_code == 200):
self.https_user.append(u)
self.https_user.append(p)
else:
d = ErrorDialog(self)
d.SetTitleText("Server Error")
d.SetLabelText(" Username or password incorrect.")
d.ShowModal()
self.https_bind()
except:
d = ErrorDialog(self)
d.SetTitleText("Server Error")
d.SetLabelText(" Username or password incorrect.")
d.ShowModal()
self.https_bind()
if val == wx.ID_CANCEL:
os._exit(0)
**编辑:看来这是一个Python范围的错误,因为我的整个应用程序没有捕捉关键事件。不过,它捕捉鼠标就好了。