Commits

Alain Leufroy committed e805e89

[gui.qt] mainwindow: put selected sheet on the left

  • Participants
  • Parent commits 873e23f

Comments (0)

Files changed (3)

structure/book_tree.py

                 for index, book in enumerate(self.books)
                 if book.name == book_name).next()
 
+    def get_book_from_name(self, book_name):
+        """Return the book named ``book_name``."""
+        return self.books[self._book_index_from_name(book_name)]
+
     def delete_book(self, i_book):
         book = self.books[i_book]
         book.remove_data()

ui/gui/qt/mainwindow.py

 class MainWindow(UiFromDesigner, QtGui.QMainWindow):
     """Main Window of the Qt interface."""
     __ui__ = 'mainwindow'
-    __slots__ = ['booktree', 'sheet']
 
     def set_booktree(self, widget):
         """set the book widget"""
             self._ui.booktree.removeItem(item)
         self._ui.booktree.addWidget(widget)
 
-    def get_booktree(self):
-        """Return the book tree ui."""
-        return self._ui.booktree.itemAt(0)
-
-    booktree = property(get_booktree, set_booktree, None,
-                        "The book tree widget that contains books")
+    def set_sheet(self, widget):
+        """set the book widget"""
+        item = self._ui.sheet.itemAt(0)
+        if item:
+            self._ui.sheet.removeItem(item)
+        self._ui.sheet.addWidget(widget)

ui/gui/qt/qt_ui.py

 from limma.ui.ui import AbstractUI
 from limma.ui.gui.qt.mainwindow import MainWindow
 from limma.ui.gui.qt.booktree import BookTree
+from limma.ui.gui.qt.sheet import Sheet
 
 BOOKNAMEROLE = QtCore.Qt.StatusTipRole # role used to store the book name
 
 
     def __init__(self, conf):
         AbstractUI.__init__(self, conf)
-        self._struct = Structure(conf)
+        self._ui = None
+        self._sheet = None
+        self._book_tree = Structure(conf).book_tree
 
     def loop(self):
         """Start the main loop."""
 
     def setup_ui(self, mainwindow):
         """setup the uiser interface."""
-        booktree = BookTree()
-        mainwindow.booktree = booktree
-        self._setup_ui_booktree(booktree)
+        self._ui = mainwindow
+        self._setup_ui_booktree()
 
-    def _setup_ui_booktree(self, booktree):
+    def _setup_ui_booktree(self):
         """Setup the booktree of the user interface."""
         # populate the book tree
-        if self._struct.book_tree.books:
-            for book in self._struct.book_tree.books:
+        booktree = BookTree(parent=self._ui)
+        self._ui.set_booktree(booktree)
+        if self._book_tree.books:
+            for book in self._book_tree.books:
                 item = booktree.add(book.title)
                 item.setData(BOOKNAMEROLE, unicode(book.name))
-            booktree.select(0)
         # handle deletion
         booktree.removed.connect(self._on_book_removed)
         # handle edition
         booktree.edited.connect(self._on_book_edited)
+        # handle selection
+        booktree.selected.connect(self._on_book_selected)
+        # shoud stay after selected connected
+        booktree.select(0)
+
+    def _setup_ui_sheet(self):
+        """Setup the sheet of the user interface."""
+        assert self._sheet is not None
+        sheet = Sheet(title=self._sheet.title, parent=self._ui)
+        self._ui.set_sheet(sheet)
 
     def _on_book_removed(self, item):
         """handle removed book item requested by user"""
         book_name = item.data(BOOKNAMEROLE).toPyObject()
-        self._struct.book_tree.delete_book_from_name(book_name)
+        self._book_tree.delete_book_from_name(book_name)
 
     def _on_book_edited(self, item):
         """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
-            book = self._struct.book_tree.add_book(title)
+            book = self._book_tree.add_book(title)
             item.setData(BOOKNAMEROLE, unicode(book.name))
         else:
             # retitle tolerate no change
-            self._struct.book_tree.retitle_book_from_name(book_name, title)
+            self._book_tree.retitle_book_from_name(book_name, title)
+
+    def _on_book_selected(self, item):
+        """handle selected book requested by user"""
+        book_name = item.data(BOOKNAMEROLE).toPyObject()
+        assert book_name is not None
+        book = self._book_tree.get_book_from_name(book_name)
+        self._sheet = book.sheet
+        self._setup_ui_sheet()