[pybliographer/gtk3: 17/25] editor: Port entry type change in editor to Gtk3



commit f0411f605fdbc4771d30ea1ff0053aeed3ed12c7
Author: Germán Poo-Caamaño <gpoo gnome org>
Date:   Wed Jul 17 19:26:33 2013 -0700

    editor: Port entry type change in editor to Gtk3

 Pyblio/GnomeUI/Compat.py |   13 ++++++++++++-
 Pyblio/GnomeUI/Editor.py |   32 ++++++++++++++++++++++++--------
 2 files changed, 36 insertions(+), 9 deletions(-)
---
diff --git a/Pyblio/GnomeUI/Compat.py b/Pyblio/GnomeUI/Compat.py
index 1257567..5a113a4 100644
--- a/Pyblio/GnomeUI/Compat.py
+++ b/Pyblio/GnomeUI/Compat.py
@@ -25,6 +25,8 @@ Compatability module
 
 
 """
+from gettext import gettext as _
+from gi.repository import Gtk
 
 # gnome-python (2.x)
 #try:
@@ -33,7 +35,16 @@ Compatability module
 #    from gnome.ui import error_dialog_parented as gnome_error_dialog_parented
 #
 #error_dialog_parented = gnome_error_dialog_parented
-error_dialog_parented = str
+# error_dialog_parented = str
+
+class error_dialog_parented(Gtk.Dialog):
+    def __init__(self, message, parent):
+        Gtk.Dialog.__init__(self, _("Error"), parent, 0,
+                            (Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE))
+        label = Gtk.Label(message)
+        box = self.get_content_area()
+        box.add(label)
+        self.show_all()
 
 
 # gnome-python (2.x)
diff --git a/Pyblio/GnomeUI/Editor.py b/Pyblio/GnomeUI/Editor.py
index 695517a..5413250 100644
--- a/Pyblio/GnomeUI/Editor.py
+++ b/Pyblio/GnomeUI/Editor.py
@@ -635,14 +635,28 @@ class RealEditor (Connector.Publisher):
 
     def menu_select (self, menu):
         idx   = menu.get_active_iter ()
-        entry = menu.get_model ().get_value (idx, 1)
+        if idx is None:
+            return
+
+        entry = menu.get_model().get_value (idx, 1)
         
         # update the current entry
         new = self.update (self.database, copy.deepcopy (self.entry))
         if new is None:
             entry_list = Config.get ("base/entries").data.values ()
             entry_list.sort (lambda x, y: cmp (x.name, y.name))
-            self.menu.set_history (entry_list.index (self.entry.type))
+            
+            liststore = self.menu.get_model()
+            liststore.clear()
+
+            i = 0
+            history = 0
+            for entry in entry_list:
+                if entry == self.entry.type: history = i
+                liststore.append ((entry.name, entry))
+                i = i + 1
+
+            self.menu.set_model(liststore)
             return
         else:
             new.type = entry
@@ -725,8 +739,9 @@ class RealEditor (Connector.Publisher):
     def update_notebook (self):
 
         if self.notebook_init:
-            self.notebook.foreach(
-                lambda x: self.notebook.remove_page(0))
+            # FIXMEgpoo: Check for secondary effects
+            f = lambda x, y: self.notebook.remove_page(0)
+            self.notebook.foreach(f, None)
         
         self.notebook_init = True
         self.current_page = None
@@ -932,14 +947,15 @@ class RealEditor (Connector.Publisher):
         for item in self.content:
             try:
                 result = item.update(self.entry)
-                
             except UnicodeError:
+                # FIXMEgpoo: check enconding handling
                 f = Types.get_field(item.field)
-                
-                Compat.error_dialog_parented(
+                d = Compat.error_dialog_parented(
                     _("The `%s' field contains a non Latin-1 symbol") %
                     f.name, self.w.get_toplevel())
-                return None
+                d.run()
+                d.destroy()
+                result = -1
             
             if result == -1: return None
             


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]