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:
parent
f009c7a1f5
commit
3833ee63a6
@ -21,6 +21,7 @@
|
||||
# $Id$
|
||||
|
||||
import const
|
||||
import constfunc
|
||||
import config
|
||||
import locale
|
||||
import os
|
||||
@ -92,7 +93,10 @@ def run_file(file):
|
||||
Open a file or url with the default application. This should work
|
||||
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:
|
||||
os.spawnvpe(os.P_NOWAIT, prog, [prog, file], os.environ)
|
||||
return True
|
||||
|
@ -77,3 +77,35 @@ def win():
|
||||
if platform.system() in WINDOWS:
|
||||
return True
|
||||
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
|
||||
|
@ -30,7 +30,9 @@ Utility functions that depend on GUI components or for GUI components
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import os
|
||||
import sys
|
||||
from gen.ggettext import gettext as _
|
||||
from constfunc import has_display
|
||||
# gtk is not included here, because this file is currently imported
|
||||
# by code that needs to run without the DISPLAY variable (eg, in
|
||||
# the cli only).
|
||||
@ -67,6 +69,39 @@ def add_menuitem(menu, msg, obj, func):
|
||||
item.show()
|
||||
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()
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Progress meter class
|
||||
@ -109,7 +144,10 @@ class ProgressMeter(object):
|
||||
else:
|
||||
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:
|
||||
self.__dialog.connect('delete_event', self.__cancel_callback)
|
||||
else:
|
||||
|
@ -77,6 +77,7 @@ from gui.pluginmanager import GuiPluginManager
|
||||
import Relationship
|
||||
import DisplayState
|
||||
import const
|
||||
import constfunc
|
||||
import config
|
||||
import Errors
|
||||
from QuestionDialog import (ErrorDialog, WarningDialog, QuestionDialog2,
|
||||
@ -101,6 +102,15 @@ from gen.utils.configmanager import safe_eval
|
||||
# Constants
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
if constfunc.is_quartz():
|
||||
try:
|
||||
import gtk_osxapplication as QuartzApp
|
||||
_GTKOSXAPPLICATION = True
|
||||
except:
|
||||
_GTKOSXAPPLICATION = False
|
||||
else:
|
||||
_GTKOSXAPPLICATION = False
|
||||
|
||||
_UNSUPPORTED = _("Unsupported")
|
||||
|
||||
UIDEFAULT = '''<ui>
|
||||
@ -280,6 +290,9 @@ class ViewManager(CLIManager):
|
||||
the view categories are accessible in the sidebar.
|
||||
"""
|
||||
CLIManager.__init__(self, dbstate, False)
|
||||
if _GTKOSXAPPLICATION:
|
||||
self.macapp = QuartzApp.OSXApplication()
|
||||
|
||||
self.view_category_order = view_category_order
|
||||
|
||||
#set pluginmanager to GUI one
|
||||
@ -302,6 +315,8 @@ class ViewManager(CLIManager):
|
||||
|
||||
self.__build_main_window()
|
||||
self.__connect_signals()
|
||||
if _GTKOSXAPPLICATION:
|
||||
self.macapp.ready()
|
||||
|
||||
self.do_reg_plugins(self.dbstate, self.uistate)
|
||||
#plugins loaded now set relationship class
|
||||
@ -699,6 +714,8 @@ class ViewManager(CLIManager):
|
||||
"""
|
||||
self.window.connect('delete-event', self.quit)
|
||||
self.notebook.connect('switch-page', self.view_changed)
|
||||
if _GTKOSXAPPLICATION:
|
||||
self.macapp.connect('NSApplicationWillTerminate', self.quit)
|
||||
|
||||
def __init_lists(self):
|
||||
"""
|
||||
@ -1018,6 +1035,15 @@ class ViewManager(CLIManager):
|
||||
|
||||
self.uimanager.add_ui_from_string(UIDEFAULT)
|
||||
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):
|
||||
"""
|
||||
@ -1202,6 +1228,9 @@ class ViewManager(CLIManager):
|
||||
self.__connect_active_page(page_num)
|
||||
|
||||
self.uimanager.ensure_update()
|
||||
if _GTKOSXAPPLICATION:
|
||||
self.macapp.sync_menubar()
|
||||
|
||||
while gtk.events_pending():
|
||||
gtk.main_iteration()
|
||||
|
||||
@ -1787,7 +1816,8 @@ def run_plugin(pdata, dbstate, uistate):
|
||||
getattr(mod, pdata.reportclass),
|
||||
getattr(mod, pdata.optionclass),
|
||||
pdata.name, pdata.id,
|
||||
pdata.category, pdata.require_active)
|
||||
pdata.category, pdata.require_active,
|
||||
)
|
||||
else:
|
||||
tool.gui_tool(dbstate, uistate,
|
||||
getattr(mod, pdata.toolclass),
|
||||
|
@ -38,13 +38,15 @@ _LOG = logging.getLogger(".widgets.expandcollapsearrow")
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import gtk
|
||||
import constfunc
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Constants
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
HAND_CURSOR = gtk.gdk.Cursor(gtk.gdk.HAND2)
|
||||
if constfunc.has_display():
|
||||
HAND_CURSOR = gtk.gdk.Cursor(gtk.gdk.HAND2)
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
|
@ -54,7 +54,8 @@ import constfunc
|
||||
# Constants
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
HAND_CURSOR = gtk.gdk.Cursor(gtk.gdk.HAND2)
|
||||
if constfunc.has_display():
|
||||
HAND_CURSOR = gtk.gdk.Cursor(gtk.gdk.HAND2)
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
|
@ -60,14 +60,16 @@ from gui.widgets.springseparator import SpringSeparatorAction
|
||||
from Spell import Spell
|
||||
from GrampsDisplay import url as display_url
|
||||
import config
|
||||
from constfunc import has_display
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Constants
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
HAND_CURSOR = gtk.gdk.Cursor(gtk.gdk.HAND2)
|
||||
REGULAR_CURSOR = gtk.gdk.Cursor(gtk.gdk.XTERM)
|
||||
if has_display():
|
||||
HAND_CURSOR = gtk.gdk.Cursor(gtk.gdk.HAND2)
|
||||
REGULAR_CURSOR = gtk.gdk.Cursor(gtk.gdk.XTERM)
|
||||
|
||||
FORMAT_TOOLBAR = '''
|
||||
<ui>
|
||||
|
@ -42,12 +42,6 @@ import sys
|
||||
#-------------------------------------------------------------------------
|
||||
import gtk
|
||||
|
||||
try:
|
||||
import cairo
|
||||
CAIRO_AVAILABLE = True
|
||||
except ImportError:
|
||||
CAIRO_AVAILABLE = False
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Gramps Modules
|
||||
@ -68,6 +62,7 @@ import cPickle as pickle
|
||||
import config
|
||||
import Bookmarks
|
||||
import const
|
||||
import constfunc
|
||||
from QuestionDialog import RunDatabaseRepair, ErrorDialog
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@ -75,6 +70,15 @@ from QuestionDialog import RunDatabaseRepair, ErrorDialog
|
||||
# Constants
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
if constfunc.is_quartz():
|
||||
CAIRO_AVAILABLE = False
|
||||
else:
|
||||
try:
|
||||
import cairo
|
||||
CAIRO_AVAILABLE = True
|
||||
except ImportError:
|
||||
CAIRO_AVAILABLE = False
|
||||
|
||||
_PERSON = "p"
|
||||
_BORN = _('short for born|b.')
|
||||
_DIED = _('short for died|d.')
|
||||
|
Loading…
Reference in New Issue
Block a user