本文整理汇总了Python中quodlibet.qltk.cbes.ComboBoxEntrySave类的典型用法代码示例。如果您正苦于以下问题:Python ComboBoxEntrySave类的具体用法?Python ComboBoxEntrySave怎么用?Python ComboBoxEntrySave使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ComboBoxEntrySave类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
quodlibet.config.init()
h, self.fname = mkstemp()
os.close(h)
with open(self.fname, "w") as f:
f.write(self.memory)
with open(self.fname + ".saved", "w") as f:
f.write(self.saved)
self.cbes = ComboBoxEntrySave(self.fname, count=2)
self.cbes2 = ComboBoxEntrySave(self.fname, count=2)
示例2: setUp
def setUp(self):
quodlibet.config.init()
self.fname = tempfile.mkstemp()[1]
f = file(self.fname, "w")
f.write(self.memory)
f.close()
f = file(self.fname + ".saved", "w")
f.write(self.saved)
f.close()
self.cbes = ComboBoxEntrySave(self.fname, count=2)
self.cbes2 = ComboBoxEntrySave(self.fname, count=2)
示例3: __init__
def __init__(self, filename=None, button=True, completion=None,
accel_group=None):
super(SearchBarBox, self).__init__(spacing=6)
if filename is None:
filename = os.path.join(const.USERDIR, "lists", "queries")
combo = ComboBoxEntrySave(filename, count=8,
validator=Query.is_valid_color, title=_("Saved Searches"),
edit_title=_("Edit saved searches..."))
combo.enable_clear_button()
self.__refill_id = None
self.__combo = combo
entry = combo.child
self.__entry = entry
if completion:
entry.set_completion(completion)
self.connect('destroy', lambda w: w.__remove_timeout())
self.__sig = combo.connect('changed', self.__text_changed)
entry.connect('clear', self.__filter_changed)
entry.connect('backspace', self.__text_changed)
entry.connect('populate-popup', self.__menu)
entry.connect('activate', self.__filter_changed)
entry.connect('activate', self.__save_search)
entry.connect('focus-out-event', self.__save_search)
label = gtk.Label(_("_Search:"))
label.set_use_underline(True)
label.connect('mnemonic-activate', self.__mnemonic_activate)
label.set_mnemonic_widget(entry)
self.pack_start(label, expand=False)
self.pack_start(combo)
# search button
if button:
search = Button(_("Search"), gtk.STOCK_FIND,
size=gtk.ICON_SIZE_MENU)
search.connect('clicked', self.__filter_changed)
search.set_tooltip_text(_("Search your library"))
self.pack_start(search, expand=False)
if accel_group:
key, mod = gtk.accelerator_parse("<ctrl>L")
accel_group.connect_group(key, mod, 0,
lambda *x: label.mnemonic_activate(True))
self.show_all()
示例4: __init__
def __init__(self, filename=None, completion=None, accel_group=None,
timeout=DEFAULT_TIMEOUT, validator=Query.validator,
star=None):
super(SearchBarBox, self).__init__(spacing=6)
if filename is None:
filename = os.path.join(
quodlibet.get_user_dir(), "lists", "queries")
combo = ComboBoxEntrySave(filename, count=8,
validator=validator,
title=_("Saved Searches"),
edit_title=_(u"Edit saved searches…"))
self.__deferred_changed = DeferredSignal(
self.__filter_changed, timeout=timeout, owner=self)
self.__combo = combo
entry = combo.get_child()
self.__entry = entry
if completion:
entry.set_completion(completion)
self._star = star
self._query = None
self.__sig = combo.connect('text-changed', self.__text_changed)
entry.connect('clear', self.__filter_changed)
entry.connect('backspace', self.__text_changed)
entry.connect('populate-popup', self.__menu)
entry.connect('activate', self.__filter_changed)
entry.connect('activate', self.__save_search)
entry.connect('focus-out-event', self.__save_search)
entry.connect('key-press-event', self.__key_pressed)
entry.set_placeholder_text(_("Search"))
entry.set_tooltip_text(_("Search your library, "
"using free text or QL queries"))
combo.enable_clear_button()
self.pack_start(combo, True, True, 0)
if accel_group:
key, mod = Gtk.accelerator_parse("<Primary>L")
accel_group.connect(key, mod, 0,
lambda *x: entry.mnemonic_activate(True))
for child in self.get_children():
child.show_all()
示例5: __init__
def __init__(self, parent, library):
super(TagsFromPath, self).__init__(spacing=6)
self.set_border_width(12)
hbox = Gtk.HBox(spacing=6)
cbes_defaults = TBP_EXAMPLES.split("\n")
self.combo = ComboBoxEntrySave(TBP, cbes_defaults,
title=_("Path Patterns"),
edit_title=_(u"Edit saved patterns…"))
self.combo.show_all()
hbox.pack_start(self.combo, True, True, 0)
self.preview = qltk.Button(_("_Preview"), Icons.VIEW_REFRESH)
self.preview.show()
hbox.pack_start(self.preview, False, True, 0)
self.pack_start(hbox, False, True, 0)
self.combo.get_child().connect('changed', self._changed)
model = ObjectStore()
self.view = Gtk.TreeView(model=model)
self.view.show()
sw = Gtk.ScrolledWindow()
sw.set_shadow_type(Gtk.ShadowType.IN)
sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
sw.add(self.view)
self.pack_start(sw, True, True, 0)
vbox = Gtk.VBox()
addreplace = Gtk.ComboBoxText()
addreplace.append_text(_("Tags replace existing ones"))
addreplace.append_text(_("Tags are added to existing ones"))
addreplace.set_active(config.getboolean("tagsfrompath", "add"))
addreplace.connect('changed', self.__add_changed)
vbox.pack_start(addreplace, True, True, 0)
addreplace.show()
self.pack_start(vbox, False, True, 0)
filter_box = FilterPluginBox(self.handler, self.FILTERS)
filter_box.connect("preview", self.__filter_preview)
filter_box.connect("changed", self.__filter_changed)
self.filter_box = filter_box
self.pack_start(filter_box, False, True, 0)
# Save button
self.save = qltk.Button(_("Save"), Icons.DOCUMENT_SAVE)
self.save.show()
bbox = Gtk.HButtonBox()
bbox.set_layout(Gtk.ButtonBoxStyle.END)
bbox.pack_start(self.save, True, True, 0)
self.pack_start(bbox, False, True, 0)
connect_obj(self.preview, 'clicked', self.__preview, None)
connect_obj(parent, 'changed', self.__class__.__preview, self)
# Save changes
connect_obj(self.save, 'clicked', self.__save, addreplace, library)
for child in self.get_children():
child.show()
示例6: __init__
def __init__(self, parent, library):
super(RenameFiles, self).__init__(spacing=6)
self.set_border_width(12)
hbox = Gtk.HBox(spacing=6)
cbes_defaults = NBP_EXAMPLES.split("\n")
self.combo = ComboBoxEntrySave(NBP, cbes_defaults,
title=_("Path Patterns"),
edit_title=_(u"Edit saved patterns…"))
self.combo.show_all()
hbox.pack_start(self.combo, True, True, 0)
self.preview = qltk.Button(_("_Preview"), Icons.VIEW_REFRESH)
self.preview.show()
hbox.pack_start(self.preview, False, True, 0)
self.pack_start(hbox, False, True, 0)
self.combo.get_child().connect('changed', self._changed)
model = ObjectStore()
self.view = Gtk.TreeView(model=model)
self.view.show()
sw = Gtk.ScrolledWindow()
sw.set_shadow_type(Gtk.ShadowType.IN)
sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
sw.add(self.view)
self.pack_start(sw, True, True, 0)
self.pack_start(Gtk.VBox(), False, True, 0)
filter_box = FilterPluginBox(self.handler, self.FILTERS)
filter_box.connect("preview", self.__filter_preview)
filter_box.connect("changed", self.__filter_changed)
self.filter_box = filter_box
self.pack_start(filter_box, False, True, 0)
# Save button
self.save = Button(_("_Save"), Icons.DOCUMENT_SAVE)
self.save.show()
bbox = Gtk.HButtonBox()
bbox.set_layout(Gtk.ButtonBoxStyle.END)
bbox.pack_start(self.save, True, True, 0)
self.pack_start(bbox, False, True, 0)
render = Gtk.CellRendererText()
column = TreeViewColumn(_('File'), render)
def cell_data_file(column, cell, model, iter_, data):
entry = model.get_value(iter_)
cell.set_property("text", entry.name)
column.set_cell_data_func(render, cell_data_file)
column.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
self.view.append_column(column)
render = Gtk.CellRendererText()
render.set_property('editable', True)
column = TreeViewColumn(_('New Name'), render)
def cell_data_new_name(column, cell, model, iter_, data):
entry = model.get_value(iter_)
cell.set_property("text", entry.new_name or u"")
column.set_cell_data_func(render, cell_data_new_name)
column.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
self.view.append_column(column)
connect_obj(self.preview, 'clicked', self.__preview, None)
connect_obj(parent, 'changed', self.__class__.__preview, self)
connect_obj(self.save, 'clicked', self.__rename, library)
render.connect('edited', self.__row_edited)
for child in self.get_children():
child.show()
示例7: RenameFiles
class RenameFiles(Gtk.VBox):
title = _("Rename Files")
FILTERS = [SpacesToUnderscores, StripWindowsIncompat, StripDiacriticals,
StripNonASCII, Lowercase]
handler = RenameFilesPluginHandler()
@classmethod
def init_plugins(cls):
PluginManager.instance.register_handler(cls.handler)
def __init__(self, parent, library):
super(RenameFiles, self).__init__(spacing=6)
self.set_border_width(12)
hbox = Gtk.HBox(spacing=6)
cbes_defaults = NBP_EXAMPLES.split("\n")
self.combo = ComboBoxEntrySave(NBP, cbes_defaults,
title=_("Path Patterns"),
edit_title=_(u"Edit saved patterns…"))
self.combo.show_all()
hbox.pack_start(self.combo, True, True, 0)
self.preview = qltk.Button(_("_Preview"), Icons.VIEW_REFRESH)
self.preview.show()
hbox.pack_start(self.preview, False, True, 0)
self.pack_start(hbox, False, True, 0)
self.combo.get_child().connect('changed', self._changed)
model = ObjectStore()
self.view = Gtk.TreeView(model=model)
self.view.show()
sw = Gtk.ScrolledWindow()
sw.set_shadow_type(Gtk.ShadowType.IN)
sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
sw.add(self.view)
self.pack_start(sw, True, True, 0)
self.pack_start(Gtk.VBox(), False, True, 0)
filter_box = FilterPluginBox(self.handler, self.FILTERS)
filter_box.connect("preview", self.__filter_preview)
filter_box.connect("changed", self.__filter_changed)
self.filter_box = filter_box
self.pack_start(filter_box, False, True, 0)
# Save button
self.save = Button(_("_Save"), Icons.DOCUMENT_SAVE)
self.save.show()
bbox = Gtk.HButtonBox()
bbox.set_layout(Gtk.ButtonBoxStyle.END)
bbox.pack_start(self.save, True, True, 0)
self.pack_start(bbox, False, True, 0)
render = Gtk.CellRendererText()
column = TreeViewColumn(_('File'), render)
def cell_data_file(column, cell, model, iter_, data):
entry = model.get_value(iter_)
cell.set_property("text", entry.name)
column.set_cell_data_func(render, cell_data_file)
column.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
self.view.append_column(column)
render = Gtk.CellRendererText()
render.set_property('editable', True)
column = TreeViewColumn(_('New Name'), render)
def cell_data_new_name(column, cell, model, iter_, data):
entry = model.get_value(iter_)
cell.set_property("text", entry.new_name or u"")
column.set_cell_data_func(render, cell_data_new_name)
column.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
self.view.append_column(column)
connect_obj(self.preview, 'clicked', self.__preview, None)
connect_obj(parent, 'changed', self.__class__.__preview, self)
connect_obj(self.save, 'clicked', self.__rename, library)
render.connect('edited', self.__row_edited)
for child in self.get_children():
child.show()
def __filter_preview(self, *args):
Gtk.Button.clicked(self.preview)
def __filter_changed(self, *args):
self._changed(self.combo.get_child())
def _changed(self, entry):
self.save.set_sensitive(False)
self.preview.set_sensitive(bool(entry.get_text()))
def __row_edited(self, renderer, path, new):
path = Gtk.TreePath.new_from_string(path)
model = self.view.get_model()
#.........这里部分代码省略.........
示例8: TComboBoxEntrySave
class TComboBoxEntrySave(TestCase):
memory = "pattern 1\npattern 2\n"
saved = "pattern text\npattern name\n"
def setUp(self):
quodlibet.config.init()
h, self.fname = mkstemp()
os.close(h)
with open(self.fname, "w") as f:
f.write(self.memory)
with open(self.fname + ".saved", "w") as f:
f.write(self.saved)
self.cbes = ComboBoxEntrySave(self.fname, count=2)
self.cbes2 = ComboBoxEntrySave(self.fname, count=2)
def test_equivalence(self):
model1 = self.cbes.get_model()
model2 = self.cbes2.get_model()
self.failUnlessEqual(model1, model2)
rows1 = list(model1)
rows2 = list(model2)
for row1, row2 in zip(rows1, rows2):
self.failUnlessEqual(row1[0], row2[0])
self.failUnlessEqual(row1[1], row2[1])
self.failUnlessEqual(row1[2], row2[2])
def test_text_changed_signal(self):
called = [0]
def cb(*args):
called[0] += 1
def get_count():
c = called[0]
called[0] = 0
return c
self.cbes.connect("text-changed", cb)
entry = self.cbes.get_child()
entry.set_text("foo")
self.failUnlessEqual(get_count(), 1)
self.cbes.prepend_text("bar")
# in case the model got changed but the entry is still the same
# the text-changed signal should not be triggered
self.failUnlessEqual(entry.get_text(), "foo")
self.failUnlessEqual(get_count(), 0)
def test_shared_model(self):
self.cbes.prepend_text("a test")
self.test_equivalence()
def test_initial_size(self):
# 1 saved, Edit, separator, 2 remembered
self.failUnlessEqual(5, len(self.cbes.get_model()))
def test_prepend_text(self):
self.cbes.prepend_text("pattern 3")
self.memory = "pattern 3\npattern 1\n"
self.test_save()
def test_save(self):
self.cbes.write()
self.failUnlessEqual(self.memory, open(self.fname).read())
self.failUnlessEqual(self.saved, open(self.fname + ".saved").read())
def test_set_text_then_prepend(self):
self.cbes.get_child().set_text("foobar")
self.cbes.prepend_text("foobar")
self.memory = "foobar\npattern 1\n"
self.test_save()
def tearDown(self):
self.cbes.destroy()
self.cbes2.destroy()
os.unlink(self.fname)
os.unlink(self.fname + ".saved")
quodlibet.config.quit()
示例9: TagsFromPath
class TagsFromPath(Gtk.VBox):
title = _("Tags From Path")
FILTERS = [UnderscoresToSpaces, TitleCase, SplitTag]
handler = TagsFromPathPluginHandler()
@classmethod
def init_plugins(cls):
PluginManager.instance.register_handler(cls.handler)
def __init__(self, parent, library):
super(TagsFromPath, self).__init__(spacing=6)
self.set_border_width(12)
hbox = Gtk.HBox(spacing=6)
cbes_defaults = TBP_EXAMPLES.split("\n")
self.combo = ComboBoxEntrySave(TBP, cbes_defaults,
title=_("Path Patterns"),
edit_title=_(u"Edit saved patterns…"))
self.combo.show_all()
hbox.pack_start(self.combo, True, True, 0)
self.preview = qltk.Button(_("_Preview"), Icons.VIEW_REFRESH)
self.preview.show()
hbox.pack_start(self.preview, False, True, 0)
self.pack_start(hbox, False, True, 0)
self.combo.get_child().connect('changed', self._changed)
model = ObjectStore()
self.view = Gtk.TreeView(model=model)
self.view.show()
sw = Gtk.ScrolledWindow()
sw.set_shadow_type(Gtk.ShadowType.IN)
sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
sw.add(self.view)
self.pack_start(sw, True, True, 0)
vbox = Gtk.VBox()
addreplace = Gtk.ComboBoxText()
addreplace.append_text(_("Tags replace existing ones"))
addreplace.append_text(_("Tags are added to existing ones"))
addreplace.set_active(config.getboolean("tagsfrompath", "add"))
addreplace.connect('changed', self.__add_changed)
vbox.pack_start(addreplace, True, True, 0)
addreplace.show()
self.pack_start(vbox, False, True, 0)
filter_box = FilterPluginBox(self.handler, self.FILTERS)
filter_box.connect("preview", self.__filter_preview)
filter_box.connect("changed", self.__filter_changed)
self.filter_box = filter_box
self.pack_start(filter_box, False, True, 0)
# Save button
self.save = qltk.Button(_("Save"), Icons.DOCUMENT_SAVE)
self.save.show()
bbox = Gtk.HButtonBox()
bbox.set_layout(Gtk.ButtonBoxStyle.END)
bbox.pack_start(self.save, True, True, 0)
self.pack_start(bbox, False, True, 0)
connect_obj(self.preview, 'clicked', self.__preview, None)
connect_obj(parent, 'changed', self.__class__.__preview, self)
# Save changes
connect_obj(self.save, 'clicked', self.__save, addreplace, library)
for child in self.get_children():
child.show()
def __filter_preview(self, *args):
Gtk.Button.clicked(self.preview)
def __filter_changed(self, *args):
self._changed(self.combo.get_child())
def _changed(self, entry):
self.save.set_sensitive(False)
self.preview.set_sensitive(bool(entry.get_text()))
def __add_changed(self, combo):
config.set("tagsfrompath", "add", str(bool(combo.get_active())))
def __preview(self, songs):
if songs is None:
songs = [row[0].song for row in (self.view.get_model() or [])]
if songs:
pattern_text = gdecode(self.combo.get_child().get_text())
else:
pattern_text = ""
try:
pattern = TagsFromPattern(pattern_text)
except re.error:
qltk.ErrorMessage(
self, _("Invalid pattern"),
_("The pattern\n\t<b>%s</b>\nis invalid. "
"Possibly it contains the same tag twice or "
"it has unbalanced brackets (< / >).") % (
util.escape(pattern_text))).run()
return
#.........这里部分代码省略.........
示例10: TComboBoxEntrySave
class TComboBoxEntrySave(TestCase):
memory = "pattern 1\npattern 2\n"
saved = "pattern text\npattern name\n"
def setUp(self):
quodlibet.config.init()
self.fname = tempfile.mkstemp()[1]
f = file(self.fname, "w")
f.write(self.memory)
f.close()
f = file(self.fname + ".saved", "w")
f.write(self.saved)
f.close()
self.cbes = ComboBoxEntrySave(self.fname, count=2)
self.cbes2 = ComboBoxEntrySave(self.fname, count=2)
def test_equivalence(self):
model1 = self.cbes.get_model()
model2 = self.cbes2.get_model()
self.failUnlessEqual(model1, model2)
rows1 = list(model1)
rows2 = list(model2)
for row1, row2 in zip(rows1, rows2):
self.failUnlessEqual(row1[0], row2[0])
self.failUnlessEqual(row1[1], row2[1])
self.failUnlessEqual(row1[2], row2[2])
def test_shared_model(self):
self.cbes.append_text("a test")
self.test_equivalence()
def test_initial_size(self):
# 1 saved, Edit, separator, 2 remembered
self.failUnlessEqual(5, len(self.cbes.get_model()))
def test_prepend_text(self):
self.cbes.prepend_text("pattern 3")
self.memory = "pattern 3\npattern 1\n"
self.test_save()
def test_save(self):
self.cbes.write()
self.failUnlessEqual(self.memory, file(self.fname).read())
self.failUnlessEqual(self.saved, file(self.fname + ".saved").read())
def test_set_text_then_prepend(self):
self.cbes.child.set_text("foobar")
self.cbes.prepend_text("foobar")
self.memory = "foobar\npattern 1\n"
self.test_save()
def tearDown(self):
self.cbes.destroy()
self.cbes2.destroy()
os.unlink(self.fname)
os.unlink(self.fname + ".saved")
quodlibet.config.quit()
示例11: __init__
def __init__(self, parent, library):
super(RenameFiles, self).__init__(spacing=6)
self.__skip_interactive = False
self.set_border_width(12)
hbox = Gtk.HBox(spacing=6)
cbes_defaults = NBP_EXAMPLES.split("\n")
self.combo = ComboBoxEntrySave(NBP, cbes_defaults,
title=_("Path Patterns"),
edit_title=_(u"Edit saved patterns…"))
self.combo.show_all()
hbox.pack_start(self.combo, True, True, 0)
self.preview = qltk.Button(_("_Preview"), Icons.VIEW_REFRESH)
self.preview.show()
hbox.pack_start(self.preview, False, True, 0)
self.pack_start(hbox, False, True, 0)
self.combo.get_child().connect('changed', self._changed)
model = ObjectStore()
self.view = Gtk.TreeView(model=model)
self.view.show()
sw = Gtk.ScrolledWindow()
sw.set_shadow_type(Gtk.ShadowType.IN)
sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
sw.add(self.view)
self.pack_start(sw, True, True, 0)
self.pack_start(Gtk.VBox(), False, True, 0)
# rename options
rename_options = Gtk.HBox()
# file name options
filter_box = FilterPluginBox(self.handler, self.FILTERS)
filter_box.connect("preview", self.__filter_preview)
filter_box.connect("changed", self.__filter_changed)
self.filter_box = filter_box
frame_filename_options = Frame(_("File names"), filter_box)
frame_filename_options.show_all()
rename_options.pack_start(frame_filename_options, False, True, 0)
# album art options
albumart_box = Gtk.VBox()
# move art
moveart_box = Gtk.VBox()
self.moveart = ConfigCheckButton(
_('_Move album art'),
"rename", "move_art", populate=True)
self.moveart.set_tooltip_text(
_("See '[albumart] filenames' config entry " +
"for image search strings"))
self.moveart.show()
moveart_box.pack_start(self.moveart, False, True, 0)
self.moveart_overwrite = ConfigCheckButton(
_('_Overwrite album art at target'),
"rename", "move_art_overwrite", populate=True)
self.moveart_overwrite.show()
moveart_box.pack_start(self.moveart_overwrite, False, True, 0)
albumart_box.pack_start(moveart_box, False, True, 0)
# remove empty
removeemptydirs_box = Gtk.VBox()
self.removeemptydirs = ConfigCheckButton(
_('_Remove empty directories'),
"rename", "remove_empty_dirs", populate=True)
self.removeemptydirs.show()
removeemptydirs_box.pack_start(self.removeemptydirs, False, True, 0)
albumart_box.pack_start(removeemptydirs_box, False, True, 0)
frame_albumart_options = Frame(_("Album art"), albumart_box)
frame_albumart_options.show_all()
rename_options.pack_start(frame_albumart_options, False, True, 0)
self.pack_start(rename_options, False, True, 0)
# Save button
self.save = Button(_("_Save"), Icons.DOCUMENT_SAVE)
self.save.show()
bbox = Gtk.HButtonBox()
bbox.set_layout(Gtk.ButtonBoxStyle.END)
bbox.pack_start(self.save, True, True, 0)
self.pack_start(bbox, False, True, 0)
render = Gtk.CellRendererText()
column = TreeViewColumn(title=_('File'))
column.pack_start(render, True)
def cell_data_file(column, cell, model, iter_, data):
entry = model.get_value(iter_)
cell.set_property("text", entry.name)
column.set_cell_data_func(render, cell_data_file)
column.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
self.view.append_column(column)
render = Gtk.CellRendererText()
render.set_property('editable', True)
#.........这里部分代码省略.........
示例12: RenameFiles
class RenameFiles(Gtk.VBox):
title = _("Rename Files")
FILTERS = [SpacesToUnderscores, StripWindowsIncompat, StripDiacriticals,
StripNonASCII, Lowercase]
handler = RenameFilesPluginHandler()
IMAGE_EXTENSIONS = ['jpg', 'jpeg', 'png', 'bmp']
@classmethod
def init_plugins(cls):
PluginManager.instance.register_handler(cls.handler)
def __init__(self, parent, library):
super(RenameFiles, self).__init__(spacing=6)
self.__skip_interactive = False
self.set_border_width(12)
hbox = Gtk.HBox(spacing=6)
cbes_defaults = NBP_EXAMPLES.split("\n")
self.combo = ComboBoxEntrySave(NBP, cbes_defaults,
title=_("Path Patterns"),
edit_title=_(u"Edit saved patterns…"))
self.combo.show_all()
hbox.pack_start(self.combo, True, True, 0)
self.preview = qltk.Button(_("_Preview"), Icons.VIEW_REFRESH)
self.preview.show()
hbox.pack_start(self.preview, False, True, 0)
self.pack_start(hbox, False, True, 0)
self.combo.get_child().connect('changed', self._changed)
model = ObjectStore()
self.view = Gtk.TreeView(model=model)
self.view.show()
sw = Gtk.ScrolledWindow()
sw.set_shadow_type(Gtk.ShadowType.IN)
sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
sw.add(self.view)
self.pack_start(sw, True, True, 0)
self.pack_start(Gtk.VBox(), False, True, 0)
# rename options
rename_options = Gtk.HBox()
# file name options
filter_box = FilterPluginBox(self.handler, self.FILTERS)
filter_box.connect("preview", self.__filter_preview)
filter_box.connect("changed", self.__filter_changed)
self.filter_box = filter_box
frame_filename_options = Frame(_("File names"), filter_box)
frame_filename_options.show_all()
rename_options.pack_start(frame_filename_options, False, True, 0)
# album art options
albumart_box = Gtk.VBox()
# move art
moveart_box = Gtk.VBox()
self.moveart = ConfigCheckButton(
_('_Move album art'),
"rename", "move_art", populate=True)
self.moveart.set_tooltip_text(
_("See '[albumart] filenames' config entry " +
"for image search strings"))
self.moveart.show()
moveart_box.pack_start(self.moveart, False, True, 0)
self.moveart_overwrite = ConfigCheckButton(
_('_Overwrite album art at target'),
"rename", "move_art_overwrite", populate=True)
self.moveart_overwrite.show()
moveart_box.pack_start(self.moveart_overwrite, False, True, 0)
albumart_box.pack_start(moveart_box, False, True, 0)
# remove empty
removeemptydirs_box = Gtk.VBox()
self.removeemptydirs = ConfigCheckButton(
_('_Remove empty directories'),
"rename", "remove_empty_dirs", populate=True)
self.removeemptydirs.show()
removeemptydirs_box.pack_start(self.removeemptydirs, False, True, 0)
albumart_box.pack_start(removeemptydirs_box, False, True, 0)
frame_albumart_options = Frame(_("Album art"), albumart_box)
frame_albumart_options.show_all()
rename_options.pack_start(frame_albumart_options, False, True, 0)
self.pack_start(rename_options, False, True, 0)
# Save button
self.save = Button(_("_Save"), Icons.DOCUMENT_SAVE)
self.save.show()
bbox = Gtk.HButtonBox()
bbox.set_layout(Gtk.ButtonBoxStyle.END)
bbox.pack_start(self.save, True, True, 0)
self.pack_start(bbox, False, True, 0)
render = Gtk.CellRendererText()
column = TreeViewColumn(title=_('File'))
column.pack_start(render, True)
#.........这里部分代码省略.........