1# Gramps - a GTK+/GNOME based genealogy program
2#
3# Copyright (C) 2007-2009  Douglas S. Blank <doug.blank@gmail.com>
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19#------------------------------------------------------------------------
20#
21# Gtk modules
22#
23#------------------------------------------------------------------------
24from gi.repository import Gtk
25
26#------------------------------------------------------------------------
27#
28# Gramps modules
29#
30#------------------------------------------------------------------------
31from gramps.gen.const import URL_WIKISTRING, URL_MANUAL_PAGE, URL_HOMEPAGE
32from gramps.gen.plug import Gramplet
33from gramps.gui.widgets.styledtexteditor import StyledTextEditor
34from gramps.gen.lib import StyledText, StyledTextTag, StyledTextTagType
35from gramps.gen.const import GRAMPS_LOCALE as glocale
36_ = glocale.translation.sgettext
37
38#------------------------------------------------------------------------
39#
40# Functions
41#
42#------------------------------------------------------------------------
43def st(text):
44    """ Return text as styled text
45    """
46    return StyledText(text)
47
48def boldst(text):
49    """ Return text as bold styled text
50    """
51    tags = [StyledTextTag(StyledTextTagType.BOLD, True, [(0, len(text))])]
52    return StyledText(text, tags)
53
54def linkst(text, url):
55    """ Return text as link styled text
56    """
57    tags = [StyledTextTag(StyledTextTagType.LINK, url, [(0, len(text))])]
58    return StyledText(text, tags)
59
60#------------------------------------------------------------------------
61#
62# Gramplet class
63#
64#------------------------------------------------------------------------
65
66class WelcomeGramplet(Gramplet):
67    """
68    Displays a welcome note to the user.
69    """
70    def init(self):
71        self.gui.WIDGET = self.build_gui()
72        self.gui.get_container_widget().remove(self.gui.textview)
73        self.gui.get_container_widget().add(self.gui.WIDGET)
74        self.gui.WIDGET.show()
75
76    def build_gui(self):
77        """
78        Build the GUI interface.
79        """
80        top = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
81
82        scrolledwindow = Gtk.ScrolledWindow()
83        scrolledwindow.set_policy(Gtk.PolicyType.AUTOMATIC,
84                                  Gtk.PolicyType.AUTOMATIC)
85        self.texteditor = StyledTextEditor()
86        self.texteditor.set_editable(False)
87        self.texteditor.set_wrap_mode(Gtk.WrapMode.WORD)
88        scrolledwindow.add(self.texteditor)
89
90        self.display_text()
91
92        top.pack_start(scrolledwindow, True, True, 0)
93        top.show_all()
94        return top
95
96    def display_text(self):
97        """
98        Display the welcome text.
99        """
100        welcome = boldst(_('Intro')) + '\n\n'
101        welcome += _(
102            'Gramps is a software package designed for genealogical research.'
103            ' Although similar to other genealogical programs, Gramps offers '
104            'some unique and powerful features.\n\n')
105        welcome += boldst(_('Links')) + '\n\n'
106        welcome += linkst(_('Home Page'), URL_HOMEPAGE) + '\n'
107        welcome += linkst(_('Start with Genealogy and Gramps'),
108                          '%(gramps_wiki_url)sStart_with_Genealogy' %
109                          {'gramps_wiki_url': URL_WIKISTRING}) + '\n'
110        welcome += linkst(_('Gramps online manual'),
111                          URL_WIKISTRING + URL_MANUAL_PAGE +
112                          _('locale_suffix|')) + '\n'
113        welcome += linkst(_('Ask questions on gramps-users mailing list'),
114                          '%(gramps_home_url)scontact/' %
115                          {'gramps_home_url': URL_HOMEPAGE}) + '\n\n'
116
117        welcome += boldst(_('Who makes Gramps?')) + '\n\n' + _(
118            'Gramps is created by genealogists for genealogists, organized in'
119            ' the Gramps Project.'
120            ' Gramps is an Open Source Software package, which means you are '
121            'free to make copies and distribute it to anyone you like. It\'s '
122            'developed and maintained by a worldwide team of volunteers whose'
123            ' goal is to make Gramps powerful, yet easy to use.\n\n')
124        welcome += boldst(_('Getting Started')) + '\n\n' + _(
125            'The first thing you must do is to create a new Family Tree. To '
126            'create a new Family Tree (sometimes called \'database\') select '
127            '"Family Trees" from the menu, pick "Manage Family Trees", press '
128            '"New" and name your Family Tree. For more details, please read '
129            'the information at the links above\n\n')
130        welcome += boldst(_('Dashboard View')) + '\n\n' + _(
131            'You are currently reading from the "Dashboard" view, where you can'
132            ' add your own gramplets. You can also add gramplets to any view by'
133            ' adding a sidebar and/or bottombar, and right-clicking to the'
134            ' right of the tab.\n\n'
135            'You can click the configuration icon in the toolbar to add'
136            ' additional columns, while right-click on the background allows to'
137            ' add gramplets. You can also drag the Properties button to'
138            ' reposition the gramplet on this page, and detach the gramplet to'
139            ' float above Gramps.'
140        )
141
142        self.texteditor.set_text(welcome)
143
144    def get_has_data(self, obj):
145        """
146        Return True if the gramplet has data, else return False.
147        """
148        return True
149
150