Ejemplo n.º 1
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),
Ejemplo n.º 2
0
    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]
Ejemplo n.º 3
0
    def _build_gui(self, file_data):
        """Create the GUI for the property page holding the emblems.

        The emblems (retrieved during instantiation) will be aligned in
        a grid model, selectable via check box.
        file_data has to be a dict holding the "filename", the Gio.File
        instance ("gio_file"), the Gio.FileInfo ("file_info") and its
        currently applied emblems ("emblem_names"). It will be passed to
        the checkbox toggle event.
        """
        tab_label = Gtk.Label(TAB_LABEL)
        tab_label.show()

        tab = Gtk.ScrolledWindow()
        grid = Gtk.Grid(column_homogeneous=True,
                        row_homogeneous=True,
                        column_spacing=15,
                        row_spacing=10,
                        border_width=20,
                        vexpand=True,
                        hexpand=True)
        tab.add(grid)

        left = 0
        top = 0
        emblems = sorted(self.icon_names.items(), key=lambda x: x[1])
        for emblem_name, display_name in emblems:
            emblem = Gtk.Image.new_from_icon_name(emblem_name,
                                                  Gtk.IconSize.LARGE_TOOLBAR)
            checkbutton = Gtk.CheckButton(label=display_name,
                                          image=emblem,
                                          always_show_image=True)
            # check current active emblems
            if emblem_name in file_data["emblem_names"]:
                checkbutton.set_active(True)

            checkbutton.connect("toggled", self.on_button_toggled, emblem_name,
                                file_data)
            checkbutton.show()
            grid.attach(checkbutton, left, top, 1, 1)
            left += 1
            if left > 2:
                left = 0
                top += 1

        tab.show_all()
        return Nemo.PropertyPage(name=PAGE_NAME, label=tab_label, page=tab),
Ejemplo n.º 4
0
    def get_property_pages(self, items):
        paths = []

        for item in items:
            if self.valid_uri(item.get_uri()):
                path = rabbitvcs.util.helper.unquote_url(self.get_local_path(item.get_uri()))
                
                if self.vcs_client.is_in_a_or_a_working_copy(path):
                    paths.append(path)
                    self.nemoVFSFile_table[path] = item

        if len(paths) == 0: return []

        label = rabbitvcs.ui.property_page.PropertyPageLabel(claim_domain=False).get_widget()
        page = rabbitvcs.ui.property_page.PropertyPage(paths, claim_domain=False).get_widget()

        ppage = Nemo.PropertyPage(name='RabbitVCS::PropertyPage',
            label=label,
            page=page)

        return [ppage]
Ejemplo n.º 5
0
    def get_property_pages(self, files):
        if len(files) != 1:
            return

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

        if file.is_directory():
            return

        filename = urllib.unquote(file.get_uri()[7:])

        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.show()
        self.hbox.pack_start(label, False, False, 0)

        self.value_label = Gtk.Label()
        self.hbox.pack_start(self.value_label, False, False, 0)

        md5sum = hashlib.md5()
        with open(filename, 'rb') as f:
            for chunk in iter(lambda: f.read(8192), ''):
                md5sum.update(chunk)
        f.close()

        self.value_label.set_text(md5sum.hexdigest())
        self.value_label.show()

        return Nemo.PropertyPage(name="NemoPython::md5_sum",
                                 label=self.property_label,
                                 page=self.hbox),
Ejemplo n.º 6
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
        
        filename = urllib.unquote(file.get_uri()[7:])
        
        #GUI
        locale.setlocale(locale.LC_ALL, '')
        _ = gettext.gettext
        self.property_label = Gtk.Label(_('Audio'))
        self.property_label.show()
        
        self.builder = Gtk.Builder()
        self.builder.add_from_file("/usr/share/nemo-python/extensions/nemo-audio-tab.glade")
        
        #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)
        
        # set defaults to blank to prevent nonetype errors
        file.add_string_attribute('title', '')
        file.add_string_attribute('album', '')
        file.add_string_attribute('artist', '')
        file.add_string_attribute('albumartist', '')
        file.add_string_attribute('tracknumber', '')
        file.add_string_attribute('genre', '')
        file.add_string_attribute('date', '')
        file.add_string_attribute('bitrate', '')
        file.add_string_attribute('samplerate', '')
        file.add_string_attribute('length', '')
        file.add_string_attribute('encodedby', '')
        file.add_string_attribute('copyright', '')
        
        no_info = _("No Info")
        mutaFile = mutagen.File(filename)

        #MP3
        if file.is_mime_type('audio/mpeg'):
            # attempt to read ID3 tag
            try:
                audio = EasyID3(filename)
                # sometimes the audio variable will not have one of these items defined, that's why
                # there is this long try / except attempt
                try: file.add_string_attribute('title', audio["title"][0])
                except: file.add_string_attribute('title', no_info)
                try: file.add_string_attribute('album', audio["album"][0])
                except: file.add_string_attribute('album', no_info)
                try: file.add_string_attribute('artist', audio["artist"][0])
                except: file.add_string_attribute('artist', no_info)
                try: file.add_string_attribute('albumartist', audio["performer"][0])
                except: file.add_string_attribute('albumartist', no_info)
                try: file.add_string_attribute('tracknumber', audio["tracknumber"][0])
                except: file.add_string_attribute('tracknumber', no_info)
                try: file.add_string_attribute('genre', audio["genre"][0])
                except: file.add_string_attribute('genre', no_info)
                try: file.add_string_attribute('date', audio["date"][0])
                except: file.add_string_attribute('date', no_info)
                try: file.add_string_attribute('encodedby', audio["encodedby"][0])
                except: file.add_string_attribute('encodedby', no_info)
                try: file.add_string_attribute('copyright', audio["copyright"][0])
                except: file.add_string_attribute('copyright', no_info)
            except:
                # [SabreWolfy] some files have no ID3 tag and will throw this exception:
                file.add_string_attribute('title', no_info)
                file.add_string_attribute('album', no_info)
                file.add_string_attribute('artist', no_info)
                file.add_string_attribute('albumartist', no_info)
                file.add_string_attribute('tracknumber', no_info)
                file.add_string_attribute('genre', no_info)
                file.add_string_attribute('date', no_info)
                file.add_string_attribute('encodedby', no_info)
                file.add_string_attribute('copyright', no_info)
                
                # try to read MP3 information (bitrate, length, samplerate)
            try:
                mpinfo = MPEGInfo (filename)
                file.add_string_attribute('bitrate', str(mpinfo.bitrate/1000) + " Kbps")

                file.add_string_attribute('samplerate', str(mpinfo.sample_rate) + " Hz")
                # [SabreWolfy] added consistent formatting of times in format hh:mm:ss
                mp3length = "%02i:%02i:%02i" % ((int(mpinfo.length/3600)), (int(mpinfo.length/60%60)), (int(mpinfo.length%60)))
                file.add_string_attribute('length', mp3length)
            except:
                file.add_string_attribute('bitrate', no_info)
                file.add_string_attribute('length', no_info)
                file.add_string_attribute('samplerate', no_info)

        #FLAC
        if file.is_mime_type('audio/flac'):
            try:
                audio = FLAC(filename)
                # sometimes the audio variable will not have one of these items defined, that's why
                # there is this long try / except attempt
                try: file.add_string_attribute('title', audio["title"][0])
                except: file.add_string_attribute('title', no_info)
                try: file.add_string_attribute('album', audio["album"][0])
                except: file.add_string_attribute('album', no_info)
                try: file.add_string_attribute('artist', audio["artist"][0])
                except: file.add_string_attribute('artist', no_info)
                try: file.add_string_attribute('albumartist', audio["albumartist"][0]) # this tag is different then mp3s
                except: file.add_string_attribute('albumartist', no_info)
                try: file.add_string_attribute('tracknumber', audio["tracknumber"][0])
                except: file.add_string_attribute('tracknumber', no_info)
                try: file.add_string_attribute('genre', audio["genre"][0])
                except: file.add_string_attribute('genre', no_info)
                try: file.add_string_attribute('date', audio["date"][0])
                except: file.add_string_attribute('date', no_info)
                try: file.add_string_attribute('encodedby', audio["encoded-by"][0]) # this tag is different then mp3s
                except: file.add_string_attribute('encodedby', no_info)
                try: file.add_string_attribute('copyright', audio["copyright"][0])
                except: file.add_string_attribute('copyright', no_info)
            except:
                # [SabreWolfy] some files have no ID3 tag and will throw this exception:
                file.add_string_attribute('title', no_info)
                file.add_string_attribute('album', no_info)
                file.add_string_attribute('artist', no_info)
                file.add_string_attribute('albumartist', no_info)
                file.add_string_attribute('tracknumber', no_info)
                file.add_string_attribute('genre', no_info)
                file.add_string_attribute('date', no_info)
                file.add_string_attribute('encodedby', no_info)
                file.add_string_attribute('copyright', no_info)
                
                # try to read the FLAC information (length, samplerate)
            try:
                fcinfo = StreamInfo (filename)
                
                file.add_string_attribute('samplerate', str(fcinfo.sample_rate) + " Hz")
                
                # [SabreWolfy] added consistent formatting of times in format hh:mm:ss
                flaclength = "%02i:%02i:%02i" % ((int(mutaFile.info.length/3600)), (int(mutaFile.info.length/60%60)), (int(mutaFile.info.length%60)))
                file.add_string_attribute('length', flaclength)
                file.add_string_attribute('bitrate', no_info) # flac doesn't really have a bitrate
            except:
                file.add_string_attribute('bitrate', no_info)
                file.add_string_attribute('length', no_info)
                file.add_string_attribute('samplerate', no_info)

        self.builder.get_object("title_text").set_label(file.get_string_attribute('title'))
        self.builder.get_object("album_text").set_label(file.get_string_attribute('album'))
        self.builder.get_object("album_artist_text").set_label(file.get_string_attribute('albumartist'))
        self.builder.get_object("artist_text").set_label(file.get_string_attribute('artist'))
        self.builder.get_object("genre_text").set_label(file.get_string_attribute('genre'))
        self.builder.get_object("year_text").set_label(file.get_string_attribute('date'))
        self.builder.get_object("track_number_text").set_label(file.get_string_attribute('tracknumber'))
        self.builder.get_object("sample_rate_text").set_label(file.get_string_attribute('samplerate'))
        self.builder.get_object("length_number").set_label(file.get_string_attribute('length'))
        self.builder.get_object("bitrate_number").set_label(file.get_string_attribute('bitrate'))
        self.builder.get_object("encoded_by_text").set_label(file.get_string_attribute('encodedby'))
        self.builder.get_object("copyright_text").set_label(file.get_string_attribute('copyright'))

        if file.is_mime_type('audio/mpeg') or file.is_mime_type('audio/flac'):
            return Nemo.PropertyPage(name="NemoPython::audio", label=self.property_label, page=self.mainWindow),
Ejemplo n.º 7
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 []

        if file.is_directory():
            return []

        if not(file.is_mime_type('application/x-msdownload')):
            return []

        filename = parse.unquote(file.get_uri()[7:])

        #GUI
        locale.setlocale(locale.LC_ALL, '')
        gettext.bindtextdomain("nemo-extensions")
        gettext.textdomain("nemo-extensions")
        _ = gettext.gettext

        self.property_label = Gtk.Label(_('.NET'))
        self.property_label.show()

        self.builder = Gtk.Builder()
        self.builder.set_translation_domain('nemo-extensions')
        self.builder.add_from_file("/usr/share/nemo-dotnetinfo-tab/nemo-dotnetinfo-tab.glade")

        #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)
        
        no_info = _("No Info")
        
        # set defaults to blank to prevent nonetype errors
        file.add_string_attribute('filedesc', '')
        file.add_string_attribute('filever', '')
        file.add_string_attribute('productname', '')
        file.add_string_attribute('productversion', '')
        file.add_string_attribute('language', '')
        file.add_string_attribute('copyright', '')
        file.add_string_attribute('company', '')
        file.add_string_attribute('comments', '')

        dictionary={}
        out = check_output(["exiftool", filename]).decode()
        
        for keyValue in out.split("\n"):
            keyValuePair = keyValue.split(":")
            if(len(keyValuePair) == 2):
                m = keyValuePair[0].strip()
                dictionary[m] = keyValuePair[1].strip()
           

        file.add_string_attribute('filedesc', dictionary.get('File Description',''))
        file.add_string_attribute('filever', dictionary.get('Assembly Version',''))
        file.add_string_attribute('productname', dictionary.get('Product Name',''))
        file.add_string_attribute('productversion', dictionary.get('Product Version',''))
        file.add_string_attribute('language', dictionary.get('Language Code',''))
        file.add_string_attribute('copyright', dictionary.get('Legal Copyright',''))
        file.add_string_attribute('company', dictionary.get('Company Name',''))
        file.add_string_attribute('comments', dictionary.get('Comments',''))
               
        self.builder.get_object("filedesc_text").set_label(file.get_string_attribute('filedesc'))
        self.builder.get_object("filever_text").set_label(file.get_string_attribute('filever'))
        self.builder.get_object("productname_text").set_label(file.get_string_attribute('productname'))
        self.builder.get_object("productversion_text").set_label(file.get_string_attribute('productversion'))
        self.builder.get_object("language_text").set_label(file.get_string_attribute('language'))
        self.builder.get_object("copyright_text").set_label(file.get_string_attribute('copyright'))
        self.builder.get_object("company_text").set_label(file.get_string_attribute('company'))
        self.builder.get_object("comments_text").set_label(file.get_string_attribute('comments'))

        return [
            Nemo.PropertyPage(name="NemoPython::NET",
                              label=self.property_label,
                              page=self.builder_root_widget)
        ]
Ejemplo n.º 8
0
    def _build_gui(self, label, tagdata, default_tags=None, icon=None):
        """Build and return GUI based on the tagdata retrieved before.

        label -- tab label/title text widget
        tagdata -- data to be displayed
        default_tags -- dict of {tags : translated_tags} (will be listed first)
        icon -- image widget to be
        """
        tab_label = Gtk.Label(label)
        tab_label.show()

        tab = Gtk.ScrolledWindow()
        holder = Gtk.VBox(valign=Gtk.Align.START)
        tab.add(holder)
        grid_default_tags = Gtk.Grid(orientation=Gtk.Orientation.VERTICAL,
                                     column_homogeneous=False,
                                     column_spacing=15,
                                     row_spacing=10,
                                     border_width=20)
        holder.pack_start(grid_default_tags, True, False, 0)

        details = Gtk.Expander(label=_("More…"))
        holder.pack_start(details, True, False, 0)
        grid_details = Gtk.Grid(orientation=Gtk.Orientation.VERTICAL,
                                column_homogeneous=False,
                                column_spacing=15,
                                row_spacing=10,
                                border_width=20)
        details.add(grid_details)

        # put tagdata in a grid model,
        # leave out empty tags and
        # try to use translated versions of tags (as defined in default_tags)
        # non-default tags are hidden in an expander
        n_rows = 0
        for tagname, data in tagdata.items():
            if not data:
                continue
            if default_tags and tagname in default_tags:
                nice_tagname = default_tags[tagname] + ":"
                grid = grid_default_tags
                n_rows += 1
            else:
                nice_tagname = _(tagname) + ":"
                grid = grid_details
            label_name = Gtk.Label(label=nice_tagname,
                                   halign=Gtk.Align.START,
                                   valign=Gtk.Align.START)
            grid.add(label_name)
            tagvalue = "".join(data)
            label_data = Gtk.Label(label=tagvalue,
                                   halign=Gtk.Align.START,
                                   valign=Gtk.Align.START,
                                   hexpand=True,
                                   selectable=True)
            label_data.set_line_wrap(True)
            label_data.set_ellipsize(Pango.EllipsizeMode.END)
            grid.attach_next_to(label_data, label_name, Gtk.PositionType.RIGHT,
                                1, 1)

        # add icon, if any
        if icon:
            grid_default_tags.attach_next_to(
                icon, grid_default_tags.get_child_at(1, 0),
                Gtk.PositionType.RIGHT, 1, n_rows)
            icon.set_valign(Gtk.Align.START)

        # Show details expander only when there are any
        if not grid_details.get_children():
            details.destroy()

        tab.show_all()
        return Nemo.PropertyPage(name=PAGE_NAME, label=tab_label, page=tab),
Ejemplo n.º 9
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

        if file.is_directory():
            return

        filename = unquote(file.get_uri()[7:])

        try:
            filename = filename.decode("utf-8")
        except:
            pass

        MI = MediaInfo()
        MI.Option_Static("Complete")
        MI.Option_Static("Inform", "Nothing")
        MI.Option_Static("Language", "file://{}".format(locale_file))
        MI.Open(filename)
        info = MI.Inform().splitlines()
        MI.Close()
        if len(info) < 8:
            return

        locale.setlocale(locale.LC_ALL, '')
        gettext.bindtextdomain("nemo-extensions")
        gettext.textdomain("nemo-extensions")
        _ = gettext.gettext

        self.property_label = Gtk.Label(_('Media Info'))
        self.property_label.show()

        self.builder = Gtk.Builder()
        self.builder.set_translation_domain('nemo-extensions')
        self.builder.add_from_string(GUI)

        self.mainWindow = self.builder.get_object("mainWindow")
        self.grid = self.builder.get_object("grid")

        top = 0
        for line in info:
            tag = line[:41].strip()
            if tag not in excludeList:
                label = Gtk.Label()
                label.set_markup("<b>" + tag + "</b>")
                label.set_justify(Gtk.Justification.LEFT)
                label.set_halign(Gtk.Align.START)
                label.show()
                self.grid.attach(label, 0, top, 1, 1)
                label = Gtk.Label()
                label.set_text(line[42:].strip())
                label.set_justify(Gtk.Justification.LEFT)
                label.set_halign(Gtk.Align.START)
                label.set_selectable(True)
                label.set_line_wrap(True)
                label.show()
                self.grid.attach(label, 1, top, 1, 1)
                top += 1

        return Nemo.PropertyPage(name="NemoPython::mediainfo",
                                 label=self.property_label,
                                 page=self.mainWindow),