Georg Brandl avatar Georg Brandl committed 15a98bc

gui: generate data description in panel

Comments (0)

Files changed (2)

ufit/gui/datalist.py

             return QVariant()
         nr = index.row()
         if role == Qt.DisplayRole:
-            return QVariant(self.panels[nr][0])
+            return QVariant(self.panels[nr].as_html())
         elif role == Qt.TextAlignmentRole:
             return QVariant(int(Qt.AlignLeft|Qt.AlignVCenter))
         return QVariant()
         self.model = model or self.mbuilder.default_model(data)
         self._limits = None
         self.picker_widget = None
+        self.index = 0
 
         self.canvas = canvas
         self.dataops.initialize(self.data)
         self.addTab(self.mbuilder, 'Modeling')
         self.addTab(self.fitter, 'Fitting')
 
+    def as_html(self):
+        return '<big><b>%s</b></big> - %s<br>%s<br><small>%s</small>' % \
+            (self.index,
+             self.data.meta.get('title', ''),
+             ', '.join(self.data.environment),
+             '<br>'.join(self.data.sources))
+
     def on_mbuilder_newModel(self, model):
         self.model = model
         self.fitter.initialize(self.model, self.data, fit=False)
         self.pristine = True  # nothing loaded so far
         self.filename = None
         self.sgroup = SettingGroup('main')
+        self.max_index = 1
 
         loadUi(self, 'main.ui')
 
                                 'OK to remove %d dataset(s)?' % len(indlist),
                                 QMessageBox.Yes|QMessageBox.No) == QMessageBox.No:
             return
-        new_panels = [p for i, p in enumerate(self.panels)
-                      if i not in indlist]
+        new_panels = [p for i, p in enumerate(self.panels) if i not in indlist]
         self.panels[:] = new_panels
         self.datalistmodel.reset()
         self.on_loadBtn_clicked()
         if len(indlist) == 0:
             self.on_loadBtn_clicked()
         elif len(indlist) == 1:
-            panel = self.panels[indlist[0]][1]
+            panel = self.panels[indlist[0]]
             self.select_new_panel(panel)
             panel.replot(panel._limits)
             self.toolbar.update()
         else:
-            panels = [self.panels[i][1] for i in indlist]
+            panels = [self.panels[i] for i in indlist]
             self.canvas.plotter.reset()
+            self.isModal()
             # XXX this doesn't belong here
             for p in panels:
                 c = self.canvas.plotter.plot_data(p.data, multi=True)
 
     def handle_new_data(self, data, update=True, model=None):
         panel = DatasetPanel(self, self.canvas, data, model)
+        panel.index = self.max_index
+        self.max_index += 1
         self.stacker.addWidget(panel)
         self.stacker.setCurrentWidget(panel)
-        # XXX generate HTML in panel itself
-        # XXX numbering is meaningless
-        self.panels.append(
-            ('<big><b>%s</b></big> - %s<br>%s<br><small>%s</small>' %
-             (len(self.panels) + 1,
-              data.meta.get('title', ''),
-              ', '.join(data.environment),
-              '<br>'.join(data.sources)), panel))
+        self.panels.append(panel)
         self.pristine = False
         if not self._loading and update:
             self.datalistmodel.reset()
 
     def load_session(self, filename):
         for panel in self.panels[1:]:
-            self.stacker.removeWidget(panel[1])
+            self.stacker.removeWidget(panel)
         del self.panels[1:]
         info = pickle.load(open(filename, 'rb'))
         self._loading = True
     def save_session_inner(self, filename):
         fp = open(filename, 'wb')
         info = {
-            'panels': [(panel[1].data, panel[1].model) for panel in self.panels]
+            'panels': [(panel.data, panel.model) for panel in self.panels]
         }
         pickle.dump(info, fp, protocol=pickle.HIGHEST_PROTOCOL)
 
         loadUi(dlg, 'rebin.ui')
         if dlg.exec_():
             precision = dlg.precision.value()
-            datalist = [p[1].data for i, p in enumerate(self.panels)
+            datalist = [p.data for i, p in enumerate(self.panels)
                         if i in indlist]
             new_data = datalist[0].merge(precision, *datalist[1:])
             self.handle_new_data(new_data)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.