如何解决在 perforce 触发器脚本中调用时不会出现 Tkinter 消息框
我正在使用我们的 Perforce 服务器的 P4Python 接口在 Python 3.8.7 中编写脚本。 在某些情况下,我不想中止更改的提交,但我需要通知用户一些信息。 为此,我想使用 tkinter 库中的消息框。 如果脚本由 perforce 执行,则不会出现消息框,但如果我在终端中运行它,它会按预期工作。
我如何解决这个问题的任何线索。
def setupConnection(cfg):
connectionError = False
exit = False
errorMsg = ""
while not exit:
try:
client = http.client.httpconnection(cfg.serverAddress)
client.connect()
except:
connectionError = True
errorMsg = "Address " + cfg.serverAddress + " is not available! Check connection or configuration."
#sys.exit("Address " + cfg.serverAddress + " is not available! Check connection or configuration.")
if not connectionError:
client.request(method=GET,url=cfg.apiAddress,headers=cfg.headers)
response = client.getresponse()
if response.status == pageNotFound404:
connectionError = True
errorMsg = "Address " + cfg.apiAddress + " is not available! Check connection or configuration."
#sys.exit("Address " + cfg.apiAddress + " is not available! Check connection or configuration.")
else:
cfg.apiGetResponse = (response.read()).decode()
exit = True
return client
if connectionError:
window = Tk()
window.eval('tk::PlaceWindow %s center' % window.winfo_toplevel())
window.withdraw()
if not messageBox.askretrycancel('Connection error',errorMsg,icon='error'):
exit = True
errorMsg = ('Please add changelist ' + cfg.changelist_ID + ' in ' + cfg.customFieldName + ' textBox of workpackage ' + cfg.workpackage_ID)
messageBox.showinfo('User action required',errorMsg)
window.destroy()
window.quit()
return None
解决方法
触发器在服务器上定义和执行。如果您在服务器上弹出一个消息框,客户端将不会看到它。相反,您的脚本应该将消息打印到标准输出;服务器将接收它并将其发送给客户端(客户端可以将其打印到控制台或将其放入 GUI 窗口或任何适合该客户端应用程序的内容)。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。