Read filenames as plain arguments
authorDmitriy Morozov <dmitriy@mrzv.org>
Thu, 17 Mar 2011 22:18:46 -0700
changeset 8 2eaa2bffa6f4
parent 7 cbb51ef4dd6d
child 9 a500b28a675d
Read filenames as plain arguments
VEFViewer.py
--- a/VEFViewer.py	Sun Mar 06 13:21:48 2011 -0800
+++ b/VEFViewer.py	Thu Mar 17 22:18:46 2011 -0700
@@ -2,6 +2,8 @@
 
 import  ui_PyVEFViewer  as ui
 from    opster          import command, dispatch
+from    sys             import exit
+from    os.path         import splitext; ext = lambda fn: splitext(fn)[1]
 
 class VEFViewerWindow(ui.QtGui.QWidget):
     def __init__(self, parent = None):
@@ -10,11 +12,28 @@
         self.ui = ui.Ui_MainWindow()
         self.ui.setupUi(self)
 
-@command(usage = '%name [options]')
-def main(points     = ('p', [], 'files with points'),       # TODO: add completer for filenames
-         edges      = ('e', [], 'files with edges'),
-         triangles  = ('t', [], 'files with triangles')):
+@command(usage = '%name [options]',
+         options = [('p', 'points',    [], 'files with points'),       # TODO: add completer for filenames
+                    ('e', 'edges',     [], 'files with edges'),
+                    ('t', 'triangles', [], 'files with triangles')])
+def main(*args, **opts):
     
+    points    = opts['points']
+    edges     = opts['edges']
+    triangles = opts['triangles']
+
+    # Guess types from extensions
+    for fn in args:
+        if   ext(fn) == '.vrt' or ext(fn) == '.pts':
+            points.append(fn)
+        elif ext(fn) == '.edg':
+            edges.append(fn)
+        elif ext(fn) == '.stl':
+            triangles.append(fn)
+        else:
+            print "Cannot guess type from extension:", fn
+            exit(1)
+
     qapp = ui.QtGui.QApplication([])
     win  = VEFViewerWindow()
     win.show()