Separate some general code from GUI specific code - particularly for graph generators so that graphs can be generated from the CLI.

svn: r16838
This commit is contained in:
Brian Matherly
2011-03-17 03:02:36 +00:00
parent 12a01f6700
commit e6befe67b9
15 changed files with 959 additions and 1049 deletions

View File

@ -29,7 +29,8 @@
#-------------------------------------------------------------------------
import os
from types import ClassType
from gen.ggettext import gettext as _
import threading
import time
import logging
LOG = logging.getLogger(".")
@ -46,8 +47,10 @@ import gtk
# GRAMPS modules
#
#-------------------------------------------------------------------------
from gen.ggettext import gettext as _
import config
import Errors
from gui.utils import ProgressMeter, open_file_with_default_application
from QuestionDialog import ErrorDialog, OptionDialog
from gen.plug.report import (CATEGORY_TEXT, CATEGORY_DRAW, CATEGORY_BOOK,
CATEGORY_CODE, CATEGORY_WEB, CATEGORY_GRAPHVIZ,
@ -66,6 +69,43 @@ import Utils
#-------------------------------------------------------------------------
URL_REPORT_PAGE = URL_MANUAL_PAGE + "_-_Reports"
#-------------------------------------------------------------------------------
#
# Private Functions
#
#-------------------------------------------------------------------------------
def _run_long_process_in_thread(func, header):
"""
This function will spawn a new thread to execute the provided function.
While the function is running, a progress bar will be created.
The progress bar will show activity while the function executes.
@param func: A function that will take an unknown amount of time to
complete.
@type category: callable
@param header: A header for the progress bar.
Example: "Updating Data"
@type name: string
@return: nothing
"""
pbar = ProgressMeter(_('Processing File'))
pbar.set_pass(total=40,
mode=ProgressMeter.MODE_ACTIVITY,
header=header)
sys_thread = threading.Thread(target=func)
sys_thread.start()
while sys_thread.isAlive():
# The loop runs 20 times per second until the thread completes.
# With the progress pass total set at 40, it should move across the bar
# every two seconds.
time.sleep(0.05)
pbar.step()
pbar.close()
#-------------------------------------------------------------------------
#
# ReportDialog class
@ -644,10 +684,18 @@ def report(dbstate, uistate, person, report_class, options_class,
dialog.close()
try:
MyReport = report_class(dialog.db, dialog.options)
MyReport.doc.init()
MyReport.begin_report()
MyReport.write_report()
MyReport.end_report()
def do_report():
MyReport.doc.init()
MyReport.begin_report()
MyReport.write_report()
MyReport.end_report()
_run_long_process_in_thread(do_report, dialog.raw_name)
if dialog.open_with_app.get_active():
open_file_with_default_application(dialog.options.get_output())
except Errors.FilterError, msg:
(m1, m2) = msg.messages()
ErrorDialog(m1, m2)