Commits

Alain Leufroy  committed 5f0dfa0

[gui.qt] mainwindow: populate sheet

  • Participants
  • Parent commits 568ec05

Comments (0)

Files changed (3)

File ui/gui/qt/elements.py

 
     __ui__ = 'subprocessbox'
 
-    def __init__(self, title, text, *ags, **kws):
+    def __init__(self, title='', text='', *ags, **kws):
         """
         :title: label of the text box
         :text: content text of the box
 
     __ui__ = 'subprocessbox'
 
+    def __init__(self, *ags, **kws):
+        super(TextBox, self).__init__(*ags, **kws)
+        self._ui.edit.textChanged.connect(partial(self.edited.emit, self))
+
     def setupUi(self, *ags, **kws):
         super(TextBox, self).setupUi(*ags, **kws)
         self._ui.edit.setReadOnly(False)

File ui/gui/qt/qt_ui.py

 from limma.ui.gui.qt.mainwindow import MainWindow
 from limma.ui.gui.qt.booktree import BookTree
 from limma.ui.gui.qt.sheet import Sheet
+from limma.ui.gui.qt.item import Item
+from limma.elements import elements
+from limma.ui.gui.qt import elements as ui_elements
 
 BOOKNAMEROLE = QtCore.Qt.StatusTipRole # role used to store the book name
 
+ELT_UIS = {
+    elements.TextInput: ui_elements.TextInputBox,
+    elements.PathBox: ui_elements.PathBox,
+    elements.SubprocessBox: ui_elements.SubprocessBox,
+    elements.TextBox: ui_elements.TextBox,
+    }
+
 class QtUI(AbstractUI):
     """UI controller that synchronize data and the Qt UI"""
 
     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)
+        ui_sheet = Sheet(title=self._sheet.title, parent=self._ui)
+        self._ui.set_sheet(ui_sheet)
+        for item in self._sheet.items:
+            ui_item = Item(title=item.title, parent=ui_sheet)
+            ui_sheet.append(ui_item)
+            ui_item.edited.connect(self._on_element_edited)
+            for element in item.elements:
+                ui_type = ELT_UIS[type(element)]
+                ui_element = ui_type(title=element.title, parent=ui_item)
+                ui_item.append(ui_element)
 
     def _on_book_removed(self, item):
         """handle removed book item requested by user"""
-        book_name = item.data(BOOKNAMEROLE).toPyObject()
+        book_name = item.data(BOOKNAMEROLE).toPoyObject()
         self._book_tree.delete_book_from_name(book_name)
 
     def _on_book_edited(self, item):
         book = self._book_tree.get_book_from_name(book_name)
         self._sheet = book.sheet
         self._setup_ui_sheet()
+
+    def _on_element_edited(self, ui_element):
+        """handle edited element requested by user"""
+        print 'element edited: %r' % ui_element

File ui/gui/qt/sheet.py

         self._ui.label.setText(unicode(title or ''))
         self._setup_actions()
 
-
     def _setup_actions(self):
         """implement the user actions"""
         self._menu = QtGui.QMenu(self)
         widget.hide() # ensure the widget is no more visible
         widget.deleted.disconnect()
         del widget # finally delete the widget
-
-# used for tests
-if __name__ == '__main__':
-    import sys
-    from limma.ui.gui.qt.mainwindow import MainWindow
-    from limma.ui.gui.qt.item import Item
-    app = QtGui.QApplication(sys.argv)
-    main_window = MainWindow()
-    sheet = Sheet(main_window)
-    item0 = Item(sheet)
-    item1 = Item(sheet)
-    item2 = Item(sheet)
-    sheet.append(item1)
-    sheet.insert(0, item0)
-    sheet.append(item2)
-    main_window.setCentralWidget(sheet)
-    main_window.show()
-
-    assert sheet[0] == item0
-    assert sheet[1] == item1
-    assert sheet[2] == item2
-
-    sys.exit(app.exec_())
-