Add color schemes to config

This commit is contained in:
vantu5z 2018-01-14 16:00:02 +09:00 committed by Nick Hall
parent cd32559282
commit 028f9582f5
3 changed files with 139 additions and 65 deletions

View File

@ -272,22 +272,25 @@ register('preferences.last-view', '')
register('preferences.last-views', []) register('preferences.last-views', [])
register('preferences.family-relation-type', 3) # UNKNOWN register('preferences.family-relation-type', 3) # UNKNOWN
register('preferences.age-display-precision', 1) register('preferences.age-display-precision', 1)
register('preferences.color-gender-male-alive', '#b8cee6')
register('preferences.color-gender-male-death', '#b8cee6') register('colors.scheme', 0)
register('preferences.color-gender-female-alive', '#feccf0') register('colors.male-alive', ['#b8cee6', '#1f344a'])
register('preferences.color-gender-female-death', '#feccf0') register('colors.male-dead', ['#b8cee6', '#2d3039'])
register('preferences.color-gender-unknown-alive', '#f3dbb6') register('colors.female-alive', ['#feccf0', '#62242D'])
register('preferences.color-gender-unknown-death', '#f3dbb6') register('colors.female-dead', ['#feccf0', '#3a292b'])
#register('preferences.color-gender-other-alive', '#fcaf3e') register('colors.unknown-alive', ['#f3dbb6', '#75507B'])
#register('preferences.color-gender-other-death', '#fcaf3e') register('colors.unknown-dead', ['#f3dbb6', '#35103b'])
register('preferences.bordercolor-gender-male-alive', '#1f4986') register('colors.family', ['#eeeeee', '#454545'])
register('preferences.bordercolor-gender-male-death', '#000000') register('colors.family-divorced', ['#ffdede', '#5c3636'])
register('preferences.bordercolor-gender-female-alive', '#861f69') register('colors.home-person', ['#bbe68a', '#304918'])
register('preferences.bordercolor-gender-female-death', '#000000') register('colors.border-male-alive', ['#1f4986', '#171d26'])
register('preferences.bordercolor-gender-unknown-alive', '#8e5801') register('colors.border-male-dead', ['#000000', '#000000'])
register('preferences.bordercolor-gender-unknown-death', '#000000') register('colors.border-female-alive', ['#861f69', '#261111'])
#register('preferences.bordercolor-gender-other-alive', '#f57900') register('colors.border-female-dead', ['#000000', '#000000'])
#register('preferences.bordercolor-gender-other-death', '#000000') register('colors.border-unknown-alive', ['#8e5801', '#8e5801'])
register('colors.border-unknown-dead', ['#000000', '#000000'])
register('colors.border-family', ['#cccccc', '#252525'])
register('colors.border-family-divorced', ['#ff7373', '#720b0b'])
register('researcher.researcher-addr', '') register('researcher.researcher-addr', '')
register('researcher.researcher-locality', '') register('researcher.researcher-locality', '')

View File

@ -249,13 +249,23 @@ class ConfigureDialog(ManagedWindow):
""" """
self.__config.set(constant, obj.get_text()) self.__config.set(constant, obj.get_text())
def update_color(self, obj, constant, color_hex_label): def update_color(self, obj, pspec, constant, color_hex_label):
"""
Called on changing some color.
Either on programmatically color change.
"""
rgba = obj.get_rgba() rgba = obj.get_rgba()
hexval = "#%02x%02x%02x" % (int(rgba.red * 255), hexval = "#%02x%02x%02x" % (int(rgba.red * 255),
int(rgba.green * 255), int(rgba.green * 255),
int(rgba.blue * 255)) int(rgba.blue * 255))
color_hex_label.set_text(hexval) color_hex_label.set_text(hexval)
self.__config.set(constant, hexval) colors = self.__config.get(constant)
if isinstance(colors, list):
scheme = self.__config.get('colors.scheme')
colors[scheme] = hexval
self.__config.set(constant, colors)
else:
self.__config.set(constant, hexval)
def update_checkbox(self, obj, constant, config=None): def update_checkbox(self, obj, constant, config=None):
if not config: if not config:
@ -383,15 +393,24 @@ class ConfigureDialog(ManagedWindow):
grid.attach(entry, col_attach+1, index, 1, 1) grid.attach(entry, col_attach+1, index, 1, 1)
def add_color(self, grid, label, index, constant, config=None, col=0): def add_color(self, grid, label, index, constant, config=None, col=0):
"""
Add color chooser widget with label to the grid.
"""
if not config: if not config:
config = self.__config config = self.__config
lwidget = BasicLabel(_("%s: ") % label) # needed for French, else ignore lwidget = BasicLabel(_("%s: ") % label) # needed for French, else ignore
hexval = config.get(constant) colors = config.get(constant)
if isinstance(colors, list):
scheme = config.get('colors.scheme')
hexval = colors[scheme]
else:
hexval = colors
color = Gdk.color_parse(hexval) color = Gdk.color_parse(hexval)
entry = Gtk.ColorButton(color=color) entry = Gtk.ColorButton(color=color)
color_hex_label = BasicLabel(hexval) color_hex_label = BasicLabel(hexval)
color_hex_label.set_hexpand(True) color_hex_label.set_hexpand(True)
entry.connect('color-set', self.update_color, constant, color_hex_label) entry.connect('notify::color', self.update_color, constant,
color_hex_label)
grid.attach(lwidget, col, index, 1, 1) grid.attach(lwidget, col, index, 1, 1)
grid.attach(entry, col+1, index, 1, 1) grid.attach(entry, col+1, index, 1, 1)
grid.attach(color_hex_label, col+2, index, 1, 1) grid.attach(color_hex_label, col+2, index, 1, 1)
@ -554,7 +573,7 @@ class GrampsPreferences(ConfigureDialog):
def add_color_panel(self, configdialog): def add_color_panel(self, configdialog):
""" """
Add the tab to set defaults colors for graph boxes Add the tab to set defaults colors for graph boxes.
""" """
grid = Gtk.Grid() grid = Gtk.Grid()
grid.set_border_width(12) grid.set_border_width(12)
@ -562,40 +581,62 @@ class GrampsPreferences(ConfigureDialog):
grid.set_row_spacing(6) grid.set_row_spacing(6)
self.add_text(grid, _('Set the colors used for boxes in the graphical views'), self.add_text(grid, _('Set the colors used for boxes in the graphical views'),
0, line_wrap=False) 0, line_wrap=False)
self.add_color(grid, _('Gender Male Alive'), 1,
'preferences.color-gender-male-alive') hbox = Gtk.Box(spacing=12)
self.add_color(grid, _('Border Male Alive'), 2, self.color_scheme_box = Gtk.ComboBoxText()
'preferences.bordercolor-gender-male-alive') formats = [_("Light colors"),
self.add_color(grid, _('Gender Male Death'), 3, _("Dark colors"),]
'preferences.color-gender-male-death') list(map(self.color_scheme_box.append_text, formats))
self.add_color(grid, _('Border Male Death'), 4, scheme = config.get('colors.scheme')
'preferences.bordercolor-gender-male-death') self.color_scheme_box.set_active(scheme)
self.add_color(grid, _('Gender Female Alive'), 1, self.color_scheme_box.connect('changed', self.color_scheme_changed)
'preferences.color-gender-female-alive', col=4) lwidget = BasicLabel(_("%s: ") % _('Color scheme'))
self.add_color(grid, _('Border Female Alive'), 2, hbox.pack_start(lwidget, False, False, 0)
'preferences.bordercolor-gender-female-alive', col=4) hbox.pack_start(self.color_scheme_box, False, False, 0)
self.add_color(grid, _('Gender Female Death'), 3,
'preferences.color-gender-female-death', col=4) restore_btn = Gtk.Button(_('Restore to defaults'))
self.add_color(grid, _('Border Female Death'), 4, restore_btn.connect('clicked', self.restore_colors)
'preferences.bordercolor-gender-female-death', col=4) hbox.pack_start(restore_btn, False, False, 0)
## self.add_color(grid, _('Gender Other Alive'), 5, grid.attach(hbox, 1, 1, 6, 1)
## 'preferences.color-gender-other-alive')
## self.add_color(grid, _('Border Other Alive'), 6, color_list = [
## 'preferences.bordercolor-gender-other-alive') (_('Male Alive'), 'male-alive', 2, 0),
## self.add_color(grid, _('Gender Other Death'), 7, (_('Male Dead'), 'male-dead', 4, 0),
## 'preferences.color-gender-other-death') (_('Female Alive'), 'female-alive', 2, 4),
## self.add_color(grid, _('Border Other Death'), 8, (_('Female Dead'), 'female-dead', 4, 4),
## 'preferences.bordercolor-gender-other-death') (_('Unknown Alive'), 'unknown-alive', 6, 4),
self.add_color(grid, _('Gender Unknown Alive'), 5, (_('Unknown Dead'), 'unknown-dead', 8, 4),
'preferences.color-gender-unknown-alive', col=4) (_('Family Node'), 'family', 7, 0),
self.add_color(grid, _('Border Unknown Alive'), 6, (_('Family Divorced'), 'family-divorced', 9, 0),
'preferences.bordercolor-gender-unknown-alive', col=4) (_('Home Person'), 'home-person', 6, 0),
self.add_color(grid, _('Gender Unknown Death'), 7, (_('Border Male Alive'), 'border-male-alive', 3, 0),
'preferences.color-gender-unknown-death', col=4) (_('Border Male Dead'), 'border-male-dead', 5, 0),
self.add_color(grid, _('Border Unknown Death'), 8, (_('Border Female Alive'), 'border-female-alive', 3, 4),
'preferences.bordercolor-gender-unknown-death', col=4) (_('Border Female Dead'), 'border-female-dead', 5, 4),
(_('Border Unknown Alive'), 'border-unknown-alive', 7, 4),
(_('Border Unknown Dead'), 'border-unknown-dead', 9, 4),
(_('Border Family'), 'border-family', 8, 0),
(_('Border Family Divorced'), 'border-family-divorced', 10, 0),
]
self.colors = {}
for color in color_list:
pref_name = 'colors.' + color[1]
self.colors[pref_name] = self.add_color(grid, color[0], color[2],
pref_name, col=color[3])
return _('Colors'), grid return _('Colors'), grid
def restore_colors(self, widget=None):
"""
Restore colors of selected scheme to default.
"""
scheme = config.get('colors.scheme')
for key, widget in self.colors.items():
color = Gdk.RGBA()
hexval = config.get_default(key)[scheme]
Gdk.RGBA.parse(color, hexval)
widget.set_rgba(color)
def add_advanced_panel(self, configdialog): def add_advanced_panel(self, configdialog):
grid = Gtk.Grid() grid = Gtk.Grid()
grid.set_border_width(12) grid.set_border_width(12)
@ -1205,6 +1246,18 @@ class GrampsPreferences(ConfigureDialog):
self.old_format = the_list.get_value(the_iter, COL_FMT) self.old_format = the_list.get_value(the_iter, COL_FMT)
win = DisplayNameEditor(self.uistate, self.dbstate, self.track, self) win = DisplayNameEditor(self.uistate, self.dbstate, self.track, self)
def color_scheme_changed(self, obj):
"""
Called on swiching color scheme.
"""
scheme = obj.get_active()
config.set('colors.scheme', scheme)
for key, widget in self.colors.items():
color = Gdk.RGBA()
hexval = config.get(key)[scheme]
Gdk.RGBA.parse(color, hexval)
widget.set_rgba(color)
def check_for_type_changed(self, obj): def check_for_type_changed(self, obj):
active = obj.get_active() active = obj.get_active()
if active == 0: # update if active == 0: # update

View File

@ -53,6 +53,7 @@ from gi.repository import Gdk
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext _ = glocale.translation.gettext
from gramps.gen.lib import EventType, EventRoleType
from gramps.gen.lib.person import Person from gramps.gen.lib.person import Person
from gramps.gen.constfunc import has_display, is_quartz, mac, win from gramps.gen.constfunc import has_display, is_quartz, mac, win
from gramps.gen.config import config from gramps.gen.config import config
@ -474,33 +475,50 @@ def is_right_click(event):
if Gdk.Event.triggers_context_menu(event): if Gdk.Event.triggers_context_menu(event):
return True return True
def color_graph_family(family, dbstate):
"""
:return: based on the config the color for graph family node in hex
:rtype: tuple (hex color fill, hex color border)
"""
scheme = config.get('colors.scheme')
for event_ref in family.get_event_ref_list():
event = dbstate.db.get_event_from_handle(event_ref.ref)
if (event.type == EventType.DIVORCE and
event_ref.get_role() in (EventRoleType.FAMILY,
EventRoleType.PRIMARY)):
return (config.get('colors.family-divorced')[scheme],
config.get('colors.border-family-divorced')[scheme])
return (config.get('colors.family')[scheme],
config.get('colors.border-family')[scheme])
def color_graph_box(alive=False, gender=Person.MALE): def color_graph_box(alive=False, gender=Person.MALE):
""" """
:return: based on the config the color for graph boxes in hex :return: based on the config the color for graph boxes in hex
If gender is None, an empty box is assumed If gender is None, an empty box is assumed
:rtype: tuple (hex color fill, hex color border) :rtype: tuple (hex color fill, hex color border)
""" """
scheme = config.get('colors.scheme')
if gender == Person.MALE: if gender == Person.MALE:
if alive: if alive:
return (config.get('preferences.color-gender-male-alive'), return (config.get('colors.male-alive')[scheme],
config.get('preferences.bordercolor-gender-male-alive')) config.get('colors.border-male-alive')[scheme])
else: else:
return (config.get('preferences.color-gender-male-death'), return (config.get('colors.male-dead')[scheme],
config.get('preferences.bordercolor-gender-male-death')) config.get('colors.border-male-dead')[scheme])
elif gender == Person.FEMALE: elif gender == Person.FEMALE:
if alive: if alive:
return (config.get('preferences.color-gender-female-alive'), return (config.get('colors.female-alive')[scheme],
config.get('preferences.bordercolor-gender-female-alive')) config.get('colors.border-female-alive')[scheme])
else: else:
return (config.get('preferences.color-gender-female-death'), return (config.get('colors.female-dead')[scheme],
config.get('preferences.bordercolor-gender-female-death')) config.get('colors.border-female-dead')[scheme])
elif gender == Person.UNKNOWN: elif gender == Person.UNKNOWN:
if alive: if alive:
return (config.get('preferences.color-gender-unknown-alive'), return (config.get('colors.unknown-alive')[scheme],
config.get('preferences.bordercolor-gender-unknown-alive')) config.get('colors.border-unknown-alive')[scheme])
else: else:
return (config.get('preferences.color-gender-unknown-death'), return (config.get('colors.unknown-dead')[scheme],
config.get('preferences.bordercolor-gender-unknown-death')) config.get('colors.border-unknown-dead')[scheme])
#empty box, no gender #empty box, no gender
return ('#d2d6ce', '#000000') return ('#d2d6ce', '#000000')
## print 'male alive', rgb_to_hex((185/256.0, 207/256.0, 231/256.0)) ## print 'male alive', rgb_to_hex((185/256.0, 207/256.0, 231/256.0))