Added is_quartz() and has_display() functions to tell if running with quartz window manager, and if have a display, respectively. See #4467 for more details

svn: r16307
This commit is contained in:
Doug Blank 2010-12-23 16:51:04 +00:00
parent f009c7a1f5
commit 3833ee63a6
8 changed files with 126 additions and 13 deletions

View File

@ -21,6 +21,7 @@
# $Id$ # $Id$
import const import const
import constfunc
import config import config
import locale import locale
import os import os
@ -92,7 +93,10 @@ def run_file(file):
Open a file or url with the default application. This should work Open a file or url with the default application. This should work
on GNOME, KDE, XFCE, ... as we use a freedesktop application on GNOME, KDE, XFCE, ... as we use a freedesktop application
""" """
prog = find_binary('xdg-open') if constfunc.is_quartz():
prog = find_binary('open')
else:
prog = find_binary('xdg-open')
if prog: if prog:
os.spawnvpe(os.P_NOWAIT, prog, [prog, file], os.environ) os.spawnvpe(os.P_NOWAIT, prog, [prog, file], os.environ)
return True return True

View File

@ -77,3 +77,35 @@ def win():
if platform.system() in WINDOWS: if platform.system() in WINDOWS:
return True return True
return False return False
## The following functions do import gtk, but only when called. They
## should only be called after translation system has been
## initialized!
def is_quartz():
"""
Tests to see if Python is currently running with gtk and
windowing system is Mac OS-X's "quartz".
"""
if mac():
try:
import gtk
except:
return False
return gtk.gdk.WINDOWING == "quartz"
return False
def has_display():
"""
Tests to see if Python is currently running with gtk and
windowing system is Mac OS-X's "quartz".
"""
try:
import gtk
except:
return False
try:
gtk.init_check()
return True
except:
return False

View File

@ -30,7 +30,9 @@ Utility functions that depend on GUI components or for GUI components
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import os import os
import sys
from gen.ggettext import gettext as _ from gen.ggettext import gettext as _
from constfunc import has_display
# gtk is not included here, because this file is currently imported # gtk is not included here, because this file is currently imported
# by code that needs to run without the DISPLAY variable (eg, in # by code that needs to run without the DISPLAY variable (eg, in
# the cli only). # the cli only).
@ -66,6 +68,39 @@ def add_menuitem(menu, msg, obj, func):
item.connect("activate", func) item.connect("activate", func)
item.show() item.show()
menu.append(item) menu.append(item)
class CLIVbox():
"""
Command-line interface vbox, to keep compatible with Dialog.
"""
def set_border_width(self, width):
pass
def add(self, widget):
pass
def set_spacing(self, spacing):
pass
def set_border_width(self, width):
pass
class CLIDialog:
"""
Command-line interface vbox, to keep compatible with Dialog.
"""
def connect(self, signal, callback):
pass
def set_has_separator(self, flag):
pass
def set_title(self, title):
pass
def set_border_width(self, width):
pass
def set_size_request(self, width, height):
pass
def show_all(self):
pass
def destroy(self):
pass
vbox = CLIVbox()
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -109,7 +144,10 @@ class ProgressMeter(object):
else: else:
self.__cancel_callback = self.handle_cancel self.__cancel_callback = self.handle_cancel
self.__dialog = gtk.Dialog() if has_display():
self.__dialog = gtk.Dialog()
else:
self.__dialog = CLIDialog()
if self.__can_cancel: if self.__can_cancel:
self.__dialog.connect('delete_event', self.__cancel_callback) self.__dialog.connect('delete_event', self.__cancel_callback)
else: else:

View File

@ -77,6 +77,7 @@ from gui.pluginmanager import GuiPluginManager
import Relationship import Relationship
import DisplayState import DisplayState
import const import const
import constfunc
import config import config
import Errors import Errors
from QuestionDialog import (ErrorDialog, WarningDialog, QuestionDialog2, from QuestionDialog import (ErrorDialog, WarningDialog, QuestionDialog2,
@ -101,6 +102,15 @@ from gen.utils.configmanager import safe_eval
# Constants # Constants
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
if constfunc.is_quartz():
try:
import gtk_osxapplication as QuartzApp
_GTKOSXAPPLICATION = True
except:
_GTKOSXAPPLICATION = False
else:
_GTKOSXAPPLICATION = False
_UNSUPPORTED = _("Unsupported") _UNSUPPORTED = _("Unsupported")
UIDEFAULT = '''<ui> UIDEFAULT = '''<ui>
@ -280,6 +290,9 @@ class ViewManager(CLIManager):
the view categories are accessible in the sidebar. the view categories are accessible in the sidebar.
""" """
CLIManager.__init__(self, dbstate, False) CLIManager.__init__(self, dbstate, False)
if _GTKOSXAPPLICATION:
self.macapp = QuartzApp.OSXApplication()
self.view_category_order = view_category_order self.view_category_order = view_category_order
#set pluginmanager to GUI one #set pluginmanager to GUI one
@ -302,6 +315,8 @@ class ViewManager(CLIManager):
self.__build_main_window() self.__build_main_window()
self.__connect_signals() self.__connect_signals()
if _GTKOSXAPPLICATION:
self.macapp.ready()
self.do_reg_plugins(self.dbstate, self.uistate) self.do_reg_plugins(self.dbstate, self.uistate)
#plugins loaded now set relationship class #plugins loaded now set relationship class
@ -699,6 +714,8 @@ class ViewManager(CLIManager):
""" """
self.window.connect('delete-event', self.quit) self.window.connect('delete-event', self.quit)
self.notebook.connect('switch-page', self.view_changed) self.notebook.connect('switch-page', self.view_changed)
if _GTKOSXAPPLICATION:
self.macapp.connect('NSApplicationWillTerminate', self.quit)
def __init_lists(self): def __init_lists(self):
""" """
@ -1018,6 +1035,15 @@ class ViewManager(CLIManager):
self.uimanager.add_ui_from_string(UIDEFAULT) self.uimanager.add_ui_from_string(UIDEFAULT)
self.uimanager.ensure_update() self.uimanager.ensure_update()
if _GTKOSXAPPLICATION:
menubar = self.uimanager.get_widget("/MenuBar")
menubar.hide()
quit_item = self.uimanager.get_widget("/MenuBar/FileMenu/Quit")
about_item = self.uimanager.get_widget("/MenuBar/HelpMenu/About")
prefs_item = self.uimanager.get_widget("/MenuBar/EditMenu/Preferences")
self.macapp.set_menu_bar(menubar)
self.macapp.insert_app_menu_item(about_item, 0)
self.macapp.insert_app_menu_item(prefs_item, 1)
def preferences_activate(self, obj): def preferences_activate(self, obj):
""" """
@ -1202,6 +1228,9 @@ class ViewManager(CLIManager):
self.__connect_active_page(page_num) self.__connect_active_page(page_num)
self.uimanager.ensure_update() self.uimanager.ensure_update()
if _GTKOSXAPPLICATION:
self.macapp.sync_menubar()
while gtk.events_pending(): while gtk.events_pending():
gtk.main_iteration() gtk.main_iteration()
@ -1787,7 +1816,8 @@ def run_plugin(pdata, dbstate, uistate):
getattr(mod, pdata.reportclass), getattr(mod, pdata.reportclass),
getattr(mod, pdata.optionclass), getattr(mod, pdata.optionclass),
pdata.name, pdata.id, pdata.name, pdata.id,
pdata.category, pdata.require_active) pdata.category, pdata.require_active,
)
else: else:
tool.gui_tool(dbstate, uistate, tool.gui_tool(dbstate, uistate,
getattr(mod, pdata.toolclass), getattr(mod, pdata.toolclass),

View File

@ -38,13 +38,15 @@ _LOG = logging.getLogger(".widgets.expandcollapsearrow")
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import gtk import gtk
import constfunc
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Constants # Constants
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
HAND_CURSOR = gtk.gdk.Cursor(gtk.gdk.HAND2) if constfunc.has_display():
HAND_CURSOR = gtk.gdk.Cursor(gtk.gdk.HAND2)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

View File

@ -54,7 +54,8 @@ import constfunc
# Constants # Constants
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
HAND_CURSOR = gtk.gdk.Cursor(gtk.gdk.HAND2) if constfunc.has_display():
HAND_CURSOR = gtk.gdk.Cursor(gtk.gdk.HAND2)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

View File

@ -60,14 +60,16 @@ from gui.widgets.springseparator import SpringSeparatorAction
from Spell import Spell from Spell import Spell
from GrampsDisplay import url as display_url from GrampsDisplay import url as display_url
import config import config
from constfunc import has_display
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Constants # Constants
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
HAND_CURSOR = gtk.gdk.Cursor(gtk.gdk.HAND2) if has_display():
REGULAR_CURSOR = gtk.gdk.Cursor(gtk.gdk.XTERM) HAND_CURSOR = gtk.gdk.Cursor(gtk.gdk.HAND2)
REGULAR_CURSOR = gtk.gdk.Cursor(gtk.gdk.XTERM)
FORMAT_TOOLBAR = ''' FORMAT_TOOLBAR = '''
<ui> <ui>

View File

@ -42,12 +42,6 @@ import sys
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import gtk import gtk
try:
import cairo
CAIRO_AVAILABLE = True
except ImportError:
CAIRO_AVAILABLE = False
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Gramps Modules # Gramps Modules
@ -68,6 +62,7 @@ import cPickle as pickle
import config import config
import Bookmarks import Bookmarks
import const import const
import constfunc
from QuestionDialog import RunDatabaseRepair, ErrorDialog from QuestionDialog import RunDatabaseRepair, ErrorDialog
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -75,6 +70,15 @@ from QuestionDialog import RunDatabaseRepair, ErrorDialog
# Constants # Constants
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
if constfunc.is_quartz():
CAIRO_AVAILABLE = False
else:
try:
import cairo
CAIRO_AVAILABLE = True
except ImportError:
CAIRO_AVAILABLE = False
_PERSON = "p" _PERSON = "p"
_BORN = _('short for born|b.') _BORN = _('short for born|b.')
_DIED = _('short for died|d.') _DIED = _('short for died|d.')