From 28da140d33cb25f637e7dd18e28fb3be8d9acc1f Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 29 Sep 2010 10:17:07 -0400 Subject: [PATCH 1/1] Cleanups so hooke/ui/gui/ passes unittests. --- hooke/ui/gui/dialog/string.py | 7 +- hooke/ui/gui/handler/__init__.py | 7 +- hooke/ui/gui/handler/boolean.py | 9 +- hooke/ui/gui/handler/float.py | 30 ++++- hooke/ui/gui/handler/selection.py | 9 +- hooke/ui/gui/handler/string.py | 3 - hooke/ui/gui/panel/selection.py | 2 +- hooke/ui/gui/results.py | 189 ------------------------------ 8 files changed, 51 insertions(+), 205 deletions(-) delete mode 100644 hooke/ui/gui/results.py diff --git a/hooke/ui/gui/dialog/string.py b/hooke/ui/gui/dialog/string.py index 6e29ba7..734bfaa 100644 --- a/hooke/ui/gui/dialog/string.py +++ b/hooke/ui/gui/dialog/string.py @@ -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), diff --git a/hooke/ui/gui/handler/__init__.py b/hooke/ui/gui/handler/__init__.py index 98bdb06..d22a459 100644 --- a/hooke/ui/gui/handler/__init__.py +++ b/hooke/ui/gui/handler/__init__.py @@ -16,7 +16,7 @@ # License along with Hooke. If not, see # . -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`. """ diff --git a/hooke/ui/gui/handler/boolean.py b/hooke/ui/gui/handler/boolean.py index c87bf83..7931590 100644 --- a/hooke/ui/gui/handler/boolean.py +++ b/hooke/ui/gui/handler/boolean.py @@ -18,11 +18,17 @@ 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 - diff --git a/hooke/ui/gui/handler/float.py b/hooke/ui/gui/handler/float.py index b2e1ba0..8f6eb13 100644 --- a/hooke/ui/gui/handler/float.py +++ b/hooke/ui/gui/handler/float.py @@ -1,6 +1,34 @@ +# Copyright (C) 2010 W. Trevor King +# +# 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 +# . + +"""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) - diff --git a/hooke/ui/gui/handler/selection.py b/hooke/ui/gui/handler/selection.py index ee0e5e0..d8330b5 100644 --- a/hooke/ui/gui/handler/selection.py +++ b/hooke/ui/gui/handler/selection.py @@ -22,18 +22,18 @@ 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): diff --git a/hooke/ui/gui/handler/string.py b/hooke/ui/gui/handler/string.py index 4147026..a5876e7 100644 --- a/hooke/ui/gui/handler/string.py +++ b/hooke/ui/gui/handler/string.py @@ -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() - diff --git a/hooke/ui/gui/panel/selection.py b/hooke/ui/gui/panel/selection.py index 13da12e..6038b08 100644 --- a/hooke/ui/gui/panel/selection.py +++ b/hooke/ui/gui/panel/selection.py @@ -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 index 01f859d..0000000 --- a/hooke/ui/gui/results.py +++ /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 -- 2.26.2