desktop icon indicating copy to clipboard operation
desktop copied to clipboard

Compatibility with older python3-nautilus

Open nteodosio opened this issue 3 years ago • 5 comments
trafficstars

Quoting from devhelp (sorry, couldn't find a web document to link to), migrating Nautilus section:

The get_file_items, get_file_items_full, get_background_items a get_background_items_full methods of Nautilus.MenuProvider no longer take the window argument. Remove it from your implementations. If you need to keep supporting older versions of Nautilus, you can use variadic arguments:

  def get_file_items(self, *args):
      # `args` will be `[files: List[Nautilus.FileInfo]]` in Nautilus 4.0 API,
      # and `[window: Gtk.Widget, files: List[Nautilus.FileInfo]]` in Nautilus 3.0 API.
      files = args[-1]

nteodosio avatar Aug 26 '22 18:08 nteodosio

Using this patch will not generate the menu because the API is expecting one parameter, a list of files.

I don't think it would be wise to update the extension for the new API because Nautilus 43 just entered rc, and it would break Nautilus <=42

@jtojnar in Nautilus, we changed the pkgconfig name and directory (extensions-4 vs extensions-3.0). Does it make sense to do the same for nautilus-python. That way, we could have two versions of the extension co-exist.

edit: I saw that using *args was actually in the migration guide that @jtojnar wrote, but it doesn't work for me. I still think that separating the extensions seems the cleanest from my perspective.

coreyberla avatar Sep 05 '22 03:09 coreyberla

@coreyberla Just tested the following patch with Nautilus 43.beta.1 again and it still works for me (although Nautilus appears to call get_file_items more times than necessary and even when no files are selected).

--- a/examples/submenu.py
+++ b/examples/submenu.py
@@ -5,14 +5,16 @@ from typing import List
 class ExampleMenuProvider(GObject.GObject, Nautilus.MenuProvider):
     def get_file_items(
         self,
-        files: List[Nautilus.FileInfo],
+        *args,
     ) -> List[Nautilus.MenuItem]:
+        files = args[-1]
         top_menuitem = Nautilus.MenuItem(
             name="ExampleMenuProvider::Foo",
             label="Foo",
             tip="",
             icon="",
         )
+        print(files)
 
         submenu = Nautilus.Menu()
         top_menuitem.set_submenu(submenu)

As for changing the extension directory, I considered it. But given that many extensions will not require any changes and those that do will fail without affecting Nautilus (as far as I could see when testing random scripts), I did not see a point to it.

jtojnar avatar Sep 05 '22 09:09 jtojnar

@jtojnar you're 100% correct. I think I had two versions of the nextcloud extension running during my test which caused the confusion. Yes, this patch works. And very good point that you are requiring Nautilus >=43 on the new nautilus-python, so my concern is not an issue.

This patch looks good.

coreyberla avatar Sep 05 '22 13:09 coreyberla

Codecov Report

Merging #4870 (1a7395e) into master (63fb2d3) will increase coverage by 0.02%. The diff coverage is n/a.

:exclamation: Current head 1a7395e differs from pull request most recent head 6ad8c4f. Consider uploading reports for the commit 6ad8c4f to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4870      +/-   ##
==========================================
+ Coverage   57.17%   57.20%   +0.02%     
==========================================
  Files         138      138              
  Lines       17136    17136              
==========================================
+ Hits         9798     9802       +4     
+ Misses       7338     7334       -4     
Impacted Files Coverage Δ
src/libsync/propagatedownload.cpp 65.18% <0.00%> (+0.29%) :arrow_up:
src/libsync/vfs/cfapi/cfapiwrapper.cpp 74.65% <0.00%> (+0.45%) :arrow_up:

codecov[bot] avatar Sep 10 '22 19:09 codecov[bot]

AppImage file: nextcloud-PR-4870-6ad8c4f2c6305afce36bb46189c081d11337b908-x86_64.AppImage

To test this change/fix you can simply download above AppImage file and test it.

Please make sure to quit your existing Nextcloud app and backup your data.

nextcloud-desktop-bot avatar Sep 10 '22 19:09 nextcloud-desktop-bot

Was this closed intentionally? By the way the docs are online now: https://gnome.pages.gitlab.gnome.org/nautilus-python/nautilus-python-migrating-to-4.html

jtojnar avatar Sep 28 '22 18:09 jtojnar

Oh Jeez, no it was unintentional, sorry!

nteodosio avatar Sep 28 '22 19:09 nteodosio

Also the commit name should probably be “Fix compatibility with newer nautilus-python”.

jtojnar avatar Sep 28 '22 19:09 jtojnar

/rebase

claucambra avatar Oct 25 '22 10:10 claucambra

Since the head repository has been deleted we can no longer merge this PR :(

claucambra avatar Oct 25 '22 10:10 claucambra