From 782841c73871056c16d2e36e96357640e14810eb Mon Sep 17 00:00:00 2001
From: Don Allingham <don@gramps-project.org>
Date: Mon, 21 Oct 2002 01:18:07 +0000
Subject: [PATCH] Fixed place editing

svn: r1146
---
 src/AddMedia.py       |  4 ++--
 src/EditPerson.py     |  2 +-
 src/EditPlace.py      |  5 +++--
 src/ImageSelect.py    |  5 +++--
 src/MediaView.py      |  4 ++--
 src/PlaceView.py      | 46 +++++++++++++++++++-------------------
 src/QuestionDialog.py | 25 ++++++++++++++++++++-
 src/ReadXML.py        | 22 +++++++++----------
 src/RelImage.py       | 26 ++++++++++------------
 src/RelLib.py         | 51 ++++++++++++++++++++++++++++---------------
 src/Report.py         |  6 +++--
 src/WriteXML.py       |  7 +++---
 src/gramps_main.py    | 16 +++++++-------
 13 files changed, 128 insertions(+), 91 deletions(-)

diff --git a/src/AddMedia.py b/src/AddMedia.py
index 889d90e21..8b449b5f3 100644
--- a/src/AddMedia.py
+++ b/src/AddMedia.py
@@ -43,7 +43,7 @@ _ = gettext
 # GTK/Gnome modules
 #
 #-------------------------------------------------------------------------
-from gnome.ui import GnomeErrorDialog
+from QuestionDialog import ErrorDialog
 import gtk.glade
 
 #-------------------------------------------------------------------------
@@ -103,7 +103,7 @@ class AddMediaObject:
         
         if os.path.exists(filename) == 0:
             msgstr = _("%s is not a valid file name or does not exist.")
-            GnomeErrorDialog(msgstr % filename)
+            ErrorDialog(msgstr % filename)
             return
 
         type = Utils.get_mime_type(filename)
diff --git a/src/EditPerson.py b/src/EditPerson.py
index 3dca00f1f..e83f68338 100644
--- a/src/EditPerson.py
+++ b/src/EditPerson.py
@@ -1248,7 +1248,7 @@ class EditPerson:
             msg = _("Changing the gender caused problems "
                     "with marriage information.\nPlease check "
                     "the person's marriages.")
-            GnomeErrorDialog(msg)
+            ErrorDialog(msg)
 
         text = self.notes_buffer.get_text(self.notes_buffer.get_start_iter(),
                                           self.notes_buffer.get_end_iter(),gtk.FALSE)
diff --git a/src/EditPlace.py b/src/EditPlace.py
index 33d942abe..10f56124e 100644
--- a/src/EditPlace.py
+++ b/src/EditPlace.py
@@ -404,7 +404,7 @@ class DeletePlaceQuery:
         self.update = update
         
     def query_response(self):
-        del self.db.getPlaceMap()[self.place.getId()]
+        self.db.removePlace(self.place.getId())
         Utils.modified()
 
         for key in self.db.getPersonKeys():
@@ -416,4 +416,5 @@ class DeletePlaceQuery:
             for event in f.getEventList():
                 if event.getPlace() == self.place:
                     event.setPlace(None)
-        self.update(0)
+
+        self.update(None)
diff --git a/src/ImageSelect.py b/src/ImageSelect.py
index dae6317a7..33181c240 100644
--- a/src/ImageSelect.py
+++ b/src/ImageSelect.py
@@ -53,6 +53,7 @@ import Marriage
 import EditPlace
 import EditSource
 
+from QuestionDialog import ErrorDialog
 from intl import gettext as _
 
 _IMAGEX = 140
@@ -137,7 +138,7 @@ class ImageSelect:
         description = self.description.get_text()
 
         if os.path.exists(filename) == 0:
-            gnome.ui.GnomeErrorDialog(_("That is not a valid file name."));
+            ErrorDialog(_("That is not a valid file name."));
             return
 
         already_imported = None
@@ -325,7 +326,7 @@ class Gallery(ImageSelect):
                 except IOError, msg:
                     t = _("Could not import %s") % d
                     
-                    gnome.ui.GnomeErrorDialog("%s\n%s %d" % (t,msg[0],msg[1]))
+                    ErrorDialog("%s\n%s %d" % (t,msg[0],msg[1]))
                     return
                 mime = Utils.get_mime_type(tfile)
                 photo = Photo()
diff --git a/src/MediaView.py b/src/MediaView.py
index ba6421860..796f10870 100644
--- a/src/MediaView.py
+++ b/src/MediaView.py
@@ -42,7 +42,7 @@ import ImageSelect
 #
 #-------------------------------------------------------------------------
 from RelLib import *
-from QuestionDialog import QuestionDialog
+from QuestionDialog import QuestionDialog, ErrorDialog
 import Utils
 import os
 import GrampsCfg
@@ -325,7 +325,7 @@ class MediaView:
                 except IOError, msg:
                     t = _("Could not import %s") % d
                     
-                    gnome.ui.GnomeErrorDialog("%s\n%s %d" % (t,msg[0],msg[1]))
+                    ErrorDialog("%s\n%s %d" % (t,msg[0],msg[1]))
                     return
                 mime = Utils.get_mime_type(tfile)
                 photo = Photo()
diff --git a/src/PlaceView.py b/src/PlaceView.py
index 30c165f9f..31595529f 100644
--- a/src/PlaceView.py
+++ b/src/PlaceView.py
@@ -37,7 +37,7 @@ import gtk.gdk
 #
 #-------------------------------------------------------------------------
 from RelLib import *
-from QuestionDialog import QuestionDialog
+from QuestionDialog import QuestionDialog, ErrorDialog
 
 import EditPlace
 import Utils
@@ -68,10 +68,10 @@ _column_headers = [
 class PlaceView:
     
     def __init__(self,db,glade,update):
-        self.db = db
-        self.glade = glade
-        self.list    = glade.get_widget("place_list")
-        self.update_display= update
+        self.db     = db
+        self.glade  = glade
+        self.list   = glade.get_widget("place_list")
+        self.update = update
 
         self.active = None
 
@@ -130,11 +130,11 @@ class PlaceView:
     def merge(self):
         if len(self.place_list.selection) != 2:
             msg = _("Exactly two places must be selected to perform a merge")
-            gnome.ui.GnomeErrorDialog(msg)
+            ErrorDialog(msg)
         else:
             import MergeData
             p1 = self.place_list.get_row_data(self.place_list.selection[0])
-            p2 = self.place_list.get_row_data(self.place_list.selection[1])
+            P2 = self.place_list.get_row_data(self.place_list.selection[1])
             p1 = self.db.getPlace(p1)
             p2 = self.db.getPlace(p2)
             MergeData.MergePlaces(self.db,p1,p2,self.load_places)
@@ -148,38 +148,36 @@ class PlaceView:
             EditPlace.EditPlace(self,place,self.update_display)
             return 1
 
-    def insert_place(self,place):
-        self.place_list.append(place.getDisplayInfo())
-        self.place_list.set_row_data(self.place_list.rows-1,place.getId())
+#    def insert_place(self,place):
+#        self.place_list.append(place.getDisplayInfo())
+#        self.place_list.set_row_data(self.place_list.rows-1,place.getId())
         
     def new_place_after_edit(self,place):
         self.db.addPlace(place)
         self.update(0)
 
     def update_display(self,place):
-        self.db.buildPlaceDisplay(place.getId())
+        if place:
+            self.db.buildPlaceDisplay(place.getId())
         self.update(0)
 
     def on_add_place_clicked(self,obj):
         EditPlace.EditPlace(self,Place(),self.new_place_after_edit)
 
-    def moveto(self,row):
-        self.place_list.unselect_all()
-        self.place_list.select_row(row,0)
-        self.place_list.moveto(row)
+#    def moveto(self,row):
+#        self.place_list.unselect_all()
+#        self.place_list.select_row(row,0)
+#        self.place_list.moveto(row)
         
     def on_delete_clicked(self,obj):
-        if len(obj.selection) == 0:
+        store,iter = self.selection.get_selected()
+        if not iter:
             return
-        elif len(obj.selection) > 1:
-            msg = _("Currently, you can only delete one place at a time")
-            gnome.ui.GnomeErrorDialog(msg)
-            return
-        else:
-            index = obj.selection[0]
+        
+        id = store.get_value(iter,1)
 
         used = 0
-        place = self.db.getPlace(obj.get_row_data(index))
+        place = self.db.getPlace(id)
         for key in self.db.getPersonKeys():
             p = self.db.getPerson(key)
             event_list = [p.getBirth(), p.getDeath()] + p.getEventList()
@@ -208,8 +206,8 @@ class PlaceView:
                            _('Delete Place'),ans.query_response,
                            _('Keep Place'))
         else:
-            obj.remove(index)
             self.db.removePlace(place.getId())
+            self.update(0)
             Utils.modified()
 
     def on_edit_clicked(self,obj):
diff --git a/src/QuestionDialog.py b/src/QuestionDialog.py
index 3e9a408dc..883748a3d 100644
--- a/src/QuestionDialog.py
+++ b/src/QuestionDialog.py
@@ -18,8 +18,9 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #
 
-import gnome.ui
 import gtk
+import gnome.ui
+from intl import gettext as _
 
 class QuestionDialog:
     def __init__(self,title,msg,blabel1,task1,blabel2,task2=None):
@@ -58,4 +59,26 @@ class QuestionDialog:
         if self.task2:
             self.task2()
         self.top.destroy()
+
+class ErrorDialog:
+    def __init__(self,msg):
+        title = '%s - GRAMPS' % _('Error')
+        
+        self.top = gtk.Dialog()
+        self.top.set_title(title)
+        label = gtk.Label(msg)
+        label.show()
+        hbox = gtk.HBox()
+        image = gtk.Image()
+        image.set_from_stock(gtk.STOCK_DIALOG_ERROR,gtk.ICON_SIZE_DIALOG)
+        hbox.set_spacing(10)
+        hbox.pack_start(image)
+        hbox.add(label)
+        self.top.vbox.pack_start(hbox)
+        self.top.set_default_size(300,150)
+        self.top.add_button(gtk.STOCK_OK,0)
+        self.top.set_response_sensitive(0,gtk.TRUE)
+        self.top.show_all()
+        self.top.run()
+        self.top.destroy()
         
diff --git a/src/ReadXML.py b/src/ReadXML.py
index bc6932f73..82ad58731 100644
--- a/src/ReadXML.py
+++ b/src/ReadXML.py
@@ -31,7 +31,7 @@ import os
 # Gnome/GTK
 #
 #-------------------------------------------------------------------------
-import gnome.ui #import GnomeErrorDialog
+import gnome.ui
 
 #-------------------------------------------------------------------------
 #
@@ -40,8 +40,8 @@ import gnome.ui #import GnomeErrorDialog
 #-------------------------------------------------------------------------
 from RelLib import *
 from GrampsParser import GrampsParser, GrampsImportParser
-from intl import gettext
-_ = gettext
+from QuestionDialog import ErrorDialog
+from intl import gettext as _
 
 #-------------------------------------------------------------------------
 #
@@ -86,16 +86,16 @@ def importData(database, filename, callback):
         else:
             xml_file = open(filename,"r")
     except IOError,msg:
-        GnomeErrorDialog(_("%s could not be opened\n") % filename + str(msg))
+        ErrorDialog(_("%s could not be opened\n") % filename + str(msg))
         return 0
     except:
-        GnomeErrorDialog(_("%s could not be opened\n") % filename)
+        ErrorDialog(_("%s could not be opened\n") % filename)
         return 0
         
     try:
         parser.parse(xml_file)
     except IOError,msg:
-        GnomeErrorDialog(_("Error reading %s") % filename + "\n" + str(msg))
+        ErrorDialog(_("Error reading %s") % filename + "\n" + str(msg))
         import traceback
         traceback.print_exc()
         return 0
@@ -142,22 +142,22 @@ def loadData(database, filename, callback=None):
             xml_file = open(filename,"r")
     except IOError,msg:
         filemsg = _("%s could not be opened\n") % filename
-        GnomeErrorDialog(filemsg + str(msg))
+        ErrorDialog(filemsg + str(msg))
         return 0
     except:
-        GnomeErrorDialog(_("%s could not be opened\n") % filename)
+        ErrorDialog(_("%s could not be opened\n") % filename)
         return 0
 
     try:
         parser.parse(xml_file)
     except IOError,msg:
         errmsg = "%s\n%s" % (_("Error reading %s") % filename,str(msg))
-        GnomeErrorDialog(errmsg)
+        ErrorDialog(errmsg)
         import traceback
         traceback.print_exc()
         return 0
     except:
-        GnomeErrorDialog(_("Error reading %s") % filename)
+        ErrorDialog(_("Error reading %s") % filename)
         import traceback
         traceback.print_exc()
         return 0
@@ -186,7 +186,7 @@ def loadRevision(database, file, filename, revision, callback=None):
         parser.parse(file)
     except IOError,msg:
         errmsg = "%s\n%s" % (_("Error reading %s") % filename, str(msg))
-        GnomeErrorDialog(errmsg)
+        ErrorDialog(errmsg)
         import traceback
         traceback.print_exc()
         return 0
diff --git a/src/RelImage.py b/src/RelImage.py
index 924b33360..48d8bfc51 100644
--- a/src/RelImage.py
+++ b/src/RelImage.py
@@ -32,7 +32,7 @@ import string
 #
 #-------------------------------------------------------------------------
 import gtk
-#from gnome.ui import GnomeErrorDialog, GnomeWarningDialog
+from QuestionDialog import ErrorDialog
 
 #-------------------------------------------------------------------------
 #
@@ -42,9 +42,7 @@ import gtk
 import const
 import Utils
 import ImgManip
-from intl import gettext
-_ = gettext
-
+from intl import gettext as _
 
 #-------------------------------------------------------------------------
 #
@@ -55,7 +53,7 @@ def import_media_object(filename,path,base):
     import shutil
 
     if not os.path.exists(filename):
-        GnomeErrorDialog(_("Could not import %s\nThe file has been moved or deleted") % filename)
+        ErrorDialog(_("Could not import %s\nThe file has been moved or deleted") % filename)
         return ""
 
     ext = os.path.splitext(filename)[1]
@@ -71,23 +69,23 @@ def import_media_object(filename,path,base):
             if not os.path.exists(thumb):
                 os.mkdir(thumb)
         except IOError,msg:
-            GnomeErrorDialog(_("Could not create %s") % thumb + "\n" + str(msg))
+            ErrorDialog(_("Could not create %s") % thumb + "\n" + str(msg))
             return ""
         except:
-            GnomeErrorDialog(_("Could not create %s") % thumb)
+            ErrorDialog(_("Could not create %s") % thumb)
             return ""
         
         try:
             path = "%s/%s.jpg" % (thumb,base)
             mk_thumb(filename,path,const.thumbScale)
         except:
-            GnomeErrorDialog(_("Error creating the thumbnail : %s"))
+            ErrorDialog(_("Error creating the thumbnail : %s"))
             return ""
 
         try:
             shutil.copy(filename,name)
         except IOError,msg:
-            GnomeErrorDialog(_("Error copying %s") % filename + "\n" + msg)
+            ErrorDialog(_("Error copying %s") % filename + "\n" + msg)
             return ""
 
     else:
@@ -136,10 +134,10 @@ def mk_thumb(source,dest,size):
         if not os.path.exists(dir):
             os.mkdir(dir)
     except IOError,msg:
-        GnomeErrorDialog(_("Could not create %s") % dir + "\n" + str(msg))
+        ErrorDialog(_("Could not create %s") % dir + "\n" + str(msg))
         return
     except:
-        GnomeErrorDialog(_("Could not create %s") % dir)
+        ErrorDialog(_("Could not create %s") % dir)
         return
 
     if os.path.exists(dest):
@@ -147,11 +145,11 @@ def mk_thumb(source,dest,size):
             os.remove(dest)
         except IOError,msg:
             errmsg = _("Could not replace %s") % dir
-            GnomeErrorDialog(errmsg + "\n" + msg)
+            ErrorDialog(errmsg + "\n" + msg)
             return
 
     if not os.path.exists(source):
-        GnomeErrorDialog(_("Could not create a thumbnail for %s\nThe file has been moved or deleted") % source)
+        ErrorDialog(_("Could not create a thumbnail for %s\nThe file has been moved or deleted") % source)
 
     try:
         img = ImgManip.ImgManip(source)
@@ -159,7 +157,7 @@ def mk_thumb(source,dest,size):
     except:
         import sys
         msg = "%s\n%s %s" % (source,sys.exc_type,sys.exc_value)
-        GnomeErrorDialog(_("Could not create a thumbnail for %s") % msg)
+        ErrorDialog(_("Could not create a thumbnail for %s") % msg)
         return
 
 #-------------------------------------------------------------------------
diff --git a/src/RelLib.py b/src/RelLib.py
index 29c953498..f2d5eafe7 100644
--- a/src/RelLib.py
+++ b/src/RelLib.py
@@ -1890,35 +1890,50 @@ class GrampsDB(Persistent):
         self.placeTable[nkey] = self.placeMap[nkey].getDisplayInfo()
         
     def set_iprefix(self,val):
-        if _id_reg.search(val):
-            self.iprefix = val
+        if val:
+            if _id_reg.search(val):
+                self.iprefix = val
+            else:
+                self.iprefix = val + "%d"
         else:
-            self.iprefix = val + "%d"
-
+            self.iprefix = "I%d"
+            
     def set_sprefix(self,val):
-        if _id_reg.search(val):
-            self.sprefix = val
+        if val:
+            if _id_reg.search(val):
+                self.sprefix = val
+            else:
+                self.sprefix = val + "%d"
         else:
-            self.sprefix = val + "%d"
-
+            self.sprefix = "S%d"
+            
     def set_oprefix(self,val):
-        if _id_reg.search(val):
-            self.oprefix = val
+        if val:
+            if _id_reg.search(val):
+                self.oprefix = val
+            else:
+                self.oprefix = val + "%d"
         else:
-            self.oprefix = val + "%d"
+            self.oprefix = "O%d"
 
     def set_pprefix(self,val):
-        if _id_reg.search(val):
-            self.pprefix = val
+        if val:
+            if _id_reg.search(val):
+                self.pprefix = val
+            else:
+                self.pprefix = val + "%d"
         else:
-            self.pprefix = val + "%d"
+            self.pprefix = "P%d"
 
     def set_fprefix(self,val):
-        if _id_reg.search(val):
-            self.fprefix = val
+        if val:
+            if _id_reg.search(val):
+                self.fprefix = val
+            else:
+                self.fprefix = val + "%d"
         else:
-            self.fprefix = val + "%d"
-
+            self.fprefix = "F%d"
+            
     def new(self):
         """initializes the GrampsDB to empty values"""
 
diff --git a/src/Report.py b/src/Report.py
index ffc713277..d6e5898ff 100644
--- a/src/Report.py
+++ b/src/Report.py
@@ -58,6 +58,8 @@ import latin_utf8
 u2l = latin_utf8.utf8_to_latin
 _ = intl.gettext
 
+from QuesionDialog import  ErrorDialog
+
 #-------------------------------------------------------------------------
 #
 # Import XML libraries
@@ -813,7 +815,7 @@ class ReportDialog:
             return None
 
         if not self.get_target_is_directory() and os.path.isdir(self.target_path):
-            gnome.ui.GnomeErrorDialog(_("The filename that you gave is a directory.\n"
+            GnomeErrorDialog(_("The filename that you gave is a directory.\n"
                                "You need to provide a valid filename."))
             return None
         
@@ -942,7 +944,7 @@ class ReportDialog:
             try:
                 self.make_report()
             except (IOError,OSError),msg:
-                gnome.ui.GnomeErrorDialog(str(msg))
+                ErrorDialog(str(msg))
 
             # Clean up the dialog object
             self.window.destroy()
diff --git a/src/WriteXML.py b/src/WriteXML.py
index 8089aa8c9..3560c6409 100644
--- a/src/WriteXML.py
+++ b/src/WriteXML.py
@@ -41,8 +41,8 @@ import const
 import GrampsCfg
 from RelLib import *
 from Date import SingleDate
-from intl import gettext
-_ = gettext
+from intl import gettext as _
+from QuestionDialog import ErrorDialog
 
 #-------------------------------------------------------------------------
 #
@@ -71,11 +71,10 @@ def exportData(database, filename, callback):
         g = XmlWriter(database,callback,0,compress)
         g.write(filename)
     except:
-        from gnome.ui import GnomeErrorDialog
         import DisplayTrace
 
         DisplayTrace.DisplayTrace()
-        GnomeErrorDialog(_("Failure writing %s, original file restored") % filename)
+        ErrorDialog(_("Failure writing %s, original file restored") % filename)
         shutil.copy(filename + ".bak", filename)
 
 #-------------------------------------------------------------------------
diff --git a/src/gramps_main.py b/src/gramps_main.py
index 062ba7510..e96cf00c3 100755
--- a/src/gramps_main.py
+++ b/src/gramps_main.py
@@ -56,7 +56,7 @@ from SourceView import SourceView
 from MediaView import MediaView
 from FamilyView import FamilyView
 
-from QuestionDialog import QuestionDialog
+from QuestionDialog import QuestionDialog, ErrorDialog
 
 import DisplayTrace
 import Filter
@@ -350,7 +350,7 @@ class Gramps:
         elif cpage == 3:
             self.source_view.on_add_clicked(obj)
         elif cpage == 4:
-            self.place_view.on_add_clicked(obj)
+            self.place_view.on_add_place_clicked(obj)
 
     def remove_button_clicked(self,obj):
         cpage = self.notebook.get_current_page()
@@ -475,7 +475,7 @@ class Gramps:
         if page == 0:
             if len(self.person_list.selection) != 2:
                 msg = _("Exactly two people must be selected to perform a merge")
-                gnome.ui.GnomeErrorDialog(msg)
+                ErrorDialog(msg)
             else:
                 import MergeData
                 p1 = self.person_list.get_row_data(self.person_list.selection[0])
@@ -897,10 +897,10 @@ class Gramps:
                 os.mkdir(filename)
             except (OSError,IOError), msg:
                 emsg = _("Could not create %s") % filename + "\n" + str(msg)
-                gnome.ui.GnomeErrorDialog(emsg)
+                ErrorDialog(emsg)
                 return
             except:
-                gnome.ui.GnomeErrorDialog(_("Could not create %s") % filename)
+                ErrorDialog(_("Could not create %s") % filename)
                 return
         
         old_file = filename
@@ -909,7 +909,7 @@ class Gramps:
             self.db.save(filename,self.load_progress)
         except (OSError,IOError), msg:
             emsg = _("Could not create %s") % filename + "\n" + str(msg)
-            gnome.ui.GnomeErrorDialog(emsg)
+            ErrorDialog(emsg)
             return
 
         self.db.setSavePath(old_file)
@@ -1526,7 +1526,7 @@ class Gramps:
                                              self.bookmark_callback)
 
     def displayError(self,msg):
-        gnome.ui.GnomeErrorDialog(msg)
+        ErrorDialog(msg)
         self.statusbar.set_status("")
 
     def apply_filter(self):
@@ -1555,7 +1555,7 @@ class Gramps:
             self.change_active_person(temp)
             self.update_display(0)
         else:
-            gnome.ui.GnomeErrorDialog(_("No default/home person has been set"))
+            ErrorDialog(_("No default/home person has been set"))
 
     def on_add_bookmark_activate(self,obj):
         if self.active_person: