2013-05-02 38 views
0

我一直在爲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範圍的錯誤,因爲我的整個應用程序沒有捕捉關鍵事件。不過,它捕捉鼠標就好了。

回答

0

我認爲你不僅需要一個.app軟件包,但它需要作爲登錄到顯示器的同一用戶運行。這是一項安全措施,可幫助防止類似於網上誘騙的桌面操作。可能有一些辦法可以解決這個問題,比如暫時成爲那個用戶,或者通過一些系統安全API來完成訪問其他用戶的顯示,但我不知道細節。希望這會給你一些東西來搜索,但。

另一種可能性可能是將用戶界面拆分爲單獨的進程,該進程在用戶空間中根據驅動程序的某些信號啓動。然後它可以獲取憑證並將其發回給驅動程序。