Update
svn: r7196
This commit is contained in:
parent
fc7e453f2e
commit
f95f7496de
@ -45,6 +45,7 @@ import gtk
|
|||||||
import GrampsDisplay
|
import GrampsDisplay
|
||||||
import Assistant
|
import Assistant
|
||||||
import Errors
|
import Errors
|
||||||
|
from BasicUtils import UpdateCallback
|
||||||
from PluginUtils import Tool, register_tool
|
from PluginUtils import Tool, register_tool
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
@ -58,6 +59,7 @@ class MediaMan(Tool.Tool):
|
|||||||
|
|
||||||
Tool.Tool.__init__(self, dbstate, options_class, name)
|
Tool.Tool.__init__(self, dbstate, options_class, name)
|
||||||
self.uistate = uistate
|
self.uistate = uistate
|
||||||
|
self.callback = uistate.pulse_progressbar
|
||||||
|
|
||||||
self.build_batch_ops()
|
self.build_batch_ops()
|
||||||
self.batch_settings = None
|
self.batch_settings = None
|
||||||
@ -137,7 +139,7 @@ class MediaMan(Tool.Tool):
|
|||||||
if not group:
|
if not group:
|
||||||
group = button
|
group = button
|
||||||
self.batch_op_buttons.append(button)
|
self.batch_op_buttons.append(button)
|
||||||
table.attach(button,0,2,2*ix,2*ix+1)
|
table.attach(button,0,2,2*ix,2*ix+1,yoptions=0)
|
||||||
tip.set_tip(button,description)
|
tip.set_tip(button,description)
|
||||||
|
|
||||||
box.add(table)
|
box.add(table)
|
||||||
@ -186,10 +188,7 @@ class MediaMan(Tool.Tool):
|
|||||||
elif self.batch_settings:
|
elif self.batch_settings:
|
||||||
self.w.remove_page(self.settings_page)
|
self.w.remove_page(self.settings_page)
|
||||||
self.batch_settings = None
|
self.batch_settings = None
|
||||||
title = self.batch_ops[ix][3][0]
|
title,box = self.batch_ops[ix][3]
|
||||||
settings_box_class = self.batch_ops[ix][3][1]
|
|
||||||
self.settings_box_instance = settings_box_class()
|
|
||||||
box = self.settings_box_instance.get_option_box()
|
|
||||||
self.settings_page = self.w.insert_page(title,box,
|
self.settings_page = self.w.insert_page(title,box,
|
||||||
self.selection_page+1)
|
self.selection_page+1)
|
||||||
self.confirm_page += 1
|
self.confirm_page += 1
|
||||||
@ -207,7 +206,7 @@ class MediaMan(Tool.Tool):
|
|||||||
ix = self.get_selected_op_index()
|
ix = self.get_selected_op_index()
|
||||||
batch_op = self.batch_ops[ix][0]
|
batch_op = self.batch_ops[ix][0]
|
||||||
self.pre_run()
|
self.pre_run()
|
||||||
success = batch_op()
|
success = batch_op(self.db,self.callback)
|
||||||
self.post_run()
|
self.post_run()
|
||||||
return success
|
return success
|
||||||
|
|
||||||
@ -244,22 +243,88 @@ class MediaMan(Tool.Tool):
|
|||||||
# These are the actuall sub-tools (batch-ops) for use from Assistant
|
# These are the actuall sub-tools (batch-ops) for use from Assistant
|
||||||
#
|
#
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
class PathChange:
|
class BatchOp:
|
||||||
def __init__(self):
|
"""
|
||||||
self.title = _('Change path')
|
Base class for the sub-tools.
|
||||||
self.description = _('This tool allows changing specified path '
|
"""
|
||||||
'into another specified path')
|
title = 'Untitled operation'
|
||||||
|
description = 'This operation needs to be described'
|
||||||
|
|
||||||
|
## def __init__(self,db,callback):
|
||||||
|
## self.db = db
|
||||||
|
## self.callback = callback
|
||||||
|
|
||||||
def build_config(self):
|
def build_config(self):
|
||||||
|
"""
|
||||||
|
This method should return either None (if the batch op requires
|
||||||
|
no settings to run) or a tuple (title,box) for the settings page.
|
||||||
|
"""
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def run_tool(self):
|
def run_tool(self,db,callback):
|
||||||
print "Running PathChange tool... done."
|
print "Running BatchOp tool... done."
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def get_self(self):
|
def get_self(self):
|
||||||
return (self.run_tool,self.title,self.description,self.build_config())
|
return (self.run_tool,self.title,self.description,self.build_config())
|
||||||
|
|
||||||
|
class PathChange(BatchOp):
|
||||||
|
title = _('Change path')
|
||||||
|
description = _('This tool allows changing specified path '
|
||||||
|
'into another specified path')
|
||||||
|
|
||||||
|
def build_config(self):
|
||||||
|
title = _("Change path settings")
|
||||||
|
|
||||||
|
box = gtk.VBox()
|
||||||
|
box.set_spacing(12)
|
||||||
|
|
||||||
|
table = gtk.Table(2,2)
|
||||||
|
table.set_row_spacings(6)
|
||||||
|
table.set_col_spacings(6)
|
||||||
|
|
||||||
|
self.from_entry = gtk.Entry()
|
||||||
|
table.attach(self.from_entry,1,2,0,1,yoptions=0)
|
||||||
|
|
||||||
|
from_label = gtk.Label(_('_Replace:'))
|
||||||
|
from_label.set_use_underline(True)
|
||||||
|
from_label.set_alignment(0,0.5)
|
||||||
|
from_label.set_mnemonic_widget(self.from_entry)
|
||||||
|
table.attach(from_label,0,1,0,1,xoptions=0,yoptions=0)
|
||||||
|
|
||||||
|
self.to_entry = gtk.Entry()
|
||||||
|
table.attach(self.to_entry,1,2,1,2,yoptions=0)
|
||||||
|
|
||||||
|
to_label = gtk.Label(_('_With:'))
|
||||||
|
to_label.set_use_underline(True)
|
||||||
|
to_label.set_alignment(0,0.5)
|
||||||
|
to_label.set_mnemonic_widget(self.to_entry)
|
||||||
|
table.attach(to_label,0,1,1,2,xoptions=0,yoptions=0)
|
||||||
|
|
||||||
|
box.add(table)
|
||||||
|
|
||||||
|
return (title,box)
|
||||||
|
|
||||||
|
def run_tool(self,db,callback):
|
||||||
|
uc = UpdateCallback(callback)
|
||||||
|
uc.set_total(db.get_number_of_media_objects())
|
||||||
|
from_text = unicode(self.from_entry.get_text())
|
||||||
|
to_text = unicode(self.to_entry.get_text())
|
||||||
|
trans = db.transaction_begin("",batch=True)
|
||||||
|
db.disable_signals()
|
||||||
|
for handle in db.get_media_object_handles():
|
||||||
|
obj = db.get_object_from_handle(handle)
|
||||||
|
if obj.get_path().find(from_text) != -1:
|
||||||
|
new_path = obj.get_path().replace(from_text,to_text)
|
||||||
|
obj.set_path(new_path)
|
||||||
|
db.commit_media_object(obj,trans)
|
||||||
|
uc.update()
|
||||||
|
db.transaction_commit(trans,self.title)
|
||||||
|
db.enable_signals()
|
||||||
|
db.request_rebuild()
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user