diff --git a/ChangeLog b/ChangeLog index 1baf02c78..8b2244c63 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,33 @@ +2006-02-28 Don Allingham + * src/AddrEdit.py: remove already_exist check in favor of exception + * src/AttrEdit.py: remove already_exist check in favor of exception + * src/DisplayState.py: remove already_exist variable + * src/DisplayTabs.py: handle exception + * src/EditEventRef.py: remove already_exist check in favor of exception + * src/EditFamily.py: update to derive from EditPrimary + * src/EditMedia.py: update to derive from EditPrimary + * src/EditMediaRef.py: remove already_exist check in favor of exception + * src/EditPerson.py: update to derive from EditPrimary + * src/EditPlace.py: update to derive from EditPrimary + * src/EditRepository.py:update to derive from EditPrimary + * src/EditSource.py: update to derive from EditPrimary + * src/EditSourceRef.py: remove already_exist check in favor of exception + * src/Errors.py: new exception + * src/EventEdit.py: update to derive from EditPrimary + * src/EventView.py: catch exception of window already exists + * src/FamilyList.py: catch exception of window already exists + * src/FamilyView.py: catch exception of window already exists + * src/GrampsWidgets.py: typos + * src/NameEdit.py: remove already_exist check in favor of exception + * src/PedView.py: catch exception of window already exists + * src/PersonView.py: catch exception of window already exists + * src/PlaceView.py: catch exception of window already exists + * src/Plugins.py: catch exception of window already exists + * src/UrlEdit.py: remove already_exist check in favor of exception + * src/const.py.in: dynamically determine path + * src/gramps.glade: name changes + * src/gramps.py: set path + 2006-02-28 Alex Roitman * src/plugins/WritePkg.py (PackageWriter.export): Add existing image filenames to the archive. diff --git a/src/AddrEdit.py b/src/AddrEdit.py index 705648338..c21bfb5e4 100644 --- a/src/AddrEdit.py +++ b/src/AddrEdit.py @@ -48,11 +48,7 @@ import GrampsDisplay import const import Utils import RelLib -import Sources -import DateEdit -import DateHandler import DisplayState -import Spell from DisplayTabs import * from GrampsWidgets import * @@ -81,8 +77,6 @@ class AddressEditor(DisplayState.ManagedWindow): self.addr = addr DisplayState.ManagedWindow.__init__(self, uistate, track, addr) - if self.already_exist: - return if not self.addr: self.addr = RelLib.Address() diff --git a/src/AttrEdit.py b/src/AttrEdit.py index bd4b603f2..82ce0250f 100644 --- a/src/AttrEdit.py +++ b/src/AttrEdit.py @@ -85,8 +85,6 @@ class AttributeEditor(DisplayState.ManagedWindow): self.alist = data_list DisplayState.ManagedWindow.__init__(self, uistate, track, attrib) - if self.already_exist: - return if not attrib: self.attrib = RelLib.Attribute() diff --git a/src/DateEdit.py b/src/DateEdit.py index e0422ecfa..82a609b34 100644 --- a/src/DateEdit.py +++ b/src/DateEdit.py @@ -100,10 +100,6 @@ class DateEdit: """Class that associates a pixmap with a text widget, providing visual feedback that indicates if the text widget contains a valid date""" - good = gtk.gdk.pixbuf_new_from_file(const.good_xpm) - bad = gtk.gdk.pixbuf_new_from_file(const.bad_xpm) - caution = gtk.gdk.pixbuf_new_from_file(const.caution_xpm) - def __init__(self,date_obj,text_obj,button_obj,parent_window=None): """ Creates a connection between the date_obj, text_obj and the pixmap_obj. diff --git a/src/DisplayState.py b/src/DisplayState.py index 7b0ea5e2c..c3c250071 100644 --- a/src/DisplayState.py +++ b/src/DisplayState.py @@ -45,6 +45,7 @@ import GrampsKeys import NameDisplay import GrampsMime import const +import Errors #------------------------------------------------------------------------- # @@ -453,9 +454,6 @@ class ManagedWindow: window_id, submenu_label, menu_label) - if self.already_exist: - return - # Proceed with the class. ... @@ -466,9 +464,8 @@ class ManagedWindow: if uistate.gwm.get_item_from_id(window_key): uistate.gwm.get_item_from_id(window_key).present() - self.already_exist = True + raise Errors.WindowActiveError('This window is already active') else: - self.already_exist = False self.window_id = window_key self.submenu_label = submenu_label self.menu_label = menu_label diff --git a/src/DisplayTabs.py b/src/DisplayTabs.py index 9178ba82a..a33f536bc 100644 --- a/src/DisplayTabs.py +++ b/src/DisplayTabs.py @@ -54,6 +54,7 @@ import RelLib import Utils import ImgManip import Spell +import Errors from DdTargets import DdTargets from GrampsWidgets import SimpleButton @@ -593,8 +594,11 @@ class EventEmbedList(EmbeddedList): def add_button_clicked(self,obj): from EditEventRef import EditEventRef - EditEventRef(self.dbstate,self.uistate,self.track, - None, None, self.obj, self.event_added) + try: + EditEventRef(self.dbstate,self.uistate,self.track, + None, None, self.obj, self.event_added) + except Errors.WindowActiveError: + pass def share_button_clicked(self,obj): from EditEventRef import EditEventRef @@ -602,16 +606,22 @@ class EventEmbedList(EmbeddedList): sel = SelectEvent.SelectEvent(self.dbstate.db,"Event Select") event = sel.run() - EditEventRef(self.dbstate,self.uistate,self.track, - event, None, self.obj, self.event_added) + try: + EditEventRef(self.dbstate,self.uistate,self.track, + event, None, self.obj, self.event_added) + except Errors.WindowActiveError: + pass def edit_button_clicked(self,obj): ref = self.get_selected() if ref: from EditEventRef import EditEventRef event = self.dbstate.db.get_event_from_handle(ref.ref) - EditEventRef(self.dbstate,self.uistate,self.track, - event, ref, self.obj, self.event_updated) + try: + EditEventRef(self.dbstate,self.uistate,self.track, + event, ref, self.obj, self.event_updated) + except Errors.WindowActiveError: + pass def event_updated(self,value): self.changed = True @@ -814,9 +824,12 @@ class AttrEmbedList(EmbeddedList): import AttrEdit pname = '' attr_list = [] - AttrEdit.AttributeEditor( - self.dbstate, self.uistate, self.track, None, - pname, attr_list, self.add_callback) + try: + AttrEdit.AttributeEditor( + self.dbstate, self.uistate, self.track, None, + pname, attr_list, self.add_callback) + except Errors.WindowActiveError: + pass def add_callback(self,name): self.get_data().append(name) @@ -829,9 +842,12 @@ class AttrEmbedList(EmbeddedList): import AttrEdit pname = '' attr_list = [] - AttrEdit.AttributeEditor( - self.dbstate, self.uistate, self.track, attr, - pname, attr_list, self.edit_callback) + try: + AttrEdit.AttributeEditor( + self.dbstate, self.uistate, self.track, attr, + pname, attr_list, self.edit_callback) + except Errors.WindowActiveError: + pass def edit_callback(self,name): self.changed = True @@ -867,8 +883,11 @@ class WebEmbedList(EmbeddedList): def add_button_clicked(self,obj): import UrlEdit url = RelLib.Url() - UrlEdit.UrlEditor(self.dbstate, self.uistate, self.track, - '', url, self.add_callback) + try: + UrlEdit.UrlEditor(self.dbstate, self.uistate, self.track, + '', url, self.add_callback) + except Errors.WindowActiveError: + pass def add_callback(self,url): self.get_data().append(url) @@ -878,8 +897,11 @@ class WebEmbedList(EmbeddedList): url = self.get_selected() if url: import UrlEdit - UrlEdit.UrlEditor(self.dbstate, self.uistate, self.track, - '', url, self.edit_callback) + try: + UrlEdit.UrlEditor(self.dbstate, self.uistate, self.track, + '', url, self.edit_callback) + except Errors.WindowActiveError: + pass def edit_callback(self,url): self.rebuild() @@ -913,8 +935,11 @@ class NameEmbedList(EmbeddedList): def add_button_clicked(self,obj): import NameEdit name = RelLib.Name() - NameEdit.NameEditor(self.dbstate, self.uistate, self.track, - name, self.add_callback) + try: + NameEdit.NameEditor(self.dbstate, self.uistate, self.track, + name, self.add_callback) + except Errors.WindowActiveError: + pass def add_callback(self,name): self.get_data().append(name) @@ -924,8 +949,11 @@ class NameEmbedList(EmbeddedList): name = self.get_selected() if name: import NameEdit - NameEdit.NameEditor(self.dbstate, self.uistate, self.track, - name, self.edit_callback) + try: + NameEdit.NameEditor(self.dbstate, self.uistate, self.track, + name, self.edit_callback) + except Errors.WindowActiveError: + pass def edit_callback(self,name): self.rebuild() @@ -962,8 +990,11 @@ class AddrEmbedList(EmbeddedList): def add_button_clicked(self,obj): import AddrEdit addr = RelLib.Address() - AddrEdit.AddressEditor(self.dbstate, self.uistate, self.track, - addr, self.add_callback) + try: + AddrEdit.AddressEditor(self.dbstate, self.uistate, self.track, + addr, self.add_callback) + except Errors.WindowActiveError: + pass def add_callback(self,name): self.get_data().append(name) @@ -973,8 +1004,11 @@ class AddrEmbedList(EmbeddedList): addr = self.get_selected() if addr: import AddrEdit - AddrEdit.AddressEditor(self.dbstate, self.uistate, self.track, - addr, self.edit_callback) + try: + AddrEdit.AddressEditor(self.dbstate, self.uistate, self.track, + addr, self.edit_callback) + except Errors.WindowActiveError: + pass def edit_callback(self,name): self.rebuild() @@ -1011,8 +1045,11 @@ class LocationEmbedList(EmbeddedList): def add_button_clicked(self,obj): import LocEdit loc = RelLib.Location() - LocEdit.LocationEditor(self.dbstate, self.uistate, self.track, - loc, self.add_callback) + try: + LocEdit.LocationEditor(self.dbstate, self.uistate, self.track, + loc, self.add_callback) + except Errors.WindowActiveError: + pass def add_callback(self,name): self.get_data().append(name) @@ -1022,8 +1059,11 @@ class LocationEmbedList(EmbeddedList): loc = self.get_selected() if loc: import LocEdit - LocEdit.LocationEditor(self.dbstate, self.uistate, self.track, - loc, self.edit_callback) + try: + LocEdit.LocationEditor(self.dbstate, self.uistate, self.track, + loc, self.edit_callback) + except Errors.WindowActiveError: + pass def edit_callback(self,name): self.rebuild() @@ -1213,8 +1253,11 @@ class GalleryTab(ButtonTab): sref = RelLib.MediaRef() src = RelLib.MediaObject() - EditMediaRef(self.dbstate, self.uistate, self.track, - src, sref, self.add_callback) + try: + EditMediaRef(self.dbstate, self.uistate, self.track, + src, sref, self.add_callback) + except Errors.WindowActiveError: + pass def add_callback(self,name): self.get_data().append(name) @@ -1233,8 +1276,11 @@ class GalleryTab(ButtonTab): from EditMediaRef import EditMediaRef obj = self.dbstate.db.get_object_from_handle(ref.get_reference_handle()) - EditMediaRef(self.dbstate, self.uistate, self.track, - obj, ref, self.edit_callback) + try: + EditMediaRef(self.dbstate, self.uistate, self.track, + obj, ref, self.edit_callback) + except Errors.WindowActiveError: + pass def edit_callback(self, name): self.changed = True @@ -1276,8 +1322,11 @@ class SourceEmbedList(EmbeddedList): sref = RelLib.SourceRef() src = RelLib.Source() - EditSourceRef(self.dbstate, self.uistate, self.track, - src, sref, self.add_callback) + try: + EditSourceRef(self.dbstate, self.uistate, self.track, + src, sref, self.add_callback) + except Errors.WindowActiveError: + pass def add_callback(self,obj): self.get_data().append(obj) @@ -1290,8 +1339,11 @@ class SourceEmbedList(EmbeddedList): sref = self.get_selected() src = self.dbstate.db.get_source_from_handle(sref.ref) if sref: - EditSourceRef(self.dbstate, self.uistate, self.track, - src, sref, self.edit_callback) + try: + EditSourceRef(self.dbstate, self.uistate, self.track, + src, sref, self.edit_callback) + except Errors.WindowActiveError: + pass def edit_callback(self,name): self.changed = True @@ -1333,8 +1385,11 @@ class RepoEmbedList(EmbeddedList): ref = RelLib.RepoRef() repo = RelLib.Repository() - EditRepositoryRef( - self.dbstate, self.uistate, self.track, repo, ref, self.add_callback) + try: + EditRepositoryRef( + self.dbstate, self.uistate, self.track, repo, ref, self.add_callback) + except Errors.WindowActiveError: + pass def add_callback(self,value): value[0].ref = value[1].handle @@ -1348,9 +1403,12 @@ class RepoEmbedList(EmbeddedList): ref = self.get_selected() if ref: repo = self.dbstate.db.get_repository_from_handle(ref.ref) - EditRepositoryRef.EditRepositoryRef( - self.dbstate, self.uistate, self.track, repo, - ref, self.edit_callback) + try: + EditRepositoryRef.EditRepositoryRef( + self.dbstate, self.uistate, self.track, repo, + ref, self.edit_callback) + except Errors.WindowActiveError: + pass def edit_callback(self,name): self.changed = True diff --git a/src/EditEventRef.py b/src/EditEventRef.py index df19609c0..294c90460 100644 --- a/src/EditEventRef.py +++ b/src/EditEventRef.py @@ -50,12 +50,9 @@ import const import Utils import AutoComp import RelLib -from DateHandler import displayer as _dd -import DateEdit import DisplayState from QuestionDialog import WarningDialog, ErrorDialog -from WindowUtils import GladeIf from DisplayTabs import * from GrampsWidgets import * @@ -84,8 +81,6 @@ class EditEventRef(DisplayState.ManagedWindow): self.event = event DisplayState.ManagedWindow.__init__(self, uistate, track, event_ref) - if self.already_exist: - return self.update = update @@ -187,11 +182,12 @@ class EditEventRef(DisplayState.ManagedWindow): dict(total_events), RelLib.Event.CUSTOM) - self.date_check = DateEdit.DateEdit( - self.event.get_date_object(), + self.date_check = MonitoredDate( self.top.get_widget("eer_date"), self.top.get_widget("eer_date_stat"), - self.window) + self.event.get_date_object(), + self.window, + self.db.readonly) def _connect_signals(self): self.top.get_widget('ok').connect('clicked',self.ok_clicked) diff --git a/src/EditFamily.py b/src/EditFamily.py index 389ab7df6..0fd7d6de9 100644 --- a/src/EditFamily.py +++ b/src/EditFamily.py @@ -26,8 +26,6 @@ # #------------------------------------------------------------------------- import cPickle as pickle -import os -import sys from gettext import gettext as _ #------------------------------------------------------------------------- @@ -66,16 +64,14 @@ import gtk.glade import const import Utils import NameDisplay -import DisplayState +import EditPrimary import Spell import GrampsDisplay import RelLib import ReportUtils import AutoComp -import GrampsWidgets from DdTargets import DdTargets -from WindowUtils import GladeIf from DisplayTabs import * from GrampsWidgets import * from ObjectSelector import PersonSelector,PersonFilterSpec @@ -204,40 +200,35 @@ class ChildEmbedList(EmbeddedList): handle = self.get_selected() if handle: import EditPerson - person = self.dbstate.db.get_person_from_handle(handle) - EditPerson.EditPerson(self.dbstate,self.uistate,self.track,person) + try: + person = self.dbstate.db.get_person_from_handle(handle) + EditPerson.EditPerson(self.dbstate,self.uistate,self.track,person) + except Errors.WindowActiveError: + pass #------------------------------------------------------------------------- # # EditFamily # #------------------------------------------------------------------------- -class EditFamily(DisplayState.ManagedWindow): +class EditFamily(EditPrimary.EditPrimary): def __init__(self,dbstate,uistate,track,family): - self.dbstate = dbstate - self.uistate = uistate - self.family = family + EditPrimary.EditPrimary.__init__(self, dbstate, uistate, track, + family, dbstate.db.get_family_from_handle) - DisplayState.ManagedWindow.__init__(self, uistate, track, family) - if self.already_exist: - return - + + def _local_init(self): self.build_interface() - self.load_data() self.mname = None self.fname = None - self.signal_keys = [] - self.signal_keys.append(self.dbstate.db.connect('person-update', - self.check_for_change)) - self.signal_keys.append(self.dbstate.db.connect('person-delete', - self.check_for_change)) - self.signal_keys.append(self.dbstate.db.connect('person-rebuild', - self.reload_people)) + self._add_db_signal('person-update', self.check_for_change) + self._add_db_signal('person-delete', self.check_for_change) + self._add_db_signal('person-rebuild', self.reload_people) - self.show() + self.load_data() def check_for_change(self,handles): for node in handles: @@ -246,27 +237,22 @@ class EditFamily(DisplayState.ManagedWindow): break; def reload_people(self): - fhandle = self.family.get_father_handle() + fhandle = self.obj.get_father_handle() self.update_father(fhandle) - mhandle = self.family.get_mother_handle() + mhandle = self.obj.get_mother_handle() self.update_mother(mhandle) self.child_list.rebuild() def build_menu_names(self,obj): return ('Edit Family','Undefined Submenu') - def build_window_key(self,obj): - if self.family.handle: - return id(self.family.handle) - else: - return id(self) - def build_interface(self): - self.top = gtk.glade.XML(const.gladeFile,"marriageEditor","gramps") - self.gladeif = GladeIf(self.top) - self.window = self.top.get_widget("marriageEditor") + self.top = gtk.glade.XML(const.gladeFile,"family_editor","gramps") + + self.define_top_level(self.top.get_widget("family_editor"), + None,_('Family Editor')) self.fbirth = self.top.get_widget('fbirth') self.fdeath = self.top.get_widget('fdeath') @@ -280,83 +266,79 @@ class EditFamily(DisplayState.ManagedWindow): self.mbox = self.top.get_widget('mbox') self.fbox = self.top.get_widget('fbox') - self.ok = self.top.get_widget('ok') - self.cancel = self.top.get_widget('cancel') - - self.vbox = self.top.get_widget('vbox') self.child_list = self.top.get_widget('child_list') - self.notebook = gtk.Notebook() - self.notebook.show() - self.vbox.pack_start(self.notebook,True) + def _connect_signals(self): + self.define_ok_button(self.top.get_widget('ok'), self.save) + self.define_cancel_button(self.top.get_widget('cancel')) - self._setup_monitored_values() - - self.cancel.connect('clicked', self.close_window) - self.ok.connect('clicked', self.apply_changes) - - def _setup_monitored_values(self): - self.private= GrampsWidgets.PrivacyButton(self.top.get_widget('private'), - self.family) - - self.gid = GrampsWidgets.MonitoredEntry(self.top.get_widget('gid'), - self.family.set_gramps_id, - self.family.get_gramps_id) + def _setup_fields(self): - self.data_type = GrampsWidgets.MonitoredType( - self.top.get_widget('marriage_type'), self.family.set_relationship, - self.family.get_relationship, dict(Utils.family_relations), + self.private= PrivacyButton( + self.top.get_widget('private'), + self.obj, + self.db.readonly) + + self.gid = MonitoredEntry( + self.top.get_widget('gid'), + self.obj.set_gramps_id, + self.obj.get_gramps_id, + self.db.readonly) + + self.data_type = MonitoredType( + self.top.get_widget('marriage_type'), + self.obj.set_relationship, + self.obj.get_relationship, + dict(Utils.family_relations), RelLib.Family.CUSTOM) def load_data(self): - fhandle = self.family.get_father_handle() + fhandle = self.obj.get_father_handle() self.update_father(fhandle) - mhandle = self.family.get_mother_handle() + mhandle = self.obj.get_mother_handle() self.update_mother(mhandle) - self.phandles = [mhandle, fhandle] + self.family.get_child_handle_list() + self.phandles = [mhandle, fhandle] + self.obj.get_child_handle_list() self.phandles = [handle for handle in self.phandles if handle] self.mbutton.connect('clicked',self.mother_clicked) self.fbutton.connect('clicked',self.father_clicked) - self.child_list = ChildEmbedList(self.dbstate,self.uistate, - self.track, self.family) - self.event_list = EventEmbedList(self.dbstate,self.uistate, - self.track,self.family) - self.src_list = SourceEmbedList(self.dbstate,self.uistate, - self.track,self.family.source_list) - self.attr_list = AttrEmbedList(self.dbstate, self.uistate, self.track, - self.family.get_attribute_list()) - self.note_tab = NoteTab(self.dbstate, self.uistate, self.track, - self.family.get_note_object()) - self.gallery_tab = GalleryTab(self.dbstate, self.uistate, self.track, - self.family.get_media_list()) + def _create_tabbed_pages(self): - self.notebook.insert_page(self.child_list) - self.notebook.set_tab_label(self.child_list, - self.child_list.get_tab_widget()) + notebook = gtk.Notebook() - self.notebook.insert_page(self.event_list) - self.notebook.set_tab_label(self.event_list, - self.event_list.get_tab_widget()) + self.child_list = self._add_tab( + notebook, + ChildEmbedList(self.dbstate,self.uistate, self.track, self.obj)) + + self.event_list = self._add_tab( + notebook, + EventEmbedList(self.dbstate,self.uistate, self.track,self.obj)) + + self.src_list = self._add_tab( + notebook, + SourceEmbedList(self.dbstate,self.uistate, + self.track,self.obj.source_list)) + + self.attr_list = self._add_tab( + notebook, + AttrEmbedList(self.dbstate, self.uistate, self.track, + self.obj.get_attribute_list())) + + self.note_tab = self._add_tab( + notebook, + NoteTab(self.dbstate, self.uistate, self.track, + self.obj.get_note_object())) + + self.gallery_tab = self._add_tab( + notebook, + GalleryTab(self.dbstate, self.uistate, self.track, + self.obj.get_media_list())) - self.notebook.insert_page(self.src_list) - self.notebook.set_tab_label(self.src_list, - self.src_list.get_tab_widget()) - - self.notebook.insert_page(self.attr_list) - self.notebook.set_tab_label(self.attr_list, - self.attr_list.get_tab_widget()) - - self.notebook.insert_page(self.note_tab) - self.notebook.set_tab_label(self.note_tab, - self.note_tab.get_tab_widget()) - - self.notebook.insert_page(self.gallery_tab) - self.notebook.set_tab_label(self.gallery_tab, - self.gallery_tab.get_tab_widget()) + notebook.show_all() + self.top.get_widget('vbox').pack_start(notebook,True) def update_father(self,handle): self.load_parent(handle, self.fbox, self.fbirth, @@ -370,7 +352,7 @@ class EditFamily(DisplayState.ManagedWindow): if obj.__class__ == RelLib.Person: try: person = obj - self.family.set_mother_handle(person.get_handle()) + self.obj.set_mother_handle(person.get_handle()) self.update_mother(person.get_handle()) except: log.warn( @@ -388,21 +370,21 @@ class EditFamily(DisplayState.ManagedWindow): def mother_clicked(self,obj): - handle = self.family.get_mother_handle() + handle = self.obj.get_mother_handle() if handle: - self.family.set_mother_handle(None) + self.obj.set_mother_handle(None) self.update_mother(None) else: filter_spec = PersonFilterSpec() filter_spec.set_gender(RelLib.Person.FEMALE) child_birth_years = [] - for person_handle in self.family.get_child_handle_list(): - person = self.dbstate.db.get_person_from_handle(person_handle) + for person_handle in self.obj.get_child_handle_list(): + person = self.db.get_person_from_handle(person_handle) event_ref = person.get_birth_ref() event_handle = event_ref.ref if event_handle: - event = self.dbstate.db.get_event_from_handle(event_handle) + event = self.db.get_event_from_handle(event_handle) child_birth_years.append(event.get_date_object().get_year()) if len(child_birth_years) > 0: @@ -419,7 +401,7 @@ class EditFamily(DisplayState.ManagedWindow): if obj.__class__ == RelLib.Person: try: person = obj - self.family.set_father_handle(person.get_handle()) + self.obj.set_father_handle(person.get_handle()) self.update_father(person.get_handle()) except: log.warn("Failed to update father: \n" @@ -436,21 +418,21 @@ class EditFamily(DisplayState.ManagedWindow): selector_window.close() def father_clicked(self,obj): - handle = self.family.get_father_handle() + handle = self.obj.get_father_handle() if handle: - self.family.set_father_handle(None) + self.obj.set_father_handle(None) self.update_father(None) else: filter_spec = PersonFilterSpec() filter_spec.set_gender(RelLib.Person.MALE) child_birth_years = [] - for person_handle in self.family.get_child_handle_list(): - person = self.dbstate.db.get_person_from_handle(person_handle) + for person_handle in self.obj.get_child_handle_list(): + person = self.db.get_person_from_handle(person_handle) event_ref = person.get_birth_ref() event_handle = event_ref.ref if event_handle: - event = self.dbstate.db.get_event_from_handle(event_handle) + event = self.db.get_event_from_handle(event_handle) child_birth_years.append(event.get_date_object().get_year()) if len(child_birth_years) > 0: @@ -465,9 +447,12 @@ class EditFamily(DisplayState.ManagedWindow): def edit_person(self,obj,event,handle): if event.type == gtk.gdk.BUTTON_PRESS and event.button == 1: import EditPerson - person = self.dbstate.db.get_person_from_handle(handle) - EditPerson.EditPerson(self.dbstate, self.uistate, - self.track, person) + try: + person = self.db.get_person_from_handle(handle) + EditPerson.EditPerson(self.dbstate, self.uistate, + self.track, person) + except Errors.WindowActiveError: + pass def load_parent(self,handle,box,birth_obj,death_obj,btn_obj): @@ -479,7 +464,7 @@ class EditFamily(DisplayState.ManagedWindow): btn_obj.remove(btn_obj.get_children()[0]) if is_used: - db = self.dbstate.db + db = self.db person = db.get_person_from_handle(handle) name = "%s [%s]" % (NameDisplay.displayer.display(person), person.gramps_id) @@ -492,9 +477,9 @@ class EditFamily(DisplayState.ManagedWindow): del_image.set_from_stock(gtk.STOCK_REMOVE,gtk.ICON_SIZE_BUTTON) btn_obj.add(del_image) - box.pack_start(GrampsWidgets.LinkBox( - GrampsWidgets.BasicLabel(name), - GrampsWidgets.IconButton(self.edit_person,person.handle) + box.pack_start(LinkBox( + BasicLabel(name), + IconButton(self.edit_person,person.handle) )) else: name = "" @@ -512,54 +497,49 @@ class EditFamily(DisplayState.ManagedWindow): def fix_parent_handles(self,orig_handle, new_handle, trans): if orig_handle != new_handle: if orig_handle: - person = self.dbstate.db.get_person_from_handle(orig_handle) - person.family_list.remove(self.family.handle) - self.dbstate.db.commit_person(person,trans) + person = self.db.get_person_from_handle(orig_handle) + person.family_list.remove(self.obj.handle) + self.db.commit_person(person,trans) if new_handle: - person = self.dbstate.db.get_person_from_handle(orig_handle) - if self.family.handle not in self.person.family_list: - person.family_list.append(self.family.handle) - self.dbstate.db.commit_person(person,trans) + person = self.db.get_person_from_handle(orig_handle) + if self.obj.handle not in self.obj.family_list: + person.family_list.append(self.obj.handle) + self.db.commit_person(person,trans) - def apply_changes(self,obj): - if self.family.handle: - original = self.dbstate.db.get_family_from_handle(self.family.handle) + def save(self,obj): + if self.obj.handle: + original = self.db.get_family_from_handle(self.obj.handle) else: original = None if not original: - trans = self.dbstate.db.transaction_begin() - self.dbstate.db.add_family(self.family,trans) - self.dbstate.db.transaction_commit(trans,_("Edit Family")) - elif cmp(original.serialize(),self.family.serialize()): + trans = self.db.transaction_begin() + self.db.add_family(self.obj,trans) + self.db.transaction_commit(trans,_("Edit Family")) + elif cmp(original.serialize(),self.obj.serialize()): - trans = self.dbstate.db.transaction_begin() + trans = self.db.transaction_begin() self.fix_parent_handles(original.get_father_handle(), - self.family.get_father_handle(),trans) + self.obj.get_father_handle(),trans) self.fix_parent_handles(original.get_mother_handle(), - self.family.get_mother_handle(),trans) + self.obj.get_mother_handle(),trans) orig_set = set(original.get_child_handle_list()) - new_set = set(self.family.get_child_handle_list()) + new_set = set(self.obj.get_child_handle_list()) # remove the family from children which have been removed for handle in orig_set.difference(new_set): - person = self.dbstate.db.get_person_from_handle(handle) - person.remove_parent_family_handle(self.family.handle) - self.dbstate.db.commit_person(person,trans) + person = self.db.get_person_from_handle(handle) + person.remove_parent_family_handle(self.obj.handle) + self.db.commit_person(person,trans) # add the family from children which have been removed for handle in new_set.difference(orig_set): - person = self.dbstate.db.get_person_from_handle(handle) - #person.remove_parent_family_handle(self.family.handle) - #self.dbstate.db.commit_person(person,trans) + person = self.db.get_person_from_handle(handle) + #person.remove_parent_family_handle(self.obj.handle) + #self.db.commit_person(person,trans) - self.dbstate.db.commit_family(self.family,trans) - self.dbstate.db.transaction_commit(trans,_("Edit Family")) + self.db.commit_family(self.obj,trans) + self.db.transaction_commit(trans,_("Edit Family")) self.close_window() - - def close_window(self,*obj): - for key in self.signal_keys: - self.dbstate.db.disconnect(key) - self.close() diff --git a/src/EditMedia.py b/src/EditMedia.py index 4100edb18..96c68e84e 100644 --- a/src/EditMedia.py +++ b/src/EditMedia.py @@ -46,174 +46,130 @@ import const import Utils import RelLib import GrampsMime -import DateEdit -import DateHandler import ImgManip -import DisplayState -import GrampsDisplay +import EditPrimary +from GrampsWidgets import * from QuestionDialog import ErrorDialog -from DdTargets import DdTargets -from WindowUtils import GladeIf from DisplayTabs import * -_drag_targets = [ - ('STRING', 0, 0), - ('text/plain',0,0), - ('text/uri-list',0,2), - ('application/x-rootwin-drop',0,1)] - #------------------------------------------------------------------------- # # EditMedia # #------------------------------------------------------------------------- -class EditMedia(DisplayState.ManagedWindow): +class EditMedia(EditPrimary.EditPrimary): def __init__(self,state,uistate,track,obj): - self.dp = DateHandler.parser - self.dd = DateHandler.displayer - DisplayState.ManagedWindow.__init__(self, uistate, track, obj) + EditPrimary.EditPrimary.__init__(self, state, uistate, track, obj, + state.db.get_object_from_handle) - if self.already_exist: - return + def _local_init(self): + assert(self.obj) + self.glade = gtk.glade.XML(const.gladeFile, + "change_global","gramps") + self.define_top_level(self.glade.get_widget('change_global'), + self.glade.get_widget('title'), + _('Media Properties Editor')) - self.state = state + def _connect_signals(self): + self.define_cancel_button(self.glade.get_widget('button91')) + self.define_ok_button(self.glade.get_widget('ok'),self.save) + self.define_help_button(self.glade.get_widget('button102'),'adv-media') - self.pdmap = {} - self.obj = obj - self.lists_changed = 0 - self.db = self.state.db - self.idle = None - if obj: - self.date_object = RelLib.Date(self.obj.get_date_object()) - self.alist = self.obj.get_attribute_list()[:] - self.refs = 0 - else: - self.date_object = RelLib.Date() - self.alist = [] - self.refs = 1 + def _setup_fields(self): + self.date_field = MonitoredDate( + self.glade.get_widget('date'), + self.glade.get_widget("date_edit"), + self.obj.get_date_object(), + self.window, + self.db.readonly) - self.refmodel = None # this becomes the model for the references + self.descr_window = MonitoredEntry( + self.glade.get_widget("description"), + self.obj.set_description, + self.obj.get_description, + self.db.readonly) - self.path = self.db.get_save_path() - self.change_dialog = gtk.glade.XML(const.gladeFile, - "change_global","gramps") - self.gladeif = GladeIf(self.change_dialog) + self.gid = MonitoredEntry( + self.glade.get_widget("gid"), + self.obj.set_gramps_id, + self.obj.get_gramps_id, + self.db.readonly) - mode = not self.db.readonly - - title = _('Media Properties Editor') - - self.window = self.change_dialog.get_widget('change_global') - - self.date_entry = self.change_dialog.get_widget('date') - self.date_entry.set_editable(mode) - - if self.obj: - self.date_entry.set_text(self.dd.display(self.date_object)) - - Utils.set_titles(self.window, - self.change_dialog.get_widget('title'),title) - - self.descr_window = self.change_dialog.get_widget("description") - self.descr_window.set_editable(mode) - self.descr_window.set_text(self.obj.get_description()) - - self.date_edit = self.change_dialog.get_widget("date_edit") - self.date_edit.set_sensitive(mode) - - self.date_check = DateEdit.DateEdit( - self.date_object, self.date_entry, - self.date_edit, self.window) - - self.pixmap = self.change_dialog.get_widget("pixmap") + pixmap = self.glade.get_widget("pixmap") mtype = self.obj.get_mime_type() if mtype: pb = ImgManip.get_thumbnail_image(self.obj.get_path(),mtype) - self.pixmap.set_from_pixbuf(pb) + pixmap.set_from_pixbuf(pb) descr = GrampsMime.get_description(mtype) if descr: - self.change_dialog.get_widget("type").set_text(descr) + self.glade.get_widget("type").set_text(descr) else: pb = GrampsMime.find_mime_type_pixbuf('text/plain') - self.pixmap.set_from_pixbuf(pb) - self.change_dialog.get_widget("type").set_text(_('Note')) - - self.change_dialog.get_widget("gid").set_text(self.obj.get_gramps_id()) + pixmap.set_from_pixbuf(pb) + self.glade.get_widget("type").set_text(_('Note')) self.setup_filepath() - self.gladeif.connect('change_global','delete_event', - self.on_delete_event) - self.gladeif.connect('button91','clicked',self.close_window) - self.gladeif.connect('ok','clicked',self.on_ok_clicked) - self.gladeif.connect('button102','clicked',self.on_help_clicked) - - self._create_tabbed_windows() - - self.show() - - def _create_tabbed_windows(self): - self.vbox = self.change_dialog.get_widget('vbox') - self.notebook = gtk.Notebook() - self.notebook.show() - self.vbox.pack_start(self.notebook,True) - - self.attr_list = AttrEmbedList(self.state, self.uistate, self.track, - self.obj.get_attribute_list()) - self.note_tab = NoteTab(self.state, self.uistate, self.track, - self.obj.get_note_object()) - self.src_list = SourceEmbedList(self.state,self.uistate, - self.track,self.obj.source_list) + def _create_tabbed_pages(self): + notebook = gtk.Notebook() if self.obj.get_mime_type(): - self.notebook.insert_page(self.src_list) - self.notebook.insert_page(self.attr_list) - self.notebook.insert_page(self.note_tab) + self.src_list = self._add_tab( + notebook, + SourceEmbedList(self.dbstate,self.uistate, + self.track,self.obj.source_list)) + + self.attr_list = self._add_tab( + notebook, + AttrEmbedList(self.dbstate, self.uistate, self.track, + self.obj.get_attribute_list())) + + self.note_tab = self._add_tab( + notebook, + NoteTab(self.dbstate, self.uistate, self.track, + self.obj.get_note_object())) else: - self.notebook.insert_page(self.note_tab) - self.notebook.insert_page(self.src_list) - self.notebook.insert_page(self.attr_list) + self.note_tab = self._add_tab( + notebook, + NoteTab(self.dbstate, self.uistate, self.track, + self.obj.get_note_object())) - self.notebook.set_tab_label(self.src_list,self.src_list.get_tab_widget()) - self.notebook.set_tab_label(self.note_tab,self.note_tab.get_tab_widget()) - self.notebook.set_tab_label(self.attr_list,self.attr_list.get_tab_widget()) + self.src_list = self._add_tab( + notebook, + SourceEmbedList(self.dbstate,self.uistate, + self.track,self.obj.source_list)) + + self.attr_list = self._add_tab( + notebook, + AttrEmbedList(self.dbstate, self.uistate, self.track, + self.obj.get_attribute_list())) - self.backref_list = self._add_page(MediaBackRefList( - self.state,self.uistate,self.track, - self.db.find_backlink_handles(self.obj.handle))) + self.backref_list = self._add_tab( + notebook, + MediaBackRefList(self.dbstate,self.uistate,self.track, + self.db.find_backlink_handles(self.obj.handle))) - def _add_page(self,page): - self.notebook.insert_page(page) - self.notebook.set_tab_label(page,page.get_tab_widget()) - return page + notebook.show_all() + self.glade.get_widget('vbox').pack_start(notebook,True) def build_menu_names(self,person): win_menu_label = _("Media Properties") return (_('Edit Media Object'),win_menu_label) - def build_window_key(self,person): - if person: - return person.get_handle() - else: - return id(self) - - def on_delete_event(self,obj,b): - self.close() - def select_file(self,obj): - f = gtk.FileChooserDialog(_('Select Media Object'), - action=gtk.FILE_CHOOSER_ACTION_OPEN, - buttons=(gtk.STOCK_CANCEL, - gtk.RESPONSE_CANCEL, - gtk.STOCK_OPEN, - gtk.RESPONSE_OK)) + f = gtk.FileChooserDialog( + _('Select Media Object'), + action=gtk.FILE_CHOOSER_ACTION_OPEN, + buttons=(gtk.STOCK_CANCEL, + gtk.RESPONSE_CANCEL, + gtk.STOCK_OPEN, + gtk.RESPONSE_OK)) text = self.file_path.get_text() - name = os.path.basename(text) path = os.path.dirname(text) f.set_filename(path) @@ -223,48 +179,31 @@ class EditMedia(DisplayState.ManagedWindow): self.file_path.set_text(f.get_filename()) f.destroy() - def close_window(self,obj): - if self.idle != None: - gobject.source_remove(self.idle) - self.close() - def setup_filepath(self): - self.select = self.change_dialog.get_widget('file_select') - self.file_path = self.change_dialog.get_widget("path") + self.select = self.glade.get_widget('file_select') + self.file_path = self.glade.get_widget("path") if self.obj.get_mime_type(): fname = self.obj.get_path() self.file_path.set_text(fname) self.select.connect('clicked', self.select_file) else: - self.change_dialog.get_widget('path_label').hide() + self.glade.get_widget('path_label').hide() self.file_path.hide() self.select.hide() - def on_apply_clicked(self, obj): - desc = unicode(self.descr_window.get_text()) - note = self.obj.get_note() - path = self.change_dialog.get_widget('path').get_text() + def save(self, *obj): + path = self.glade.get_widget('path').get_text() if path != self.obj.get_path(): mime = GrampsMime.get_type(path) self.obj.set_mime_type(mime) self.obj.set_path(path) - if not self.date_object.is_equal(self.obj.get_date_object()): - self.obj.set_date_object(self.date_object) - trans = self.db.transaction_begin() self.db.commit_media_object(self.obj,trans) self.db.transaction_commit(trans,_("Edit Media Object")) - - def on_help_clicked(self, obj): - """Display the relevant portion of GRAMPS manual""" - GrampsDisplay.help('adv-media') - - def on_ok_clicked(self, obj): - self.on_apply_clicked(obj) - self.close(obj) + self.close_window() class DeleteMediaQuery: @@ -319,12 +258,3 @@ class DeleteMediaQuery: self.db.remove_object(self.media_handle,trans) self.db.transaction_commit(trans,_("Remove Media Object")) -def build_dropdown(entry,strings): - store = gtk.ListStore(str) - for value in strings: - node = store.append() - store.set(node,0,value) - completion = gtk.EntryCompletion() - completion.set_text_column(0) - completion.set_model(store) - entry.set_completion(completion) diff --git a/src/EditMediaRef.py b/src/EditMediaRef.py index 1f889824a..58c9debe7 100644 --- a/src/EditMediaRef.py +++ b/src/EditMediaRef.py @@ -25,7 +25,6 @@ # Standard python modules # #------------------------------------------------------------------------- -import urlparse from gettext import gettext as _ #------------------------------------------------------------------------- @@ -44,22 +43,14 @@ import gtk.glade #------------------------------------------------------------------------- import const import Utils -import GrampsKeys -import NameDisplay -import PluginMgr import RelLib -import RelImage -import ListModel import GrampsMime import ImgManip import DisplayState import GrampsDisplay from QuestionDialog import ErrorDialog -from DdTargets import DdTargets from WindowUtils import GladeIf - -import DisplayState from DisplayTabs import * from GrampsWidgets import * @@ -80,10 +71,7 @@ class EditMediaRef(DisplayState.ManagedWindow): self.db = self.state.db DisplayState.ManagedWindow.__init__(self, uistate, track, media_ref) - if self.already_exist: - return - fname = self.media.get_path() self.change_dialog = gtk.glade.XML(const.gladeFile, "change_description","gramps") @@ -135,7 +123,7 @@ class EditMediaRef(DisplayState.ManagedWindow): self.gladeif = GladeIf(self.change_dialog) self.window.connect('delete_event',self.on_delete_event) - self.gladeif.connect('button84','clicked',self.close) + self.gladeif.connect('button84','clicked',self.close_window) self.gladeif.connect('button82','clicked',self.on_ok_clicked) self.gladeif.connect('button104','clicked',self.on_help_clicked) @@ -192,10 +180,12 @@ class EditMediaRef(DisplayState.ManagedWindow): def on_delete_event(self,obj,b): self.gladeif.close() + self.close() - def close(self,obj): + def close_window(self,obj): self.gladeif.close() self.window.destroy() + self.close() def on_apply_clicked(self): @@ -226,4 +216,4 @@ class EditMediaRef(DisplayState.ManagedWindow): def on_ok_clicked(self,obj): self.on_apply_clicked() - self.close(obj) + self.close() diff --git a/src/EditPerson.py b/src/EditPerson.py index e960726ea..2b38fc8e6 100644 --- a/src/EditPerson.py +++ b/src/EditPerson.py @@ -37,7 +37,6 @@ from cgi import escape #------------------------------------------------------------------------- import gtk import gtk.glade -import gobject import gtk.gdk #------------------------------------------------------------------------- @@ -49,7 +48,6 @@ import const import Utils import GrampsKeys import GrampsMime -import AutoComp import RelLib import DateHandler import NameDisplay @@ -57,218 +55,201 @@ import NameEdit import DisplayState import GrampsDisplay import GrampsWidgets +import EditPrimary from DisplayTabs import * -from WindowUtils import GladeIf -from QuestionDialog import WarningDialog, ErrorDialog, SaveDialog, QuestionDialog2 +from QuestionDialog import WarningDialog, ErrorDialog, QuestionDialog2 from DdTargets import DdTargets +try: + set() +except: + from sets import Set as set + #------------------------------------------------------------------------- # # Constants # #------------------------------------------------------------------------- -_temple_names = const.lds_temple_codes.keys() -_temple_names.sort() -_temple_names = [""] + _temple_names _select_gender = ((True,False,False),(False,True,False),(False,False,True)) -_use_patronymic = [ - "ru","RU","ru_RU","koi8r","ru_koi8r","russian","Russian", - ] +_use_patronymic = set(["ru","RU","ru_RU","koi8r","ru_koi8r","russian","Russian"]) #------------------------------------------------------------------------- # # EditPerson class # #------------------------------------------------------------------------- -class EditPerson(DisplayState.ManagedWindow): +class EditPerson(EditPrimary.EditPrimary): use_patronymic = locale.getlocale(locale.LC_TIME)[0] in _use_patronymic def __init__(self,state,uistate,track,person,callback=None): """Creates an edit window. Associates a person with the window.""" - self.dp = DateHandler.parser - self.dd = DateHandler.displayer - self.nd = NameDisplay.displayer + EditPrimary.EditPrimary.__init__(self, state, uistate, track, + person, state.db.get_person_from_handle, + callback) - self.person = person - self.orig_handle = self.person.get_handle() - if self.orig_handle: - self.person = state.db.get_person_from_handle(self.orig_handle) - - DisplayState.ManagedWindow.__init__(self, uistate, track, self.person) - - if self.already_exist: - return - - self.dbstate = state - self.uistate = uistate - self.retval = const.UPDATE_PERSON - - self.orig_surname = self.person.get_primary_name().get_group_name() - self.db = self.dbstate.db - self.callback = callback - self.pdmap = {} - self.add_places = [] - self.should_guess_gender = (not person.get_gramps_id() and - person.get_gender () == + def _local_init(self): + self.pname = self.obj.get_primary_name() + self.should_guess_gender = (not self.obj.get_gramps_id() and + self.obj.get_gender () == RelLib.Person.UNKNOWN) - for key in self.db.get_place_handles(): - p = self.db.get_place_from_handle(key).get_display_info() - self.pdmap[p[0]] = key - - mod = not self.db.readonly - self.load_obj = None self.top = gtk.glade.XML(const.editPersonFile, "edit_person","gramps") - self.window = self.top.get_widget("edit_person") - self.gladeif = GladeIf(self.top) - self.window.set_title("%s - GRAMPS" % _('Edit Person')) + self.define_top_level(self.top.get_widget("edit_person"), None, + _('Edit Person')) - self.marker = self.top.get_widget('marker') - self.marker.set_sensitive(mod) - if person: - try: - defval = person.get_marker()[0] - except: - defval = (RelLib.PrimaryObject.MARKER_NONE,"") - else: - defval = None - self.marker_type_selector = AutoComp.StandardCustomSelector( - Utils.marker_types, self.marker, - RelLib.PrimaryObject.MARKER_CUSTOM, defval) - - self.gender = self.top.get_widget('gender') - self.gender.set_sensitive(mod) - self.private = GrampsWidgets.PrivacyButton(self.top.get_widget('private'), - self.person) - - self.ntype_field = self.top.get_widget("ntype") - self.ntype_field.set_sensitive(mod) - - self.vbox = self.top.get_widget('vbox') - self.suffix = self.top.get_widget("suffix") - self.suffix.set_editable(mod) - self.prefix = self.top.get_widget("prefix") - self.prefix.set_editable(mod) - self.given = self.top.get_widget("given_name") - self.given.set_editable(mod) - self.title = self.top.get_widget("title") - self.title.set_editable(mod) - self.surname = self.top.get_widget("surname") - self.surname.set_editable(mod) - self.gid = self.top.get_widget("gid") - self.gid.set_editable(mod) - - self.person_photo = self.top.get_widget("personPix") + self.obj_photo = self.top.get_widget("personPix") self.eventbox = self.top.get_widget("eventbox1") - self.prefix_label = self.top.get_widget('prefix_label') - if self.use_patronymic: - self.prefix_label.set_text(_('Patronymic:')) - self.prefix_label.set_use_underline(True) - - self.birth_ref = person.get_birth_ref() - self.death_ref = person.get_death_ref() - - self.pname = RelLib.Name(self.person.get_primary_name()) - - self.gender.set_active(self.person.get_gender()) - - self.place_list = self.pdmap.keys() - self.place_list.sort() - - build_dropdown(self.surname,self.db.get_surname_list()) - - gid = self.person.get_gramps_id() - if gid: - self.gid.set_text(gid) - self.gid.set_editable(True) - -# self.lds_baptism = RelLib.LdsOrd(self.person.get_lds_baptism()) -# self.lds_endowment = RelLib.LdsOrd(self.person.get_lds_endowment()) -# self.lds_sealing = RelLib.LdsOrd(self.person.get_lds_sealing()) - -# if GrampsKeys.get_uselds() \ -# or (not self.lds_baptism.is_empty()) \ -# or (not self.lds_endowment.is_empty()) \ -# or (not self.lds_sealing.is_empty()): -# self.top.get_widget("lds_tab").show() -# self.top.get_widget("lds_page").show() -# if (not self.lds_baptism.is_empty()) \ -# or (not self.lds_endowment.is_empty()) \ -# or (not self.lds_sealing.is_empty()): -# Utils.bold_label(self.lds_tab) -# else: -# self.top.get_widget("lds_tab").hide() -# self.top.get_widget("lds_page").hide() - - self.ntype_selector = \ - AutoComp.StandardCustomSelector(Utils.name_types, - self.ntype_field, - RelLib.Name.CUSTOM, - RelLib.Name.BIRTH) - self.write_primary_name() + def _post_init(self): self.load_person_image() - - self.gladeif.connect("edit_person", "delete_event", self.on_delete_event) - self.gladeif.connect("button15", "clicked", self.on_cancel_edit) - self.gladeif.connect("ok", "clicked", self.on_apply_person_clicked) - self.gladeif.connect("button134", "clicked", self.on_help_clicked) - self.gladeif.connect("given_name", "focus_out_event", - self.on_given_focus_out_event) - self.gladeif.connect("button177", "clicked", self.on_edit_name_clicked) + self.surname_field.grab_focus() + + def _connect_signals(self): + self.define_cancel_button(self.top.get_widget("button15")) + self.define_ok_button(self.top.get_widget("ok"), self.save) + self.define_help_button(self.top.get_widget("button134"),'adv-pers') + + self.top.get_widget("given_name").connect("focus_out_event", + self.given_focus_out_event) + self.top.get_widget("button177").connect("clicked", self.edit_name_clicked) self.eventbox.connect('button-press-event',self.image_button_press) - self._create_tabbed_pages() - - self.surname.grab_focus() - self.show() + def _setup_fields(self): - def _add_page(self,page): - self.notebook.insert_page(page) - self.notebook.set_tab_label(page,page.get_tab_widget()) - return page + self.private = GrampsWidgets.PrivacyButton( + self.top.get_widget('private'), + self.obj) + + self.gender = GrampsWidgets.MonitoredMenu( + self.top.get_widget('gender'), + self.obj.set_gender, + self.obj.get_gender, + ( + (_('female'),RelLib.Person.FEMALE), + (_('male'),RelLib.Person.MALE), + (_('unknown'),RelLib.Person.UNKNOWN) + ), + self.db.readonly) + + self.ntype_field = GrampsWidgets.MonitoredType( + self.top.get_widget("ntype"), + self.pname.set_type, + self.pname.get_type, + dict(Utils.name_types), + RelLib.Name.CUSTOM, + self.db.readonly) + + self.marker = GrampsWidgets.MonitoredType( + self.top.get_widget('marker'), + self.obj.set_marker, + self.obj.get_marker, + dict(Utils.marker_types), + RelLib.PrimaryObject.MARKER_CUSTOM, + self.db.readonly) + if self.use_patronymic: + self.prefix = GrampsWidgets.MonitoredEntry( + self.top.get_widget("prefix"), + self.pname.set_patronymic, + self.pname.get_patronymic, + self.db.readonly) + + prefix_label = self.top.get_widget('prefix_label') + prefix_label.set_text(_('Patronymic:')) + prefix_label.set_use_underline(True) + else: + self.prefix = GrampsWidgets.MonitoredEntry( + self.top.get_widget("prefix"), + self.pname.set_surname_prefix, + self.pname.get_surname_prefix, + self.db.readonly) + + self.suffix = GrampsWidgets.MonitoredEntry( + self.top.get_widget("suffix"), + self.pname.set_suffix, + self.pname.get_suffix, + self.db.readonly) + + self.given = GrampsWidgets.MonitoredEntry( + self.top.get_widget("given_name"), + self.pname.set_first_name, + self.pname.get_first_name, + self.db.readonly) + + self.title = GrampsWidgets.MonitoredEntry( + self.top.get_widget("title"), + self.pname.set_title, + self.pname.get_title, + self.db.readonly) + + self.surname_field = GrampsWidgets.MonitoredEntry( + self.top.get_widget("surname"), + self.pname.set_surname, + self.pname.get_surname, + self.db.readonly) + + self.gid = GrampsWidgets.MonitoredEntry( + self.top.get_widget("gid"), + self.obj.set_gramps_id, + self.obj.get_gramps_id, + self.db.readonly) + def _create_tabbed_pages(self): """ Creates the notebook tabs and inserts them into the main window. """ - self.notebook = gtk.Notebook() + notebook = gtk.Notebook() - self.event_list = self._add_page(PersonEventEmbedList( - self.dbstate,self.uistate, self.track,self.person)) + self.event_list = self._add_tab( + notebook, + PersonEventEmbedList(self.dbstate,self.uistate, + self.track,self.obj)) - self.name_list = self._add_page(NameEmbedList( - self.dbstate, self.uistate, self.track, - self.person.get_alternate_names())) - self.srcref_list = self._add_page(SourceEmbedList( - self.dbstate,self.uistate, self.track, - self.person.source_list)) - self.attr_list = self._add_page(AttrEmbedList( - self.dbstate,self.uistate,self.track, - self.person.get_attribute_list())) - self.addr_list = self._add_page(AddrEmbedList( - self.dbstate,self.uistate,self.track, - self.person.get_address_list())) - self.note_tab = self._add_page(NoteTab( - self.dbstate, self.uistate, self.track, - self.person.get_note_object())) - self.gallery_tab = self._add_page(GalleryTab( - self.dbstate, self.uistate, self.track, - self.person.get_media_list())) - self.web_list = self._add_page(WebEmbedList( - self.dbstate,self.uistate,self.track, - self.person.get_url_list())) + self.name_list = self._add_tab( + notebook, + NameEmbedList(self.dbstate, self.uistate, self.track, + self.obj.get_alternate_names())) + + self.srcref_list = self._add_tab( + notebook, + SourceEmbedList(self.dbstate,self.uistate, + self.track, self.obj.source_list)) + + self.attr_list = self._add_tab( + notebook, + AttrEmbedList(self.dbstate,self.uistate, self.track, + self.obj.get_attribute_list())) + + self.addr_list = self._add_tab( + notebook, + AddrEmbedList(self.dbstate,self.uistate,self.track, + self.obj.get_address_list())) + + self.note_tab = self._add_tab( + notebook, + NoteTab(self.dbstate, self.uistate, self.track, + self.obj.get_note_object())) + + self.gallery_tab = self._add_tab( + notebook, + GalleryTab(self.dbstate, self.uistate, self.track, + self.obj.get_media_list())) + + self.web_list = self._add_tab( + notebook, + WebEmbedList(self.dbstate,self.uistate,self.track, + self.obj.get_url_list())) - self.notebook.show_all() - self.vbox.pack_start(self.notebook,True) + notebook.show_all() + self.top.get_widget('vbox').pack_start(notebook,True) def build_menu_names(self,person): win_menu_label = self.nd.display(person) @@ -276,31 +257,15 @@ class EditPerson(DisplayState.ManagedWindow): win_menu_label = _("New Person") return (_('Edit Person'),win_menu_label) - def build_window_key(self,person): - if person: - return person.get_handle() - else: - return id(self) - - def set_list_dnd(self,obj, get, begin, receive): - obj.drag_dest_set(gtk.DEST_DEFAULT_ALL, [DdTargets.NAME.target()], - gtk.gdk.ACTION_COPY) - obj.drag_source_set(gtk.gdk.BUTTON1_MASK,[DdTargets.NAME.target()], - gtk.gdk.ACTION_COPY) - obj.connect('drag_data_get', get) - obj.connect('drag_begin', begin) - if not self.db.readonly: - obj.connect('drag_data_received', receive) - - def build_pdmap(self): - self.pdmap.clear() - cursor = self.db.get_place_cursor() - data = cursor.next() - while data: - if data[1][2]: - self.pdmap[data[1][2]] = data[0] - data = cursor.next() - cursor.close() +# def set_list_dnd(self,obj, get, begin, receive): +# obj.drag_dest_set(gtk.DEST_DEFAULT_ALL, [DdTargets.NAME.target()], +# gtk.gdk.ACTION_COPY) +# obj.drag_source_set(gtk.gdk.BUTTON1_MASK,[DdTargets.NAME.target()], +# gtk.gdk.ACTION_COPY) +# obj.connect('drag_data_get', get) +# obj.connect('drag_begin', begin) +# if not self.db.readonly: +# obj.connect('drag_data_received', receive) def image_callback(self,ref): obj = self.db.get_object_from_handle(ref.get_reference_handle()) @@ -309,7 +274,7 @@ class EditPerson(DisplayState.ManagedWindow): def image_button_press(self,obj,event): if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1: - media_list = self.person.get_media_list() + media_list = self.obj.get_media_list() if media_list: from EditMediaRef import EditMediaRef @@ -320,7 +285,7 @@ class EditPerson(DisplayState.ManagedWindow): EditMediaRef(self.dbstate, self.uistate, self.track, media_obj, media_ref, self.image_callback) elif event.type == gtk.gdk.BUTTON_PRESS and event.button == 3: - media_list = self.person.get_media_list() + media_list = self.obj.get_media_list() if media_list: ph = media_list[0] self.show_popup(ph,event) @@ -347,7 +312,7 @@ class EditPerson(DisplayState.ManagedWindow): def popup_view_photo(self, obj): """Open this picture in a picture viewer""" - media_list = self.person.get_media_list() + media_list = self.obj.get_media_list() if media_list: ph = media_list[0] object_handle = ph.get_reference_handle() @@ -355,7 +320,7 @@ class EditPerson(DisplayState.ManagedWindow): def popup_edit_photo(self, obj): """Open this picture in a picture editor""" - media_list = self.person.get_media_list() + media_list = self.obj.get_media_list() if media_list: ph = media_list[0] object_handle = ph.get_reference_handle() @@ -364,7 +329,7 @@ class EditPerson(DisplayState.ManagedWindow): os.execvp(const.editor,[const.editor, obj.get_path()]) def popup_change_description(self,obj): - media_list = self.person.get_media_list() + media_list = self.obj.get_media_list() if media_list: from EditMediaRef import EditMediaRef @@ -375,167 +340,17 @@ class EditPerson(DisplayState.ManagedWindow): media_obj, media_ref, self.image_callback) - def on_help_clicked(self,obj): - """Display the relevant portion of GRAMPS manual""" - GrampsDisplay.help('adv-pers') - - def on_gender_activate (self, button): - self.should_guess_gender = False - - def on_given_focus_out_event (self, entry, event): + def given_focus_out_event (self, entry, event): if not self.should_guess_gender: return - gender = self.db.genderStats.guess_gender(unicode(entry.get_text ())) - self.gender.set_active( gender) - - def build_menu(self,list,task,opt_menu,type): - cell = gtk.CellRendererText() - opt_menu.pack_start(cell,True) - opt_menu.add_attribute(cell,'text',0) - - store = gtk.ListStore(str) - for val in list: - store.append(row=[val]) - opt_menu.set_model(store) - opt_menu.connect('changed',task) - opt_menu.set_active(type) - - def on_cancel_edit(self,obj): - """If the data has changed, give the user a chance to cancel - the close window""" - - if not self.db.readonly and self.did_data_change() and not GrampsKeys.get_dont_ask(): - n = "%s" % escape(self.nd.display(self.person)) - SaveDialog(_('Save changes to %s?') % n, - _('If you close without saving, the changes you ' - 'have made will be lost'), - self.cancel_callback, - self.save) - else: - self.close() - - def save(self): - self.on_apply_person_clicked(None) - - def on_delete_event(self,obj,b): - """If the data has changed, give the user a chance to cancel - the close window""" - if not self.db.readonly and self.did_data_change() and not GrampsKeys.get_dont_ask(): - n = "%s" % escape(self.nd.display(self.person)) - SaveDialog(_('Save Changes to %s?') % n, - _('If you close without saving, the changes you ' - 'have made will be lost'), - self.cancel_callback, - self.save) - return True - else: - self.close() - return False - - def cancel_callback(self): - """If the user answered yes to abandoning changes, close the window""" - self.close() - - def did_data_change(self): - """Check to see if any of the data has changed from the - orig record""" - - return False - surname = unicode(self.surname.get_text()) - - ntype = self.ntype_selector.get_values() - suffix = unicode(self.suffix.get_text()) - prefix = unicode(self.prefix.get_text()) - given = unicode(self.given.get_text()) - title = unicode(self.title.get_text()) - - idval = unicode(self.gid.get_text()) - if idval == "": - idval = None - - changed = False - name = self.person.get_primary_name() - - if self.private.get_active() != self.person.get_privacy(): - changed = True - - if self.person.get_gramps_id() != idval: - changed = True - if suffix != name.get_suffix(): - changed = True - if self.use_patronymic: - if prefix != name.get_patronymic(): - changed = True - elif prefix != name.get_surname_prefix(): - changed = True - if surname.upper() != name.get_surname().upper(): - changed = True - if ntype != name.get_type(): - changed = True - if given != name.get_first_name(): - changed = True - if title != name.get_title(): - changed = True - if self.pname.get_note() != name.get_note(): - changed = True -# if self.check_lds(): -# changed = True - - (female,male,unknown) = _select_gender[self.gender.get_active()] - - if male and self.person.get_gender() != RelLib.Person.MALE: - changed = True - elif female and self.person.get_gender() != RelLib.Person.FEMALE: - changed = True - elif unknown and self.person.get_gender() != RelLib.Person.UNKNOWN: - changed = True - -# if not self.lds_baptism.are_equal(self.person.get_lds_baptism()): -# changed= True - -# if not self.lds_endowment.are_equal(self.person.get_lds_endowment()): -# changed = True - -# if not self.lds_sealing.are_equal(self.person.get_lds_sealing()): -# changed = True - - return changed - -# def check_lds(self): -# date_str = unicode(self.ldsbap_date.get_text()) -# DateHandler.set_date(self.lds_baptism,date_str) -# temple = _temple_names[self.ldsbap_temple.get_active()] -# if const.lds_temple_codes.has_key(temple): -# self.lds_baptism.set_temple(const.lds_temple_codes[temple]) -# else: -# self.lds_baptism.set_temple("") -# self.lds_baptism.set_place_handle(self.get_place(self.ldsbapplace,1)) - -# date_str = unicode(self.ldsend_date.get_text()) -# DateHandler.set_date(self.lds_endowment,date_str) -# temple = _temple_names[self.ldsend_temple.get_active()] -# if const.lds_temple_codes.has_key(temple): -# self.lds_endowment.set_temple(const.lds_temple_codes[temple]) -# else: -# self.lds_endowment.set_temple("") -# self.lds_endowment.set_place_handle(self.get_place(self.ldsendowplace,1)) - -# date_str = unicode(self.ldsseal_date.get_text()) -# DateHandler.set_date(self.lds_sealing,date_str) -# temple = _temple_names[self.ldsseal_temple.get_active()] -# if const.lds_temple_codes.has_key(temple): -# self.lds_sealing.set_temple(const.lds_temple_codes[temple]) -# else: -# self.lds_sealing.set_temple("") -# self.lds_sealing.set_family_handle(self.ldsfam) -# self.lds_sealing.set_place_handle(self.get_place(self.ldssealplace,1)) + self.gender.force(self.db.genderStats.guess_gender(self.given.get_value())) def load_photo(self,photo): """loads, scales, and displays the person's main photo""" self.load_obj = photo if photo == None: - self.person_photo.hide() + self.obj_photo.hide() else: try: i = gtk.gdk.pixbuf_new_from_file(photo) @@ -544,13 +359,13 @@ class EditPerson(DisplayState.ManagedWindow): x = int(scale*(i.get_width())) y = int(scale*(i.get_height())) i = i.scale_simple(x,y,gtk.gdk.INTERP_BILINEAR) - self.person_photo.set_from_pixbuf(i) - self.person_photo.show() + self.obj_photo.set_from_pixbuf(i) + self.obj_photo.show() except: - self.person_photo.hide() + self.obj_photo.hide() def _check_for_unknown_gender(self): - if self.gender.get_active() == RelLib.Person.UNKNOWN: + if self.obj.get_gender() == RelLib.Person.UNKNOWN: dialog = QuestionDialog2( _("Unknown gender specified"), _("The gender of the person is currently unknown. " @@ -564,12 +379,12 @@ class EditPerson(DisplayState.ManagedWindow): return False def _check_and_update_id(self): - idval = unicode(self.gid.get_text()) - if idval != self.person.get_gramps_id(): + original = self.db.get_person_from_handle(self.obj.get_handle()) + + if original.get_gramps_id() != self.obj.get_gramps_id(): + idval = self.obj.get_gramps_id() person = self.db.get_person_from_gramps_id(idval) - if not person: - self.person.set_gramps_id(idval) - else: + if person: n = self.nd.display(person) msg1 = _("GRAMPS ID value was not changed.") msg2 = _("You have attempted to change the GRAMPS ID to a value " @@ -578,92 +393,56 @@ class EditPerson(DisplayState.ManagedWindow): 'person' : n } WarningDialog(msg1,msg2) - def _update_primary_name(self): - surname = unicode(self.surname.get_text()) - suffix = unicode(self.suffix.get_text()) - prefix = unicode(self.prefix.get_text()) - ntype = self.ntype_selector.get_values() - given = unicode(self.given.get_text()) - title = unicode(self.title.get_text()) - - name = self.pname - - if suffix != name.get_suffix(): - name.set_suffix(suffix) - - if self.use_patronymic: - if prefix != name.get_patronymic(): - name.set_patronymic(prefix) - else: - if prefix != name.get_surname_prefix(): - name.set_surname_prefix(prefix) - - if surname != name.get_surname(): - name.set_surname(surname) - - if given != name.get_first_name(): - name.set_first_name(given) - - if title != name.get_title(): - name.set_title(title) - - name.set_source_reference_list(self.pname.get_source_references()) - - if name != self.person.get_primary_name(): - self.person.set_primary_name(name) - - def _update_family_ids(self, trans): # Update each of the families child lists to reflect any # change in ordering due to the new birth date - family = self.person.get_main_parents_family_handle() + family = self.obj.get_main_parents_family_handle() if (family): f = self.db.find_family_from_handle(family,trans) - new_order = self.reorder_child_list(self.person,f.get_child_handle_list()) + new_order = self.reorder_child_list(self.obj,f.get_child_handle_list()) f.set_child_handle_list(new_order) - for (family, rel1, rel2) in self.person.get_parent_family_handle_list(): + for (family, rel1, rel2) in self.obj.get_parent_family_handle_list(): f = self.db.find_family_from_handle(family,trans) - new_order = self.reorder_child_list(self.person,f.get_child_handle_list()) + new_order = self.reorder_child_list(self.obj,f.get_child_handle_list()) f.set_child_handle_list(new_order) error = False - (female,male,unknown) = _select_gender[self.gender.get_active()] - if male and self.person.get_gender() != RelLib.Person.MALE: - self.person.set_gender(RelLib.Person.MALE) - for temp_family_handle in self.person.get_family_handle_list(): + original = self.db.get_person_from_handle(self.obj.handle) + + (female,male,unknown) = _select_gender[self.obj.get_gender()] + if male and original.get_gender() != RelLib.Person.MALE: + for temp_family_handle in self.obj.get_family_handle_list(): temp_family = self.db.get_family_from_handle(temp_family_handle) - if self.person == temp_family.get_mother_handle(): + if self.obj == temp_family.get_mother_handle(): if temp_family.get_father_handle() != None: error = True else: temp_family.set_mother_handle(None) - temp_family.set_father_handle(self.person) - elif female and self.person.get_gender() != RelLib.Person.FEMALE: - self.person.set_gender(RelLib.Person.FEMALE) - for temp_family_handle in self.person.get_family_handle_list(): + temp_family.set_father_handle(self.obj) + elif female and original != RelLib.Person.FEMALE: + for temp_family_handle in self.obj.get_family_handle_list(): temp_family = self.db.get_family_from_handle(temp_family_handle) - if self.person == temp_family.get_father_handle(): + if self.obj == temp_family.get_father_handle(): if temp_family.get_mother_handle() != None: error = True else: temp_family.set_father_handle(None) - temp_family.set_mother_handle(self.person) - elif unknown and self.person.get_gender() != RelLib.Person.UNKNOWN: - self.person.set_gender(RelLib.Person.UNKNOWN) - for temp_family_handle in self.person.get_family_handle_list(): + temp_family.set_mother_handle(self.obj) + elif unknown and original.get_gender() != RelLib.Person.UNKNOWN: + for temp_family_handle in self.obj.get_family_handle_list(): temp_family = self.db.get_family_from_handle(temp_family_handle) - if self.person == temp_family.get_father_handle(): + if self.obj == temp_family.get_father_handle(): if temp_family.get_mother_handle() != None: error = True else: temp_family.set_father_handle(None) - temp_family.set_mother_handle(self.person) - if self.person == temp_family.get_mother_handle(): + temp_family.set_mother_handle(self.obj) + if self.obj == temp_family.get_mother_handle(): if temp_family.get_father_handle() != None: error = True else: temp_family.set_mother_handle(None) - temp_family.set_father_handle(self.person) + temp_family.set_father_handle(self.obj) if error: msg2 = _("Problem changing the gender") @@ -671,104 +450,47 @@ class EditPerson(DisplayState.ManagedWindow): "with marriage information.\nPlease check " "the person's marriages.") ErrorDialog(msg) - - def on_apply_person_clicked(self,obj): + def save(self,*obj): """ Save the data. """ - if self._check_for_unknown_gender(): return - (br, dr, el) = self.event_list.return_info() - self.person.set_birth_ref(br) - self.person.set_death_ref(dr) - self.person.set_event_ref_list(el) + self.obj.set_birth_ref(br) + self.obj.set_death_ref(dr) + self.obj.set_event_ref_list(el) self.window.hide() trans = self.db.transaction_begin() self._check_and_update_id() - self._update_primary_name() - - self.build_pdmap() - self._update_family_ids(trans) - self.person.set_marker(self.marker_type_selector.get_values()) - self.person.set_privacy(self.private.get_active()) - -# if not self.lds_not_loaded: -# self.check_lds() -# lds_ord = RelLib.LdsOrd(self.person.get_lds_baptism()) -# if not self.lds_baptism.are_equal(lds_ord): -# self.person.set_lds_baptism(self.lds_baptism) - -# lds_ord = RelLib.LdsOrd(self.person.get_lds_endowment()) -# if not self.lds_endowment.are_equal(lds_ord): -# self.person.set_lds_endowment(self.lds_endowment) - -# lds_ord = RelLib.LdsOrd(self.person.get_lds_sealing()) -# if not self.lds_sealing.are_equal(lds_ord): -# self.person.set_lds_sealing(self.lds_sealing) - -# self.person.set_source_reference_list(self.srcreflist) - - if not self.person.get_handle(): - self.db.add_person(self.person, trans) + if not self.obj.get_handle(): + self.db.add_person(self.obj, trans) else: - if not self.person.get_gramps_id(): - self.person.set_gramps_id(self.db.find_next_person_gramps_id()) - self.db.commit_person(self.person, trans) + if not self.obj.get_gramps_id(): + self.obj.set_gramps_id(self.db.find_next_person_gramps_id()) + self.db.commit_person(self.obj, trans) - n = self.nd.display(self.person) - - self.db.transaction_commit(trans,_("Edit Person (%s)") % n) + self.db.transaction_commit(trans,_("Edit Person (%s)") % self.nd.display(self.obj)) self.close() - def get_place(self,field,makenew=0): - text = unicode(field.get_text().strip()) - if text: - if self.pdmap.has_key(text): - return self.pdmap[text] - elif makenew: - place = RelLib.Place() - place.set_title(text) - trans = self.db.transaction_begin() - self.db.add_place(place,trans) - self.retval |= const.UPDATE_PLACE - self.db.transaction_commit(trans,_('Add Place (%s)' % text)) - self.pdmap[text] = place.get_handle() - self.add_places.append(place) - return place.get_handle() - else: - return u"" - else: - return u"" - - def on_edit_name_clicked(self,obj): - ntype = self.ntype_selector.get_values() - self.pname.set_type(ntype) - self.pname.set_suffix(unicode(self.suffix.get_text())) - self.pname.set_surname(unicode(self.surname.get_text())) - if self.use_patronymic: - self.pname.set_patronymic(unicode(self.prefix.get_text())) - else: - self.pname.set_surname_prefix(unicode(self.prefix.get_text())) - self.pname.set_first_name(unicode(self.given.get_text())) - self.pname.set_title(unicode(self.title.get_text())) - + def edit_name_clicked(self,obj): NameEdit.NameEditor(self.dbstate, self.uistate, self.track, - self.pname, self) + self.pname, self.update_name) def update_name(self,name): - self.write_primary_name() + for obj in (self.suffix, self.prefix, self.given, self.title, self.ntype_field, + self.surname_field): + obj.update() def load_person_image(self): - media_list = self.person.get_media_list() + media_list = self.obj.get_media_list() if media_list: ph = media_list[0] object_handle = ph.get_reference_handle() @@ -782,18 +504,6 @@ class EditPerson(DisplayState.ManagedWindow): else: self.load_photo(None) - def write_primary_name(self): - # initial values - self.suffix.set_text(self.pname.get_suffix()) - if self.use_patronymic: - self.prefix.set_text(self.pname.get_patronymic()) - else: - self.prefix.set_text(self.pname.get_surname_prefix()) - - self.surname.set_text(self.pname.get_surname()) - self.given.set_text(self.pname.get_first_name()) - self.title.set_text(self.pname.get_title()) - def birth_dates_in_order(self,list): """Check any *valid* birthdates in the list to insure that they are in numerically increasing order.""" @@ -867,22 +577,3 @@ class EditPerson(DisplayState.ManagedWindow): list.insert(target,person.get_handle()) return list -def build_dropdown(entry,strings): - store = gtk.ListStore(str) - for value in strings: - node = store.append() - store.set(node,0,unicode(value)) - completion = gtk.EntryCompletion() - completion.set_text_column(0) - completion.set_model(store) - entry.set_completion(completion) - -def build_combo(entry,strings): - cell = gtk.CellRendererText() - entry.pack_start(cell,True) - entry.add_attribute(cell,'text',0) - store = gtk.ListStore(str) - for value in strings: - node = store.append() - store.set(node,0,unicode(value)) - entry.set_model(store) diff --git a/src/EditPlace.py b/src/EditPlace.py index 0f00e6acf..207bb2ebe 100644 --- a/src/EditPlace.py +++ b/src/EditPlace.py @@ -26,9 +26,7 @@ # #------------------------------------------------------------------------- import cPickle as pickle -import gc from gettext import gettext as _ -import sys import logging log = logging.getLogger(".") @@ -49,15 +47,9 @@ import gtk.glade #------------------------------------------------------------------------- import const import Utils -import Sources -import NameDisplay -import DisplayState -import Spell -import GrampsDisplay import RelLib -import ListModel +import EditPrimary -from DdTargets import DdTargets from DisplayTabs import * from GrampsWidgets import * @@ -66,50 +58,33 @@ from GrampsWidgets import * # EditPlace # #------------------------------------------------------------------------- -class EditPlace(DisplayState.ManagedWindow): +class EditPlace(EditPrimary.EditPrimary): - def __init__(self,dbstate,uistate,track,place): - self.dbstate = dbstate + def __init__(self,dbstate,uistate,track,place,callback=None): + EditPrimary.EditPrimary.__init__( + self, dbstate, uistate, track, place, + dbstate.db.get_place_from_handle, callback) - DisplayState.ManagedWindow.__init__(self, uistate, track, place) + def _local_init(self): + self.top = gtk.glade.XML(const.gladeFile,"place_editor","gramps") - self.name_display = NameDisplay.displayer.display - self.place = place - self.db = dbstate.db - - self.top = gtk.glade.XML(const.gladeFile,"placeEditor","gramps") - - self.window = self.top.get_widget("placeEditor") - title_label = self.top.get_widget('title') - - Utils.set_titles(self.window,title_label,_('Place Editor')) - - self.top.get_widget('changed').set_text(place.get_change_display()) - - self.notebook = self.top.get_widget('notebook3') - - self._create_tabbed_pages() - self._setup_fields() - self._connect_signals() - self.show() - - self.pdmap = {} - self.build_pdmap() + self.define_top_level(self.top.get_widget("place_editor"), + self.top.get_widget('title'), + _('Place Editor')) def _connect_signals(self): - self.top.get_widget('placeEditor').connect('delete_event', self.delete_event) - self.top.get_widget('button127').connect('clicked', self.close) - self.top.get_widget('button135').connect('clicked', self.help_clicked) - ok = self.top.get_widget('ok') - ok.connect('clicked', self.apply_clicked) - ok.set_sensitive(not self.db.readonly) + self.define_ok_button(self.top.get_widget('ok'),self.save) + self.define_cancel_button(self.top.get_widget('cancel')) + self.define_help_button(self.top.get_widget('help'),'adv-plc') def _setup_fields(self): - mloc = self.place.get_main_location() + mloc = self.obj.get_main_location() + self.top.get_widget('changed').set_text(self.obj.get_change_display()) + self.title = MonitoredEntry( self.top.get_widget("place_title"), - self.place.set_title, self.place.get_title, + self.obj.set_title, self.obj.get_title, self.db.readonly) self.city = MonitoredEntry( @@ -142,21 +117,14 @@ class EditPlace(DisplayState.ManagedWindow): self.longitude = MonitoredEntry( self.top.get_widget("longitude"), - self.place.set_longitude, self.place.get_longitude, + self.obj.set_longitude, self.obj.get_longitude, self.db.readonly) self.latitude = MonitoredEntry( self.top.get_widget("latitude"), - self.place.set_latitude, self.place.get_latitude, + self.obj.set_latitude, self.obj.get_latitude, self.db.readonly) - - def build_window_key(self,place): - if place: - return place.get_handle() - else: - return id(self) - def build_menu_names(self,place): win_menu_label = place.get_title() if not win_menu_label.strip(): @@ -164,7 +132,7 @@ class EditPlace(DisplayState.ManagedWindow): return (win_menu_label, _('Edit Place')) def build_pdmap(self): - self.pdmap.clear() + self.pdmap = {} cursor = self.db.get_place_cursor() data = cursor.next() while data: @@ -173,60 +141,52 @@ class EditPlace(DisplayState.ManagedWindow): data = cursor.next() cursor.close() - 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.loc_list = self._add_page(LocationEmbedList( - self.dbstate,self.uistate, self.track, - self.place.alt_loc)) - self.srcref_list = self._add_page(SourceEmbedList( - self.dbstate,self.uistate, self.track, - self.place.source_list)) - self.note_tab = self._add_page(NoteTab( - self.dbstate, self.uistate, self.track, - self.place.get_note_object())) - self.gallery_tab = self._add_page(GalleryTab( - self.dbstate, self.uistate, self.track, - self.place.get_media_list())) - self.web_list = self._add_page(WebEmbedList( - self.dbstate,self.uistate,self.track, - self.place.get_url_list())) - self.backref_list = self._add_page(PlaceBackRefList( - self.dbstate,self.uistate,self.track, - self.db.find_backlink_handles(self.place.handle))) + notebook = self.top.get_widget('notebook3') - def delete_event(self,obj,b): - self.close() + self.loc_list = self._add_tab( + notebook, + LocationEmbedList(self.dbstate,self.uistate, self.track, + self.obj.alt_loc)) + + self.srcref_list = self._add_tab( + notebook, + SourceEmbedList(self.dbstate,self.uistate, self.track, + self.obj.source_list)) + + self.note_tab = self._add_tab( + notebook, + NoteTab(self.dbstate, self.uistate, self.track, + self.obj.get_note_object())) + + self.gallery_tab = self._add_tab( + notebook, + GalleryTab(self.dbstate, self.uistate, self.track, + self.obj.get_media_list())) + + self.web_list = self._add_tab( + notebook, + WebEmbedList(self.dbstate,self.uistate,self.track, + self.obj.get_url_list())) + + self.backref_list = self._add_tab( + notebook, + PlaceBackRefList(self.dbstate,self.uistate,self.track, + self.db.find_backlink_handles(self.obj.handle))) - def close_window(self,obj): - self.close() - self.window.destroy() + def _cleanup_on_exit(self): + self.backref_list.close() - def help_clicked(self,obj): - """Display the relevant portion of GRAMPS manual""" - GrampsDisplay.help('adv-plc') + def save(self,*obj): + title = self.obj.get_title() + self.build_pdmap() - def build_columns(self,tree,list): - cnum = 0 - for name in list: - renderer = gtk.CellRendererText() - column = gtk.TreeViewColumn(name[0],renderer,text=cnum) - column.set_min_width(name[1]) - cnum = cnum + 1 - tree.append_column(column) - - def apply_clicked(self,obj): - - title = self.place.get_title() - if self.pdmap.has_key(title) and self.pdmap[title] != self.place.handle: + if self.pdmap.has_key(title) and self.pdmap[title] != self.obj.handle: import QuestionDialog QuestionDialog.ErrorDialog( _("Place title is already in use"), @@ -236,12 +196,12 @@ class EditPlace(DisplayState.ManagedWindow): return trans = self.db.transaction_begin() - if self.place.get_handle(): - self.db.commit_place(self.place,trans) + if self.obj.get_handle(): + self.db.commit_place(self.obj,trans) else: - self.db.add_place(self.place,trans) + self.db.add_place(self.obj,trans) self.db.transaction_commit(trans, - _("Edit Place (%s)") % self.place.get_title()) + _("Edit Place (%s)") % self.obj.get_title()) self.close(obj) @@ -254,13 +214,13 @@ class DeletePlaceQuery: def __init__(self,place,db): self.db = db - self.place = place + self.obj = place def query_response(self): trans = self.db.transaction_begin() self.db.disable_signals() - place_handle = self.place.get_handle() + place_handle = self.obj.get_handle() for handle in self.db.get_person_handles(sort_handles=False): person = self.db.get_person_from_handle(handle) @@ -283,4 +243,4 @@ class DeletePlaceQuery: self.db.enable_signals() self.db.remove_place(place_handle,trans) self.db.transaction_commit(trans, - _("Delete Place (%s)") % self.place.get_title()) + _("Delete Place (%s)") % self.obj.get_title()) diff --git a/src/EditRepository.py b/src/EditRepository.py index 66f0aa715..32ea17f03 100644 --- a/src/EditRepository.py +++ b/src/EditRepository.py @@ -32,9 +32,8 @@ from gettext import gettext as _ # GTK/Gnome modules # #------------------------------------------------------------------------- -import gobject +import gtk import gtk.glade -import gtk.gdk #------------------------------------------------------------------------- # @@ -44,117 +43,91 @@ import gtk.gdk import const import Utils import RelLib -import NameDisplay -import GrampsDisplay from GrampsWidgets import * from DisplayTabs import * -import DisplayState +import EditPrimary -class EditRepository(DisplayState.ManagedWindow): +class EditRepository(EditPrimary.EditPrimary): def __init__(self,dbstate,uistate,track,repository): - if repository: - self.repository = repository - else: - self.repository = RelLib.Repository() + EditPrimary.EditPrimary.__init__(self, dbstate, uistate, track, + repository, dbstate.db.get_repository_from_handle) - DisplayState.ManagedWindow.__init__(self, uistate, track, repository) + def _local_init(self): + self.glade = gtk.glade.XML(const.gladeFile,"repository_editor","gramps") + self.define_top_level(self.glade.get_widget("repository_editor"), + self.glade.get_widget('repository_title'), + _('Repository Editor')) - self.dbstate = dbstate - self.db = dbstate.db - self.name_display = NameDisplay.displayer.display - - self.path = self.db.get_save_path() - - self.glade = gtk.glade.XML(const.gladeFile,"repositoryEditor","gramps") - self.window = self.glade.get_widget("repositoryEditor") - - Utils.set_titles(self.window,self.glade.get_widget('repository_title'), - _('Repository Editor')) + def _setup_fields(self): self.name = MonitoredEntry( self.glade.get_widget("repository_name"), - self.repository.set_name, - self.repository.get_name, + self.obj.set_name, + self.obj.get_name, self.db.readonly) self.type = MonitoredType( self.glade.get_widget("repository_type"), - self.repository.set_type, - self.repository.get_type, + self.obj.set_type, + self.obj.get_type, dict(Utils.repository_types), RelLib.Repository.CUSTOM) self.call_number = MonitoredEntry( self.glade.get_widget('gid'), - self.repository.set_gramps_id, - self.repository.get_gramps_id, + self.obj.set_gramps_id, + self.obj.get_gramps_id, self.db.readonly) - self.notebook = gtk.Notebook() - self.notebook.show() - self.glade.get_widget("vbox").pack_start(self.notebook,True,True) - - self.addr_tab = self._add_page(AddrEmbedList( - self.dbstate, self.uistate, self.track, - repository.get_address_list())) - - self.url_tab = self._add_page(WebEmbedList( - self.dbstate, self.uistate, self.track, - repository.get_url_list())) + def _create_tabbed_pages(self): - self.note_tab = self._add_page(NoteTab( - self.dbstate, self.uistate, self.track, - repository.get_note_object())) + notebook = gtk.Notebook() - self.backref_tab = self._add_page(SourceBackRefList( - self.dbstate, self.uistate, self.track, - self.db.find_backlink_handles(self.repository.handle))) + self.addr_tab = self._add_tab( + notebook, + AddrEmbedList(self.dbstate, self.uistate, self.track, + self.obj.get_address_list())) - self.glade.signal_autoconnect({ - "on_repositoryEditor_help_clicked" : self.on_help_clicked, - "on_repositoryEditor_ok_clicked" : self.on_repository_apply_clicked, - "on_repositoryEditor_cancel_clicked" : self.close_window, - "on_repositoryEditor_delete_event" : self.on_delete_event, - }) - - self.glade.get_widget('ok').set_sensitive(not self.db.readonly) - self.window.show() - - def _add_page(self,page): - self.notebook.insert_page(page) - self.notebook.set_tab_label(page,page.get_tab_widget()) - return page - - def on_delete_event(self,obj,b): - self.close() - - def on_help_clicked(self,obj): - """Display the relevant portion of GRAMPS manual""" - GrampsDisplay.help('adv-src') - - def close_window(self,obj): - self.close() - self.window.destroy() + self.url_tab = self._add_tab( + notebook, + WebEmbedList(self.dbstate, self.uistate, self.track, + self.obj.get_url_list())) - def on_repository_apply_clicked(self,obj): + self.note_tab = self._add_tab( + notebook, + NoteTab(self.dbstate, self.uistate, self.track, + self.obj.get_note_object())) + self.backref_tab = self._add_tab( + notebook, + SourceBackRefList(self.dbstate, self.uistate, self.track, + self.db.find_backlink_handles(self.obj.handle))) + + notebook.show_all() + self.glade.get_widget("vbox").pack_start(notebook,True,True) + + def _connect_signals(self): + self.define_help_button(self.glade.get_widget('help'),'adv-src') + self.define_cancel_button(self.glade.get_widget('cancel')) + self.define_ok_button(self.glade.get_widget('ok'), self.save) + + def save(self,*obj): trans = self.db.transaction_begin() - handle = None - if self.repository.get_handle() == None: - handle = self.db.add_repository(self.repository,trans) + if self.obj.get_handle() == None: + handle = self.db.add_repository(self.obj,trans) else: - self.db.commit_repository(self.repository,trans) - handle = self.repository.get_handle() - self.db.transaction_commit(trans,_("Edit Repository (%s)") % self.repository.get_name()) - + self.db.commit_repository(self.obj,trans) + handle = self.obj.get_handle() + msg = _("Edit Repository (%s)") % self.obj.get_name() + self.db.transaction_commit(trans,msg) self.close(obj) class DelRepositoryQuery: def __init__(self,repository,db,sources): - self.repository = repository + self.obj = repository self.db = db self.sources = sources @@ -162,13 +135,13 @@ class DelRepositoryQuery: trans = self.db.transaction_begin() - repos_handle_list = [self.repository.get_handle()] + repos_handle_list = [self.obj.get_handle()] for handle in self.sources: source = self.db.get_source_from_handle(handle) source.remove_repo_references(repos_handle_list) self.db.commit_source(source,trans) - self.db.remove_repository(self.repository.get_handle(),trans) + self.db.remove_repository(self.obj.get_handle(),trans) self.db.transaction_commit( - trans,_("Delete Repository (%s)") % self.repository.get_name()) + trans,_("Delete Repository (%s)") % self.obj.get_name()) diff --git a/src/EditSource.py b/src/EditSource.py index ad5b2db56..e892052ba 100644 --- a/src/EditSource.py +++ b/src/EditSource.py @@ -26,8 +26,6 @@ # #------------------------------------------------------------------------- from gettext import gettext as _ -import gc -import sys import logging log = logging.getLogger(".") @@ -51,7 +49,7 @@ import RelLib import NameDisplay import Spell import GrampsDisplay -import DisplayState +import EditPrimary from DisplayTabs import * from WindowUtils import GladeIf @@ -62,104 +60,84 @@ from GrampsWidgets import * # Constants # #------------------------------------------------------------------------- -class EditSource(DisplayState.ManagedWindow): +class EditSource(EditPrimary.EditPrimary): - def __init__(self,dbstate,uistate,track,source,readonly=False): - self.dbstate = dbstate - self.track = track - self.uistate = uistate + def __init__(self,dbstate,uistate,track,source): - self.db = dbstate.db - self.name_display = NameDisplay.displayer.display + EditPrimary.EditPrimary.__init__( + self, dbstate, uistate, track, + source, dbstate.db.get_source_from_handle) - DisplayState.ManagedWindow.__init__(self, uistate, self.track, source) + def _local_init(self): - if source: - self.source = source - else: - self.source = RelLib.Source() + assert(self.obj) + self.glade = gtk.glade.XML(const.gladeFile,"source_editor","gramps") - self.glade = gtk.glade.XML(const.gladeFile,"sourceEditor","gramps") - self.window = self.glade.get_widget("sourceEditor") - - Utils.set_titles(self.window,self.glade.get_widget('title'), - _('Source Editor')) + self.define_top_level(self.glade.get_widget("source_editor"), + self.glade.get_widget('title'), + _('Source Editor')) - self.vbox = self.glade.get_widget('vbox') - - self.notebook = gtk.Notebook() - self.notebook.show() - self.vbox.pack_start(self.notebook,True) - - self._create_tabbed_pages() - self._setup_fields() - self._connect_signals() - self.show() def _connect_signals(self): - self.glade.get_widget('cancel').connect('clicked', self.close_window) - - ok = self.glade.get_widget('ok') - ok.set_sensitive(not self.db.readonly) - ok.connect('clicked', self.apply_clicked) + self.define_ok_button(self.glade.get_widget('ok'),self.save) + self.define_cancel_button(self.glade.get_widget('cancel')) + self.define_help_button(self.glade.get_widget('help'),'adv-src') def _setup_fields(self): self.author = MonitoredEntry( self.glade.get_widget("author"), - self.source.set_author, - self.source.get_author, + self.obj.set_author, + self.obj.get_author, self.db.readonly) self.pubinfo = MonitoredEntry( self.glade.get_widget("pubinfo"), - self.source.set_publication_info, - self.source.get_publication_info, + self.obj.set_publication_info, + self.obj.get_publication_info, self.db.readonly) self.abbrev = MonitoredEntry( self.glade.get_widget("abbrev"), - self.source.set_abbreviation, - self.source.get_abbreviation, + self.obj.set_abbreviation, + self.obj.get_abbreviation, self.db.readonly) self.title = MonitoredEntry( self.glade.get_widget("source_title"), - self.source.set_title, - self.source.get_title, + self.obj.set_title, + self.obj.get_title, self.db.readonly) - 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): - self.note_tab = self._add_page(NoteTab( - self.dbstate, self.uistate, self.track, - self.source.get_note_object())) - - self.gallery_tab = self._add_page(GalleryTab( - self.dbstate, self.uistate, self.track, - self.source.get_media_list())) - - self.data_tab = self._add_page(DataEmbedList( - self.dbstate, self.uistate, self.track, self.source)) - - self.repo_tab = self._add_page(RepoEmbedList( - self.dbstate, self.uistate, self.track, - self.source.get_reporef_list())) - - self.backref_tab = self._add_page(SourceBackRefList( - self.dbstate, self.uistate, self.track, - self.db.find_backlink_handles(self.source.handle))) - - self.notebook.show_all() + notebook = gtk.Notebook() - def build_window_key(self,source): - if source: - return source.get_handle() - else: - return id(self) + self.note_tab = self._add_tab( + notebook, + NoteTab(self.dbstate, self.uistate, self.track, + self.obj.get_note_object())) + + self.gallery_tab = self._add_tab( + notebook, + GalleryTab(self.dbstate, self.uistate, self.track, + self.obj.get_media_list())) + + self.data_tab = self._add_tab( + notebook, + DataEmbedList(self.dbstate, self.uistate, self.track, + self.obj)) + + self.repo_tab = self._add_tab( + notebook, + RepoEmbedList(self.dbstate, self.uistate, self.track, + self.obj.get_reporef_list())) + + self.backref_tab = self._add_tab( + notebook, + SourceBackRefList(self.dbstate, self.uistate, self.track, + self.db.find_backlink_handles(self.obj.handle))) + + notebook.show_all() + self.glade.get_widget('vbox').pack_start(notebook,True) def build_menu_names(self,source): if source: @@ -168,27 +146,18 @@ class EditSource(DisplayState.ManagedWindow): label = "New Source" return (label, _('Source Editor')) - def on_delete_event(self,obj,b): + def _cleanup_on_exit(self): self.backref_tab.close() - self.close() - def on_help_clicked(self,obj): - """Display the relevant portion of GRAMPS manual""" - GrampsDisplay.help('adv-src') - - def close_window(self,obj): - self.backref_tab.close() - self.close() - - def apply_clicked(self,obj): + def save(self,*obj): trans = self.db.transaction_begin() - if self.source.get_handle() == None: - self.db.add_source(self.source,trans) + if self.obj.get_handle() == None: + self.db.add_source(self.obj,trans) else: - self.db.commit_source(self.source,trans) + self.db.commit_source(self.obj,trans) self.db.transaction_commit(trans, - _("Edit Source (%s)") % self.source.get_title()) + _("Edit Source (%s)") % self.obj.get_title()) self.close(obj) class DelSrcQuery: diff --git a/src/EditSourceRef.py b/src/EditSourceRef.py index 8f2979f9a..f0dc16e70 100644 --- a/src/EditSourceRef.py +++ b/src/EditSourceRef.py @@ -45,13 +45,10 @@ import gtk.glade # gramps modules # #------------------------------------------------------------------------- -import Sources -import Witness import const import Utils import AutoComp import RelLib -import GrampsDisplay import DisplayState from QuestionDialog import WarningDialog, ErrorDialog @@ -74,8 +71,6 @@ class EditSourceRef(DisplayState.ManagedWindow): self.source = source DisplayState.ManagedWindow.__init__(self, uistate, track, source_ref) - if self.already_exist: - return self.update = update diff --git a/src/Errors.py b/src/Errors.py index 5665306a7..a6a26e0b1 100644 --- a/src/Errors.py +++ b/src/Errors.py @@ -102,3 +102,12 @@ class FileVersionError(Exception): def __str__(self): return self.value + +class WindowActiveError(Exception): + """Error used to report that the request window is already displayed.""" + def __init__(self,value): + Exception.__init__(self) + self.value = value + + def __str__(self): + return self.value diff --git a/src/EventEdit.py b/src/EventEdit.py index faea9efed..490be1a3f 100644 --- a/src/EventEdit.py +++ b/src/EventEdit.py @@ -49,9 +49,8 @@ import const import Utils import AutoComp import RelLib -import DateEdit import GrampsDisplay -import DisplayState +import EditPrimary from QuestionDialog import WarningDialog, ErrorDialog from DisplayTabs import * @@ -72,111 +71,95 @@ for event_type in Utils.family_events.keys(): # EventEditor class # #------------------------------------------------------------------------- -class EventEditor(DisplayState.ManagedWindow): +class EventEditor(EditPrimary.EditPrimary): def __init__(self,event,dbstate,uistate,track=[],callback=None): - self.db = dbstate.db - self.uistate = uistate - self.dbstate = dbstate - self.track = track - self.callback = callback - - self.event = event - self.path = self.db.get_save_path() - self.plist = [] - self.pmap = {} - DisplayState.ManagedWindow.__init__(self, uistate, self.track, event) - if self.already_exist: - return - - if not event: - self.event = RelLib.Event() + EditPrimary.EditPrimary.__init__(self, dbstate, uistate, track, + event, dbstate.db.get_event_from_handle) + def _local_init(self): self.top = gtk.glade.XML(const.gladeFile, "event_edit","gramps") - self.window = self.top.get_widget("event_edit") - title_label = self.top.get_widget('title') etitle = _('Event Editor') - Utils.set_titles(self.window,title_label, etitle, - _('Event Editor')) - - self._create_tabbed_pages() - self._setup_fields() - self._connect_signals() - self.show() + Utils.set_titles(self.window, self.top.get_widget('title'), + etitle, etitle) def _connect_signals(self): - self.top.get_widget('button111').connect('clicked',self.close_window) - self.top.get_widget('button126').connect('clicked',self.on_help_clicked) + self.top.get_widget('button111').connect('clicked',self.delete_event) + self.top.get_widget('button126').connect('clicked',self.help_clicked) ok = self.top.get_widget('ok') ok.set_sensitive(not self.db.readonly) - ok.connect('clicked',self.on_event_edit_ok_clicked) + ok.connect('clicked',self.save) def _setup_fields(self): self.place_field = PlaceEntry( self.top.get_widget("eventPlace"), - self.event.get_place_handle(), + self.obj.get_place_handle(), self.dbstate.get_place_completion(), self.db.readonly) self.cause_monitor = MonitoredEntry( self.top.get_widget("eventCause"), - self.event.set_cause, - self.event.get_cause, self.db.readonly) + self.obj.set_cause, + self.obj.get_cause, self.db.readonly) self.descr_field = MonitoredEntry( self.top.get_widget("event_description"), - self.event.set_description, - self.event.get_description, self.db.readonly) + self.obj.set_description, + self.obj.get_description, self.db.readonly) self.priv = PrivacyButton( self.top.get_widget("private"), - self.event, self.db.readonly) + self.obj, self.db.readonly) self.event_menu = MonitoredType( self.top.get_widget("personal_events"), - self.event.set_type, - self.event.get_type, + self.obj.set_type, + self.obj.get_type, dict(total_events), RelLib.Event.CUSTOM) self.date_field = MonitoredDate( self.top.get_widget("eventDate"), self.top.get_widget("date_stat"), - self.event.get_date_object(), + self.obj.get_date_object(), self.window, self.db.readonly) - 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. """ - vbox = self.top.get_widget('vbox') - self.notebook = gtk.Notebook() + notebook = gtk.Notebook() + + self.srcref_list = self._add_tab( + notebook, + SourceEmbedList(self.dbstate,self.uistate, self.track, + self.obj.source_list)) + + self.note_tab = self._add_tab( + notebook, + NoteTab(self.dbstate, self.uistate, self.track, + self.obj.get_note_object())) + + self.gallery_tab = self._add_tab( + notebook, + GalleryTab(self.dbstate, self.uistate, self.track, + self.obj.get_media_list())) + + self.backref_tab = self._add_tab( + notebook, + EventBackRefList(self.dbstate, self.uistate, self.track, + self.dbstate.db.find_backlink_handles(self.obj.handle))) - self.srcref_list = self._add_page(SourceEmbedList( - self.dbstate,self.uistate, self.track, - self.event.source_list)) - self.note_tab = self._add_page(NoteTab( - self.dbstate, self.uistate, self.track, - self.event.get_note_object())) - self.gallery_tab = self._add_page(GalleryTab( - self.dbstate, self.uistate, self.track, - self.event.get_media_list())) - self.backref_tab = self._add_page(EventBackRefList( - self.dbstate, self.uistate, self.track, - self.dbstate.db.find_backlink_handles(self.event.handle))) + notebook.show_all() + self.top.get_widget('vbox').pack_start(notebook,True) - self.notebook.show_all() - vbox.pack_start(self.notebook,True) + def _cleanup_on_exit(self): + self.backref_tab.close() def build_menu_names(self,event): if event: @@ -192,60 +175,53 @@ class EventEditor(DisplayState.ManagedWindow): submenu_label = _('New Event') return (_('Event Editor'),submenu_label) - def build_window_key(self,obj): - if obj: - return obj.get_handle() - else: - return id(self) - - def on_delete_event(self,obj,b): - self.close() - - def close_window(self,obj): - self.close() - self.window.destroy() - - def on_help_clicked(self,obj): + def help_clicked(self,obj): """Display the relevant portion of GRAMPS manual""" GrampsDisplay.help('adv-ev') - def on_event_edit_ok_clicked(self,obj): + def save(self,*obj): (need_new, handle) = self.place_field.get_place_info() if need_new: place_obj = RelLib.Place() place_obj.set_title(handle) - self.event.set_place_handle(place_obj.get_handle()) + self.obj.set_place_handle(place_obj.get_handle()) else: - self.event.set_place_handle(handle) + self.obj.set_place_handle(handle) - if self.event.handle == None: + if self.obj.handle == None: trans = self.db.transaction_begin() if need_new: self.db.add_place(place_obj,trans) - self.db.add_event(self.event,trans) + self.db.add_event(self.obj,trans) self.db.transaction_commit(trans,_("Add Event")) else: - orig = self.dbstate.db.get_event_from_handle(self.event.handle) - if cmp(self.event.serialize(),orig.serialize()): + orig = self.dbstate.db.get_event_from_handle(self.obj.handle) + if cmp(self.obj.serialize(),orig.serialize()): trans = self.db.transaction_begin() if need_new: self.db.add_place(place_obj,trans) - self.db.commit_event(self.event,trans) + self.db.commit_event(self.obj,trans) self.db.transaction_commit(trans,_("Edit Event")) if self.callback: - self.callback(self.event) + self.callback(self.obj) self.close(obj) - def commit(self,event,trans): - self.db.commit_event(event,trans) - def get_event_names(self): data = set(self.db.get_family_event_types()) data.union(self.db.get_person_event_types()) return list(data) + def data_has_changed(self): + if self.db.readonly: + return False + elif self.obj.handle: + orig = self.db.get_event_from_handle(self.obj.handle) + return cmp(orig.serialize(),self.obj.serialize()) != 0 + else: + return True + #------------------------------------------------------------------------- # # Delete Query class diff --git a/src/EventView.py b/src/EventView.py index c644fff5e..f556b94e7 100644 --- a/src/EventView.py +++ b/src/EventView.py @@ -114,10 +114,16 @@ class EventView(PageView.ListView): def on_double_click(self,obj,event): handle = self.first_selected() the_event = self.dbstate.db.get_event_from_handle(handle) - EventEdit.EventEditor(the_event,self.dbstate, self.uistate, []) + try: + EventEdit.EventEditor(the_event,self.dbstate, self.uistate, []) + except Errors.WindowActiveError: + pass def add(self,obj): - EventEdit.EventEditor(RelLib.Event(),self.dbstate, self.uistate, []) + try: + EventEdit.EventEditor(RelLib.Event(),self.dbstate, self.uistate, []) + except Errors.WindowActiveError: + pass def remove(self,obj): for event_handle in self.selected_handles(): @@ -155,5 +161,8 @@ class EventView(PageView.ListView): for handle in mlist: event = self.dbstate.db.get_event_from_handle(handle) - EventEdit.EventEditor(event, self.dbstate, self.uistate) + try: + EventEdit.EventEditor(event, self.dbstate, self.uistate) + except Errors.WindowActiveError: + pass diff --git a/src/FamilyList.py b/src/FamilyList.py index dd3fbc6d1..fb2f04e67 100644 --- a/src/FamilyList.py +++ b/src/FamilyList.py @@ -37,6 +37,7 @@ import PageView import DisplayModels import const import Utils +import Errors from QuestionDialog import QuestionDialog, ErrorDialog #------------------------------------------------------------------------- @@ -114,7 +115,10 @@ class FamilyListView(PageView.ListView): def add(self,obj): import EditFamily family = RelLib.Family() - EditFamily.EditFamily(self.dbstate,self.uistate,[],family) + try: + EditFamily.EditFamily(self.dbstate,self.uistate,[],family) + except Errors.WindowActiveError: + pass def remove(self,obj): return @@ -126,4 +130,7 @@ class FamilyListView(PageView.ListView): for handle in mlist: import EditFamily family = self.dbstate.db.get_family_from_handle(handle) - EditFamily.EditFamily(self.dbstate,self.uistate,[],family) + try: + EditFamily.EditFamily(self.dbstate,self.uistate,[],family) + except Errors.WindowActiveError: + pass diff --git a/src/FamilyView.py b/src/FamilyView.py index 0b24544af..57e2eec27 100644 --- a/src/FamilyView.py +++ b/src/FamilyView.py @@ -31,6 +31,7 @@ import ImgManip import ReportUtils import GrampsKeys import GrampsWidgets +import Errors _GenderCode = { RelLib.Person.MALE : u'\u2642', @@ -556,24 +557,36 @@ class FamilyView(PageView.PersonNavView): if event.type == gtk.gdk.BUTTON_PRESS and event.button == 1: import EditPerson person = self.dbstate.db.get_person_from_handle(handle) - EditPerson.EditPerson(self.dbstate, self.uistate, [], person) + try: + EditPerson.EditPerson(self.dbstate, self.uistate, [], person) + except Errors.WindowActiveError: + pass def edit_person(self,obj,handle): import EditPerson person = self.dbstate.db.get_person_from_handle(handle) - EditPerson.EditPerson(self.dbstate, self.uistate, [], person) + try: + EditPerson.EditPerson(self.dbstate, self.uistate, [], person) + except Errors.WindowActiveError: + pass def edit_family(self,obj,event,handle): if event.type == gtk.gdk.BUTTON_PRESS and event.button == 1: import EditFamily family = self.dbstate.db.get_family_from_handle(handle) - EditFamily.EditFamily(self.dbstate,self.uistate,[],family) + try: + EditFamily.EditFamily(self.dbstate,self.uistate,[],family) + except Errors.WindowActiveError: + pass def add_family(self,obj,event,handle): if event.type == gtk.gdk.BUTTON_PRESS and event.button == 1: import EditFamily family = RelLib.Family() - EditFamily.EditFamily(self.dbstate,self.uistate,[],family) + try: + EditFamily.EditFamily(self.dbstate,self.uistate,[],family) + except Errors.WindowActiveError: + pass def delete_family(self,obj,event,handle): if event.type == gtk.gdk.BUTTON_PRESS and event.button == 1: diff --git a/src/GrampsWidgets.py b/src/GrampsWidgets.py index d3e3454cf..d8fa4bc68 100644 --- a/src/GrampsWidgets.py +++ b/src/GrampsWidgets.py @@ -236,12 +236,12 @@ class MonitoredCheckbox: self.obj = obj self.set_val = set_val self.get_val = get_val - self.set_active(get_val()) + self.obj.set_active(get_val()) def _on_toggle(self,obj): self.set_val(obj.get_active()) if self.on_toggle: - self.on_toggle(get_val()) + self.on_toggle(self.get_val()) class MonitoredEntry: @@ -256,6 +256,9 @@ class MonitoredEntry: self.obj.connect('changed', self._on_change) self.obj.set_editable(not read_only) + def connect(self,signal,callback): + self.obj.connect(signal,callback) + def _on_change(self,obj): self.set_val(unicode(obj.get_text())) if self.changed: @@ -264,10 +267,20 @@ class MonitoredEntry: def force_value(self,value): self.obj.set_text(value) + def get_value(self,value): + return unicode(self.obj.get_text()) + def enable(self,value): self.obj.set_sensitive(value) self.obj.set_editable(value) + def grab_focus(self): + self.obj.grab_focus() + + def update(self): + if self.get_val(): + self.obj.set_text(self.get_val()) + class MonitoredText: def __init__(self,obj,set_val,get_val,read_only=False): @@ -304,6 +317,10 @@ class MonitoredType: self.obj.set_sensitive(not readonly) self.obj.connect('changed', self.on_change) + def update(self): + if self.get_val(): + self.sel.set_values(self.get_val()) + def on_change(self, obj): self.set_val(self.sel.get_values()) @@ -322,6 +339,9 @@ class MonitoredMenu: self.obj.connect('changed',self.on_change) self.obj.set_sensitive(not readonly) + def force(self,value): + self.obj.set_active(value) + def on_change(self, obj): self.set_val(self.model.get_value(obj.get_active_iter(),1)) diff --git a/src/LocEdit.py b/src/LocEdit.py index 148466fb9..e08c4b2aa 100644 --- a/src/LocEdit.py +++ b/src/LocEdit.py @@ -35,7 +35,6 @@ import gtk.glade #------------------------------------------------------------------------- import const import Utils -import RelLib import GrampsDisplay import DisplayState diff --git a/src/NameEdit.py b/src/NameEdit.py index bd2cabd2e..f39afc7ae 100644 --- a/src/NameEdit.py +++ b/src/NameEdit.py @@ -43,13 +43,8 @@ import gtk.glade #------------------------------------------------------------------------- import const import Utils -import AutoComp -import Sources import RelLib import NameDisplay -import DateEdit -import DateHandler -import Spell import GrampsDisplay import DisplayState from DisplayTabs import * @@ -71,8 +66,6 @@ class NameEditor(DisplayState.ManagedWindow): self.callback = callback DisplayState.ManagedWindow.__init__(self, uistate, track, name) - if self.already_exist: - return self.name = name self.original_group_as = self.name.get_group_as() diff --git a/src/PedView.py b/src/PedView.py index db33de830..63dfdfb49 100644 --- a/src/PedView.py +++ b/src/PedView.py @@ -908,7 +908,11 @@ class PedView(PageView.PersonNavView): def edit_person_cb(self,obj,person_handle): person = self.db.get_person_from_handle(person_handle) if person: - EditPerson.EditPerson(self.dbstate, self.uistate, [], person, self.person_edited_cb) + try: + EditPerson.EditPerson(self.dbstate, self.uistate, [], person, + self.person_edited_cb) + except Errors.WindowActiveError: + pass return True return False @@ -929,7 +933,12 @@ class PedView(PageView.PersonNavView): if event.button==1 and event.type == gtk.gdk._2BUTTON_PRESS: person = self.db.get_person_from_handle(person_handle) if person: - EditPerson.EditPerson(self.dbstate, self.uistate, [], person, self.person_edited_cb) + try: + EditPerson.EditPerson(self.dbstate, self.uistate, [], person, + self.person_edited_cb) + except Errors.WindowActiveError: + pass + elif event.button!=1: self.build_full_nav_menu_cb(obj,event,person_handle) return True diff --git a/src/PersonView.py b/src/PersonView.py index 2fb3d468f..23dff14f9 100644 --- a/src/PersonView.py +++ b/src/PersonView.py @@ -53,6 +53,7 @@ import NameDisplay import Utils import QuestionDialog import TreeTips +import Errors from DdTargets import DdTargets @@ -349,12 +350,18 @@ class PersonView(PageView.PersonNavView): def add(self,obj): person = RelLib.Person() - EditPerson.EditPerson(self.dbstate, self.uistate, [], person) + try: + EditPerson.EditPerson(self.dbstate, self.uistate, [], person) + except Errors.WindowActiveError: + pass def edit(self,obj): if self.dbstate.active: - EditPerson.EditPerson(self.dbstate, self.uistate, [], - self.dbstate.active) + try: + EditPerson.EditPerson(self.dbstate, self.uistate, [], + self.dbstate.active) + except Errors.WindowActiveError: + pass def remove(self,obj): mlist = self.get_selected_objects() @@ -608,7 +615,10 @@ class PersonView(PageView.PersonNavView): handle = self.first_selected() person = self.dbstate.db.get_person_from_handle(handle) if person: - EditPerson.EditPerson(self.dbstate, self.uistate, [], person) + try: + EditPerson.EditPerson(self.dbstate, self.uistate, [], person) + except Errors.WindowActiveError: + pass return True elif event.type == gtk.gdk.BUTTON_PRESS and event.button == 3: menu = self.uistate.uimanager.get_widget('/Popup') diff --git a/src/PlaceView.py b/src/PlaceView.py index 57a973a10..f1795c998 100644 --- a/src/PlaceView.py +++ b/src/PlaceView.py @@ -38,6 +38,7 @@ import EditPlace import DisplayModels import const import Utils +import Errors from QuestionDialog import QuestionDialog, ErrorDialog #------------------------------------------------------------------------- @@ -118,10 +119,16 @@ class PlaceView(PageView.ListView): def on_double_click(self,obj,event): handle = self.first_selected() place = self.dbstate.db.get_place_from_handle(handle) - EditPlace.EditPlace(self.dbstate,self.uistate,[],place) + try: + EditPlace.EditPlace(self.dbstate,self.uistate,[],place) + except Errors.WindowActiveError: + pass def add(self,obj): - EditPlace.EditPlace(self.dbstate,self.uistate,[],RelLib.Place()) + try: + EditPlace.EditPlace(self.dbstate,self.uistate,[],RelLib.Place()) + except Errors.WindowActiveError: + pass def remove(self,obj): for event_handle in self.selected_handles(): @@ -159,5 +166,8 @@ class PlaceView(PageView.ListView): for handle in mlist: place = self.dbstate.db.get_place_from_handle(handle) - EditPlace.EditPlace(self.dbstate,self.uistate,[],place) + try: + EditPlace.EditPlace(self.dbstate,self.uistate,[],place) + except Errors.WindowActiveError: + pass diff --git a/src/Plugins.py b/src/Plugins.py index de33bf398..37ff36f6f 100644 --- a/src/Plugins.py +++ b/src/Plugins.py @@ -94,8 +94,7 @@ class PluginDialog(DisplayState.ManagedWindow): self.content = content DisplayState.ManagedWindow.__init__(self, uistate, [], None) - if self.already_exist: - return + self.state = state self.uistate = uistate @@ -315,8 +314,7 @@ class PluginStatus(DisplayState.ManagedWindow): import cStringIO DisplayState.ManagedWindow.__init__(self, uistate, [], None) - if self.already_exist: - return + self.state = state self.uistate = uistate diff --git a/src/UrlEdit.py b/src/UrlEdit.py index 38c528772..ddf029018 100644 --- a/src/UrlEdit.py +++ b/src/UrlEdit.py @@ -26,7 +26,6 @@ # #------------------------------------------------------------------------- from gettext import gettext as _ -import gc from cgi import escape #------------------------------------------------------------------------- @@ -65,8 +64,6 @@ class UrlEditor(DisplayState.ManagedWindow): self.name = name DisplayState.ManagedWindow.__init__(self, uistate, track, url) - if self.already_exist: - return self.url = url self.callback = callback diff --git a/src/Utils.py b/src/Utils.py index c13d9882d..2a3da3ed5 100644 --- a/src/Utils.py +++ b/src/Utils.py @@ -654,8 +654,9 @@ def set_title_label(xmlobj,t): title_label.set_use_markup(True) def set_titles(window,title,t,msg=None): - title.set_text('%s' % t) - title.set_use_markup(True) + if title: + title.set_text('%s' % t) + title.set_use_markup(True) if msg: window.set_title('%s - GRAMPS' % msg) else: diff --git a/src/const.py.in b/src/const.py.in index ae62a26b7..4ff392854 100644 --- a/src/const.py.in +++ b/src/const.py.in @@ -22,6 +22,14 @@ # $Id$ +#------------------------------------------------------------------------- +# +# Standard python modules +# +#------------------------------------------------------------------------- +import os +from gettext import gettext as _ + #------------------------------------------------------------------------- # # Standard GRAMPS Websites @@ -31,14 +39,6 @@ url_homepage = "http://gramps-project.org/" url_mailinglist = "http://sourceforge.net/mail/?group_id=25770" url_burtracker = "http://sourceforge.net/tracker/?group_id=25770&atid=385137" -#------------------------------------------------------------------------- -# -# Standard python modules -# -#------------------------------------------------------------------------- -import os -from gettext import gettext as _ - #------------------------------------------------------------------------- # # Mime Types @@ -88,14 +88,8 @@ no_gconf = False # this one, and that the plugins directory is in a directory below this. # #------------------------------------------------------------------------- -if os.environ.has_key('GRAMPSDIR'): - rootDir = os.environ['GRAMPSDIR'] -else: - rootDir = os.getcwd() -good_xpm = os.path.join(rootDir,"good.png") -bad_xpm = os.path.join(rootDir,"bad.png") -caution_xpm = os.path.join(rootDir,"caution.png") +rootDir = os.path.abspath(os.path.dirname(__file__)) system_filters = os.path.join(rootDir,"system_filters.xml") custom_filters = "~/.gramps/custom_filters.xml" diff --git a/src/gramps.glade b/src/gramps.glade index 9ff70d633..3036722af 100644 --- a/src/gramps.glade +++ b/src/gramps.glade @@ -4,7 +4,7 @@ - + True GTK_WINDOW_TOPLEVEL @@ -68,7 +68,7 @@ - + True True True @@ -492,7 +492,7 @@ - + True GTK_WINDOW_TOPLEVEL @@ -1370,7 +1370,7 @@ - + True GTK_WINDOW_TOPLEVEL @@ -1403,7 +1403,7 @@ GTK_BUTTONBOX_END - + True True True @@ -1432,7 +1432,7 @@ - + True True True @@ -12995,7 +12995,7 @@ Text Beside Icons - + True GTK_WINDOW_TOPLEVEL diff --git a/src/gramps.py b/src/gramps.py index 99fd55431..140fb69fa 100755 --- a/src/gramps.py +++ b/src/gramps.py @@ -48,6 +48,11 @@ import gtk.gdk import gtk import gtk.glade + +# setup import path + +sys.path.append(os.path.abspath(os.path.basename(__file__))) + #------------------------------------------------------------------------- # # Load internationalization setup