Re: In extension, context menu items are showing up in random order
- From: "Adam Plumb" <adamplumb gmail com>
- To: nautilus-list gnome org
- Subject: Re: In extension, context menu items are showing up in random order
- Date: Fri, 16 Jan 2009 16:37:35 -0500
hi everyone again,
I've generate a minimal test case for what I'm pretty sure is a bug either in nautilus or nautilus-python. I will be adding a comment to the following bug report:
http://bugzilla.gnome.org/show_bug.cgi?id=564864
Here is the file. Put it in your ~/.nautilus/python-extensions folder and then type: nautilus -q && nautilus --no-desktop to run it.
import nautilus
import random
class ExampleProvider(nautilus.MenuProvider):
def __init__(self):
pass
def get_file_items(self, window, files):
menuitems = []
for i in range(0, 5):
identifier = "Test::Item%s" % i
if (random.randint(0, 1) == 1):
menuitems.append(nautilus.MenuItem(identifier, identifier, ""))
print [menuitem.get_property("label") for menuitem in menuitems]
return menuitems
def get_background_items(self, window, files):
pass
This will produce a listing of menu items that appear in a random, incorrect order.
Adam
On Fri, Jan 16, 2009 at 12:15 PM, Adam Plumb
<adamplumb gmail com> wrote:
hi all,
I'm working on the NautilusSvn python extension (http://code.google.com/p/nautilussvn) and have an issue with our context menus.
We set up our context menus by defining a list of items, each having a condition method. When the get_file_items and get_background_items are called, we call a third method that constructs the menu and returns it to the first two methods. The construction method works like this...
menu_definition = [
{
"identifier": "NautilusSvn::Commit",
....,
"condition": self.condition_commit
},
...
]
menu = []
for item in menu_definition:
if item["condition"]():
menu.append(item)
return menu
So if the condition method returns True, the menu item is added, if False it is not added.
This seems to work, except for one problem. When the context menu is drawn, the menu items are sometimes in a seemingly random order. So if our menu list is like this: ['Item 1', 'Item 2', 'Item 3'], it will show up in the context menu like so: ['Item 3', 'Item 2', 'Item 1']. Just to see if we could narrow it down somewhat, we changed the line "if item["condition"]():" to "if True:". When we did this, the menu items all showed up in the correct order. I also tried printing out the menu list just prior to returning it, and it always shows the correct ordering.
It seems that there may be something going on with Nautilus or the nautilus-python extension that is causing this mis-ordering. But I'm not sure. I'm hoping there may be some gurus on this list that may be able to provide an insight or help.
Thanks!
Adam Plumb
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]