###################################################################### # Copyright (c) 2007, Petteri Aimonen # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # * Redistributions of source code must retain the above copyright # notice and this list of conditions. # * Redistributions in binary form must reproduce the above copyright # notice and this list of conditions in the documentation and/or other # materials provided with the distribution. '''GUI progress dialog for data import''' import wx from pymisc import _ from importlog import ImportLogger from upkeep import getupkeeptasks from dataimport import getimporttasks def do_guiimport(): '''Import all files and do upkeep. Shows progressdialog. Returns ImportLogger instance.''' logger = ImportLogger() tasks = getimporttasks(logger) tasks += getupkeeptasks(logger) # Last upkeep task is db save # Placeholder to get dialog size about right # MSW has some strangeness about this if wx.Platform == 'MSW': message = "Importing datafiles..." else: message = 'n' * max([len(r[0]) for r in tasks]) dialog = wx.ProgressDialog(title = _('Data import in progress'), message = message, maximum = len(tasks), style = wx.PD_CAN_ABORT | wx.PD_APP_MODAL) i = 0 for description, function, args, kwargs in tasks: if not dialog.Update(i, description): # User canceled logger.log_cancel() break i += 1 function(*args, **kwargs) dialog.Destroy() return logger