gpt4 book ai didi

python - 使用 python 在 nautilus 扩展中使用 gtk

转载 作者:太空宇宙 更新时间:2023-11-03 11:35:53 26 4
gpt4 key购买 nike

下面的代码

import gtk
import nautilus
import os
def alert(message):
"""A function to debug"""
dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE, message)
dialog.run()
dialog.destroy()

class TestExtension(nautilus.MenuProvider):
def __init__(self):
pass

def get_file_items(self, window, files):
items = []
"""Called when the user selects a file in Nautilus."""
item = nautilus.MenuItem("NautilusPython::test_item", "Test", "Test")
item.connect("activate", self.menu_activate_cb, files)
items.append(item)
return items

def menu_activate_cb(self, menu, files):
"""Called when the user selects the menu."""
for name in files:
alert(name)

不产生任何消息。
然而

import easygui
import nautilus
import os

def alert(message):
"""A function to debug"""
easygui.msgbox(message)

class TestExtension(nautilus.MenuProvider):
def __init__(self):
pass

def get_file_items(self, window, files):
items = []
"""Called when the user selects a file in Nautilus."""
item = nautilus.MenuItem("NautilusPython::test_item", "Test", "Test")
item.connect("activate", self.menu_activate_cb, files)
items.append(item)
return items

def menu_activate_cb(self, menu, files):
"""Called when the user selects the menu."""
for name in files:
alert(name)

运行良好并生成请求的消息。

有人可以解释这个 - 或者更好 - 提供解决方法吗?

(更好的是,当将 alert() 调用移动到 get_file_items() 时,消息会正确显示)

最佳答案

关于nautilus mailing list Ahmad Sherif 发现了我的错误:

gtk.MessageDialog is not working with your code because the fifth argument has to be either string or None, and the variable name is of type nautilus.FileInfo, which means you need to call alert(name.get_name()) not just alert(name)
Please refer to the docs for more info about nautilus.FileInfo.

感谢 Ahmad 指出这一点。

second posting 中Ahmad 解释了如何更好地调试:

I think you could've obtained such debug info if you launched Nautilus from terminal. […]
You should quit Nautilus first (nautilus -q) then launch it (nautilus --no-desktop). If [nautilus] did [automatically] re-spawn [after quitting], you should edit /usr/share/applications/nautilus.desktop as follows (A backup of it would be a good idea):

  • Replace "X-GNOME-AutoRestart=true" with "X-GNOME-AutoRestart=false"
  • Comment this line out "X-GNOME-Autostart-Phase=Desktop" by "#" at the beginning of the line. Actually I forgot why I did this but this how my is my configuration :).
  • Add this line "AutostartCondition=GNOME /apps/nautilus/preferences/show_desktop"
  • Finally, you should restart your session, then try quitting and launching again.

Credits go to wrc1944 […] for the respawning solution.

应用 Ahmad 解释的步骤,我能够看到我的错误代码生成的错误消息。

关于python - 使用 python 在 nautilus 扩展中使用 gtk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3325772/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com