wx.TextCtrl有蓝色轮廓但不会在wxMac中接收文本

时间:2013-05-02 18:30:56

标签: python cocoa wxpython wxwidgets osx-mountain-lion

我一直在为Linux和Mac编写一个打印机驱动程序后端,它显示一个允许用户选择打印机的窗口。部分过程是用户输入用户名和密码进行身份验证。这一切在Linux上运行良好。但是,我有一个奇怪的问题。当我作为普通用户在OSX Mountain Lion上运行脚本时,它工作正常。但是,当我通过CUPS后端(作为用户_lp)运行它时,尽管被选中,但用户名和密码框突然不会接收文本。部分原因是应用程序不会在所有窗口之上生成。

我已经搜索并了解了Macs如何需要.app软件包,但即使尝试过,它也无法解决我的问题。这是我的LoginWindow类:

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范围的错误,因为我的整个应用程序都没有捕获关键事件。然而,它捕获鼠标就好了。

1 个答案:

答案 0 :(得分:0)

我认为您不仅需要.app软件包,还需要以登录到显示器的同一用户身份运行。这是一种安全措施,可帮助防止桌面等同于网络钓鱼。可能有某种方法可以解决这个问题,例如暂时成为该用户,或者可能通过一些系统安全API来完成,这些API允许进程完全访问另一个用户的显示,但我不知道细节。希望这会给你一些搜索的东西。

另一种可能性是将UI拆分为一个单独的进程,该进程在驱动程序发出一些信号时在用户空间中启动。然后它可以获取凭据并将它们发送回驱动程序。