Add LocationBox widget

svn: r16622
This commit is contained in:
Nick Hall 2011-02-15 16:35:25 +00:00
parent dc505e7671
commit a5dc64899a
4 changed files with 90 additions and 0 deletions

View File

@ -257,6 +257,7 @@ src/gui/views/treemodels/repomodel.py
src/gui/views/treemodels/sourcemodel.py
# gui/widgets - the GUI widgets package
src/gui/widgets/locationbox.py
src/gui/widgets/menutoolbuttonaction.py
src/gui/widgets/styledtextbuffer.py
src/gui/widgets/undoablestyledbuffer.py

View File

@ -12,6 +12,7 @@ pkgdata_PYTHON = \
grampletpane.py \
labels.py \
linkbox.py \
locationbox.py \
menutoolbuttonaction.py \
monitoredwidgets.py \
multitreeview.py \

View File

@ -27,6 +27,7 @@ from buttons import *
from expandcollapsearrow import *
from labels import *
from linkbox import *
from locationbox import *
from monitoredwidgets import *
from shortlistcomboentry import *
from springseparator import *

View File

@ -0,0 +1,87 @@
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2011 Nick Hall
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id$
#
#-------------------------------------------------------------------------
#
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
import gtk
#-------------------------------------------------------------------------
#
# LocationBox class
#
#-------------------------------------------------------------------------
class LocationBox(gtk.VBox):
"""
Displays a location.
"""
def __init__(self):
gtk.VBox.__init__(self)
self.__street = self.__create_label()
self.__locality = self.__create_label()
self.__city = self.__create_label()
self.__county = self.__create_label()
self.__state = self.__create_label()
self.__country = self.__create_label()
self.__postal_code = self.__create_label()
def set_location(self, location):
"""
Set the location to be displayed.
"""
if location is not None:
self.__set_line(self.__street, location.get_street())
self.__set_line(self.__locality, location.get_locality())
self.__set_line(self.__city, location.get_city())
self.__set_line(self.__county, location.get_county())
self.__set_line(self.__state, location.get_state())
self.__set_line(self.__country, location.get_country())
self.__set_line(self.__postal_code, location.get_postal_code())
else:
self.__set_line(self.__street, '')
self.__set_line(self.__locality, '')
self.__set_line(self.__city, '')
self.__set_line(self.__county, '')
self.__set_line(self.__state, '')
self.__set_line(self.__country, '')
self.__set_line(self.__postal_code, '')
def __create_label(self):
"""
Create a label to display a single line of the location.
"""
label = gtk.Label()
label.set_alignment(0, 0)
self.pack_start(label, False, False)
return label
def __set_line(self, label, value):
"""
Display a single line of the location.
"""
if value:
label.set_text(value)
label.show()
else:
label.hide()