2006-05-22 Alex Roitman <shura@gramps-project.org>

* src/ArgHandler.py (need_gui): Add method.
	* src/ViewManager.py: Move statusbar notification from gramps_main.
	* src/gramps_main.py: Remove unused methods, handle ArgHandler better.



svn: r6749
This commit is contained in:
Alex Roitman 2006-05-22 18:07:12 +00:00
parent 9056f20f16
commit 9fa0c2bd12
4 changed files with 73 additions and 51 deletions

View File

@ -1,3 +1,8 @@
2006-05-22 Alex Roitman <shura@gramps-project.org>
* src/ArgHandler.py (need_gui): Add method.
* src/ViewManager.py: Move statusbar notification from gramps_main.
* src/gramps_main.py: Remove unused methods, handle ArgHandler better.
2006-05-21 Don Allingham <don@gramps-project.org>
* src/ViewManager.py: handle export, import, and save as if
database does not exist, yet UIManager still wants to call them.

View File

@ -58,9 +58,7 @@ import Utils
from PluginUtils import Report, Tool, cl_list, cli_tool_list
#-------------------------------------------------------------------------
#
# ArgHandler
#
#-------------------------------------------------------------------------
class ArgHandler:
"""
@ -104,33 +102,33 @@ class ArgHandler:
self.imports = []
self.parse_args()
self.handle_args()
#-------------------------------------------------------------------------
#
# Argument parser: sorts out given arguments
#
#-------------------------------------------------------------------------
def parse_args(self):
"""
Fill in lists with open, exports, imports, and actions options.
Any parsing errors lead to abort via os._exit(1).
"""
try:
options,leftargs = getopt.getopt(self.args[1:],
const.shortopts,const.longopts)
const.shortopts,const.longopts)
except getopt.GetoptError:
# return without filling anything if we could not parse the args
print "Error parsing arguments: %s " % self.args[1:]
return
os._exit(1)
if leftargs:
# if there were an argument without option, use it as a file to
# open and return
# if there were an argument without option,
# use it as a file to open and return
self.open_gui = leftargs[0]
print "Trying to open: %s ..." % leftargs[0]
return
# Go over all given option and place them into appropriate lists
for opt_ix in range(len(options)):
o,v = options[opt_ix]
if o in ( '-O', '--open'):
@ -248,12 +246,33 @@ class ArgHandler:
and options[opt_ix+1][0] in ( '-p', '--options' ):
options_str = options[opt_ix+1][1]
self.actions.append((action,options_str))
#-------------------------------------------------------------------------
# Determine the need for GUI
#-------------------------------------------------------------------------
def need_gui(self):
"""
Determine whether we need a GUI session for the given tasks.
"""
if self.open_gui:
# No-option argument, definitely GUI
return True
# If we have data to work with:
if (self.open or self.imports):
if (self.exports or self.actions):
# have both data and what to do with it => no GUI
return False
else:
# data given, but no action/export => GUI
return True
# No data, can only do GUI here
return True
#-------------------------------------------------------------------------
#
# Overall argument handler:
# sorts out the sequence and details of operations
#
#-------------------------------------------------------------------------
def handle_args(self):
"""

View File

@ -416,6 +416,11 @@ class ViewManager:
self.build_report_menu()
self.fileactions.set_sensitive(True)
self.uistate.widget.set_sensitive(True)
Config.client.notify_add("/apps/gramps/interface/statusbar",
self.statusbar_key_update)
def statusbar_key_update(self,client,cnxn_id,entry,data):
self.uistate.modify_statusbar()
def post_init_interface(self):
# Showing the main window is deferred so that

View File

@ -20,16 +20,24 @@
# $Id$
#-------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
from gettext import gettext as _
import os
import platform
import logging
log = logging.getLogger(".")
#-------------------------------------------------------------------------
#
# GTK+/GNOME modules
#
#-------------------------------------------------------------------------
import gtk
import logging
import os
log = logging.getLogger(".")
#-------------------------------------------------------------------------
#
@ -46,13 +54,14 @@ import TipOfDay
import DataViews
from Mime import mime_type_is_defined
from QuestionDialog import ErrorDialog
from gettext import gettext as _
#-------------------------------------------------------------------------
#
# helper functions
#
#-------------------------------------------------------------------------
iconpaths = [const.image_dir,"."]
import platform
if platform.system() == "Windows":
person_icon = "person.png"
relation_icon = "relation.png"
@ -132,7 +141,11 @@ def build_user_paths():
if not os.path.isdir(path):
os.mkdir(path)
#-------------------------------------------------------------------------
#
# Main Gramps class
#
#-------------------------------------------------------------------------
class Gramps:
"""
Main class corresponding to a running gramps process.
@ -169,7 +182,6 @@ class Gramps:
gtk.main_quit()
return
register_stock_icons()
state = GrampsDb.DbState()
@ -178,28 +190,23 @@ class Gramps:
self.vm.register_view(view)
self.vm.init_interface()
ArgHandler.ArgHandler(state,self.vm,args)
self.vm.post_init_interface()
# Depending on the nature of this session,
# we may need to change the order of operation
ah = ArgHandler.ArgHandler(state,self.vm,args)
if ah.need_gui():
self.vm.post_init_interface()
ah.handle_args()
else:
ah.handle_args()
self.vm.post_init_interface()
state.db.request_rebuild()
state.change_active_person(state.db.get_default_person())
# Don't show main window until ArgHandler is done.
# This prevents a window from annoyingly popping up when
# the command line args are sufficient to operate without it.
Config.client.notify_add("/apps/gramps/researcher",
self.researcher_key_update)
Config.client.notify_add("/apps/gramps/interface/statusbar",
self.statusbar_key_update)
if Config.get(Config.USE_TIPS):
TipOfDay.TipOfDay(self.vm.uistate)
## # FIXME: THESE will have to be added (ViewManager?)
## # once bookmarks work again
## self.db.set_researcher(GrampsCfg.get_researcher())
## self.db.connect('person-delete',self.on_remove_bookmark)
## self.db.connect('person-update',self.on_update_bookmark)
def welcome(self):
if not Config.get(Config.BETAWARN):
@ -221,17 +228,3 @@ class Gramps:
Config.set(Config.BETAWARN,True)
return
def researcher_key_update(self,client,cnxn_id,entry,data):
pass
# self.db.set_person_id_prefix(Config.get(Config.IPREFIX))
# self.db.set_family_id_prefix(Config.get(Config.FPREFIX))
# self.db.set_source_id_prefix(Config.get(Config.SPREFIX))
# self.db.set_object_id_prefix(Config.get(Config.OPREFIX))
# self.db.set_place_id_prefix(Config.get(Config.PPREFIX))
# self.db.set_event_id_prefix(Config.get(Config.EPREFIX))
def statusbar_key_update(self,client,cnxn_id,entry,data):
self.vm.uistate.modify_statusbar()