Python RenameExtension Example

说明

python renameextension示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: Python

命名空间/包名称: plugin_baserename_extension

示例#1
文件: letter_case.py项目: ArseniyK/Sunflower

	def __init__(self, parent):
		RenameExtension.__init__(self, parent)

		self._basename_methods = (
					(_('Do nothing'), self.__do_nothing),
					(_('Capitalize'), self.__capitalize),
					(_('Upper case'), self.__upper),
					(_('Lower case'), self.__lower),
					(_('Swap case'), self.__swap),
				)

		self._extension_methods = (
					(_('Do nothing'), self.__do_nothing),
					(_('Upper case'), self.__upper),
					(_('Lower case'), self.__lower),
				)

		# create labels
		label_basename = gtk.Label(_('Item name:'))
		label_basename.set_alignment(0, 0.5)

		label_extension = gtk.Label(_('Extension:'))
		label_extension.set_alignment(0, 0.5)

		# create combo boxes
		self._combo_basename = gtk.combo_box_new_text()
		self._combo_basename.connect('changed', self._update_parent_list)

		self._combo_extension = gtk.combo_box_new_text()
		self._combo_extension.connect('changed', self._update_parent_list)

		# fill comboboxes
		for method in self._basename_methods:
			self._combo_basename.append_text(method[0])

		for method in self._extension_methods:
			self._combo_extension.append_text(method[0])

		self._combo_basename.set_active(0)
		self._combo_extension.set_active(0)

		# pack gui
		table = gtk.Table(2, 2, False)
		table.set_col_spacing(0, 5)
		table.set_row_spacings(5)

		table.attach(label_basename, 0, 1, 0, 1, xoptions=gtk.FILL)
		table.attach(label_extension, 0, 1, 1, 2, xoptions=gtk.FILL)

		table.attach(self._combo_basename, 1, 2, 0, 1, xoptions=gtk.FILL)
		table.attach(self._combo_extension, 1, 2, 1, 2, xoptions=gtk.FILL)

		self.vbox.pack_start(table, False, False, 0)

示例#2
文件: audio_metadata.py项目: Alwnikrotikz/sunflower-fm

	def __init__(self, parent):
		RenameExtension.__init__(self, parent)

		self._templates = {
					'[a]': ('album', _('Album')),
					'[A]': ('artist', _('Artist')),
					'[T]': ('title', _('Title')),
					'[G]': ('genre', _('Genre')),
					'[D]': ('date', _('Date')),
					'[t]': ('tracknumber', _('Track number')),
				}

		# create template entry
		label_template = gtk.Label(_('Template:'))
		label_template.set_alignment(0, 0.5)

		self._entry_template = gtk.Entry()
		self._entry_template.set_text('[[t]] [A] - [T]')
		self._entry_template.connect('changed', self._update_parent_list)

		# create replace entry
		label_replace1 = gtk.Label(_('Replace:'))
		label_replace1.set_alignment(0, 0.5)

		self._entry_replace = gtk.Entry()
		self._entry_replace.set_text(',?/')
		self._entry_replace.connect('changed', self._update_parent_list)

		# create replace combo boxes
		label_replace2 = gtk.Label(_('With:'))
		label_replace2.set_alignment(0, 0.5)

		self._combobox_replace = gtk.combo_box_entry_new_text()
		self._combobox_replace.connect('changed', self._update_parent_list)

		for str_rep in ('_', '-', ''):
			self._combobox_replace.append_text(str_rep)

		# create syntax
		label_tip = gtk.Label()
		label_tip.set_alignment(0, 0)
		label_tip.set_use_markup(True)
		label_tip.set_markup('<b>{0}</b>\n{1}'.format(_('Template syntax'),
			'\n'.join(['{0}\t{1}'.format(k, v[1]) for k, v in self._templates.iteritems()])))

		# create boxes
		hbox = gtk.HBox(True, 15)
		vbox_left = gtk.VBox(False, 5)
		vbox_right = gtk.VBox(False, 0)
		vbox_template = gtk.VBox(False, 0)
		table_replace = gtk.Table(2, 2, False)
		table_replace.set_border_width(5)

		frame_replace = gtk.Frame(label=_('Character replacement'))

		# disable checkbox if mutagen is not available
		self._checkbox_active.set_sensitive(USE_MUTAGEN)

		# create warning label
		label_warning = gtk.Label(_(
							'In order to use this extension you need <b>mutagen</b> module installed!'
						))
		label_warning.set_use_markup(True)
		label_warning.set_property('no-show-all', USE_MUTAGEN)

		# pack gui
		vbox_template.pack_start(label_template, False, False, 0)
		vbox_template.pack_start(self._entry_template, False, False, 0)

		self.vbox.remove(self._checkbox_active)

		table_replace.attach(label_replace1, 0, 1, 0, 1)
		table_replace.attach(self._entry_replace, 1, 2, 0, 1, xoptions=gtk.FILL)
		table_replace.attach(label_replace2, 0, 1, 1, 2)
		table_replace.attach(self._combobox_replace, 1, 2, 1, 2, xoptions=gtk.FILL)

		frame_replace.add(table_replace)

		vbox_left.pack_start(self._checkbox_active, False, False, 0)
		vbox_left.pack_start(vbox_template, False, False, 0)
		vbox_left.pack_start(frame_replace, False, False, 0)

		vbox_right.pack_start(label_tip, False, False, 0)

		hbox.pack_start(vbox_left, True, True, 0)
		hbox.pack_start(vbox_right, True, True, 0)

		self.vbox.pack_start(hbox, False, False, 0)
		self.vbox.pack_end(label_warning, False, False, 0)

示例#3
文件: default.py项目: SmokeyCosmy/Sunflower

	def __init__(self, parent):
		RenameExtension.__init__(self, parent)

		# default option needs to be active by default
		self._checkbox_active.set_active(True)

		# create expressions
		self._regexp_name = re.compile('\[(N|E|C)([\d][^-]*)?-?([\d][^\]]*)?\]', re.I | re.U)

		self._template = '[N][E]'
		self._counter = 0
		self._counter_start = 0
		self._counter_step = 1
		self._counter_digits = 1

		# create user interface
		hbox = gtk.HBox(True, 15)

		vbox_left = gtk.VBox(False, 5)
		vbox_right = gtk.VBox(False, 5)

		# help
		label_help = gtk.Label()
		label_help.set_alignment(0, 0)
		label_help.set_use_markup(True)

		label_help.set_markup(_(
							'<b>Template syntax</b>\n'
							'[N]\tItem name\n'
							'[E]\tExtension\n'
							'[C]\tCounter\n\n'
							'For name and extension you can\n'
							'use range in format [N#-#].'
						))

		# template
		vbox_template = gtk.VBox(False, 0)
		hbox_template = gtk.HBox(False, 2)

		label_template = gtk.Label(_('Template:'))
		label_template.set_alignment(0, 0.5)

		self._entry_template = gtk.Entry()
		self._entry_template.set_text(self._template)
		self._entry_template.connect('changed', self.__template_changed)

		style = gtk.RcStyle()
		style.xthickness = 0
		style.ythickness = 0

		image_add = gtk.Image()
		image_add.set_from_stock(gtk.STOCK_ADD, gtk.ICON_SIZE_BUTTON)
		button_add = gtk.Button()
		button_add.set_image(image_add)
		button_add.modify_style(style)
		button_add.connect('clicked', self.__button_add_clicked)

		# create popup menu
		self._add_menu = gtk.Menu()

		item_add_name = gtk.MenuItem(label=_('Name'))
		item_add_name.connect('activate', self.__add_to_template, 'N')

		item_add_name_part = gtk.MenuItem(label=_('Part of name'))
		item_add_name_part.connect('activate', self.__add_range_to_template, 'N')

		item_separator1 = gtk.SeparatorMenuItem()

		item_add_extension = gtk.MenuItem(label=_('Extension'))
		item_add_extension.connect('activate', self.__add_to_template, 'E')

		item_add_extension_part = gtk.MenuItem(label=_('Part of extension'))
		item_add_extension_part.connect('activate', self.__add_range_to_template, 'E')

		item_separator2 = gtk.SeparatorMenuItem()

		item_add_counter = gtk.MenuItem(label=_('Counter'))
		item_add_counter.connect('activate', self.__add_to_template, 'C')

		self._add_menu.append(item_add_name)
		self._add_menu.append(item_add_name_part)
		self._add_menu.append(item_separator1)
		self._add_menu.append(item_add_extension)
		self._add_menu.append(item_add_extension_part)
		self._add_menu.append(item_separator2)
		self._add_menu.append(item_add_counter)

		self._add_menu.show_all()

		# counter
		frame_counter = gtk.Frame(label=_('Counter'))

		table_counter = gtk.Table(3, 2)
		table_counter.set_border_width(5)
		table_counter.set_col_spacings(5)

		label_start = gtk.Label(_('Start:'))
		label_start.set_alignment(0, 0.5)

		adjustment = gtk.Adjustment(0, 0, 10**10, 1, 10)
		self._entry_start = gtk.SpinButton(adjustment, 0, 0)
		self._entry_start.connect('value-changed', self.__counter_changed)

		label_step = gtk.Label(_('Step:'))
		label_step.set_alignment(0, 0.5)

		adjustment = gtk.Adjustment(1, 1, 10**10, 1, 10)
		self._entry_step = gtk.SpinButton(adjustment, 0, 0)
		self._entry_step.connect('value-changed', self.__counter_changed)

		label_digits = gtk.Label(_('Digits:'))
		label_digits.set_alignment(0, 0.5)

		adjustment = gtk.Adjustment(1, 1, 20, 1, 5)
		self._entry_digits = gtk.SpinButton(adjustment, 0, 0)
		self._entry_digits.connect('value-changed', self.__counter_changed)

		# repack 'active' check box
		self.vbox.remove(self._checkbox_active)
		vbox_left.pack_start(self._checkbox_active, False, False, 0)

		# pack interface
		table_counter.attach(label_start, 0, 1, 0, 1)
		table_counter.attach(self._entry_start, 0, 1, 1, 2, xoptions=gtk.EXPAND|gtk.FILL)
		table_counter.attach(label_step, 1, 2, 0, 1)
		table_counter.attach(self._entry_step, 1, 2, 1, 2, xoptions=gtk.EXPAND|gtk.FILL)
		table_counter.attach(label_digits, 2, 3, 0, 1)
		table_counter.attach(self._entry_digits, 2, 3, 1, 2, xoptions=gtk.EXPAND|gtk.FILL)

		frame_counter.add(table_counter)

		hbox_template.pack_start(self._entry_template, True, True, 0)
		hbox_template.pack_start(button_add, False, False, 0)

		vbox_template.pack_start(label_template, False, False, 0)
		vbox_template.pack_start(hbox_template, False, False, 0)

		vbox_left.pack_start(vbox_template, False, False, 0)
		vbox_left.pack_start(frame_counter, False, False, 0)

		vbox_right.pack_start(label_help, True, True, 0)

		hbox.pack_start(vbox_left, True, True, 0)
		hbox.pack_start(vbox_right, True, True, 0)

		self.vbox.pack_start(hbox, True, True, 0)

		self.vbox.show_all()

展开阅读全文