Example #1
0
    def get_columns(self):
        """
        Return all the columns we support.

        """

        return (
            Nemo.Column(
                name="RabbitVCS::status_column",
                attribute="status",
                label=_("RVCS Status"),
                description=""
            ),
            Nemo.Column(
                name="RabbitVCS::revision_column",
                attribute="revision",
                label=_("RVCS Revision"),
                description=""
            ),
            Nemo.Column(
                name="RabbitVCS::author_column",
                attribute="author",
                label=_("RVCS Author"),
                description=""
            ),
            Nemo.Column(
                name="RabbitVCS::age_column",
                attribute="age",
                label=_("RVCS Age"),
                description=""
            )
        )
Example #2
0
 def get_file_items(self, window, files):
     """ Tell nemo whether and when to show the menu """
     if len(files) == 0:
         return
     myfile = files[0]
     if not self.is_valid_file(myfile):
         return
     item1 = Nemo.MenuItem(
         name='Nemo::gnupg_scripts_encrypt',
         label=gettext.dgettext('gnupg-scripts',
                                'Encrypt').decode('utf-8', 'replace'),
         tip=gettext.dgettext('gnupg-scripts',
                              'Encrypt the file(s) with GnuPG').decode(
                                  'utf-8', 'replace'),
         icon="gnupg-scripts-encrypt")
     item1.connect('activate', self.menu1_activate_cb, files)
     item2 = Nemo.MenuItem(
         name='Nemo::gnupg_scripts_sign',
         label=gettext.dgettext('gnupg-scripts',
                                'Sign').decode('utf-8', 'replace'),
         tip=gettext.dgettext(
             'gnupg-scripts',
             'Signs the selected file with a detached signature').decode(
                 'utf-8', 'replace'),
         icon="gnupg-scripts-sign")
     item2.connect('activate', self.menu2_activate_cb, files)
     return item1, item2,
    def get_file_items(self, window, files):

        """Ensure there are reachable devices"""
        try:
            devices = self.get_reachable_devices()
        except Exception as e:
            raise Exception("Error while getting reachable devices")

        """if there is no reacheable devices don't show this on context menu"""
        if not devices:
            return

        """Ensure that user only select files"""
        for file in files:
            if file.get_uri_scheme() != 'file' or file.is_directory() and os.path.isfile(file):
                return

        self.setup_gettext()
        """If user only select file(s) create menu and sub menu"""
        menu = Nemo.MenuItem(name='KdeConnectSendExtension::KDEConnect_Send',
                             label=_('KDEConnect - Send To'),
                             tip=_('send file(s) with kdeconnect'),
                             icon='kdeconnect')

        sub_menu = Nemo.Menu()

        menu.set_submenu(sub_menu)

        for device in devices:
            item = Nemo.MenuItem(name="KDEConnectSendExtension::Send_File_To",
                                 label=device["name"])
            item.connect('activate', self.menu_activate_cb, files, device["id"], device["name"])
            sub_menu.append_item(item)

        return menu,
    def get_file_items(self, window, files):
        if len(files) != 1:
            return

        nfile = files[0]

        if nfile.is_directory():
            return

        if nfile.get_mime_type().split("/")[0] != "image":
            return

        menu = FileManager.MenuItem(name="SearchByImageExtension::Engines",
                                    label="Search by image")

        submenu = FileManager.Menu()
        menu.set_submenu(submenu)
        for engine in SEARCH_URLS.keys():
            item = FileManager.MenuItem(
                name=f"SearchByImageExtension::{engine}",
                label=f"Search image on {engine}",
                tip=f"Use {engine} reverse image search on {nfile.get_name()}",
            )
            item.connect("activate", self._search_image, nfile, engine)
            submenu.append_item(item)

        return (menu, )
Example #5
0
    def write_creation_time_callback(self, provider, handle, closure, fileinfo):
        """
        Callback to update the creation time for a file.
        """
        filename = fileinfo.get_location().get_path()
        try:
            crtime = get_crtime(filename)
        except:
            traceback.print_exc()  # Log exceptions
        else:
            # get_crtime() returns None if on an unsupported file system
            if crtime is not None:
                struct_time = time.gmtime(crtime)
                # Respect Nemo's time formatting. XXX: can we get this data from Nemo directly?
                settings = Gio.Settings.new('org.nemo.preferences')
                timeformat = settings.get_enum('date-format')

                if timeformat == NEMO_DATE_FORMAT_LOCALE:
                    formatted_time = time.strftime('%c', struct_time)
                else:  # XXX: no support for "informal" time format yet
                    formatted_time = time.strftime('%Y-%m-%d %H:%M:%S', struct_time)
                fileinfo.invalidate_extension_info()
                fileinfo.add_string_attribute('creation_time', formatted_time)

        # Tell nemo that we're done processing.
        Nemo.info_provider_update_complete_invoke(closure, provider,
                                                  handle, Nemo.OperationResult.COMPLETE)
        return False
    def update_cb(self, provider, handle, closure, file):
        self.do_update_file_info(file)

        if handle in self.ids_by_handle.keys():
            del self.ids_by_handle[handle]

        Nemo.info_provider_update_complete_invoke(closure, provider, handle, Nemo.OperationResult.COMPLETE)

        return False
Example #7
0
    def update_cb(self, provider, handle, closure, file):
        self.current_idle_id = 0

        self.do_update_file_info(file)

        Nemo.info_provider_update_complete_invoke(
            closure, provider, handle, Nemo.OperationResult.COMPLETE)

        return False
    def get_file_items(self, window, files):
        if len(files) != 1: #Only allow for a single folder selection
            return

        folder = files[0]
        if not folder.is_directory(): #Only allow on folders
            return

        #Get the full system path of the selected folder
        folder_uri = urllib.parse.unquote(folder.get_uri()[7:]) if PYTHON3 else urllib.unquote(folder.get_uri()[7:])
        folder_name = os.path.basename(os.path.normpath(folder_uri))

        #Prevents recursion issues
        if folder_name == META_DIR:
            return

        top_menuitem = Nemo.MenuItem(name='NemoRcloneSyncProvider::Sync',
                                     label='Sync',
                                     tip='Perform an rclone sync of this folder to a remote',
                                     icon='network-transmit-receive') #possible icons = "add", "network-transmit-receive"

        submenu = Nemo.Menu()
        top_menuitem.set_submenu(submenu)

        #Was the same folder opened again?
        #Prevents the metadata file from being read multiple times
        if folder_uri != self.last_dir:
            self.meta_object_cache = self.read_meta_file(folder_uri) #Get the sync metadata (if any) for this folder
            self.last_dir = folder_uri
        
        if "places" in self.meta_object_cache:
            places = self.meta_object_cache["places"]
            for p in places:
                #Create a new menu item for every remote path
                if ("label" in p) and ("path" in p):
                    sub_menuitem = Nemo.MenuItem(name=PLUGIN_NAME + "::Place-" + p["label"],
                                     label=p["label"],
                                     tip='Sync to this remote directory',
                                     icon='folder')

                    sub_menuitem.connect('activate', self.on_sync_requested, window, str(folder_uri), str(p["path"]), self.meta_object_cache["first_sync"])

                    submenu.append_item(sub_menuitem)

        #Append a separator
        sum_menuitem_separator = Nemo.MenuItem.new_separator(PLUGIN_NAME + "::Other_separator")
        submenu.append_item(sum_menuitem_separator)

        #Append the "other" option to the menu
        sub_menuitem = Nemo.MenuItem(name=PLUGIN_NAME + "::Other",
                                     label='Other...',
                                     tip='Choose a destination directory not listed here',
                                     icon='folder-saved-search')
        sub_menuitem.connect('activate', self.on_menu_other_activated, window, folder_uri)
        submenu.append_item(sub_menuitem)

        return top_menuitem,
Example #9
0
    def update_cb(self, provider, handle, closure, file):
        self.do_update_file_info(file)

        if handle in self.ids_by_handle.keys():
            del self.ids_by_handle[handle]

        Nemo.info_provider_update_complete_invoke(
            closure, provider, handle, Nemo.OperationResult.COMPLETE)

        return False
Example #10
0
    def _update_file_info(self, provider, handle, closure, item):
        path = self.uri_to_path(item.get_uri())
        state = self.file_states.get(path)
        item.connect('changed', self.changed_cb)

        self.fetch_file_state(path)
        Nemo.info_provider_update_complete_invoke(
            closure, provider, handle, Nemo.OperationResult.COMPLETE)

        return False
    def _update_file_info(self, provider, handle, closure, item):
        path = self.uri_to_path(item.get_uri())
        state = self.file_states.get(path)
        item.connect('changed', self.changed_cb)

        self.fetch_file_state(path)
        Nemo.info_provider_update_complete_invoke(
            closure, provider, handle, Nemo.OperationResult.COMPLETE)

        return False
Example #12
0
    def add_menu_device(self, stream_type, files, cast_label, submenu, device,
                        is_short_list):
        if (is_short_list or not device):
            device_config_name = None
            cast_submenu = submenu
            playlist_allowed = self.get_playlist_allowed(stream_type)
        else:
            device_config_name = device['friendlyName']
            cast_submenu = FileManager.Menu()
            name_item = FileManager.MenuItem(name='CastToTVMenu::CastFile',
                                             label=device_config_name)
            name_item.set_submenu(cast_submenu)
            submenu.append_item(name_item)
            playlist_allowed = False
            receiver_type = self.ext_settings.get_string('receiver-type')
            if receiver_type == 'chromecast' or receiver_type == 'playercast':
                if device_config_name == self.ext_settings.get_string(
                        receiver_type + '-name'):
                    playlist_allowed = self.get_playlist_allowed(stream_type)

        cast_item = FileManager.MenuItem(name='CastToTVMenu::CastFile',
                                         label=_(cast_label))
        cast_item.connect('activate', self.cast_files_cb, files, stream_type,
                          device_config_name)
        cast_submenu.append_item(cast_item)

        if playlist_allowed:
            playlist_item = FileManager.MenuItem(
                name='CastToTVMenu::AddToPlaylist', label=_("Add to Playlist"))
            playlist_item.connect('activate', self.add_to_playlist_cb, files,
                                  stream_type)
            cast_submenu.append_item(playlist_item)

        if stream_type == 'VIDEO':
            transcode_item = FileManager.MenuItem(
                name='CastTranscodeMenu::Transcode', label=_("Transcode"))
            transcode_submenu = FileManager.Menu()
            transcode_item.set_submenu(transcode_submenu)

            video_only_item = FileManager.MenuItem(
                name='CastTranscodeMenu::Video', label=_("Video"))
            video_only_item.connect('activate', self.transcode_video_cb, files,
                                    stream_type, False, device_config_name)
            transcode_submenu.append_item(video_only_item)

            audio_only_item = FileManager.MenuItem(
                name='CastTranscodeMenu::Audio', label=_("Audio"))
            audio_only_item.connect('activate', self.transcode_audio_cb, files,
                                    stream_type, device_config_name)
            transcode_submenu.append_item(audio_only_item)

            video_audio_item = FileManager.MenuItem(
                name='CastTranscodeMenu::Video+Audio',
                label=_("Video + Audio"))
            video_audio_item.connect('activate', self.transcode_video_cb,
                                     files, stream_type, True,
                                     device_config_name)
            transcode_submenu.append_item(video_audio_item)

            cast_submenu.append_item(transcode_item)
Example #13
0
    def create_menu_item(self, stream_type, files):
        cast_label = "Cast Selected File"
        if len(files) > 1:
            cast_label += "s"

        connected_devices = None
        cast_devices = []
        parsed_devices = []
        receiver_type = self.ext_settings.get_string('receiver-type')

        if not self.ws_data or not self.ws_data['isPlaying']:
            if receiver_type == 'playercast':
                connected_devices = self.get_soup_data('playercasts')
                for friendly_name in connected_devices:
                    full_name = (friendly_name.replace(' ',
                                                       '')).lower() + '.local'
                    device = {"name": full_name, "friendlyName": friendly_name}
                    parsed_devices.append(device)
            if (receiver_type == 'chromecast'
                    or receiver_type == 'playercast'):
                cast_devices = json.loads(
                    self.ext_settings.get_string(receiver_type + '-devices'))
                for device in cast_devices:
                    if ((device['name'].endswith('.local') or device['ip']) and
                        (not connected_devices
                         or device['friendlyName'] not in connected_devices)):
                        parsed_devices.append(device)

        if len(parsed_devices) > 1:
            menu_label = self.get_menu_name(False)
        else:
            menu_label = self.get_menu_name(True)

        if not menu_label:
            return None

        top_menuitem = FileManager.MenuItem(name='CastToTVMenu::CastMenu',
                                            label=menu_label)
        submenu = FileManager.Menu()
        top_menuitem.set_submenu(submenu)

        if len(parsed_devices) > 1:
            for device in parsed_devices:
                self.add_menu_device(stream_type, files, cast_label, submenu,
                                     device, False)
        else:
            self.add_menu_device(stream_type, files, cast_label, submenu, None,
                                 True)

        return top_menuitem
Example #14
0
 def get_columns(self):
     return (
         Nemo.Column(name="NemoPython::at_1_column",
                     attribute="at_1",
                     label=("@1"),
                     description="Get the 1st at-prefixed part"),
         Nemo.Column(name="NemoPython::at_2_column",
                     attribute="at_2",
                     label=("@2"),
                     description="Get the 2nd at-prefixed part"),
         Nemo.Column(name="NemoPython::dollar_1_column",
                     attribute="dollar_1",
                     label=("$1"),
                     description="Get the 1st dollar-prefixed part"),
         Nemo.Column(name="NemoPython::dollar_2_column",
                     attribute="dollar_2",
                     label=("$2"),
                     description="Get the 2nd dollar-prefixed part"),
         Nemo.Column(name="NemoPython::hash_1_column",
                     attribute="hash_1",
                     label=("#1"),
                     description="Get the 1st hashtagged part"),
         Nemo.Column(name="NemoPython::hash_2_column",
                     attribute="hash_2",
                     label=("#2"),
                     description="Get the 2nd hashtagged part"),
         Nemo.Column(name="NemoPython::name_2_column",
                     attribute="name_2",
                     label=("Name2"),
                     description="Get the name after first space"),
         Nemo.Column(name="NemoPython::name_3_column",
                     attribute="name_3",
                     label=("Name3"),
                     description="Get the name after second space"),
     )
Example #15
0
    def get_background_items(self, window, file):
        submenu = Nemo.Menu()
        submenu.append_item(
            Nemo.MenuItem(name='ExampleMenuProvider::Bar2',
                          label='Bar2',
                          tip='',
                          icon=''))

        menuitem = Nemo.MenuItem(name='ExampleMenuProvider::Foo2',
                                 label='Foo2',
                                 tip='',
                                 icon='')
        menuitem.set_submenu(submenu)

        return menuitem,
Example #16
0
 def get_columns(self):
     """Return the list of columns provided by this extension."""
     return (Nemo.Column(name="NemoCrtime::creation_time_column",
                         attribute="creation_time",
                         # For consistency with Nemo's style (Date Modified, Date Accessed, ...)
                         label=_("Date Created"),
                         description=_("File/folder creation time (NTFS/FAT32)")),)
Example #17
0
    def get_file_items(self, window, files):
        if len(files) != 1:
            return
        file = files[0]
        items = []

        # internal or external file?!
        syncedFile = False
        for reg_path in socketConnect.registered_paths:
            filename = get_local_path(file.get_uri())
            if filename.startswith(reg_path):
                syncedFile = True

        # if it is neither in a synced folder or is a directory
        if (not syncedFile):
            return items

        # create an menu item
        labelStr = "Share with " + appname + "..."
        item = Nemo.MenuItem(name='NemoPython::ShareItem',
                             label=labelStr,
                             tip='Share file %s through ownCloud' %
                             file.get_name())
        item.connect("activate", self.menu_share, file)
        items.append(item)

        return items
Example #18
0
    def get_property_pages(self, files):
        # files: list of NemoVFSFile
        if len(files) != 1:
            return

        file = files[0]
        if file.get_uri_scheme() != 'file':
            return

        self.filename = parse.unquote(file.get_uri()[7:])
        self.gio_file = Gio.File.new_for_path(self.filename)
        self.file_info = self.gio_file.query_info(METADATA_EMBLEMS, 0, None)
        self.file_emblem_names = self.file_info.get_attribute_stringv(
            METADATA_EMBLEMS)

        #GUI
        self.property_label = Gtk.Label(_('Emblems'))
        self.property_label.show()

        self.builder = Gtk.Builder()
        self.builder.add_from_string(GUI)

        #connect signals to python methods
        self.builder.connect_signals(self)

        #connect gtk objects to python variables
        for obj in self.builder.get_objects():
            if issubclass(type(obj), Gtk.Buildable):
                name = Gtk.Buildable.get_name(obj)
                setattr(self, name, obj)

        left = 0
        top = 0
        for emblem_name, display_name in sorted(list(
                self.display_names.items()),
                                                key=lambda x: x[1]):
            checkbutton = Gtk.CheckButton()
            checkbutton.set_label(_(display_name))

            image = Gtk.Image.new_from_icon_name(emblem_name,
                                                 Gtk.IconSize.BUTTON)
            image.set_pixel_size(24)  # this should not be necessary
            checkbutton.set_always_show_image(True)
            checkbutton.set_image(image)

            if emblem_name in self.file_emblem_names:
                checkbutton.set_active(True)

            checkbutton.connect("toggled", self.on_button_toggled, emblem_name)
            checkbutton.show()

            self.grid.attach(checkbutton, left, top, 1, 1)
            left += 1
            if left > 2:
                left = 0
                top += 1

        return Nemo.PropertyPage(name="NemoPython::emblem",
                                 label=self.property_label,
                                 page=self.mainWindow),
Example #19
0
    def get_file_items(self, window, files):
        top_menuitem = Nemo.MenuItem(name='ExampleMenuProvider::Foo',
                                     label='Foo',
                                     tip='',
                                     icon='')

        submenu = Nemo.Menu()
        top_menuitem.set_submenu(submenu)

        sub_menuitem = Nemo.MenuItem(name='ExampleMenuProvider::Bar',
                                     label='Bar',
                                     tip='',
                                     icon='')
        submenu.append_item(sub_menuitem)

        return top_menuitem,
Example #20
0
    def get_file_items(self, window, items):
        """Return the context menu widget.

        Called by Nemo on view changes. items are the currently selected
        items.
        """
        if not items:
            return
        # skip if current theme has no other colors
        if not self.installed_colors:
            return
        # only folders and scheme is file
        if any(item.get_uri_scheme() != "file" or not item.is_directory()
               for item in items):
            return

        widget_a = generate_menu_widget(self.installed_colors,
                                        items,
                                        callback=self.menu_activate_cb)
        widget_b = generate_menu_widget(self.installed_colors,
                                        items,
                                        callback=self.menu_activate_cb)

        menuItem = Nemo.MenuItem(name="NemoFolderColorSwitcher::Widget",
                                 widget_a=widget_a,
                                 widget_b=widget_b)
        return (Nemo.MenuItem.new_separator("NemoFolderColorSwitcher::TopSep"),
                menuItem,
                Nemo.MenuItem.new_separator("NemoFolderColorSwitcher::BotSep"))
Example #21
0
 def get_file_items(self, window, files):
     """
     Return a menu item if some files were selected.
     """
     if not len(files):
         return
     item = Nemo.MenuItem(
         name='NitroShare::SendFiles',
         label="Send with NitroShare...",
     )
     try:
         with open(self._LOCALFILE, 'r') as f:
             d = loads(f.read())
         port = d['port']
         token = d['token']
     except (IOError, KeyError):
         item.set_property('sensitive', False)
     else:
         item.connect(
             'activate',
             self.send_items,
             window,
             [url2pathname(urlparse(x.get_uri()).path) for x in files],
             port,
             token,
         )
     return [item]
Example #22
0
    def make_menu_item(self, item, id_magic):
        identifier = item.make_magic_id(id_magic)
        menuitem = Nemo.MenuItem(name=identifier,
                                 label=item.make_label(),
                                 tip=item.tooltip,
                                 icon=item.icon)

        return menuitem
Example #23
0
 def _create_hide_item(self, files, hidden_path, hidden):
     """Creates the 'Hide file(s)' menu item."""
     item = Nemo.MenuItem(name="NemoHide::HideFile",
                          label=ngettext("_Hide File", "_Hide Files",
                                         len(files)),
                          tip=ngettext("Hide this file", "Hide these files",
                                       len(files)))
     item.connect("activate", self._hide_run, files, hidden_path, hidden)
     return item
 def get_background_items(self, window, current_folder):
   menu_item = Nemo.MenuItem(
     name  = 'NemoPython::open-in-vscode',
     label = intl('Open in Visual Studio Code'),
     tip   = intl('Opens the current folder in Visual Studio Code'),
     icon  = 'gtk-execute'
   )
   menu_item.connect('activate', self.execute, current_folder)
   return menu_item,
    def get_file_items(self, window, files):
        """Ensure there are reachable devices"""
        try:
            devices = self.get_reachable_devices()
        except Exception as e:
            raise Exception("Error while getting reachable devices")
        """if there is no reacheable devices don't show this on context menu"""
        if len(devices) == 0:
            return
        """Ensure that user only select files"""
        for file in files:
            if file.get_uri_scheme() != 'file' or file.is_directory():
                return

        self.setup_gettext()
        """If user only select file(s) create menu and sub menu"""
        menu = Nemo.MenuItem(name='SendViaExtension::SendViaKDEConnect',
                             label=_('KDEConnect Send To'),
                             tip=_('send file(s) with kdeconnect'),
                             icon='kdeconnect')

        sub_menu = Nemo.Menu()

        menu.set_submenu(sub_menu)

        for deviceId, deviceName in devices.items():
            item = Nemo.MenuItem(name='SendViaExtension::SendFileTo' +
                                 deviceId,
                                 label=deviceName)
            item.connect('activate', self.send_files, files, deviceId,
                         deviceName)
            sub_menu.append_item(item)

        if len(devices) > 1:
            item = Nemo.MenuItem(
                name='SendViaExtension::SendFileToMultipleDevices',
                label='Multiple Devices')
            item.connect('activate', self.send_to_multiple_devices, files)

            sub_menu.append_item(item)

        return menu,
Example #26
0
    def get_file_items(self, window, files):
        """Return a list of select files to be sent"""

        # Only accept regular files
        for uri in files:
            if uri.get_uri_scheme() != 'file' or uri.is_directory():
                return ()

        # Enumerate capable devices
        devices = []

        for name, action_group in self.devices.values():
            if action_group.get_action_enabled('shareFile'):
                devices.append([name, action_group])

        # No capable devices; don't show menu entry
        if not devices:
            return ()

        # Context Menu Item
        menu = FileManager.MenuItem(
            name='GSConnectShareExtension::Devices',
            label=_('Send To Mobile Device')
        )

        # Context Submenu
        submenu = FileManager.Menu()
        menu.set_submenu(submenu)

        # Context Submenu Items
        for name, action_group in devices:
            item = FileManager.MenuItem(
                name='GSConnectShareExtension::Device' + name,
                label=name
            )

            item.connect('activate', self.send_files, files, action_group)

            submenu.append_item(item)

        return (menu,)
Example #27
0
class MtgActions(GObject.GObject, Nemo.MenuProvider):

    def __init__(self):
        try:
            factory = Gtk.IconFactory()
            pixbuf = GdkPixbuf.Pixbuf.new_from_file(ICONPATH)
            iconset = Gtk.IconSet.new_from_pixbuf(pixbuf)
            factory.add("mtg", iconset)
            factory.add_default()
        except: pass

    #def run(self, menu, element_1, element_2):
    #    """Runs the Meld Comparison of selected files/folders"""
    #    subprocess.call("meld %s %s &" % (element_1, element_2), shell=True)

    def meld_save(self, menu, element):
		call(['gedit', ' ', '&'])

    def get_file_items(self, window, sel_items):
        """Adds the 'Add To Audacious Playlist' menu item to the Nemo right-click menu,
           connects its 'activate' signal to the 'run' method passing the list of selected Audio items"""
		call(['gedit', ' ', '&'])
        num_paths = len(sel_items)
        if num_paths == 0: return
        uri_raw = sel_items[0].get_uri()
        if len(uri_raw) < 7: return
        element_1 = urllib.unquote(uri_raw[7:])
         
        top_menuitem = Nemo.MenuItem(name='Mtg::actions',
                                         label=_('MTG Manage'),
                                         tip=_('Tools for managing your MTG Collection'),
                                         icon='mtg')
        submenu = Nemo.Menu()
        top_menuitem.set_submenu(submenu)
        sub_menuitem_save = Nemo.MenuItem(name='Mtg::download_price',
                                              label=_('Reload prices'),
                                              tip=_('Download and show selected cards prices.'),
                                              icon='prices')
        sub_menuitem_save.connect('activate', self.meld_save, element_1)
        submenu.append_item(sub_menuitem_save)
        return top_menuitem
Example #28
0
    def get_file_items( # pylint: disable=arguments-differ
        self, _, files: list[GObject]) -> list[Nemo.MenuItem]|None:
        '''
        Called when context menu is called with files selected.

        :param files: The currently selected file objects.
        '''
        files = get_files(files) # type: ignore
        try:
            is_iter = iter(files)
            check = all(file.lower().endswith('png') for file in files)
        except TypeError:
            is_iter = False
            check = False
        if check:
            convert = Nemo.MenuItem(
                name="CrushImages",
                label="Optimize image(s) with pngcrush",
                tip="Optimize filesize(s) with pngcrush"
            )
            convert.connect('activate', crush_images, files)
            return [convert]

        if is_iter:
            check = all(file.lower().endswith(EXTENSIONS) for file in files)
        if check:
            convert = Nemo.MenuItem(
                name="ConvertImagetoPNG",
                label="Convert selected image(s) to .png",
                tip="Convert image(s) to .png"
            )
            convert.connect('activate', convert_images, files)

            crush = Nemo.MenuItem(
                name="ConvertandCrush",
                label="Convert to PNG and optimize with pngcrush",
                tip="Convert image(s) to PNG and optimize filesize(s) with\
                    pngcrush"
            )
            crush.connect('activate', convert_and_crush, files)
            return [convert, crush]
 def get_background_items(self, window, folder):
     """ Show 'wipe free space' menu entry """
     if folder.get_uri_scheme() != 'file':
         return
     item = Nemo.MenuItem(
         name='Nemo::wipe_free_space',
         label=gettext.dgettext('truecrypt-helper', 'Wipe free space'),
         tip=gettext.dgettext(
             'truecrypt-helper',
             'Overwrites free space on the current location'))
     item.connect('activate', self.wipe_activate_cb, folder)
     return item,
    def update_cb(self, provider, handle, closure, file):
        # stopit uses threads, so don't give it anything that isn't safe

        mimetype = file.get_mime_type()
        # Recent and Favorites set the G_FILE_ATTRIBUTE_STANDARD_TARGET_URI attribute
        # to their real files' locations. Use that uri in those cases.
        uri = file.get_activation_uri()
        info = None

        if uri.startswith("file"):
            try:
                with stopit.ThreadingTimeout(.1):
                    info = self.get_media_info(uri, mimetype)
            except stopit.utils.TimeoutException:
                print(
                    "nemo-media-columns failed to process '%s' within a reasonable amount of time"
                    % (gfile.get_uri(), e))

        # TODO: we shouldn't set attributes on files that didn't match any of our mimetypes.
        # we do currently so the given columns can be set to '' - we should maybe do this in
        # nemo (https://github.com/linuxmint/nemo/blob/master/libnemo-private/nemo-file.c#L6811-L6814)
        # so that here we only set files that we support.
        #
        # get_media_info can return None if nothing matched, or there was an error, instead of always
        # adding the attributes to a file whether it's useful or not.

        if info == None:
            info = FileExtensionInfo()

        # if info:
        self.set_file_attributes(file, info)
        del info

        if handle in self.ids_by_handle.keys():
            del self.ids_by_handle[handle]

        Nemo.info_provider_update_complete_invoke(
            closure, provider, handle, Nemo.OperationResult.COMPLETE)

        return False
    def get_property_pages(self, files):
        if len(files) != 1:
            return

        file = files[0]
        print file.get_mount()
        if not (((file.get_uri_scheme() == 'x-nemo-desktop') and
                 (file.get_mime_type() == 'application/x-nemo-link')) or
                (file.get_uri_scheme() == 'computer')):
            return

        self.mountpoint = file.get_mount().get_root().get_path()
        if not os.path.ismount(self.mountpoint):
            return

        found = 0
        for line in open('/proc/mounts', 'r').readlines():
            sp = line.split()
            try:
                if sp[1] == self.mountpoint:
                    self.device = sp[0]
                    found = 1
                    break
            except IndexError:
                continue
        if found == 0:
            return
        self.property_label = Gtk.Label(
            gettext.dgettext('nemo-fscheck', 'Check').decode('utf-8'))
        self.property_label.show()

        self.vbox = Gtk.VBox(0, False)
        self.hbox = Gtk.HBox(0, False)
        self.text = Gtk.Label()
        self.text.set_markup(
            gettext.dgettext(
                'nemo-fscheck',
                "Here you can check the filesystem on this device for errors and repair them"
            ).decode('utf-8'))
        self.vbox.pack_start(self.text, False, False, 10)
        self.button = Gtk.Button(
            gettext.dgettext('nemo-fscheck',
                             'Check Filesystem').decode('utf-8'))
        self.button.connect('clicked', self.check_filesystem)
        self.hbox.pack_start(self.button, False, False, 10)
        self.vbox.pack_start(self.hbox, False, False, 0)
        self.vbox.show_all()

        page = Nemo.PropertyPage(name="NemoPython::fscheck",
                                 label=self.property_label,
                                 page=self.vbox)
        return [page]
    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':
            return

        item = Nemo.MenuItem(name='NemoPython::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 update_cb(self, provider, handle, closure):
     print "update_cb"
     Nemo.info_provider_update_complete_invoke(closure, provider, handle, Nemo.OperationResult.FAILED)