[nautilus-python] examples: Format code with black



commit 871eab8af239985d0598525c2760401a95f9f160
Author: Jan Tojnar <jtojnar gmail com>
Date:   Thu Aug 11 02:59:28 2022 +0200

    examples: Format code with black
    
    So that the style is consistent.

 examples/TestExtension.py            |  7 ++---
 examples/background-image.py         | 27 ++++++++++---------
 examples/block-size-column.py        | 22 ++++++++-------
 examples/location-widget-provider.py |  3 ++-
 examples/md5sum-property-page.py     | 23 +++++++++-------
 examples/open-terminal.py            | 40 ++++++++++++++-------------
 examples/submenu.py                  | 52 +++++++++++++++++++++---------------
 examples/update-file-info-async.py   | 16 ++++++++---
 8 files changed, 113 insertions(+), 77 deletions(-)
---
diff --git a/examples/TestExtension.py b/examples/TestExtension.py
index 1137d31..4f4f047 100644
--- a/examples/TestExtension.py
+++ b/examples/TestExtension.py
@@ -1,11 +1,12 @@
 from gi.repository import Nautilus, GObject
 
+
 class ColumnExtension(GObject.GObject, Nautilus.MenuProvider):
     def __init__(self):
         pass
 
     def menu_activate_cb(self, menu, file):
-        print "menu_activate_cb",file
+        print("menu_activate_cb", file)
 
     def get_file_items(self, window, files):
         if len(files) != 1:
@@ -16,9 +17,9 @@ class ColumnExtension(GObject.GObject, Nautilus.MenuProvider):
         item = Nautilus.MenuItem(
             name="SimpleMenuExtension::Show_File_Name",
             label="Showing %s" % file.get_name(),
-            tip="Showing %s" % file.get_name()
+            tip="Showing %s" % file.get_name(),
         )
-        item.connect('activate', self.menu_activate_cb, file)
+        item.connect("activate", self.menu_activate_cb, file)
 
         return [item]
 
diff --git a/examples/background-image.py b/examples/background-image.py
index f5fca3c..20371b5 100644
--- a/examples/background-image.py
+++ b/examples/background-image.py
@@ -1,19 +1,20 @@
 from gi.repository import Nautilus, GObject, Gio
 
-SUPPORTED_FORMATS = 'image/jpeg', 'image/png'
-BACKGROUND_SCHEMA = 'org.gnome.desktop.background'
-BACKGROUND_KEY = 'picture-uri'
+SUPPORTED_FORMATS = "image/jpeg", "image/png"
+BACKGROUND_SCHEMA = "org.gnome.desktop.background"
+BACKGROUND_KEY = "picture-uri"
+
 
 class BackgroundImageExtension(GObject.GObject, Nautilus.MenuProvider):
     def __init__(self):
         self.bgsettings = Gio.Settings.new(BACKGROUND_SCHEMA)
-    
+
     def menu_activate_cb(self, menu, file):
         if file.is_gone():
             return
-        
+
         self.bgsettings[BACKGROUND_KEY] = file.get_uri()
-        
+
     def get_file_items(self, window, files):
         if len(files) != 1:
             return
@@ -26,14 +27,16 @@ class BackgroundImageExtension(GObject.GObject, Nautilus.MenuProvider):
 
         # Gnome can only handle file:
         # In the future we might want to copy the file locally
-        if file.get_uri_scheme() != 'file':
+        if file.get_uri_scheme() != "file":
             return
 
-        item = Nautilus.MenuItem(name='Nautilus::set_background_image',
-                                 label='Use as background image',
-                                 tip='Set the current image as a background image')
-        item.connect('activate', self.menu_activate_cb, file)
-        return item,
+        item = Nautilus.MenuItem(
+            name="Nautilus::set_background_image",
+            label="Use as background image",
+            tip="Set the current image as a background image",
+        )
+        item.connect("activate", self.menu_activate_cb, file)
+        return (item,)
 
     # Current versions of Nautilus will throw a warning if get_background_items
     # isn't present
diff --git a/examples/block-size-column.py b/examples/block-size-column.py
index b87dada..6ded93e 100644
--- a/examples/block-size-column.py
+++ b/examples/block-size-column.py
@@ -2,20 +2,24 @@ import os
 from urllib.parse import unquote
 from gi.repository import GObject, Nautilus
 
+
 class ColumnExtension(GObject.GObject, Nautilus.ColumnProvider, Nautilus.InfoProvider):
     def __init__(self):
         pass
-    
+
     def get_columns(self):
-        return Nautilus.Column(name="NautilusPython::block_size_column",
-                               attribute="block_size",
-                               label="Block size",
-                               description="Get the block size"),
+        column = Nautilus.Column(
+            name="NautilusPython::block_size_column",
+            attribute="block_size",
+            label="Block size",
+            description="Get the block size",
+        )
+        return (column,)
 
     def update_file_info(self, file):
-        if file.get_uri_scheme() != 'file':
+        if file.get_uri_scheme() != "file":
             return
-        
+
         filename = unquote(file.get_uri()[7:])
-        
-        file.add_string_attribute('block_size', str(os.stat(filename).st_blksize))
+
+        file.add_string_attribute("block_size", str(os.stat(filename).st_blksize))
diff --git a/examples/location-widget-provider.py b/examples/location-widget-provider.py
index e5a6cb0..84fff0d 100644
--- a/examples/location-widget-provider.py
+++ b/examples/location-widget-provider.py
@@ -1,9 +1,10 @@
 from gi.repository import Nautilus, Gtk, GObject
 
+
 class LocationProviderExample(GObject.GObject, Nautilus.LocationWidgetProvider):
     def __init__(self):
         pass
-    
+
     def get_widget(self, uri, window):
         entry = Gtk.Entry()
         entry.set_text(uri)
diff --git a/examples/md5sum-property-page.py b/examples/md5sum-property-page.py
index 1beb469..a441394 100644
--- a/examples/md5sum-property-page.py
+++ b/examples/md5sum-property-page.py
@@ -2,16 +2,17 @@ import hashlib
 from urllib.parse import unquote
 from gi.repository import Nautilus, Gtk, GObject
 
+
 class MD5SumPropertyPage(GObject.GObject, Nautilus.PropertyPageProvider):
     def __init__(self):
         pass
-    
+
     def get_property_pages(self, files):
         if len(files) != 1:
             return
-        
+
         file = files[0]
-        if file.get_uri_scheme() != 'file':
+        if file.get_uri_scheme() != "file":
             return
 
         if file.is_directory():
@@ -19,13 +20,13 @@ class MD5SumPropertyPage(GObject.GObject, Nautilus.PropertyPageProvider):
 
         filename = unquote(file.get_uri()[7:])
 
-        self.property_label = Gtk.Label('MD5Sum')
+        self.property_label = Gtk.Label("MD5Sum")
         self.property_label.show()
 
         self.hbox = Gtk.HBox(homogeneous=False, spacing=0)
         self.hbox.show()
 
-        label = Gtk.Label('MD5Sum:')
+        label = Gtk.Label("MD5Sum:")
         label.show()
         self.hbox.pack_start(label, False, False, 0)
 
@@ -35,7 +36,11 @@ class MD5SumPropertyPage(GObject.GObject, Nautilus.PropertyPageProvider):
         md5sum = hashlib.md5(filename.encode("utf-8")).hexdigest()
         self.value_label.set_text(md5sum)
         self.value_label.show()
-        
-        return Nautilus.PropertyPage(name="NautilusPython::md5_sum",
-                                     label=self.property_label, 
-                                     page=self.hbox),
+
+        return (
+            Nautilus.PropertyPage(
+                name="NautilusPython::md5_sum",
+                label=self.property_label,
+                page=self.hbox,
+            ),
+        )
diff --git a/examples/open-terminal.py b/examples/open-terminal.py
index a7d98b6..0647203 100644
--- a/examples/open-terminal.py
+++ b/examples/open-terminal.py
@@ -12,31 +12,35 @@ class OpenTerminalExtension(Nautilus.MenuProvider, GObject.GObject):
         filename = unquote(file.get_uri()[7:])
 
         os.chdir(filename)
-        os.system('gnome-terminal')
-        
+        os.system("gnome-terminal")
+
     def menu_activate_cb(self, menu, file):
         self._open_terminal(file)
-        
-    def menu_background_activate_cb(self, menu, file): 
+
+    def menu_background_activate_cb(self, menu, file):
         self._open_terminal(file)
-       
+
     def get_file_items(self, window, files):
         if len(files) != 1:
             return
-        
+
         file = files[0]
-        if not file.is_directory() or file.get_uri_scheme() != 'file':
+        if not file.is_directory() or file.get_uri_scheme() != "file":
             return
-       
-        item = Nautilus.MenuItem(name='NautilusPython::openterminal_file_item',
-                                 label='Open Terminal' ,
-                                 tip='Open Terminal In %s' % file.get_name())
-        item.connect('activate', self.menu_activate_cb, file)
-        return item,
+
+        item = Nautilus.MenuItem(
+            name="NautilusPython::openterminal_file_item",
+            label="Open Terminal",
+            tip="Open Terminal In %s" % file.get_name(),
+        )
+        item.connect("activate", self.menu_activate_cb, file)
+        return (item,)
 
     def get_background_items(self, window, file):
-        item = Nautilus.MenuItem(name='NautilusPython::openterminal_file_item2',
-                                 label='Open Terminal' ,
-                                 tip='Open Terminal In %s' % file.get_name())
-        item.connect('activate', self.menu_background_activate_cb, file)
-        return item,
+        item = Nautilus.MenuItem(
+            name="NautilusPython::openterminal_file_item2",
+            label="Open Terminal",
+            tip="Open Terminal In %s" % file.get_name(),
+        )
+        item.connect("activate", self.menu_background_activate_cb, file)
+        return (item,)
diff --git a/examples/submenu.py b/examples/submenu.py
index f3f2783..6fcadf6 100644
--- a/examples/submenu.py
+++ b/examples/submenu.py
@@ -1,38 +1,48 @@
 from gi.repository import Nautilus, GObject
 
+
 class ExampleMenuProvider(GObject.GObject, Nautilus.MenuProvider):
     def __init__(self):
         pass
-        
+
     def get_file_items(self, window, files):
-        top_menuitem = Nautilus.MenuItem(name='ExampleMenuProvider::Foo', 
-                                         label='Foo', 
-                                         tip='',
-                                         icon='')
+        top_menuitem = Nautilus.MenuItem(
+            name="ExampleMenuProvider::Foo",
+            label="Foo",
+            tip="",
+            icon="",
+        )
 
         submenu = Nautilus.Menu()
         top_menuitem.set_submenu(submenu)
 
-        sub_menuitem = Nautilus.MenuItem(name='ExampleMenuProvider::Bar', 
-                                         label='Bar', 
-                                         tip='',
-                                         icon='')
+        sub_menuitem = Nautilus.MenuItem(
+            name="ExampleMenuProvider::Bar",
+            label="Bar",
+            tip="",
+            icon="",
+        )
         submenu.append_item(sub_menuitem)
 
-        return top_menuitem,
+        return (top_menuitem,)
 
     def get_background_items(self, window, file):
         submenu = Nautilus.Menu()
-        submenu.append_item(Nautilus.MenuItem(name='ExampleMenuProvider::Bar2', 
-                                         label='Bar2', 
-                                         tip='',
-                                         icon=''))
-
-        menuitem = Nautilus.MenuItem(name='ExampleMenuProvider::Foo2', 
-                                         label='Foo2', 
-                                         tip='',
-                                         icon='')
+        submenu.append_item(
+            Nautilus.MenuItem(
+                name="ExampleMenuProvider::Bar2",
+                label="Bar2",
+                tip="",
+                icon="",
+            )
+        )
+
+        menuitem = Nautilus.MenuItem(
+            name="ExampleMenuProvider::Foo2",
+            label="Foo2",
+            tip="",
+            icon="",
+        )
         menuitem.set_submenu(submenu)
 
-        return menuitem,
-
+        return (menuitem,)
diff --git a/examples/update-file-info-async.py b/examples/update-file-info-async.py
index 332a043..613d35b 100644
--- a/examples/update-file-info-async.py
+++ b/examples/update-file-info-async.py
@@ -1,18 +1,26 @@
 from gi.repository import Nautilus, GObject
 
+
 class UpdateFileInfoAsync(GObject.GObject, Nautilus.InfoProvider):
     def __init__(self):
         self.timers = []
         pass
-    
+
     def update_file_info_full(self, provider, handle, closure, file):
         print("update_file_info_full")
-        self.timers.append(GObject.timeout_add_seconds(3, self.update_cb, provider, handle, closure))
+        self.timers.append(
+            GObject.timeout_add_seconds(3, self.update_cb, provider, handle, closure)
+        )
         return Nautilus.OperationResult.IN_PROGRESS
-        
+
     def update_cb(self, provider, handle, closure):
         print("update_cb")
-        Nautilus.info_provider_update_complete_invoke(closure, provider, handle, 
Nautilus.OperationResult.FAILED)
+        Nautilus.info_provider_update_complete_invoke(
+            closure,
+            provider,
+            handle,
+            Nautilus.OperationResult.FAILED,
+        )
 
     def cancel_update(self, provider, handle):
         print("cancel_update")


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]