From 3fd2b2f8383cc11e0cea55348d6508fb3345f791 Mon Sep 17 00:00:00 2001 From: gimick Date: Sat, 4 Sep 2010 12:30:43 +0100 Subject: [PATCH] Import: Show progress bar during bulk import --- pyfpdb/GuiBulkImport.py | 10 ++++---- pyfpdb/fpdb.pyw | 2 +- pyfpdb/fpdb_import.py | 53 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/pyfpdb/GuiBulkImport.py b/pyfpdb/GuiBulkImport.py index a90f566c..e311c68e 100755 --- a/pyfpdb/GuiBulkImport.py +++ b/pyfpdb/GuiBulkImport.py @@ -142,10 +142,12 @@ class GuiBulkImport(): """returns the vbox of this thread""" return self.vbox - def __init__(self, settings, config, sql = None): + def __init__(self, settings, config, parent, sql = None): self.settings = settings self.config = config - self.importer = fpdb_import.Importer(self, self.settings, config, sql) + self.parent = parent + + self.importer = fpdb_import.Importer(self, self.settings, config,parent, sql) self.vbox = gtk.VBox(False, 0) self.vbox.show() @@ -385,7 +387,7 @@ def main(argv=None): print _('-q is deprecated. Just use "-f filename" instead') # This is because -q on its own causes an error, so -f is necessary and sufficient for cmd line use if not options.filename: - i = GuiBulkImport(settings, config) + i = GuiBulkImport(settings, config, None) main_window = gtk.Window() main_window.connect('destroy', destroy) main_window.add(i.vbox) @@ -393,7 +395,7 @@ def main(argv=None): gtk.main() else: #Do something useful - importer = fpdb_import.Importer(False,settings, config) + importer = fpdb_import.Importer(False,settings, config, self.parent) # importer.setDropIndexes("auto") importer.setDropIndexes(_("don't drop")) importer.setFailOnError(options.failOnError) diff --git a/pyfpdb/fpdb.pyw b/pyfpdb/fpdb.pyw index 385d07ef..656284ad 100755 --- a/pyfpdb/fpdb.pyw +++ b/pyfpdb/fpdb.pyw @@ -996,7 +996,7 @@ class fpdb: def tab_bulk_import(self, widget, data=None): """opens a tab for bulk importing""" - new_import_thread = GuiBulkImport.GuiBulkImport(self.settings, self.config, self.sql) + new_import_thread = GuiBulkImport.GuiBulkImport(self.settings, self.config, self.window, self.sql) self.threads.append(new_import_thread) bulk_tab=new_import_thread.get_vbox() self.add_and_display_tab(bulk_tab, _("Bulk Import")) diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index a0f7373a..e9ce1c31 100755 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -70,12 +70,13 @@ else: psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) class Importer: - def __init__(self, caller, settings, config, sql = None): + def __init__(self, caller, settings, config, parent, sql = None): """Constructor""" self.settings = settings self.caller = caller self.config = config self.sql = sql + self.parent = parent #log = Configuration.get_logger("logging.conf", "importer", log_dir=self.config.dir_log) self.filelist = {} @@ -301,7 +302,16 @@ class Importer: totpartial = 0 toterrors = 0 tottime = 0 + progresscount = 0 + progressgoal = len(self.filelist) + + ProgressDialog = ProgressBar(self.parent) + for file in self.filelist: + + progresscount += 1 + ProgressDialog.progress_update(progresscount,progressgoal) + (stored, duplicates, partial, errors, ttime) = self.import_file_dict(db, file ,self.filelist[file][0], self.filelist[file][1], q) totstored += stored @@ -313,6 +323,8 @@ class Importer: print _("sending finish message queue length ="), q.qsize() db.send_finish_msg(q) + del ProgressDialog + return (totstored, totdups, totpartial, toterrors) # end def importFiles @@ -527,6 +539,45 @@ class Importer: logfile.write(str(s) + "\n") logfile.write("\n") logfile.close() + + +class ProgressBar: + + def __del__(self): + self.progress.destroy() + + def progress_update(self, fraction, sum): + + progresspercent = float(fraction) / (float(sum) + 1.0) + x = sometext.center(100) + + self.pbar.set_fraction(progresspercent) + self.pbar.set_text(str(fraction) + " / " + str(sum)) + + def __init__(self, parent): + + self.progress = gtk.Window(gtk.WINDOW_TOPLEVEL) + + self.progress.set_resizable(False) + self.progress.set_modal(True) + self.progress.set_transient_for(parent) + self.progress.set_decorated(False) + + vbox = gtk.VBox(False, 5) + vbox.set_border_width(10) + self.progress.add(vbox) + vbox.show() + + align = gtk.Alignment(0.5, 0.5, 0, 0) + vbox.pack_start(align, True, True, 2) + align.show() + + self.pbar = gtk.ProgressBar() + align.add(self.pbar) + self.pbar.show() + + self.progress.show() + if __name__ == "__main__": print _("CLI for fpdb_import is now available as CliFpdb.py")