使用Python和Gtk.AlertDialog

huangapple go评论54阅读模式
英文:

Using Gtk.AlertDialog with Python

问题

我尝试将一个用Python编写的旧GTK3项目移植到GTK4,但我在处理Gtk.Dialog的废弃时遇到了问题。具体来说,我找不到如何使用Python从Gtk.AlertDialog中检索用户反馈的示例。有人知道吗?我试图创建一个简单的对话框,让用户如果需要时可以中止操作。谢谢。

英文:

I'm trying to port an old GTK3 project written in Python to GTK4, and I'm having trouble with the deprecation of Gtk.Dialog. Specifically, I can find no example of how to retrieve user feedback from a Gtk.AlertDialog using Python. Does anyone know of one? I am trying to create a small dialog that would simply let the user bail out of an operation if desired. Thanks.

答案1

得分: 2

以下部分已翻译:

以下部分已翻译

def delete_query(self, widget, data):
    selected_item = self.dropdown.get_selected_item()
    item_to_delete = selected_item.iid
    dialog = Gtk.AlertDialog()
    dialog.set_message("注意")
    dialog.set_detail("您即将执行无法撤销的操作。是否继续?")
    dialog.set_modal(True)
    dialog.set_buttons(["取消", "确定"])
    dialog.choose(self, None, self.delete_perform, item_to_delete)

def delete_perform(self, source_obj, async_res, item_to_delete):
    result = source_obj.choose_finish(async_res)
    if result == 1:
        # 删除项目 item_to_delete
英文:

The following works:

def delete_query(self, widget, data):
    selected_item = self.dropdown.get_selected_item()
    item_to_delete = selected_item.iid
    dialog = Gtk.AlertDialog()
    dialog.set_message("Caution")
    dialog.set_detail("You are about to take an action that cannot be undone. Proceed?")
    dialog.set_modal(True)
    dialog.set_buttons(["Cancel", "OK"])
    dialog.choose(self, None, self.delete_perform, item_to_delete)
   
def delete_perform(self, source_obj, async_res, item_to_delete):
    result = source_obj.choose_finish(async_res)
    if result == 1:
        < delete item_to_delete >

huangapple
  • 本文由 发表于 2023年6月9日 00:16:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76433875.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定