Cleanups so hooke/ui/gui/ passes unittests.
authorW. Trevor King <wking@drexel.edu>
Wed, 29 Sep 2010 14:17:07 +0000 (10:17 -0400)
committerW. Trevor King <wking@drexel.edu>
Wed, 29 Sep 2010 14:17:07 +0000 (10:17 -0400)
hooke/ui/gui/dialog/string.py
hooke/ui/gui/handler/__init__.py
hooke/ui/gui/handler/boolean.py
hooke/ui/gui/handler/float.py
hooke/ui/gui/handler/selection.py
hooke/ui/gui/handler/string.py
hooke/ui/gui/panel/selection.py
hooke/ui/gui/results.py [deleted file]

index 6e29ba76912f075a24b51d96510cd17548b3ee59..734bfaa8b1b1dae0ae2a0d9cc3c9b2ea8b841cbd 100644 (file)
@@ -1,5 +1,10 @@
-class StringPopup (wx.Dialog):
+# Copyright
+
+import wx
 
+
+class StringPopup (wx.Dialog):
+    def __init__(self):
         self._c = {
             'text': wx.StaticText(
                 parent=self, label=message, style=wx.ALIGN_CENTRE),
index 98bdb06a257eae2e0d4cf1abeee652598ceae7b7..d22a45946e2bc61a7ad660789291e0f751ed8c1a 100644 (file)
@@ -16,7 +16,7 @@
 # License along with Hooke.  If not, see
 # <http://www.gnu.org/licenses/>.
 
-from ....util.pluggable import IsSubclass, construct_graph
+from ....util.pluggable import IsSubclass, construct_odict
 
 
 HANDLER_MODULES = [
@@ -44,12 +44,13 @@ class Handler (object):
 
     def _cancel(self, *args, **kwargs):
         # TODO: somehow abort the running command
+        pass
 
 
 HANDLERS = construct_odict(
     this_modname=__name__,
-    submodnames=USER_INTERFACE_MODULES,
-    class_selector=IsSubclass(UserInterface, blacklist=[UserInterface]))
+    submodnames=HANDLER_MODULES,
+    class_selector=IsSubclass(Handler, blacklist=[Handler]))
 """:class:`hooke.compat.odict.odict` of :class:`Handler`
 instances keyed by `.name`.
 """
index c87bf83e5bf2fd09b077334fd771d7620af903f5..79315909bc532de95263c09c055be2df30b85cb2 100644 (file)
 
 import wx
 
+"""Define :class:`BooleanHandler` to handle
+:class:`~hooke.interaction.BooleanRequest`\s.
+"""
+
 from . import Handler
 
 
 class BooleanHandler (Handler):
-    
+    def __init__(self):
+        super(BooleanHandler, self).__init__(name='boolean')
+
     def run(self, hooke_frame, msg):
         if msg.default == True:
             default = wx.YES_DEFAULT
@@ -36,4 +42,3 @@ class BooleanHandler (Handler):
         dialog.ShowModal()
         dialog.Destroy()
         return value
-
index b2e1ba03fa84eab9ef1abe8d7c98b074226ea05e..8f6eb13940260dd3c567b516fdf7572746829e6b 100644 (file)
@@ -1,6 +1,34 @@
+# Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
+#
+# This file is part of Hooke.
+#
+# Hooke is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# Hooke is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
+# Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with Hooke.  If not, see
+# <http://www.gnu.org/licenses/>.
+
+"""Define :class:`FloatHandler` to handle
+:class:`~hooke.interaction.FloatRequest`\s.
+"""
+
+from . import Handler
+
+
+class FloatHandler (object):
+    def __init__(self):
+        super(FloatHandler, self).__init__(name='float')
+
     def _float_request_prompt(self, msg):
         return self._string_request_prompt(msg)
 
     def _float_request_parser(self, msg, resposne):
         return float(response)
-
index ee0e5e0d10f43c0a5aec8e5a4854a4cb317147cd..d8330b5000fa7522c0e6e6de364a556e190e58e9 100644 (file)
 
 import wx
 
-from ..dialog.selection import SelectionDialog
+from ..dialog.selection import Selection
 from . import Handler
 
 
 class SelectionHandler (Handler):
     def __init__(self):
-        super(StringHandler, self).__init__(name='selection')
+        super(SelectionHandler, self).__init__(name='selection')
 
     def run(self, hooke_frame, msg):
         self._canceled = True
         while self._canceled:
-            s = SelectionDialog(
+            s = Selection(
                 options=msg.options,
                 message=msg.msg,
                 button_id=wxID_OK,
@@ -44,8 +44,7 @@ class SelectionHandler (Handler):
                 selection_style='single',
                 parent=self,
                 label='Selection handler',
-                style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER),
-            )
+                style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
         return self._selected
 
     def _selection(self, _class, method, options, selected):
index 4147026327d549465db740ca7a07f08fa3d8b876..a5876e7fa1ee09857a774a16d5f2fbea6585c1d1 100644 (file)
@@ -25,8 +25,6 @@ import wx
 from . import Handler
 
 
-
-
 class StringHandler (Handler):
     def __init__(self):
         super(StringHandler, self).__init__(name='string')
@@ -43,4 +41,3 @@ class StringHandler (Handler):
 
     def _string_request_parser(self, msg, response):
         return response.strip()
-
index 13da12ec416742ab8bc5a3ff3f05edbbdc9906fb..6038b0881841a5d0222c93a1140014a595f5b014 100644 (file)
@@ -109,6 +109,6 @@ class SelectionDialog (wx.Dialog):
             selected = self._c['listbox'].GetSelection()
         else:
             assert self._selection_style == 'multiple', self._selection_style
-            selected = self._c['listbox'].GetChecked())
+            selected = self._c['listbox'].GetChecked()
         in_callback(self, options=self._options, selected=selected)
         self.EndModal(wx.ID_CLOSE)
diff --git a/hooke/ui/gui/results.py b/hooke/ui/gui/results.py
deleted file mode 100644 (file)
index 01f859d..0000000
+++ /dev/null
@@ -1,189 +0,0 @@
-#!/usr/bin/env python
-
-'''
-results.py
-
-Result and Results classes for Hooke.
-
-Copyright 2009 by Dr. Rolf Schmidt (Concordia University, Canada)
-
-This program is released under the GNU General Public License version 2.
-'''
-
-from numpy import nan
-
-import prettyformat
-import lib.curve
-
-DEFAULT_COLOR = 'green'
-DEFAULT_DECIMAL = 2
-DEFAULT_STYLE = 'scatter'
-
-class Result(lib.curve.Curve):
-    def __init__(self):
-        lib.curve.Curve.__init__(self)
-        self.color = DEFAULT_COLOR
-        self.result = {}
-        self.style = DEFAULT_STYLE
-
-class Results(object):
-    def __init__(self):
-        self.columns = []
-        self.decimals = {}
-        self.has_multipliers = False
-        self.multipliers = {}
-        self.results = []
-        self.separator='\t'
-        self.units = {}
-
-    def get_pretty_value(self, column, value):
-        if self.has_multipliers and self.has_results():
-            multiplier = self.multipliers[column]
-            decimals = self.decimals[column]
-            return prettyformat.pretty_format(value, '', decimals, multiplier, True)
-        return str(value)
-
-    def has_results(self):
-        return len(self.results) > 0
-
-    def get_header_as_list(self):
-        header_list = []
-        if self.has_results():
-            if not self.has_multipliers:
-                self.set_multipliers()
-            for column in self.columns:
-                unit_str = ''.join([prettyformat.get_prefix(self.multipliers[column]), self.units[column]])
-                header_str = ''.join([column, ' [', unit_str, ']'])
-                header_list.append(header_str)
-        return header_list
-
-    def get_header_as_str(self, separator=None):
-        if separator is None:
-            separator = self.separator
-        return separator.join(map(str, self.get_header_as_list()))
-
-    def get_result_as_list(self, index=0):
-        if index >= 0 and index < len(self.results):
-            result_list = []
-            if self.has_results():
-                if not self.has_multipliers:
-                    self.set_multipliers()
-                for column in self.columns:
-                    result_str = prettyformat.pretty_format(self.results[index].result[column], '', self.decimals[column], self.multipliers[column], True)
-                    result_list.append(result_str)
-            return result_list
-        else:
-            return None
-
-    def get_result_as_string(self, index=0):
-        results_list = self.get_result_as_list(index)
-        if results_list is not None:
-            return self.separator.join(map(str, results_list))
-        else:
-            return ''
-
-    def set_decimal(self, column, decimal=DEFAULT_DECIMAL):
-        if self.decimals.has_key(column):
-            self.decimals[column] = decimal
-
-    def set_decimals(self, decimals=DEFAULT_DECIMAL):
-        if decimals < 0:
-            #set default value if necessary
-            decimals = DEFAULT_DECIMAL
-        for column in self.columns:
-            self.decimals[column] = decimals
-
-    def set_multipliers(self, index=0):
-        if self.has_results():
-            for column in self.columns:
-                #result will contain the results dictionary at 'index'
-                result = self.results[index].result
-                #in position 0 of the result we find the value
-                self.multipliers[column] = prettyformat.get_multiplier(result[column])
-            self.has_multipliers = True
-        else:
-            self.has_multipliers = False
-
-    def update(self):
-        pass
-
-
-class ResultsFJC(Results):
-    def __init__(self):
-        Results.__init__(self)
-        self.columns = ['Contour length', 'sigma contour length', 'Kuhn length', 'sigma Kuhn length', 'Rupture force', 'Slope', 'Loading rate']
-        self.units['Contour length'] = 'm'
-        self.units['sigma contour length'] = 'm'
-        self.units['Kuhn length'] = 'm'
-        self.units['sigma Kuhn length'] = 'm'
-        self.units['Rupture force'] = 'N'
-        self.units['Slope'] = 'N/m'
-        self.units['Loading rate'] = 'N/s'
-        self.set_decimals(2)
-
-    def set_multipliers(self, index=0):
-        if self.has_results():
-            for column in self.columns:
-                #result will contain the results dictionary at 'index'
-                result = self.results[index].result
-                #in position 0 of the result we find the value
-                if column == 'sigma contour length':
-                    self.multipliers[column] = self.multipliers['Contour length']
-                elif column == 'sigma Kuhn length':
-                    self.multipliers[column] = self.multipliers['Kuhn length']
-                else:
-                    self.multipliers[column] = prettyformat.get_multiplier(result[column])
-            self.has_multipliers = True
-        else:
-            self.has_multipliers = False
-
-class ResultsMultiDistance(Results):
-    def __init__(self):
-        Results.__init__(self)
-        self.columns = ['Distance']
-        self.units['Distance'] = 'm'
-        self.set_decimals(2)
-
-    def update(self):
-        if (self.results) > 0:
-            for result in self.results:
-                if result.visible:
-                    reference_peak = result.x
-                    break
-
-            for result in self.results:
-                if result.visible:
-                    result.result['Distance'] = reference_peak - result.x
-                    reference_peak = result.x
-                else:
-                    result.result['Distance'] = nan
-
-
-class ResultsWLC(Results):
-    def __init__(self):
-        Results.__init__(self)
-        self.columns = ['Contour length', 'sigma contour length', 'Persistence length', 'sigma persistence length', 'Rupture force', 'Slope', 'Loading rate']
-        self.units['Contour length'] = 'm'
-        self.units['sigma contour length'] = 'm'
-        self.units['Persistence length'] = 'm'
-        self.units['sigma persistence length'] = 'm'
-        self.units['Rupture force'] = 'N'
-        self.units['Slope'] = 'N/m'
-        self.units['Loading rate'] = 'N/s'
-        self.set_decimals(2)
-
-    def set_multipliers(self, index=0):
-        if self.has_results():
-            for column in self.columns:
-                #result will contain the results dictionary at 'index'
-                result = self.results[index].result
-                #in position 0 of the result we find the value
-                if column == 'sigma contour length':
-                    self.multipliers[column] = self.multipliers['Contour length']
-                elif column == 'sigma persistence length':
-                    self.multipliers[column] = self.multipliers['Persistence length']
-                else:
-                    self.multipliers[column] = prettyformat.get_multiplier(result[column])
-            self.has_multipliers = True
-        else:
-            self.has_multipliers = False