Commits

Alain Leufroy committed e5d8054

[gui.qt] controller: fix add/retitle book (related #625952)
:retitle: fix when new title already exists
:add: if the focus is loosed the entry exists but the book is not yet created => immediatly create the book
:add: display the sheet on creation

  • Participants
  • Parent commits bed77a0

Comments (0)

Files changed (3)

File ui/gui/qt/booktree.py

         The ``selected`` signal is emitted at the end of the process.
         """
         item = QtGui.QListWidgetItem(title)
+        self._ui.books.addItem(item) # here to prevent emmiting signal
         item.setFlags(QtCore.Qt.ItemIsEnabled |
                       QtCore.Qt.ItemIsSelectable |
                       QtCore.Qt.ItemIsEditable)
-        self._ui.books.addItem(item) # here to prevent emmiting signal
         return item
 
     def select(self, index):

File ui/gui/qt/mainwindow.py

         item = self._ui.sheet.itemAt(0)
         if item:
             self._ui.sheet.removeItem(item)
+            del item
         self._ui.sheet.addWidget(widget)
         self._ui.menu_sheet.clear()
         widget.setup_actions(self._ui.menu_sheet)

File ui/gui/qt/qt_ui.py

     def __init__(self, conf):
         AbstractUI.__init__(self, conf)
         self._ui = None
-        self._ui_sheet = None
+        self._sheet = None
         self.logger = get_module_logger()
         self._book_tree = Structure(conf).book_tree
 
         """handle edited book requested by user."""
         book_name = item.data(BOOKNAMEROLE).toPyObject()
         title = unicode(item.text())
-        if book_name is None: # if not yet exists => add
-            try:
+        try:
+            if book_name is None: # if not yet exists => add
                 book = self._book_tree.add_book(title)
                 item.setData(BOOKNAMEROLE, unicode(book.name))
-            except ValueError, err: # occures on name already exists
-                self.logger.warning(unicode(err))
-                 # loop: auto emit a signal indicating about book edited
-                item.setText(title + DUPLICATENAMESUFFIX)
-        else:
-            # retitle tolerate no change
-            self._book_tree.retitle_book_from_name(book_name, title)
+                self._on_book_selected(item)
+            else:
+                # retitle tolerate no change
+                self._book_tree.retitle_book_from_name(book_name, title)
+        except ValueError, err: # occures on name already exists
+            self.logger.warning(unicode(err))
+             # loop: auto emit a signal indicating about book edited
+            item.setText(title + DUPLICATENAMESUFFIX)
 
     def _on_book_selected(self, item):
         """handle selected book requested by user"""