예제 #1
0
    def __edit_tag(self, renderer, path, new_value, model):
        new_value = gdecode(new_value)
        new_value = ', '.join(new_value.splitlines())
        path = Gtk.TreePath.new_from_string(path)
        entry = model[path][0]
        error_dialog = None

        if not massagers.is_valid(entry.tag, new_value):
            error_dialog = qltk.WarningMessage(
                self, _("Invalid value"),
                _("Invalid value: <b>%(value)s</b>\n\n%(error)s") % {
                "value": new_value,
                "error": massagers.error_message(entry.tag, new_value)})
        else:
            new_value = massagers.validate(entry.tag, new_value)

        comment = entry.value
        changed = comment.text != new_value
        if (changed and ((comment.shared and comment.complete) or new_value)) \
                or (new_value and comment.shared and not comment.complete):
            # only give an error if we would have applied the value
            if error_dialog is not None:
                error_dialog.run()
                return
            entry.value = Comment(new_value)
            entry.edited = True
            entry.deleted = False
            model.path_changed(path)
예제 #2
0
    def __edit_tag(self, renderer, path, new_value, model):
        #pfps leaving the newline should be OK
        #        new_value = ', '.join(new_value.splitlines())
        path = Gtk.TreePath.new_from_string(path)
        entry = model[path][0]
        error_dialog = None

        if not massagers.is_valid(entry.tag, new_value):
            error_dialog = qltk.WarningMessage(
                self, _("Invalid value"),
                _("Invalid value: <b>%(value)s</b>\n\n%(error)s") % {
                    "value": new_value,
                    "error": massagers.error_message(entry.tag, new_value)
                })
        else:
            new_value = massagers.validate(entry.tag, new_value)

        comment = entry.value
        changed = comment.text != new_value
        identical = comment.shared and comment.complete
        if (changed and (identical or new_value)) \
                or (new_value and not identical):
            # only give an error if we would have applied the value
            if error_dialog is not None:
                error_dialog.run()
                return
            entry.value = Comment(new_value)
            entry.edited = True
            entry.deleted = False
            model.path_changed(path)
예제 #3
0
 def __validate(self, editable, add, invalid, box):
     tag = self.get_tag()
     value = self.get_value()
     valid = massagers.is_valid(tag, value)
     add.set_sensitive(valid)
     if valid:
         invalid.hide()
         box.set_tooltip_text("")
     else:
         invalid.show()
         box.set_tooltip_text(massagers.error_message(tag, value))
예제 #4
0
 def __validate(self, editable, add, invalid, box):
     tag = self.get_tag()
     value = self.get_value()
     valid = massagers.is_valid(tag, value)
     add.set_sensitive(valid)
     if valid:
         invalid.hide()
         box.set_tooltip_text("")
     else:
         invalid.show()
         box.set_tooltip_text(massagers.error_message(tag, value))
예제 #5
0
    def __edit_tag_name(self, renderer, path, new_tag, model):
        new_tag = ' '.join(new_tag.splitlines()).lower()
        path = Gtk.TreePath.new_from_string(path)
        entry = model[path][0]
        if new_tag == entry.tag:
            return
        elif not self.__songinfo.can_change(new_tag):
            # Can't add the new tag.
            title = _("Invalid tag")
            msg = _("Invalid tag <b>%s</b>\n\nThe files currently"
                    " selected do not support editing this tag."
                    ) % util.escape(new_tag)
            qltk.ErrorMessage(self, title, msg).run()
        else:
            # FIXME: In case this is a special one we only
            # validate one value and never write it back..

            text = entry.value.text
            if not massagers.is_valid(new_tag, text):
                qltk.WarningMessage(
                    self, _("Invalid value"),
                    _("Invalid value: <b>%(value)s</b>\n\n%(error)s") % {
                        "value": text,
                        "error": massagers.error_message(new_tag, text)
                    }).run()
                return
            text = massagers.validate(new_tag, text)

            if entry.origvalue is None:
                # The tag hasn't been saved yet, so we can just update
                # the name in the model, and the value, since it
                # may have been re-validated.
                entry.tag = new_tag
                entry.value = Comment(text)
            else:
                # The tag has been saved, so delete the old tag and
                # add a new one with the old (or sanitized) value.
                entry.renamed = entry.edited = True
                entry.origtag = entry.tag
                entry.tag = new_tag
                if not entry.value.is_special():
                    entry.value = Comment(text)

            entry.canedit = True

            model.row_changed(path, model.get_iter(path))
예제 #6
0
    def __edit_tag_name(self, renderer, path, new_tag, model):
        new_tag = " ".join(new_tag.splitlines()).lower()
        path = Gtk.TreePath.new_from_string(path)
        entry = model[path][0]
        if new_tag == entry.tag:
            return
        elif not self.__songinfo.can_change(new_tag):
            # Can't add the new tag.
            title = _("Invalid tag")
            msg = _(
                "Invalid tag <b>%s</b>\n\nThe files currently" " selected do not support editing this tag."
            ) % util.escape(new_tag)
            qltk.ErrorMessage(self, title, msg).run()
        else:
            # FIXME: In case this is a special one we only
            # validate one value and never write it back..

            text = entry.value.text
            if not massagers.is_valid(new_tag, text):
                qltk.WarningMessage(
                    self,
                    _("Invalid value"),
                    _("Invalid value: <b>%(value)s</b>\n\n%(error)s")
                    % {"value": text, "error": massagers.error_message(new_tag, text)},
                ).run()
                return
            text = massagers.validate(new_tag, text)

            if entry.origvalue is None:
                # The tag hasn't been saved yet, so we can just update
                # the name in the model, and the value, since it
                # may have been re-validated.
                entry.tag = new_tag
                entry.value = Comment(text)
            else:
                # The tag has been saved, so delete the old tag and
                # add a new one with the old (or sanitized) value.
                entry.renamed = entry.edited = True
                entry.origtag = entry.tag
                entry.tag = new_tag
                if not entry.value.is_special():
                    entry.value = Comment(text)

            entry.canedit = True

            model.row_changed(path, model.get_iter(path))
 def test_is_valid_helper(self):
     self.assertTrue(is_valid("foo", "bar"))
     self.assertFalse(is_valid("date", "bar"))
     self.assertTrue(is_valid("date", "2000"))
예제 #8
0
 def test_is_valid_helper(self):
     self.assertTrue(is_valid("foo", "bar"))
     self.assertFalse(is_valid("date", "bar"))
     self.assertTrue(is_valid("date", "2000"))