diff --git a/ChangeLog b/ChangeLog index 2b3286702..22dfc9262 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2006-02-21 Don Allingham + * src/AddrEdit.py: Full edit functionality + * src/AttrEdit.py: Full edit functionality + * src/DisplayTabs.py: call EditEventRef + * src/EditSourceRef.py: Full edit functionality + * src/EventEdit.py: separate out EditEventRef + * src/GrampsWidgets.py: Add date, menu, type handling widgets + * src/NameEdit.py: Full edit functionality + * src/gramps.glade: fix names and privacy buttons + * src/EditEventRef.py: broken out of EditEvent + 2006-02-20 Don Allingham * src/GrampsWidgets.py: Add monitored widgets for type and combo * src/EditFamily.py: use MonitoredType diff --git a/src/AddrEdit.py b/src/AddrEdit.py index 7bcb6e220..705648338 100644 --- a/src/AddrEdit.py +++ b/src/AddrEdit.py @@ -54,8 +54,8 @@ import DateHandler import DisplayState import Spell -from WindowUtils import GladeIf from DisplayTabs import * +from GrampsWidgets import * #------------------------------------------------------------------------- # @@ -84,62 +84,64 @@ class AddressEditor(DisplayState.ManagedWindow): if self.already_exist: return - # Get the important widgets from the glade description - self.top = gtk.glade.XML(const.gladeFile, "addr_edit","gramps") - self.gladeif = GladeIf(self.top) - - self.window = self.top.get_widget("addr_edit") - self.addr_start = self.top.get_widget("address_start") - self.addr_start.set_editable(not self.db.readonly) - self.street = self.top.get_widget("street") - self.street.set_editable(not self.db.readonly) - self.city = self.top.get_widget("city") - self.city.set_editable(not self.db.readonly) - self.state = self.top.get_widget("state") - self.state.set_editable(not self.db.readonly) - self.country = self.top.get_widget("country") - self.country.set_editable(not self.db.readonly) - self.postal = self.top.get_widget("postal") - self.postal.set_editable(not self.db.readonly) - self.phone = self.top.get_widget("phone") - self.phone.set_editable(not self.db.readonly) - self.priv = self.top.get_widget("priv") - self.priv.set_sensitive(not self.db.readonly) - - title_label = self.top.get_widget("title") - - Utils.set_titles(self.window,title_label,_('Address Editor')) - - if self.addr: - self.addr_date_obj = RelLib.Date(self.addr.get_date_object()) - self.addr_start.set_text(DateHandler.get_date(self.addr)) - self.street.set_text(self.addr.get_street()) - self.city.set_text(self.addr.get_city()) - self.state.set_text(self.addr.get_state()) - self.country.set_text(self.addr.get_country()) - self.postal.set_text(self.addr.get_postal_code()) - self.phone.set_text(self.addr.get_phone()) - self.priv.set_active(self.addr.get_privacy()) - else: - self.addr_date_obj = RelLib.Date() + if not self.addr: self.addr = RelLib.Address() - date_stat = self.top.get_widget("date_stat") - date_stat.set_sensitive(not self.db.readonly) - self.date_check = DateEdit.DateEdit( - self.addr_date_obj, self.addr_start, date_stat, self.window) + # Get the important widgets from the glade description + self.top = gtk.glade.XML(const.gladeFile, "addr_edit","gramps") + self.window = self.top.get_widget("addr_edit") - self.gladeif.connect('addr_edit','delete_event',self.on_delete_event) - self.gladeif.connect('button122','clicked',self.close_window) - self.gladeif.connect('button121','clicked',self.ok_clicked) - okbtn = self.top.get_widget('button121') - okbtn.set_sensitive(not self.db.readonly) - self.gladeif.connect('button129','clicked',self.on_help_clicked) + title_label = self.top.get_widget("title") + Utils.set_titles(self.window,title_label,_('Address Editor')) + self._setup_fields() self._create_tabbed_pages() - + self._connect_signals() self.show() + def _setup_fields(self): + self.addr_start = MonitoredDate( + self.top.get_widget("address_start"), + self.top.get_widget("date_stat"), + self.addr.get_date_object(), + self.window, self.db.readonly) + + self.street = MonitoredEntry( + self.top.get_widget("street"), self.addr.set_street, + self.addr.get_street, self.db.readonly) + + self.city = MonitoredEntry( + self.top.get_widget("city"), self.addr.set_city, + self.addr.get_city, self.db.readonly) + + self.state = MonitoredEntry( + self.top.get_widget("state"), self.addr.set_state, + self.addr.get_state, self.db.readonly) + + self.country = MonitoredEntry( + self.top.get_widget("country"), self.addr.set_country, + self.addr.get_country, self.db.readonly) + + self.postal = MonitoredEntry( + self.top.get_widget("postal"), self.addr.set_postal_code, + self.addr.get_postal_code, self.db.readonly) + + self.phone = MonitoredEntry( + self.top.get_widget("phone"), self.addr.set_phone, + self.addr.get_phone, self.db.readonly) + + self.priv = PrivacyButton(self.top.get_widget("private"), + self.addr, self.db.readonly) + + def _connect_signals(self): + self.window.connect('delete_event',self.on_delete_event) + self.top.get_widget('cancel').connect('clicked',self.close_window) + self.top.get_widget('help').connect('clicked',self.help_clicked) + + okbtn = self.top.get_widget('ok') + okbtn.connect('clicked',self.ok_clicked) + okbtn.set_sensitive(not self.db.readonly) + def _add_page(self,page): self.notebook.insert_page(page) self.notebook.set_tab_label(page,page.get_tab_widget()) @@ -167,18 +169,16 @@ class AddressEditor(DisplayState.ManagedWindow): vbox.pack_start(self.notebook,True) def on_delete_event(self,obj,b): - self.gladeif.close() self.close() def close_window(self,obj): - self.gladeif.close() self.window.destroy() self.close() def build_menu_names(self,obj): return (_('Address'),_('Address Editor')) - def on_help_clicked(self,obj): + def help_clicked(self,obj): """Display the relevant portion of GRAMPS manual""" GrampsDisplay.help('adv-ad') @@ -187,41 +187,6 @@ class AddressEditor(DisplayState.ManagedWindow): Called when the OK button is pressed. Gets data from the form and updates the Address data structure. """ - date_obj = self.addr_date_obj - street = unicode(self.street.get_text()) - city = unicode(self.city.get_text()) - state = unicode(self.state.get_text()) - country = unicode(self.country.get_text()) - phone = unicode(self.phone.get_text()) - postal = unicode(self.postal.get_text()) - b = self.note_field.get_buffer() - note = unicode(b.get_text(b.get_start_iter(),b.get_end_iter(),False)) - priv = self.priv.get_active() - - self.addr.set_source_reference_list(self.srcreflist) - - self.update(date_obj,street,city,state,country,postal,phone,priv) self.callback(self.addr) self.close_window(obj) - def check(self,get,set,data): - """Compares a data item, updates if necessary, and sets the - parents lists_changed flag""" - if get() != data: - set(data) - - def update(self,date_obj,street,city,state,country,postal,phone,priv): - """Compares the data items, and updates if necessary""" - - if not self.addr.get_date_object().is_equal(date_obj): - self.addr.set_date_object(date_obj) - - self.check(self.addr.get_street,self.addr.set_street,street) - self.check(self.addr.get_country,self.addr.set_country,country) - self.check(self.addr.get_city,self.addr.set_city,city) - self.check(self.addr.get_state,self.addr.set_state,state) - self.check(self.addr.get_postal_code,self.addr.set_postal_code,postal) - self.check(self.addr.get_phone,self.addr.set_phone,phone) - self.check(self.addr.get_note,self.addr.set_note,note) - self.check(self.addr.get_note_format,self.addr.set_note_format,format) - self.check(self.addr.get_privacy,self.addr.set_privacy,priv) diff --git a/src/AttrEdit.py b/src/AttrEdit.py index 4db8b70a0..bd4b603f2 100644 --- a/src/AttrEdit.py +++ b/src/AttrEdit.py @@ -34,8 +34,6 @@ __version__ = "$Revision$" # #------------------------------------------------------------------------- from gettext import gettext as _ -import gc -from cgi import escape #------------------------------------------------------------------------- # @@ -51,16 +49,13 @@ import gtk.glade #------------------------------------------------------------------------- import const import Utils -import Sources -import AutoComp import RelLib -import Spell import GrampsDisplay import DisplayState from QuestionDialog import WarningDialog -from WindowUtils import GladeIf from DisplayTabs import * +from GrampsWidgets import * #------------------------------------------------------------------------- # @@ -93,47 +88,47 @@ class AttributeEditor(DisplayState.ManagedWindow): if self.already_exist: return + if not attrib: + self.attrib = RelLib.Attribute() + self.top = gtk.glade.XML(const.gladeFile, "attr_edit","gramps") - self.value_field = self.top.get_widget("attr_value") - self.attrib_menu = self.top.get_widget("attr_menu") - self.source_field = self.top.get_widget("attr_source") - self.priv = self.top.get_widget("priv") self.notebook = self.top.get_widget("notebook") self.window = self.top.get_widget("attr_edit") - self.type_selector = AutoComp.StandardCustomSelector( - Utils.personal_attributes,self.attrib_menu, - RelLib.Attribute.CUSTOM,RelLib.Attribute.DESCRIPTION) - - if title == ", ": - title = _("Attribute Editor") - else: - title = _("Attribute Editor for %s") % escape(title) + title = _("Attribute Editor") l = self.top.get_widget("title") Utils.set_titles(self.window,l,title,_('Attribute Editor')) - - if attrib: - self.type_selector.set_values(attrib.get_type()) - self.value_field.set_text(attrib.get_value()) - self.priv.set_active(attrib.get_privacy()) - else: - self.attrib = RelLib.Attribute() - self.gladeif = GladeIf(self.top) - self.gladeif.connect('attr_edit','delete_event', self.on_delete_event) - self.gladeif.connect('button116', 'clicked', self.close_window) - self.gladeif.connect('button115', 'clicked', self.on_ok_clicked) - self.gladeif.connect('button127', 'clicked', self.on_help_clicked) - - if self.db.readonly: - w = self.top.get_widget("button115") - w.set_sensitive(False) - self.value_field.set_editable(False) - self.attrib_menu.set_sensitive(False) - self._create_tabbed_pages() + self._setup_fields() + self._connect_signals() self.show() + def _connect_signals(self): + self.window.connect('delete_event', self.on_delete_event) + + self.top.get_widget('cancel').connect('clicked', self.close_window) + self.top.get_widget('help').connect('clicked', self.on_help_clicked) + + ok = self.top.get_widget('ok') + ok.connect('clicked', self.on_ok_clicked) + if self.db.readonly: + ok.set_sensitive(False) + + def _setup_fields(self): + self.value_field = MonitoredEntry( + self.top.get_widget("attr_value"), + self.attrib.set_value, self.attrib.get_value, + self.db.readonly) + + self.priv = PrivacyButton(self.top.get_widget("private"),self.attrib) + + self.type_selector = MonitoredType( + self.top.get_widget("attr_menu"), + self.attrib.set_type, self.attrib.get_type, + dict(Utils.personal_attributes), + RelLib.Attribute.CUSTOM) + def _create_tabbed_pages(self): vbox = self.top.get_widget('vbox') @@ -153,11 +148,9 @@ class AttributeEditor(DisplayState.ManagedWindow): return page def on_delete_event(self,obj,b): - self.gladeif.close() self.close() def close_window(self,obj): - self.gladeif.close() self.close() def build_menu_names(self, attrib): @@ -179,11 +172,8 @@ class AttributeEditor(DisplayState.ManagedWindow): Called when the OK button is pressed. Gets data from the form and updates the Attribute data structure. """ - attr_data = self.type_selector.get_values() - value = unicode(self.value_field.get_text()) - - priv = self.priv.get_active() + attr_data = self.attrib.get_type() if (attr_data[0] == RelLib.Attribute.CUSTOM and not attr_data[1] in self.alist): WarningDialog( @@ -193,18 +183,6 @@ class AttributeEditor(DisplayState.ManagedWindow): self.alist.append(attr_data[1]) self.alist.sort() - self.update(attr_data,value,priv) self.callback(self.attrib) self.close_window(obj) - def check(self,get,set,data): - """Compares a data item, updates if necessary, and sets the - parents lists_changed flag""" - if get() != data: - set(data) - - def update(self,attr_data,value,priv): - """Compares the data items, and updates if necessary""" - self.check(self.attrib.get_type,self.attrib.set_type,attr_data) - self.check(self.attrib.get_value,self.attrib.set_value,value) - self.check(self.attrib.get_privacy,self.attrib.set_privacy,priv) diff --git a/src/DisplayTabs.py b/src/DisplayTabs.py index 73310496d..e2dd1545d 100644 --- a/src/DisplayTabs.py +++ b/src/DisplayTabs.py @@ -592,26 +592,26 @@ class EventEmbedList(EmbeddedList): return ((1,0),(1,1),(1,2),(1,3),(1,4),(1,5)) def add_button_clicked(self,obj): - import EventEdit - EventEdit.EventRefEditor(self.dbstate,self.uistate,self.track, - None, None, self.obj, self.event_added) + from EditEventRef import EditEventRef + EditEventRef(self.dbstate,self.uistate,self.track, + None, None, self.obj, self.event_added) def share_button_clicked(self,obj): - import EventEdit + from EditEventRef import EditEventRef import SelectEvent sel = SelectEvent.SelectEvent(self.dbstate.db,"Event Select") event = sel.run() - EventEdit.EventRefEditor(self.dbstate,self.uistate,self.track, - event, None, self.obj, self.event_added) + EditEventRef(self.dbstate,self.uistate,self.track, + event, None, self.obj, self.event_added) def edit_button_clicked(self,obj): ref = self.get_selected() if ref: - import EventEdit + from EditEventRef import EditEventRef event = self.dbstate.db.get_event_from_handle(ref.ref) - EventEdit.EventRefEditor(self.dbstate,self.uistate,self.track, - event, ref, self.obj, self.event_updated) + EditEventRef(self.dbstate,self.uistate,self.track, + event, ref, self.obj, self.event_updated) def event_updated(self,value): self.changed = True diff --git a/src/EditSourceRef.py b/src/EditSourceRef.py index 1b9c7f851..ef4f798e9 100644 --- a/src/EditSourceRef.py +++ b/src/EditSourceRef.py @@ -51,8 +51,6 @@ import const import Utils import AutoComp import RelLib -from DateHandler import parser as _dp, displayer as _dd -import DateEdit import GrampsDisplay import DisplayState @@ -86,17 +84,13 @@ class EditSourceRef(DisplayState.ManagedWindow): self.top = gtk.glade.XML(const.gladeFile, "source_ref_edit","gramps") self.window = self.top.get_widget('source_ref_edit') - self.ref_note_field = self.top.get_widget('eer_ref_note') - self.role_combo = self.top.get_widget('eer_role_combo') - self.date_field = self.top.get_widget("date") - self.ok = self.top.get_widget('ok') - self.expander = self.top.get_widget("src_expander") - self.warning = self.top.get_widget("warn_box") self.notebook_src = self.top.get_widget('notebook_src') self.notebook_ref = self.top.get_widget('notebook_ref') - self.expander.set_expanded(True) + expander = self.top.get_widget("src_expander") + expander.set_expanded(True) + warning = self.top.get_widget("warn_box") if self.source.handle: self.warning.show_all() else: @@ -116,13 +110,6 @@ class EditSourceRef(DisplayState.ManagedWindow): Utils.set_titles(self.window, self.top.get_widget('source_title'), self.title) - self.date = self.source_ref.get_date_object() - self.date_check = DateEdit.DateEdit( - self.source_ref.date, self.date_field, - self.top.get_widget("date_stat"), self.window) - - self.date_field.set_text(_dd.display(self.date)) - self._create_tabbed_pages() self._setup_fields() self._connect_signals() @@ -173,6 +160,11 @@ class EditSourceRef(DisplayState.ManagedWindow): (_('High'), RelLib.SourceRef.CONF_HIGH), (_('Very High'), RelLib.SourceRef.CONF_VERY_HIGH)]) + + self.date = MonitoredDate(self.top.get_widget("date"), + self.top.get_widget("date_stat"), + self.source_ref.get_date_object(),self.window) + def _add_source_page(self,page): self.notebook_src.insert_page(page) self.notebook_src.set_tab_label(page,page.get_tab_widget()) diff --git a/src/EventEdit.py b/src/EventEdit.py index 270fc3a7a..035931208 100644 --- a/src/EventEdit.py +++ b/src/EventEdit.py @@ -306,224 +306,6 @@ class EventEditor(DisplayState.ManagedWindow): data.union(self.db.get_person_event_types()) return list(data) -#------------------------------------------------------------------------- -# -# EventRefEditor class -# -#------------------------------------------------------------------------- -class EventRefEditor(DisplayState.ManagedWindow): - def __init__(self, state, uistate, track, - event, event_ref, referent, update): - self.db = state.db - self.state = state - self.uistate = uistate - self.referent = referent - self.event_ref = event_ref - self.event = event - - DisplayState.ManagedWindow.__init__(self, uistate, track, event_ref) - if self.already_exist: - return - - self.update = update - - self.pmap = {} - for key in self.db.get_place_handles(): - title = self.db.get_place_from_handle(key).get_title() - self.pmap[title] = key - - self.title = _('Event Reference Editor') - - self.top = gtk.glade.XML(const.gladeFile, "event_eref_edit","gramps") - self.window = self.top.get_widget('event_eref_edit') - self.ref_note_field = self.top.get_widget('eer_ref_note') - self.role_combo = self.top.get_widget('eer_role_combo') - self.date_field = self.top.get_widget("eer_date") - self.place_field = self.top.get_widget("eer_place") - self.cause_field = self.top.get_widget("eer_cause") - self.ev_note_field = self.top.get_widget("eer_ev_note") - self.type_combo = self.top.get_widget("eer_type_combo") - self.general_label = self.top.get_widget("eer_general_tab") - self.ok = self.top.get_widget('ok') - self.expander = self.top.get_widget("eer_expander") - self.warning = self.top.get_widget("eer_warning") - self.notebook = self.top.get_widget('notebook') - - if self.referent.__class__.__name__ == 'Person': - default_type = RelLib.Event.BIRTH - default_role = RelLib.EventRef.PRIMARY - ev_dict = Utils.personal_events - role_dict = Utils.event_roles - elif self.referent.__class__.__name__ == 'Family': - default_type = RelLib.Event.MARRIAGE - default_role = RelLib.EventRef.FAMILY - ev_dict = Utils.family_events - role_dict = Utils.family_event_roles - - if self.event: - self.event_added = False - self.date = RelLib.Date(self.event.get_date_object()) - if self.event_ref: - if self.event_ref.get_role()[0] == default_role: - self.expander.set_expanded(True) - self.warning.hide() - else: - self.expander.set_expanded(False) - self.warning.show_all() - else: - self.event = RelLib.Event() - self.event.set_type((default_type,ev_dict[default_type])) - self.event.set_handle(self.db.create_id()) - self.event.set_gramps_id(self.db.find_next_event_gramps_id()) - self.event_added = True - self.date = RelLib.Date(None) - self.expander.set_expanded(True) - self.warning.hide() - - if not self.event_ref: - self.event_ref = RelLib.EventRef() - self.event_ref.set_role((default_role,role_dict[default_role])) - self.event_ref.set_reference_handle(self.event.get_handle()) - - self.cause_monitor = MonitoredEntry(self.cause_field,self.event.set_cause, - self.event.get_cause, False) - self.ref_privacy = PrivacyButton(self.top.get_widget('eer_ref_priv'), - self.event_ref) - - self.descr_field = MonitoredEntry(self.top.get_widget("eer_description"), - self.event.set_description, - self.event.get_description, False) - - self.ev_privacy = PrivacyButton(self.top.get_widget("eer_ev_priv"), - self.event) - - Utils.set_titles(self.window, - self.top.get_widget('eer_title'), - self.title) - - self.top.signal_autoconnect({ - "on_eer_help_clicked" : self.on_help_clicked, - "on_eer_ok_clicked" : self.on_ok_clicked, - "on_eer_cancel_clicked" : self.close, - "on_eer_delete_event" : self.close, - }) - - self.role_selector = AutoComp.StandardCustomSelector( - role_dict,self.role_combo, - RelLib.EventRef.CUSTOM,default_role) - - AutoComp.fill_entry(self.place_field,self.pmap.keys()) - - self.type_selector = AutoComp.StandardCustomSelector( - ev_dict,self.type_combo, - RelLib.Event.CUSTOM,default_type) - - self.date_check = DateEdit.DateEdit(self.date, - self.date_field, - self.top.get_widget("eer_date_stat"), - self.window) - - # set event_ref values - self.role_selector.set_values(self.event_ref.get_role()) - self.ref_note_field.get_buffer().set_text(self.event_ref.get_note()) - - # set event values - self.type_selector.set_values(self.event.get_type()) - place_handle = self.event.get_place_handle() - if not place_handle: - place_name = u"" - else: - place_name = self.db.get_place_from_handle(place_handle).get_title() - self.place_field.set_text(place_name) - self.date_field.set_text(_dd.display(self.date)) - - self._create_tabbed_pages() - - self.show() - - def _add_page(self,page): - self.notebook.insert_page(page) - self.notebook.set_tab_label(page,page.get_tab_widget()) - return page - - def _create_tabbed_pages(self): - """ - Creates the notebook tabs and inserts them into the main - window. - - """ - - self.srcref_list = self._add_page(SourceEmbedList( - self.state,self.uistate, self.track, - self.event.source_list)) - self.note_tab = self._add_page(NoteTab( - self.state, self.uistate, self.track, - self.event.get_note_object())) - self.gallery_tab = self._add_page(GalleryTab( - self.state, self.uistate, self.track, - self.event.get_media_list())) - - def build_menu_names(self,eventref): - if self.event: - if self.event.get_type()[0] == RelLib.Event.CUSTOM: - event_name = self.event.get_type()[1] - else: - try: - event_name = Utils.personal_events[self.event.get_type()[0]] - except: - event_name = Utils.family_events[self.event.get_type()[0]] - submenu_label = _('Event: %s') % event_name - else: - submenu_label = _('New Event') - return (_('Event Reference Editor'),submenu_label) - - def build_window_key(self,eventref): - if self.event: - return self.event.get_handle() - else: - return id(self) - - def on_help_clicked(self,obj): - pass - - def on_ok_clicked(self,obj): - - # first, save event if changed - etype = self.type_selector.get_values() - eplace_obj = get_place(self.place_field,self.pmap,self.db) - self.update_event(etype,self.date,eplace_obj) - - trans = self.db.transaction_begin() - self.db.commit_event(self.event,trans) - if self.event_added: - self.db.transaction_commit(trans,_("Add Event")) - else: - self.db.transaction_commit(trans,_("Modify Event")) - - # then, set properties of the event_ref - self.event_ref.set_role(self.role_selector.get_values()) - self.event_ref.set_privacy(self.ref_privacy.get_active()) - self.close(None) - - if self.update: - self.update((self.event_ref,self.event)) - - def update_event(self,the_type,date,place): - if place: - if self.event.get_place_handle() != place.get_handle(): - self.event.set_place_handle(place.get_handle()) - else: - if self.event.get_place_handle(): - self.event.set_place_handle("") - - if self.event.get_type() != the_type: - self.event.set_type(the_type) - - dobj = self.event.get_date_object() - - if not dobj.is_equal(date): - self.event.set_date_object(date) - #------------------------------------------------------------------------- # # Delete Query class diff --git a/src/GrampsWidgets.py b/src/GrampsWidgets.py index 3031f18aa..2fade5568 100644 --- a/src/GrampsWidgets.py +++ b/src/GrampsWidgets.py @@ -32,6 +32,8 @@ import gobject import gtk import AutoComp +import DateHandler +import DateEdit class LinkLabel(gtk.EventBox): @@ -190,12 +192,13 @@ class TypeCellRenderer(gtk.CellRendererCombo): class PrivacyButton: - def __init__(self,button,obj): + def __init__(self,button,obj,readonly=False): self.button = button self.button.connect('toggled',self._on_toggle) self.tooltips = gtk.Tooltips() self.obj = obj self.set_active(obj.get_privacy()) + self.button.set_sensitive(not readonly) def set_sensitive(self,val): self.button.set_sensitive(val) @@ -213,28 +216,57 @@ class PrivacyButton: obj.remove(child) image = gtk.Image() if obj.get_active(): - image.set_from_icon_name('stock_lock',gtk.ICON_SIZE_BUTTON) + image.set_from_icon_name('stock_lock',gtk.ICON_SIZE_MENU) self.tooltips.set_tip(obj,_('Record is private')) self.obj.set_privacy(True) else: - image.set_from_icon_name('stock_lock-open',gtk.ICON_SIZE_BUTTON) + image.set_from_icon_name('stock_lock-open',gtk.ICON_SIZE_MENU) self.tooltips.set_tip(obj,_('Record is public')) self.obj.set_privacy(False) image.show() obj.add(image) - -class MonitoredEntry: - def __init__(self,obj,set_val,get_val,read_only=False): +class MonitoredCheckbox: + + def __init__(self,obj,button,set_val,get_val,on_toggle=None): + self.button = button + self.button.connect('toggled',self._on_toggle) + self.on_toggle = on_toggle self.obj = obj self.set_val = set_val self.get_val = get_val + self.set_active(get_val()) + + def _on_toggle(self,obj): + self.set_val(obj.get_active()) + if self.on_toggle: + self.on_toggle(get_val()) + +class MonitoredEntry: + + def __init__(self,obj,set_val,get_val,read_only=False, changed=None): + self.obj = obj + self.set_val = set_val + self.get_val = get_val + self.changed = changed if get_val(): self.obj.set_text(get_val()) - self.obj.connect('changed', lambda x: self.set_val(unicode(x.get_text()))) + self.obj.connect('changed', self._on_change) self.obj.set_editable(not read_only) + def _on_change(self,obj): + self.set_val(unicode(obj.get_text())) + if self.changed: + self.changed(obj) + + def force_value(self,value): + self.obj.set_text(value) + + def enable(self,value): + self.obj.set_sensitive(value) + self.obj.set_editable(value) + class MonitoredText: def __init__(self,obj,set_val,get_val,read_only=False): @@ -275,7 +307,7 @@ class MonitoredType: class MonitoredMenu: - def __init__(self,obj,set_val,get_val,mapping): + def __init__(self,obj,set_val,get_val,mapping,readonly=False): self.set_val = set_val self.get_val = get_val @@ -286,7 +318,19 @@ class MonitoredMenu: self.obj.set_model(self.model) self.obj.set_active(get_val()) self.obj.connect('changed',self.on_change) + self.obj.set_sensitive(not readonly) def on_change(self, obj): self.set_val(self.model.get_value(obj.get_active_iter(),1)) +class MonitoredDate: + + def __init__(self,field,button,value,window, readonly=False): + self.date = value + self.date_check = DateEdit.DateEdit( + self.date, field, button, window) + field.set_editable(not readonly) + button.set_sensitive(not readonly) + + field.set_text(DateHandler.displayer.display(self.date)) + diff --git a/src/NameEdit.py b/src/NameEdit.py index 824f1235d..bd2cabd2e 100644 --- a/src/NameEdit.py +++ b/src/NameEdit.py @@ -53,8 +53,7 @@ import Spell import GrampsDisplay import DisplayState from DisplayTabs import * - -from WindowUtils import GladeIf +from GrampsWidgets import * #------------------------------------------------------------------------- # @@ -76,56 +75,17 @@ class NameEditor(DisplayState.ManagedWindow): return self.name = name + self.original_group_as = self.name.get_group_as() + self.top = gtk.glade.XML(const.gladeFile, "name_edit","gramps") - self.gladeif = GladeIf(self.top) self.window = self.top.get_widget("name_edit") - self.given_field = self.top.get_widget("alt_given") - self.given_field.set_editable(not self.db.readonly) - self.sort_as = self.top.get_widget("sort_as") - self.sort_as.set_sensitive(not self.db.readonly) - self.display_as = self.top.get_widget("display_as") - self.display_as.set_sensitive(not self.db.readonly) - self.group_as = self.top.get_widget("group_as") - self.title_field = self.top.get_widget("alt_title") - self.title_field.set_editable(not self.db.readonly) - self.suffix_field = self.top.get_widget("alt_suffix") - self.suffix_field.set_editable(not self.db.readonly) - self.patronymic_field = self.top.get_widget("patronymic") - self.patronymic_field.set_editable(not self.db.readonly) - self.surname_field = self.top.get_widget("alt_surname") - self.date = self.top.get_widget('date') - self.date.set_editable(not self.db.readonly) - if self.name: - self.date_obj = self.name.get_date_object() - else: - self.date_obj = RelLib.Date() - self.name = RelLib.Name() - - self.date.set_text(DateHandler.displayer.display(self.date_obj)) - - date_stat = self.top.get_widget("date_stat") - date_stat.set_sensitive(not self.db.readonly) - self.date_check = DateEdit.DateEdit( - self.date_obj, self.date, - date_stat, self.window) - - self.prefix_field = self.top.get_widget("alt_prefix") - self.prefix_field.set_editable(not self.db.readonly) - - self.type_combo = self.top.get_widget("name_type") - self.type_combo.set_sensitive(not self.db.readonly) - - self.priv = self.top.get_widget("priv") self.notebook = self.top.get_widget("notebook") self.general_label = self.top.get_widget("general_tab") - self.priv.set_sensitive(not self.db.readonly) - self.group_over = self.top.get_widget('group_over') - self.group_over.set_sensitive(not self.db.readonly) - self.type_selector = AutoComp.StandardCustomSelector( - Utils.name_types, self.type_combo, RelLib.Name.CUSTOM, - RelLib.Name.BIRTH) + self.group_over = self.top.get_widget('group_over') + self.group_over.connect('toggled',self.on_group_over_toggled) + self.group_over.set_sensitive(not self.db.readonly) full_name = NameDisplay.displayer.display_name(name) @@ -138,37 +98,86 @@ class NameEditor(DisplayState.ManagedWindow): Utils.set_titles(self.window, alt_title, tmsg, _('Name Editor')) - self.gladeif.connect('name_edit','delete_event',self.on_delete_event) - self.gladeif.connect('button119','clicked',self.close_window) - self.gladeif.connect('button118','clicked',self.on_name_edit_ok_clicked) + Utils.bold_label(self.general_label) + + self._create_tabbed_pages() + self._setup_fields() + self._connect_signals() + + if self.original_group_as and self.original_group_as != self.name.get_surname(): + self.group_over.set_active(True) + + self.show() + + def _connect_signals(self): + self.window.connect('delete_event',self.on_delete_event) + self.top.get_widget('button119').connect('clicked',self.close_window) + self.top.get_widget('button131').connect('clicked',self.on_help_clicked) okbtn = self.top.get_widget('button118') okbtn.set_sensitive(not self.db.readonly) - self.gladeif.connect('button131','clicked',self.on_help_clicked) - self.gladeif.connect('group_over','toggled',self.on_group_over_toggled) + okbtn.connect('clicked',self.on_name_edit_ok_clicked) - if name != None: - self.given_field.set_text(name.get_first_name()) - self.surname_field.set_text(name.get_surname()) - self.title_field.set_text(name.get_title()) - self.suffix_field.set_text(name.get_suffix()) - self.prefix_field.set_text(name.get_surname_prefix()) - self.type_selector.set_values(name.get_type()) - self.patronymic_field.set_text(name.get_patronymic()) - self.priv.set_active(name.get_privacy()) - Utils.bold_label(self.general_label) - self.display_as.set_active(name.get_display_as()) - self.sort_as.set_active(name.get_display_as()) - grp_as = name.get_group_as() - if grp_as: - self.group_as.set_text(name.get_group_as()) - else: - self.group_as.set_text(name.get_surname()) - else: - self.display_as.set_active(0) - self.sort_as.set_active(0) + def _setup_fields(self): + self.group_as = MonitoredEntry( + self.top.get_widget("group_as"), self.name.set_group_as, + self.name.get_group_as, self.db.readonly) - self.surname_field.connect('changed',self.update_group_as) + if not self.original_group_as: + self.group_as.force_value(self.name.get_surname()) + + self.sort_as = MonitoredMenu( + self.top.get_widget('sort_as'),self.name.set_sort_as, + self.name.get_sort_as, + [(_('Default (based on locale'),RelLib.Name.DEF), + (_('Given name Family name'), RelLib.Name.FNLN), + (_('Family name Given Name'), RelLib.Name.LNFN)], + self.db.readonly) + self.display_as = MonitoredMenu( + self.top.get_widget('display_as'), + self.name.set_display_as, self.name.get_display_as, + [(_('Default (based on locale'),RelLib.Name.DEF), + (_('Given name Family name'), RelLib.Name.FNLN), + (_('Family name Given Name'), RelLib.Name.LNFN)], + self.db.readonly) + + self.given_field = MonitoredEntry( + self.top.get_widget("alt_given"), self.name.set_first_name, + self.name.get_first_name, self.db.readonly) + + self.title_field = MonitoredEntry( + self.top.get_widget("alt_title"), self.name.set_title, + self.name.get_title, self.db.readonly) + + self.suffix_field = MonitoredEntry( + self.top.get_widget("alt_suffix"), self.name.set_suffix, + self.name.get_suffix, self.db.readonly) + + self.patronymic_field = MonitoredEntry( + self.top.get_widget("patronymic"), self.name.set_patronymic, + self.name.get_patronymic, self.db.readonly) + + self.surname_field = MonitoredEntry( + self.top.get_widget("alt_surname"), self.name.set_surname, + self.name.get_surname, self.db.readonly, + self.update_group_as) + + self.prefix_field = MonitoredEntry( + self.top.get_widget("alt_prefix"), self.name.set_surname_prefix, + self.name.get_surname_prefix, self.db.readonly) + + self.date = MonitoredDate(self.top.get_widget("date"), + self.top.get_widget("date_stat"), + self.name.get_date_object(),self.window) + + self.name_combo = MonitoredType( + self.top.get_widget("name_type"), self.name.set_type, + self.name.get_type, dict(Utils.name_types), RelLib.Name.CUSTOM) + + self.privacy = PrivacyButton( + self.top.get_widget("priv"), self.name) + + def _create_tabbed_pages(self): self.srcref_list = self._add_page(SourceEmbedList( self.dbstate,self.uistate, self.track, self.name.source_list)) @@ -176,8 +185,6 @@ class NameEditor(DisplayState.ManagedWindow): self.dbstate, self.uistate, self.track, self.name.get_note_object())) - self.show() - def build_menu_names(self,name): if name: ntext = NameDisplay.displayer.display_name(name) @@ -194,30 +201,25 @@ class NameEditor(DisplayState.ManagedWindow): def update_group_as(self,obj): if not self.group_over.get_active(): - if self.name and self.name.get_group_as() != self.name.get_surname(): + if self.name.get_group_as() != self.name.get_surname(): val = self.name.get_group_as() else: - name = unicode(self.surname_field.get_text()) + name = self.name.get_surname() val = self.db.get_name_group_mapping(name) - self.group_as.set_text(val) + self.group_as.force_value(val) def on_group_over_toggled(self,obj): - if obj.get_active(): - self.group_as.set_sensitive(True) - self.group_as.set_editable(True) - else: - field_value = unicode(self.surname_field.get_text()) + self.group_as.enable(obj.get_active()) + + if not obj.get_active(): + field_value = self.name.get_surname() mapping = self.db.get_name_group_mapping(field_value) self.group_as.set_text(mapping) - self.group_as.set_sensitive(False) - self.group_as.set_editable(False) def on_delete_event(self,*obj): - self.gladeif.close() self.close() def close_window(self,*obj): - self.gladeif.close() self.close() self.window.destroy() gc.collect() @@ -227,40 +229,14 @@ class NameEditor(DisplayState.ManagedWindow): GrampsDisplay.help('adv-an') def on_name_edit_ok_clicked(self,obj): - first = unicode(self.given_field.get_text()) - last = unicode(self.surname_field.get_text()) - title = unicode(self.title_field.get_text()) - prefix = unicode(self.prefix_field.get_text()) - suffix = unicode(self.suffix_field.get_text()) - patronymic = unicode(self.patronymic_field.get_text()) - priv = self.priv.get_active() - - the_type = self.type_selector.get_values() - - # FIXME: this remained from gramps20 -- check - # if const.NameTypesMap.has_value(mtype): - # mtype = const.NameTypesMap.find_key(mtype) - # if not mtype: - # mtype = "Also Known As" - - self.name.set_date_object(self.date_obj) - - grp_as = unicode(self.group_as.get_text()) - srn = unicode(self.surname_field.get_text()) - - if self.name.get_display_as() != self.display_as.get_active(): - self.name.set_display_as(self.display_as.get_active()) - - prefix = unicode(self.prefix_field.get_text()) - if self.name.get_surname_prefix() != prefix: - self.name.set_surname_prefix(prefix) - - if self.name.get_sort_as() != self.sort_as.get_active(): - self.name.set_sort_as(self.sort_as.get_active()) if not self.group_over.get_active(): self.name.set_group_as("") - elif self.name.get_group_as() != grp_as: + elif self.name.get_group_as() == self.name.get_surname(): + self.name.set_group_as("") + elif self.name.get_group_as() != self.original_group_as: + grp_as = self.name.get_group_as() + srn = self.name.get_surname() if grp_as not in self.db.get_name_group_keys(): from QuestionDialog import QuestionDialog2 q = QuestionDialog2( @@ -278,31 +254,7 @@ class NameEditor(DisplayState.ManagedWindow): else: self.name.set_group_as(grp_as) - self.update_name(first,last,suffix,patronymic,title,the_type,priv) self.callback(self.name) self.close_window(obj) - def update_name(self,first,last,suffix,patronymic,title, - the_type,priv): - - if self.name.get_first_name() != first: - self.name.set_first_name(first) - - if self.name.get_surname() != last: - self.name.set_surname(last) - - if self.name.get_suffix() != suffix: - self.name.set_suffix(suffix) - - if self.name.get_patronymic() != patronymic: - self.name.set_patronymic(patronymic) - - if self.name.get_title() != title: - self.name.set_title(title) - - if self.name.get_type() != the_type: - self.name.set_type(the_type) - - if self.name.get_privacy() != priv: - self.name.set_privacy(priv) diff --git a/src/gramps.glade b/src/gramps.glade index 66a2e411b..a7f8c0984 100644 --- a/src/gramps.glade +++ b/src/gramps.glade @@ -2,7 +2,6 @@ - True @@ -10753,7 +10752,7 @@ Very High GTK_BUTTONBOX_END - + True True True @@ -10767,7 +10766,7 @@ Very High - + True True True @@ -10782,7 +10781,7 @@ Very High - + True True True @@ -10838,8 +10837,8 @@ Very High 12 True - 3 - 2 + 2 + 3 False 6 12 @@ -10901,28 +10900,6 @@ Very High - - - True - True - _Private record - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 1 - 2 - 2 - 3 - fill - - - - True @@ -10937,13 +10914,44 @@ Very High 1 - 2 + 3 1 2 + + + True + True + GTK_RELIEF_NONE + True + False + False + + + + True + 1 + gtk-dialog-authentication + 0.5 + 0.5 + 0 + 0 + + + + + 2 + 3 + 0 + 1 + + + + + True @@ -10956,7 +10964,6 @@ Very High 2 0 1 - fill fill @@ -11514,7 +11521,7 @@ Very High GTK_BUTTONBOX_END - + True True True @@ -11528,7 +11535,7 @@ Very High - + True Accept changes and close window True @@ -11544,7 +11551,7 @@ Very High - + True True True @@ -11872,55 +11879,6 @@ Very High - - - True - True - _Private record - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 5 - 6 - 4 - 5 - fill - - - - - - - True - True - GTK_RELIEF_NONE - True - - - - True - 0.5 - 0.5 - 0 - 0 - - - - - 6 - 7 - 0 - 1 - fill - fill - - - True @@ -11943,27 +11901,6 @@ Very High - - - True - True - True - True - 0 - - True - * - False - - - 1 - 7 - 1 - 2 - - - - True @@ -12005,6 +11942,85 @@ Very High + + + + True + True + True + True + 0 + + True + * + False + + + 1 + 6 + 1 + 2 + + + + + + + True + True + GTK_RELIEF_NONE + True + False + False + + + + True + 1 + gtk-dialog-authentication + 0.5 + 0.5 + 0 + 0 + + + + + 6 + 7 + 1 + 2 + + + + + + + + True + True + GTK_RELIEF_NONE + True + + + + True + 0.5 + 0.5 + 0 + 0 + + + + + 6 + 7 + 0 + 1 + + fill + + 0 @@ -12353,7 +12369,6 @@ Very High - True GTK_WINDOW_TOPLEVEL GTK_WIN_POS_NONE @@ -12472,7 +12487,7 @@ Very High 12 True 4 - 4 + 5 False 6 12 @@ -12635,49 +12650,6 @@ Very High - - - True - True - True - True - 0 - - True - * - False - - - 3 - 4 - 0 - 1 - - - - - - - True - True - True - True - True - 0 - - True - * - False - - - 1 - 4 - 1 - 2 - - - - True @@ -12757,27 +12729,6 @@ Very High - - - True - True - True - True - 0 - - True - * - False - - - 3 - 4 - 2 - 3 - - - - True @@ -12806,6 +12757,80 @@ Very High + + + True + True + True + True + 0 + + True + * + False + + + 3 + 5 + 0 + 1 + + + + + + + True + True + True + True + True + 0 + + True + * + False + + + 1 + 4 + 1 + 2 + + + + + + + True + True + GTK_RELIEF_NONE + True + False + False + + + + True + 1 + gtk-dialog-authentication + 0.5 + 0.5 + 0 + 0 + + + + + 4 + 5 + 1 + 2 + shrink + + + + True @@ -12815,11 +12840,32 @@ Very High 3 - 4 + 5 3 4 + + + + + + + True + True + True + True + 0 + + True + * + False + + + 3 + 4 + 2 + 3 fill - fill + @@ -12845,34 +12891,12 @@ Very High 12 True - 6 + 5 3 False 6 12 - - - True - True - P_rivate record - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 2 - 3 - 5 - 6 - fill - - - - True @@ -12995,9 +13019,7 @@ Very High True - Default (based on locale) -Given name Family name -Family name Given name + False True @@ -13159,9 +13181,7 @@ Family name Given name True - Default (based on locale) -Family name, Given name -Given name, Family name + False True