[Yt-svn] yt-commit r576 - in trunk/yt: fido reason

mturk at wrangler.dreamhost.com mturk at wrangler.dreamhost.com
Thu Jun 19 13:56:56 PDT 2008


Author: mturk
Date: Thu Jun 19 13:56:55 2008
New Revision: 576
URL: http://yt.spacepope.org/changeset/576

Log:
Added support for importing directories (which will be functionally identical
to running fimport) within the GUI.  Might be a bit buggy.  You can also delete
existing stored output lists.

This *should* close #101, but I want to test it a bit first before closing.



Modified:
   trunk/yt/fido/OutputCollection.py
   trunk/yt/fido/RunStandalones.py
   trunk/yt/reason/App.py

Modified: trunk/yt/fido/OutputCollection.py
==============================================================================
--- trunk/yt/fido/OutputCollection.py	(original)
+++ trunk/yt/fido/OutputCollection.py	Thu Jun 19 13:56:55 2008
@@ -39,6 +39,7 @@
         self.output_times = na.array((), dtype='float64')
 
     def read_in(self, filename):
+        self._last_read_filename = filename
         lines = open(filename).readlines()
         output_lines = [line for line in lines if line.startswith("Output:")]
         outputs = [line.split(":")[1] for line in output_lines]
@@ -70,6 +71,7 @@
     def add_output(self, filename):
         # We're passing in *just* filenames here.  So, we simply snag the
         # two appropriate lines in the parameter file.
+        if filename in self.output_names: return
         time = get_parameter_line(filename, "InitialTime").split()[-1]
         # Implement exception catching
         try:

Modified: trunk/yt/fido/RunStandalones.py
==============================================================================
--- trunk/yt/fido/RunStandalones.py	(original)
+++ trunk/yt/fido/RunStandalones.py	Thu Jun 19 13:56:55 2008
@@ -173,21 +173,27 @@
 
 class Import(FidoAction):
     description = "Import an existing set of buried outputs"
-    def __init__(self):
+    _matches = ["*.dir/*.hierarchy", "*Dir/*.hierarchy", "RD*/*.hierarchy",
+                "DD*/*.hierarchy", "moving*/*.hierarchy", "star*/*.hierarchy",
+                "*.hierarchy"]
+    def __init__(self, current_path = None, title = None):
+        if current_path is None: current_path = os.getcwd()
+        self.current_path = current_path
         FidoAction.__init__(self)
         self._parse_args()
         self._guess_collection()
-        self.title = os.path.basename(os.getcwd())
-        if self.oc != None: self.title = self.oc.title
-        else: self.oc=OutputCollection(self.title)
+        if title is None:
+            if self.oc is not None: title = self.oc.title
+            else: title = os.path.basename(current_path)
+        self.title = title
+        if self.oc is None:
+            self.oc=OutputCollection(self.title)
         open(NEW_OUTPUT_CREATED,"w").close()
 
     def PerformAction(self):
-        for i in glob.glob("*.dir/*.hierarchy") + \
-                 glob.glob("*Dir/*.hierarchy"):
-            print i
-            fn = i[:-10]
-            self.oc.add_output(os.path.abspath(fn))
+        patterns = [os.path.join(self.current_path, m) for m in self._matches]
+        for p in patterns:
+            for i in glob.glob(p): self.oc.add_output(os.path.abspath(i[:-10]))
         Giles = Watcher(title=self.title, oc=self.oc)
         Giles.run(True)
         self.oc.write_out()

Modified: trunk/yt/reason/App.py
==============================================================================
--- trunk/yt/reason/App.py	(original)
+++ trunk/yt/reason/App.py	Thu Jun 19 13:56:55 2008
@@ -32,6 +32,7 @@
 _SliceObjectMenuItems = []
 _CuttingPlaneObjectMenuItems = ["export",]
 _ProfileObjectMenuItems = ["export",]
+_FidoOutputMenuItems = ["delete",]
 
 class ReasonMainWindow(wx.Frame):
     def __init__(self, *args, **kwds):
@@ -100,17 +101,20 @@
 
         # Set up IDs for event binding
 
-        open_hierarchy = file_menu.Append(-1, "Open Hierarchy")
+        open_hierarchy = file_menu.Append(-1, "Open Individual Hierarchy")
+        import_directory = file_menu.Append(-1, "Import Data Directory")
+        file_menu.AppendSeparator()
         field_inspector = file_menu.Append(-1, "Inspect Fields")
-        open_shell = file_menu.Append(-1, "Open Shell")
-        open_editor = file_menu.Append(-1, "Open Editor")
+        #open_shell = file_menu.Append(-1, "Open Shell")
+        open_editor = file_menu.Append(-1, "Open Shell & Editor")
         save_image = file_menu.Append(-1, "Save Image")
         file_menu.AppendSeparator()
         exit = file_menu.Append(-1, "Exit")
 
         self.Bind(wx.EVT_MENU, self.OnOpenHierarchy, open_hierarchy)
+        self.Bind(wx.EVT_MENU, self.OnImportDirectory, import_directory)
         self.Bind(wx.EVT_MENU, self.OnInspectFields, field_inspector)
-        self.Bind(wx.EVT_MENU, self.OnOpenShell, open_shell)
+        #self.Bind(wx.EVT_MENU, self.OnOpenShell, open_shell)
         self.Bind(wx.EVT_MENU, self.OnOpenEditor, open_editor)
         self.Bind(wx.EVT_MENU, self.OnSaveImage, save_image)
         self.Bind(wx.EVT_MENU, self.OnExit, exit)
@@ -128,6 +132,7 @@
         self.PopupMenuIds["extract"] = self.PopupMenu.Append(-1, "Extract Set")
         self.PopupMenuIds["cube"] = self.PopupMenu.Append(-1, "Extract Cube")
         self.PopupMenuIds["export"] = self.PopupMenu.Append(-1, "Export Data")
+        self.PopupMenuIds["delete"] = self.PopupMenu.Append(-1, "Delete Item")
 
         self.Bind(wx.EVT_MENU, self._add_slice, self.PopupMenuIds["slice"])
         self.Bind(wx.EVT_MENU, self._add_proj, self.PopupMenuIds["proj"])
@@ -137,6 +142,7 @@
         self.Bind(wx.EVT_MENU, self._extract_set, self.PopupMenuIds["extract"])
         #self.Bind(wx.EVT_MENU, self._extract_cube, self.PopupMenuIds["cube"])
         self.Bind(wx.EVT_MENU, self._export_data_object, self.PopupMenuIds["export"])
+        self.Bind(wx.EVT_MENU, self._remove_fido_output, self.PopupMenuIds["delete"])
 
     def __setup_data_tree(self):
 
@@ -161,7 +167,9 @@
         self.data_tree.DeleteChildren(self.fido_root)
         gc = fido.GrabCollections()
         for c in gc:
-            cRoot = self.data_tree.AppendItem(self.fido_root, c.title)
+            tid = wx.TreeItemData((c.title, c._last_read_filename,
+                                  -1, _FidoOutputMenuItems,))
+            cRoot = self.data_tree.AppendItem(self.fido_root, c.title, data=tid)
             for fn in c:
                 if not os.path.isfile(fn): continue
                 try:
@@ -171,15 +179,22 @@
                     z = "N/A"
                 tt = str(fido.get_parameter_line(fn,
                              "InitialTime"))
-                tid = wx.TreeItemData((fn, tt, z, _StaticOutputMenuItems))
+                tid = wx.TreeItemData((fn, tt, z, _StaticOutputMenuItems, ))
                 ni = self.data_tree.AppendItem(cRoot,
                     "%s" % (os.path.basename(fn)), data=tid)
 
     def _remove_fido_output(self, event=None):
-        pass
-
-    def _remove_fido_outputcollection(self, event=None):
-        pass
+        tid = self.data_tree.GetSelection()
+        data_object = self.data_tree.GetItemData(tid).GetData()
+        dlg = wx.MessageDialog(self,
+                'Are you sure you want to delete the record of that output?\n' + \
+                'This will leave the data itself unaffected.',
+                'Record Deletion Confirmation', wx.YES_NO | wx.ICON_INFORMATION)
+        if dlg.ShowModal() == wx.ID_YES and os.path.isfile(data_object[1]):
+            mylog.info("Removing %s", data_object[1])
+            os.unlink(data_object[1])
+        dlg.Destroy()
+        self.__setup_fido_tree()
 
     def __setup_toolbar(self):
         # Tool Bar
@@ -530,6 +545,15 @@
         p = FieldFunctionInspector(self, -1)
         p.Show()
 
+    def OnImportDirectory(self, event=None):
+        dialog = wx.DirDialog(self, "Choose a data directory",
+                    style=wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST)
+        if dialog.ShowModal() == wx.ID_OK:
+            file = dialog.GetPath()
+            fido.Import(current_path = file).PerformAction()
+        self.__setup_fido_tree()
+        dialog.Destroy()
+
     def OnOpenHierarchy(self, event):
         wildcard = "Hierarchy (*.hierarchy)|*.hierarchy|" \
                    "All files (*,*)|*.*"



More information about the yt-svn mailing list