From: W. Trevor King Date: Sat, 31 Jul 2010 20:15:11 +0000 (-0400) Subject: Removed some old cruft from hooke/ui/gui/ X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=29350f8118615a796ba7dddbe4741840c84d1c5f;p=hooke.git Removed some old cruft from hooke/ui/gui/ --- diff --git a/hooke/ui/gui/delta.py b/hooke/ui/gui/delta.py deleted file mode 100644 index 7996daa..0000000 --- a/hooke/ui/gui/delta.py +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env python - -''' -delta.py - -Delta class for Hooke to describe differences between 2 points. - -Copyright 2010 by Dr. Rolf Schmidt (Concordia University, Canada) - -This program is released under the GNU General Public License version 2. -''' - -from lib.curve import Units - -class Point(object): - - def __init__(self): - self.x = 0 - self.y = 0 - -class Delta(object): - - def __init__(self): - self.point1 = Point() - self.point2 = Point() - self.units = Units() - - def get_delta_x(self): - return self.point1.x - self.point2.x - - def get_delta_y(self): - return self.point1.y - self.point2.y - - diff --git a/hooke/ui/gui/driver.py b/hooke/ui/gui/driver.py deleted file mode 100644 index b5b4809..0000000 --- a/hooke/ui/gui/driver.py +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env python - -''' -driver.py - -Base class for file format drivers. - -Copyright 2006 by Massimo Sandal (University of Bologna, Italy). - -This program is released under the GNU General Public License version 2. -''' - -import lib.plot - -class Driver(object): - ''' - Base class for file format drivers. - - To be overridden - ''' - def __init__(self): - self.experiment = '' - self.filetype = '' - - def is_me(self): - ''' - This method must read the file and return True if the filetype can be managed by the driver, False if not. - ''' - return False - - def close_all(self): - ''' - This method must close all the open files of the driver, explicitly. - ''' - return None - - def default_plots(self): - plot = lib.plot.Plot() - plot.curves.append([0]) - plot.curves.append([0]) - - return [plot] - - - diff --git a/hooke/ui/gui/export.py b/hooke/ui/gui/export.py deleted file mode 100644 index 9e5e6ea..0000000 --- a/hooke/ui/gui/export.py +++ /dev/null @@ -1,48 +0,0 @@ -# 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 -# . - - #PLOT EXPORT AND MANIPULATION COMMANDS - def help_export(self): - print ''' -EXPORT -Saves the current plot as an image file ---------------- -Syntax: export [filename] {plot to export} - -The supported formats are PNG and EPS; the file extension of the filename is automatically recognized -and correctly exported. Resolution is (for now) fixed at 150 dpi. - -If you have a multiple plot, the optional plot to export argument tells Hooke which plot you want to export. If 0, the top plot is exported. If 1, the bottom plot is exported (Exporting both plots is still to implement) - ''' - def do_export(self,args): - #FIXME: the bottom plot doesn't have the title - - dest=0 - - if len(args)==0: - #FIXME: We have to go into the libinput stuff and fix it, for now here's a dummy replacement... - #name=linp.safeinput('Filename?',[self.current.path+'.png']) - name=raw_input('Filename? ') - else: - args=args.split() - name=args[0] - if len(args) > 1: - dest=int(args[1]) - - export_image=self.list_of_events['export_image'] - wx.PostEvent(self.frame, export_image(name=name, dest=dest)) diff --git a/hooke/ui/gui/file.py b/hooke/ui/gui/file.py deleted file mode 100644 index 6af41db..0000000 --- a/hooke/ui/gui/file.py +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env python - -''' -file.py - -File class for Hooke. - -Copyright 2010 by Dr. Rolf Schmidt (Concordia University, Canada) - -This program is released under the GNU General Public License version 2. -''' - -import os.path -import lib.plot - -class File(object): - - def __init__(self, filename=None, drivers=None): - self.driver = None - self.note = '' - self.plot = lib.plot.Plot() - if filename is None: - self.filename = None - self.name = None - self.path = None - else: - self.filename = filename - self.path, self.name = os.path.split(filename) - - def identify(self, drivers): - ''' - identifies a curve and returns the corresponding object - ''' - for driver in drivers: - current_driver = driver(self.filename) - if current_driver.is_me(): - #bring on all the driver, with its load of methods etc. - #so we can access the whole of it. - self.plot = current_driver.default_plots() - self.driver = current_driver diff --git a/hooke/ui/gui/hookeplaylist.py b/hooke/ui/gui/hookeplaylist.py deleted file mode 100644 index 130bd0a..0000000 --- a/hooke/ui/gui/hookeplaylist.py +++ /dev/null @@ -1,124 +0,0 @@ -# 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 -# . - -#import os -#import os.path -import wx -#import xml.dom.minidom - -class Playlists(wx.Panel): - - def __init__(self, parent): - # Use the WANTS_CHARS style so the panel doesn't eat the Return key. - wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS|wx.NO_BORDER, size=(160, 200)) - - self.PlaylistsTree = wx.TreeCtrl(self, -1, wx.Point(0, 0), wx.Size(160, 250), wx.TR_DEFAULT_STYLE | wx.NO_BORDER | wx.TR_HIDE_ROOT) - imglist = wx.ImageList(16, 16, True, 2) - imglist.Add(wx.ArtProvider.GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, wx.Size(16, 16))) - imglist.Add(wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, wx.Size(16, 16))) - self.PlaylistsTree.AssignImageList(imglist) - self.PlaylistsTree.AddRoot('Playlists', 0) - self.PlaylistsTree.Bind(wx.EVT_RIGHT_DOWN , self.OnContextMenu) - - self.Playlists = {} - - sizer = wx.BoxSizer(wx.VERTICAL) - sizer.Add(self.PlaylistsTree, 1, wx.EXPAND) - self.SetSizer(sizer) - sizer.Fit(self) - - #def add_playlist(self, files=[], name='Untitled'): - ##TODO: change cursor or progressbar (maybe in statusbar) - ##self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) - #if files: - #playlist = hookeplaylist.Playlist(self.drivers) - #for item in files: - #playlist.append_curve_by_path(item) - #if playlist.count > 0: - #playlist_name = name - #count = 1 - #while playlist_name in self.Playlists: - #playlist_name = ''.join([name, str(count)]) - #count += 1 - #playlist.name = playlist_name - #playlist.reset() - #self.AddToPlaylists(playlist) - - #def FilterPlaylist(self, curves_to_keep=[]): - #playlist_active = self.GetActivePlaylist() - #playlist_new = Playlist(self.drivers) - #for curve_index in curves_to_keep: - #playlist_new.curves.append(playlist_active.curves[curve_index]) - #return playlist_new - - def GetActivePlaylist(self): - playlist_name = self.GetActivePlaylistName() - if playlist_name in self.playlists: - return self.playlists[playlist_name][0] - else: - return None - - def GetActivePlaylistName(self): - #get the selected item from the tree - selected_item = self.PlaylistsTree.GetSelection() - #test if a playlist or a curve was double-clicked - if self.PlaylistsTree.ItemHasChildren(selected_item): - playlist_item = selected_item - else: - #get the name of the playlist - playlist_item = self.PlaylistsTree.GetItemParent(selected_item) - #now we have a playlist - return self.PlaylistsTree.GetItemText(playlist_item) - - def OnContextMenu(self, event): - hit_item, hit_flags = self.PlaylistsTree.HitTest(event.GetPosition()) - if (hit_flags & wx.TREE_HITTEST_ONITEM) != 0: - self.PlaylistsTree.SelectItem(hit_item) - # only do this part the first time so the events are only bound once - # - # Yet another alternate way to do IDs. Some prefer them up top to - # avoid clutter, some prefer them close to the object of interest - # for clarity. - if not hasattr(self, 'ID_popupAdd'): - self.ID_popupAdd = wx.NewId() - self.ID_popupClose = wx.NewId() - self.Bind(wx.EVT_MENU, self.OnPopupAdd, id=self.ID_popupAdd) - self.Bind(wx.EVT_MENU, self.OnPopupClose, id=self.ID_popupClose) - # make a menu - menu = wx.Menu() - items = [['Add', self.ID_popupAdd] , ['Close', self.ID_popupClose]] - for item in items: - menu.Append(item[1], item[0]) - # Popup the menu. If an item is selected then its handler - # will be called before PopupMenu returns. - self.PopupMenu(menu) - menu.Destroy() - - def OnPopupAdd(self, event): - pass - - def OnPopupClose(self, event): - item = self.PlaylistsTree.GetSelection() - if self.PlaylistsTree.ItemHasChildren(item): - playlist_name = self.PlaylistsTree.GetItemText(item) - self.Parent.DeletePlotPage(playlist_name) - #del self.Playlists[playlist_name] - #TODO: delete playlist, close notebook tab - #self.Parent.AddToPlaylists() - else: - pass diff --git a/hooke/ui/gui/hookeresults.py b/hooke/ui/gui/hookeresults.py deleted file mode 100644 index 8ab93fc..0000000 --- a/hooke/ui/gui/hookeresults.py +++ /dev/null @@ -1,94 +0,0 @@ -# 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 -# . - -import sys -import wx -from wx.lib.mixins.listctrl import CheckListCtrlMixin - -import prettyformat - -class CheckListCtrl(wx.ListCtrl, CheckListCtrlMixin): - def __init__(self, parent): - wx.ListCtrl.__init__(self, parent, -1, style=wx.LC_REPORT) - CheckListCtrlMixin.__init__(self) - self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated) - - def OnItemActivated(self, evt): - self.ToggleItem(evt.m_itemIndex) - - -class Results(wx.Panel): - def __init__(self, parent): - wx.Panel.__init__(self, parent, -1) - self.results_list = CheckListCtrl(self) - sizer = wx.BoxSizer() - sizer.Add(self.results_list, 1, wx.EXPAND) - self.SetSizer(sizer) - self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.results_list) - self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected, self.results_list) - #self.results_list.OnCheckItem = self.OnCheckItem - - def _GetWidthInPixels(self, text): - #TODO: - #Returns the width of a string in pixels - #Unfortunately, it does not work terribly well (although it should). - #Thus, we have to add a bit afterwards. - #Annoys the heck out of me. - font = self.results_list.GetFont() - dc = wx.WindowDC(self.results_list) - dc.SetFont(font) - width, height = dc.GetTextExtent(text) - return width - - def ClearResults(self): - self.results_list.ClearAll() - - def DisplayResults(self, results): - self.ClearResults() - header = results.header_as_list() - self.results_list.InsertColumn(0, 'Show') - for index, column in enumerate(header): - self.results_list.InsertColumn(index + 1, column, wx.LIST_FORMAT_RIGHT) - - for result in results.results: - done = False - for index, column in enumerate(results.columns): - value_str = results.get_pretty_value(column, result.result[column]) - if not done: - index_col = self.results_list.InsertStringItem(sys.maxint, '') - done = True - column_width = len(self.results_list.GetColumn(index + 1).GetText()) - value_str = value_str.center(column_width) - self.results_list.SetStringItem(index_col, index + 1, value_str) - #self.results_list.SetItemData(index, result) - - for index, result in enumerate(results.results): - if result.visible: - #if we use 'CheckItem' then 'UpdatePlot' is called (ie repeated updates) - self.results_list.SetItemImage(index, 1) - #self.results_list.CheckItem(index) - for index in range(self.results_list.GetColumnCount()): - column_text = self.results_list.GetColumn(index).GetText() - column_width = self._GetWidthInPixels(column_text) - self.results_list.SetColumnWidth(index, column_width + 15) - - def OnItemSelected(self, evt): - pass - - def OnItemDeselected(self, evt): - pass diff --git a/hooke/ui/gui/libhooke.py b/hooke/ui/gui/libhooke.py deleted file mode 100644 index 17dbf6a..0000000 --- a/hooke/ui/gui/libhooke.py +++ /dev/null @@ -1,109 +0,0 @@ -#!/usr/bin/env python - -''' -libhooke.py - -General library of internal objects and utilities for Hooke. - -Copyright 2006 by Massimo Sandal (University of Bologna, Italy). -With algorithms contributed by Francesco Musiani (University of Bologna, Italy) -And additions contributed by Dr. Rolf Schmidt (Concordia University, Canada) - -This program is released under the GNU General Public License version 2. -''' - -import csv -import os.path -import numpy -import scipy - -HOOKE_VERSION=['0.9.0_devel', 'Kenzo', '2010-01-31'] - -hookeDir='' - -#constants for 'special' curves -#this can make it easier to understand what curve we are working on -EXTENSION = 0 -RETRACTION = 1 - -def coth(z): - ''' - Hyperbolic cotangent. - ''' - return (numpy.exp(2 * z) + 1) / (numpy.exp(2 * z) - 1) - -def delete_empty_lines_from_xmlfile(filename): - #the following 3 lines are needed to strip newlines. - #Otherwise, since newlines are XML elements too, the parser would read them - #(and re-save them, multiplying newlines...) - aFile=file(filename).read() - aFile=aFile.split('\n') - aFile=''.join(aFile) - return aFile - -def fit_interval_nm(start_index, x_vect, nm, backwards): - ''' - Calculates the number of points to fit, given a fit interval in nm - start_index: index of point - plot: plot to use - backwards: if true, finds a point backwards. - ''' - c = 0 - i = start_index - maxlen=len(x_vect) - while abs(x_vect[i] - x_vect[start_index]) * (10**9) < nm: - if i == 0 or i == maxlen-1: #we reached boundaries of vector! - return c - if backwards: - i -= 1 - else: - i += 1 - c += 1 - return c - -def get_file_path(filename, folders = []): - if os.path.dirname(filename) == '' or os.path.isabs(filename) == False: - path = '' - for folder in folders: - path = os.path.join(path, folder) - filename = os.path.join(hookeDir, path, filename) - return filename - -def remove_extension(filename): - ''' - Removes the extension from a filename. - ''' - name, extension = os.path.splitext(filename) - return name - -#CSV-HELPING FUNCTIONS -def csv_write_dictionary(f, data, sorting='COLUMNS'): - ''' - Writes a CSV file from a dictionary, with keys as first column or row - Keys are in "random" order. - - Keys should be strings - Values should be lists or other iterables - ''' - keys=data.keys() - values=data.values() - t_values=transposed2(values) - writer=csv.writer(f) - - if sorting=='COLUMNS': - writer.writerow(keys) - for item in t_values: - writer.writerow(item) - - if sorting=='ROWS': - print 'Not implemented!' #FIXME: implement it. - -def transposed2(lists, defval=0): - ''' - transposes a list of lists, i.e. from [[a,b,c],[x,y,z]] to [[a,x],[b,y],[c,z]] without losing - elements - (by Zoran Isailovski on the Python Cookbook online) - ''' - if not lists: return [] - return map(lambda *row: [elem or defval for elem in row], *lists) - diff --git a/hooke/ui/gui/peakspot.py b/hooke/ui/gui/peakspot.py deleted file mode 100644 index 1a715ac..0000000 --- a/hooke/ui/gui/peakspot.py +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/env python - -''' -peakspot.py - -A library of helping functions for spotting force spectroscopy peaks. - -Copyright 2007 by Fabrizio Benedetti and Massimo Sandal - -This program is released under the GNU General Public License version 2. -''' - -from numpy import mean - -def conv_dx(data,vect): - ''' - Returns the right-centered convolution of data with vector vect - ''' - dim=len(data) - window=len(vect) - temparr=[0.0]*dim - - end=dim-window - - for j in range(end): - for k in range(window): - temparr[j]+=data[j+k]*vect[k] - - return temparr - -def absdev(arr): - ''' - Calculates the absolute deviation of a vector - ''' - med=0.0 - absD=0.0 - - med=mean(arr) - for j in arr: - absD+=abs(j-med) - return absD/len(arr) - -def noise_absdev(data,positive=False,maxcut=0.2,stable=0.005): - ''' - Returns the standard deviation of the noise. - The logic is: we cut the most negative (or positive) data points until the absolute deviation - becomes stable (it doesn't vary more than 0.005) or we have cut more than maxcut*len(data) points. - Then calculate the absolute deviation. - - If positive=True we cut the most positive data points, False=we cut the negative ones. - ''' - #TOD: check if this is necessary - out=[item for item in data] #we copy just to be sure... - out.sort() - if positive: - out.reverse() - - temp_absdev=absdev(out) - - for index in range(len(out)): - cutindex=(index+1)*5 - cut_absdev=absdev(out[cutindex:]) #we jump five points after five points... - if 1-(cut_absdev/temp_absdev) < stable and cutindex<(maxcut*len(out)): - temp_absdev=cut_absdev - else: - break - - return cut_absdev - -def abovenoise(convoluted,noise_level,cut_index=0,abs_devs=4): - ''' - Generates a vector which is 0 where the vector is less than abs_devs*noise_level ; 1 if not (spike). - ''' - #calculate absolute noise deviation - #noise_level=noise_absdev(convoluted[cut_index:]) - - above=[] - - for index in range(len(convoluted)): - if index1: - for index in range(len(peaks_location)-1): - if peaks_location[index+1]-peaks_location[index] < seedouble: - temp_location=peaks_location[:index]+peaks_location[index+1:] - if temp_location != []: - peaks_location=temp_location - - return peaks_location,peaks_size \ No newline at end of file diff --git a/hooke/ui/gui/plot.py b/hooke/ui/gui/plot.py deleted file mode 100644 index cfad721..0000000 --- a/hooke/ui/gui/plot.py +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env python - -''' -plot.py - -Plot class for Hooke. - -Copyright 2010 by Dr. Rolf Schmidt (Concordia University, Canada) - -This program is released under the GNU General Public License version 2. -''' - -class Invert(object): - - def __init__(self): - self.x = False - self.y = False - - -class Plot(object): - - def __init__(self): - self.corrected_curves = [] - self.curves = [] - self.invert = Invert() - self.raw_curves = [] - self.results = {} - self.title = '' - - def normalize(self): - ''' - Trims the vector lengths as to be equal in a plot. - ''' - lengths = [] - for curve in self.curves: - lengths.append(len(curve.x)) - lengths.append(len(curve.y)) - if min(lengths) != max(lengths): - curve.x = curve.x[0:min(lengths)] - curve.y = curve.y[0:min(lengths)] diff --git a/hooke/ui/gui/plotmanipulator.py b/hooke/ui/gui/plotmanipulator.py deleted file mode 100644 index 2d820d3..0000000 --- a/hooke/ui/gui/plotmanipulator.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python - -''' -plotmanipulator.py - -Plotmanipulator class for Hooke. - -Copyright 2010 by Dr. Rolf Schmidt (Concordia University, Canada) - -This program is released under the GNU General Public License version 2. -''' - -from string import replace - -class Plotmanipulator(object): - def __init__(self, command=None, method=None): - #the command (e.g. plotmanip_correct) - self.command = command - #the method associated with the command - self.method = method - #the suffix of the command (e.g. correct) to retrieve - #status (active or not from config) - self.name = command.replace('plotmanip_', '') - - diff --git a/hooke/ui/gui/plugin.py b/hooke/ui/gui/plugin.py deleted file mode 100644 index 24364cb..0000000 --- a/hooke/ui/gui/plugin.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env python - -''' -plugin.py - -ConfigObj plugin class for Hooke. - -Copyright 2010 by Dr. Rolf Schmidt (Concordia University, Canada) - -This program is released under the GNU General Public License version 2. -''' - -class Plugin(object): - ''' - Plugin is a class that is used to facilitate accessing - configuration parameters in a ConfigObj from different plugins. - ''' - - def __init__(self): - self.name = '' - #if the calling plugin uses a prefix, this can be added to the name - #e.g. autopeak.ini: [[peak_color]] - #flatfilts.ini [[color]] - #are both used to set the color of the peak plot (scatter plot) - #in order to access 'peak_color' rather than 'color', the prefix needs to - #be set to 'peak_' - #if the names are identical, set prefix to '' - self.prefix = '' - self.section = ''