예제 #1
0
    def add_media(self, infile, pos, x, y, alt='', style_name=None, crop=None):
        """Add photo to report"""
        outfile = os.path.splitext(infile)[0]
        pictname = latexescape(os.path.split(outfile)[1])
        outfile = ''.join((outfile, '.jpg'))
        outfile2 = ''.join((outfile, '.jpeg'))
        outfile3 = ''.join((outfile, '.png'))
        if HAVE_PIL and infile not in [outfile, outfile2, outfile3]:
            try:
                curr_img = Image.open(infile)
                curr_img.save(outfile)
                width, height = curr_img.size
                if height > width:
                    y = y * height / width
            except IOError:
                self.emit(''.join(
                    ('%\n *** Error: cannot convert ', infile,
                     '\n ***                    to ', outfile, '%\n')))
        elif not HAVE_PIL:
            from gramps.gen.config import config
            if not config.get('interface.ignore-pil'):
                from gramps.gen.constfunc import has_display
                if has_display():
                    from gramps.gui.dialog import MessageHideDialog
                    title = _("PIL (Python Imaging Library) not loaded.")
                    message = _("Production of jpg images from non-jpg images "
                                "in LaTeX documents will not be available. "
                                "Use your package manager to install "
                                "python-imaging or python-pillow or "
                                "python3-pillow")
                    MessageHideDialog(
                        title,
                        message,  # TODO no-parent
                        'interface.ignore-pil')
            self.emit(''.join(('%\n *** Error: cannot convert ', infile,
                               '\n ***                    to ', outfile,
                               '\n *** PIL not installed %\n')))

        if self.in_table:
            self.pict_in_table = True

        self.emit(''.join(('\\grmkpicture{', outfile, '}{', repr(x), '}{',
                           repr(y), '}{', pictname, '}%\n')))
        self.pict_width = x
        self.pict_height = y
예제 #2
0
파일: latexdoc.py 프로젝트: ewongbb/gramps
    def add_media(self, infile, pos, x, y, alt='', style_name=None, crop=None):
        """Add photo to report"""
        outfile = os.path.splitext(infile)[0]
        pictname = latexescape(os.path.split(outfile)[1])
        outfile = ''.join((outfile, '.jpg'))
        outfile2 = ''.join((outfile, '.jpeg'))
        outfile3 = ''.join((outfile, '.png'))
        if HAVE_PIL and infile not in [outfile, outfile2, outfile3]:
            try:
                curr_img = Image.open(infile)
                curr_img.save(outfile)
                width, height = curr_img.size
                if height > width:
                    y = y*height/width
            except IOError:
                self.emit(''.join(('%\n *** Error: cannot convert ', infile,
                                   '\n ***                    to ', outfile,
                                   '%\n')))
        elif not HAVE_PIL:
            from gramps.gen.config import config
            if not config.get('interface.ignore-pil'):
                from gramps.gen.constfunc import has_display
                if has_display():
                    from gramps.gui.dialog import MessageHideDialog
                    title = _("PIL (Python Imaging Library) not loaded.")
                    message = _("Production of jpg images from non-jpg images "
                                "in LaTeX documents will not be available. "
                                "Use your package manager to install "
                                "python-imaging or python-pillow or "
                                "python3-pillow")
                    MessageHideDialog(title, message, # TODO no-parent
                                      'interface.ignore-pil')
            self.emit(''.join(('%\n *** Error: cannot convert ', infile,
                               '\n ***                    to ', outfile,
                               '\n *** PIL not installed %\n')))

        if self.in_table:
            self.pict_in_table = True

        self.emit(''.join(('\\grmkpicture{', outfile, '}{', repr(x), '}{',
                           repr(y), '}{', pictname, '}%\n')))
        self.pict_width = x
        self.pict_height = y
예제 #3
0
        name=_("Image Metadata"),
        description=_("Gramplet showing metadata for a media object"),
        version="1.0.0",
        gramps_target_version=MODULE_VERSION,
        status=STABLE,
        fname="metadataviewer.py",
        height=200,
        gramplet='MetadataViewer',
        gramplet_title=_("Image Metadata"),
        navtypes=["Media"],
    )
else:
    from gramps.gen.config import config
    if not config.get('interface.ignore-gexiv2'):
        from gramps.gen.constfunc import has_display
        if has_display():
            from gramps.gui.dialog import MessageHideDialog
            from gramps.gen.const import URL_WIKISTRING
            gexiv2_dict = {
                'gramps_wiki_build_gexiv2_url':
                URL_WIKISTRING + "GEPS_029:_GTK3-GObject_introspection"
                "_Conversion#GExiv2_for_Image_metadata"
            }
            title = _("GExiv2 module not loaded.")
            message = _("Image metadata functionality will not be available.\n"
                        "To build it for Gramps see "
                        "%(gramps_wiki_build_gexiv2_url)s" % gexiv2_dict)
            if uistate:
                MessageHideDialog(title,
                                  message,
                                  'interface.ignore-gexiv2',
예제 #4
0
    def __init__(self,
                 title,
                 header='',
                 can_cancel=False,
                 cancel_callback=None,
                 message_area=False,
                 parent=None):
        """
        Specify the title and the current pass header.
        """
        from gi.repository import Gtk
        self.__mode = ProgressMeter.MODE_FRACTION
        self.__pbar_max = 100.0
        self.__pbar_index = 0.0
        self.__old_val = -1
        self.__can_cancel = can_cancel
        self.__cancelled = False
        if cancel_callback:
            self.__cancel_callback = cancel_callback
        else:
            self.__cancel_callback = self.handle_cancel

        if has_display():
            self.__dialog = Gtk.Dialog()
        else:
            self.__dialog = CLIDialog()
        if self.__can_cancel:
            self.__dialog.connect('delete_event', self.__cancel_callback)
        else:
            self.__dialog.connect('delete_event', self.__warn)
        self.__dialog.set_title(title)
        self.__dialog.set_border_width(12)
        self.__dialog.vbox.set_spacing(10)
        self.__dialog.vbox.set_border_width(24)
        self.__dialog.set_size_request(400, 125)
        if not parent:  # if we don't have an explicit parent, try to find one
            for win in Gtk.Window.list_toplevels():
                if win.is_active():
                    parent = win
                    break
        # if we still don't have a parent, give up
        if parent:
            self.__dialog.set_transient_for(parent)
            self.__dialog.set_modal(True)

        tlbl = Gtk.Label(label='<span size="larger" weight="bold">%s</span>' %
                         title)
        tlbl.set_use_markup(True)
        self.__dialog.vbox.add(tlbl)

        self.__lbl = Gtk.Label(label=header)
        self.__lbl.set_use_markup(True)
        self.__dialog.vbox.add(self.__lbl)

        self.__pbar = Gtk.ProgressBar()
        self.__dialog.vbox.add(self.__pbar)

        if self.__can_cancel:
            self.__dialog.set_size_request(350, 170)
            self.__cancel_button = Gtk.Button.new_with_mnemonic(_('_Cancel'))
            self.__cancel_button.connect('clicked', self.__cancel_callback)
            self.__dialog.vbox.add(self.__cancel_button)

        self.message_area = None
        if message_area:
            area = Gtk.ScrolledWindow()
            text = Gtk.TextView()
            text.set_border_width(6)
            text.set_editable(False)
            self.message_area = text
            area.add(text)
            area.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
            self.__dialog.vbox.add(area)
            self.message_area_ok = Gtk.Button.new_with_mnemonic(_('_OK'))
            self.message_area_ok.connect("clicked", self.close)
            self.message_area_ok.set_sensitive(False)
            self.__dialog.vbox.pack_start(self.message_area_ok,
                                          expand=False,
                                          fill=False)
            self.__dialog.set_size_request(500, 350)

        self.__dialog.show_all()
        if header == '':
            self.__lbl.hide()
예제 #5
0
from .valueaction import ValueAction
from .toolcomboentry import ToolComboEntry
from .springseparator import SpringSeparatorAction
from ..spell import Spell
from ..display import display_url
from ..utils import SystemFonts, rgb_to_hex
from gramps.gen.config import config
from gramps.gen.constfunc import has_display
from ..actiongroup import ActionGroup

#-------------------------------------------------------------------------
#
# Constants
#
#-------------------------------------------------------------------------
if has_display():
    display = Gdk.Display.get_default()
    HAND_CURSOR = Gdk.Cursor.new_for_display(display, Gdk.CursorType.HAND2)
    REGULAR_CURSOR = Gdk.Cursor.new_for_display(display, Gdk.CursorType.XTERM)

FORMAT_TOOLBAR = '''
<ui>
<toolbar name="ToolBar">
  <toolitem action="%d"/>
  <toolitem action="%d"/>
  <toolitem action="%d"/>
  <toolitem action="Undo"/>
  <toolitem action="Redo"/>
  <toolitem action="%d"/>
  <toolitem action="%d"/>
  <toolitem action="%d"/>
예제 #6
0
def __startgramps(errors, argparser):
    """
    Main startup function started via GObject.timeout_add
    First action inside the gtk loop
    """
    try:
        from .dialog import ErrorDialog
        #handle first existing errors in GUI fashion
        if errors:
            for error in errors:
                ErrorDialog(error[0], error[1])
            Gtk.main_quit()
            sys.exit(1)

        if argparser.errors:
            for error in argparser.errors:
                ErrorDialog(error[0], error[1])
            Gtk.main_quit()
            sys.exit(1)

        # add gui logger
        from .logger import RotateHandler, GtkHandler
        form = logging.Formatter(fmt="%(relativeCreated)d: %(levelname)s: "
                                    "%(filename)s: line %(lineno)d: %(message)s")
        # Create the log handlers
        rh = RotateHandler(capacity=20)
        rh.setFormatter(form)
        # Only error and critical log records should
        # trigger the GUI handler.
        gtkh = GtkHandler(rotate_handler=rh)
        gtkh.setFormatter(form)
        gtkh.setLevel(logging.ERROR)
        l = logging.getLogger()
        l.addHandler(rh)
        l.addHandler(gtkh)

    except:
        #make sure there is a clean exit if there is an error in above steps
        quit_now = True
        exit_code = 1
        LOG.error(_(
    "\nGramps failed to start. Please report a bug about this.\n"
    "This could be because of an error in a (third party) View on startup.\n"
    "To use another view, don't load a Family Tree, change view, and then load"
    " your Family Tree.\n"
    "You can also change manually the startup view in the gramps.ini file \n"
    "by changing the last-view parameter.\n"
                   ), exc_info=True)

    # start Gramps, errors stop the gtk loop
    try:
        quit_now = False
        exit_code = 0
        if has_display():
            Gramps(argparser)
        else:
            print("Gramps terminated because of no DISPLAY")
            sys.exit(exit_code)

    except SystemExit as e:
        quit_now = True
        if e.code:
            exit_code = e.code
            LOG.error("Gramps terminated with exit code: %d." \
                      % e.code, exc_info=True)
    except OSError as e:
        quit_now = True
        exit_code = e.errno or 1
        try:
            fn = e.filename
        except AttributeError:
            fn = ""
        LOG.error("Gramps terminated because of OS Error\n" +
            "Error details: %s %s" % (repr(e), fn), exc_info=True)

    except:
        quit_now = True
        exit_code = 1
        LOG.error(_(
    "\nGramps failed to start. Please report a bug about this.\n"
    "This could be because of an error in a (third party) View on startup.\n"
    "To use another view, don't load a Family Tree, change view, and then load"
    " your Family Tree.\n"
    "You can also change manually the startup view in the gramps.ini file \n"
    "by changing the last-view parameter.\n"
                   ), exc_info=True)

    if quit_now:
        #stop gtk loop and quit
        Gtk.main_quit()
        sys.exit(exit_code)

    #function finished, return False to stop the timeout_add function calls
    return False
예제 #7
0
def startqml(errors, argparser):
    """
    Main startup function started via GObject.timeout_add
    First action inside the gtk loop
    """
    from guiQML.questiondialog import ErrorDialog, run_dialog_standalone
    
    #handle first existing errors in GUI fashion
    if errors:
        run_dialog_standalone(ErrorDialog,errors[0], errors[1])
        sys.exit()

    if argparser.errors:
        run_dialog_standalone(ErrorDialog, argparser.errors[0], 
                              argparser.errors[1])
        sys.exit()

    # add gui logger
    from gui.logger import RotateHandler
    form = logging.Formatter(fmt="%(relativeCreated)d: %(levelname)s: "
                                "%(filename)s: line %(lineno)d: %(message)s")
    # Create the log handlers
    rh = RotateHandler(capacity=20)
    rh.setFormatter(form)
    # Only error and critical log records should
    # trigger the GUI handler.
    #qmlh = QMLHandler(rotate_handler=rh)
    #qmlh.setFormatter(form)
    #qmlh.setLevel(logging.ERROR)
    l = logging.getLogger()
    l.addHandler(rh)
    #l.addHandler(gmlh)

    # start GRAMPS, errors stop the gtk loop
    try:
        quit_now = False
        openGL = True
        exit_code = 0
        if has_display():
            GrampsQML(argparser)
        else:
            print("Gramps terminated because of no DISPLAY")
            sys.exit(exit_code)

    except SystemExit as e:
        quit_now = True
        if e.code:
            exit_code = e.code
            LOG.error("Gramps terminated with exit code: %d." \
                      % e.code, exc_info=True)
    except OSError as e:
        quit_now = True
        exit_code = e[0] or 1
        try:
            fn = e.filename
        except AttributeError:
            fn = ""
        LOG.error("Gramps terminated because of OS Error\n" +
            "Error details: %s %s" % (repr(e), fn), exc_info=True)

    except:
        quit_now = True
        exit_code = 1
        LOG.error("Gramps failed to start.", exc_info=True)

    if quit_now:
        #quit
        sys.exit(exit_code)

    #function finished, return False to stop the timeout_add function calls
    return False
예제 #8
0
def __startgramps(errors, argparser):
    """
    Main startup function started via GObject.timeout_add
    First action inside the gtk loop
    """
    try:
        from .dialog import ErrorDialog
        #handle first existing errors in GUI fashion
        if errors:
            for error in errors:
                ErrorDialog(error[0], error[1])  # TODO no-parent
            Gtk.main_quit()
            sys.exit(1)

        if argparser.errors:
            for error in argparser.errors:
                ErrorDialog(error[0], error[1])  # TODO no-parent
            Gtk.main_quit()
            sys.exit(1)

        # add gui logger
        from .logger import RotateHandler, GtkHandler
        form = logging.Formatter(fmt="%(relativeCreated)d: %(levelname)s: "
                                 "%(filename)s: line %(lineno)d: %(message)s")
        # Create the log handlers
        rot_h = RotateHandler(capacity=20)
        rot_h.setFormatter(form)
        # Only error and critical log records should
        # trigger the GUI handler.
        gtkh = GtkHandler(rotate_handler=rot_h)
        gtkh.setFormatter(form)
        gtkh.setLevel(logging.ERROR)
        logger = logging.getLogger()
        logger.addHandler(rot_h)
        logger.addHandler(gtkh)

    except:
        #make sure there is a clean exit if there is an error in above steps
        quit_now = True
        exit_code = 1
        LOG.error(_("\nGramps failed to start. "
                    "Please report a bug about this.\n"
                    "This could be because of an error "
                    "in a (third party) View on startup.\n"
                    "To use another view, don't load a Family Tree, "
                    "change view, and then load your Family Tree.\n"
                    "You can also change manually "
                    "the startup view in the gramps.ini file \n"
                    "by changing the last-view parameter.\n"),
                  exc_info=True)

    # start Gramps, errors stop the gtk loop
    try:
        quit_now = False
        exit_code = 0
        if has_display():
            Gramps(argparser)
        else:
            print(_("Gramps terminated because of no DISPLAY"))
            quit_now = True
            exit_code = 1
    except SystemExit as err:
        quit_now = True
        if err.code:
            exit_code = err.code
            LOG.error("Gramps terminated with exit code: %d.",
                      err.code,
                      exc_info=True)
    except OSError as err:
        quit_now = True
        exit_code = err.errno or 1
        try:
            fname = err.filename
        except AttributeError:
            fname = ""
        LOG.error("Gramps terminated because of OS Error\n" +
                  "Error details: %s %s",
                  repr(err),
                  fname,
                  exc_info=True)
    except:
        quit_now = True
        exit_code = 1
        LOG.error(_("\nGramps failed to start. "
                    "Please report a bug about this.\n"
                    "This could be because of an error "
                    "in a (third party) View on startup.\n"
                    "To use another view, don't load a Family Tree, "
                    "change view, and then load your Family Tree.\n"
                    "You can also change manually "
                    "the startup view in the gramps.ini file \n"
                    "by changing the last-view parameter.\n"),
                  exc_info=True)

    if quit_now:
        #stop gtk loop and quit
        Gtk.main_quit()
        sys.exit(exit_code)

    #function finished, return False to stop the timeout_add function calls
    return False
예제 #9
0
파일: grampsqml.py 프로젝트: goetzk/gramps
def startqml(errors, argparser):
    """
    Main startup function started via GObject.timeout_add
    First action inside the gtk loop
    """
    from guiQML.questiondialog import ErrorDialog, run_dialog_standalone

    #handle first existing errors in GUI fashion
    if errors:
        run_dialog_standalone(ErrorDialog, errors[0], errors[1])
        sys.exit()

    if argparser.errors:
        run_dialog_standalone(ErrorDialog, argparser.errors[0],
                              argparser.errors[1])
        sys.exit()

    # add gui logger
    from gui.logger import RotateHandler
    form = logging.Formatter(fmt="%(relativeCreated)d: %(levelname)s: "
                             "%(filename)s: line %(lineno)d: %(message)s")
    # Create the log handlers
    rh = RotateHandler(capacity=20)
    rh.setFormatter(form)
    # Only error and critical log records should
    # trigger the GUI handler.
    #qmlh = QMLHandler(rotate_handler=rh)
    #qmlh.setFormatter(form)
    #qmlh.setLevel(logging.ERROR)
    l = logging.getLogger()
    l.addHandler(rh)
    #l.addHandler(gmlh)

    # start GRAMPS, errors stop the gtk loop
    try:
        quit_now = False
        openGL = True
        exit_code = 0
        if has_display():
            GrampsQML(argparser)
        else:
            print("Gramps terminated because of no DISPLAY")
            sys.exit(exit_code)

    except SystemExit as e:
        quit_now = True
        if e.code:
            exit_code = e.code
            LOG.error("Gramps terminated with exit code: %d." \
                      % e.code, exc_info=True)
    except OSError as e:
        quit_now = True
        exit_code = e[0] or 1
        try:
            fn = e.filename
        except AttributeError:
            fn = ""
        LOG.error("Gramps terminated because of OS Error\n" +
                  "Error details: %s %s" % (repr(e), fn),
                  exc_info=True)

    except:
        quit_now = True
        exit_code = 1
        LOG.error("Gramps failed to start.", exc_info=True)

    if quit_now:
        #quit
        sys.exit(exit_code)

    #function finished, return False to stop the timeout_add function calls
    return False
예제 #10
0
# Attempting to import webkit gives an error dialog if webkit is not
# available so test first and log just a warning to the console instead.
repository = Repository.get_default()
if repository.enumerate_versions("WebKit"):
    try:
        from gi.repository import WebKit
        TOOLKIT = WEBKIT
    except:
        pass

from gramps.gen.config import config
if TOOLKIT == NOWEB and not config.get('interface.ignore-webkit'):
    from gramps.gen.constfunc import has_display, mac, win
    if win() or mac():  # WebKit is not put into either Windows or Mac bundles
        config.set('interface.ignore-webkit', True)
    if has_display() and not config.get('interface.ignore-webkit'):
        from gramps.gui.dialog import MessageHideDialog
        title = _("Webkit module not loaded.")
        msg = _("Webkit module not loaded. "
                "Embedded web page viewing will not be available. "
                "Use your package manager to install gir1.2-webkit-3.0")
        MessageHideDialog(title, msg, 'interface.ignore-webkit')

#no interfaces present, we do not register these plugins
if not (TOOLKIT == NOWEB):
    register(
        VIEW,
        id='htmlview',
        name=_("Html View"),
        description=_("A view showing html pages embedded in Gramps"),
        version='1.0',
예제 #11
0
파일: utils.py 프로젝트: Greunlis/gramps
    def __init__(self, title, header='', can_cancel=False,
                 cancel_callback=None, message_area=False, parent=None):
        """
        Specify the title and the current pass header.
        """
        from gi.repository import Gtk
        self.__mode = ProgressMeter.MODE_FRACTION
        self.__pbar_max = 100.0
        self.__pbar_index = 0.0
        self.__old_val = -1
        self.__can_cancel = can_cancel
        self.__cancelled = False
        if cancel_callback:
            self.__cancel_callback = cancel_callback
        else:
            self.__cancel_callback = self.handle_cancel

        if has_display():
            self.__dialog = Gtk.Dialog()
        else:
            self.__dialog = CLIDialog()
        if self.__can_cancel:
            self.__dialog.connect('delete_event', self.__cancel_callback)
        else:
            self.__dialog.connect('delete_event', self.__warn)
        self.__dialog.set_title(title)
        self.__dialog.set_border_width(12)
        self.__dialog.vbox.set_spacing(10)
        self.__dialog.vbox.set_border_width(24)
        self.__dialog.set_size_request(400, 125)
        if parent:
            self.__dialog.set_transient_for(parent)
            self.__dialog.set_modal(True)

        tlbl = Gtk.Label(label='<span size="larger" weight="bold">%s</span>' % title)
        tlbl.set_use_markup(True)
        self.__dialog.vbox.add(tlbl)

        self.__lbl = Gtk.Label(label=header)
        self.__lbl.set_use_markup(True)
        self.__dialog.vbox.add(self.__lbl)

        self.__pbar = Gtk.ProgressBar()
        self.__dialog.vbox.add(self.__pbar)

        if self.__can_cancel:
            self.__dialog.set_size_request(350, 170)
            self.__cancel_button = Gtk.Button.new_with_mnemonic(_('_Cancel'))
            self.__cancel_button.connect('clicked', self.__cancel_callback)
            self.__dialog.vbox.add(self.__cancel_button)

        self.message_area = None
        if message_area:
            area = Gtk.ScrolledWindow()
            text = Gtk.TextView()
            text.set_border_width(6)
            text.set_editable(False)
            self.message_area = text
            area.add(text)
            area.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
            self.__dialog.vbox.add(area)
            self.message_area_ok = Gtk.Button.new_with_mnemonic(_('_OK'))
            self.message_area_ok.connect("clicked", self.close)
            self.message_area_ok.set_sensitive(False)
            self.__dialog.vbox.pack_start(self.message_area_ok, expand=False, fill=False)
            self.__dialog.set_size_request(500, 350)

        self.__dialog.show_all()
        if header == '':
            self.__lbl.hide()