small improvement; display first plot at startup

Mon, 04 Feb 2008 19:19:57 +0100

author
David Douard <david.douard@logilab.fr>
date
Mon, 04 Feb 2008 19:19:57 +0100
changeset 38
73bd2fe81005
parent 37
e0790756059d
child 39
8becd52c2171

small improvement; display first plot at startup

plotter/qgpib_plotter.py file | annotate | diff | comparison | revisions
--- a/plotter/qgpib_plotter.py	Mon Feb 04 19:19:32 2008 +0100
+++ b/plotter/qgpib_plotter.py	Mon Feb 04 19:19:57 2008 +0100
@@ -153,10 +153,14 @@
     def openTriggered(self, checked=False):
         filenames = QtGui.QFileDialog.getOpenFileNames(self, "Open a HPGL file to display", '.', 'HPGL files (*.plt)\nAll files (*)')
         self.openFiles(filenames)
+        self.displayFirst()
+        
+    def displayFirst(self):
         if not self.plotsView.currentIndex().isValid():
             self.plotsView.setCurrentIndex(self.plotsView.model().index(0, 0))
-
+        
     def openFiles(self, filenames):
+        ok = False
         for filename in filenames:
             filename = str(filename)
             if os.path.exists(filename):
@@ -167,6 +171,8 @@
                 lst.append(name)            
                 self._plots[name] = data
                 self.plotsView.model().setStringList(lst)
+                ok = True
+        return ok
         
     def plotReceived(self, num):
         self._receiving = False
@@ -327,14 +333,13 @@
     
     options, argv = opt.parse_args(sys.argv)
 
-    if options.verbose:
-        sys.stderr.write('connection established\n')
-
     a = QtGui.QApplication(argv)
     w = QtHPGLPlotter()
     files = [f for f in argv[1:] if os.path.isfile(f)]
     files.sort(cmp=str_num_cmp)
-    w.openFiles(files)
+    if w.openFiles(files):    
+        w.displayFirst()
+
     w.show()
     a.exec_()
         

mercurial