some improvements; can now give a bunch of files to open on cmd line; removed print statements

Mon, 04 Feb 2008 19:02:42 +0100

author
David Douard <david.douard@logilab.fr>
date
Mon, 04 Feb 2008 19:02:42 +0100
changeset 36
cb4124e3e75b
parent 35
3b7a38af5c42
child 37
e0790756059d

some improvements; can now give a bunch of files to open on cmd line; removed print statements

plotter/hpgl_qt.py file | annotate | diff | comparison | revisions
plotter/qgpib_plotter.py file | annotate | diff | comparison | revisions
plotter/qpreferences.py file | annotate | diff | comparison | revisions
tools.py file | annotate | diff | comparison | revisions
--- a/plotter/hpgl_qt.py	Sun Feb 03 23:39:27 2008 +0100
+++ b/plotter/hpgl_qt.py	Mon Feb 04 19:02:42 2008 +0100
@@ -116,7 +116,7 @@
         self.qscene.removeItem(t0)
         # don't ask me why theses constants are here, they seem OK, that's all
         t = self.qscene.addSimpleText(s, self.qfont)
-        t.scale(1.5 * cw/mw, -2.0 * ch/mh)
+        t.scale(1.1 * cw/mw, -1.6 * ch/mh)
         x, y = self.pos
         t.moveBy(x,y)
         br = t.boundingRect()
--- a/plotter/qgpib_plotter.py	Sun Feb 03 23:39:27 2008 +0100
+++ b/plotter/qgpib_plotter.py	Mon Feb 04 19:02:42 2008 +0100
@@ -2,6 +2,7 @@
 
 import os, sys
 import time
+import glob
 
 from PyQt4 import QtGui, QtCore, uic
 from PyQt4.QtCore import SIGNAL, Qt
@@ -22,6 +23,8 @@
 from qpreferences import AbstractPreferences
 from qpreferenceseditor import PreferencesEditor
 
+from tools import str_num_cmp
+
 class Preferences(AbstractPreferences):
     ORGANISATION="Logilab"
     APPLICATION="qgpib_plotter"
@@ -86,7 +89,6 @@
         if bg and bg.isValid():
             self.plotterWidget.qview.setBackgroundBrush(QtGui.QBrush(bg))
         pen_colors = [self._prefs["color%d"%i] for i in range(8)]
-        print 
         self.plotterWidget.pen_colors = pen_colors
         
     def replotCurrent(self):
@@ -150,6 +152,11 @@
         
     def openTriggered(self, checked=False):
         filenames = QtGui.QFileDialog.getOpenFileNames(self, "Open a HPGL file to display", '.', 'HPGL files (*.plt)\nAll files (*)')
+        self.openFiles(filenames)
+        if not self.plotsView.currentIndex().isValid():
+            self.plotsView.setCurrentIndex(self.plotsView.model().index(0, 0))
+
+    def openFiles(self, filenames):
         for filename in filenames:
             filename = str(filename)
             if os.path.exists(filename):
@@ -160,10 +167,7 @@
                 lst.append(name)            
                 self._plots[name] = data
                 self.plotsView.model().setStringList(lst)
-
-        if not self.plotsView.currentIndex().isValid():
-            self.plotsView.setCurrentIndex(self.plotsView.model().index(0, 0))
-
+        
     def plotReceived(self, num):
         self._receiving = False
         self.setReceivingLed()
@@ -180,6 +184,7 @@
         
     def saveTriggered(self, checked=False):
         print "save"
+        
     def saveAsTriggered(self, checked=False):
         index = self.plotsView.selectionModel().currentIndex()
         if index.isValid():
@@ -306,9 +311,6 @@
             return self._plots[num]
         finally:
             self._plotsmutex.unlock()
-            
-        
-            
 
 def main():
     import optparse
@@ -330,6 +332,9 @@
 
     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)
     w.show()
     a.exec_()
         
--- a/plotter/qpreferences.py	Sun Feb 03 23:39:27 2008 +0100
+++ b/plotter/qpreferences.py	Mon Feb 04 19:02:42 2008 +0100
@@ -111,7 +111,6 @@
             if isinstance(item, BaseItem):
                 keys.append((k,item))
         keys.sort(key=lambda x: x[1]._id)
-        print [x[1]._id for x in keys]
         for k, item in keys:
             self._prefs[item._id] = k
             if item._group not in self.groups:
--- a/tools.py	Sun Feb 03 23:39:27 2008 +0100
+++ b/tools.py	Mon Feb 04 19:02:42 2008 +0100
@@ -1,3 +1,22 @@
+#
+"""
+Helper functions and classes
+"""
+import re
+
+def str_num_cmp(s1,s2):
+    """
+    string comparator function that will put 'toto_10' after 'toto_2'
+    Also works for strings like 'toto_1_et_23er25'.
+    """
+    r = re.compile(r'((?<=\d)\D+|(?<=\D)\d+)')
+    r1= r.split(s1)
+    r2= r.split(s2)
+    r1=[not x.isdigit() and x or int(x) for x in r1 if x!='']
+    r2=[not x.isdigit() and x or int(x) for x in r2 if x!='']
+    return cmp(r1,r2)
+
+
 class AbstractRegister(object):
     _instance = None
     _registered_type = None

mercurial