Fixed curve/playlist choice argument handling in panel.propertyeditor2
authorW. Trevor King <wking@drexel.edu>
Sat, 31 Jul 2010 12:36:29 +0000 (08:36 -0400)
committerW. Trevor King <wking@drexel.edu>
Sat, 31 Jul 2010 12:36:29 +0000 (08:36 -0400)
hooke/ui/gui/__init__.py
hooke/ui/gui/panel/propertyeditor2.py

index 231b0544359a62e507ea891198e72e5f38fb0a22..b1e854d2995ee7d1317c6a67b6fbe62b7550696d 100644 (file)
@@ -335,7 +335,7 @@ class HookeFrame (wx.Frame):
 \r
     # Command-specific postprocessing\r
 \r
-    def _postprocess_text(self, command, args, results):\r
+    def _postprocess_text(self, command, args={}, results=[]):\r
         """Print the string representation of the results to the Results window.\r
 \r
         This is similar to :class:`~hooke.ui.commandline.DoCommand`'s\r
@@ -348,27 +348,27 @@ class HookeFrame (wx.Frame):
                 self._c['output'].write(result.__class__.__name__+'\n')\r
             self._c['output'].write(str(result).rstrip()+'\n')\r
 \r
-    def _postprocess_load_playlist(self, command, args, results):\r
+    def _postprocess_load_playlist(self, command, args={}, results=None):\r
         """Update `self` to show the playlist.\r
         """\r
         if not isinstance(results[-1], Success):\r
-            self._postprocess_text(command, results)\r
+            self._postprocess_text(command, results=results)\r
         assert len(results) == 2, results\r
         playlist = results[0]\r
         self._c['playlists']._c['tree'].add_playlist(playlist)\r
 \r
-    def _postprocess_get_playlist(self, command, args, results):\r
+    def _postprocess_get_playlist(self, command, args={}, results=[]):\r
         if not isinstance(results[-1], Success):\r
-            self._postprocess_text(command, results)\r
+            self._postprocess_text(command, results=results)\r
         assert len(results) == 2, results\r
         playlist = results[0]\r
         self._c['playlists']._c['tree'].update_playlist(playlist)\r
 \r
-    def _postprocess_get_curve(self, command, args, results):\r
+    def _postprocess_get_curve(self, command, args={}, results=[]):\r
         """Update `self` to show the curve.\r
         """\r
         if not isinstance(results[-1], Success):\r
-            self._postprocess_text(command, results)\r
+            self._postprocess_text(command, results=results)\r
         assert len(results) == 2, results\r
         curve = results[0]\r
         if args.get('curve', None) == None:\r
@@ -381,12 +381,12 @@ class HookeFrame (wx.Frame):
         self._c['playlists']._c['tree'].set_selected_curve(\r
             playlist, curve)\r
 \r
-    def _postprocess_next_curve(self, command, args, results):\r
+    def _postprocess_next_curve(self, command, args={}, results=[]):\r
         """No-op.  Only call 'next curve' via `self._next_curve()`.\r
         """\r
         pass\r
 \r
-    def _postprocess_previous_curve(self, command, args, results):\r
+    def _postprocess_previous_curve(self, command, args={}, results=[]):\r
         """No-op.  Only call 'previous curve' via `self._previous_curve()`.\r
         """\r
         pass\r
@@ -696,8 +696,25 @@ class HookeFrame (wx.Frame):
         for argument in command.arguments:\r
             if argument.name == 'help':\r
                 continue\r
+\r
+            results = self.execute_command(\r
+                command=self._command_by_name('playlists'))\r
+            if not isinstance(results[-1], Success):\r
+                self._postprocess_text(command, results=results)\r
+                playlists = []\r
+            else:\r
+                playlists = results[0]\r
+\r
+            results = self.execute_command(\r
+                command=self._command_by_name('playlist curves'))\r
+            if not isinstance(results[-1], Success):\r
+                self._postprocess_text(command, results=results)\r
+                curves = []\r
+            else:\r
+                curves = results[0]\r
+\r
             p = prop_from_argument(\r
-                argument, curves=[], playlists=[])  # TODO: lookup playlists/curves\r
+                argument, curves=curves, playlists=playlists)\r
             if p == None:\r
                 continue  # property intentionally not handled (yet)\r
             self._c['property'].append_property(p)\r
@@ -1012,10 +1029,10 @@ class GUI (UserInterface):
                     value='0',\r
                     help='This should probably go...'),\r
             Setting(section=self.setting_section, option='main height',\r
-                    value=500,\r
+                    value=450,\r
                     help='Height of main window in pixels.'),\r
             Setting(section=self.setting_section, option='main width',\r
-                    value=500,\r
+                    value=800,\r
                     help='Width of main window in pixels.'),\r
             Setting(section=self.setting_section, option='main top',\r
                     value=0,\r
index 0bf04a3e04a60ba49b83a37713fa7cdce19a00ab..759441ef964771ca384abea32e419de7da96ee83 100644 (file)
@@ -39,10 +39,10 @@ def prop_from_argument(argument, curves=None, playlists=None):
         return _class(**kwargs)\r
     elif type in ['curve', 'playlist']:\r
         if type == 'curve':\r
-            choices = curves  # extract from a particular playlist?\r
+            choices = curves  # extracted from the current playlist\r
         else:\r
             choices = playlists\r
-        return ChoiceProperty(choices=[c.name for c in choices], **kwargs)\r
+        return ChoiceProperty(choices=choices, **kwargs)\r
     raise NotImplementedError(argument.type)\r
 \r
 def prop_from_setting(setting):\r
@@ -168,18 +168,34 @@ class FloatProperty (Property):
 class ChoiceProperty (Property):\r
     def __init__(self, choices, **kwargs):\r
         assert 'type' not in kwargs, kwargs\r
-        if 'default' not in kwargs:\r
+        if 'default' in kwargs:\r
+            if kwargs['default'] not in choices:\r
+                choices.insert(0, kwargs['default'])\r
+        else:\r
             kwargs['default'] = choices[0]\r
         super(ChoiceProperty, self).__init__(type='choice', **kwargs)\r
         self._choices = choices\r
 \r
     def get_editor(self):\r
-        return wx.grid.GridCellChoiceEditor(choices=self._choices)\r
+        choices = [self.string_for_value(c) for c in self._choices]\r
+        return wx.grid.GridCellChoiceEditor(choices=choices)\r
 \r
     def get_renderer(self):\r
         return None\r
         #return wx.grid.GridCellChoiceRenderer()\r
 \r
+    def string_for_value(self, value):\r
+        if hasattr(value, 'name'):\r
+            return value.name\r
+        return str(value)\r
+\r
+    def value_for_string(self, string):\r
+        for choice in self._choices:\r
+            if self.string_for_value(choice) == string:\r
+               return choice\r
+        raise ValueError(string)\r
+\r
+\r
 class PathProperty (StringProperty):\r
     """Simple file or path property.\r
 \r